Skip to content

Commit

Permalink
Support the optional path operator (?.), which is the replacement
Browse files Browse the repository at this point in the history
of the optional path operator (->) used in Classic Groovy.
For an example,

  class Person {
      String name
      int age
  }

  Person x = new Person(name:"Foo", age:25)
  assert x.name == "Foo"
  assert x?.name == "Foo"

  x = null
  assert x?.name == null
  // assert x->name == null  for the case of Classic Groovy


git-svn-id: http://svn.codehaus.org/groovy/trunk/groovy/groovy-core@1974 a5544e8c-8a19-0410-ba12-f9af4593a198
  • Loading branch information
Pilho Kim committed Mar 14, 2005
1 parent 5a8268a commit f223c9b
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,6 @@ protected Expression expressionSwitch(AST node) {
return ternaryExpression(node);

case OPTIONAL_ARG:
return binaryExpression(Types.NAVIGATE, node);

case DOT:
return dotExpression(node);

Expand Down Expand Up @@ -1292,7 +1290,7 @@ protected Expression dotExpression(AST node) {
return new AttributeExpression(leftExpression, field);
}
String property = identifier(identifierNode);
return new PropertyExpression(leftExpression, property);
return new PropertyExpression(leftExpression, property, node.getType()==OPTIONAL_ARG);
}
}
return methodCallExpression(node);
Expand Down

0 comments on commit f223c9b

Please sign in to comment.