diff options
| author | Szymon Ptaszkiewicz | 2012-02-22 09:35:17 +0000 |
|---|---|---|
| committer | Satyam Kandula | 2012-02-22 09:35:17 +0000 |
| commit | 3e46d275b92d309fd1fe675f261b23afc851c7bf (patch) | |
| tree | 8906930345341f19bbd234e0a2c0b1d037035979 | |
| parent | 02009b41ec945f5cfcf629234ac75cbc76ce6809 (diff) | |
| download | eclipse.jdt.core-3e46d275b92d309fd1fe675f261b23afc851c7bf.tar.gz eclipse.jdt.core-3e46d275b92d309fd1fe675f261b23afc851c7bf.tar.xz eclipse.jdt.core-3e46d275b92d309fd1fe675f261b23afc851c7bf.zip | |
Fix for 220928: [buildpath] Should be able to ignore warnings fromv20120222-0935
certain source folders
26 files changed, 1174 insertions, 41 deletions
diff --git a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Options.java b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Options.java index 7b29f99331..2ba27f44f2 100644 --- a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Options.java +++ b/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Options.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2010 IBM Corporation and others. + * Copyright (c) 2006, 2012 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 @@ -41,7 +41,6 @@ public final class Options { Options.ZERO_ARGUMENT_OPTIONS.add("-inlineJSR");//$NON-NLS-1$ Options.ZERO_ARGUMENT_OPTIONS.add("-g");//$NON-NLS-1$ Options.ZERO_ARGUMENT_OPTIONS.add("-g:none");//$NON-NLS-1$ - Options.ZERO_ARGUMENT_OPTIONS.add("-nowarn");//$NON-NLS-1$ Options.ZERO_ARGUMENT_OPTIONS.add("-warn:none");//$NON-NLS-1$ Options.ZERO_ARGUMENT_OPTIONS.add("-preserveAllLocals");//$NON-NLS-1$ Options.ZERO_ARGUMENT_OPTIONS.add("-enableJavadoc");//$NON-NLS-1$ @@ -243,6 +242,28 @@ public final class Options { return 0; } } + if (option.startsWith("-nowarn")) {//$NON-NLS-1$ + switch (option.length()) { + case 7: + return 0; + case 8: + return -1; + default: + int foldersStart = option.indexOf('[') + 1; + int foldersEnd = option.lastIndexOf(']'); + if (foldersStart <= 8 || foldersEnd == -1 + || foldersStart > foldersEnd + || foldersEnd < option.length() - 1) { + return -1; + } + String folders = option.substring(foldersStart, foldersEnd); + if (folders.length() > 0) { + return 0; + } else { + return -1; + } + } + } if (option.startsWith("-J")//$NON-NLS-1$ || option.startsWith("-X")//$NON-NLS-1$ || option.startsWith("-A")) {//$NON-NLS-1$ diff --git a/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ErrorsTests.java b/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ErrorsTests.java index f11a112c40..93ead6b1fc 100644 --- a/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ErrorsTests.java +++ b/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ErrorsTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -17,14 +17,17 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.util.Arrays; import java.util.Comparator; +import java.util.Hashtable; -import junit.framework.*; +import junit.framework.Test; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.IClasspathAttribute; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.IRegion; import org.eclipse.jdt.core.JavaCore; @@ -43,6 +46,8 @@ import org.eclipse.jdt.internal.core.builder.JavaBuilder; * Basic errors tests of the image builder. */ public class ErrorsTests extends BuilderTests { + private static final IClasspathAttribute ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE = JavaCore.newClasspathAttribute(IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS, "true"); + private static final Comparator COMPARATOR = new Comparator() { public int compare(Object o1, Object o2) { IResource resource1 = (IResource) o1; @@ -441,4 +446,199 @@ private String getResourceOuput(IResource[] resources) { writer.close(); return Util.convertToIndependantLineDelimiter(String.valueOf(stringWriter)); } + +// ignore optional errors +public void test0108() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); + + JavaCore.setOptions(newOptions); + + IPath projectPath = env.addProject("P"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + env.setOutputFolder(projectPath, "bin"); + IPath root = new Path("/P/src"); + env.addEntry(projectPath, JavaCore.newSourceEntry(root, null, null, + null, new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE })); + + env.addClass(root, "p", "X", + "package p;\n" + + "public class X {\n" + + " public void foo() {\n" + + " int i;\n" + + " }\n" + + "}"); + + fullBuild(projectPath); + expectingNoProblems(); + + JavaCore.setOptions(options); +} + +// two different source folders ignore only from one +public void test0109() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); + + JavaCore.setOptions(newOptions); + + IPath projectPath = env.addProject("P"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + env.setOutputFolder(projectPath, "bin"); + IPath src = new Path("/P/src"); + IPath src2 = new Path("/P/src2"); + env.addEntry(projectPath, JavaCore.newSourceEntry(src, null, null, + null, new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE })); + env.addEntry(projectPath, JavaCore.newSourceEntry(src2)); + + env.addClass(src, "p", "X", + "package p;\n" + + "public class X {\n" + + " public void foo() {\n" + + " int i;\n" + + " }\n" + + "}"); + + IPath classY = env.addClass(src2, "q", "Y", + "package q;\n" + + "public class Y {\n" + + " public void foo() {\n" + + " int i;\n" + + " }\n" + + "}"); + + fullBuild(projectPath); + expectingNoProblemsFor(src); + expectingOnlySpecificProblemFor(classY, new Problem("q", "The value of the local variable i is not used", classY, 55, 56, CategorizedProblem.CAT_UNNECESSARY_CODE, IMarker.SEVERITY_ERROR)); + + JavaCore.setOptions(options); +} + +// two different source folders ignore from both +public void test0110() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); + + JavaCore.setOptions(newOptions); + + IPath projectPath = env.addProject("P"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + env.setOutputFolder(projectPath, "bin"); + IPath src = new Path("/P/src"); + IPath src2 = new Path("/P/src2"); + env.addEntry(projectPath, JavaCore.newSourceEntry(src, null, null, + null, new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE })); + env.addEntry(projectPath, JavaCore.newSourceEntry(src2, null, null, + null, new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE })); + + env.addClass(src, "p", "X", + "package p;\n" + + "public class X {\n" + + " public void foo() {\n" + + " int i;\n" + + " }\n" + + "}"); + + env.addClass(src2, "q", "Y", + "package q;\n" + + "public class Y {\n" + + " public void foo() {\n" + + " int i;\n" + + " }\n" + + "}"); + + fullBuild(projectPath); + expectingNoProblems(); + + JavaCore.setOptions(options); +} + +//non-optional errors cannot be ignored +public void test0111() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); + + JavaCore.setOptions(newOptions); + + IPath projectPath = env.addProject("P"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + env.setOutputFolder(projectPath, "bin"); + IPath root = new Path("/P/src"); + env.addEntry(projectPath, JavaCore.newSourceEntry(root, null, null, + null, new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE })); + + IPath classX = env.addClass(root, "p", "X", + "package p;\n" + + "public class X {\n" + + " public void foo() {\n" + + " int i;\n" + + " }\n" + + " public void bar() {\n" + + " a++;\n" + + " }\n" + + "}"); + + fullBuild(projectPath); + expectingOnlySpecificProblemFor(classX, new Problem("p", "a cannot be resolved to a variable", classX, 84, 85, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); + + JavaCore.setOptions(options); +} + +//task tags cannot be ignored +public void test0112() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); + newOptions.put(JavaCore.COMPILER_TASK_TAGS, "TODO"); + newOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "NORMAL"); + + JavaCore.setOptions(newOptions); + + IPath projectPath = env.addProject("P"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + env.setOutputFolder(projectPath, "bin"); + IPath root = new Path("/P/src"); + env.addEntry(projectPath, JavaCore.newSourceEntry(root, null, null, + null, new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE })); + + IPath classX = env.addClass(root, "p", "X", + "package p;\n" + + "public class X {\n" + + " public void foo() {\n" + + " int i;\n" + + " }\n" + + " public void bar() {\n" + + " // TODO nothing\n" + + " }\n" + + "}"); + + fullBuild(projectPath); + expectingOnlySpecificProblemFor(classX, new Problem("p", "TODO nothing", classX, 87, 99, -1, IMarker.SEVERITY_ERROR)); + + JavaCore.setOptions(options); +} } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java index 2714e691c9..af0d0b0cf6 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java @@ -1577,6 +1577,9 @@ public void test012(){ " -deprecation + deprecation outside deprecated code (equivalent to\n" + " -warn:+deprecation)\n" + " -nowarn -warn:none disable all warnings\n" + + " -nowarn:[<directories separated by " + File.pathSeparator+ ">]\n" + + " specify directories from which optional problems should\n" + + " be ignored\n" + " -?:warn -help:warn display advanced warning options\n" + " \n" + " Error options:\n" + @@ -1689,6 +1692,9 @@ public void test012b(){ " Warning options:\n" + " -deprecation + deprecation outside deprecated code\n" + " -nowarn -warn:none disable all warnings\n" + + " -nowarn:[<directories separated by " + File.pathSeparator+ ">]\n" + + " specify directories from which optional problems should\n" + + " be ignored\n" + " -warn:<warnings separated by ,> enable exactly the listed warnings\n" + " -warn:+<warnings separated by ,> enable additional warnings\n" + " -warn:-<warnings separated by ,> disable specific warnings\n" + @@ -12696,4 +12702,349 @@ public void test316_warn_options() { "Token nullAnnot(foo|bar) is not in the expected format \"nullAnnot(<non null annotation name> | <nullable annotation name> | <non-null by default annotation name>)\"\n", true); } + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//default +public void test317_nowarn_options() { + this.runConformTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -warn:javadoc -nowarn:[\"" + + OUTPUT_DIR + File.separator + "src" + + "\"] -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//two different source folders ignore only from one +public void test318_nowarn_options() { + this.runConformTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + "src2/Y.java", + "public class Y {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " \"" + OUTPUT_DIR + File.separator + "src2/Y.java\"" + + " -warn:javadoc -nowarn:[" + + "\"" + OUTPUT_DIR + File.separator + "src" + + "\"] -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/src2/Y.java (at line 3)\n" + + " @param\n" + + " ^^^^^\n" + + "Javadoc: Missing parameter name\n" + + "----------\n" + + "1 problem (1 warning)", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//two different source folders ignore from both +public void test319_nowarn_options() { + this.runConformTest( + new String[] { + "src1/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + "src2/Y.java", + "public class Y {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "src1/X.java\"" + + " \"" + OUTPUT_DIR + File.separator + "src2/Y.java\"" + + " -warn:javadoc -nowarn:[" + + "\"" + OUTPUT_DIR + File.separator + "src1\"" + File.pathSeparator + + "\"" + OUTPUT_DIR + File.separator + + "src2\"] -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//two different source folders ignore from both using multiple -nowarn +public void test320_nowarn_options() { + this.runConformTest( + new String[] { + "src1/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + "src2/Y.java", + "public class Y {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "src1/X.java\"" + + " \"" + OUTPUT_DIR + File.separator + "src2/Y.java\"" + + " -warn:javadoc -nowarn:[" + + "\"" + OUTPUT_DIR + File.separator + "src1\"] -nowarn:[" + + "\"" + OUTPUT_DIR + File.separator + "src2\"] " + + "-proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//option syntax error -nowarn: +public void test321_nowarn_options() { + this.runNegativeTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -warn:javadoc -nowarn: -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "invalid syntax for nowarn option: -nowarn:\n", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//option syntax error -nowarn:[ +public void test322_nowarn_options() { + this.runNegativeTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -warn:javadoc -nowarn:[ -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "invalid syntax for nowarn option: -nowarn:[\n", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//option syntax error -nowarn:[src +public void test323_nowarn_options() { + this.runNegativeTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -warn:javadoc -nowarn:[src -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "invalid syntax for nowarn option: -nowarn:[src\n", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//option syntax error -nowarn:src] +public void test324_nowarn_options() { + this.runNegativeTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -warn:javadoc -nowarn:src] -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "invalid syntax for nowarn option: -nowarn:src]\n", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//option syntax error -nowarn[src] +public void test325_nowarn_options() { + this.runNegativeTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -warn:javadoc -nowarn[src] -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "invalid syntax for nowarn option: -nowarn[src]\n", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//option syntax error -nowarn:[src1]src2 +public void test326_nowarn_options() { + this.runNegativeTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -warn:javadoc -nowarn:[src1]src2 -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "invalid syntax for nowarn option: -nowarn:[src1]src2\n", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//option syntax error -nowarn:[] +public void test327_nowarn_options() { + this.runNegativeTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -warn:javadoc -nowarn:[] -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "invalid syntax for nowarn option: -nowarn:[]\n", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//non-optional errors cannot be ignored +public void test328_nowarn_options() { + this.runNegativeTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " a++;\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -warn:javadoc -nowarn:[" + + "\"" + OUTPUT_DIR + File.separator + "src]\" -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/X.java (at line 6)\n" + + " a++;\n" + + " ^\n" + + "a cannot be resolved to a variable\n" + + "----------\n" + + "1 problem (1 error)", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//task tags cannot be ignored +public void test329_nowarn_options() { + this.runConformTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " // TODO nothing\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -warn:javadoc,tasks(TODO) -nowarn:[" + + "\"" + OUTPUT_DIR + File.separator + "src]\" -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/src/X.java (at line 6)\n" + + " // TODO nothing\n" + + " ^^^^^^^^^^^^\n" + + "TODO nothing\n" + + "----------\n" + + "1 problem (1 warning)", + true); +} } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java index 537f730fde..e33db135cc 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -130,6 +130,9 @@ private static Class[] getAllTestClasses() { // Access restrictions tests AccessRestrictionsTests.class, + // Ignore optional problems from source folders tests + IgnoreOptionalProblemsFromSourceFoldersTests.class, + // Signature tests SignatureTests.class, diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java index fcbe28f289..77a5b58b27 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -69,9 +69,12 @@ import org.eclipse.jdt.internal.core.ClasspathEntry; import org.eclipse.jdt.internal.core.JavaModelManager; import org.eclipse.jdt.internal.core.JavaProject; import org.eclipse.jdt.internal.core.UserLibraryClasspathContainer; +import org.eclipse.jdt.internal.core.builder.State; import org.eclipse.team.core.RepositoryProvider; public class ClasspathTests extends ModifyingResourceTests { + private static final IClasspathAttribute ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE = JavaCore.newClasspathAttribute(IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS, "true"); + private static final IClasspathAttribute ATTR_IGNORE_OPTIONAL_PROBLEMS_FALSE = JavaCore.newClasspathAttribute(IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS, "false"); public class TestContainer implements IClasspathContainer { IPath path; @@ -339,6 +342,8 @@ public static Test suite() { suite.addTest(new ClasspathTests("testBug274737")); suite.addTest(new ClasspathTests("testBug357425")); suite.addTest(new ClasspathTests("testBug287164")); + suite.addTest(new ClasspathTests("testBug220928a")); + suite.addTest(new ClasspathTests("testBug220928b")); return suite; } public void setUpSuite() throws Exception { @@ -7342,4 +7347,77 @@ public void testBug287164() throws CoreException { } } +/** + * @bug220928: [buildpath] Should be able to ignore warnings from certain source folders + * + * Verify that adding the {@link IClasspathAttribute#IGNORE_OPTIONAL_PROBLEMS} attribute is + * correctly reflected by the {@link ClasspathEntry#ignoreOptionalProblems()} method. + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928" + */ +public void testBug220928a() throws CoreException { + ClasspathEntry entry; + + entry = (ClasspathEntry) JavaCore.newSourceEntry(new Path("/P/src")); + assertFalse(entry.ignoreOptionalProblems()); + + entry = (ClasspathEntry) JavaCore.newSourceEntry(new Path("/P/src"), null, null, null, + new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE }); + assertTrue(entry.ignoreOptionalProblems()); + + entry = (ClasspathEntry) JavaCore.newSourceEntry(new Path("/P/src"), null, null, null, + new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_FALSE }); + assertFalse(entry.ignoreOptionalProblems()); +} + +/** + * @bug220928: [buildpath] Should be able to ignore warnings from certain source folders + * + * Verify that value of the {@link IClasspathAttribute#IGNORE_OPTIONAL_PROBLEMS} attribute is + * correctly saved on workspace save. + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928" + */ +public void testBug220928b() throws CoreException { + boolean autoBuild = getWorkspace().isAutoBuilding(); + IWorkspaceDescription preferences = getWorkspace().getDescription(); + try { + // ensure that the workspace auto-build is ON + preferences.setAutoBuilding(true); + getWorkspace().setDescription(preferences); + + IJavaProject project = createJavaProject("P", new String[] {}, "bin"); + createFolder("/P/src"); + IClasspathEntry[] originalCP = project.getRawClasspath(); + IClasspathEntry[] newCP = new IClasspathEntry[originalCP.length + 1]; + State state; + + System.arraycopy(originalCP, 0, newCP, 0, originalCP.length); + newCP[originalCP.length] = JavaCore.newSourceEntry(new Path("/P/src")); + getJavaProject("P").setRawClasspath(newCP, null); + simulateExitRestart(); + state = (State) JavaModelManager.getJavaModelManager().getLastBuiltState(getJavaProject("P").getProject(), null); + assertFalse(state.sourceLocations[0].ignoreOptionalProblems); + + System.arraycopy(originalCP, 0, newCP, 0, originalCP.length); + newCP[originalCP.length] = JavaCore.newSourceEntry(new Path("/P/src"), null, null, null, + new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE }); + getJavaProject("P").setRawClasspath(newCP, null); + simulateExitRestart(); + state = (State) JavaModelManager.getJavaModelManager().getLastBuiltState(getJavaProject("P").getProject(), null); + assertTrue(state.sourceLocations[0].ignoreOptionalProblems); + + System.arraycopy(originalCP, 0, newCP, 0, originalCP.length); + newCP[originalCP.length] = JavaCore.newSourceEntry(new Path("/P/src"), null, null, null, + new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_FALSE }); + getJavaProject("P").setRawClasspath(newCP, null); + simulateExitRestart(); + state = (State) JavaModelManager.getJavaModelManager().getLastBuiltState(getJavaProject("P").getProject(), null); + assertFalse(state.sourceLocations[0].ignoreOptionalProblems); + } finally { + preferences.setAutoBuilding(autoBuild); + getWorkspace().setDescription(preferences); + deleteProject("P"); + } +} } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/IgnoreOptionalProblemsFromSourceFoldersTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/IgnoreOptionalProblemsFromSourceFoldersTests.java new file mode 100644 index 0000000000..87fb395a47 --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/IgnoreOptionalProblemsFromSourceFoldersTests.java @@ -0,0 +1,289 @@ +/******************************************************************************* + * Copyright (c) 2012 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 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.model; + +import junit.framework.Test; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.IClasspathAttribute; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.WorkingCopyOwner; + +public class IgnoreOptionalProblemsFromSourceFoldersTests extends ModifyingResourceTests { + private static final IClasspathAttribute ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE = JavaCore.newClasspathAttribute(IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS, "true"); + + public static Test suite() { + return buildModelTestSuite(IgnoreOptionalProblemsFromSourceFoldersTests.class); + } + + public IgnoreOptionalProblemsFromSourceFoldersTests(String name) { + super(name); + } + + // ignore optional errors + public void test001() throws CoreException { + ICompilationUnit unit = null; + try { + IJavaProject project = createJavaProject("P", new String[] {}, new String[] { "JCL_LIB" }, "bin"); + project.setOption(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); + + IClasspathEntry[] originalCP = project.getRawClasspath(); + IClasspathEntry[] newCP = new IClasspathEntry[originalCP.length + 1]; + System.arraycopy(originalCP, 0, newCP, 0, originalCP.length); + newCP[originalCP.length] = JavaCore.newSourceEntry(new Path("/P/src"), null, null, null, + new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE }); + project.setRawClasspath(newCP, null); + + createFolder("/P/src/p"); + IFile file = createFile("/P/src/p/X.java", + "package p;\n" + + "public class X {\n" + + " public void foo() {\n" + + " int i;\n" + + " }\n" + + "}"); + unit = (ICompilationUnit) JavaCore.create(file); + + ProblemRequestor problemRequestor = new ProblemRequestor(); + WorkingCopyOwner owner = newWorkingCopyOwner(problemRequestor); + unit.getWorkingCopy(owner, null); + assertProblems("Unexpected problems", + "----------\n" + + "----------\n", + problemRequestor); + } finally { + if (unit != null) { + unit.discardWorkingCopy(); + } + deleteProject("P"); + } + } + + // two different source folders ignore only from one + public void test002() throws CoreException { + ICompilationUnit x = null; + ICompilationUnit y = null; + try { + IJavaProject project = createJavaProject("P", new String[] {}, new String[] { "JCL_LIB" }, "bin"); + project.setOption(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); + + IClasspathEntry[] originalCP = project.getRawClasspath(); + IClasspathEntry[] newCP = new IClasspathEntry[originalCP.length + 2]; + System.arraycopy(originalCP, 0, newCP, 0, originalCP.length); + newCP[originalCP.length] = JavaCore.newSourceEntry(new Path("/P/src"), null, null, null, + new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE }); + newCP[originalCP.length + 1] = JavaCore.newSourceEntry(new Path("/P/src2")); + project.setRawClasspath(newCP, null); + + createFolder("/P/src/p"); + IFile fileX = createFile("/P/src/p/X.java", + "package p;\n" + + "public class X {\n" + + " public void foo() {\n" + + " int i;\n" + + " }\n" + + "}"); + x = (ICompilationUnit) JavaCore.create(fileX); + createFolder("/P/src2/q"); + IFile fileY = createFile("/P/src2/q/Y.java", + "package q;\n" + + "public class Y {\n" + + " public void foo() {\n" + + " int i;\n" + + " }\n" + + "}"); + y = (ICompilationUnit) JavaCore.create(fileY); + + ProblemRequestor problemRequestorX = new ProblemRequestor(); + WorkingCopyOwner ownerX = newWorkingCopyOwner(problemRequestorX); + x.getWorkingCopy(ownerX, null); + assertProblems("Unexpected problems", + "----------\n" + + "----------\n", + problemRequestorX); + + ProblemRequestor problemRequestorY = new ProblemRequestor(); + WorkingCopyOwner ownerY = newWorkingCopyOwner(problemRequestorY); + y.getWorkingCopy(ownerY, null); + assertProblems("Unexpected problems value", + "----------\n" + + "1. ERROR in /P/src2/q/Y.java\n" + + "The value of the local variable i is not used\n" + + "----------\n", + problemRequestorY); + } finally { + if (x != null) { + x.discardWorkingCopy(); + } + if (y != null) { + y.discardWorkingCopy(); + } + deleteProject("P"); + } + } + + // two different source folders ignore from both + public void test003() throws CoreException { + ICompilationUnit x = null; + ICompilationUnit y = null; + try { + IJavaProject project = createJavaProject("P", new String[] {}, new String[] { "JCL_LIB" }, "bin"); + project.setOption(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); + + IClasspathEntry[] originalCP = project.getRawClasspath(); + IClasspathEntry[] newCP = new IClasspathEntry[originalCP.length + 2]; + System.arraycopy(originalCP, 0, newCP, 0, originalCP.length); + newCP[originalCP.length] = JavaCore.newSourceEntry(new Path("/P/src"), null, null, null, + new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE }); + newCP[originalCP.length + 1] = JavaCore.newSourceEntry(new Path("/P/src2"), null, null, null, + new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE }); + project.setRawClasspath(newCP, null); + + createFolder("/P/src/p"); + IFile fileX = createFile("/P/src/p/X.java", + "package p;\n" + + "public class X {\n" + + " public void foo() {\n" + + " int i;\n" + + " }\n" + + "}"); + x = (ICompilationUnit) JavaCore.create(fileX); + createFolder("/P/src2/q"); + IFile fileY = createFile("/P/src2/q/Y.java", + "package q;\n" + + "public class Y {\n" + + " public void foo() {\n" + + " int i;\n" + + " }\n" + + "}"); + y = (ICompilationUnit) JavaCore.create(fileY); + + ProblemRequestor problemRequestorX = new ProblemRequestor(); + WorkingCopyOwner ownerX = newWorkingCopyOwner(problemRequestorX); + x.getWorkingCopy(ownerX, null); + assertProblems("Unexpected problems", + "----------\n" + + "----------\n", + problemRequestorX); + + ProblemRequestor problemRequestorY = new ProblemRequestor(); + WorkingCopyOwner ownerY = newWorkingCopyOwner(problemRequestorY); + y.getWorkingCopy(ownerY, null); + assertProblems("Unexpected problems", + "----------\n" + + "----------\n", + problemRequestorY); + } finally { + if (x != null) { + x.discardWorkingCopy(); + } + if (y != null) { + y.discardWorkingCopy(); + } + deleteProject("P"); + } + } + + // non-optional errors cannot be ignored + public void test004() throws CoreException { + ICompilationUnit unit = null; + try { + IJavaProject project = createJavaProject("P", new String[] {}, new String[] { "JCL_LIB" }, "bin"); + project.setOption(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); + + IClasspathEntry[] originalCP = project.getRawClasspath(); + IClasspathEntry[] newCP = new IClasspathEntry[originalCP.length + 1]; + System.arraycopy(originalCP, 0, newCP, 0, originalCP.length); + newCP[originalCP.length] = JavaCore.newSourceEntry(new Path("/P/src"), null, null, null, + new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE }); + project.setRawClasspath(newCP, null); + + createFolder("/P/src/p"); + IFile file = createFile("/P/src/p/X.java", + "package p;\n" + + "public class X {\n" + + " public void foo() {\n" + + " int i;\n" + + " }\n" + + " public void bar() {\n" + + " a++;\n" + + " }\n" + + "}"); + unit = (ICompilationUnit) JavaCore.create(file); + + ProblemRequestor problemRequestor = new ProblemRequestor(); + WorkingCopyOwner owner = newWorkingCopyOwner(problemRequestor); + unit.getWorkingCopy(owner, null); + assertProblems("Unexpeted problems", + "----------\n" + + "1. ERROR in /P/src/p/X.java\n" + + "a cannot be resolved to a variable\n" + + "----------\n", + problemRequestor); + } finally { + if (unit != null) { + unit.discardWorkingCopy(); + } + deleteProject("P"); + } + } + + // task tags cannot be ignored + public void test005() throws CoreException { + ICompilationUnit unit = null; + try { + IJavaProject project = createJavaProject("P", new String[] {}, new String[] { "JCL_LIB" }, "bin"); + project.setOption(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); + project.setOption(JavaCore.COMPILER_TASK_TAGS, "TODO"); + project.setOption(JavaCore.COMPILER_TASK_PRIORITIES, "NORMAL"); + + IClasspathEntry[] originalCP = project.getRawClasspath(); + IClasspathEntry[] newCP = new IClasspathEntry[originalCP.length + 1]; + System.arraycopy(originalCP, 0, newCP, 0, originalCP.length); + newCP[originalCP.length] = JavaCore.newSourceEntry(new Path("/P/src"), null, null, null, + new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE }); + project.setRawClasspath(newCP, null); + + createFolder("/P/src/p"); + IFile file = createFile("/P/src/p/X.java", + "package p;\n" + + "public class X {\n" + + " public void foo() {\n" + + " int i;\n" + + " }\n" + + " public void bar() {\n" + + " // TODO nothing\n" + + " }\n" + + "}"); + unit = (ICompilationUnit) JavaCore.create(file); + + ProblemRequestor problemRequestor = new ProblemRequestor(); + WorkingCopyOwner owner = newWorkingCopyOwner(problemRequestor); + unit.getWorkingCopy(owner, null); + assertProblems("Unexpeted problems", + "----------\n" + + "1. WARNING in /P/src/p/X.java\n" + + "TODO nothing\n" + + "----------\n", + problemRequestor); + } finally { + if (unit != null) { + unit.discardWorkingCopy(); + } + deleteProject("P"); + } + } +} diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/CompilationUnit.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/CompilationUnit.java index 0166e8781a..64d3d89879 100644 --- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/CompilationUnit.java +++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/CompilationUnit.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -31,12 +31,17 @@ public class CompilationUnit implements ICompilationUnit { // == Main.NONE: absorbent element, do not output class files; // else: use as the path of the directory into which class files must // be written. + private boolean ignoreOptionalProblems; public CompilationUnit(char[] contents, String fileName, String encoding) { this(contents, fileName, encoding, null); } public CompilationUnit(char[] contents, String fileName, String encoding, String destinationPath) { + this(contents, fileName, encoding, destinationPath, false); +} +public CompilationUnit(char[] contents, String fileName, String encoding, + String destinationPath, boolean ignoreOptionalProblems) { this.contents = contents; char[] fileNameCharArray = fileName.toCharArray(); switch(File.separatorChar) { @@ -61,6 +66,7 @@ public CompilationUnit(char[] contents, String fileName, String encoding, this.mainTypeName = CharOperation.subarray(fileNameCharArray, start, end); this.encoding = encoding; this.destinationPath = destinationPath; + this.ignoreOptionalProblems = ignoreOptionalProblems; } public char[] getContents() { if (this.contents != null) @@ -86,6 +92,9 @@ public char[] getMainTypeName() { public char[][] getPackageName() { return null; } +public boolean ignoreOptionalProblems() { + return this.ignoreOptionalProblems; +} public String toString() { return "CompilationUnit[" + new String(this.fileName) + "]"; //$NON-NLS-2$ //$NON-NLS-1$ } diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java index 14df01633f..97a9654ffa 100644 --- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java +++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java @@ -1323,6 +1323,7 @@ public class Main implements ProblemSeverities, SuffixConstants { public Logger logger; public int maxProblems; public Map options; + public char[][] ignoreOptionalProblemsFromFolders; protected PrintWriter out; public boolean proceed = true; public boolean proceedOnError = false; @@ -1839,6 +1840,42 @@ public void configure(String[] argv) { switch(mode) { case DEFAULT : + if (currentArg.startsWith("-nowarn")) { //$NON-NLS-1$ + switch (currentArg.length()) { + case 7: + disableAll(ProblemSeverities.Warning); + break; + case 8: + throw new IllegalArgumentException(this.bind( + "configure.invalidNowarnOption", currentArg)); //$NON-NLS-1$ + default: + int foldersStart = currentArg.indexOf('[') + 1; + int foldersEnd = currentArg.lastIndexOf(']'); + if (foldersStart <= 8 || foldersEnd == -1 || foldersStart > foldersEnd + || foldersEnd < currentArg.length() - 1) { + throw new IllegalArgumentException(this.bind( + "configure.invalidNowarnOption", currentArg)); //$NON-NLS-1$ + } + String folders = currentArg.substring(foldersStart, foldersEnd); + if (folders.length() > 0) { + char[][] currentFolders = decodeIgnoreOptionalProblemsFromFolders(folders); + if (this.ignoreOptionalProblemsFromFolders != null) { + int length = this.ignoreOptionalProblemsFromFolders.length + currentFolders.length; + char[][] tempFolders = new char[length][]; + System.arraycopy(this.ignoreOptionalProblemsFromFolders, 0, tempFolders, 0, this.ignoreOptionalProblemsFromFolders.length); + System.arraycopy(currentFolders, 0, tempFolders, this.ignoreOptionalProblemsFromFolders.length, currentFolders.length); + this.ignoreOptionalProblemsFromFolders = tempFolders; + } else { + this.ignoreOptionalProblemsFromFolders = currentFolders; + } + } else { + throw new IllegalArgumentException(this.bind( + "configure.invalidNowarnOption", currentArg)); //$NON-NLS-1$ + } + } + mode = DEFAULT; + continue; + } if (currentArg.startsWith("[")) { //$NON-NLS-1$ throw new IllegalArgumentException( this.bind("configure.unexpectedBracket", //$NON-NLS-1$ @@ -2189,11 +2226,6 @@ public void configure(String[] argv) { throw new IllegalArgumentException( this.bind("configure.invalidDebugOption", debugOption)); //$NON-NLS-1$ } - if (currentArg.startsWith("-nowarn")) { //$NON-NLS-1$ - disableAll(ProblemSeverities.Warning); - mode = DEFAULT; - continue; - } if (currentArg.startsWith("-warn")) { //$NON-NLS-1$ mode = DEFAULT; String warningOption = currentArg; @@ -2759,6 +2791,31 @@ public void configure(String[] argv) { this.pendingErrors = null; } } + +private static char[][] decodeIgnoreOptionalProblemsFromFolders(String folders) { + StringTokenizer tokenizer = new StringTokenizer(folders, File.pathSeparator); + char[][] result = new char[tokenizer.countTokens()][]; + int count = 0; + while (tokenizer.hasMoreTokens()) { + String fileName = tokenizer.nextToken(); + // relative folder names are created relative to the current user dir + File file = new File(fileName); + if (file.exists()) { + // if the file exists, we should try to use its canonical path + try { + result[count++] = file.getCanonicalPath().toCharArray(); + } catch (IOException e) { + // if we got exception during canonicalization, fall back to the name that was specified + result[count++] = fileName.toCharArray(); + } + } else { + // if the file does not exist, use the name that was specified + result[count++] = fileName.toCharArray(); + } + } + return result; +} + private static String getAllEncodings(Set encodings) { int size = encodings.size(); String[] allEncodings = new String[size]; @@ -2913,8 +2970,15 @@ public CompilationUnit[] getCompilationUnits() { String encoding = this.encodings[i]; if (encoding == null) encoding = defaultEncoding; - units[i] = new CompilationUnit(null, this.filenames[i], encoding, - this.destinationPaths[i]); + String fileName; + try { + fileName = file.getCanonicalPath(); + } catch (IOException e) { + // if we got exception during canonicalization, fall back to the name that was specified + fileName = this.filenames[i]; + } + units[i] = new CompilationUnit(null, fileName, encoding, this.destinationPaths[i], + shouldIgnoreOptionalProblems(this.ignoreOptionalProblemsFromFolders, fileName.toCharArray())); } return units; } @@ -3651,6 +3715,7 @@ protected void initialize(PrintWriter outWriter, PrintWriter errWriter, boolean this.err = errWriter; this.systemExitWhenFinished = systemExit; this.options = new CompilerOptions().getMap(); + this.ignoreOptionalProblemsFromFolders = null; this.progress = compilationProgress; if (customDefaultOptions != null) { @@ -3687,7 +3752,20 @@ protected void initializeAnnotationProcessorManager() { this.logger.logIncorrectVMVersionForAnnotationProcessing(); } } - +private static boolean isParentOf(char[] folderName, char[] fileName) { + if (folderName.length >= fileName.length) { + return false; + } + if (fileName[folderName.length] != '\\' && fileName[folderName.length] != '/') { + return false; + } + for (int i = folderName.length - 1; i >= 0; i--) { + if (folderName[i] != fileName[i]) { + return false; + } + } + return true; +} // Dump classfiles onto disk for all compilation units that where successful // and do not carry a -d none spec, either directly or inherited from Main. public void outputClassFiles(CompilationResult unitResult) { @@ -4233,6 +4311,18 @@ protected void setPaths(ArrayList bootclasspaths, classpaths.toArray(this.checkedClasspaths); this.logger.logClasspath(this.checkedClasspaths); } +private static boolean shouldIgnoreOptionalProblems(char[][] folderNames, char[] fileName) { + if (folderNames == null || fileName == null) { + return false; + } + for (int i = 0, max = folderNames.length; i < max; i++) { + char[] folderName = folderNames[i]; + if (isParentOf(folderName, fileName)) { + return true; + } + } + return false; +} protected void validateOptions(boolean didSpecifyCompliance) { if (didSpecifyCompliance) { Object version = this.options.get(CompilerOptions.OPTION_Compliance); diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties index 00a5f74d5e..09180eb26f 100644 --- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties +++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties @@ -67,6 +67,7 @@ configure.incompatibleComplianceForSource = Compliance level ''{0}'' is incompat configure.incompatibleComplianceForTarget = Compliance level ''{0}'' is incompatible with target level ''{1}''. A compliance level ''{1}'' or better is required configure.repetition = repetition must be a positive integer: {0} configure.maxProblems = max problems must be a positive integer: {0} +configure.invalidNowarnOption = invalid syntax for nowarn option: {0} configure.invalidErrorConfiguration = invalid error configuration: ''{0}'' configure.invalidError = invalid error token: ''{0}''. Ignoring this error token and compiling @@ -187,6 +188,9 @@ misc.usage = {1} {2}\n\ \ -deprecation + deprecation outside deprecated code (equivalent to\n\ \ -warn:+deprecation)\n\ \ -nowarn -warn:none disable all warnings\n\ +\ -nowarn:[<directories separated by {0}>]\n\ +\ specify directories from which optional problems should\n\ +\ be ignored\n\ \ -?:warn -help:warn display advanced warning options\n\ \ \n\ \ Error options:\n\ @@ -270,6 +274,9 @@ misc.usage.warn = {1} {2}\n\ \ Warning options:\n\ \ -deprecation + deprecation outside deprecated code\n\ \ -nowarn -warn:none disable all warnings\n\ +\ -nowarn:[<directories separated by {0}>]\n\ +\ specify directories from which optional problems should\n\ +\ be ignored\n\ \ -warn:<warnings separated by ,> enable exactly the listed warnings\n\ \ -warn:+<warnings separated by ,> enable additional warnings\n\ \ -warn:-<warnings separated by ,> disable specific warnings\n\ diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/ICompilationUnit.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/ICompilationUnit.java index adbcaa6827..bbe34a26c8 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/ICompilationUnit.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/ICompilationUnit.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -35,4 +35,9 @@ char[] getMainTypeName(); * For example, {java, lang}. */ char[][] getPackageName(); +/** +* Answer if optional problems should be ignored for this compilation unit. +* Implementors should return <code>false</code> if there is no preference. +*/ +boolean ignoreOptionalProblems(); } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java index 3765f695e3..970b9e0523 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java @@ -12,10 +12,12 @@ package org.eclipse.jdt.internal.compiler.problem; import org.eclipse.jdt.core.compiler.CategorizedProblem; import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.core.compiler.IProblem; import org.eclipse.jdt.internal.compiler.CompilationResult; import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy; import org.eclipse.jdt.internal.compiler.IProblemFactory; import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.impl.ReferenceContext; import org.eclipse.jdt.internal.compiler.util.Util; @@ -115,6 +117,12 @@ public void handle( if (severity == ProblemSeverities.Ignore) return; + if ((severity & ProblemSeverities.Optional) != 0 && problemId != IProblem.Task) { + ICompilationUnit cu = unitResult.getCompilationUnit(); + if (cu != null && cu.ignoreOptionalProblems()) + return; + } + // if no reference context, we need to abort from the current compilation process if (referenceContext == null) { if ((severity & ProblemSeverities.Error) != 0) { // non reportable error is fatal diff --git a/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/EvaluationContext.java b/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/EvaluationContext.java index ed5dc371b1..33c30f44be 100644 --- a/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/EvaluationContext.java +++ b/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/EvaluationContext.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -157,6 +157,9 @@ public void complete( public char[][] getPackageName() { return null; } + public boolean ignoreOptionalProblems() { + return false; + } }; CompletionEngine engine = new CompletionEngine(environment, mapper.getCompletionRequestor(requestor), options, project, owner, monitor); @@ -601,6 +604,9 @@ public void select( public char[][] getPackageName() { return null; } + public boolean ignoreOptionalProblems() { + return false; + } }; SelectionEngine engine = new SelectionEngine(environment, mapper.getSelectionRequestor(requestor), options, owner); engine.select(sourceUnit, mapper.startPosOffset + selectionSourceStart, mapper.startPosOffset + selectionSourceEnd); diff --git a/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/Evaluator.java b/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/Evaluator.java index de5c56e4e1..de07b6600f 100644 --- a/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/Evaluator.java +++ b/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/Evaluator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -141,6 +141,9 @@ ClassFile[] getClasses() { public char[][] getPackageName() { return null; } + public boolean ignoreOptionalProblems() { + return false; + } }}); if (compilerRequestor.hasErrors) { return null; diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IClasspathAttribute.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IClasspathAttribute.java index 8322c18823..dc2c826e43 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IClasspathAttribute.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IClasspathAttribute.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2011 IBM Corporation and others. + * Copyright (c) 2005, 2012 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 @@ -88,6 +88,19 @@ public interface IClasspathAttribute { String SOURCE_ATTACHMENT_ENCODING = "source_encoding"; //$NON-NLS-1$ /** + * Constant for the name of the ignore optional compile problems attribute. + * This attribute is valid only for classpath entries describing source folders. + * The possible values for this attribute are <code>"true"</code> or + * <code>"false"</code>. When not present, <code>"false"</code> is assumed. + * If the value of this attribute is <code>"true"</code>, all optional problems + * from the source folder described by this classpath entry will not be reported + * by the compiler. + * + * @since 3.8 + */ + String IGNORE_OPTIONAL_PROBLEMS = "ignore_optional_problems"; //$NON-NLS-1$ + + /** * Constant for the name of the optional attribute. The possible values * for this attribute are <code>"true"</code> or <code>"false"</code>. * When not present, <code>"false"</code> is assumed. diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BasicCompilationUnit.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BasicCompilationUnit.java index 3b7e3ac9c1..11cdaa3500 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BasicCompilationUnit.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/BasicCompilationUnit.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -133,6 +133,9 @@ public char[] getMainTypeName() { public char[][] getPackageName() { return this.packageName; } +public boolean ignoreOptionalProblems() { + return false; +} public String toString(){ return "CompilationUnit: "+new String(this.fileName); //$NON-NLS-1$ } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java index 41f66ec295..8baef63fa2 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -1561,7 +1561,19 @@ public class ClasspathEntry implements IClasspathEntry { } } return null; - } + } + + public boolean ignoreOptionalProblems() { + if (this.entryKind == IClasspathEntry.CPE_SOURCE) { + for (int i = 0; i < this.extraAttributes.length; i++) { + IClasspathAttribute attrib = this.extraAttributes[i]; + if (IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS.equals(attrib.getName())) { + return "true".equals(attrib.getValue()); //$NON-NLS-1$ + } + } + } + return false; + } /** * Validate a given classpath and output location for a project, using the following rules: diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java index ae648aeb2d..332762c07d 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -1005,6 +1005,9 @@ public boolean hasResourceChanged() { if (resource == null) return false; return ((CompilationUnitElementInfo)info).timestamp != resource.getModificationStamp(); } +public boolean ignoreOptionalProblems() { + return getPackageFragmentRoot().ignoreOptionalProblems(); +} /** * @see IWorkingCopy#isBasedOn(IResource) * @deprecated diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java index c1e54a01ec..817fc9ba2b 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -711,6 +711,14 @@ public int hashCode() { return resource().hashCode(); } +public boolean ignoreOptionalProblems() { + try { + return ((PackageFragmentRootInfo) getElementInfo()).ignoreOptionalProblems(this); + } catch (JavaModelException e) { + return false; + } +} + /** * @see IPackageFragmentRoot */ diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRootInfo.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRootInfo.java index 22333a8a4b..431b9c70cc 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRootInfo.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRootInfo.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -41,11 +41,15 @@ class PackageFragmentRootInfo extends OpenableElementInfo { * A array with all the non-java resources contained by this PackageFragment */ protected Object[] nonJavaResources; + + private boolean ignoreOptionalProblems; + private boolean initialized; /** * Create and initialize a new instance of the receiver */ public PackageFragmentRootInfo() { this.nonJavaResources = null; + this.initialized = false; } /** * Starting at this folder, create non-java resources for this package fragment root @@ -155,6 +159,13 @@ public int getRootKind() { protected SourceMapper getSourceMapper() { return this.sourceMapper; } +boolean ignoreOptionalProblems(PackageFragmentRoot packageFragmentRoot) throws JavaModelException { + if (this.initialized == false) { + this.ignoreOptionalProblems = ((ClasspathEntry) packageFragmentRoot.getRawClasspathEntry()).ignoreOptionalProblems(); + this.initialized = true; + } + return this.ignoreOptionalProblems; +} private static boolean isClasspathEntry(IPath path, IClasspathEntry[] resolvedClasspath) { for (int i = 0, length = resolvedClasspath.length; i < length; i++) { IClasspathEntry entry = resolvedClasspath[i]; diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathLocation.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathLocation.java index 89d1d6747d..aef33e1b60 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathLocation.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathLocation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -18,8 +18,8 @@ import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; public abstract class ClasspathLocation { -static ClasspathLocation forSourceFolder(IContainer sourceFolder, IContainer outputFolder, char[][] inclusionPatterns, char[][] exclusionPatterns) { - return new ClasspathMultiDirectory(sourceFolder, outputFolder, inclusionPatterns, exclusionPatterns); +static ClasspathLocation forSourceFolder(IContainer sourceFolder, IContainer outputFolder, char[][] inclusionPatterns, char[][] exclusionPatterns, boolean ignoreOptionalProblems) { + return new ClasspathMultiDirectory(sourceFolder, outputFolder, inclusionPatterns, exclusionPatterns, ignoreOptionalProblems); } public static ClasspathLocation forBinaryFolder(IContainer binaryFolder, boolean isOutputFolder, AccessRuleSet accessRuleSet) { diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathMultiDirectory.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathMultiDirectory.java index 1273281912..3d41e087a9 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathMultiDirectory.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathMultiDirectory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -15,20 +15,22 @@ import org.eclipse.core.resources.*; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.core.util.Util; -class ClasspathMultiDirectory extends ClasspathDirectory { +public class ClasspathMultiDirectory extends ClasspathDirectory { IContainer sourceFolder; char[][] inclusionPatterns; // used by builders when walking source folders char[][] exclusionPatterns; // used by builders when walking source folders boolean hasIndependentOutputFolder; // if output folder is not equal to any of the source folders +public boolean ignoreOptionalProblems; -ClasspathMultiDirectory(IContainer sourceFolder, IContainer binaryFolder, char[][] inclusionPatterns, char[][] exclusionPatterns) { +ClasspathMultiDirectory(IContainer sourceFolder, IContainer binaryFolder, char[][] inclusionPatterns, char[][] exclusionPatterns, boolean ignoreOptionalProblems) { super(binaryFolder, true, null); this.sourceFolder = sourceFolder; this.inclusionPatterns = inclusionPatterns; this.exclusionPatterns = exclusionPatterns; this.hasIndependentOutputFolder = false; + this.ignoreOptionalProblems = ignoreOptionalProblems; // handle the case when a state rebuilds a source folder if (this.inclusionPatterns != null && this.inclusionPatterns.length == 0) @@ -42,7 +44,8 @@ public boolean equals(Object o) { if (!(o instanceof ClasspathMultiDirectory)) return false; ClasspathMultiDirectory md = (ClasspathMultiDirectory) o; - return this.sourceFolder.equals(md.sourceFolder) && this.binaryFolder.equals(md.binaryFolder) + return this.ignoreOptionalProblems == md.ignoreOptionalProblems + && this.sourceFolder.equals(md.sourceFolder) && this.binaryFolder.equals(md.binaryFolder) && CharOperation.equals(this.inclusionPatterns, md.inclusionPatterns) && CharOperation.equals(this.exclusionPatterns, md.exclusionPatterns); } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java index 66fde9804e..65c3c79e95 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -114,7 +114,7 @@ private void computeClasspathLocations( createOutputFolder(outputFolder); } sLocations.add( - ClasspathLocation.forSourceFolder((IContainer) target, outputFolder, entry.fullInclusionPatternChars(), entry.fullExclusionPatternChars())); + ClasspathLocation.forSourceFolder((IContainer) target, outputFolder, entry.fullInclusionPatternChars(), entry.fullExclusionPatternChars(), entry.ignoreOptionalProblems())); continue nextEntry; case IClasspathEntry.CPE_PROJECT : diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/SourceFile.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/SourceFile.java index 4955f5da2d..4a5b04d896 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/SourceFile.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/SourceFile.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -103,6 +103,9 @@ public char[][] getPackageName() { public int hashCode() { return this.initialTypeName.hashCode(); } +public boolean ignoreOptionalProblems() { + return this.sourceLocation.ignoreOptionalProblems; +} String typeLocator() { return this.resource.getProjectRelativePath().toString(); } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/State.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/State.java index 434866d496..6dfb1ece1f 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/State.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/State.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -27,7 +27,7 @@ public class State { // NOTE: this state cannot contain types that are not defined in this project String javaProjectName; -ClasspathMultiDirectory[] sourceLocations; +public ClasspathMultiDirectory[] sourceLocations; ClasspathLocation[] binaryLocations; // keyed by the project relative path of the type (i.e. "src1/p1/p2/A.java"), value is a ReferenceCollection or an AdditionalTypeCollection SimpleLookupTable references; @@ -44,7 +44,7 @@ private long previousStructuralBuildTime; private StringSet structurallyChangedTypes; public static int MaxStructurallyChangedTypes = 100; // keep track of ? structurally changed types, otherwise consider all to be changed -public static final byte VERSION = 0x001A; // fix for 287164 +public static final byte VERSION = 0x001B; static final byte SOURCE_FOLDER = 1; static final byte BINARY_FOLDER = 2; @@ -246,7 +246,7 @@ static State read(IProject project, DataInputStream in) throws IOException { if ((folderName = in.readUTF()).length() > 0) sourceFolder = project.getFolder(folderName); if ((folderName = in.readUTF()).length() > 0) outputFolder = project.getFolder(folderName); ClasspathMultiDirectory md = - (ClasspathMultiDirectory) ClasspathLocation.forSourceFolder(sourceFolder, outputFolder, readNames(in), readNames(in)); + (ClasspathMultiDirectory) ClasspathLocation.forSourceFolder(sourceFolder, outputFolder, readNames(in), readNames(in), in.readBoolean()); if (in.readBoolean()) md.hasIndependentOutputFolder = true; newState.sourceLocations[i] = md; @@ -425,6 +425,7 @@ void write(DataOutputStream out) throws IOException { out.writeUTF(md.binaryFolder.getProjectRelativePath().toString()); writeNames(md.inclusionPatterns, out); writeNames(md.exclusionPatterns, out); + out.writeBoolean(md.ignoreOptionalProblems); out.writeBoolean(md.hasIndependentOutputFolder); } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/jdom/CompilationUnit.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/jdom/CompilationUnit.java index fc644978af..c00aa48a7c 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/jdom/CompilationUnit.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/jdom/CompilationUnit.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -51,6 +51,9 @@ public char[] getMainTypeName() { public char[][] getPackageName() { return null; } +public boolean ignoreOptionalProblems() { + return false; +} public String toString() { return "CompilationUnit[" + new String(this.fFileName) + "]"; //$NON-NLS-2$ //$NON-NLS-1$ } diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PossibleMatch.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PossibleMatch.java index dc3450d161..2a967c402c 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PossibleMatch.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PossibleMatch.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -154,6 +154,9 @@ public int hashCode() { hashCode += CharOperation.hashCode(this.compoundName[i]); return hashCode; } +public boolean ignoreOptionalProblems() { + return false; +} void setSimilarMatch(PossibleMatch possibleMatch) { // source does not matter on similar match as it is read on // the first stored possible match |
