### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/JavaProject.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java,v retrieving revision 1.376 diff -u -r1.376 JavaProject.java --- model/org/eclipse/jdt/internal/core/JavaProject.java 24 Nov 2006 01:32:03 -0000 1.376 +++ model/org/eclipse/jdt/internal/core/JavaProject.java 6 Dec 2006 17:48:27 -0000 @@ -64,6 +64,7 @@ import org.eclipse.jdt.internal.compiler.util.ObjectVector; import org.eclipse.jdt.internal.compiler.util.SuffixConstants; import org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo; +import org.eclipse.jdt.internal.core.builder.JavaBuilder; import org.eclipse.jdt.internal.core.eval.EvaluationContextWrapper; import org.eclipse.jdt.internal.core.util.MementoTokenizer; import org.eclipse.jdt.internal.core.util.Messages; @@ -805,6 +806,7 @@ IJavaModelMarker.ID, IJavaModelMarker.ARGUMENTS , IJavaModelMarker.CATEGORY_ID, + IMarker.GENERATED_BY, }, new Object[] { status.getMessage(), @@ -814,7 +816,8 @@ isClasspathFileFormatProblem ? "true" : "false",//$NON-NLS-1$ //$NON-NLS-2$ new Integer(status.getCode()), Util.getProblemArgumentsForMarker(arguments) , - new Integer(CategorizedProblem.CAT_BUILDPATH) + new Integer(CategorizedProblem.CAT_BUILDPATH), + JavaBuilder.GENERATED_BY, } ); } catch (CoreException e) { Index: compiler/org/eclipse/jdt/core/compiler/CategorizedProblem.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/CategorizedProblem.java,v retrieving revision 1.17 diff -u -r1.17 CategorizedProblem.java --- compiler/org/eclipse/jdt/core/compiler/CategorizedProblem.java 28 Mar 2006 20:30:01 -0000 1.17 +++ compiler/org/eclipse/jdt/core/compiler/CategorizedProblem.java 6 Dec 2006 17:48:26 -0000 @@ -28,7 +28,7 @@ *
  • its message description and a predicate to check its severity (warning or error).
  • *
  • its ID : a number identifying the very nature of this problem. All possible IDs for standard Java * problems are listed as constants on IProblem,
  • - *
  • its marker type : a string identfying the problem creator. It corresponds to the marker type + *
  • its marker type : a string identifying the problem creator. It corresponds to the marker type * chosen if this problem was to be persisted. Standard Java problems are associated to marker * type "org.eclipse.jdt.core.problem"),
  • *
  • its category ID : a number identifying the category this problem belongs to. All possible IDs for @@ -46,6 +46,14 @@ * participating in compilation operations, so as to allow participant to contribute their own marker types, and thus * defining their own domain specific problem/category IDs. * + * Note: standard Java problems produced by Java default tooling will set the + * marker IMarker#GENERATED_BY attribute to JavaBuilder#GENERATED_BY; compiler + * participants may specify the IMarker#GENERATED_BY attribute of their markers + * by adding it to the extra marker attributes of the problems they generate; + * markers resulting from compiler participants' problems that do not have the + * IMarker#GENERATED_BY extra attribute set do not have the IMarker#GENERATED_BY + * attribute set either. + * * @since 3.2 */ public abstract class CategorizedProblem implements IProblem { Index: model/org/eclipse/jdt/internal/core/eval/RequestorWrapper.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/eval/RequestorWrapper.java,v retrieving revision 1.13 diff -u -r1.13 RequestorWrapper.java --- model/org/eclipse/jdt/internal/core/eval/RequestorWrapper.java 29 Mar 2006 03:09:16 -0000 1.13 +++ model/org/eclipse/jdt/internal/core/eval/RequestorWrapper.java 6 Dec 2006 17:48:27 -0000 @@ -17,6 +17,7 @@ import org.eclipse.jdt.core.compiler.CategorizedProblem; import org.eclipse.jdt.core.eval.ICodeSnippetRequestor; import org.eclipse.jdt.internal.compiler.ClassFile; +import org.eclipse.jdt.internal.core.builder.JavaBuilder; import org.eclipse.jdt.internal.eval.IRequestor; public class RequestorWrapper implements IRequestor { @@ -60,6 +61,7 @@ //marker.setAttribute(IMarker.LOCATION, "#" + problem.getSourceLineNumber()); marker.setAttribute(IMarker.MESSAGE, problem.getMessage()); marker.setAttribute(IMarker.SEVERITY, (problem.isWarning() ? IMarker.SEVERITY_WARNING : IMarker.SEVERITY_ERROR)); + marker.setAttribute(IMarker.GENERATED_BY, JavaBuilder.GENERATED_BY); this.requestor.acceptProblem(marker, new String(fragmentSource), fragmentKind); } catch (CoreException e) { e.printStackTrace(); Index: model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java,v retrieving revision 1.123 diff -u -r1.123 JavaBuilder.java --- model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java 13 Jun 2006 13:00:44 -0000 1.123 +++ model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java 6 Dec 2006 17:48:27 -0000 @@ -35,6 +35,7 @@ BuildNotifier notifier; char[][] extraResourceFileFilters; String[] extraResourceFolderFilters; +public static final String GENERATED_BY = "JDT"; //$NON-NLS-1$ public static boolean DEBUG = false; @@ -203,12 +204,14 @@ marker.setAttribute(IMarker.MESSAGE, Messages.bind(Messages.build_inconsistentProject, e.getLocalizedMessage())); marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); marker.setAttribute(IJavaModelMarker.CATEGORY_ID, CategorizedProblem.CAT_BUILDPATH); + marker.setAttribute(IMarker.GENERATED_BY, JavaBuilder.GENERATED_BY); } catch (ImageBuilderInternalException e) { Util.log(e.getThrowable(), "JavaBuilder handling ImageBuilderInternalException while building: " + currentProject.getName()); //$NON-NLS-1$ IMarker marker = currentProject.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER); marker.setAttribute(IMarker.MESSAGE, Messages.bind(Messages.build_inconsistentProject, e.getLocalizedMessage())); marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); marker.setAttribute(IJavaModelMarker.CATEGORY_ID, CategorizedProblem.CAT_BUILDPATH); + marker.setAttribute(IMarker.GENERATED_BY, JavaBuilder.GENERATED_BY); } catch (MissingClassFileException e) { // do not log this exception since its thrown to handle aborted compiles because of missing class files if (DEBUG) @@ -217,6 +220,7 @@ marker.setAttribute(IMarker.MESSAGE, Messages.bind(Messages.build_incompleteClassPath, e.missingClassFile)); marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); marker.setAttribute(IJavaModelMarker.CATEGORY_ID, CategorizedProblem.CAT_BUILDPATH); + marker.setAttribute(IMarker.GENERATED_BY, JavaBuilder.GENERATED_BY); } catch (MissingSourceFileException e) { // do not log this exception since its thrown to handle aborted compiles because of missing source files if (DEBUG) @@ -225,6 +229,7 @@ IMarker marker = currentProject.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER); marker.setAttribute(IMarker.MESSAGE, Messages.bind(Messages.build_missingSourceFile, e.missingSourceFile)); marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); + marker.setAttribute(IMarker.GENERATED_BY, JavaBuilder.GENERATED_BY); } finally { if (!ok) // If the build failed, clear the previously built state, forcing a full build next time. @@ -286,6 +291,7 @@ IMarker marker = currentProject.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER); marker.setAttribute(IMarker.MESSAGE, Messages.bind(Messages.build_inconsistentProject, e.getLocalizedMessage())); marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); + marker.setAttribute(IMarker.GENERATED_BY, JavaBuilder.GENERATED_BY); } finally { notifier.done(); cleanup(); @@ -606,6 +612,7 @@ marker.setAttribute(IMarker.MESSAGE, Messages.build_abortDueToClasspathProblems); marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); marker.setAttribute(IJavaModelMarker.CATEGORY_ID, CategorizedProblem.CAT_BUILDPATH); + marker.setAttribute(IMarker.GENERATED_BY, JavaBuilder.GENERATED_BY); return false; } @@ -644,6 +651,7 @@ : Messages.bind(Messages.build_prereqProjectMustBeRebuilt, p.getName())); marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); marker.setAttribute(IJavaModelMarker.CATEGORY_ID, CategorizedProblem.CAT_BUILDPATH); + marker.setAttribute(IMarker.GENERATED_BY, JavaBuilder.GENERATED_BY); return false; } } Index: model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java,v retrieving revision 1.99 diff -u -r1.99 AbstractImageBuilder.java --- model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java 13 Sep 2006 18:41:05 -0000 1.99 +++ model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java 6 Dec 2006 17:48:27 -0000 @@ -71,6 +71,7 @@ IMarker.CHAR_END, IMarker.LINE_NUMBER, IMarker.USER_EDITABLE, + IMarker.GENERATED_BY, }; public final static Integer S_ERROR = new Integer(IMarker.SEVERITY_ERROR); public final static Integer S_WARNING = new Integer(IMarker.SEVERITY_WARNING); @@ -318,8 +319,8 @@ int start = range == null ? 0 : range.getOffset(); int end = range == null ? 1 : start + range.getLength(); marker.setAttributes( - new String[] {IMarker.MESSAGE, IMarker.SEVERITY, IMarker.CHAR_START, IMarker.CHAR_END}, - new Object[] {message, new Integer(severity), new Integer(start), new Integer(end)}); + new String[] {IMarker.MESSAGE, IMarker.SEVERITY, IMarker.CHAR_START, IMarker.CHAR_END, IMarker.GENERATED_BY}, + new Object[] {message, new Integer(severity), new Integer(start), new Integer(end), JavaBuilder.GENERATED_BY}); } catch (CoreException e) { throw internalException(e); } @@ -543,6 +544,9 @@ * - its priority reflects the severity of the problem * - its range is the problem's range * - it has an extra attribute "ID" which holds the problem's id + * - it's GENERATED_BY attribute is positioned to JavaBuilder.GENERATED_BY if + * the problem was generated by JDT; else the GENERATED_BY attribute is + * carried from the problem to the marker in extra attributes, if present. */ protected void storeProblemsFor(SourceFile sourceFile, CategorizedProblem[] problems) throws CoreException { if (sourceFile == null || problems == null || problems.length == 0) return; @@ -560,8 +564,9 @@ } String markerType = problem.getMarkerType(); + boolean managedProblem = false; if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(markerType) - || managedMarkerTypes.contains(markerType)) { + || (managedProblem = managedMarkerTypes.contains(markerType))) { IMarker marker = resource.createMarker(markerType); // standard attributes @@ -575,9 +580,13 @@ new Integer(problem.getSourceEnd() + 1), // end new Integer(problem.getSourceLineNumber()), // line Util.getProblemArgumentsForMarker(problem.getArguments()), // arguments - new Integer(problem.getCategoryID()), // category ID + new Integer(problem.getCategoryID()) // category ID } ); + // GENERATED_BY attribute for JDT problems + if (!managedProblem) { + marker.setAttribute(IMarker.GENERATED_BY, JavaBuilder.GENERATED_BY); + } // optional extra attributes String[] extraAttributeNames = problem.getExtraMarkerAttributeNames(); int extraLength = extraAttributeNames == null ? 0 : extraAttributeNames.length; @@ -614,6 +623,7 @@ new Integer(task.getSourceEnd() + 1), new Integer(task.getSourceLineNumber()), Boolean.FALSE, + JavaBuilder.GENERATED_BY }); String[] extraAttributeNames = task.getExtraMarkerAttributeNames(); int extraLength = extraAttributeNames == null ? 0 : extraAttributeNames.length; #P org.eclipse.jdt.core.tests.builder Index: src/org/eclipse/jdt/core/tests/builder/Problem.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Problem.java,v retrieving revision 1.12 diff -u -r1.12 Problem.java --- src/org/eclipse/jdt/core/tests/builder/Problem.java 29 Mar 2006 03:16:23 -0000 1.12 +++ src/org/eclipse/jdt/core/tests/builder/Problem.java 6 Dec 2006 17:48:28 -0000 @@ -19,6 +19,7 @@ private String message; private IPath resourcePath; private int start = -1, end = -1, categoryId = -1; + private String generatedBy; public Problem(String location, String message, IPath resourcePath, int start, int end, int categoryId){ this.location = location; @@ -41,11 +42,22 @@ this.start = marker.getAttribute(IMarker.CHAR_START, -1); this.end = marker.getAttribute(IMarker.CHAR_END, -1); this.categoryId = marker.getAttribute(IJavaModelMarker.CATEGORY_ID, -1); + this.generatedBy = marker.getAttribute(IMarker.GENERATED_BY, "missing"); } public int getCategoryId() { return categoryId; } +/** + * Return the IMarker.GENERATED_BY attribute of the underlying marker if any. + * Value null denotes a problem created from explicit structural attributes + * (instead of using a source marker). Value "missing" denotes that the marker + * used to initialize the problem had no IMarker.GENERATED_BY attribute. + * @return the IMarker.GENERATED_BY attribute of the underlying marker if any + */ +public String getGeneratedBy() { + return this.generatedBy; +} /** * Gets the location. * @return Returns a String Index: src/org/eclipse/jdt/core/tests/builder/ErrorsTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ErrorsTests.java,v retrieving revision 1.17 diff -u -r1.17 ErrorsTests.java --- src/org/eclipse/jdt/core/tests/builder/ErrorsTests.java 29 Mar 2006 03:16:23 -0000 1.17 +++ src/org/eclipse/jdt/core/tests/builder/ErrorsTests.java 6 Dec 2006 17:48:28 -0000 @@ -15,6 +15,7 @@ import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.compiler.CategorizedProblem; import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.core.builder.JavaBuilder; /** @@ -98,4 +99,96 @@ expectingNoProblems(); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158611 +// Checking the GENERATED_BY attribute +public void test0100() throws JavaModelException { + IPath projectPath = env.addProject("Project"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + IPath classTest1 = env.addClass(root, "p1", "Test1", + "package p1;\n" + + "public class Test1 extends Test2 {}" + ); + fullBuild(); + Problem[] prob1 = env.getProblemsFor(classTest1); + expectingSpecificProblemFor(classTest1, new Problem("p1", "Test2 cannot be resolved to a type", classTest1, 39, 44, 40)); + assertEquals(JavaBuilder.GENERATED_BY, prob1[0].getGeneratedBy()); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158611 +// Checking the GENERATED_BY attribute +public void test0101() throws JavaModelException { + IPath projectPath = env.addProject("Project"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + IPath classTest1 = env.addClass(root, "p1", "Test1", + "package p1;\n" + + "public class Test1 extends {}" + ); + fullBuild(); + Problem[] prob1 = env.getProblemsFor(classTest1); + expectingSpecificProblemFor(classTest1, new Problem("p1", "Syntax error on token \"extends\", Type expected after this token", classTest1, 31, 38, 20)); + assertEquals(JavaBuilder.GENERATED_BY, prob1[0].getGeneratedBy()); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158611 +// Checking the GENERATED_BY attribute +public void test0102() throws JavaModelException { + IPath projectPath = env.addProject("Project"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + IPath classTest1 = env.addClass(root, "p1", "Test1", + "package p1;\n" + + "public class Test1 {\n" + + " private static int i;\n" + + " int j = i;\n" + + "}\n" + + "class Test2 {\n" + + " static int i = Test1.i;\n" + + "}\n" + ); + fullBuild(); + Problem[] prob1 = env.getProblemsFor(classTest1); + expectingSpecificProblemFor(classTest1, new Problem("p1", "The field Test1.i is not visible", classTest1, 109, 110, 50)); + assertEquals(JavaBuilder.GENERATED_BY, prob1[0].getGeneratedBy()); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158611 +// Checking the GENERATED_BY attribute +public void test0103() throws JavaModelException { + IPath projectPath = env.addProject("Project"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + IPath classTest1 = env.addClass(root, "p1", "Test1", + "package p1;\n" + + "public class Test1 {\n" + + " // TODO: marker only\n" + + "}\n" + ); + fullBuild(); + Problem[] prob1 = env.getProblemsFor(classTest1); + expectingSpecificProblemFor(classTest1, new Problem("p1", "TODO : marker only", classTest1, 38, 55, -1)); + assertEquals(JavaBuilder.GENERATED_BY, prob1[0].getGeneratedBy()); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158611 +// Checking the GENERATED_BY attribute +public void test0104() throws JavaModelException { + IPath projectPath = env.addProject("Project"); + env.removePackageFragmentRoot(projectPath, ""); + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + IPath classTest1 = env.addClass(root, "p1", "Test1", + "package p1;\n" + + "public class Test1 {}" + ); + fullBuild(); + Problem[] prob1 = env.getProblemsFor(classTest1); + expectingSpecificProblemFor(classTest1, + new Problem("p1", "The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files", classTest1, 0, 1, 10)); + assertEquals(JavaBuilder.GENERATED_BY, prob1[0].getGeneratedBy()); +} } Index: src/org/eclipse/jdt/core/tests/builder/ParticipantBuildTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ParticipantBuildTests.java,v retrieving revision 1.15 diff -u -r1.15 ParticipantBuildTests.java --- src/org/eclipse/jdt/core/tests/builder/ParticipantBuildTests.java 3 Apr 2006 14:40:32 -0000 1.15 +++ src/org/eclipse/jdt/core/tests/builder/ParticipantBuildTests.java 6 Dec 2006 17:48:28 -0000 @@ -419,4 +419,73 @@ fullBuild(projectPath); expectingNoProblems(); } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158611 +// Checking the GENERATED_BY attribute +public void test1001() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + env.addClass(root, "p", "X", + "package p;\n" + + "public class X { /* generate problem*/ }" + ); + new BuildTestParticipant() { + public void buildStarting(BuildContext[] files, boolean isBatch) { + for (int i = 0, total = files.length; i < total; i++) { + BuildContext context = files[i]; + if (CharOperation.indexOf("generate problem".toCharArray(), + context.getContents(), true) != -1) { + context.recordNewProblems(new CategorizedProblem[] { + new ParticipantProblem("Participant problem", context.getFile().getFullPath().toString())}); + } + } + } + }; + fullBuild(projectPath); + Problem[] problems = env.getProblemsFor(projectPath, "org.eclipse.jdt.core.tests.compile.problem"); + assertNotNull("null problems array", problems); + assertEquals("unexpected problems count", 1, problems.length); + assertEquals("unexpected generated by attribute", "missing", problems[0].getGeneratedBy()); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158611 +// Checking the GENERATED_BY attribute +public void test1002() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + env.addClass(root, "p", "X", + "package p;\n" + + "public class X { /* generate problem*/ }" + ); + final String specificGeneratedBy = "specific"; + new BuildTestParticipant() { + public void buildStarting(BuildContext[] files, boolean isBatch) { + for (int i = 0, total = files.length; i < total; i++) { + BuildContext context = files[i]; + if (CharOperation.indexOf("generate problem".toCharArray(), + context.getContents(), true) != -1) { + context.recordNewProblems(new CategorizedProblem[] { + new ParticipantProblem("Participant problem", context.getFile().getFullPath().toString()) { + public String[] getExtraMarkerAttributeNames() { + return new String[] {IMarker.GENERATED_BY}; + } + public Object[] getExtraMarkerAttributeValues() { + return new String[] {specificGeneratedBy}; + } + }}); + } + } + } + }; + fullBuild(projectPath); + Problem[] problems = env.getProblemsFor(projectPath, "org.eclipse.jdt.core.tests.compile.problem"); + assertNotNull("null problems array", problems); + assertEquals("unexpected problems count", 1, problems.length); + assertEquals("unexpected generated by attribute", specificGeneratedBy, problems[0].getGeneratedBy()); +} }