groovy

Parsing quoted method name fails if there is no modifier

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.5.2
  • Component/s: None
  • Labels:
    None
  • Environment:
    Ubuntu 6.06 LTS Dapper Drake, JDK 1.5.0_05, Groovy Revision 3983
  • Number of attachments :
    0

Description

The script:

class stringMethodName {
Integer 'flob' ( ) {
}
}

fails with the message:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, stringMethodName.groovy: 2: unexpected token: Integer @ line 2, column 3.
Integer 'flob' ( ) {
^

1 error

If any combination of modifiers is put before the Integer, for example:

class stringMethodName {
public Integer 'flob' ( ) {
}
}

then compilation is successful.

Activity

Hide
Andres Almiray added a comment -

The following blow too

class StringMethodName {
  Integer 'flob'() {}
  def 'foo'() {} // blows
  private boolean 'fooBoolean'() { false }
  public int 'fooInt'() { 1 }
  public def 'fooDef'() {}
}

Seems like quoted method names only work for those methods that
a) have an access modifier
b) return a non-primitive, non-def value

Show
Andres Almiray added a comment - The following blow too
class StringMethodName {
  Integer 'flob'() {}
  def 'foo'() {} // blows
  private boolean 'fooBoolean'() { false }
  public int 'fooInt'() { 1 }
  public def 'fooDef'() {}
}
Seems like quoted method names only work for those methods that a) have an access modifier b) return a non-primitive, non-def value
Hide
Paul King added a comment -

Groovy should behave more consistently across these cases now - just be warned that you can still only have legal Java identifier names between the quotes.

It would be interesting to have a way of handling method name mangling, e.g. so 'my method' went to 'my$method' or '$$my$space$method' in the Java bytecode.

Show
Paul King added a comment - Groovy should behave more consistently across these cases now - just be warned that you can still only have legal Java identifier names between the quotes. It would be interesting to have a way of handling method name mangling, e.g. so 'my method' went to 'my$method' or '$$my$space$method' in the Java bytecode.
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 (0)

Dates

  • Created:
    Updated:
    Resolved: