Log Message
Start QDOX-240: support enum + method invocation
Modified Paths
- trunk/qdox/src/grammar/parser.y
- trunk/qdox/src/main/java/com/thoughtworks/qdox/builder/impl/DefaultJavaAnnotationAssembler.java
- trunk/qdox/src/main/java/com/thoughtworks/qdox/builder/impl/EvaluatingVisitor.java
- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/_expression_/ExpressionVisitor.java
- trunk/qdox/src/main/java/com/thoughtworks/qdox/parser/_expression_/ElemValueTransformer.java
- trunk/qdox/src/test/java/com/thoughtworks/qdox/EnumsTest.java
Added Paths
Diff
Modified: trunk/qdox/src/grammar/parser.y (1491 => 1492)
--- trunk/qdox/src/grammar/parser.y 2012-03-15 22:40:09 UTC (rev 1491)
+++ trunk/qdox/src/grammar/parser.y 2012-04-16 19:41:37 UTC (rev 1492)
@@ -60,9 +60,9 @@
%type <annoval> _expression_ Literal Annotation ElementValue ElementValueArrayInitializer
%type <annoval> ConditionalExpression ConditionalOrExpression ConditionalAndExpression InclusiveOrExpression ExclusiveOrExpression AndExpression
%type <annoval> EqualityExpression RelationalExpression ShiftExpression AdditiveExpression MultiplicativeExpression
-%type <annoval> UnaryExpression UnaryExpressionNotPlusMinus primary
+%type <annoval> UnaryExpression UnaryExpressionNotPlusMinus primary MethodInvocation
%type <annoval> PostfixExpression CastExpression Assignment LeftHandSide AssignmentExpression
-%type <ival> dims Dims_opt
+%type <ival> Dims Dims_opt
%type <sval> AnyName TypeDeclSpecifier memberend AssignmentOperator
%type <type> Type ReferenceType VariableDeclaratorId ClassOrInterfaceType ActualTypeArgument
@@ -314,37 +314,7 @@
// PackageName | TypeName | ExpressionName | MethodName | PackageOrTypeName | AmbiguousName
AnyName: IDENTIFIER { $$ = $1; }
| AnyName DOT IDENTIFIER { $$ = $1 + '.' + $3; };
-
-
-// 15.8 Primary Expressions
-//Primary: PrimaryNoNewArray
-// | ArrayCreationExpression;
-
-//PrimaryNoNewArray: Literal
-// | Type DOT CLASS
-// | VOID DOT CLASS
-// | THIS
-// ClassName.this
-// ( _expression_ )
-// ClassInstanceCreationExpression
-// FieldAccess
-// MethodInvocation
-// ArrayAccess
-
-primary:
- Literal |
- PARENOPEN _expression_ PARENCLOSE { $$ = new ParenExpressionDef($2); } |
- PrimitiveType Dims_opt DOT CLASS { $$ = new TypeRefDef(new TypeDef($1.getName(), $2)); } |
- AnyName DOT CLASS { $$ = new TypeRefDef(new TypeDef($1, 0)); } |
- AnyName dims DOT CLASS { $$ = new TypeRefDef(new TypeDef($1, $2)); } |
- AnyName { $$ = new FieldRefDef($1); };
-Dims_opt: { $$ = 0; }
- | dims;
-dims:
- SQUAREOPEN SQUARECLOSE { $$ = 1; } |
- dims SQUAREOPEN SQUARECLOSE { $$ = $1 + 1; };
-
// 8 Classes
// 8.1.1 ClassModifier: Annotation public protected private abstract static final strictfp
@@ -715,6 +685,48 @@
ElementValue: ConditionalExpression
| Annotation
| ElementValueArrayInitializer;
+
+// 15.8 Primary Expressions
+//Primary: PrimaryNoNewArray
+// | ArrayCreationExpression;
+
+//PrimaryNoNewArray: Literal
+// | Type DOT CLASS
+// | VOID DOT CLASS
+// | THIS
+// ClassName.this
+// ( _expression_ )
+// ClassInstanceCreationExpression
+// FieldAccess
+// MethodInvocation
+// ArrayAccess
+
+primary: Literal
+ | PARENOPEN _expression_ PARENCLOSE
+ {
+ $$ = new ParenExpressionDef($2);
+ }
+ | PrimitiveType Dims_opt DOT CLASS
+ {
+ $$ = new TypeRefDef(new TypeDef($1.getName(), $2));
+ }
+ | AnyName DOT CLASS
+ {
+ $$ = new TypeRefDef(new TypeDef($1, 0));
+ }
+ | AnyName Dims DOT CLASS
+ {
+ $$ = new TypeRefDef(new TypeDef($1, $2));
+ }
+ | AnyName
+ {
+ $$ = new FieldRefDef($1);
+ }
+ | MethodInvocation
+ {
+ $$ = $1;
+ };
+
// 15.9 Class Instance Creation Expressions
ArgumentList_opt:
@@ -726,7 +738,31 @@
}
| ArgumentList COMMA _expression_;
+// 15.10 Array Creation Expressions
+Dims_opt: {
+ $$ = 0;
+ }
+ | Dims;
+Dims: SQUAREOPEN SQUARECLOSE
+ {
+ $$ = 1;
+ }
+ | Dims SQUAREOPEN SQUARECLOSE
+ {
+ $$ = $1 + 1;
+ };
+
+// 15.12 Method Invocation Expressions
+MethodInvocation: IDENTIFIER PARENOPEN ArgumentList_opt PARENCLOSE
+ {
+ $$ = new MethodInvocationDef($1, null);
+ }
+ | AnyName DOT TypeParameters_opt IDENTIFIER PARENOPEN ArgumentList_opt PARENCLOSE
+ {
+ $$ = new MethodInvocationDef($1, null);
+ };
+
// 15.14 Postfix Expressions
PostfixExpression: /* ExpressionName | */
primary
@@ -748,7 +784,7 @@
// 15.16 Cast Expressions
CastExpression: PARENOPEN PrimitiveType Dims_opt PARENCLOSE UnaryExpression { $$ = new CastDef(new TypeDef($2.getName(), $3), $5); }
| PARENOPEN AnyName PARENCLOSE UnaryExpressionNotPlusMinus { $$ = new CastDef(new TypeDef($2, 0), $4); }
- | PARENOPEN AnyName dims PARENCLOSE UnaryExpressionNotPlusMinus { $$ = new CastDef(new TypeDef($2, $3), $5); };
+ | PARENOPEN AnyName Dims PARENCLOSE UnaryExpressionNotPlusMinus { $$ = new CastDef(new TypeDef($2, $3), $5); };
// 15.17 Multiplicative Operators
MultiplicativeExpression: UnaryExpression
Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/builder/impl/DefaultJavaAnnotationAssembler.java (1491 => 1492)
--- trunk/qdox/src/main/java/com/thoughtworks/qdox/builder/impl/DefaultJavaAnnotationAssembler.java 2012-03-15 22:40:09 UTC (rev 1491)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/builder/impl/DefaultJavaAnnotationAssembler.java 2012-04-16 19:41:37 UTC (rev 1492)
@@ -85,6 +85,7 @@
import com.thoughtworks.qdox.parser._expression_.LogicalAndDef;
import com.thoughtworks.qdox.parser._expression_.LogicalNotDef;
import com.thoughtworks.qdox.parser._expression_.LogicalOrDef;
+import com.thoughtworks.qdox.parser._expression_.MethodInvocationDef;
import com.thoughtworks.qdox.parser._expression_.MinusSignDef;
import com.thoughtworks.qdox.parser._expression_.MultiplyDef;
import com.thoughtworks.qdox.parser._expression_.NotDef;
@@ -445,4 +446,9 @@
{
return new PostDecrement( postDecrementDef.getElemValueDef().transform( this ) );
}
+
+ public AnnotationValue transform( MethodInvocationDef methodInvocationDef )
+ {
+ return null;
+ }
}
\ No newline at end of file
Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/builder/impl/EvaluatingVisitor.java (1491 => 1492)
--- trunk/qdox/src/main/java/com/thoughtworks/qdox/builder/impl/EvaluatingVisitor.java 2012-03-15 22:40:09 UTC (rev 1491)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/builder/impl/EvaluatingVisitor.java 2012-04-16 19:41:37 UTC (rev 1492)
@@ -46,6 +46,7 @@
import com.thoughtworks.qdox.model._expression_.LogicalAnd;
import com.thoughtworks.qdox.model._expression_.LogicalNot;
import com.thoughtworks.qdox.model._expression_.LogicalOr;
+import com.thoughtworks.qdox.model._expression_.MethodInvocation;
import com.thoughtworks.qdox.model._expression_.MinusSign;
import com.thoughtworks.qdox.model._expression_.Multiply;
import com.thoughtworks.qdox.model._expression_.Not;
@@ -977,4 +978,9 @@
{
throw new IllegalArgumentException( "Cannot evaluate '" + assignment + "'." );
}
+
+ public Object visit( MethodInvocation methodInvocation )
+ {
+ throw new IllegalArgumentException( "Cannot evaluate '" + methodInvocation + "'." );
+ }
}
\ No newline at end of file
Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/_expression_/ExpressionVisitor.java (1491 => 1492)
--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/_expression_/ExpressionVisitor.java 2012-03-15 22:40:09 UTC (rev 1491)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/_expression_/ExpressionVisitor.java 2012-04-16 19:41:37 UTC (rev 1492)
@@ -100,4 +100,6 @@
Object visit( Assignment assignment );
+ Object visit( MethodInvocation methodInvocation );
+
}
\ No newline at end of file
Added: trunk/qdox/src/main/java/com/thoughtworks/qdox/model/_expression_/MethodInvocation.java (0 => 1492)
--- trunk/qdox/src/main/java/com/thoughtworks/qdox/model/_expression_/MethodInvocation.java (rev 0)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/model/_expression_/MethodInvocation.java 2012-04-16 19:41:37 UTC (rev 1492)
@@ -0,0 +1,54 @@
+package com.thoughtworks.qdox.model._expression_;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.List;
+
+public class MethodInvocation implements AnnotationValue
+{
+ private String methodName;
+ private List<AnnotationValue> arguments;
+
+ public MethodInvocation( String methodName, List<AnnotationValue> arguments )
+ {
+ this.methodName = methodName;
+ this.arguments = arguments;
+ }
+
+ public Object getParameterValue()
+ {
+ return null;
+ }
+
+ public String getMethodName()
+ {
+ return methodName;
+ }
+
+ public List<AnnotationValue> getArguments()
+ {
+ return arguments;
+ }
+
+ public Object accept( ExpressionVisitor visitor )
+ {
+ return visitor.visit( this );
+ }
+}
\ No newline at end of file
Modified: trunk/qdox/src/main/java/com/thoughtworks/qdox/parser/_expression_/ElemValueTransformer.java (1491 => 1492)
--- trunk/qdox/src/main/java/com/thoughtworks/qdox/parser/_expression_/ElemValueTransformer.java 2012-03-15 22:40:09 UTC (rev 1491)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/parser/_expression_/ElemValueTransformer.java 2012-04-16 19:41:37 UTC (rev 1492)
@@ -94,4 +94,6 @@
U transform( PreDecrementDef preDecrementDef );
U transform( PreIncrementDef preIncrementDef );
+
+ U transform( MethodInvocationDef methodInvocationDef );
}
\ No newline at end of file
Added: trunk/qdox/src/main/java/com/thoughtworks/qdox/parser/_expression_/MethodInvocationDef.java (0 => 1492)
--- trunk/qdox/src/main/java/com/thoughtworks/qdox/parser/_expression_/MethodInvocationDef.java (rev 0)
+++ trunk/qdox/src/main/java/com/thoughtworks/qdox/parser/_expression_/MethodInvocationDef.java 2012-04-16 19:41:37 UTC (rev 1492)
@@ -0,0 +1,50 @@
+package com.thoughtworks.qdox.parser._expression_;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.List;
+
+public class MethodInvocationDef extends ExpressionDef
+{
+ private String methodName;
+
+ private List<ExpressionDef> arguments;
+
+ public MethodInvocationDef( String methodName, List<ExpressionDef> arguments )
+ {
+ this.methodName = methodName;
+ this.arguments = arguments;
+ }
+
+ public String getMethodName()
+ {
+ return methodName;
+ }
+
+ public List<ExpressionDef> getArguments()
+ {
+ return arguments;
+ }
+
+ public <U> U transform( ElemValueTransformer<U> transformer )
+ {
+ return transformer.transform( this );
+ }
+}
\ No newline at end of file
Modified: trunk/qdox/src/test/java/com/thoughtworks/qdox/EnumsTest.java (1491 => 1492)
--- trunk/qdox/src/test/java/com/thoughtworks/qdox/EnumsTest.java 2012-03-15 22:40:09 UTC (rev 1491)
+++ trunk/qdox/src/test/java/com/thoughtworks/qdox/EnumsTest.java 2012-04-16 19:41:37 UTC (rev 1492)
@@ -177,4 +177,46 @@
new JavaProjectBuilder().addSource(new StringReader(source));
}
+
+ // QDOX-240
+ public void testObjectCreation()
+ {
+ String source="package simpleenum;\r\n" +
+ "\r\n" +
+ "import java.util.Date;\r\n" +
+ "\r\n" +
+ "public enum MinimalEnumExampleConstructor\r\n" +
+ "{\r\n" +
+ " D_CONSTRUCTOR(new Date()); // FAILS to be parsed\r\n" +
+ "\r\n" +
+ " private final Date date;\r\n" +
+ "\r\n" +
+ " private MinimalEnumExampleConstructor(final Date date)\r\n" +
+ " {\r\n" +
+ " this.date = date;\r\n" +
+ " }\r\n" +
+ "}";
+ }
+
+ // QDOX-240
+ public void testMethodInvocation()
+ {
+ String source="package simpleenum;\r\n" +
+ "import java.util.Date;\r\n" +
+ "public enum MinimalEnumExampleMethod\r\n" +
+ "{\r\n" +
+ " D_METHOD(create()); // FAILS to be parsed\r\n" +
+ " private final Date date;\r\n" +
+ " private MinimalEnumExampleMethod(final Date date)\r\n" +
+ " {\r\n" +
+ " this.date = date;\r\n" +
+ " }\r\n" +
+ " public static Date create()\r\n" +
+ " {\r\n" +
+ " return new Date();\r\n" +
+ " }\r\n" +
+ "}";
+ new JavaProjectBuilder().addSource(new StringReader(source));
+ }
+
}
To unsubscribe from this list please visit:
