Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarry Terkelsen2014-08-15 17:48:22 +0000
committerHarry Terkelsen2014-08-21 23:10:23 +0000
commita16b4bac72f18b88e0ee337c3ee2d4cf28bfb8b4 (patch)
tree384b76098b502d643606980f8c2376fcf252471d /org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/annotationvalue
parent65f5152e309a08bb91b2b35f96e93b2fa93bae4f (diff)
downloadeclipse.jdt.core-a16b4bac72f18b88e0ee337c3ee2d4cf28bfb8b4.tar.gz
eclipse.jdt.core-a16b4bac72f18b88e0ee337c3ee2d4cf28bfb8b4.tar.xz
eclipse.jdt.core-a16b4bac72f18b88e0ee337c3ee2d4cf28bfb8b4.zip
Bug 441790 - AnnotationValue.toString is creating incorrect and
truncated text that cannot be used in source code Change-Id: Icdbccc0d0ca80a862f8b4b17c67c999492333478 Signed-off-by: Harry Terkelsen <het@google.com>
Diffstat (limited to 'org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/annotationvalue')
-rw-r--r--org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/annotationvalue/AnnotationValueProcessor.java99
-rw-r--r--org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/annotationvalue/AnnotationValueProcessorFactory.java31
-rw-r--r--org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/annotationvalue/CodeExample.java27
3 files changed, 157 insertions, 0 deletions
diff --git a/org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/annotationvalue/AnnotationValueProcessor.java b/org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/annotationvalue/AnnotationValueProcessor.java
new file mode 100644
index 0000000000..16f87d8ea6
--- /dev/null
+++ b/org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/annotationvalue/AnnotationValueProcessor.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2014 BEA Systems, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * het@google.com - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.apt.tests.annotations.annotationvalue;
+
+import com.sun.mirror.apt.AnnotationProcessorEnvironment;
+import com.sun.mirror.declaration.AnnotationMirror;
+import com.sun.mirror.declaration.AnnotationTypeElementDeclaration;
+import com.sun.mirror.declaration.AnnotationValue;
+import com.sun.mirror.declaration.FieldDeclaration;
+import com.sun.mirror.declaration.TypeDeclaration;
+
+import junit.framework.ComparisonFailure;
+
+import org.eclipse.jdt.apt.tests.annotations.BaseProcessor;
+import org.eclipse.jdt.apt.tests.annotations.ProcessorTestStatus;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+public class AnnotationValueProcessor extends BaseProcessor {
+ public AnnotationValueProcessor(AnnotationProcessorEnvironment env) {
+ super(env);
+ }
+
+ public void process() {
+ ProcessorTestStatus.setProcessorRan();
+ try{
+ TypeDeclaration typeDecl = _env.getTypeDeclaration("question.AnnotationTest");
+ junit.framework.TestCase.assertNotNull("failed to locate type 'question.AnnotationTest'", typeDecl);
+ if( typeDecl != null){
+ FieldDeclaration firstFieldDecl = null;
+ for (FieldDeclaration fieldDeclaration : typeDecl.getFields()) {
+ firstFieldDecl = fieldDeclaration;
+ break;
+ }
+
+ AnnotationMirror rtVisibleAnnotationMirror = null;
+ for (AnnotationMirror annotationMirror : firstFieldDecl.getAnnotationMirrors()) {
+ if (annotationMirror.getAnnotationType().getDeclaration().getSimpleName().equals("RTVisibleAnno")) {
+ rtVisibleAnnotationMirror = annotationMirror;
+ break;
+ }
+ }
+
+ final Map<String, String> namesToValues = new HashMap<String, String>();
+ namesToValues.put("name", "\"Foundation\"");
+ namesToValues.put("boolValue", "false");
+ namesToValues.put("byteValue", "16");
+ namesToValues.put("charValue", "'c'");
+ namesToValues.put("doubleValue", "99.0");
+ namesToValues.put("floatValue", "9.0");
+ namesToValues.put("intValue", "999");
+ namesToValues.put("longValue", "3333");
+ namesToValues.put("shortValue", "3");
+ namesToValues.put("colors", "{question.Color.RED, question.Color.BLUE}");
+ namesToValues.put("anno", "@question.SimpleAnnotation(value = \"core\")");
+ namesToValues.put("simpleAnnos", "{@question.SimpleAnnotation(value = \"org\"), @question.SimpleAnnotation(value = \"eclipse\"), @question.SimpleAnnotation(value = \"jdt\")}");
+ namesToValues.put("clazzes", "{java.lang.Object.class, java.lang.String.class}");
+ namesToValues.put("clazz", "java.lang.Object.class");
+ assertAnnotation(namesToValues, rtVisibleAnnotationMirror);
+ }
+ }
+ catch(ComparisonFailure failure) {
+ if (!ProcessorTestStatus.hasErrors()) {
+ ProcessorTestStatus.failWithoutException(failure.toString());
+ }
+ throw failure;
+ }
+ catch(junit.framework.AssertionFailedError error) {
+ if (!ProcessorTestStatus.hasErrors()) {
+ ProcessorTestStatus.failWithoutException(error.toString());
+ }
+ throw error;
+ }
+ }
+
+ private void assertAnnotation(final Map<String, String> namesToValues, AnnotationMirror annotation) {
+ Map<AnnotationTypeElementDeclaration, AnnotationValue> values = annotation.getElementValues();
+ for (Entry<AnnotationTypeElementDeclaration, AnnotationValue> e : values.entrySet()) {
+ String key = e.getKey().getSimpleName();
+ if (namesToValues.containsKey(key)) {
+ junit.framework.TestCase.assertEquals(namesToValues.get(key), e.getValue().toString());
+ namesToValues.remove(key);
+ } else {
+ junit.framework.TestCase.fail("Unexpected annotation element: " + key);
+ }
+ }
+ junit.framework.TestCase.assertEquals(0, namesToValues.size());
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/annotationvalue/AnnotationValueProcessorFactory.java b/org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/annotationvalue/AnnotationValueProcessorFactory.java
new file mode 100644
index 0000000000..e7edd09b50
--- /dev/null
+++ b/org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/annotationvalue/AnnotationValueProcessorFactory.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2014 BEA Systems, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * het - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.apt.tests.annotations.annotationvalue;
+
+import java.util.Set;
+
+import org.eclipse.jdt.apt.tests.annotations.BaseFactory;
+
+import com.sun.mirror.apt.AnnotationProcessor;
+import com.sun.mirror.apt.AnnotationProcessorEnvironment;
+import com.sun.mirror.declaration.AnnotationTypeDeclaration;
+
+public class AnnotationValueProcessorFactory extends BaseFactory {
+ public AnnotationValueProcessorFactory() {
+ super("trigger.MyTrigger"); //$NON-NLS-1$
+ }
+
+ public AnnotationProcessor getProcessorFor(
+ Set<AnnotationTypeDeclaration> atds,
+ AnnotationProcessorEnvironment env) {
+ return new AnnotationValueProcessor(env);
+ }
+}
diff --git a/org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/annotationvalue/CodeExample.java b/org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/annotationvalue/CodeExample.java
new file mode 100644
index 0000000000..f8f860bd5c
--- /dev/null
+++ b/org.eclipse.jdt.apt.tests/src-annotations/org/eclipse/jdt/apt/tests/annotations/annotationvalue/CodeExample.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2014 BEA Systems, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * het@google.com - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.apt.tests.annotations.annotationvalue;
+
+public class CodeExample {
+ public static final String PACKAGE_TRIGGER = "trigger";
+ public static final String TRIGGER_CLASS = "Trigger";
+ public static final String TRIGGER_CODE =
+ "package trigger; \n" +
+ "\n" +
+ "@MyTrigger \n" +
+ "public class Trigger {}";
+
+ public static final String MYTRIGGER_CLASS = "MyTrigger";
+ public static final String MYTRIGGER_CODE =
+ "package trigger; \n" +
+ "\n" +
+ "public @interface MyTrigger {}";
+}

Back to the top