Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Arthanareeswaran2015-05-13 17:52:49 +0000
committerJay Arthanareeswaran2015-05-13 20:07:11 +0000
commit42f7a750991845ea38763c1731c7ef38a727c093 (patch)
tree239ab0dfb3e4e0a49422c3b2dc150fce3cc93ac4 /org.eclipse.jdt.compiler.apt.tests
parent7c18a9763024ad321fbd37c2e6b52a79b1b2fb7c (diff)
downloadeclipse.jdt.core-42f7a750991845ea38763c1731c7ef38a727c093.tar.gz
eclipse.jdt.core-42f7a750991845ea38763c1731c7ef38a727c093.tar.xz
eclipse.jdt.core-42f7a750991845ea38763c1731c7ef38a727c093.zip
Bug 444045 - Test case + a minor fix for null charset in JavaFileObject
created by EclipseCompilerImpl
Diffstat (limited to 'org.eclipse.jdt.compiler.apt.tests')
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jarbin193057 -> 193253 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/messager/MessagerProc.java11
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/targets/errors/pa/Nested.java12
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/targets/errors/pa/Outer.java13
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/targets/errors/pb/D.java3
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/MessagerTests.java32
6 files changed, 63 insertions, 8 deletions
diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors.jar
index f084ec1f37..52cebf9c9e 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/messager/MessagerProc.java b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/messager/MessagerProc.java
index 629a704454..bfa1125f91 100644
--- a/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/messager/MessagerProc.java
+++ b/org.eclipse.jdt.compiler.apt.tests/processors/org/eclipse/jdt/compiler/apt/tests/processors/messager/MessagerProc.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 BEA Systems, Inc. and others
+ * Copyright (c) 2007, 2015 BEA Systems, Inc. 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
@@ -93,6 +93,8 @@ public class MessagerProc extends AbstractProcessor {
// Initialized in collectElements()
private AnnotationMirror _annotationMirror;
+ private AnnotationMirror _nestedAnnotation;
+
// Initialized in collectElements()
private AnnotationValue _annotationValue;
@@ -228,6 +230,12 @@ public class MessagerProc extends AbstractProcessor {
for (AnnotationMirror mirror : annotationMirrors) {
if (_annotationMirror == null) {
_annotationMirror = mirror;
+ } else if (_nestedAnnotation == null) {
+ Collection<? extends AnnotationValue> values = mirror.getElementValues().values();
+ for (AnnotationValue annotationValue : values) {
+ _nestedAnnotation = (AnnotationMirror) annotationValue.getValue();
+ }
+ } else {
break;
}
}
@@ -310,6 +318,7 @@ public class MessagerProc extends AbstractProcessor {
_messager.printMessage(Kind.NOTE, "Informational message not associated with an element");
_messager.printMessage(Kind.ERROR, "Error on element D", _elementD);
_messager.printMessage(Kind.ERROR, "Error on element D", _elementD, _annotationMirror);
+ _messager.printMessage(Kind.ERROR, "Error on element D", _elementD, _nestedAnnotation);
_messager.printMessage(Kind.ERROR, "Error on element D", _elementD, _annotationMirror, _annotationValue);
_messager.printMessage(Kind.ERROR, "Error on element java.lang.String", _element2);
_messager.printMessage(Kind.WARNING, "Warning on method foo", _methodElement);
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/errors/pa/Nested.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/errors/pa/Nested.java
new file mode 100644
index 0000000000..b22e67c74c
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/errors/pa/Nested.java
@@ -0,0 +1,12 @@
+/*******************************************************************************
+ * 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
+ *******************************************************************************/
+
+package target.errors.pa;
+
+public @interface Nested {
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/errors/pa/Outer.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/errors/pa/Outer.java
new file mode 100644
index 0000000000..b197fdc07e
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/errors/pa/Outer.java
@@ -0,0 +1,13 @@
+/*******************************************************************************
+ * 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
+ *******************************************************************************/
+
+package target.errors.pa;
+
+public @interface Outer {
+ Nested value();
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/errors/pb/D.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/errors/pb/D.java
index 36b4c5f95d..d5b0d063b3 100644
--- a/org.eclipse.jdt.compiler.apt.tests/resources/targets/errors/pb/D.java
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/errors/pb/D.java
@@ -8,9 +8,12 @@
package targets.errors.pb;
import target.errors.pa.AnnoZ;
+import target.errors.pa.Outer;
+import target.errors.pa.Nested;
@AnnoZ(
annoZString = "annoZOnD")
+@Outer(@Nested())
@SuppressWarnings("all")
public class D {
public enum DEnum { DEnum1, DEnum2, DEnum3 }
diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/MessagerTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/MessagerTests.java
index 23a3f6789c..b6fee90bba 100644
--- a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/MessagerTests.java
+++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/MessagerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 BEA Systems, Inc. and others
+ * Copyright (c) 2007, 2015 BEA Systems, Inc. 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
@@ -16,6 +16,7 @@ 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;
@@ -32,16 +33,27 @@ import junit.framework.TestCase;
public class MessagerTests extends TestCase {
public final class DiagnosticReport<S> implements DiagnosticListener<S> {
- public int errors;
-
+ public int count;
+ public StringBuffer buffer;
+ private List<Diagnostic<? extends S>> errors = new ArrayList<>();
DiagnosticReport() {
- this.errors = 0;
+ this.count = 0;
+ this.buffer = new StringBuffer();
}
public void report(Diagnostic<? extends S> diagnostic) {
if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
- errors++;
+ errors.add(diagnostic);
+ count++;
+ buffer.append(diagnostic.getMessage(Locale.getDefault()));
+ buffer.append("\n");
}
}
+ public Diagnostic<? extends S> getErrorAt(int index) {
+ return errors.get(index);
+ }
+ public String toString() {
+ return this.buffer.toString();
+ }
}
// See corresponding usages in the MessagerProc class
private static final String MESSAGERPROCNAME = "org.eclipse.jdt.compiler.apt.tests.processors.messager.MessagerProc";
@@ -66,7 +78,7 @@ public class MessagerTests extends TestCase {
internalTestMessager(compiler, diagnosticListener);
// surprisingly enough javac 1.7 only reports 3 errors
// javac 1.6 reports 4 errors as expected
- assertTrue("Wrong number of reported errors", diagnosticListener.errors >= 3);
+ assertTrue("Wrong number of reported errors", diagnosticListener.count >= 3);
}
/**
@@ -77,7 +89,13 @@ public class MessagerTests extends TestCase {
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
DiagnosticReport<JavaFileObject> diagnosticListener = new DiagnosticReport<JavaFileObject>();
internalTestMessager(compiler, diagnosticListener);
- assertEquals("Wrong number of reported errors", 4, diagnosticListener.errors);
+ assertEquals("Wrong number of reported errors", 5, diagnosticListener.count);
+ @SuppressWarnings("unchecked")
+ Diagnostic<JavaFileObject> diag = (Diagnostic<JavaFileObject>) diagnosticListener.getErrorAt(2);
+ JavaFileObject fileObject = diag.getSource();
+ CharSequence content = fileObject.getCharContent(true);
+ String marker = content.subSequence((int) diag.getStartPosition(), (int) diag.getEndPosition() + 1).toString();
+ assertEquals("Wrong error postion", "@Nested", marker);
}
/**

Back to the top