groovy

'as' not allowed as namespace in embedding Groovy-code

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.0-JSR-6
  • Fix Version/s: 1.5.2
  • Component/s: parser
  • Labels:
    None
  • Environment:
    Java SDK 1.4.2
  • Number of attachments :
    0

Description

I accidently stumbled over the problem that I could not use Java classes packaged in namespace 'as'.

Example (Java-Code with embedded Groovy-script):

import as.AsTest;
public class TestAs
{
// different trials:
private static String groovyCode1 =
"import as.AsTest as a; " +
"return new AsTest(); ";

private static String groovyCode2 =
"import as.*; " +
"return new AsTest(); ";

private static String groovyCode3 =
"return new as.AsTest(); ";

private static String groovyCode4 =
"import as.AsTest; " +
"return new AsTest(); ";

public static void main(String[] args) { AsTest a = new AsTest(); // Ok GroovyShell shell = new GroovyShell(new Binding()); Object value = shell.evaluate(groovyCode3); // ..1-4 System.out.println(value); return; }
}

Error message is 'MultipleCompilationErrorsException'.

'as' is a reserved word in Groovy. Nevertheless I think 'as' should be allowed as namespace-name (as it is allowed in Java).

Activity

Hide
Guillaume Laforge added a comment -

"as" is a keyword, hence the errors you get.
Fortunately, there's a workaround in that you can quote 'as' where you need it, like in package names.
The following thing should work:

import 'as'.AsTest

I'm not closing the issue since we could possibly allow as as a semi-keyword the way we're allowing "it" to be allowed to in certain circumstances.

Show
Guillaume Laforge added a comment - "as" is a keyword, hence the errors you get. Fortunately, there's a workaround in that you can quote 'as' where you need it, like in package names. The following thing should work: import 'as'.AsTest I'm not closing the issue since we could possibly allow as as a semi-keyword the way we're allowing "it" to be allowed to in certain circumstances.
Hide
Travis Jensen added a comment -

The workaround doesn't work, and given that the most common package used in the library that I base my daily work around has an 'as' package, Groovy is no longer an option. Guess I'll head back to Jython.

Of interest, perhaps, are libraries having an 'as' package:

Vignette (that is my killer)
Xerces
JASS
JBoss

tj

Show
Travis Jensen added a comment - The workaround doesn't work, and given that the most common package used in the library that I base my daily work around has an 'as' package, Groovy is no longer an option. Guess I'll head back to Jython. Of interest, perhaps, are libraries having an 'as' package: Vignette (that is my killer) Xerces JASS JBoss tj
Hide
blackdrag blackdrag added a comment -

Travis, you mean something like:

import foo.'as'.bar.*

does not work?

Show
blackdrag blackdrag added a comment - Travis, you mean something like: import foo.'as'.bar.* does not work?
Hide
Andres Almiray added a comment -

Close it as "Not an Issue" then ?

Show
Andres Almiray added a comment - Close it as "Not an Issue" then ?
Hide
Peter Fürholz added a comment -

I just made some tests with different quoting variants - neither of them worked.
As far as I know, just using the absolute package name and quoting worked on a much earlier Groovy version. E.g. new foo.'as'.bar.Test();
That does not work anymore.

I did my latest tests using Groovy 1.1-rc-3.

As Travis mentioned earlier, it's not uncommon to have 'as' as package name. So it would be good to have viable solution for this problem.

Show
Peter Fürholz added a comment - I just made some tests with different quoting variants - neither of them worked. As far as I know, just using the absolute package name and quoting worked on a much earlier Groovy version. E.g. new foo.'as'.bar.Test(); That does not work anymore. I did my latest tests using Groovy 1.1-rc-3. As Travis mentioned earlier, it's not uncommon to have 'as' as package name. So it would be good to have viable solution for this problem.
Hide
Paul King added a comment -

patch applied - email sent to dev list - no tests yet

Show
Paul King added a comment - patch applied - email sent to dev list - no tests yet
Hide
Paul King added a comment -

Fixed for 'as', 'in' and 'def'.

Show
Paul King added a comment - Fixed for 'as', 'in' and 'def'.
Hide
Paul King added a comment -

close off release 1.5.4

Show
Paul King added a comment - close off release 1.5.4

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: