Carsten Saager | 1 Jul 2007 18:43
Picon

Re: Re: mixed scala & java eclipse projects

...3.3 works and is my primary test platform, and in fact for hover help
3.2 won't work while 3.3 will (we are reusing an internal JDT control that keeps changing names).
Otherwise, you shouldn't notice too much difference between the two versions. I recommend the latest
3.3 as Eclipse is still a rapidly maturing platform (much like Scala).

I tried to add Scala to the Europa final:

 Scala Development Tools (JDK 1.5 non-BETA/Eclipse 3.2 only) (2.6.2) requires plug-in "org.eclipse.pde.runtime ".

and I can't install - I think you already noticed - with a RC I didn't had this problem.

Carsten 

 
Peter Niederwieser | 1 Jul 2007 19:47
Picon
Gravatar

Re: Re: mixed scala & java eclipse projects


I assume you installed an Eclipse package which doesn't include PDE (e.g.
Eclipse IDE for Java Developers). Downloading the PDE runtime binary and
extracting it to your Eclipse folder should solve the problem. You can get
it from here:
http://europa-mirror1.eclipse.org/eclipse/downloads/drops/R-3.3-200706251500/download.php?dropFile=eclipse-PDE-3.3.zip

Cheers
Peter

csar wrote:
> 
> I tried to add Scala to the Europa final:
> Scala Development Tools (JDK 1.5 non-BETA/Eclipse 3.2 only) (2.6.2)
> requires plug-in "org.eclipse.pde.runtime".
> 

--

-- 
View this message in context: http://www.nabble.com/-scala--mixed-scala---java-eclipse-projects-tf3985735.html#a11383953
Sent from the Scala mailing list archive at Nabble.com.

Alex Boisvert | 1 Jul 2007 20:46
Favicon
Gravatar

Selftype example

Following this week's discussion on object factories, I re-read the paper http://lamp.epfl.ch/~odersky/papers/ScalableComponent.pdf and came up with an example that should be familiar to Java/J2EE programmers where the data access object (DAO) pattern is a quite common abstraction (for data-source independence, testing, etc), 

Going through this exercise helped me get a better understanding of selftypes and how they help with compile-time dependency injection, so I figured I'd share it...

package com.example.database

// data objects
class Department(val id: String, val name: String)
class Employee(val id: String, val name: String, val department: String)

// data access objects (DAOs)
trait Departments {
  def department(id: String): Department
  def employeeCount(d: Department): Int
}
trait Employees {
  def employee(id: String): Employee
  def employees: List[Employee]
}

// combine interdependent DAOs
trait Company extends Departments with Employees

// specialize Company trait with JDBC database access
trait CompanyJDBC extends Company with DepartmentsJDBC with EmployeesJDBC
{
  import java.sql.{Connection, Statement, ResultSet}
  def connection: Connection
  def execute(sql: String) : Option[ResultSet] = {
    val stmt = connection.createStatement
    if (stmt.execute(sql)) Some(stmt.getResultSet) else None
  }
}

// JDBC DAO implementations
trait DepartmentsJDBC extends Departments {
  // self-type used to access DAO dependencies and common behavior
  self: CompanyJDBC =>

  def department(id: String): Department = {
    val result = execute("select * from companies where id = '"+id+"'")
    new Department("mkt", "Marketing") // fake result
  }
  def employeeCount(d: Department): Int = {
    // notice how "employees" is in scope due to JDBCDatabase selftype
    employees.filter(_.department == d.id).size
  }
}

trait EmployeesJDBC extends Employees {
  self: CompanyJDBC =>

  def employee(id: String): Employee = {
    val result = execute("select * from employees where id = '"+id+"'")
    new Employee("1", "John Doe", "mkt") // fake
  }
  def employees: List[Employee] = {
    List( new Employee("1", "John Doe", "mkt") ) // fake
  }
}

object MyApplication extends Application {

  object company extends CompanyJDBC {
    import javax.naming.InitialContext, java.sql.Connection
    // J2EE-style lookup, could also directly create from JDBC driver
    def connection =  (new InitialContext).lookup("datasource").asInstanceOf[Connection]
  }

  val d = company.department("mkt")
  Console.println("Number of employees in marketing department: "+company.employeeCount(d))
}

cheers,
alex

sean.mcdirmid | 2 Jul 2007 07:43
Picon
Picon
Favicon

Re: Re: mixed scala & java eclipse projects

Yikes. I'll admit the 3.3 final just snuck up on me. Perhaps pde.runtime has changed its name. I'll look 
into it. 

Thanks for the info.

Sean

引言 Carsten Saager <csaager <at> gmail.com>:

> >
> > ...3.3 works and is my primary test platform, and in fact for hover
> help
> > 3.2 won't work while 3.3 will (we are reusing an internal JDT control
> that
> > keeps changing names).
> > Otherwise, you shouldn't notice too much difference between the two
> > versions. I recommend the latest
> > 3.3 as Eclipse is still a rapidly maturing platform (much like
> Scala).
> 
> 
> I tried to add Scala to the Europa final:
> 
>  Scala Development Tools (JDK 1.5 non-BETA/Eclipse 3.2 only) (2.6.2)
> requires plug-in "org.eclipse.pde.runtime".
> 
> and I can't install - I think you already noticed - with a RC I didn't
> had
> this problem.
> 
> Carsten
> 

Burak Emir | 2 Jul 2007 10:13
Picon

json access to aladdin

hey derek,

just to tell you, i enabled json access to the bug database, you can get test strings using urls like

http://scala-webapps.epfl.ch/bugtracking/bugs/json/1193

i just escape " and \ using unicode escapes \uxxxx, i hope this was enough to ensure that these are proper json strings... didn't really test or use this feature yet.

for error handling, one gets a json string that has only field "exception" set to some string.

at some point, I will put the list at http://scala-webapps.epfl.ch/bugtracking/bugs/displayBugs.do into an array, but there's no json access to have the abbreviated list yet.

cheers,
Burak
--
Burak Emir
Research Assistant / PhD Candidate
Programming Methods Group
EPFL, 1015 Lausanne, Switzerland
http://lamp.epfl.ch/~emir

Viktor Klang | 2 Jul 2007 12:37
Picon

Re: First Class Properties (Was: Partial Classes)

Hello everybody,
 
I've been lurking the mailinglist for about a week now and altough I have minimal experience using Scala I have 5+ years of Java-experience.
 
Back on topic.
 
I have some ideas concerning first class properties.
 
What I'd like to be able to do for each property:
 
declare a type
declare a validator for that type
 
I would also like to be able to get further information of the property:
 
getType() //Returns the type of the property
getEnclosingType() // returns type of enclosing object/class whatever
getDeclaredName() //returns the name of the property in the enclosing type
getValidator() //returns the validator specified when declaring/constructing the property
set(ReferenceOfSameTypeAsEnclosingClass obj, TypeOfProperty value) //sets value of this property in obj
get(ReferenceOfSameTypeAsEnclosingClass obj) //returns value of the porperty in obj
 
 
conceptual idea: (written in semi-pseudo, semi-java, semi-scala)
 
class Foo
{
     property name: (String, RegexValidator("^blah~") )
}
 
def main(Array[Foo] foos, Array[Property[Foo]] fooProps)
{
   for all foo in foos
        for all fooProp in fooProps
            print fooProp.get(foo)
}
 
Looks a bit sticky when I look on the code, and it could probably be cleaned up alot.
 
Perhaps foo.fooProp would be the same as foo.name (if they are indeed the same property).
 
foo.fooProp could be compiled to fooProp.get(foo) / fooProp.setFoo(foo,value) depending on usage.
 
 
Also, validators and types are kinda redundant.
The calidator itself must be aware of the type it validates, and so it would be unnessescary to declare the property with: "property name : (String,Regex...)" and perhaps "property name : Regex("^blah~")"
 
where the type of Regex would be scala.String.
 
 
 
 
Hmmm... do I make any sense?
 
 
Best regards
/Viktor Klang
 


 
On 6/30/07, Daniel Dekany <ddekany <at> freemail.hu> wrote:
Saturday, June 30, 2007, 3:26:27 PM, Erik Engbrecht wrote:

> Bill,
> Ok, since I introduced the term "first-class properties," I'll take
> the first crack at providing a concise definition:
>
> 1. Properties are objects (OO sense, not necessarily Scala object
> declaration sense) that govern access to a (possibly calculated)
> field. This means properties can have other methods in addition to
> get/set logic, such as registering event listeners.

I'm newbie here at Scala, thus it can happen easily that I miss
something obvious, but still... I wonder what's if instead of val-s
and var-s and methods without argument list (for me that last feels
like a dirty hack) we only had properties. Which then should be Java
bean properties as well -- the Java world use this property concept a
lot, so it would be nice. Wouldn't that be a cleaner concept? Even if
in big part it is only the question of what name we give to things.

BTW, I do realize that when I have var-s and val-s in a class that
will generate setter/getter methods in the resulting Java class. I'm
not sure how much is it just an implementation detail, but even if it
is not just that, they are still not Java bean property
setters/getters. They signatures are not like that.

> and also the "def" syntax, which doesn't group everything into a single structural entity:
> private var _name: String = "John Doe"
> def name = _name
> def name_=(v: String): Unit = _name = v

(Is this something that should work with the current official release,
2.5.1? Not very elegant BTW...)

--
Best regards,
Daniel Dekany


Viktor Klang | 2 Jul 2007 12:53
Picon

Re: First Class Properties (Was: Partial Classes)

Hello everybody,
 
I've been lurking the mailinglist for about a week now and altough I have minimal experience using Scala I have 5+ years of Java-experience.
 
Back on topic.
 
I have some ideas concerning first class properties.
 
What I'd like to be able to do for each property:
 
declare a type
declare a validator for that type
 
I would also like to be able to get further information of the property:
 
getType() //Returns the type of the property
getEnclosingType() // returns type of enclosing object/class whatever
getDeclaredName() //returns the name of the property in the enclosing type
getValidator() //returns the validator specified when declaring/constructing the property
set(ReferenceOfSameTypeAsEnclosingClass obj, TypeOfProperty value) //sets value of this property in obj
get(ReferenceOfSameTypeAsEnclosingClass obj) //returns value of the porperty in obj
 
 
conceptual idea: (written in semi-pseudo, semi-java, semi-scala)
 
class Foo
{
     property name: (String, RegexValidator("^blah~") )
}
 
def main(Array[Foo] foos, Array[Property[Foo]] fooProps)
{
   for all foo in foos
        for all fooProp in fooProps
            print fooProp.get(foo)
}
 
Looks a bit sticky when I look on the code, and it could probably be cleaned up alot.
 
Perhaps foo.fooProp would be the same as foo.name (if they are indeed the same property).
 
foo.fooProp could be compiled to fooProp.get(foo) / fooProp.setFoo(foo,value) depending on usage.
 
 
Also, validators and types are kinda redundant.
The calidator itself must be aware of the type it validates, and so it would be unnessescary to declare the property with: "property name : (String,Regex...)" and perhaps "property name : Regex("^blah~")"
 
where the type of Regex would be scala.String.
 
 
 
 
Hmmm... do I make any sense?
 
 
Best regards
/Viktor Klang


On 6/30/07, Daniel Dekany <ddekany <at> freemail.hu> wrote:
Saturday, June 30, 2007, 3:26:27 PM, Erik Engbrecht wrote:

> Bill,
> Ok, since I introduced the term "first-class properties," I'll take
> the first crack at providing a concise definition:
>
> 1. Properties are objects (OO sense, not necessarily Scala object
> declaration sense) that govern access to a (possibly calculated)
> field. This means properties can have other methods in addition to
> get/set logic, such as registering event listeners.

I'm newbie here at Scala, thus it can happen easily that I miss
something obvious, but still... I wonder what's if instead of val-s
and var-s and methods without argument list (for me that last feels
like a dirty hack) we only had properties. Which then should be Java
bean properties as well -- the Java world use this property concept a
lot, so it would be nice. Wouldn't that be a cleaner concept? Even if
in big part it is only the question of what name we give to things.

BTW, I do realize that when I have var-s and val-s in a class that
will generate setter/getter methods in the resulting Java class. I'm
not sure how much is it just an implementation detail, but even if it
is not just that, they are still not Java bean property
setters/getters. They signatures are not like that.

> and also the "def" syntax, which doesn't group everything into a single structural entity:
> private var _name: String = "John Doe"
> def name = _name
> def name_=(v: String): Unit = _name = v

(Is this something that should work with the current official release,
2.5.1? Not very elegant BTW...)

--
Best regards,
Daniel Dekany


Daniel Dekany | 2 Jul 2007 14:17
Picon
Favicon

Re: First Class Properties (Was: Partial Classes)

Let me clarify a bit. What *I* tried to say -- which is maybe not what
Erik Engbrecht had in mind -- was about defining Bean properties in
Scala. The most important thing from my point of view was not
validation and whatever meta-info, but that Java stuff sees these
fictional Scala properties as Java Bean properties, rather than as
getter/setter methods with non-standard signatures or as fields.

The first question is if it would be a good idea to introduce a
special notation to define properties in classes. If it would be
useful enough. Like, in the simplest case:

  class Foo {
     prop foo = 0: Int
  }

which in the case of the Java platform generates something like this
behind the scenes:

  public class Foo {
    private int prop$foo;
    public int getFoo() {return prop$foo;}
    public void setFoo(int v) {prop$foo = v;}
  }

saving you from tedious work. (Why the Java language has still no such
feature? Now really, it's so silly.)

Also of course it would be possible to create more sophisticated
property definitions, like making a property read-only (like a val),
directly specifying the getter/setter functions and so on.

So, first it should be decided if such kind of feature is desirable. I
believe that at least if we think about Scala on Java platform, it
would be very useful. Then, if it is desirable and it was find out how
it should look, I think you will find that var/val members in classes
become a needless, because properties can do the the same and more.
That's why I brought up the idea that maybe var-s/val-s as class
members (i.e. I didn't mean inside methods/functions) should gone and
instead a class could only have properties as members (and methods,
types, etc of course).

But if this property feature becomes so heavyweight that using prop
instead of var/val means an overhead, that will prevent the removal of
var-s/val-s from classes, creating a much less clean situation. So
such overhead should be avoided in my approach to the topic.

-- 
Best regards,
 Daniel Dekany

 
Monday, July 2, 2007, 12:53:05 PM, Viktor Klang wrote:

> Hello everybody,
>   
>  I've been lurking the mailinglist for about a week now and altough
> I have minimal experience using Scala I have 5+ years of Java-experience.
>   
>  Back on topic.
>   
>  I have some ideas concerning first class properties.
>   
>  What I'd like to be able to do for each property:
>   
>  declare a type
>  declare a validator for that type
>   
>  I would also like to be able to get further information of the property:
>   
>  getType() //Returns the type of the property
>  getEnclosingType() // returns type of enclosing object/class whatever
>  getDeclaredName() //returns the name of the property in the enclosing type
>  getValidator() //returns the validator specified when
> declaring/constructing the property
>  set(ReferenceOfSameTypeAsEnclosingClass obj, TypeOfProperty value)
> //sets value of this property in obj
>  get(ReferenceOfSameTypeAsEnclosingClass obj) //returns value of the porperty in obj
>   
>   
>  conceptual idea: (written in semi-pseudo, semi-java, semi-scala)
>   
>  class Foo
>  {
>       property name: (String, RegexValidator("^blah~") )
>  }
>   
>  def main(Array[Foo] foos, Array[Property[Foo]] fooProps)
>  {
>     for all foo in foos
>          for all fooProp in fooProps
>              print fooProp.get(foo)
>  }
>   
>  Looks a bit sticky when I look on the code, and it could probably be cleaned up alot.
>   
>  Perhaps foo.fooProp would be the same as foo.name (if they are indeed the same property).
>   
>  foo.fooProp could be compiled to fooProp.get(foo) /
> fooProp.setFoo(foo,value) depending on usage.
>   
>   
>  Also, validators and types are kinda redundant.
>  The calidator itself must be aware of the type it validates, and
> so it would be unnessescary to declare the property with: "property
> name : (String,Regex...)" and perhaps "property name : Regex("^blah~")"
>   
>  where the type of Regex would be scala.String.
>   
>   
>   
>   
>  Hmmm... do I make any sense?
>   
>   
>  Best regards
>  /Viktor Klang
>
>
>  On 6/30/07, Daniel Dekany <ddekany <at> freemail.hu> wrote: 
> Saturday, June 30, 2007, 3:26:27 PM, Erik Engbrecht wrote:
>
>> Bill,
>> Ok, since I introduced the term "first-class properties," I'll take 
>> the first crack at providing a concise definition:
>>
>> 1. Properties are objects (OO sense, not necessarily Scala object
>> declaration sense) that govern access to a (possibly calculated)
>> field. This means properties can have other methods in addition to 
>> get/set logic, such as registering event listeners.
>
> I'm newbie here at Scala, thus it can happen easily that I miss
> something obvious, but still... I wonder what's if instead of val-s
> and var-s and methods without argument list (for me that last feels 
> like a dirty hack) we only had properties. Which then should be Java
> bean properties as well -- the Java world use this property concept a
> lot, so it would be nice. Wouldn't that be a cleaner concept? Even if 
> in big part it is only the question of what name we give to things.
>
> BTW, I do realize that when I have var-s and val-s in a class that
> will generate setter/getter methods in the resulting Java class. I'm 
> not sure how much is it just an implementation detail, but even if it
> is not just that, they are still not Java bean property
> setters/getters. They signatures are not like that.
>
>> and also the "def" syntax, which doesn't group everything into a single structural entity: 
>> private var _name: String = "John Doe"
>> def name = _name
>> def name_=(v: String): Unit = _name = v
>
> (Is this something that should work with the current official release,
> 2.5.1? Not very elegant BTW...) 
>
> --
> Best regards,
> Daniel Dekany

Daniel Dekany | 2 Jul 2007 14:22
Picon
Favicon

Re: First Class Properties (Was: Partial Classes)

Monday, July 2, 2007, 2:17:52 PM, Daniel Dekany wrote:

[snip]
>   class Foo {
>      prop foo = 0: Int
[snip]

Ops... of course I meant:

  prop foo: Int = 0

--

-- 
Best regards,
 Daniel Dekany

Gábor Bakos | 2 Jul 2007 14:40
Picon

Re: First Class Properties (Was: Partial Classes)

Daniel Dekany <ddekany <at> freemail.hu> writes:
[snip]
> The first question is if it would be a good idea to introduce a
> special notation to define properties in classes. If it would be
> useful enough. Like, in the simplest case:

I think you want something like this:
http://www.scala-lang.org/docu/files/api/scala/reflect/BeanProperty.html

>   class Foo {
        <at> BeanProperty
>      prop foo = 0: Int
>   }
> 
> which in the case of the Java platform generates something like this
> behind the scenes:
> 
>   public class Foo {
>     private int prop$foo;
>     public int getFoo() {return prop$foo;}
>     public void setFoo(int v) {prop$foo = v;}
>   }
> 
> saving you from tedious work. (Why the Java language has still no such
> feature? Now really, it's so silly.)
[snip]
The Java languages designers I think are working on it.
Best regards, g


Gmane