### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.core
Index: model/org/eclipse/jdt/core/IMemberValuePair.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IMemberValuePair.java,v
retrieving revision 1.6
diff -u -r1.6 IMemberValuePair.java
--- model/org/eclipse/jdt/core/IMemberValuePair.java 27 Jun 2008 16:04:01 -0000 1.6
+++ model/org/eclipse/jdt/core/IMemberValuePair.java 10 Nov 2009 08:32:29 -0000
@@ -125,7 +125,7 @@
* analyzed to determine its kind. For example, in @MyAnnot({3.4, 1 + 2.3})
,
* the kind of the second element "1 + 2.3" is unknown.
*
@MyAnnot(1, 2.3, "abc")
@MyAnnot({1, 2.3, "abc"})
*
* If the value kind is unknown, the returned value is always either null
, or an
* array containing {@link Object}s and/or null
s for unknown elements.
Index: model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java,v
retrieving revision 1.85
diff -u -r1.85 CompilationUnitStructureRequestor.java
--- model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java 7 Mar 2009 00:58:56 -0000 1.85
+++ model/org/eclipse/jdt/internal/core/CompilationUnitStructureRequestor.java 10 Nov 2009 08:32:30 -0000
@@ -29,15 +29,17 @@
import org.eclipse.jdt.internal.compiler.ast.Literal;
import org.eclipse.jdt.internal.compiler.ast.MemberValuePair;
import org.eclipse.jdt.internal.compiler.ast.NullLiteral;
+import org.eclipse.jdt.internal.compiler.ast.OperatorIds;
import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference;
import org.eclipse.jdt.internal.compiler.ast.SingleNameReference;
+import org.eclipse.jdt.internal.compiler.ast.UnaryExpression;
import org.eclipse.jdt.internal.compiler.parser.Parser;
import org.eclipse.jdt.internal.compiler.parser.RecoveryScanner;
import org.eclipse.jdt.internal.compiler.util.HashtableOfObject;
import org.eclipse.jdt.internal.compiler.util.HashtableOfObjectToInt;
import org.eclipse.jdt.internal.core.util.ReferenceInfoAdapter;
import org.eclipse.jdt.internal.core.util.Util;
-
+import org.eclipse.jdt.internal.compiler.ast.ASTNode;
/**
* A requestor for the fuzzy parser, used to compute the children of an ICompilationUnit.
*/
@@ -719,7 +721,19 @@
if (memberValuePair.valueKind == -1)
memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
return values;
+ } else if (expression instanceof UnaryExpression) { // to deal with negative numerals (see bug - 248312)
+ UnaryExpression unaryExpression = (UnaryExpression) expression;
+ if ((unaryExpression.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT == OperatorIds.MINUS) {
+ if (unaryExpression.expression instanceof Literal) {
+ Literal subExpression = (Literal) unaryExpression.expression;
+ subExpression.computeConstant();
+ return Util.getNegativeAnnotationMemberValue(memberValuePair, subExpression.constant);
+ }
+ }
+ memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
+ return null;
} else {
+ memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
return null;
}
}
Index: model/org/eclipse/jdt/internal/core/LocalVariable.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/LocalVariable.java,v
retrieving revision 1.29
diff -u -r1.29 LocalVariable.java
--- model/org/eclipse/jdt/internal/core/LocalVariable.java 21 Aug 2008 10:15:27 -0000 1.29
+++ model/org/eclipse/jdt/internal/core/LocalVariable.java 10 Nov 2009 08:32:30 -0000
@@ -17,13 +17,16 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.*;
import org.eclipse.jdt.core.compiler.CharOperation;
+import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.ArrayInitializer;
import org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess;
import org.eclipse.jdt.internal.compiler.ast.Expression;
import org.eclipse.jdt.internal.compiler.ast.Literal;
import org.eclipse.jdt.internal.compiler.ast.NullLiteral;
+import org.eclipse.jdt.internal.compiler.ast.OperatorIds;
import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference;
import org.eclipse.jdt.internal.compiler.ast.SingleNameReference;
+import org.eclipse.jdt.internal.compiler.ast.UnaryExpression;
import org.eclipse.jdt.internal.compiler.parser.RecoveryScanner;
import org.eclipse.jdt.internal.core.util.MementoTokenizer;
import org.eclipse.jdt.internal.core.util.Util;
@@ -198,6 +201,17 @@
if (memberValuePair.valueKind == -1)
memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
return values;
+ } else if (expression instanceof UnaryExpression) { //to deal with negative numerals (see bug - 248312)
+ UnaryExpression unaryExpression = (UnaryExpression) expression;
+ if ((unaryExpression.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT == OperatorIds.MINUS) {
+ if (unaryExpression.expression instanceof Literal) {
+ Literal subExpression = (Literal) unaryExpression.expression;
+ subExpression.computeConstant();
+ return Util.getNegativeAnnotationMemberValue(memberValuePair, subExpression.constant);
+ }
+ }
+ memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
+ return null;
} else {
memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
return null;
Index: model/org/eclipse/jdt/internal/core/util/Util.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Util.java,v
retrieving revision 1.136
diff -u -r1.136 Util.java
--- model/org/eclipse/jdt/internal/core/util/Util.java 26 Oct 2009 17:20:02 -0000 1.136
+++ model/org/eclipse/jdt/internal/core/util/Util.java 10 Nov 2009 08:32:31 -0000
@@ -3160,6 +3160,34 @@
return null;
}
}
+
+ /*
+ * Creates a member value from the given constant in case of negative numerals,
+ * and sets the valueKind on the given memberValuePair
+ */
+ public static Object getNegativeAnnotationMemberValue(MemberValuePair memberValuePair, Constant constant) {
+ if (constant == null) {
+ memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
+ return null;
+ }
+ switch (constant.typeID()) {
+ case TypeIds.T_int :
+ memberValuePair.valueKind = IMemberValuePair.K_INT;
+ return new Integer(constant.intValue() * -1);
+ case TypeIds.T_float :
+ memberValuePair.valueKind = IMemberValuePair.K_FLOAT;
+ return new Float(constant.floatValue() * -1.0f);
+ case TypeIds.T_double :
+ memberValuePair.valueKind = IMemberValuePair.K_DOUBLE;
+ return new Double(constant.doubleValue() * -1.0);
+ case TypeIds.T_long :
+ memberValuePair.valueKind = IMemberValuePair.K_LONG;
+ return new Long(constant.longValue() * -1L);
+ default:
+ memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN;
+ return null;
+ }
+ }
/**
* Split signatures of all levels from a type unique key.
*
#P org.eclipse.jdt.core.tests.model
Index: src/org/eclipse/jdt/core/tests/model/ClassFileTests.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClassFileTests.java,v
retrieving revision 1.47
diff -u -r1.47 ClassFileTests.java
--- src/org/eclipse/jdt/core/tests/model/ClassFileTests.java 13 Aug 2009 01:22:32 -0000 1.47
+++ src/org/eclipse/jdt/core/tests/model/ClassFileTests.java 10 Nov 2009 08:32:35 -0000
@@ -124,6 +124,14 @@
" void foo12() {}\n" +
" @MyAnnot(_array={1, 2, 3})\n" +
" void foo13() {}\n" +
+ " @MyAnnot(_neg_int = -2)\n" +
+ " void foo14() {}\n" +
+ " @MyAnnot(_neg_float=-2.0f)\n" +
+ " void foo15() {}\n" +
+ " @MyAnnot(_neg_double=-2.0)\n" +
+ " void foo16() {}\n" +
+ " @MyAnnot(_neg_long=-2L)\n" +
+ " void foo17() {}\n" +
"}\n" +
"@interface MyAnnot {\n" +
" int _int() default 0;\n" +
@@ -139,6 +147,10 @@
" Class _class() default Object.class;\n" +
" MyEnum _enum() default MyEnum.FIRST;\n" +
" int[] _array() default {};\n" +
+ " int _neg_int() default -1;\n" +
+ " float _neg_float() default -1.0f;\n" +
+ " double _neg_double() default -1.0;\n" +
+ " long _neg_long() default -1L;\n" +
"}\n" +
"@interface MyOtherAnnot {\n" +
"}\n" +
@@ -455,6 +467,54 @@
}
/*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=248312
+ * Ensures that an annotation with a negative int value is correct
+ */
+public void testAnnotations22() throws JavaModelException {
+ IType type = this.jarRoot.getPackageFragment("annotated").getClassFile("X.class").getType();
+ IMethod method = type.getMethod("foo14", new String[0]);
+ assertAnnotationsEqual(
+ "@annotated.MyAnnot(_neg_int=(int)-2)\n",
+ method.getAnnotations());
+}
+
+/*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=248312
+ * Ensures that an annotation with a negative float value is correct
+ */
+public void testAnnotations23() throws JavaModelException {
+ IType type = this.jarRoot.getPackageFragment("annotated").getClassFile("X.class").getType();
+ IMethod method = type.getMethod("foo15", new String[0]);
+ assertAnnotationsEqual(
+ "@annotated.MyAnnot(_neg_float=-2.0f)\n",
+ method.getAnnotations());
+}
+
+/*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=248312
+ * Ensures that an annotation with a negative double value is correct
+ */
+public void testAnnotations24() throws JavaModelException {
+ IType type = this.jarRoot.getPackageFragment("annotated").getClassFile("X.class").getType();
+ IMethod method = type.getMethod("foo16", new String[0]);
+ assertAnnotationsEqual(
+ "@annotated.MyAnnot(_neg_double=(double)-2.0)\n",
+ method.getAnnotations());
+}
+
+/*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=248312
+ * Ensures that an annotation with a negative long value is correct
+ */
+public void testAnnotations25() throws JavaModelException {
+ IType type = this.jarRoot.getPackageFragment("annotated").getClassFile("X.class").getType();
+ IMethod method = type.getMethod("foo17", new String[0]);
+ assertAnnotationsEqual(
+ "@annotated.MyAnnot(_neg_long=-2L)\n",
+ method.getAnnotations());
+}
+
+/*
* Ensures that no exception is thrown for a .class file name with a dot
* (regression test for bug 114140 assertion failed when opening a class file not not the classpath)
*/
Index: src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java,v
retrieving revision 1.69
diff -u -r1.69 CompilationUnitTests.java
--- src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java 28 Jan 2009 12:34:52 -0000 1.69
+++ src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java 10 Nov 2009 08:32:36 -0000
@@ -285,6 +285,115 @@
}
/*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=248312
+ * Ensures that the default value (a negative int) for an annotation method is correct.
+ */
+public void testDefaultValue7() throws CoreException {
+ try {
+ String cuSource =
+ "package p;\n" +
+ "public @interface Y {\n" +
+ " public int member() default -1;\n" +
+ "}";
+ createFile("/P/src/p/Y.java", cuSource);
+ IMethod method = getCompilationUnit("/P/src/p/Y.java").getType("Y").getMethod("member", new String[0]);
+ assertMemberValuePairEquals(
+ "member=(int)-1",
+ method.getDefaultValue());
+ } finally {
+ deleteFile("/P/src/p/Y.java");
+ }
+}
+
+/*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=248312
+ * Ensures that the default value (a negative float) for an annotation method is correct.
+ */
+public void testDefaultValue8() throws CoreException {
+ try {
+ String cuSource =
+ "package p;\n" +
+ "public @interface Y {\n" +
+ " public float member() default -1.0f;\n" +
+ "}";
+ createFile("/P/src/p/Y.java", cuSource);
+ IMethod method = getCompilationUnit("/P/src/p/Y.java").getType("Y").getMethod("member", new String[0]);
+ assertMemberValuePairEquals(
+ "member=-1.0f",
+ method.getDefaultValue());
+ } finally {
+ deleteFile("/P/src/p/Y.java");
+ }
+}
+
+/*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=248312
+ * Ensures that the default value (a negative double) for an annotation method is correct.
+ */
+public void testDefaultValue9() throws CoreException {
+ try {
+ String cuSource =
+ "package p;\n" +
+ "public @interface Y {\n" +
+ " public double member() default -1.0;\n" +
+ "}";
+ createFile("/P/src/p/Y.java", cuSource);
+ IMethod method = getCompilationUnit("/P/src/p/Y.java").getType("Y").getMethod("member", new String[0]);
+ assertMemberValuePairEquals(
+ "member=(double)-1.0",
+ method.getDefaultValue());
+ } finally {
+ deleteFile("/P/src/p/Y.java");
+ }
+}
+
+/*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=248312
+ * Ensures that the default value (a negative long) for an annotation method is correct.
+ */
+public void testDefaultValue10() throws CoreException {
+ try {
+ String cuSource =
+ "package p;\n" +
+ "public @interface Y {\n" +
+ " public long member() default -1L;\n" +
+ "}";
+ createFile("/P/src/p/Y.java", cuSource);
+ IMethod method = getCompilationUnit("/P/src/p/Y.java").getType("Y").getMethod("member", new String[0]);
+ assertMemberValuePairEquals(
+ "member=-1L",
+ method.getDefaultValue());
+ } finally {
+ deleteFile("/P/src/p/Y.java");
+ }
+}
+
+/*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=248312
+ * Ensures that the default value (a sign appended Qualified Name Reference) for an annotation method
+ * doesn't throw an exception
+ */
+public void testDefaultValue11() throws CoreException {
+ try {
+ String cuSource =
+ "package p;\n" +
+ "interface A {\n" +
+ " static int VAL = 1;\n" +
+ "}\n" +
+ "public @interface Y {\n" +
+ " public int member() default -A.VAL;\n" +
+ "}";
+ createFile("/P/src/p/Y.java", cuSource);
+ IMethod method = getCompilationUnit("/P/src/p/Y.java").getType("Y").getMethod("member", new String[0]);
+ assertMemberValuePairEquals(
+ "member=