### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core 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 19 Oct 2009 11:08:54 -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,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) + if((((UnaryExpression) expression).bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT == OperatorIds.MINUS) { + Literal subExpression = (Literal)((UnaryExpression)expression).expression; + subExpression.computeConstant(); + return Util.getNegativeAnnotationMemberValue(memberValuePair, subExpression.constant); + } else { + 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 19 Oct 2009 11:08:54 -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,15 @@ if (memberValuePair.valueKind == -1) memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN; return values; + } else if (expression instanceof UnaryExpression){ //to deal with negative numerals (see bug - 248312) + if((((UnaryExpression) expression).bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT == OperatorIds.MINUS) { + Literal subExpression = (Literal)((UnaryExpression)expression).expression; + subExpression.computeConstant(); + return Util.getNegativeAnnotationMemberValue(memberValuePair, subExpression.constant); + } else { + 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.134 diff -u -r1.134 Util.java --- model/org/eclipse/jdt/internal/core/util/Util.java 22 Jun 2009 12:58:54 -0000 1.134 +++ model/org/eclipse/jdt/internal/core/util/Util.java 19 Oct 2009 11:08:56 -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_NEGATIVE_INT; + return new Integer(constant.intValue() * -1); + case TypeIds.T_float : + memberValuePair.valueKind = IMemberValuePair.K_NEGATIVE_FLOAT; + return new Float(constant.floatValue() * -1.0f); + case TypeIds.T_double : + memberValuePair.valueKind = IMemberValuePair.K_NEGATIVE_DOUBLE; + return new Double(constant.doubleValue() * -1.0); + case TypeIds.T_long : + memberValuePair.valueKind = IMemberValuePair.K_NEGATIVE_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. * 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 19 Oct 2009 11:08:53 -0000 @@ -131,6 +131,30 @@ * array containing {@link Object}s and/or nulls for unknown elements. */ int K_UNKNOWN = 14; + + /** + * Constant indicating that the value kind is a negative int represented by + * an instance of {@link Integer}. + */ + int K_NEGATIVE_INT = 15; + + /** + * Constant indicating that the value kind is a negative float represented by + * an instance of {@link Float}. + */ + int K_NEGATIVE_FLOAT = 16; + + /** + * Constant indicating that the value kind is a negative double represented by + * an instance of {@link Double}. + */ + int K_NEGATIVE_DOUBLE = 17; + + /** + * Constant indicating that the value kind is a negative long represented by + * an instance of {@link Long}. + */ + int K_NEGATIVE_LONG = 18; /** * Returns the member's name of this member-value pair. @@ -162,7 +186,8 @@ * {@link #K_ANNOTATION}, {@link #K_BOOLEAN}, {@link #K_BYTE}, {@link #K_CHAR}, * {@link #K_CLASS}, {@link #K_DOUBLE}, {@link #K_FLOAT}, {@link #K_INT}, {@link #K_LONG}, * {@link #K_QUALIFIED_NAME}, {@link #K_SIMPLE_NAME}, {@link #K_SHORT}, {@link #K_STRING}, - * {@link #K_UNKNOWN}. + * {@link #K_UNKNOWN}, {@link #K_NEGATIVE_INT}, {@link #K_NEGATIVE_FLOAT}, {@link #K_NEGATIVE_LONG}, + * {@link #K_NEGATIVE_DOUBLE}. * * @return the value kind of this member-value pair */ #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java,v retrieving revision 1.234 diff -u -r1.234 AbstractJavaModelTests.java --- src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 5 Oct 2009 13:42:03 -0000 1.234 +++ src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 19 Oct 2009 11:09:06 -0000 @@ -799,6 +799,7 @@ } switch(kind) { case IMemberValuePair.K_INT: + case IMemberValuePair.K_NEGATIVE_INT: buffer.append("(int)"); buffer.append(value); break; @@ -816,10 +817,12 @@ buffer.append('\''); break; case IMemberValuePair.K_FLOAT: + case IMemberValuePair.K_NEGATIVE_FLOAT: buffer.append(value); buffer.append('f'); break; case IMemberValuePair.K_DOUBLE: + case IMemberValuePair.K_NEGATIVE_DOUBLE: buffer.append("(double)"); buffer.append(value); break; @@ -827,6 +830,7 @@ buffer.append(value); break; case IMemberValuePair.K_LONG: + case IMemberValuePair.K_NEGATIVE_LONG: buffer.append(value); buffer.append('L'); break; 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 19 Oct 2009 11:09:09 -0000 @@ -285,6 +285,90 @@ } /* + * 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"); + } +} + +/* * Ensure that the deprecated flag is correctly reported * (regression test fo bug 23207 Flags.isDeprecated(IMethod.getFlags()) doesn't work) */ @@ -2290,5 +2374,35 @@ this.workingCopy.getSource()); } +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=248312 + * Ensures that negative values work while annotating local variables. + */ +public void testBug248312() throws CoreException{ + createWorkingCopy( + "package p;\n" + + "public @interface Y {\n" + + " public int member_int() default -1;\n" + + " public float member_float() default -1.0f\n" + + " public double member_double=-1.0\n" + + " public long member_long=-1L\n" + + "}\n" + + "public class Test{\n" + + " void testMethod(){\n" + + " @Y(member_int=-1) @Y(member_float=-1.0f)\n" + + " @Y(member_double=-1.0) @Y(member_long=-1L)\n" + + " Object testField1\n" + + " }\n" + + "}" + ); + ILocalVariable variable1 = selectLocalVariable(this.workingCopy, "testField1"); + IAnnotation[] annotations = variable1.getAnnotations(); + assertAnnotationsEqual( + "@Y(member_int=(int)-1)\n" + + "@Y(member_float=-1.0f)\n" + + "@Y(member_double=(double)-1.0)\n" + + "@Y(member_long=-1L)\n", + annotations); +} } 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 19 Oct 2009 11:09:07 -0000 @@ -124,6 +124,14 @@ " void foo12() {}\n" + " @MyAnnot(_array={1, 2, 3})\n" + " void foo13() {}\n" + + " @MyAnnot(_neg_int=-1)\n" + + " void foo14() {}\n" + + " @MyAnnot(_neg_float=-1.0f)\n" + + " void foo15() {}\n" + + " @MyAnnot(_neg_double=-1.0)\n" + + " void foo16() {}\n" + + " @MyAnnot(_neg_long=-1L)\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)-1)\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=-1.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)-1.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=-1L)\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) */