Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarry Terkelsen2014-08-26 23:27:27 +0000
committerMarkus Keller2014-09-08 22:59:15 +0000
commit792a8c6c3e374444dc583ac6a4c04af5f3cf356d (patch)
treeff0b0c1fb02a2b8cad28d16b51265c5afe7b6b00 /org.eclipse.jdt.apt.tests
parent4f3cb4506b570faea11a184c16ddcb866109910f (diff)
downloadeclipse.jdt.core-792a8c6c3e374444dc583ac6a4c04af5f3cf356d.tar.gz
eclipse.jdt.core-792a8c6c3e374444dc583ac6a4c04af5f3cf356d.tar.xz
eclipse.jdt.core-792a8c6c3e374444dc583ac6a4c04af5f3cf356d.zip
Bug 441790 - AnnotationValue.toString is creating incorrect and
truncated text that cannot be used in source code Change-Id: I721e35c3d749d4c5d18eafd0e22164e5dcd9afa6 Signed-off-by: Harry Terkelsen <het@google.com>
Diffstat (limited to 'org.eclipse.jdt.apt.tests')
-rw-r--r--org.eclipse.jdt.apt.tests/resources/question.jarbin3758 -> 3826 bytes
-rw-r--r--org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/readannotation/CodeExample.java61
-rw-r--r--org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/readannotation/ReadAnnotationProcessor.java77
-rw-r--r--org.eclipse.jdt.apt.tests/src-resources/question/AnnotationTest.java91
4 files changed, 123 insertions, 106 deletions
diff --git a/org.eclipse.jdt.apt.tests/resources/question.jar b/org.eclipse.jdt.apt.tests/resources/question.jar
index d9c37792ee..df0ae92792 100644
--- a/org.eclipse.jdt.apt.tests/resources/question.jar
+++ b/org.eclipse.jdt.apt.tests/resources/question.jar
Binary files differ
diff --git a/org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/readannotation/CodeExample.java b/org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/readannotation/CodeExample.java
index c57857e341..874e2a09aa 100644
--- a/org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/readannotation/CodeExample.java
+++ b/org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/readannotation/CodeExample.java
@@ -10,17 +10,18 @@
*******************************************************************************/
package org.eclipse.jdt.apt.tests.annotations.readannotation;
+
public class CodeExample {
-
+
public static final String PACKAGE_QUESTION = "question";
-
+
public static final String ANNOTATION_TEST_CLASS = "AnnotationTest";
- public static final String ANNOTATION_TEST_CODE =
+ public static final String ANNOTATION_TEST_CODE =
"package question;\n" +
"\n" +
"@Deprecated\n" +
"@RTVisibleAnno(anno=@SimpleAnnotation(\"test\"), clazzes={})\n" +
- "@RTInvisibleAnno(\"question\")\n" +
+ "@RTInvisibleAnno(\"question\")\n" +
"public interface AnnotationTest{\n" +
"\n" +
" @RTVisibleAnno(name = \"Foundation\",\n" +
@@ -34,7 +35,7 @@ public class CodeExample {
" shortValue = 3, \n" +
" colors ={ Color.RED, Color.BLUE }, \n" +
" anno = @SimpleAnnotation(\"core\"),\n" +
- " simpleAnnos = {@SimpleAnnotation(\"org\"), \n" +
+ " simpleAnnos = {@SimpleAnnotation(\"org\"), \n" +
" @SimpleAnnotation(\"eclipse\"),\n" +
" @SimpleAnnotation(\"jdt\") }, \n" +
" clazzes = {Object.class, String.class},\n " +
@@ -48,7 +49,7 @@ public class CodeExample {
"\n" +
" @RTVisibleAnno(anno=@SimpleAnnotation(\"field\"), clazzes={})\n " +
" @RTInvisibleAnno(\"2\") \n " +
- " public int field2 = 2; \n" +
+ " public int field2 = 2; \n" +
"\n" +
" @RTInvisibleAnno(\"3\") \n" +
" public int field3 = 3; \n" +
@@ -82,35 +83,41 @@ public class CodeExample {
" int p2); \n" +
"\n" +
" public int method6(int p0, int p1, int p2); \n" +
+ "\n" +
+ " @RTVisibleAnno(name = \"I'm \\\"special\\\": \\t\\\\\\n\",\n" +
+ " charValue = '\\'',\n" +
+ " clazzes = {},\n" +
+ " anno = @SimpleAnnotation(\"\"))\n" +
+ " public int method7();" +
"\n }";
public static final String COLOR_CLASS = "Color";
- public static final String COLOR_CODE =
+ public static final String COLOR_CODE =
"package question;\n" +
"\n" +
- "public enum Color { RED, WHITE, BLUE; } ";
-
+ "public enum Color { RED, WHITE, BLUE; } ";
+
public static final String PACKAGE_INFO_CLASS = "package-info";
- public static final String PACKAGE_INFO_CODE =
+ public static final String PACKAGE_INFO_CODE =
"@Deprecated package question; ";
-
+
public static final String RTINVISIBLE_CLASS = "RTInvisibleAnno";
- public static final String RTINVISIBLE_ANNOTATION_CODE =
+ public static final String RTINVISIBLE_ANNOTATION_CODE =
"package question; \n" +
"\n" +
- " public @interface RTInvisibleAnno{ \n" +
+ " public @interface RTInvisibleAnno{ \n" +
" String value(); \n" +
" }";
-
+
public static final String RTVISIBLE_CLASS = "RTVisibleAnno";
- public static final String RTVISIBLE_ANNOTATION_CODE =
+ public static final String RTVISIBLE_ANNOTATION_CODE =
"package question; \n" +
"\n" +
"import java.lang.annotation.*; \n" +
"\n" +
"@Retention(value=RetentionPolicy.RUNTIME) \n" +
"public @interface RTVisibleAnno \n" +
- "{ \n" +
+ "{ \n" +
" String name() default \"eclipse\"; \n" +
" boolean boolValue() default true; \n" +
" byte byteValue() default 0x0001; \n" +
@@ -126,9 +133,9 @@ public class CodeExample {
" Class<?>[] clazzes(); \n" +
" Class<?> clazz() default java.lang.String.class; \n" +
"\n }";
-
+
public static final String SIMPLE_ANNOTATION_CLASS = "SimpleAnnotation";
- public static final String SIMPLE_ANNOTATION_CODE =
+ public static final String SIMPLE_ANNOTATION_CODE =
"package question; \n" +
"\n" +
"import java.lang.annotation.Retention; \n" +
@@ -136,27 +143,27 @@ public class CodeExample {
"\n" +
"@Retention(value=RetentionPolicy.RUNTIME) \n" +
"public @interface SimpleAnnotation { \n" +
- "\n" +
+ "\n" +
" String value(); \n" +
"}";
-
+
public static final String PACKAGE_TRIGGER = "trigger";
public static final String TRIGGER_CLASS = "Trigger";
- public static final String TRIGGER_CODE =
+ public static final String TRIGGER_CODE =
"package trigger; \n" +
"\n" +
"@MyMarkerAnnotation \n" +
"public class Trigger {}";
-
+
public static final String MYMARKERANNOTATION_CLASS = "MyMarkerAnnotation";
- public static final String MYMARKERANNOTATION_CODE =
+ public static final String MYMARKERANNOTATION_CODE =
"package trigger; \n" +
- "\n" +
+ "\n" +
"public @interface MyMarkerAnnotation {}";
-
+
public static final String PACKAGE_NOTYPES = "notypes";
public static final String PACKAGE_INFO_NOTYPES_CLASS = "package-info";
- public static final String PACKAGE_INFO_NOTYPES_CODE =
+ public static final String PACKAGE_INFO_NOTYPES_CODE =
"@question.SimpleAnnotation(\"foo\") package notypes;\n";
-
+
}
diff --git a/org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/readannotation/ReadAnnotationProcessor.java b/org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/readannotation/ReadAnnotationProcessor.java
index 7691ca7c63..5b22a815d7 100644
--- a/org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/readannotation/ReadAnnotationProcessor.java
+++ b/org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/readannotation/ReadAnnotationProcessor.java
@@ -29,48 +29,48 @@ import com.sun.mirror.declaration.TypeDeclaration;
public class ReadAnnotationProcessor extends BaseProcessor
{
private static final String[] NO_ANNOTATIONS = new String[0];
-
+
public ReadAnnotationProcessor(AnnotationProcessorEnvironment env)
{
super(env);
}
public void process()
- {
+ {
ProcessorTestStatus.setProcessorRan();
- try{
- TypeDeclaration typeDecl = _env.getTypeDeclaration("question.AnnotationTest");
+ try{
+ TypeDeclaration typeDecl = _env.getTypeDeclaration("question.AnnotationTest");
junit.framework.TestCase.assertNotNull("failed to locate type 'question.AnnotationTest'", typeDecl);
if( typeDecl != null){
junit.framework.TestCase.assertEquals("Type name mismatch", "question.AnnotationTest", typeDecl.getQualifiedName());
final String[] expectedPkgAnnos = new String[]{ "@Deprecated()" };
- assertAnnotation(expectedPkgAnnos, typeDecl.getPackage().getAnnotationMirrors() );
+ assertAnnotation(expectedPkgAnnos, typeDecl.getPackage().getAnnotationMirrors() );
assertAnnotation(expectedPkgAnnos, _env.getPackage("question").getAnnotationMirrors() );
-
+
final String[] expectedNoTypeAnnos = new String[]{ "@SimpleAnnotation(value = foo)" };
assertAnnotation(expectedNoTypeAnnos, _env.getPackage("notypes").getAnnotationMirrors());
-
+
final String[] expectedTypeAnnos = new String[]{ "@Deprecated()",
"@RTVisibleAnno(anno = @SimpleAnnotation(value = test), clazzes = {})",
"@RTInvisibleAnno(value = question)" };
- assertAnnotation(expectedTypeAnnos, typeDecl.getAnnotationMirrors());
-
+ assertAnnotation(expectedTypeAnnos, typeDecl.getAnnotationMirrors());
+
final Collection<FieldDeclaration> fieldDecls = typeDecl.getFields();
-
+
int counter = 0;
junit.framework.TestCase.assertEquals(5, fieldDecls.size());
for(FieldDeclaration fieldDecl : fieldDecls ){
- final String name = "field" + counter;
-
+ final String name = "field" + counter;
+
junit.framework.TestCase.assertEquals("field name mismatch", name, fieldDecl.getSimpleName());
final String[] expected;
- switch(counter){
- case 0:
+ switch(counter){
+ case 0:
expected = new String[] { "@RTVisibleAnno(name = Foundation, boolValue = false, byteValue = 16, charValue = c, doubleValue = 99.0, floatValue = 9.0, intValue = 999, longValue = 3333, shortValue = 3, colors = {RED, BLUE}, anno = @SimpleAnnotation(value = core), simpleAnnos = {@SimpleAnnotation(value = org), @SimpleAnnotation(value = eclipse), @SimpleAnnotation(value = jdt)}, clazzes = {java.lang.Object, java.lang.String}, clazz = java.lang.Object)",
"@RTInvisibleAnno(value = org.eclipse.jdt.core)",
"@Deprecated()" };
- break;
+ break;
case 1:
expected = new String[] { "@Deprecated()" };
break;
@@ -87,17 +87,17 @@ public class ReadAnnotationProcessor extends BaseProcessor
default:
expected = NO_ANNOTATIONS;
}
-
+
assertAnnotation(expected, fieldDecl.getAnnotationMirrors());
counter ++;
- }
-
+ }
+
final Collection<? extends MethodDeclaration> methodDecls = typeDecl.getMethods();
counter = 0;
- junit.framework.TestCase.assertEquals(7, methodDecls.size());
+ junit.framework.TestCase.assertEquals(8, methodDecls.size());
for(MethodDeclaration methodDecl : methodDecls ){
- final String name = "method" + counter;
-
+ final String name = "method" + counter;
+
junit.framework.TestCase.assertEquals("method name mismatch", name, methodDecl.getSimpleName());
final String[] expected;
switch(counter)
@@ -105,7 +105,7 @@ public class ReadAnnotationProcessor extends BaseProcessor
case 0:
expected = new String[] { "@RTVisibleAnno(anno = @SimpleAnnotation(value = method0), clazzes = {})",
"@RTInvisibleAnno(value = 0)",
- "@Deprecated()" };
+ "@Deprecated()" };
break;
case 1:
expected = new String[] { "@Deprecated()" };
@@ -122,14 +122,19 @@ public class ReadAnnotationProcessor extends BaseProcessor
break;
case 5:
case 6:
+ expected = NO_ANNOTATIONS;
+ break;
+ case 7:
+ expected = new String[] { "@RTVisibleAnno(name = I'm \"special\": \\\n, charValue = ', clazzes = {}, anno = @SimpleAnnotation(value = ))" };
+ break;
default:
expected = NO_ANNOTATIONS;
}
-
+
assertAnnotation(expected, methodDecl.getAnnotationMirrors());
-
+
if( counter == 5 ){
- Collection<ParameterDeclaration> paramDecls = methodDecl.getParameters();
+ Collection<ParameterDeclaration> paramDecls = methodDecl.getParameters();
int pCounter = 0;
for( ParameterDeclaration paramDecl : paramDecls ){
final String[] expectedParamAnnotations;
@@ -138,23 +143,23 @@ public class ReadAnnotationProcessor extends BaseProcessor
case 1:
expectedParamAnnotations = new String[] { "@Deprecated()" };
break;
- case 2:
+ case 2:
expectedParamAnnotations = new String[] { "@RTVisibleAnno(anno = @SimpleAnnotation(value = param2), clazzes = {})",
- "@RTInvisibleAnno(value = 2)" };
- break;
+ "@RTInvisibleAnno(value = 2)" };
+ break;
default:
- expectedParamAnnotations = NO_ANNOTATIONS;
+ expectedParamAnnotations = NO_ANNOTATIONS;
}
assertAnnotation(expectedParamAnnotations, paramDecl.getAnnotationMirrors());
pCounter ++;
}
-
+
}
counter ++;
}
}
}
- catch( ComparisonFailure failure ){
+ catch( ComparisonFailure failure ){
if (!ProcessorTestStatus.hasErrors()) {
ProcessorTestStatus.failWithoutException(failure.toString());
}
@@ -167,16 +172,16 @@ public class ReadAnnotationProcessor extends BaseProcessor
throw error;
}
}
-
+
private void assertAnnotation(final String[] expected, Collection<AnnotationMirror> annotations)
{
- final int expectedLen = expected.length;
+ final int expectedLen = expected.length;
junit.framework.TestCase.assertEquals("annotation number mismatch", expected.length, annotations.size()); //$NON-NLS-1$
-
+
final HashSet<String> expectedSet = new HashSet<String>(expectedLen * 4 / 3 + 1);
for( int i=0; i<expectedLen; i++ )
expectedSet.add(expected[i]);
-
+
int counter = 0;
for( AnnotationMirror mirror : annotations ){
String mirrorString = ProcessorUtil.annoMirrorToString(mirror);
@@ -184,7 +189,7 @@ public class ReadAnnotationProcessor extends BaseProcessor
junit.framework.TestCase.assertEquals("", mirrorString); //$NON-NLS-1$
else{
final boolean contains = expectedSet.contains(mirrorString);
- if( !contains ){
+ if( !contains ){
System.err.println("found unexpected: " + mirrorString);
System.err.println("expected set: " + expectedSet);
}
diff --git a/org.eclipse.jdt.apt.tests/src-resources/question/AnnotationTest.java b/org.eclipse.jdt.apt.tests/src-resources/question/AnnotationTest.java
index 8236af02ac..5cdcc409f1 100644
--- a/org.eclipse.jdt.apt.tests/src-resources/question/AnnotationTest.java
+++ b/org.eclipse.jdt.apt.tests/src-resources/question/AnnotationTest.java
@@ -6,63 +6,68 @@ package question;
public interface AnnotationTest{
@RTVisibleAnno(name = "Foundation",
- boolValue = false,
- byteValue = 0x10,
- charValue = 'c',
- doubleValue = 99.0,
- floatValue = (float)9.0,
- intValue = 999,
- longValue = 3333,
- shortValue = 3,
- colors ={ Color.RED, Color.BLUE },
+ boolValue = false,
+ byteValue = 0x10,
+ charValue = 'c',
+ doubleValue = 99.0,
+ floatValue = (float)9.0,
+ intValue = 999,
+ longValue = 3333,
+ shortValue = 3,
+ colors ={ Color.RED, Color.BLUE },
anno = @SimpleAnnotation("core"),
- simpleAnnos = {@SimpleAnnotation("org"),
+ simpleAnnos = {@SimpleAnnotation("org"),
@SimpleAnnotation("eclipse"),
- @SimpleAnnotation("jdt") },
+ @SimpleAnnotation("jdt") },
clazzes = {Object.class, String.class},
clazz = Object.class)
@RTInvisibleAnno("org.eclipse.jdt.core")
- @Deprecated
- public int field0 = 0;
+ @Deprecated
+ public int field0 = 0;
- @Deprecated
- public int field1 = 1;
+ @Deprecated
+ public int field1 = 1;
@RTVisibleAnno(anno=@SimpleAnnotation("field"), clazzes={})
- @RTInvisibleAnno("2")
- public int field2 = 2;
+ @RTInvisibleAnno("2")
+ public int field2 = 2;
- @RTInvisibleAnno("3")
- public int field3 = 3;
+ @RTInvisibleAnno("3")
+ public int field3 = 3;
- @SimpleAnnotation("4")
- public int field4 = 4;
+ @SimpleAnnotation("4")
+ public int field4 = 4;
- @RTVisibleAnno(anno=@SimpleAnnotation("method0"), clazzes={})
- @RTInvisibleAnno("0")
- @Deprecated
- public int method0();
-
- @Deprecated
- public int method1();
-
- @RTVisibleAnno(anno=@SimpleAnnotation("method2"), clazzes={})
- @RTInvisibleAnno("2")
- public int method2();
+ @RTVisibleAnno(anno=@SimpleAnnotation("method0"), clazzes={})
+ @RTInvisibleAnno("0")
+ @Deprecated
+ public int method0();
- @RTInvisibleAnno("3")
- public int method3();
+ @Deprecated
+ public int method1();
- @SimpleAnnotation("method4")
- public int method4();
+ @RTVisibleAnno(anno=@SimpleAnnotation("method2"), clazzes={})
+ @RTInvisibleAnno("2")
+ public int method2();
- public int method5(int p0,
- @Deprecated
- int p1,
- @RTVisibleAnno(anno=@SimpleAnnotation("param2"), clazzes={})
- @RTInvisibleAnno("2")
- int p2);
+ @RTInvisibleAnno("3")
+ public int method3();
- public int method6(int p0, int p1, int p2);
+ @SimpleAnnotation("method4")
+ public int method4();
+ public int method5(int p0,
+ @Deprecated
+ int p1,
+ @RTVisibleAnno(anno=@SimpleAnnotation("param2"), clazzes={})
+ @RTInvisibleAnno("2")
+ int p2);
+
+ public int method6(int p0, int p1, int p2);
+
+ @RTVisibleAnno(name = "I'm \"special\": \t\\\n",
+ charValue = '\'',
+ clazzes = {},
+ anno = @SimpleAnnotation(""))
+ public int method7();
} \ No newline at end of file

Back to the top