### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.apt.pluggable.tests Index: src/org/eclipse/jdt/apt/pluggable/tests/FilerTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.apt.pluggable.tests/src/org/eclipse/jdt/apt/pluggable/tests/FilerTests.java,v retrieving revision 1.5 diff -u -r1.5 FilerTests.java --- src/org/eclipse/jdt/apt/pluggable/tests/FilerTests.java 7 Sep 2007 02:28:21 -0000 1.5 +++ src/org/eclipse/jdt/apt/pluggable/tests/FilerTests.java 15 Sep 2007 00:53:05 -0000 @@ -11,12 +11,21 @@ package org.eclipse.jdt.apt.pluggable.tests; +import java.util.Map; + import junit.framework.Test; import junit.framework.TestSuite; +import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.apt.core.internal.util.FactoryContainer; +import org.eclipse.jdt.apt.core.internal.util.FactoryPath; +import org.eclipse.jdt.apt.core.internal.util.FactoryContainer.FactoryType; import org.eclipse.jdt.apt.core.util.AptConfig; import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.tests.builder.Problem; /** * Basic tests for the Filer interface in the IDE. @@ -78,4 +87,57 @@ expectingNoFile( proj, ".apt_generated/summary.txt" ); } + /** + * Test generation of a source file that is referenced by the parent, using the GenClass6 annotation + * @see javax.annotation.processing.Filer#createSourceFile(CharSequence, javax.lang.model.element.Element...) + */ + public void testCreateSourceFileWithGenReference() throws Throwable + { + // Temporary workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=201931 + // Bail out on Linux + String osName = System.getProperty("os.name"); + if (null == osName || !osName.contains("Windows")) { + return; + } + + IJavaProject jproj = createJavaProject(_projectName); + IProject proj = jproj.getProject(); + IdeTestUtils.copyResources(proj, "targets/filer02a", "src/targets/filer"); + + // Make sure that there are no Java 5 processors on the factory path - see comment below. + FactoryPath fp = (FactoryPath) AptConfig.getFactoryPath(jproj); + for (Map.Entry entry : fp.getAllContainers().entrySet()) { + if (entry.getKey().getType() == FactoryType.PLUGIN) { + String id = entry.getKey().getId(); + if (!Apt6TestsPlugin.PLUGIN_ID.equals(id)) { + fp.disablePlugin(id); + } + } + } + AptConfig.setFactoryPath(jproj, fp); + AptConfig.setEnabled(jproj, true); + fullBuild(); + expectingNoProblems(); + + // Check whether generated sources were generated and compiled + expectingFile(proj, ".apt_generated/gen6/Generated02.java"); + final String[] expectedClasses = { "targets.filer.Parent02", "gen6.Generated02" }; + expectingUniqueCompiledClasses(expectedClasses); + + // Modify target file to change name of generated file and incrementally rebuild; + // generated file should be deleted. + IdeTestUtils.copyResources(proj, "targets/filer02b", "src/targets/filer"); + incrementalBuild(); + + IPath parentPath = proj.getFullPath().append("src/targets/filer/Parent02.java"); + expectingOnlySpecificProblemFor(parentPath, new Problem("Parent02", "gen6.Generated02 cannot be resolved to a type", parentPath, 842, 858, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); + + // This test only works if there are no Java 5 processors (e.g., apt.tests plugin) in the factory path. + // If Java 5 processors are present, then gen6.Generated02 will also be recompiled, before it's deleted. + final String[] expectedClasses2 = { "gen6.XxxGenerated02", "targets.filer.Parent02" }; + expectingUniqueCompiledClasses(expectedClasses2); + + expectingNoFile(proj, ".apt_generated/gen6/Generated02.java"); + } + } Index: resources/targets/filer02a/Parent02.java =================================================================== RCS file: resources/targets/filer02a/Parent02.java diff -N resources/targets/filer02a/Parent02.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ resources/targets/filer02a/Parent02.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2007 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: + * wharley@bea.com - initial API and implementation + *******************************************************************************/ + +package targets.filer; + +import org.eclipse.jdt.apt.pluggable.tests.annotations.GenClass6; + +/** + * Processing this class should result in creation of a source file, + * thereby allowing this class to compile + */ +@GenClass6(name="Generated02", pkg="gen6") +public class Parent02 { + gen6.Generated02 _gen; +} + + + Index: resources/targets/filer02b/Parent02.java =================================================================== RCS file: resources/targets/filer02b/Parent02.java diff -N resources/targets/filer02b/Parent02.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ resources/targets/filer02b/Parent02.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2007 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: + * wharley@bea.com - initial API and implementation + *******************************************************************************/ + +package targets.filer; + +import org.eclipse.jdt.apt.pluggable.tests.annotations.GenClass6; + +/** + * Processing this class should result in removal of the previously + * generated type and creation of a new one, resulting in a compilation error. + */ +@GenClass6(name="XxxGenerated02", pkg="gen6") +public class Parent02 { + gen6.Generated02 _gen; +} +