Compile error on valid Java code

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Compile error on valid Java code

Thomas Hofmann

Hi,

 

I just converted a Java class to Groovy and I got compile errors which I guess should not occur.

 

These are the relevant parts:

 

 

package a;

 

import java.util.Map;

import org.eclipse.core.runtime.preferences.IPreferenceFilter;

import org.eclipse.core.runtime.preferences.InstanceScope;

import org.eclipse.core.runtime.preferences.ConfigurationScope;

 

public class DefaultApplyConfigurationComponent  {

     

      private IPreferenceFilter getPreferenceFilter() {

            return new IPreferenceFilter() {

                  public Map<?,?> getMapping(String scope) {

                        return null;

                  }

                 

                  public String[] getScopes(){

                        return new String[]  { InstanceScope.SCOPE, ConfigurationScope.SCOPE

                        };

                  }

            };

      }

     

}

 

 

Problems are:

 

Description       Resource          Path     Location           Type

Groovy:unexpected token: , @ line 15, column 47.        DefaultApplyConfigurationComponent.groovy            /com.ibm.ecc.core/src/com/ibm/ecc/core/apply/internal line 15  Java Problem

 

Description       Resource          Path     Location           Type

Groovy:unexpected token: } @ line 19, column 2.          DefaultApplyConfigurationComponent.groovy            /com.ibm.ecc.core/src/com/ibm/ecc/core/apply/internal line 19  Java Problem

 

 

Regards,

 

Thomas

Reply | Threaded
Open this post in threaded view
|

RE: Compile error on valid Java code

Thomas Hofmann

Just to add more information. The line numbers don’t match because I removed some methods for the sample code posted before.

 

 

 

 

 


From: Thomas Hofmann
Sent: Dienstag, 18. Mai 2010 15:47
To: [hidden email]
Subject: Compile error on valid Java code

 

Hi,

 

I just converted a Java class to Groovy and I got compile errors which I guess should not occur.

 

These are the relevant parts:

 

 

package a;

 

import java.util.Map;

import org.eclipse.core.runtime.preferences.IPreferenceFilter;

import org.eclipse.core.runtime.preferences.InstanceScope;

import org.eclipse.core.runtime.preferences.ConfigurationScope;

 

public class DefaultApplyConfigurationComponent  {

     

      private IPreferenceFilter getPreferenceFilter() {

            return new IPreferenceFilter() {

                  public Map<?,?> getMapping(String scope) {

                        return null;

                  }

                 

                  public String[] getScopes(){

                        return new String[]  { InstanceScope.SCOPE, ConfigurationScope.SCOPE

                        };

                  }

            };

      }

     

}

 

 

Problems are:

 

Description       Resource          Path     Location           Type

Groovy:unexpected token: , @ line 15, column 47.        DefaultApplyConfigurationComponent.groovy            /com.ibm.ecc.core/src/com/ibm/ecc/core/apply/internal line 15  Java Problem

 

Description       Resource          Path     Location           Type

Groovy:unexpected token: } @ line 19, column 2.          DefaultApplyConfigurationComponent.groovy            /com.ibm.ecc.core/src/com/ibm/ecc/core/apply/internal line 19  Java Problem

 

 

Regards,

 

Thomas

Reply | Threaded
Open this post in threaded view
|

RE: Compile error on valid Java code

Andy Clement
I believe you are just hitting a 'difference' between java and groovy.  There are differences in syntax between the two languages, and array initializers is one of them.  Some of it is discussed here: http://webcache.googleusercontent.com/search?q=cache:http://groovy.codehaus.org/Differences%2Bfrom%2BJava

Your code doesn't build on the command line either - which is always my final check to confirm it is a groovyc issue rather than a groovy-eclipse issue.

You can change it to 

  String[] retval = [ InstanceScope.SCOPE, ConfigurationScope.SCOPE];
  return retval;


Andy

On 18 May 2010 06:50, Thomas Hofmann <[hidden email]> wrote:

Just to add more information. The line numbers don’t match because I removed some methods for the sample code posted before.

 

 

 

 

 


From: Thomas Hofmann
Sent: Dienstag, 18. Mai 2010 15:47
To: [hidden email]
Subject: Compile error on valid Java code

 

Hi,

 

I just converted a Java class to Groovy and I got compile errors which I guess should not occur.

 

These are the relevant parts:

 

 

package a;

 

import java.util.Map;

import org.eclipse.core.runtime.preferences.IPreferenceFilter;

import org.eclipse.core.runtime.preferences.InstanceScope;

import org.eclipse.core.runtime.preferences.ConfigurationScope;

 

public class DefaultApplyConfigurationComponent  {

     

      private IPreferenceFilter getPreferenceFilter() {

            return new IPreferenceFilter() {

                  public Map<?,?> getMapping(String scope) {

                        return null;

                  }

                 

                  public String[] getScopes(){

                        return new String[]  { InstanceScope.SCOPE, ConfigurationScope.SCOPE

                        };

                  }

            };

      }

     

}

 

 

Problems are:

 

Description       Resource          Path     Location           Type

Groovy:unexpected token: , @ line 15, column 47.        DefaultApplyConfigurationComponent.groovy            /com.ibm.ecc.core/src/com/ibm/ecc/core/apply/internal line 15  Java Problem

 

Description       Resource          Path     Location           Type

Groovy:unexpected token: } @ line 19, column 2.          DefaultApplyConfigurationComponent.groovy            /com.ibm.ecc.core/src/com/ibm/ecc/core/apply/internal line 19  Java Problem

 

 

Regards,

 

Thomas


Reply | Threaded
Open this post in threaded view
|

RE: Compile error on valid Java code

Thomas Hofmann

Thanks Andy,

 

I thought that I had read in a book that every valid Java program / file would also be a valid Groovy one. Probably that wasn’t so…

I am just beginning to actually make some use of Groovy.

 

Thomas

 


From: Andy Clement [mailto:[hidden email]]
Sent: Dienstag, 18. Mai 2010 17:41
To: [hidden email]
Subject: Re: [groovy-eclipse-plugin-user] RE: Compile error on valid Java code

 

I believe you are just hitting a 'difference' between java and groovy.  There are differences in syntax between the two languages, and array initializers is one of them.  Some of it is discussed here: http://webcache.googleusercontent.com/search?q=cache:http://groovy.codehaus.org/Differences%2Bfrom%2BJava

 

Your code doesn't build on the command line either - which is always my final check to confirm it is a groovyc issue rather than a groovy-eclipse issue.

 

You can change it to 

 

  String[] retval = [ InstanceScope.SCOPE, ConfigurationScope.SCOPE];

  return retval;

 

 

Andy

On 18 May 2010 06:50, Thomas Hofmann <[hidden email]> wrote:

Just to add more information. The line numbers don’t match because I removed some methods for the sample code posted before.

 

 

 

 

 


From: Thomas Hofmann
Sent: Dienstag, 18. Mai 2010 15:47
To: [hidden email]
Subject: Compile error on valid Java code

 

Hi,

 

I just converted a Java class to Groovy and I got compile errors which I guess should not occur.

 

These are the relevant parts:

 

 

package a;

 

import java.util.Map;

import org.eclipse.core.runtime.preferences.IPreferenceFilter;

import org.eclipse.core.runtime.preferences.InstanceScope;

import org.eclipse.core.runtime.preferences.ConfigurationScope;

 

public class DefaultApplyConfigurationComponent  {

     

      private IPreferenceFilter getPreferenceFilter() {

            return new IPreferenceFilter() {

                  public Map<?,?> getMapping(String scope) {

                        return null;

                  }

                 

                  public String[] getScopes(){

                        return new String[]  { InstanceScope.SCOPE, ConfigurationScope.SCOPE

                        };

                  }

            };

      }

     

}

 

 

Problems are:

 

Description       Resource          Path     Location           Type

Groovy:unexpected token: , @ line 15, column 47.        DefaultApplyConfigurationComponent.groovy            /com.ibm.ecc.core/src/com/ibm/ecc/core/apply/internal line 15  Java Problem

 

Description       Resource          Path     Location           Type

Groovy:unexpected token: } @ line 19, column 2.          DefaultApplyConfigurationComponent.groovy            /com.ibm.ecc.core/src/com/ibm/ecc/core/apply/internal line 19  Java Problem

 

 

Regards,

 

Thomas

 

Reply | Threaded
Open this post in threaded view
|

Re: Compile error on valid Java code

Peter Niederwieser
Administrator
In reply to this post by Thomas Hofmann
(Reposting because my first post didn't seem to get through)

Most valid Java code is also valid Groovy code, but it's not 100%. The concrete problem with your code is that Groovy doesn't have array literals. Instead, you use a (Groovy) list literal and coerce it to an array:

[InstanceScope.SCOPE, ConfigurationScope.SCOPE] as String[]

Essentially, this is also what Andy's solution does.

Cheers,
Peter
Reply | Threaded
Open this post in threaded view
|

Re: Compile error on valid Java code

Thomas Hofmann
Thanks, that is what I tried also.

-----Original Message-----
From: Peter Niederwieser [mailto:[hidden email]]
Sent: Donnerstag, 20. Mai 2010 10:33
To: [hidden email]
Subject: [groovy-eclipse-plugin-user] Re: Compile error on valid Java code


(Reposting because my first post didn't seem to get through)

Most valid Java code is also valid Groovy code, but it's not 100%. The concrete problem with your code is that Groovy doesn't have array literals.
Instead, you use a (Groovy) list literal and coerce it to an array:

[InstanceScope.SCOPE, ConfigurationScope.SCOPE] as String[]

Essentially, this is also what Andy's solution does.

Cheers,
Peter
--
View this message in context: http://groovy-eclipse-plugin.42567.n3.nabble.com/Compile-error-on-valid-Java-code-tp826293p831262.html
Sent from the groovy-eclipse-plugin-user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email