Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjay2018-12-04 18:55:11 +0000
committerjay2018-12-05 09:00:37 +0000
commit656a7f631fb76e187296f81dcd900dfff9ff6a65 (patch)
treefe99f1dd4ca496289e39839388017d185b7d8b3e
parentbff823d336ce03dac0d247c2ec5ced05ed4343ba (diff)
downloadeclipse.jdt.core-I20181206-0030.tar.gz
eclipse.jdt.core-I20181206-0030.tar.xz
eclipse.jdt.core-I20181206-0030.zip
Bug 542090 - FilerException: Source file already createdI20181206-0320I20181206-0225I20181206-0030I20181205-1800
Change-Id: I18e92e5ad1eaafae9230b2718ac872e5cf5f1891 Signed-off-by: jay <jarthana@in.ibm.com>
-rw-r--r--org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeFilerImpl.java13
-rw-r--r--org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/FilerTests.java43
-rw-r--r--org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/processors/filertester/FilerTesterProc.java26
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseAnnotationProcessorManager.java8
4 files changed, 83 insertions, 7 deletions
diff --git a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeFilerImpl.java b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeFilerImpl.java
index 75c763378e..4f6fa75189 100644
--- a/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeFilerImpl.java
+++ b/org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeFilerImpl.java
@@ -54,12 +54,12 @@ import org.eclipse.jdt.internal.compiler.lookup.TagBits;
*/
public class IdeFilerImpl implements Filer {
- //private final IdeAnnotationProcessorManager _dispatchManager;
+ private final IdeAnnotationProcessorManager _dispatchManager;
private final IdeProcessingEnvImpl _env;
public IdeFilerImpl(IdeAnnotationProcessorManager dispatchManager,
IdeProcessingEnvImpl env) {
- //_dispatchManager = dispatchManager;
+ _dispatchManager = dispatchManager;
_env = env;
}
@@ -174,7 +174,14 @@ public class IdeFilerImpl implements Filer {
m = _env.getCompiler().lookupEnvironment.UnNamedModule;
ReferenceBinding type = m.environment.getType(CharOperation.splitOn('.', name.toString().toCharArray()), m);
if (type != null && (type.tagBits & TagBits.HasMissingType) == 0) {
- throw new FilerException("Source file already exists : " + name); //$NON-NLS-1$
+ IFile classFile = getFileFromOutputLocation(StandardLocation.CLASS_OUTPUT, CharOperation.toString(type.fPackage.compoundName), new String(type.sourceName()) + ".class");
+ String fileName = new String(type.getFileName());
+ if (fileName != null) {
+ String osString = classFile.getFullPath().toOSString();
+ if (!osString.equals(fileName) || !_dispatchManager._isFirstRound) {
+ throw new FilerException("Source file already exists : " + name); //$NON-NLS-1$
+ }
+ }
}
Set<IFile> parentFiles = Collections.emptySet();
if (originatingElements != null && originatingElements.length > 0) {
diff --git a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/FilerTests.java b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/FilerTests.java
index dd5558c370..2d8659dece 100644
--- a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/FilerTests.java
+++ b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/FilerTests.java
@@ -452,6 +452,49 @@ public class FilerTests extends TestBase
fullBuild();
assertEquals("Processor reported errors", ProcessorTestStatus.NO_ERRORS, ProcessorTestStatus.getErrors());
}
+ public void testBug542090() throws Throwable {
+ if (!canRunJava9()) {
+ return;
+ }
+ ProcessorTestStatus.reset();
+ IJavaProject jproj = createJava9Project(_projectName);
+ disableJava5Factories(jproj);
+ IProject proj = jproj.getProject();
+ IPath projPath = proj.getFullPath();
+
+ IPath root = projPath.append("src");
+ env.addClass(root, null, "module-info", "module example {requires annotations;}");
+ env.addClass(root, "p", "Trigger",
+ "package p;\n" +
+ "import org.eclipse.jdt.apt.pluggable.tests.annotations.FilerTestTrigger;\n" +
+ "@FilerTestTrigger(test = \"testBug542090a\", arg0 = \"p\", arg1 = \"Other\")" +
+ "public class Trigger {\n" +
+ "}"
+ );
+
+ AptConfig.setEnabled(jproj, true);
+ fullBuild();
+ env.addClass(root, "p", "Trigger",
+ "package p;\n" +
+ "import org.eclipse.jdt.apt.pluggable.tests.annotations.FilerTestTrigger;\n" +
+ "@FilerTestTrigger(test = \"testBug542090a\", arg0 = \"p\", arg1 = \"Other\")" +
+ "public class Trigger {\n" +
+ "}/*added comment */"
+ );
+ incrementalBuild();
+ assertEquals("Processor reported errors", ProcessorTestStatus.NO_ERRORS, ProcessorTestStatus.getErrors());
+
+ env.addClass(root, "p", "Trigger",
+ "package p;\n" +
+ "import org.eclipse.jdt.apt.pluggable.tests.annotations.FilerTestTrigger;\n" +
+ "@FilerTestTrigger(test = \"testBug542090b\", arg0 = \"p\", arg1 = \"Other\")" +
+ "public class Trigger {\n" +
+ "}/*added comment */"
+ );
+ incrementalBuild();
+ assertEquals("Processor reported errors", "FilerException invoking test method testBug542090b - see console for details", ProcessorTestStatus.getErrors());
+ }
+
public void testCreateClass1() throws Exception {
FilerTesterProc.roundNo = 0;
ProcessorTestStatus.reset();
diff --git a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/processors/filertester/FilerTesterProc.java b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/processors/filertester/FilerTesterProc.java
index 106d252c5e..715f8c4fad 100644
--- a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/processors/filertester/FilerTesterProc.java
+++ b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/processors/filertester/FilerTesterProc.java
@@ -251,6 +251,32 @@ public class FilerTesterProc extends AbstractProcessor {
pw.close();
}
}
+ public void testBug542090a(Element e, String pkg, String relName) throws Exception {
+ if (++roundNo > 1)
+ return;
+ JavaFileObject jfo = _filer.createSourceFile(pkg + "." + relName);
+ PrintWriter pw = null;
+ try {
+ pw = new PrintWriter(jfo.openWriter());
+ pw.println("package " + pkg + ";\npublic class " + relName + "{ }");
+ }
+ finally {
+ if (pw != null)
+ pw.close();
+ }
+ }
+ public void testBug542090b(Element e, String pkg, String relName) throws Exception {
+ JavaFileObject jfo = _filer.createSourceFile(pkg + "." + relName);
+ PrintWriter pw = null;
+ try {
+ pw = new PrintWriter(jfo.openWriter());
+ pw.println("package " + pkg + ";\npublic class " + relName + "{ }");
+ }
+ finally {
+ if (pw != null)
+ pw.close();
+ }
+ }
public void testBug534979InModule(Element e, String pkg, String relName) throws Exception {
JavaFileObject jfo = _filer.createSourceFile(pkg+"."+relName, e.getEnclosingElement());
PrintWriter pw = null;
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseAnnotationProcessorManager.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseAnnotationProcessorManager.java
index 67fc9a8726..0b4b87cb3c 100644
--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseAnnotationProcessorManager.java
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/dispatch/BaseAnnotationProcessorManager.java
@@ -47,7 +47,7 @@ public abstract class BaseAnnotationProcessorManager extends AbstractAnnotationP
protected PrintWriter _out;
protected PrintWriter _err;
protected BaseProcessingEnvImpl _processingEnv;
- protected boolean _isFirstRound = true;
+ public boolean _isFirstRound = true;
/**
* The list of processors that have been loaded so far. A processor on this
@@ -161,9 +161,6 @@ public abstract class BaseAnnotationProcessorManager extends AbstractAnnotationP
}
}
RoundEnvImpl roundEnv = new RoundEnvImpl(units, referenceBindings, isLastRound, _processingEnv);
- if (_isFirstRound) {
- _isFirstRound = false;
- }
PrintWriter traceProcessorInfo = _printProcessorInfo ? _out : null;
PrintWriter traceRounds = _printRounds ? _out : null;
if (traceRounds != null) {
@@ -172,5 +169,8 @@ public abstract class BaseAnnotationProcessorManager extends AbstractAnnotationP
RoundDispatcher dispatcher = new RoundDispatcher(
this, roundEnv, roundEnv.getRootAnnotations(), traceProcessorInfo, traceRounds);
dispatcher.round();
+ if (_isFirstRound) {
+ _isFirstRound = false;
+ }
}
}

Back to the top