Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Harley2009-08-18 06:27:02 +0000
committerWalter Harley2009-08-18 06:27:02 +0000
commit973dd951906f250918cad946f16501aabb85da0b (patch)
tree3804144e66c2bbd5de74326d7407620f2e61e842
parent9eaac7d665ab2785e8869b9e11fcd4dc49d25f41 (diff)
downloadeclipse.jdt.core-973dd951906f250918cad946f16501aabb85da0b.tar.gz
eclipse.jdt.core-973dd951906f250918cad946f16501aabb85da0b.tar.xz
eclipse.jdt.core-973dd951906f250918cad946f16501aabb85da0b.zip
Bug 285838: IdeFilerImpl.CreateXxx should handle null originatingElement
-rw-r--r--org.eclipse.jdt.apt.pluggable.core/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jdt.apt.pluggable.core/src/org/eclipse/jdt/internal/apt/pluggable/core/filer/IdeFilerImpl.java31
-rw-r--r--org.eclipse.jdt.apt.pluggable.tests/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/FilerTests.java34
-rw-r--r--org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/PerformanceTests.java357
-rw-r--r--org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/processors/filertester/FilerTesterProc.java32
6 files changed, 442 insertions, 16 deletions
diff --git a/org.eclipse.jdt.apt.pluggable.core/META-INF/MANIFEST.MF b/org.eclipse.jdt.apt.pluggable.core/META-INF/MANIFEST.MF
index a0537c42c4..10190b48c4 100644
--- a/org.eclipse.jdt.apt.pluggable.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.apt.pluggable.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.apt.pluggable.core;singleton:=true
-Bundle-Version: 1.0.200.qualifier
+Bundle-Version: 1.0.300.qualifier
Bundle-Activator: org.eclipse.jdt.internal.apt.pluggable.core.Apt6Plugin
Bundle-Vendor: %providerName
Require-Bundle: org.eclipse.core.runtime,
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 482711797c..2cfca8762f 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 BEA Systems, Inc.
+ * Copyright (c) 2007 - 2009 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
@@ -14,6 +14,7 @@ package org.eclipse.jdt.internal.apt.pluggable.core.filer;
import java.io.File;
import java.io.IOException;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -91,12 +92,17 @@ public class IdeFilerImpl implements Filer {
IFile file = getFileFromOutputLocation(location, pkg, relativeName);
//TODO: check whether file has already been generated in this run
- Set<IFile> parentFiles = new HashSet<IFile>(originatingElements.length);
- for (Element elem : originatingElements) {
- IFile enclosing = _env.getEnclosingIFile(elem);
- if (null != enclosing) {
- parentFiles.add(enclosing);
+ Set<IFile> parentFiles;
+ if (originatingElements != null && originatingElements.length > 0) {
+ parentFiles = new HashSet<IFile>(originatingElements.length);
+ for (Element elem : originatingElements) {
+ IFile enclosing = _env.getEnclosingIFile(elem);
+ if (null != enclosing) {
+ parentFiles.add(enclosing);
+ }
}
+ } else {
+ parentFiles = Collections.emptySet();
}
return new IdeOutputNonSourceFileObject(_env, file, parentFiles);
}
@@ -115,11 +121,14 @@ public class IdeFilerImpl implements Filer {
throw new IllegalArgumentException("Name is null");
}
//TODO: check whether file has already been generated in this run
- Set<IFile> parentFiles = new HashSet<IFile>(originatingElements.length);
- for (Element elem : originatingElements) {
- IFile enclosing = _env.getEnclosingIFile(elem);
- if (null != enclosing) {
- parentFiles.add(enclosing);
+ Set<IFile> parentFiles = Collections.emptySet();
+ if (originatingElements != null && originatingElements.length > 0) {
+ parentFiles = new HashSet<IFile>(originatingElements.length);
+ for (Element elem : originatingElements) {
+ IFile enclosing = _env.getEnclosingIFile(elem);
+ if (null != enclosing) {
+ parentFiles.add(enclosing);
+ }
}
}
return new IdeOutputJavaFileObject(_env, name, parentFiles);
diff --git a/org.eclipse.jdt.apt.pluggable.tests/META-INF/MANIFEST.MF b/org.eclipse.jdt.apt.pluggable.tests/META-INF/MANIFEST.MF
index b63523b26e..2b76e4b808 100644
--- a/org.eclipse.jdt.apt.pluggable.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.apt.pluggable.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.apt.pluggable.tests;singleton:=true
-Bundle-Version: 3.3.200.qualifier
+Bundle-Version: 3.3.300.qualifier
Bundle-ClassPath: .
Bundle-Activator: org.eclipse.jdt.apt.pluggable.tests.Apt6TestsPlugin
Bundle-Localization: plugin
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 70d7558a57..3834cef8ea 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 BEA Systems, Inc. and others
+ * Copyright (c) 2007 - 2009 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
@@ -261,6 +261,38 @@ public class FilerTests extends TestBase
}
/**
+ * Call FilerTesterProc.testNullParents(), which checks handling of null originatingElements
+ * in the Filer.createXxx() methods.
+ */
+ public void testNullParents() throws Throwable {
+ ProcessorTestStatus.reset();
+ IJavaProject jproj = createJavaProject(_projectName);
+ disableJava5Factories(jproj);
+ IProject proj = jproj.getProject();
+ IPath projPath = proj.getFullPath();
+
+ env.addClass(projPath.append("src"), "p", "Trigger",
+ "package p;\n" +
+ "import org.eclipse.jdt.apt.pluggable.tests.annotations.FilerTestTrigger;\n" +
+ "@FilerTestTrigger(test = \"testNullParents\", arg0 = \"t\", arg1 = \"Test\")" +
+ "public class Trigger {\n" +
+ "}"
+ );
+
+ AptConfig.setEnabled(jproj, true);
+
+ fullBuild();
+ expectingNoProblems();
+ assertTrue("Processor did not run", ProcessorTestStatus.processorRan());
+ assertEquals("Processor reported errors", ProcessorTestStatus.NO_ERRORS, ProcessorTestStatus.getErrors());
+
+ expectingFile(proj, ".apt_generated/t/Test.java");
+ expectingFile(proj, ".apt_generated/t/Test.txt");
+ final String[] expectedClasses = { "p.Trigger", "t.Test" };
+ expectingUniqueCompiledClasses(expectedClasses);
+ }
+
+ /**
* Call FilerTesterProc.testURI, which tests the FileObject.toUri() method on
* various different sorts of files
*/
diff --git a/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/PerformanceTests.java b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/PerformanceTests.java
new file mode 100644
index 0000000000..3d3b858d6a
--- /dev/null
+++ b/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/PerformanceTests.java
@@ -0,0 +1,357 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Walter Harley 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:
+ * eclipse@cafewalter.com - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.jdt.apt.pluggable.tests;
+
+import java.io.File;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.apt.core.util.AptConfig;
+import org.eclipse.jdt.core.IJavaProject;
+
+/**
+ * Performance tests for use when profiling APT
+ */
+public class PerformanceTests extends TestBase
+{
+ private final static boolean VERBOSE = true;
+ private final static int PAUSE_EVERY = 200; // wait for indexer to catch up after creating this many files
+ private final static int PAUSE_TIME = 2000; // milliseconds to wait for indexer
+ private final static boolean INCLUDE_APT_DISABLED = true;
+
+ private final static String CMD_PROFILER_PREFIX = "java -jar c:/opt/yourkit-8.0.13/lib/yjp-controller-api-redist.jar localhost 10001";
+ private final static String CMD_START_CPU_PROFILING = CMD_PROFILER_PREFIX + " start-cpu-sampling noj2ee";
+ private final static String CMD_STOP_CPU_PROFILING = CMD_PROFILER_PREFIX + " stop-cpu-profiling";
+ private final static String CMD_PERF_SNAPSHOT = CMD_PROFILER_PREFIX + " capture-performance-snapshot";
+ private final static String CMD_HEAP_SNAPSHOT = CMD_PROFILER_PREFIX + " capture-memory-snapshot";
+
+ public PerformanceTests(String name) {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite( PerformanceTests.class );
+ }
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ }
+
+ /**
+ * Create files that contain annotations that won't be processed.
+ */
+ private void createBoringFiles(int numFiles, IJavaProject jproj)
+ {
+ String srcTemplate =
+ "package p;\n" +
+ "import java.util.List;\n" +
+ "@SuppressWarnings(\"unchecked\")\n" +
+ "public class TestB%05d {\n" +
+ " private List l = null;\n" +
+ " public List getL() { return l; }\n" +
+ "}";
+ String nameTemplate = "TestB%05d";
+ createFiles(numFiles, nameTemplate, srcTemplate, jproj);
+ }
+
+ /**
+ * Create files that contain annotations that will be processed with a Java 6 processor.
+ */
+ private void createInterestingFilesWithJ6(int numFiles, IJavaProject jproj)
+ {
+ String srcTemplate =
+ "package p;\n" +
+ "import org.eclipse.jdt.apt.pluggable.tests.annotations.ModelTestTrigger;\n" +
+ "import org.eclipse.jdt.apt.pluggable.tests.annotations.LookAt;\n" +
+ "import java.util.List;\n" +
+ "@ModelTestTrigger(test = \"testFieldType\")" +
+ "@SuppressWarnings(\"unused\")\n" +
+ "public class TestI6%05d {\n" +
+ " @LookAt\n" +
+ " private int _fInt = 0;\n" +
+ " @LookAt\n" +
+ " private String _fString = \"\";\n" +
+ " @LookAt\n" +
+ " private List<String> _fFoo = null;\n" +
+ "}";
+ String nameTemplate = "TestI6%05d";
+ createFiles(numFiles, nameTemplate, srcTemplate, jproj);
+ }
+
+ /**
+ * Create files that have annotations that cause other files to be generated.
+ */
+ private void createGeneratingFiles(int numFiles, IJavaProject jproj)
+ {
+ String srcTemplate =
+ "package p;\n" +
+ "import org.eclipse.jdt.apt.pluggable.tests.annotations.GenClass6;\n" +
+ "@GenClass6(pkg=\"g\", name=\"Generated%05d\")\n" +
+ "public class TestG%05d {}";
+
+ String nameTemplate = "TestG%05d";
+ createFiles(numFiles, nameTemplate, srcTemplate, jproj);
+ }
+
+ private void createFiles(int numFiles, String nameTemplate, String srcTemplate, IJavaProject jproj)
+ {
+ IProject project = jproj.getProject();
+ IFolder srcFolder = project.getFolder( "src" );
+ IPath srcRoot = srcFolder.getFullPath();
+
+ for (int i = 1; i <= numFiles; ++i) {
+ String name = String.format(nameTemplate, i);
+ String contents = String.format(srcTemplate, i, i);
+ env.addClass( srcRoot, "p", name, contents ); //$NON-NLS-1$ //$NON-NLS-2$
+
+ // pause to let indexer catch up
+ if (i % PAUSE_EVERY == 0) {
+ if (VERBOSE)
+ System.out.println("Created " + i + " files; pausing for indexer");
+ try {
+ Thread.sleep(PAUSE_TIME);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ if (VERBOSE)
+ System.out.println("Done creating source files");
+ }
+
+ /**
+ * Performance with files that contain annotations that won't be processed.
+ */
+ public void testBoringFiles() throws Exception
+ {
+ final int FILES_TO_GENERATE = 2000; // total number of files to create
+ // set up project with unique name
+ IJavaProject jproj = createJavaProject(_projectName);
+ IProject project = jproj.getProject();
+
+ createBoringFiles(FILES_TO_GENERATE, jproj);
+
+ Runtime run = Runtime.getRuntime();
+
+ long start;
+
+ if (INCLUDE_APT_DISABLED) {
+ AptConfig.setEnabled(jproj, false);
+ start = System.currentTimeMillis();
+ run.exec(CMD_START_CPU_PROFILING).waitFor();
+ fullBuild( project.getFullPath() );
+ if (VERBOSE)
+ System.out.println("APT disabled: full build took " + ((System.currentTimeMillis() - start)/1000L) + " sec");
+ run.exec(CMD_PERF_SNAPSHOT).waitFor();
+ run.exec(CMD_STOP_CPU_PROFILING).waitFor();
+ expectingNoProblems();
+
+// System.gc();
+// Thread.sleep(1000);
+//
+// AptConfig.setEnabled(jproj, false);
+// start = System.currentTimeMillis();
+// fullBuild( project.getFullPath() );
+// if (VERBOSE) {
+// System.out.println("full build took " + ((System.currentTimeMillis() - start)/1000L) + " sec");
+// System.out.println("Taking heap snapshot");
+// }
+// run.exec(CMD_HEAP_SNAPSHOT).waitFor();
+// expectingNoProblems();
+ }
+
+ System.gc();
+ Thread.sleep(1000);
+
+ AptConfig.setEnabled(jproj, true);
+ start = System.currentTimeMillis();
+ if (VERBOSE)
+ System.out.println("APT enabled: starting full build");
+ fullBuild( project.getFullPath() );
+ if (VERBOSE) {
+ System.out.println("full build took " + ((System.currentTimeMillis() - start)/1000L) + " sec");
+ System.out.println("Taking heap snapshot");
+ }
+ run.exec(CMD_HEAP_SNAPSHOT).waitFor();
+ expectingNoProblems();
+
+ System.gc();
+ Thread.sleep(1000);
+
+ AptConfig.setEnabled(jproj, true);
+ start = System.currentTimeMillis();
+ if (VERBOSE)
+ System.out.println("APT enabled: starting full build");
+ run.exec(CMD_START_CPU_PROFILING).waitFor();
+ fullBuild( project.getFullPath() );
+ if (VERBOSE)
+ System.out.println("full build took " + ((System.currentTimeMillis() - start)/1000L) + " sec");
+ run.exec(CMD_PERF_SNAPSHOT).waitFor();
+ run.exec(CMD_STOP_CPU_PROFILING).waitFor();
+ expectingNoProblems();
+
+ System.gc();
+ Thread.sleep(1000);
+
+ AptConfig.setEnabled(jproj, true);
+ start = System.currentTimeMillis();
+ if (VERBOSE)
+ System.out.println("APT enabled: starting full build");
+ run.exec(CMD_START_CPU_PROFILING).waitFor();
+ fullBuild( project.getFullPath() );
+ if (VERBOSE)
+ System.out.println("full build took " + ((System.currentTimeMillis() - start)/1000L) + " sec");
+ run.exec(CMD_PERF_SNAPSHOT).waitFor();
+ run.exec(CMD_STOP_CPU_PROFILING).waitFor();
+ expectingNoProblems();
+
+ // Now delete the project!
+ if (VERBOSE)
+ System.out.println("Deleting workspace");
+ ResourcesPlugin.getWorkspace().delete(new IResource[] { project }, true, null);
+
+ }
+
+ /**
+ * Performance with files that contain annotations that will be processed
+ * with a Java 6 processor, but no file generation.
+ */
+ public void _testInterestingFilesWithJ6() throws Exception
+ {
+ final int FILES_TO_GENERATE = 2000; // total number of files to create
+ // set up project with unique name
+ IJavaProject jproj = createJavaProject(_projectName);
+ IProject project = jproj.getProject();
+
+ createInterestingFilesWithJ6(FILES_TO_GENERATE, jproj);
+
+ Runtime run = Runtime.getRuntime();
+
+ long start;
+
+ if (INCLUDE_APT_DISABLED) {
+ AptConfig.setEnabled(jproj, false);
+ start = System.currentTimeMillis();
+ run.exec(CMD_START_CPU_PROFILING).waitFor();
+ fullBuild( project.getFullPath() );
+ if (VERBOSE)
+ System.out.println("APT disabled: full build took " + ((System.currentTimeMillis() - start)/1000L) + " sec");
+ run.exec(CMD_PERF_SNAPSHOT).waitFor();
+ run.exec(CMD_STOP_CPU_PROFILING).waitFor();
+ expectingNoProblems();
+
+// System.gc();
+// Thread.sleep(1000);
+//
+// AptConfig.setEnabled(jproj, false);
+// start = System.currentTimeMillis();
+// run.exec(CMD_START_CPU_PROFILING).waitFor();
+// fullBuild( project.getFullPath() );
+// if (VERBOSE)
+// System.out.println("APT disabled: full build took " + ((System.currentTimeMillis() - start)/1000L) + " sec");
+// run.exec(CMD_PERF_SNAPSHOT).waitFor();
+// run.exec(CMD_STOP_CPU_PROFILING).waitFor();
+// expectingNoProblems();
+ }
+
+ System.gc();
+ Thread.sleep(1000);
+
+ AptConfig.setEnabled(jproj, true);
+ start = System.currentTimeMillis();
+ if (VERBOSE)
+ System.out.println("APT enabled: starting full build");
+ run.exec(CMD_START_CPU_PROFILING).waitFor();
+ fullBuild( project.getFullPath() );
+ if (VERBOSE)
+ System.out.println("full build took " + ((System.currentTimeMillis() - start)/1000L) + " sec");
+ run.exec(CMD_PERF_SNAPSHOT).waitFor();
+ run.exec(CMD_STOP_CPU_PROFILING).waitFor();
+ expectingNoProblems();
+
+// System.gc();
+// Thread.sleep(1000);
+//
+// AptConfig.setEnabled(jproj, true);
+// start = System.currentTimeMillis();
+// if (VERBOSE)
+// System.out.println("APT enabled: starting full build");
+// run.exec(CMD_START_CPU_PROFILING).waitFor();
+// fullBuild( project.getFullPath() );
+// if (VERBOSE)
+// System.out.println("full build took " + ((System.currentTimeMillis() - start)/1000L) + " sec");
+// run.exec(CMD_PERF_SNAPSHOT).waitFor();
+// run.exec(CMD_STOP_CPU_PROFILING).waitFor();
+// expectingNoProblems();
+
+ // Now delete the project!
+ if (VERBOSE)
+ System.out.println("Deleting workspace");
+ ResourcesPlugin.getWorkspace().delete(new IResource[] { project }, true, null);
+
+ if (VERBOSE)
+ System.out.println("Test complete");
+ }
+
+ /**
+ * Test with files that have meaningful processing (generation of additional types).
+ * Currently disabled.
+ */
+ public void _testGeneratingLotsOfFiles() throws Exception
+ {
+ final int FILES_TO_GENERATE = 4000; // total number of files to create
+ // set up project with unique name
+ IJavaProject jproj = createJavaProject(_projectName);
+ IProject project = jproj.getProject();
+
+ createGeneratingFiles(FILES_TO_GENERATE, jproj);
+
+ // Set some per-project preferences
+ AptConfig.setEnabled(jproj, true);
+
+ long start = System.currentTimeMillis();
+ fullBuild( project.getFullPath() );
+ if (VERBOSE)
+ System.out.println("Done with build after " + ((System.currentTimeMillis() - start)/1000L) + " sec");
+
+ expectingNoProblems();
+
+ IPath projPath = jproj.getProject().getLocation();
+ for (int i = 1; i <= FILES_TO_GENERATE; ++i) {
+ // check that file was generated
+ String genFileName = String.format(".apt_generated/g/Generated%05d.java", i);
+ File genFile = new File(projPath.append(genFileName).toOSString());
+ assertTrue("Expected generated source file " + genFileName + " was not found", genFile != null && genFile.exists());
+ // check that generated file was compiled
+ String genClassName = String.format("bin/g/Generated%05d.class", i);
+ File genClass = new File(projPath.append(genClassName).toOSString());
+ assertTrue("Compiled file " + genClassName + " was not found", genClass != null && genClass.exists());
+ }
+
+ if (VERBOSE)
+ System.out.println("Done checking output");
+
+ // Now delete the project!
+ ResourcesPlugin.getWorkspace().delete(new IResource[] { project }, true, null);
+
+ }
+
+}
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 e5340fe0c6..9736c94472 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 BEA Systems, Inc. and others
+ * Copyright (c) 2007 - 2009 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
@@ -33,6 +33,7 @@ import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.tools.FileObject;
+import javax.tools.JavaFileObject;
import javax.tools.StandardLocation;
import org.eclipse.jdt.apt.pluggable.tests.ProcessorTestStatus;
@@ -166,7 +167,7 @@ public class FilerTesterProc extends AbstractProcessor {
}
/**
- * Attempt to get an existing resource from the SOURCE_OUTPUT.
+ * Attempt to create a new resource in SOURCE_OUTPUT.
*/
public void testCreateNonSourceFile(Element e, String pkg, String relName) throws Exception {
FileObject fo = _filer.createResource(StandardLocation.SOURCE_OUTPUT,
@@ -189,6 +190,33 @@ public class FilerTesterProc extends AbstractProcessor {
}
/**
+ * Attempt to create new resources with null parentage.
+ * See <a href="http://bugs.eclipse.org/285838">Bug 285838</a>.
+ */
+ public void testNullParents(Element e, String pkg, String relName) throws Exception {
+ FileObject fo = _filer.createResource(StandardLocation.SOURCE_OUTPUT,
+ pkg, relName + ".txt", (Element[])null);
+ PrintWriter pw = null;
+ try {
+ pw = new PrintWriter(fo.openWriter());
+ pw.println("Hello world");
+ } finally {
+ if (pw != null)
+ pw.close();
+ }
+
+ JavaFileObject jfo = _filer.createSourceFile(pkg + "/" + relName, (Element[])null);
+ pw = null;
+ try {
+ pw = new PrintWriter(jfo.openWriter());
+ pw.println("package " + pkg + ";\npublic class " + relName + "{ }");
+ } finally {
+ if (pw != null)
+ pw.close();
+ }
+ }
+
+ /**
* Test the toUri() method on various file objects.
*/
public void testURI(Element e, String pkg, String relName) throws Exception {

Back to the top