Issue Details (XML | Word | Printable)

Key: GROOVY-1560
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Paul King
Reporter: Peter Fürholz
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
groovy

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

Created: 20/Nov/06 08:58 AM   Updated: 08/Feb/08 01:26 AM
Component/s: parser
Affects Version/s: 1.0-JSR-6
Fix Version/s: 1.5.2

Time Tracking:
Not Specified

Environment: Java SDK 1.4.2


 Description  « Hide
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).



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Guillaume Laforge added a comment - 01/Dec/06 07:23 AM
"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.


Travis Jensen added a comment - 19/Mar/07 03:06 AM
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


Jochen Theodorou added a comment - 19/Mar/07 04:40 AM
Travis, you mean something like:

import foo.'as'.bar.*

does not work?


Andres Almiray added a comment - 30/Nov/07 12:40 AM
Close it as "Not an Issue" then ?

Peter Fürholz added a comment - 03/Dec/07 04:06 PM
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.


Paul King added a comment - 01/Jan/08 03:10 AM
patch applied - email sent to dev list - no tests yet

Paul King added a comment - 02/Jan/08 03:48 AM
Fixed for 'as', 'in' and 'def'.

Paul King added a comment - 08/Feb/08 01:26 AM
close off release 1.5.4