Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Arthanareeswaran2015-07-27 12:08:40 +0000
committerJay Arthanareeswaran2015-07-27 16:12:16 +0000
commit80f6342a7f709a2d6fe0cf3f1274abc00b566ec7 (patch)
tree2e920bbcd6bf27c6dc5235fe88b2e302e7ff9356 /org.eclipse.jdt.compiler.apt.tests
parent23d031b1b77753b1109ce0253088a2b7f49a7000 (diff)
downloadeclipse.jdt.core-80f6342a7f709a2d6fe0cf3f1274abc00b566ec7.tar.gz
eclipse.jdt.core-80f6342a7f709a2d6fe0cf3f1274abc00b566ec7.tar.xz
eclipse.jdt.core-80f6342a7f709a2d6fe0cf3f1274abc00b566ec7.zip
Bug 340635 - Types#erasure() doesn't return the raw type.
Diffstat (limited to 'org.eclipse.jdt.compiler.apt.tests')
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jarbin193253 -> 198078 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug340635Proc.java89
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug340635/annotation/GetType.java11
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug340635/classes/MyImpl.java12
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug340635/classes/MyInterface.java6
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java49
6 files changed, 167 insertions, 0 deletions
diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar
index 52cebf9c9e..d60c3cec07 100644
--- a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar
+++ b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar
Binary files differ
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug340635Proc.java b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug340635Proc.java
new file mode 100644
index 0000000000..ca60bf979f
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/AnnotationProcessorTests/Bug340635Proc.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2015 IBM Corporation and others.
+ * 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:
+ * Kevin Pollet - SERLI - (kevin.pollet@serli.com) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.compiler.apt.tests.processors.AnnotationProcessorTests;
+
+import java.util.Set;
+
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.Messager;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedSourceVersion;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.util.SimpleTypeVisitor6;
+import javax.lang.model.util.Types;
+import javax.tools.Diagnostic.Kind;
+
+@SupportedSourceVersion(SourceVersion.RELEASE_6)
+@SupportedAnnotationTypes("annotation.GetType")
+public class Bug340635Proc extends AbstractProcessor {
+
+ private static final boolean ALLOW_OTHER_PROCESSORS_TO_PROCESS = false;
+
+ @Override
+ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+ final Types types = processingEnv.getTypeUtils();
+ final Messager messager = processingEnv.getMessager();
+
+ for (TypeElement annotation : annotations) {
+ final Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(annotation);
+
+ // process the annotations
+ for (Element element : elements) {
+ // search and display informations about the first generic type
+ // found in the
+ // class or interface hierarchy.
+ if (element.getKind().isInterface() || element.getKind().isClass()) {
+ DeclaredType genericType = element.asType().accept(new GenericTypeVisitor(types), null);
+ DeclaredType erasedType = (DeclaredType) types.erasure(genericType);
+
+ StringBuffer message = new StringBuffer();
+ message.append("Erased type: " + erasedType);
+ message.append(" - type arguments: ");
+ for (TypeMirror typeArgument : erasedType.getTypeArguments()) {
+ message.append(typeArgument + ",");
+ }
+ messager.printMessage(Kind.WARNING, message.toString(), element);
+ }
+ }
+
+ }
+
+ return ALLOW_OTHER_PROCESSORS_TO_PROCESS;
+ }
+
+ private class GenericTypeVisitor extends SimpleTypeVisitor6<DeclaredType, Void> {
+ private final Types types;
+
+ public GenericTypeVisitor(Types types) {
+ this.types = types;
+ }
+
+ @Override
+ public DeclaredType visitDeclared(DeclaredType t, Void p) {
+ if (t.getTypeArguments().size() > 0) {
+ return t;
+ }
+ for (TypeMirror superType : types.directSupertypes(t)) {
+ DeclaredType tmp = superType.accept(this, p);
+ if (tmp != null) {
+ return tmp;
+ }
+ }
+ return null;
+ }
+ }
+
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug340635/annotation/GetType.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug340635/annotation/GetType.java
new file mode 100644
index 0000000000..3cbc06a9da
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug340635/annotation/GetType.java
@@ -0,0 +1,11 @@
+package annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface GetType {
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug340635/classes/MyImpl.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug340635/classes/MyImpl.java
new file mode 100644
index 0000000000..e109efea96
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug340635/classes/MyImpl.java
@@ -0,0 +1,12 @@
+package classes;
+
+import classes.MyInterface;
+import annotation.GetType;
+
+@GetType
+public class MyImpl implements MyInterface<String, String> {
+ @Override
+ public Class<String> foo(String param) {
+ return String.class;
+ }
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug340635/classes/MyInterface.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug340635/classes/MyInterface.java
new file mode 100644
index 0000000000..12d82c0dc1
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/AnnotationProcessorTests/bug340635/classes/MyInterface.java
@@ -0,0 +1,6 @@
+package classes;
+
+public interface MyInterface<T, S> {
+
+ Class<T> foo(S param);
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java
index 74170ce3a0..f34011e88e 100644
--- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java
+++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/AnnotationProcessorTests.java
@@ -16,12 +16,45 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
+import javax.tools.Diagnostic;
+import javax.tools.DiagnosticListener;
import javax.tools.JavaCompiler;
+import javax.tools.JavaFileObject;
import junit.framework.TestCase;
public class AnnotationProcessorTests extends TestCase {
+
+ public final class DiagnosticReport<S> implements DiagnosticListener<S> {
+ public int count;
+ public StringBuffer buffer;
+ private List<Diagnostic<? extends S>> warnings = new ArrayList<>();
+ DiagnosticReport() {
+ this.count = 0;
+ this.buffer = new StringBuffer();
+ }
+ public void report(Diagnostic<? extends S> diagnostic) {
+ if (diagnostic.getKind() == Diagnostic.Kind.WARNING) {
+ warnings.add(diagnostic);
+ count++;
+ buffer.append(diagnostic.getMessage(Locale.getDefault()));
+ buffer.append("\n");
+ }
+ }
+ public Diagnostic<? extends S> getErrorAt(int index) {
+ return warnings.get(index);
+ }
+ public String toString() {
+ return this.buffer.toString();
+ }
+ public void clear() {
+ this.count = 0;
+ this.buffer = new StringBuffer();
+ }
+ }
+
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -83,4 +116,20 @@ public class AnnotationProcessorTests extends TestCase {
BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, null, true);
assertNull(System.getProperty(PROC));
}
+ public void testBug340635() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "AnnotationProcessorTests", "bug340635");
+ BatchTestUtils.copyResources("targets/AnnotationProcessorTests/bug340635", targetFolder);
+ List<String> options = new ArrayList<String>();
+ final String PROC = "org.eclipse.jdt.compiler.apt.tests.processors.AnnotationProcessorTests.Bug340635Proc";
+ options.add("-processorpath");
+ options.add(" ");
+ options.add("-processor");
+ options.add(PROC);
+ DiagnosticReport<JavaFileObject> diagnosticListener = new DiagnosticReport<JavaFileObject>();
+ BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, diagnosticListener, true);
+ assertNull(System.getProperty(PROC));
+ assertEquals("incorrect number of messages", 1, diagnosticListener.count);
+ assertEquals("Erased type: classes.MyInterface - type arguments: \n", diagnosticListener.buffer.toString());
+ }
}

Back to the top