### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.performance Index: src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceTests.java,v retrieving revision 1.51 diff -u -r1.51 FullSourceWorkspaceTests.java --- src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceTests.java 3 Oct 2008 12:36:18 -0000 1.51 +++ src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceTests.java 16 Oct 2008 16:39:19 -0000 @@ -162,7 +162,7 @@ // use default value System.out.println("INFO: Specified 'measures' VM argument (="+measures+") is ignored as it is not an integer (0-20)!"); } - MEASURES_COUNT = count; + MEASURES_COUNT = 1; } // Scenario information @@ -643,23 +643,17 @@ System.out.println("("+(System.currentTimeMillis()-start)+"ms)"); // Init JRE_LIB variable - String[] jdkLibs = Util.getJavaClassLibs(); - int length = jdkLibs.length; - String jdkLib = null; - for (int i=0; i *
  • declarations using string pattern #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java,v retrieving revision 1.179 diff -u -r1.179 JavaSearchTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java 9 Sep 2008 12:43:37 -0000 1.179 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java 16 Oct 2008 16:39:26 -0000 @@ -251,7 +251,7 @@ * (regression test for bug 23112 search: need a way to search for references to the implicit non-arg constructor) */ public void testConstructorReference10() throws CoreException { // was testConstructorReferenceImplicitConstructorCall2 - this.resultCollector.showSynthetic = true; + this.resultCollector.showSynthetic(); search( "c11.A()", CONSTRUCTOR, @@ -814,7 +814,7 @@ public void testFieldReference03() throws CoreException { IType type = getCompilationUnit("JavaSearch", "src", "q8", "EclipseTest.java").getType("EclipseTest"); IField field = type.getField("test"); - this.resultCollector.showPotential = false; + this.resultCollector.showPotential(false); search(field, REFERENCES, getJavaSearchScope()); assertSearchResults( "src/q8/EclipseTest.java void q8.EclipseTest.main(String[]) [test]" @@ -1124,7 +1124,7 @@ public void testFieldReference20() throws CoreException { // was testFieldReferenceInOutDocComment IType type = getCompilationUnit("JavaSearch", "src", "s4", "X.java").getType("X"); IField field = type.getField("x"); - this.resultCollector.showInsideDoc = true; + this.resultCollector.showInsideDoc(); search(field, REFERENCES, getJavaSearchScope(), this.resultCollector); assertSearchResults( "src/s4/X.java int s4.X.foo() [x] OUTSIDE_JAVADOC\n" + @@ -1734,7 +1734,7 @@ public void testMethodReference15() throws CoreException { // was testMethodReferenceInOutDocComment IType type = getCompilationUnit("JavaSearch", "src", "s4", "X.java").getType("X"); IMethod method = type.getMethod("foo", new String[] {}); - this.resultCollector.showInsideDoc = true; + this.resultCollector.showInsideDoc(); search(method, REFERENCES, getJavaSearchScope(), this.resultCollector); assertSearchResults( "src/s4/X.java void s4.X.bar() [foo()] INSIDE_JAVADOC\n" + @@ -1759,7 +1759,7 @@ public void testMethodReference17() throws CoreException { IType type = getCompilationUnit("JavaSearch/src/b111416/X.java").getType("X"); IMethod method = type.getMethod("open", new String[] {"QString;"}); - this.resultCollector.showAccuracy = true; + this.resultCollector.showAccuracy(true); search(method, REFERENCES, ERASURE_RULE, getJavaSearchScope(), this.resultCollector); assertSearchResults( "src/b111416/X.java void b111416.X.foo() [open(\"\")] EXACT_MATCH", @@ -1777,7 +1777,7 @@ .getType("A1").getMethod("m", new String[] {}); SearchPattern rightPattern = createPattern(rightMethod, ALL_OCCURRENCES); SearchPattern orPattern = SearchPattern.createOrPattern(leftPattern, rightPattern); - this.resultCollector.showAccuracy = true; + this.resultCollector.showAccuracy(true); search( orPattern, getJavaSearchScope(), @@ -1868,7 +1868,7 @@ */ public void testPackageDeclarationBug73551() throws CoreException { JavaSearchResultCollector result = new JavaSearchResultCollector(); - result.showAccuracy = true; + result.showAccuracy(true); IPackageDeclaration packDecl = getCompilationUnit("JavaSearch", "src", "p71267", "Test.java").getPackageDeclaration("p71267"); search(packDecl, DECLARATIONS, getJavaSearchScope(), result); assertSearchResults( @@ -1886,7 +1886,7 @@ try { test = srcRoot.createPackageFragment("b117020", true, null); JavaSearchResultCollector result = new JavaSearchResultCollector(); - result.showAccuracy = true; + result.showAccuracy(true); search(test, DECLARATIONS, getJavaSearchScope(), result); assertSearchResults( "src/b117020 b117020 EXACT_MATCH", @@ -2145,7 +2145,7 @@ JAVA_PROJECT.setRawClasspath(newClasspath, null); // potential match for a field declaration - this.resultCollector.showAccuracy = true; + this.resultCollector.showAccuracy(true); search("MissingFieldType.*", FIELD, DECLARATIONS, getJavaSearchScope()); assertSearchResults( "AbortCompilation.jar AbortCompilation.MissingFieldType.field [No source] EXACT_MATCH\n" + @@ -2177,7 +2177,7 @@ } } }; - collector.showAccuracy = true; + collector.showAccuracy(true); search("*", FIELD, DECLARATIONS, getJavaSearchScope(), collector); assertSearchResults( "AbortCompilation.jar AbortCompilation.MissingFieldType.field [No source] EXACT_MATCH\n" + @@ -2206,7 +2206,7 @@ JAVA_PROJECT.setRawClasspath(newClasspath, null); // potential match for a method declaration - this.resultCollector.showAccuracy = true; + this.resultCollector.showAccuracy(true); search("MissingArgumentType.foo*", METHOD, DECLARATIONS, getJavaSearchScope()); assertSearchResults( "AbortCompilation.jar void AbortCompilation.MissingArgumentType.foo() [No source] EXACT_MATCH\n" + @@ -2238,7 +2238,7 @@ } } }; - collector.showAccuracy = true; + collector.showAccuracy(true); search("*", METHOD, DECLARATIONS, getJavaSearchScope(), collector); assertSearchResults( "AbortCompilation.jar void AbortCompilation.MissingArgumentType.foo() [No source] EXACT_MATCH\n" + @@ -2268,7 +2268,7 @@ JAVA_PROJECT.setRawClasspath(newClasspath, null); // exact match for a type declaration - this.resultCollector.showAccuracy = true; + this.resultCollector.showAccuracy(true); search("AbortCompilation.*Missing*", TYPE, DECLARATIONS, getJavaSearchScope()); assertSearchResults( "AbortCompilation.jar AbortCompilation.EnclosingType$MissingEnclosingType [No source] EXACT_MATCH\n" + @@ -2291,7 +2291,7 @@ JAVA_PROJECT.setRawClasspath(newClasspath, null); // exact match for a type declaration - this.resultCollector.showAccuracy = true; + this.resultCollector.showAccuracy(true); search("Missing*", TYPE, DECLARATIONS, getJavaSearchScope()); assertSearchResults( "AbortCompilation.jar AbortCompilation.EnclosingType$MissingEnclosingType [No source] EXACT_MATCH\n" + @@ -2491,15 +2491,11 @@ IPackageFragmentRoot root = getPackageFragmentRoot("JavaSearch", "test20631.jar"); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {root}); - search( - "Y", - TYPE, - DECLARATIONS, - scope, - this.resultCollector); + this.resultCollector.showJarFile(); + search("Y", TYPE, DECLARATIONS, scope); assertSearchResults( - "test20631.jar Y", - this.resultCollector); + "test20631.jar|X$Y.class X$Y" + ); } /** * Type declaration using a package scope test. @@ -2737,7 +2733,7 @@ public void testTypeReference03() throws CoreException { SearchPattern pattern = createPattern("x31985", TYPE, REFERENCES, false); - this.resultCollector.showAccuracy = true; + this.resultCollector.showAccuracy(true); search( pattern, getJavaSearchScope(), @@ -2857,7 +2853,7 @@ public void testTypeReference10() throws CoreException { // was testMemberTypeReference // references to second level member type - this.resultCollector.showAccuracy = true; + this.resultCollector.showAccuracy(true); search( "BMember", TYPE, @@ -2874,7 +2870,7 @@ // references to first level member type this.resultCollector = new JavaSearchResultCollector(); - this.resultCollector.showAccuracy = true; + this.resultCollector.showAccuracy(true); search( "AzzMember", TYPE, @@ -2889,7 +2885,7 @@ // no reference to a field with same name as member type this.resultCollector = new JavaSearchResultCollector(); - this.resultCollector.showAccuracy = true; + this.resultCollector.showAccuracy(true); search( "BMember", FIELD, @@ -2927,7 +2923,7 @@ .getType("A") .getType("Object"); - this.resultCollector.showAccuracy = true; + this.resultCollector.showAccuracy(true); search( type, REFERENCES, @@ -3136,7 +3132,7 @@ public void testTypeReference24() throws CoreException { // was testTypeReferenceInThrows IType type = getCompilationUnit("JavaSearch", "src", "a7", "X.java").getType("MyException"); - this.resultCollector.showAccuracy = true; + this.resultCollector.showAccuracy(true); search( type, REFERENCES, @@ -3173,8 +3169,8 @@ */ public void testTypeReference26() throws CoreException { // was testInnacurateTypeReference2 - this.resultCollector.showAccuracy = true; - this.resultCollector.showSelection = true; + this.resultCollector.showAccuracy(true); + this.resultCollector.showSelection(); search( "p.Zork", TYPE, @@ -3196,7 +3192,7 @@ public void testTypeReference27() throws CoreException { // was testInnacurateTypeReference3 IType type = getCompilationUnit("JavaSearch", "src", "r3", "A21485.java").getType("A21485"); - this.resultCollector.showAccuracy = true; + this.resultCollector.showAccuracy(true); search( type, REFERENCES, @@ -3298,7 +3294,7 @@ public void testTypeReference33() throws CoreException { // was testTypeReferenceWithRecovery IType type = getCompilationUnit("JavaSearch", "src", "e1", "A29366.java").getType("A29366"); - this.resultCollector.showAccuracy = true; + this.resultCollector.showAccuracy(true); search( type, REFERENCES, @@ -3315,7 +3311,7 @@ public void testTypeReference34() throws CoreException { // was testTypeReferenceWithProblem IType type = getCompilationUnit("JavaSearch", "src", "e6", "A.java").getType("A"); - this.resultCollector.showAccuracy = true; + this.resultCollector.showAccuracy(true); search( "B36479", TYPE, @@ -3343,7 +3339,7 @@ IType type = getCompilationUnit("JavaSearch", "src", "e7", "A.java").getType("A"); - this.resultCollector.showAccuracy = true; + this.resultCollector.showAccuracy(true); search( type, REFERENCES, @@ -3363,7 +3359,7 @@ IPackageFragment pkg = getPackageFragment("JavaSearch", "src", "f2"); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {pkg}); - this.resultCollector.showSelection = true; + this.resultCollector.showSelection(); search( "Y", TYPE, @@ -3384,7 +3380,7 @@ IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); - this.resultCollector.showSelection = true; + this.resultCollector.showSelection(); search( localType, REFERENCES, @@ -3399,7 +3395,7 @@ */ public void testTypeReference38() throws CoreException { // was testTypeReferenceInOutDocComment IType type = getCompilationUnit("JavaSearch", "src", "s4", "X.java").getType("X"); - this.resultCollector.showInsideDoc = true; + this.resultCollector.showInsideDoc(); search(type, REFERENCES, getJavaSearchScope(), this.resultCollector); assertSearchResults( "src/s4/X.java void s4.X.bar() [X] INSIDE_JAVADOC\n" + Index: src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java,v retrieving revision 1.224 diff -u -r1.224 AbstractJavaModelTests.java --- src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 9 Oct 2008 11:55:20 -0000 1.224 +++ src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 16 Oct 2008 16:39:21 -0000 @@ -433,8 +433,11 @@ protected void addLibraryEntry(String path, boolean exported) throws JavaModelException { addLibraryEntry(this.currentProject, new Path(path), null, null, null, null, exported); } + protected void addLibraryEntry(IJavaProject project, String path) throws JavaModelException { + addLibraryEntry(project, new Path(path), null, null, null, null, false); + } protected void addLibraryEntry(IJavaProject project, String path, boolean exported) throws JavaModelException { - addLibraryEntry(project, new Path(path), exported); + addLibraryEntry(project, new Path(path), null, null, null, null, exported); } protected void addLibraryEntry(IJavaProject project, IPath path, boolean exported) throws JavaModelException { addLibraryEntry(project, path, null, null, null, null, exported); Index: src/org/eclipse/jdt/core/tests/model/AbstractJavaSearchGenericTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaSearchGenericTests.java,v retrieving revision 1.6 diff -u -r1.6 AbstractJavaSearchGenericTests.java --- src/org/eclipse/jdt/core/tests/model/AbstractJavaSearchGenericTests.java 27 Jun 2008 16:02:38 -0000 1.6 +++ src/org/eclipse/jdt/core/tests/model/AbstractJavaSearchGenericTests.java 16 Oct 2008 16:39:21 -0000 @@ -32,8 +32,8 @@ protected void setUp () throws Exception { super.setUp(); - this.resultCollector.showAccuracy = true; - this.resultCollector.showRule = true; + this.resultCollector.showAccuracy(true); + this.resultCollector.showRule(); } /* Index: src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java,v retrieving revision 1.159 diff -u -r1.159 JavaSearchBugsTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 13 Oct 2008 14:05:19 -0000 1.159 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 16 Oct 2008 16:39:22 -0000 @@ -37,8 +37,8 @@ import org.eclipse.jdt.internal.core.index.Index; import org.eclipse.jdt.internal.core.search.AbstractSearchScope; import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants; -import org.eclipse.jdt.internal.core.search.matching.AndPattern; import org.eclipse.jdt.internal.core.search.indexing.IndexManager; +import org.eclipse.jdt.internal.core.search.matching.AndPattern; import org.eclipse.jdt.internal.core.search.matching.MatchLocator; import org.eclipse.jdt.internal.core.search.matching.PatternLocator; import org.eclipse.jdt.internal.core.search.matching.TypeDeclarationPattern; @@ -57,6 +57,7 @@ return buildModelTestSuite(JavaSearchBugsTests.class); } static { +// org.eclipse.jdt.internal.core.search.processing.JobManager.VERBOSE = true; // org.eclipse.jdt.internal.core.search.BasicSearchEngine.VERBOSE = true; // org.eclipse.jdt.internal.codeassist.SelectionEngine.DEBUG = true; } @@ -130,8 +131,168 @@ protected void setUp () throws Exception { super.setUp(); this.resultCollector = new TestCollector(); - this.resultCollector.showInsideDoc = false; - this.resultCollector.showAccuracy = true; + this.resultCollector.showAccuracy(true); +} + +/** + * @bug 12044: [search] Reference to package is not found in qualified annotation + * @test Ensure that references to package are also found in qualified annotation + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=12044" + */ +private String[] sourcesBug12044() throws CoreException { + return new String[] { + "Def.java", + "public class Def {\n" + + " public static final int ONE = 1;\n" + + " public static final int TWO = 2;\n" + + " public static final int THREE = 3;\n" + + "}\n", + "Ref.java", + "public class Ref {\n" + + " class Sub {\n" + + " int x = Def.ONE;\n" + + " int getX() {\n" + + " return x;\n" + + " }\n" + + " }\n" + + " void foo(Sub sub) {\n" + + " switch (sub.getX()) {\n" + + " case Def.ONE:\n" + + " break;\n" + + " case Def.TWO:\n" + + " break;\n" + + " case Def.THREE:\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n" + }; +} +static { TESTS_PREFIX = "testBug12044"; } +public void testBug12044_no_src() throws CoreException, IOException { + IJavaProject javaProject = null; + try { + javaProject = createJavaProject("b012044", new String[] { "src" }, new String[] {"JCL_LIB" }, "bin"); + waitUntilIndexesReady(); + String jarPath = getWorkspacePath()+"b012044"+File.separator+"b012044.jar"; + createJar(sourcesBug12044(), jarPath); + refresh(javaProject); + String resourcePath = "/b012044/b012044.jar"; + addLibraryEntry(javaProject, resourcePath); + waitUntilIndexesReady(); + IClassFile classFile = getClassFile("b012044", resourcePath, "", "Def.class"); + IField field = classFile.getType().getField("ONE"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject } ); + this.resultCollector.showJarFile(); + search(field, ALL_OCCURRENCES, scope); + assertSearchResults( + "b012044.jar|Def.class Def.ONE [No source] EXACT_MATCH" + ); + } + finally { + if (javaProject != null) { + deleteProject(javaProject); + } + } +} +// jar with sources inside +public void testBug12044_src_in_jar() throws CoreException, IOException { + IJavaProject javaProject = null; + try { + javaProject = createJavaProject("b012044", new String[] { "src" }, new String[] {"JCL_LIB" }, "bin"); + waitUntilIndexesReady(); + String path = getWorkspacePath()+"b012044"+File.separator+"b012044"; + String jarPath = path+".jar"; + Util.createJar(sourcesBug12044(), null, jarPath, "1.4", true/*write sources*/); + refresh(javaProject); + String resourcePath = "/b012044/b012044.jar"; + addLibraryEntry(javaProject, resourcePath); + waitUntilIndexesReady(); + IClassFile classFile = getClassFile("b012044", resourcePath, "", "Def.class"); + IField field = classFile.getType().getField("ONE"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject } ); + this.resultCollector.showJarFile(); + search(field, ALL_OCCURRENCES, scope); + assertSearchResults( + "b012044.jar|Def.class Def.ONE EXACT_MATCH\n" + + "b012044.jar|Ref.class void Ref.foo(Ref.Sub) EXACT_MATCH\n" + + "b012044.jar|Ref$Sub.class Ref$Sub.x EXACT_MATCH" + ); + } + finally { + if (javaProject != null) { + deleteProject(javaProject); + } + } +} +// jar with sources in another zip file +public void testBug12044_src_in_zip() throws CoreException, IOException { + IJavaProject javaProject = null; + try { + javaProject = createJavaProject("b012044", new String[] { "src" }, new String[] {"JCL_LIB" }, "bin"); + waitUntilIndexesReady(); + String path = getWorkspacePath()+"b012044"+File.separator+"b012044"; + String jarPath = path+".jar"; + createJar(sourcesBug12044(), jarPath); + String zipPath = path+".zip"; + Util.createSourceZip(sourcesBug12044(), zipPath); + refresh(javaProject); + String resourcePath = "/b012044/b012044.jar"; + String resourceZipPath = "/b012044/b012044.zip"; + addLibraryEntry(javaProject, resourcePath, resourceZipPath); + waitUntilIndexesReady(); + IClassFile classFile = getClassFile("b012044", resourcePath, "", "Def.class"); + IField field = classFile.getType().getField("ONE"); + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject } ); + this.resultCollector.showJarFile(); + search(field, ALL_OCCURRENCES, scope); + assertSearchResults( + "b012044.jar|Def.class Def.ONE EXACT_MATCH\n" + + "b012044.jar|Ref.class void Ref.foo(Ref.Sub) EXACT_MATCH\n" + + "b012044.jar|Ref$Sub.class Ref$Sub.x EXACT_MATCH" + ); + } + finally { + if (javaProject != null) { + deleteProject(javaProject); + } + } +} +// jar with sources in a folder +public void testBug12044_src_in_folder() throws CoreException, IOException { + IJavaProject javaProject = null, p2 = null; + try { + javaProject = createJavaProject("b012044", new String[] { "src" }, new String[] {"JCL_LIB" }, "bin"); + String[] sources = sourcesBug12044(); + for (int i=0; i", TYPE, REFERENCES, ERASURE_RULE); assertSearchResults( @@ -1863,7 +2024,7 @@ ); } private void setUpBug83304_MethodParameterizedElementPattern() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b83304/Methods.java", "package b83304;\n" + @@ -1880,7 +2041,7 @@ ); } public void testBug83304_MethodParameterizedElementPattern() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug83304_MethodParameterizedElementPattern(); IMethod method = selectMethod(this.workingCopies[0], "generic", 2); search(method, REFERENCES, ERASURE_RULE); @@ -1891,7 +2052,7 @@ ); } public void testBug83304_MethodGenericElementPattern() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug83304_MethodParameterizedElementPattern(); IType type = getClassFile("JavaSearchBugs", "lib/JavaSearch15.jar", "g5.m.def", "Single.class").getType(); IMethod method = type.getMethod("generic", new String[] { "TU;" }); @@ -1903,7 +2064,7 @@ ); } public void testBug83304_MethodStringPattern() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug83304_MethodParameterizedElementPattern(); search("generic", METHOD, REFERENCES, ERASURE_RULE); assertSearchResults( @@ -1913,7 +2074,7 @@ ); } private void setUpBug83304_ConstructorGenericElementPattern() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b83304/Constructors.java", "package b83304;\n" + @@ -1929,7 +2090,7 @@ ); } public void testBug83304_ConstructorGenericElementPattern() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug83304_ConstructorGenericElementPattern(); IMethod method = selectMethod(this.workingCopies[0], "Single", 3); search(method, REFERENCES, ERASURE_RULE); @@ -1940,7 +2101,7 @@ ); } public void testBug83304_ConstructorParameterizedElementPattern() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug83304_ConstructorGenericElementPattern(); IType type = getClassFile("JavaSearchBugs", "lib/JavaSearch15.jar", "g5.c.def", "Single.class").getType(); IMethod method = type.getMethod("Single", new String[] { "TT;", "TU;" }); @@ -1952,7 +2113,7 @@ ); } public void testBug83304_ConstructorStringPattern() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug83304_ConstructorGenericElementPattern(); search("Single", CONSTRUCTOR, REFERENCES, ERASURE_RULE); assertSearchResults( @@ -1997,7 +2158,7 @@ ); } public void testBug83804_Type() throws CoreException { - this.resultCollector.showInsideDoc = true; + this.resultCollector.showInsideDoc(); setUpBug83804_Type(); IType type = this.workingCopies[1].getType("Test"); search(type, REFERENCES); @@ -2010,7 +2171,7 @@ ); } public void testBug83804_Method() throws CoreException { - this.resultCollector.showInsideDoc = true; + this.resultCollector.showInsideDoc(); setUpBug83804_Type(); IMethod[] methods = this.workingCopies[1].getType("Test").getMethods(); assertEquals("Invalid number of methods", 1, methods.length); @@ -2020,7 +2181,7 @@ ); } public void testBug83804_Field() throws CoreException { - this.resultCollector.showInsideDoc = true; + this.resultCollector.showInsideDoc(); setUpBug83804_Type(); IField[] fields = this.workingCopies[1].getType("Test").getFields(); assertEquals("Invalid number of fields", 1, fields.length); @@ -2035,7 +2196,7 @@ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=83388" */ public void testBug83388() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b83388/R.java", "package b83388;\n" + @@ -2063,7 +2224,7 @@ ); } public void testBug83388b() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b83388/R.java", "package b83388;\n" + @@ -2096,8 +2257,8 @@ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=83693" */ public void testBug83693() throws CoreException { - this.resultCollector.showRule = true; - this.resultCollector.showInsideDoc = true; + this.resultCollector.showRule(); + this.resultCollector.showInsideDoc(); this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b83693/A.java", "package b83693;\n" + @@ -2153,7 +2314,7 @@ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=84100" */ private void setUpBug84100() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[2]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b84100/X.java", "package b84100;\n" + @@ -2181,7 +2342,7 @@ ); } public void testBug84100() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug84100(); IMethod method = selectMethod(this.workingCopies[0], "foo", 1); search(method, REFERENCES); @@ -2190,7 +2351,7 @@ ); } public void testBug84100b() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug84100(); IMethod method = selectMethod(this.workingCopies[0], "foo", 2); search(method, REFERENCES); @@ -2199,7 +2360,7 @@ ); } public void testBug84100c() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug84100(); IMethod method = selectMethod(this.workingCopies[0], "foo", 3); search(method, REFERENCES); @@ -2209,7 +2370,7 @@ ); } public void testBug84100d() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug84100(); IMethod method = selectMethod(this.workingCopies[0], "foo", 4); search(method, REFERENCES); @@ -2218,7 +2379,7 @@ ); } public void testBug84100e() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug84100(); IMethod method = selectMethod(this.workingCopies[0], "foo", 5); search(method, REFERENCES); @@ -2232,7 +2393,7 @@ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=84121" */ public void testBug84121() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b84121/Test.java", "package b84121;\n" + @@ -2257,7 +2418,7 @@ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=84724" */ private void setUpBug84724() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[2]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b84724/X.java", "package b84724;\n" + @@ -2283,7 +2444,7 @@ ); } public void testBug84724() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug84724(); IMethod method = selectMethod(this.workingCopies[0], "X", 2); search(method, REFERENCES); @@ -2292,7 +2453,7 @@ ); } public void testBug84724b() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug84724(); IMethod method = selectMethod(this.workingCopies[0], "X", 3); search(method, REFERENCES); @@ -2303,7 +2464,7 @@ ); } public void testBug84724c() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug84724(); IMethod method = selectMethod(this.workingCopies[0], "X", 4); search(method, REFERENCES); @@ -2312,7 +2473,7 @@ ); } public void testBug84724d() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug84724(); IMethod method = selectMethod(this.workingCopies[0], "X", 5); search(method, REFERENCES); @@ -2326,7 +2487,7 @@ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=84727" */ private void setUpBug84727() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[3]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b84727/A.java", "package b84727;\n" + @@ -2353,7 +2514,7 @@ ); } public void testBug84727() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug84727(); IMethod[] methods = this.workingCopies[0].getType("A").getMethods(); assertEquals("Invalid number of methods", 2, methods.length); @@ -2363,7 +2524,7 @@ ); } public void testBug84727b() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug84727(); IMethod[] methods = this.workingCopies[0].getType("A").getMethods(); assertEquals("Invalid number of methods", 2, methods.length); @@ -2378,7 +2539,7 @@ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=85810" */ public void testBug85810() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b85810/Test.java", "package b85810;\n" + @@ -2400,7 +2561,7 @@ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=86596" */ public void testBug86596() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[3]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b86596/aa/link/A.java", "package b86596.aa.link;\n" + @@ -2431,7 +2592,7 @@ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=86642" */ public void testBug86642() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[2]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b86642/A.java", "package b86642;\n" + @@ -2475,7 +2636,7 @@ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=86380" */ private void setUpBug86380() throws CoreException { - this.resultCollector.showInsideDoc = true; + this.resultCollector.showInsideDoc(); this.workingCopies = new ICompilationUnit[2]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b86380/package-info.java", "/**\n" + @@ -2493,7 +2654,7 @@ ); } public void testBug86380_Type() throws CoreException { - this.resultCollector.showInsideDoc = true; + this.resultCollector.showInsideDoc(); setUpBug86380(); ICompilationUnit unit = getCompilationUnit("JavaSearchBugs", "src", "b86380", "Annot.java"); IType type = unit.getType("Annot"); @@ -2506,7 +2667,7 @@ ); } public void testBug86380_Method() throws CoreException { - this.resultCollector.showInsideDoc = true; + this.resultCollector.showInsideDoc(); setUpBug86380(); ICompilationUnit unit = getCompilationUnit("JavaSearchBugs", "src", "b86380", "Annot.java"); IMethod[] methods = unit.getType("Annot").getMethods(); @@ -2518,7 +2679,7 @@ ); } public void testBug86380_Field() throws CoreException { - this.resultCollector.showInsideDoc = true; + this.resultCollector.showInsideDoc(); setUpBug86380(); ICompilationUnit unit = getCompilationUnit("JavaSearchBugs", "src", "b86380", "Annot.java"); IField[] fields = unit.getType("Annot").getFields(); @@ -2535,7 +2696,7 @@ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=88174" */ public void testBug88174() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[2]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b88174/Test.java", "package b88174;\n" + @@ -3008,7 +3169,7 @@ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=92944" */ private void setUpBug92944() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b92944/Test.java", "package b92944;\n" + @@ -3019,7 +3180,7 @@ ); } public void testBug92944_TYPE() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug92944(); TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( @@ -3042,7 +3203,7 @@ requestor); } public void testBug92944_CLASS() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug92944(); TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( @@ -3063,7 +3224,7 @@ requestor); } public void testBug92944_CLASS_AND_INTERFACE() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug92944(); TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( @@ -3085,7 +3246,7 @@ requestor); } public void testBug92944_CLASS_AND_ENUM() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug92944(); TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( @@ -3107,7 +3268,7 @@ requestor); } public void testBug92944_INTERFACE() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug92944(); TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( @@ -3127,7 +3288,7 @@ requestor); } public void testBug92944_ENUM() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug92944(); TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( @@ -3147,7 +3308,7 @@ requestor); } public void testBug92944_ANNOTATION_TYPE() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug92944(); TypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor(); new SearchEngine(this.workingCopies).searchAllTypeNames( @@ -3177,7 +3338,7 @@ */ public void testBug93392() throws CoreException { TestCollector collector = new TestCollector(); - collector.showAccuracy = true; + collector.showAccuracy(true); this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b93392/Test.java", "package b93392;\n" + @@ -3503,7 +3664,7 @@ // Verify matches TestCollector occurencesCollector = new TestCollector(); - occurencesCollector.showAccuracy = true; + occurencesCollector.showAccuracy(true); search(type, ALL_OCCURRENCES, getJavaSearchScope(), occurencesCollector); assertSearchResults( "src/b95794/Test.java [b95794.Test] EXACT_MATCH\n" + @@ -3519,13 +3680,13 @@ assertEquals("Problem with occurences or references number of matches: ", occurencesCollector.matches.size()-1, referencesCollector.matches.size()); } public void testBug95794b() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); ICompilationUnit unit = getCompilationUnit("JavaSearchBugs", "src", "b95794", "Test.java"); IType type = unit.getType("Test").getType("Color"); // Verify matches TestCollector occurencesCollector = new TestCollector(); - occurencesCollector.showAccuracy = true; + occurencesCollector.showAccuracy(true); search(type, ALL_OCCURRENCES, getJavaSearchScope(), occurencesCollector); assertSearchResults( "src/b95794/Test.java [b95794.Test.Color] EXACT_MATCH\n" + @@ -3541,13 +3702,13 @@ assertEquals("Problem with occurences or references number of matches: ", occurencesCollector.matches.size()-1, referencesCollector.matches.size()); } public void testBug95794c() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); ICompilationUnit unit = getCompilationUnit("JavaSearchBugs", "src", "b95794", "Test.java"); IField field = unit.getType("Test").getType("Color").getField("WHITE"); // Verify matches TestCollector occurencesCollector = new TestCollector(); - occurencesCollector.showAccuracy = true; + occurencesCollector.showAccuracy(true); search(field, ALL_OCCURRENCES, getJavaSearchScope(), occurencesCollector); assertSearchResults( "src/b95794/Test.java [WHITE] EXACT_MATCH\n" + @@ -3656,7 +3817,7 @@ */ public void testBug97087() throws CoreException { this.workingCopies = new ICompilationUnit[1]; - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b97087/Bug.java", "package b97087;\n" + "public class Bug {\n" + @@ -3796,7 +3957,7 @@ this.workingCopies[1].commitWorkingCopy(true, null); this.workingCopies[2].commitWorkingCopy(true, null); this.workingCopies[3].commitWorkingCopy(true, null); - this.resultCollector.showRule = true; + this.resultCollector.showRule(); IType type = this.workingCopies[0].getType("L"); search(type, REFERENCES, SearchPattern.R_ERASURE_MATCH); assertSearchResults( @@ -3849,7 +4010,7 @@ this.workingCopies[1].commitWorkingCopy(true, null); this.workingCopies[2].commitWorkingCopy(true, null); this.workingCopies[3].commitWorkingCopy(true, null); - this.resultCollector.showRule = true; + this.resultCollector.showRule(); IType type = this.workingCopies[0].getType("L"); search(type, REFERENCES, SearchPattern.R_ERASURE_MATCH); assertSearchResults( @@ -4042,7 +4203,7 @@ "public @interface Annot {\n" + "}\n" ); - this.resultCollector.showInsideDoc = true; + this.resultCollector.showInsideDoc(); IType type = this.workingCopies[1].getType("Test"); search(type, REFERENCES); assertSearchResults( @@ -6036,7 +6197,7 @@ "}" ); IType type = this.workingCopies[0].getType("X"); - this.resultCollector.showRule = true; + this.resultCollector.showRule(); search(type, REFERENCES, ERASURE_RULE); assertSearchResults( "src/p1/X.java p1.X.gen [X] EXACT_MATCH\n" + @@ -6485,7 +6646,7 @@ "}" ); IType type = this.workingCopies[0].getType("Foo"); - this.resultCollector.showRule = true; + this.resultCollector.showRule(); new SearchEngine(this.workingCopies).search( SearchPattern.createPattern(type, REFERENCES), new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, @@ -7449,7 +7610,7 @@ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=148380" */ public void testBug148380_SearchAllTypes_wc() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[4]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b148380/I.java", "package b148380;\n" + @@ -7556,7 +7717,7 @@ ); waitUntilIndexesReady(); IPackageFragment packageFragment = getPackage("/JavaSearchBugs/src/b153765"); - this.resultCollector.showSelection = true; + this.resultCollector.showSelection(); search(packageFragment, REFERENCES); assertSearchResults( "src/b153765/test/SomeClass.java void b153765.test.SomeClass.foo() [ @§|b153765|§.Unimportant public void foo() {}] EXACT_MATCH" @@ -7610,7 +7771,7 @@ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=156177" */ public void testBug156177() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b156177/Test.java", "package b156177;\n" + @@ -7643,7 +7804,7 @@ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=156491" */ public void testBug156491() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/pack/Test.java", "package pack;\n" + @@ -7714,7 +7875,7 @@ ); } public void testBug156491a() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug156491(); IMethod method = this.workingCopies[0].getType("L2").getMethod("test", new String[0]); this.resultCollector.showFlavors = PatternLocator.SUPER_INVOCATION_FLAVOR; @@ -7726,7 +7887,7 @@ ); } public void testBug156491b() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug156491(); IMethod method = this.workingCopies[0].getType("L1").getMethod("test", new String[0]); this.resultCollector.showFlavors = PatternLocator.SUPER_INVOCATION_FLAVOR; @@ -7744,7 +7905,7 @@ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=160301" */ public void testBug160301() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/Test.java", "public class Test {\n" + @@ -7774,7 +7935,7 @@ ); } public void testBug160301b() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/test/Test.java", "package test;\n" + @@ -7810,7 +7971,7 @@ ); } public void testBug160301_Interface() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/Test.java", "public class Test {\n" + @@ -7864,7 +8025,7 @@ ); } public void testBug160301_Abstract() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/Test.java", "public class Test {\n" + @@ -7911,7 +8072,7 @@ ); } public void testBug160301_Abstract2() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/Test.java", "public class Test {\n" + @@ -7946,7 +8107,7 @@ ); } public void testBug160301_Abstract3() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/Test.java", "public class Test {\n" + @@ -8301,7 +8462,7 @@ ); } public void testBug164121a() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug164121(); ILocalVariable param = getLocalVariable(this.workingCopies[0], "param", "param"); search(param, DECLARATIONS); @@ -8310,7 +8471,7 @@ ); } public void testBug164121b() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); setUpBug164121(); ILocalVariable param = getLocalVariable(this.workingCopies[0], "param", "param"); search(param, ALL_OCCURRENCES); @@ -8336,7 +8497,7 @@ assertTrue("Search match element "+element.getElementName()+" should exist!!!", element.exists()); } }; - collector.showAccuracy = true; + collector.showAccuracy(true); search(type, REFERENCES, getJavaSearchScope(), collector); assertSearchResults( "lib/b164791.jar test. EXACT_MATCH\n" + @@ -8459,7 +8620,7 @@ } }; - testCollector.showAccuracy = true; + testCollector.showAccuracy(true); IMethod method = this.workingCopies[0].getType("ClassA").getMethod("setValue", new String[] { "I" }); search(method, REFERENCES, getJavaSearchScope(), testCollector); assertSearchResults( @@ -8675,7 +8836,7 @@ "}\n" + "class Ref {}" ); - this.resultCollector.showInsideDoc = true; + this.resultCollector.showInsideDoc(); new SearchEngine(this.workingCopies).searchDeclarationsOfReferencedTypes(this.workingCopies[0], this.resultCollector, null); assertSearchResults( "src/b195489/Test.java b195489.Ref [Ref] EXACT_MATCH OUTSIDE_JAVADOC" @@ -8696,7 +8857,7 @@ "}\n" + "class Ref {}" ); - this.resultCollector.showInsideDoc = true; + this.resultCollector.showInsideDoc(); new SearchEngine(this.workingCopies).searchDeclarationsOfReferencedTypes(this.workingCopies[0], this.resultCollector, null); assertSearchResults( "src/b195489/Test.java b195489.Ref [Ref] EXACT_MATCH OUTSIDE_JAVADOC" @@ -8713,7 +8874,7 @@ "}\n" + "class Ref {}" ); - this.resultCollector.showInsideDoc = true; + this.resultCollector.showInsideDoc(); new SearchEngine(this.workingCopies).searchDeclarationsOfReferencedTypes(this.workingCopies[0], this.resultCollector, null); assertSearchResults( "src/b195489/Test.java b195489.Ref [Ref] EXACT_MATCH OUTSIDE_JAVADOC" @@ -8731,7 +8892,7 @@ "}\n" + "class Ref {}" ); - this.resultCollector.showInsideDoc = true; + this.resultCollector.showInsideDoc(); String docCommentSupport = JAVA_PROJECT.getOption(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, true); JAVA_PROJECT.setOption(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.DISABLED); try { @@ -9305,7 +9466,7 @@ ); IType type = this.workingCopies[0].getType("Test"); ReferenceCollector collector = new ReferenceCollector(); - collector.showSelection = true; + collector.showSelection(); search(type, REFERENCES, EXACT_RULE, getJavaSearchScope(), collector); assertSearchResults( "src/test/Test.java @Annot(clazz=Test.class) [ @Annot(clazz=§|Test|§.class) int x;]", @@ -9321,7 +9482,7 @@ "}\n" ); ReferenceCollector collector = new ReferenceCollector(); - collector.showSelection = true; + collector.showSelection(); search("Deprecated", TYPE, REFERENCES, EXACT_RULE, getJavaSearchScope(), collector); assertSearchResults( "src/test/Test.java @Deprecated() [ @§|Deprecated|§ foo() {}]", @@ -9347,7 +9508,7 @@ ); IType type = this.workingCopies[0].getType("Ref"); ReferenceCollector collector = new ReferenceCollector(); - collector.showSelection = true; + collector.showSelection(); search(type, REFERENCES, EXACT_RULE, getJavaSearchScope(), collector); assertSearchResults( "src/comment5/Ref.java void comment5.Ref.doA(Ref).ref [ void doA(§|Ref|§ ref) {}]\n" + @@ -9370,7 +9531,7 @@ ); IField field = this.workingCopies[0].getType("Num").getField("CONST"); ReferenceCollector collector = new ReferenceCollector(); - collector.showSelection = true; + collector.showSelection(); search(field, REFERENCES, EXACT_RULE, getJavaSearchScope(), collector); assertSearchResults( "src/comment10/Ref.java @Num(number=Num.CONST) [@Num(number= Num.§|CONST|§)]", @@ -9392,7 +9553,7 @@ ); IType type = this.workingCopies[0].getType("Tag"); TypeReferenceCollector collector = new TypeReferenceCollector(); - collector.showSelection = true; + collector.showSelection(); search(type, REFERENCES, EXACT_RULE, getJavaSearchScope(), collector); assertSearchResults( "src/comment22/Test.java @Tag() [ @§|Tag|§ Test test1, test2, test3;]\n" + @@ -9414,7 +9575,7 @@ ); IType type = this.workingCopies[0].getType("Test"); TypeReferenceCollector collector = new TypeReferenceCollector(); - collector.showSelection = true; + collector.showSelection(); search(type, REFERENCES, EXACT_RULE, getJavaSearchScope(), collector); assertSearchResults( "src/test/Test.java @Annot(clazz=test.Test.class) [ @Annot(clazz = §|test.Test|§.class) int x, y;]", @@ -9469,7 +9630,7 @@ "public class Types {\n" + "}\n" ); - this.resultCollector.showSelection = true; + this.resultCollector.showSelection(); search("*", TYPE, REFERENCES, getJavaSearchWorkingCopiesScope(), this.resultCollector); assertSearchResults( "src/generics/Generic.java [import §|java.io.Serializable|§;] EXACT_MATCH\n" + @@ -9508,7 +9669,7 @@ " Test test;\n" + "}\n" ); - this.resultCollector.showSelection = true; + this.resultCollector.showSelection(); search("*", TYPE, REFERENCES, getJavaSearchWorkingCopiesScope(), this.resultCollector); assertSearchResults( "src/test/Ref.java [import §|pack.Test|§;] EXACT_MATCH\n" + @@ -9525,7 +9686,7 @@ addLibraryEntry(JAVA_PROJECT, "/JavaSearchBugs/lib/b211366.jar", false); try { IType type = getClassFile("JavaSearchBugs", "lib/b211366.jar", "test", "Bug.class").getType(); - this.resultCollector.showMatchKind = true; + this.resultCollector.showMatchKind(); search(type, REFERENCES); assertSearchResults( "TypeReferenceMatch: lib/b211366.jar pack.Test [No source] EXACT_MATCH\n" + @@ -9545,7 +9706,7 @@ SearchPattern rightPattern = SearchPattern.createPattern(type, REFERENCES); SearchPattern leftPattern = SearchPattern.createPattern(type, DECLARATIONS); SearchPattern pattern = SearchPattern.createOrPattern(leftPattern, rightPattern); - this.resultCollector.showMatchKind = true; + this.resultCollector.showMatchKind(); new SearchEngine(this.workingCopies).search( pattern, new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, @@ -9579,7 +9740,7 @@ SearchPattern.createPattern("Bug", TYPE, REFERENCES, SearchPattern.R_EXACT_MATCH))); IPackageFragmentRoot root = JAVA_PROJECT.getPackageFragmentRoot("/JavaSearchBugs/lib/b211366.jar"); this.resultCollector.sorted = true; - this.resultCollector.showMatchKind = true; + this.resultCollector.showMatchKind(); new SearchEngine(this.workingCopies).search( SearchPattern.createOrPattern(leftPattern, rightPattern), new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, @@ -9731,7 +9892,7 @@ "\n" + "}\n" ); - this.resultCollector.showSelection = true; + this.resultCollector.showSelection(); ILocalVariable variable = selectLocalVariable(this.workingCopies[0], "test"); search(variable, READ_ACCESSES, getJavaSearchWorkingCopiesScope(), this.resultCollector); assertSearchResults( @@ -9751,7 +9912,7 @@ " int fField;" + "}" ); - this.resultCollector.showSelection = true; + this.resultCollector.showSelection(); IField field = this.workingCopies[0].getType("Test").getField("fWrapped"); search(field, READ_ACCESSES, getJavaSearchWorkingCopiesScope(), this.resultCollector); assertSearchResults( @@ -9777,7 +9938,7 @@ " }\n" + "}\n" ); - this.resultCollector.showSelection = true; + this.resultCollector.showSelection(); ILocalVariable variable = selectLocalVariable(this.workingCopies[1], "t1"); search(variable, READ_ACCESSES, getJavaSearchWorkingCopiesScope(), this.resultCollector); assertSearchResults( @@ -9806,7 +9967,7 @@ " }\n" + "}\n" ); - this.resultCollector.showSelection = true; + this.resultCollector.showSelection(); IField field = this.workingCopies[1].getType("X").getField("t1"); search(field, READ_ACCESSES, getJavaSearchWorkingCopiesScope(), this.resultCollector); assertSearchResults( @@ -9834,7 +9995,7 @@ " }\n" + "}\n" ); - this.resultCollector.showSelection = true; + this.resultCollector.showSelection(); ILocalVariable variable = selectLocalVariable(this.workingCopies[1], "t1"); search(variable, WRITE_ACCESSES, getJavaSearchWorkingCopiesScope(), this.resultCollector); assertSearchResults( @@ -9861,7 +10022,7 @@ " }\n" + "}\n" ); - this.resultCollector.showSelection = true; + this.resultCollector.showSelection(); IField field = this.workingCopies[1].getType("X").getField("t1"); search(field, WRITE_ACCESSES, getJavaSearchWorkingCopiesScope(), this.resultCollector); assertSearchResults( @@ -9887,9 +10048,9 @@ " }\n" + "}\n" ); - this.resultCollector.showSelection = true; - this.resultCollector.showAccess = true; - this.resultCollector.showAccuracy = false; + this.resultCollector.showSelection(); + this.resultCollector.showAccess(); + this.resultCollector.showAccuracy(false); ILocalVariable variable = selectLocalVariable(this.workingCopies[1], "t1"); search(variable, REFERENCES, getJavaSearchWorkingCopiesScope(), this.resultCollector); assertSearchResults( @@ -9919,9 +10080,9 @@ " }\n" + "}\n" ); - this.resultCollector.showSelection = true; - this.resultCollector.showAccess = true; - this.resultCollector.showAccuracy = false; + this.resultCollector.showSelection(); + this.resultCollector.showAccess(); + this.resultCollector.showAccuracy(false); IField field = this.workingCopies[1].getType("X").getField("t1"); search(field, REFERENCES, getJavaSearchWorkingCopiesScope(), this.resultCollector); assertSearchResults( @@ -9949,7 +10110,7 @@ " }\n" + "}" ); - this.resultCollector.showSelection = true; + this.resultCollector.showSelection(); IType type = selectType(this.workingCopies[0], "Row"); search(type, REFERENCES, getJavaSearchWorkingCopiesScope(), this.resultCollector); assertSearchResults( @@ -9975,8 +10136,8 @@ " }\n" + "}\n" ); - this.resultCollector.showSelection = true; - this.resultCollector.showRule = true; + this.resultCollector.showSelection(); + this.resultCollector.showRule(); SearchPattern typePattern = SearchPattern.createPattern("test", TYPE, ALL_OCCURRENCES, SearchPattern.R_EXACT_MATCH); SearchPattern methPattern = SearchPattern.createPattern("test", METHOD, ALL_OCCURRENCES, SearchPattern.R_EXACT_MATCH); SearchPattern fieldPattern = SearchPattern.createPattern("test", FIELD, ALL_OCCURRENCES, SearchPattern.R_EXACT_MATCH); @@ -10014,8 +10175,8 @@ "public class Y> {\n" + "}\n" ); - this.resultCollector.showSelection = true; - this.resultCollector.showRule = true; + this.resultCollector.showSelection(); + this.resultCollector.showRule(); IType type = this.workingCopies[0].getType("X"); search(type, REFERENCES, SearchPattern.R_ERASURE_MATCH, getJavaSearchWorkingCopiesScope(), this.resultCollector); assertSearchResults( @@ -10036,8 +10197,8 @@ "public class Z & I> {\n" + "}\n" ); - this.resultCollector.showSelection = true; - this.resultCollector.showRule = true; + this.resultCollector.showSelection(); + this.resultCollector.showRule(); IType type = this.workingCopies[0].getType("I"); search(type, REFERENCES, SearchPattern.R_ERASURE_MATCH, getJavaSearchWorkingCopiesScope(), this.resultCollector); assertSearchResults( @@ -10107,7 +10268,7 @@ "\n" + "}\n" ); - this.resultCollector.showSelection = true; + this.resultCollector.showSelection(); IType type = this.workingCopies[0].getType("Test"); search(type, REFERENCES, getJavaSearchWorkingCopiesScope()); Index: src/org/eclipse/jdt/core/tests/model/SearchTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SearchTests.java,v retrieving revision 1.52 diff -u -r1.52 SearchTests.java --- src/org/eclipse/jdt/core/tests/model/SearchTests.java 19 Sep 2008 09:24:36 -0000 1.52 +++ src/org/eclipse/jdt/core/tests/model/SearchTests.java 16 Oct 2008 16:39:26 -0000 @@ -81,7 +81,8 @@ CharOperation.concatWith(enclosingTypeNames, '$'), simpleTypeName, '$'); - this.results.addElement(new String(CharOperation.concat(packageName, typeName, '.'))); + String qualifiedName = new String(CharOperation.concat(packageName, typeName, '.')); + this.results.addElement(qualifiedName); } public String toString(){ int length = this.results.size(); Index: src/org/eclipse/jdt/core/tests/model/JavaSearchGenericFieldTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchGenericFieldTests.java,v retrieving revision 1.14 diff -u -r1.14 JavaSearchGenericFieldTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchGenericFieldTests.java 27 Jun 2008 16:02:38 -0000 1.14 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchGenericFieldTests.java 16 Oct 2008 16:39:24 -0000 @@ -30,7 +30,7 @@ protected void setUp () throws Exception { super.setUp(); - this.resultCollector.showAccuracy = true; + this.resultCollector.showAccuracy(true); } /** Index: src/org/eclipse/jdt/core/tests/model/JavaSearchScopeTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchScopeTests.java,v retrieving revision 1.19 diff -u -r1.19 JavaSearchScopeTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchScopeTests.java 27 Jun 2008 16:02:38 -0000 1.19 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchScopeTests.java 16 Oct 2008 16:39:25 -0000 @@ -16,7 +16,6 @@ import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Path; import org.eclipse.jdt.core.*; import org.eclipse.jdt.core.search.*; import org.eclipse.jdt.core.tests.model.AbstractJavaSearchTests.JavaSearchResultCollector; @@ -873,7 +872,7 @@ IPackageFragmentRoot root = project.getPackageFragmentRoot(getFolder("/P1/test")); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {root}); JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); - resultCollector.showProject = true; + resultCollector.showProject(); search("foo", METHOD, DECLARATIONS, scope, resultCollector); assertSearchResults( "test/Test.java [in P1] void Test.foo() [foo]", @@ -910,7 +909,7 @@ ); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {project}); JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); - resultCollector.showProject = true; + resultCollector.showProject(); search("ITest", TYPE, REFERENCES, scope, resultCollector); assertSearchResults( "test/Test.java [in P1] Test.test [ITest]\n" + @@ -947,7 +946,7 @@ assertNotNull("We should have a default fragment for project P1!", defaultFragment); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {defaultFragment}); JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); - resultCollector.showProject = true; + resultCollector.showProject(); search("main(String[]) void", METHOD, DECLARATIONS, scope, resultCollector); assertSearchResults( "Test.java [in P1] void Test.main(String[]) [main]", @@ -982,7 +981,7 @@ ); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }); JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); - resultCollector.showProject = true; + resultCollector.showProject(); search("Test", TYPE, REFERENCES, scope, resultCollector); assertSearchResults( "src/X.java [in P1] X.test [Test]", @@ -1023,7 +1022,8 @@ // Index the output location as it is a library for the project IndexManager indexManager = JavaModelManager.getIndexManager(); - indexManager.indexLibrary(new Path("/P1/bin"), project.getProject()); + IPackageFragmentRoot root = project.getPackageFragmentRoot(getWorkspaceRoot().findMember("/P1/bin")); + indexManager.indexPackageFragmentRoot(root); waitUntilIndexesReady(); // Search for all types Index: src/org/eclipse/jdt/core/tests/model/JavaSearchFineGrainTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchFineGrainTests.java,v retrieving revision 1.10 diff -u -r1.10 JavaSearchFineGrainTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchFineGrainTests.java 27 Jun 2008 16:02:40 -0000 1.10 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchFineGrainTests.java 16 Oct 2008 16:39:23 -0000 @@ -63,10 +63,10 @@ protected void setUp () throws Exception { super.setUp(); this.resultCollector = new JavaSearchResultCollector(); - this.resultCollector.showInsideDoc = false; - this.resultCollector.showAccuracy = true; - this.resultCollector.showSelection = true; - this.resultCollector.showOffset = true; +// this.resultCollector.showInsideDoc = false; + this.resultCollector.showAccuracy(true); + this.resultCollector.showSelection(); + this.resultCollector.showOffset(); } static { @@ -112,8 +112,8 @@ "----------\n", problemRequestor.problems.toString() ); - this.resultCollector.showSelection = true; - this.resultCollector.showOffset = true; + this.resultCollector.showSelection(); + this.resultCollector.showOffset(); return this.workingCopies[0].getType("Fields").getField("field"); } public void testFieldRef() throws CoreException { @@ -193,8 +193,8 @@ "----------\n", problemRequestor.problems.toString() ); - this.resultCollector.showSelection = true; - this.resultCollector.showOffset = true; + this.resultCollector.showSelection(); + this.resultCollector.showOffset(); return this.workingCopies[0].getType("Methods").getMethod("method", new String[0]); } public void testMethodRef() throws CoreException { @@ -574,8 +574,8 @@ "----------\n", problemRequestor.problems.toString() ); - this.resultCollector.showSelection = true; - this.resultCollector.showOffset = true; + this.resultCollector.showSelection(); + this.resultCollector.showOffset(); } public void testTypeRefAll_Allocation() throws CoreException { setUpTypeRefAll(); @@ -749,8 +749,8 @@ "----------\n", problemRequestor.problems.toString() ); - this.resultCollector.showSelection = true; - this.resultCollector.showOffset = true; + this.resultCollector.showSelection(); + this.resultCollector.showOffset(); return this.workingCopies[0].getType("Types"); } public void testTypeRefGeneric01() throws CoreException { @@ -970,8 +970,8 @@ "----------\n", problemRequestor.problems.toString() ); - this.resultCollector.showSelection = true; - this.resultCollector.showOffset = true; + this.resultCollector.showSelection(); + this.resultCollector.showOffset(); return this.workingCopies[0].getType("Types"); } public void testTypeRefGenericAll02() throws CoreException { @@ -1154,8 +1154,8 @@ "----------\n", problemRequestor.problems.toString() ); - this.resultCollector.showSelection = true; - this.resultCollector.showOffset = true; + this.resultCollector.showSelection(); + this.resultCollector.showOffset(); } public void testTypeRefGenericMethod_AllGenericFlags() throws CoreException { setUpTypeRefGenericMethod(); @@ -1279,8 +1279,8 @@ "----------\n", problemRequestor.problems.toString() ); - this.resultCollector.showSelection = true; - this.resultCollector.showOffset = true; + this.resultCollector.showSelection(); + this.resultCollector.showOffset(); } public void testTypeRefQualifiedAll_Allocation() throws CoreException { setUpTypeRefQualifiedAll(); Index: src/org/eclipse/jdt/core/tests/model/AbstractJavaSearchTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaSearchTests.java,v retrieving revision 1.36 diff -u -r1.36 AbstractJavaSearchTests.java --- src/org/eclipse/jdt/core/tests/model/AbstractJavaSearchTests.java 27 Jun 2008 16:02:38 -0000 1.36 +++ src/org/eclipse/jdt/core/tests/model/AbstractJavaSearchTests.java 16 Oct 2008 16:39:21 -0000 @@ -24,6 +24,7 @@ import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.search.*; import org.eclipse.jdt.internal.compiler.problem.AbortCompilationUnit; +import org.eclipse.jdt.internal.core.Member; import org.eclipse.jdt.internal.core.PackageFragment; //import org.eclipse.jdt.internal.core.ResolvedSourceMethod; //import org.eclipse.jdt.internal.core.ResolvedSourceType; @@ -47,22 +48,28 @@ // boolean discard; /** + * Flags for the default search result collector + */ + static protected final int SHOW_ACCURACY = 0x0001; + static protected final int SHOW_SELECTION = 0x0002; + static protected final int SHOW_RULE = 0x0004; + static protected final int SHOW_INSIDE_DOC = 0x0008; + static protected final int SHOW_POTENTIAL = 0x0010; + static protected final int SHOW_PROJECT = 0x0020; + static protected final int SHOW_SYNTHETIC = 0x0040; + static protected final int SHOW_OFFSET = 0x0080; + static protected final int SHOW_ACCESS = 0x0100; + static protected final int SHOW_MATCH_KIND = 0x0200; + static protected final int SHOW_JAR_FILE = 0x0400; + + /** * Collects results as a string. */ public static class JavaSearchResultCollector extends SearchRequestor { + int flags = SHOW_POTENTIAL; // default protected SearchMatch match; public StringBuffer results = new StringBuffer(), line; - public boolean showAccuracy; - public boolean showSelection; - public boolean showRule; - public boolean showInsideDoc; - public boolean showPotential = true; - public boolean showProject; - public boolean showSynthetic; - public boolean showOffset = false; - public boolean showAccess = false; public int showFlavors = 0; - public boolean showMatchKind = false; public int count = 0; List lines = new ArrayList(); boolean sorted; @@ -76,7 +83,7 @@ this.count++; this.match = searchMatch; writeLine(); - if (this.line != null && (this.match.getAccuracy() == SearchMatch.A_ACCURATE || this.showPotential)) { + if (this.line != null && (this.match.getAccuracy() == SearchMatch.A_ACCURATE || (this.flags & SHOW_POTENTIAL) != 0)) { this.lines.add(this.line); } } @@ -88,13 +95,13 @@ IResource resource = this.match.getResource(); IJavaElement element = getElement(this.match); this.line = new StringBuffer(); - if (this.showMatchKind) { + if ((this.flags & SHOW_MATCH_KIND) != 0) { String matchClassName = this.match.getClass().getName(); this.line.append(matchClassName.substring(matchClassName.lastIndexOf('.')+1)); this.line.append(": "); } this.line.append(getPathString(resource, element)); - if (this.showProject) { + if ((this.flags & SHOW_PROJECT) != 0) { IProject project = element.getJavaProject().getProject(); this.line.append(" [in "); this.line.append(project.getName()); @@ -174,7 +181,7 @@ if (start == -1 || (contents != null && contents.length > 0)) { // retrieving attached source not implemented here this.line.append(" ["); if (start > -1) { - if (this.showSelection) { + if ((this.flags & SHOW_SELECTION) != 0) { int lineStart1 = CharOperation.lastIndexOf('\n', contents, 0, start); int lineStart2 = CharOperation.lastIndexOf('\r', contents, 0, start); int lineStart = Math.max(lineStart1, lineStart2) + 1; @@ -182,7 +189,7 @@ this.line.append("§|"); } this.line.append(CharOperation.subarray(contents, start, end)); - if (this.showSelection) { + if ((this.flags & SHOW_SELECTION) != 0) { this.line.append("|§"); int lineEnd1 = CharOperation.indexOf('\n', contents, end); int lineEnd2 = CharOperation.indexOf('\r', contents, end); @@ -190,7 +197,7 @@ if (lineEnd == -1) lineEnd = contents.length; this.line.append(CharOperation.subarray(contents, end, lineEnd)); } - if (this.showOffset) { + if ((this.flags & SHOW_OFFSET) != 0) { this.line.append('@'); this.line.append(start); } @@ -200,10 +207,10 @@ this.line.append("]"); } } - if (this.showAccuracy) { + if ((this.flags & SHOW_ACCURACY) != 0) { this.line.append(" "); if (this.match.getAccuracy() == SearchMatch.A_ACCURATE) { - if (this.showRule) { + if ((this.flags & SHOW_RULE) != 0) { if (this.match.isExact()) { this.line.append("EXACT_"); } else if (this.match.isEquivalent()) { @@ -224,7 +231,7 @@ this.line.append("POTENTIAL_MATCH"); } } - if (this.showInsideDoc) { + if ((this.flags & SHOW_INSIDE_DOC) != 0) { this.line.append(" "); if (this.match.isInsideDocComment()) { this.line.append("INSIDE_JAVADOC"); @@ -232,7 +239,7 @@ this.line.append("OUTSIDE_JAVADOC"); } } - if (this.showSynthetic) { + if ((this.flags & SHOW_SYNTHETIC) != 0) { if (this.match instanceof MethodReferenceMatch) { MethodReferenceMatch methRef = (MethodReferenceMatch) this.match; if (methRef.isSynthetic()) { @@ -248,7 +255,7 @@ } } } - if (this.showAccess) { + if ((this.flags & SHOW_ACCESS) != 0) { if (this.match instanceof FieldReferenceMatch) { FieldReferenceMatch fieldRef = (FieldReferenceMatch) this.match; if (fieldRef.isReadAccess()) { @@ -277,6 +284,47 @@ private boolean showSuperInvocation() { return (this.showFlavors & PatternLocator.SUPER_INVOCATION_FLAVOR) != 0; } + public void showAccess() { + this.flags |= SHOW_ACCESS; + } + public void showAccuracy(boolean on) { + if (on) { + this.flags |= SHOW_ACCURACY; + } else { + this.flags &= ~SHOW_ACCURACY; + } + } + public void showInsideDoc() { + this.flags |= SHOW_INSIDE_DOC; + } + public void showJarFile() { + this.flags |= SHOW_JAR_FILE; + } + public void showMatchKind() { + this.flags |= SHOW_MATCH_KIND; + } + public void showOffset() { + this.flags |= SHOW_OFFSET; + } + public void showPotential(boolean on) { + if (on) { + this.flags |= SHOW_POTENTIAL; + } else { + this.flags &= ~SHOW_POTENTIAL; + } + } + public void showProject() { + this.flags |= SHOW_PROJECT; + } + public void showRule() { + this.flags |= SHOW_RULE; + } + public void showSelection() { + this.flags |= SHOW_SELECTION; + } + public void showSynthetic() { + this.flags |= SHOW_SYNTHETIC; + } protected void append(IAnnotation annotation) throws JavaModelException { this.line.append("@"); this.line.append(annotation.getElementName()); @@ -405,6 +453,22 @@ String pathString; if (resource != null) { IPath path = resource.getProjectRelativePath(); + if ((this.flags & SHOW_JAR_FILE) != 0 && element instanceof Member) { + IPackageFragmentRoot pkgFragmentRoot = null; + try { + pkgFragmentRoot = element.getJavaProject().findPackageFragmentRoot(resource.getFullPath()); + } catch (JavaModelException e) { + // ignore + } + if (pkgFragmentRoot != null && pkgFragmentRoot.isArchive()) { + if (pkgFragmentRoot.isExternal()) { + pathString = pkgFragmentRoot.getPath().toOSString(); + } else { + pathString = path.toString(); + } + return pathString + "|" + ((Member)element).getTypeRoot().getElementName(); + } + } if (path.segmentCount() == 0) { IJavaElement root = element; while (root != null && !(root instanceof IPackageFragmentRoot)) { Index: src/org/eclipse/jdt/core/tests/model/JavaSearchMultipleProjectsTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchMultipleProjectsTests.java,v retrieving revision 1.52 diff -u -r1.52 JavaSearchMultipleProjectsTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchMultipleProjectsTests.java 27 Jun 2008 16:02:38 -0000 1.52 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchMultipleProjectsTests.java 16 Oct 2008 16:39:25 -0000 @@ -96,7 +96,7 @@ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {p1, p2}); JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); - resultCollector.showProject = true; + resultCollector.showProject(); IField field = wc1.getType("X").getField("BAR"); SearchPattern pattern = SearchPattern.createPattern(field, ALL_OCCURRENCES); new SearchEngine(new ICompilationUnit[] {wc1, wc2}).search( @@ -154,7 +154,7 @@ IMethod method = type.getMethod("foo", new String[] {}); IJavaSearchScope scope = SearchEngine.createHierarchyScope(type); JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); - resultCollector.showProject = true; + resultCollector.showProject(); search( method, REFERENCES, @@ -209,7 +209,7 @@ IMethod method = type.getMethod("foo", new String[] {}); IJavaSearchScope scope = SearchEngine.createHierarchyScope(type); JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); - resultCollector.showProject = true; + resultCollector.showProject(); search( method, REFERENCES, @@ -257,7 +257,7 @@ IMethod method = type.getMethod("foo", new String[] {}); IJavaSearchScope scope = SearchEngine.createHierarchyScope(type); JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); - resultCollector.showProject = true; + resultCollector.showProject(); search( method, REFERENCES, @@ -334,8 +334,8 @@ IMethod method = type.getMethod("foo", new String[] {}); IJavaSearchScope scope = SearchEngine.createHierarchyScope(type); JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); - resultCollector.showAccuracy = true; - resultCollector.showProject = true; + resultCollector.showAccuracy(true); + resultCollector.showProject(); search( method, REFERENCES, @@ -379,7 +379,7 @@ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {p1, p2}); JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); - resultCollector.showProject = true; + resultCollector.showProject(); IMethod method = getCompilationUnit("/P1/p/I.java").getType("I").getMethod("method", new String[] {"QObject;"}); search( method, @@ -418,7 +418,7 @@ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {p1, p2}); JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); - resultCollector.showProject = true; + resultCollector.showProject(); IPackageFragment pkg = getPackage("/P1/p"); search( pkg, @@ -639,7 +639,7 @@ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {p1}); JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); - resultCollector.showProject = true; + resultCollector.showProject(); search( "Object", TYPE, @@ -653,7 +653,7 @@ scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {p2}); resultCollector = new JavaSearchResultCollector(); - resultCollector.showProject = true; + resultCollector.showProject(); search( "Object", TYPE, @@ -712,7 +712,7 @@ // search method declaration in workspace scope IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); //JavaSearchScope(new IJavaElement[] {p1, p2}); JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); - resultCollector.showProject = true; + resultCollector.showProject(); search( method, DECLARATIONS, @@ -725,7 +725,7 @@ // search method declaration in workspace scope with JDT-UI flags resultCollector = new JavaSearchResultCollector(); - resultCollector.showProject = true; + resultCollector.showProject(); search( method, UI_DECLARATIONS, @@ -780,7 +780,7 @@ // search method declaration in project scope IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {p2}); JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); - resultCollector.showProject = true; + resultCollector.showProject(); search( method, UI_DECLARATIONS, @@ -857,8 +857,8 @@ // search method declaration in workspace scope IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); //JavaSearchScope(new IJavaElement[] {p1, p2}); JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); - resultCollector.showProject = true; - resultCollector.showAccuracy = true; + resultCollector.showProject(); + resultCollector.showAccuracy(true); search(method, REFERENCES, scope, resultCollector); assertSearchResults( "Unexpected references of method Test.getType()", @@ -937,8 +937,8 @@ // Create scope and search IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { p1, p2 }, IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.REFERENCED_PROJECTS); JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); - resultCollector.showProject = true; - resultCollector.showAccuracy = true; + resultCollector.showProject(); + resultCollector.showAccuracy(true); new SearchEngine().search( SearchPattern.createPattern("toString", IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH), new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, @@ -965,8 +965,8 @@ // Create scope and search IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { p1, p2, p3 }, IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.REFERENCED_PROJECTS); JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); - resultCollector.showProject = true; - resultCollector.showAccuracy = true; + resultCollector.showProject(); + resultCollector.showAccuracy(true); new SearchEngine().search( SearchPattern.createPattern("toString", IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH), new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, @@ -1258,8 +1258,8 @@ SearchPattern leftPattern = SearchPattern.createPattern(typeA1, REFERENCES); SearchPattern pattern = SearchPattern.createOrPattern(leftPattern, rightPattern); JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); - resultCollector.showProject = true; - resultCollector.showAccuracy = true; + resultCollector.showProject(); + resultCollector.showAccuracy(true); new SearchEngine().search( pattern, new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, @@ -1322,8 +1322,8 @@ // search annotation type reference in P2 scope IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {p2}, false/*don't include referenced projects*/); JavaSearchResultCollector resultCollector = new JavaSearchResultCollector(); - resultCollector.showProject = true; - resultCollector.showAccuracy = true; + resultCollector.showProject(); + resultCollector.showAccuracy(true); search(type, ANNOTATION_TYPE_REFERENCE, scope, resultCollector); assertSearchResults( "Unexpected references of annotation type MyAnnot", Index: src/org/eclipse/jdt/core/tests/model/JavaSearchGenericTypeTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchGenericTypeTests.java,v retrieving revision 1.22 diff -u -r1.22 JavaSearchGenericTypeTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchGenericTypeTests.java 27 Jun 2008 16:02:39 -0000 1.22 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchGenericTypeTests.java 16 Oct 2008 16:39:24 -0000 @@ -47,8 +47,8 @@ protected void setUp () throws Exception { super.setUp(); - this.resultCollector.showAccuracy = true; - this.resultCollector.showRule = true; + this.resultCollector.showAccuracy(true); + this.resultCollector.showRule(); } /* Index: src/org/eclipse/jdt/core/tests/model/JavaSearchJavadocTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchJavadocTests.java,v retrieving revision 1.35 diff -u -r1.35 JavaSearchJavadocTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchJavadocTests.java 27 Jun 2008 16:02:39 -0000 1.35 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchJavadocTests.java 16 Oct 2008 16:39:25 -0000 @@ -43,8 +43,8 @@ super.setUp(); this.originalOptions = JAVA_PROJECT.getOptions(true); JAVA_PROJECT.setOption(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); - this.resultCollector.showAccuracy = true; - this.resultCollector.showInsideDoc = true; + this.resultCollector.showAccuracy(true); + this.resultCollector.showInsideDoc(); } /* (non-Javadoc) * @see org.eclipse.jdt.core.tests.model.SuiteOfTestCases#tearDownSuite() @@ -857,8 +857,8 @@ */ public void testBug54962() throws CoreException { setJavadocOptions(); - this.resultCollector.showInsideDoc = true; - this.resultCollector.showSelection = true; + this.resultCollector.showInsideDoc(); + this.resultCollector.showSelection(); IPackageDeclaration packDecl = getCompilationUnit("JavaSearch", "src", "j6", "Bug54962.java").getPackageDeclaration("j6"); search(packDecl, REFERENCES, getJavaSearchScope()); assertSearchResults( @@ -871,8 +871,8 @@ // TODO (frederic) should no longer get POTENTIAL after 196200 got fixed public void testBug54962qualified() throws CoreException { setJavadocOptions(); - this.resultCollector.showInsideDoc = true; - this.resultCollector.showSelection = true; + this.resultCollector.showInsideDoc(); + this.resultCollector.showSelection(); IPackageDeclaration packDecl = getCompilationUnit("JavaSearch", "src", "j7.qua.li.fied", "Bug54962a.java").getPackageDeclaration("j7.qua.li.fied"); search(packDecl, REFERENCES, getJavaSearchScope()); assertSearchResults( @@ -889,7 +889,7 @@ */ public void testBug71267() throws CoreException { setJavadocOptions(); - this.resultCollector.showInsideDoc = true; + this.resultCollector.showInsideDoc(); IPackageDeclaration packDecl = getCompilationUnit("JavaSearch", "src", "p71267", "Test.java").getPackageDeclaration("p71267"); search(packDecl, REFERENCES, getJavaSearchScope()); assertSearchResults( @@ -900,7 +900,7 @@ } public void testBug71267qualified() throws CoreException { setJavadocOptions(); - this.resultCollector.showInsideDoc = true; + this.resultCollector.showInsideDoc(); IPackageDeclaration packDecl = getCompilationUnit("JavaSearch", "src", "p71267.q71267", "Test.java").getPackageDeclaration("p71267.q71267"); search(packDecl, REFERENCES, getJavaSearchScope()); assertSearchResults( @@ -918,7 +918,7 @@ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=83285" */ public void testBug83285() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy("/JavaSearch/src/b83285/A.java", "package b83285;\n" + @@ -941,7 +941,7 @@ ); } public void testBug83285a() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy("/JavaSearch/src/b83285/A.java", "package b83285;\n" + @@ -974,7 +974,7 @@ ); } public void testBug83285b() throws CoreException { - this.resultCollector.showRule = true; + this.resultCollector.showRule(); this.workingCopies = new ICompilationUnit[1]; this.workingCopies[0] = getWorkingCopy("/JavaSearch/src/b83285/A.java", "package b83285;\n" + #P org.eclipse.jdt.core Index: search/org/eclipse/jdt/internal/core/search/processing/JobManager.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/processing/JobManager.java,v retrieving revision 1.97 diff -u -r1.97 JobManager.java --- search/org/eclipse/jdt/internal/core/search/processing/JobManager.java 12 Sep 2008 13:17:49 -0000 1.97 +++ search/org/eclipse/jdt/internal/core/search/processing/JobManager.java 16 Oct 2008 16:39:30 -0000 @@ -17,10 +17,13 @@ public abstract class JobManager implements Runnable { - /* queue of jobs to execute */ - protected IJob[] awaitingJobs = new IJob[10]; - protected int jobStart = 0; - protected int jobEnd = -1; + /* queues of jobs to execute */ + protected static final int HIGH_PRIORITY = 1; + protected static final int LOW_PRIORITY = 0; + protected static final int MAX_PRIORITY = HIGH_PRIORITY; + protected IJob[][] awaitingJobs = new IJob[MAX_PRIORITY+1][10]; + protected int[] jobStart = new int[MAX_PRIORITY+1]; + protected int[] jobEnd = new int[MAX_PRIORITY+1]; protected boolean executing = false; /* background processing */ @@ -36,6 +39,13 @@ public boolean activated = false; private int awaitingClients = 0; + + public JobManager() { + for (int priorityIndex = 0; priorityIndex <= MAX_PRIORITY; priorityIndex++) { + this.jobStart[priorityIndex] = 0; + this.jobEnd[priorityIndex] = -1; + } + } /** * Invoked exactly once, in background, before starting processing any job @@ -46,17 +56,50 @@ /** * Answer the amount of awaiting jobs. */ - public synchronized int awaitingJobsCount() { - // pretend busy in case concurrent job attempts performing before activated - return this.activated ? this.jobEnd - this.jobStart + 1 : 1; + public int awaitingJobsCount() { + return awaitingJobsCount(HIGH_PRIORITY); + } + + /** + * Answer the amount of awaiting jobs with a given priority (jobs with a lower priority are not considered). + */ + private synchronized int awaitingJobsCount(int maxPriority) { + if (!this.activated) { + // pretend busy in case concurrent job attempts performing before activated + return 1; + } + int count = 0; + for (int priorityIndex = 0; priorityIndex <= MAX_PRIORITY-maxPriority; priorityIndex++) { + count += this.jobEnd[priorityIndex] - this.jobStart[priorityIndex] + 1; + } + return count; + } + /** + * Answers the first job in the queue, or null if there is no job available + * Until the job has completed, the job manager will keep answering the same job. + */ + public IJob currentJob() { + return currentJob(HIGH_PRIORITY); } /** * Answers the first job in the queue, or null if there is no job available * Until the job has completed, the job manager will keep answering the same job. */ - public synchronized IJob currentJob() { - if (this.enableCount > 0 && this.jobStart <= this.jobEnd) - return this.awaitingJobs[this.jobStart]; + private synchronized IJob currentJob(int maxPriority) { + if (this.enableCount <= 0) + return null; + for (int priorityIndex = 0; priorityIndex <= MAX_PRIORITY-maxPriority; priorityIndex++) { + IJob job = currentJobForPriority(priorityIndex); + if (job != null) + return job; + } + return null; + } + + private IJob currentJobForPriority(int prorityIndex) { + int start = this.jobStart[prorityIndex]; + if (start <= this.jobEnd[prorityIndex]) + return this.awaitingJobs[prorityIndex][start]; return null; } public synchronized void disable() { @@ -65,70 +108,77 @@ Util.verbose("DISABLING background indexing"); //$NON-NLS-1$ } /** - * Remove the index from cache for a given project. + * Remove the jobs belonging to the given family. * Passing null as a job family discards them all. */ public void discardJobs(String jobFamily) { - if (VERBOSE) Util.verbose("DISCARD background job family - " + jobFamily); //$NON-NLS-1$ - - try { - IJob currentJob; - // cancel current job if it belongs to the given family - synchronized(this){ - currentJob = currentJob(); - disable(); - } - if (currentJob != null && (jobFamily == null || currentJob.belongsTo(jobFamily))) { - currentJob.cancel(); - - // wait until current active job has finished - while (this.processingThread != null && this.executing){ - try { - if (VERBOSE) - Util.verbose("-> waiting end of current background job - " + currentJob); //$NON-NLS-1$ - Thread.sleep(50); - } catch(InterruptedException e){ - // ignore - } + for (int priorityIndex = 0; priorityIndex <= MAX_PRIORITY; priorityIndex++) { + try { + IJob currentJob; + // cancel current job if it belongs to the given family + synchronized(this){ + currentJob = currentJobForPriority(priorityIndex); + disable(); } - } - - // flush and compact awaiting jobs - int loc = -1; - synchronized(this) { - for (int i = this.jobStart; i <= this.jobEnd; i++) { - currentJob = this.awaitingJobs[i]; - if (currentJob != null) { // sanity check - this.awaitingJobs[i] = null; - if (!(jobFamily == null || currentJob.belongsTo(jobFamily))) { // copy down, compacting - this.awaitingJobs[++loc] = currentJob; - } else { + if (currentJob != null && (jobFamily == null || currentJob.belongsTo(jobFamily))) { + currentJob.cancel(); + + // wait until current active job has finished + while (this.processingThread != null && this.executing){ + try { if (VERBOSE) - Util.verbose("-> discarding background job - " + currentJob); //$NON-NLS-1$ - currentJob.cancel(); + Util.verbose("-> waiting end of current background job - " + currentJob); //$NON-NLS-1$ + Thread.sleep(50); + } catch(InterruptedException e){ + // ignore + } + } + } + + // flush and compact awaiting jobs + int loc = -1; + synchronized(this) { + for (int i = this.jobStart[priorityIndex]; i <= this.jobEnd[priorityIndex]; i++) { + currentJob = this.awaitingJobs[priorityIndex][i]; + if (currentJob != null) { // sanity check + this.awaitingJobs[priorityIndex][i] = null; + if (!(jobFamily == null || currentJob.belongsTo(jobFamily))) { // copy down, compacting + this.awaitingJobs[priorityIndex][++loc] = currentJob; + } else { + if (VERBOSE) + Util.verbose("-> discarding background job - " + currentJob); //$NON-NLS-1$ + currentJob.cancel(); + } } } + this.jobStart[priorityIndex] = 0; + this.jobEnd[priorityIndex] = loc; } - this.jobStart = 0; - this.jobEnd = loc; + } finally { + enable(); } - } finally { - enable(); } if (VERBOSE) Util.verbose("DISCARD DONE with background job family - " + jobFamily); //$NON-NLS-1$ } + public synchronized void enable() { this.enableCount++; if (VERBOSE) Util.verbose("ENABLING background indexing"); //$NON-NLS-1$ notifyAll(); // wake up the background thread if it is waiting (context must be synchronized) } - protected synchronized boolean isJobWaiting(IJob request) { - for (int i = this.jobEnd; i > this.jobStart; i--) // don't check job at jobStart, as it may have already started - if (request.equals(this.awaitingJobs[i])) return true; + protected boolean isJobWaiting(IJob request) { + return isJobWaiting(request, HIGH_PRIORITY); + } + protected synchronized boolean isJobWaiting(IJob request, int maxPriority) { + for (int priorityIndex = 0; priorityIndex <= MAX_PRIORITY-maxPriority; priorityIndex++) { + for (int i = this.jobEnd[priorityIndex]; i > this.jobStart[priorityIndex]; i--) // don't check job at jobStart, as it may have already started + if (request.equals(this.awaitingJobs[priorityIndex][i])) + return true; + } return false; } /** @@ -136,13 +186,14 @@ * Note: clients awaiting until the job count is zero are still waiting at this point. */ protected synchronized void moveToNextJob() { - //if (!enabled) return; - - if (this.jobStart <= this.jobEnd) { - this.awaitingJobs[this.jobStart++] = null; - if (this.jobStart > this.jobEnd) { - this.jobStart = 0; - this.jobEnd = -1; + for (int priorityIndex=0; priorityIndex <= MAX_PRIORITY; priorityIndex++) { + if (this.jobStart[priorityIndex] <= this.jobEnd[priorityIndex]) { + this.awaitingJobs[priorityIndex][this.jobStart[priorityIndex]++] = null; + if (this.jobStart[priorityIndex] > this.jobEnd[priorityIndex]) { + this.jobStart[priorityIndex] = 0; + this.jobEnd[priorityIndex] = -1; + } + return; } } } @@ -157,17 +208,23 @@ * Indeed since other jobs are performed in background, resource sharing might be * an issue.Therefore, this functionality allows a given job to be run without * colliding with background ones. + *

    * Note: multiple thread might attempt to perform concurrent jobs at the same time, * and should synchronize (it is deliberately left to clients to decide whether * concurrent jobs might interfere or not. In general, multiple read jobs are ok). - * + *

    * Waiting policy can be: - * IJobConstants.ForceImmediateSearch - * IJobConstants.CancelIfNotReadyToSearch - * IJobConstants.WaitUntilReadyToSearch - * + *

      + *
    • {@link IJob#ForceImmediate}
    • + *
    • {@link IJob#CancelIfNotReady}
    • + *
    • {@link IJob#WaitUntilReady}
    • + *
    + *

    */ public boolean performConcurrentJob(IJob searchJob, int waitingPolicy, IProgressMonitor progress) { + return performConcurrentJob(searchJob, waitingPolicy, HIGH_PRIORITY, progress); + } + public boolean performConcurrentJob(IJob searchJob, int waitingPolicy, int maxPriority, IProgressMonitor progress) { if (VERBOSE) Util.verbose("STARTING concurrent job - " + searchJob); //$NON-NLS-1$ @@ -178,7 +235,7 @@ int concurrentJobWork = 100; if (progress != null) progress.beginTask("", concurrentJobWork); //$NON-NLS-1$ - if (awaitingJobsCount() > 0) { + if (awaitingJobsCount(maxPriority) > 0) { switch (waitingPolicy) { case IJob.ForceImmediate : @@ -225,10 +282,10 @@ int lastJobsCount = totalWork; float lastWorked = 0; float totalWorked = 0; - while ((awaitingJobsCount = awaitingJobsCount()) > 0) { + while ((awaitingJobsCount = awaitingJobsCount(maxPriority)) > 0) { if (subProgress != null && subProgress.isCanceled()) throw new OperationCanceledException(); - IJob currentJob = currentJob(); + IJob currentJob = currentJob(maxPriority); // currentJob can be null when jobs have been added to the queue but job manager is not enabled if (currentJob != null && currentJob != previousJob) { if (VERBOSE) @@ -285,17 +342,20 @@ public abstract String processName(); public synchronized void request(IJob job) { - + request(job, HIGH_PRIORITY); + } + + public void request(IJob job, int priority) { job.ensureReadyToRun(); - + int priorityIndex = MAX_PRIORITY-priority; // reverse order // append the job to the list of ones to process later on - int size = this.awaitingJobs.length; - if (++this.jobEnd == size) { // when growing, relocate jobs starting at position 0 - this.jobEnd -= this.jobStart; - System.arraycopy(this.awaitingJobs, this.jobStart, this.awaitingJobs = new IJob[size * 2], 0, this.jobEnd); - this.jobStart = 0; + int size = this.awaitingJobs[priorityIndex].length; + if (++this.jobEnd[priorityIndex] == size) { // when growing, relocate jobs starting at position 0 + this.jobEnd[priorityIndex] -= this.jobStart[priorityIndex]; + System.arraycopy(this.awaitingJobs[priorityIndex], this.jobStart[priorityIndex], this.awaitingJobs[priorityIndex] = new IJob[size * 2], 0, this.jobEnd[priorityIndex]); + this.jobStart[priorityIndex] = 0; } - this.awaitingJobs[this.jobEnd] = job; + this.awaitingJobs[priorityIndex][this.jobEnd[priorityIndex]] = job; if (VERBOSE) { Util.verbose("REQUEST background job - " + job); //$NON-NLS-1$ Util.verbose("AWAITING JOBS count: " + awaitingJobsCount()); //$NON-NLS-1$ @@ -457,13 +517,16 @@ // ignore } } - public String toString() { + public synchronized String toString() { StringBuffer buffer = new StringBuffer(10); buffer.append("Enable count:").append(this.enableCount).append('\n'); //$NON-NLS-1$ - int numJobs = this.jobEnd - this.jobStart + 1; - buffer.append("Jobs in queue:").append(numJobs).append('\n'); //$NON-NLS-1$ - for (int i = 0; i < numJobs && i < 15; i++) { - buffer.append(i).append(" - job["+i+"]: ").append(this.awaitingJobs[this.jobStart+i]).append('\n'); //$NON-NLS-1$ //$NON-NLS-2$ + for (int priorityIndex = 0; priorityIndex <= MAX_PRIORITY; priorityIndex++) { + int numJobs = this.jobEnd[priorityIndex] - this.jobStart[priorityIndex] + 1; + buffer.append("Jobs in queue [").append(MAX_PRIORITY-priorityIndex).append("]:").append(numJobs).append('\n'); //$NON-NLS-1$ //$NON-NLS-2$ + for (int i = 0; i < numJobs && i < 15; i++) { + buffer.append(i).append(" - job[").append(i).append("]: ").append(this.awaitingJobs[priorityIndex][this.jobStart[priorityIndex]+i]).append('\n'); //$NON-NLS-1$ //$NON-NLS-2$ + } + } return buffer.toString(); } Index: search/org/eclipse/jdt/internal/core/search/indexing/IndexAllProject.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexAllProject.java,v retrieving revision 1.87 diff -u -r1.87 IndexAllProject.java --- search/org/eclipse/jdt/internal/core/search/indexing/IndexAllProject.java 27 Jun 2008 16:03:49 -0000 1.87 +++ search/org/eclipse/jdt/internal/core/search/indexing/IndexAllProject.java 16 Oct 2008 16:39:29 -0000 @@ -77,7 +77,7 @@ if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && entry.getPath().equals(projectPath)) { // the project is also a library folder (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=89815) // ensure a job exists to index it as a binary folder - this.manager.indexLibrary(projectPath, this.project); + this.manager.indexLibrary(entry, javaProject); return true; } } Index: search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java,v retrieving revision 1.162 diff -u -r1.162 IndexManager.java --- search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java 3 Oct 2008 10:47:56 -0000 1.162 +++ search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java 16 Oct 2008 16:39:29 -0000 @@ -102,6 +102,12 @@ IPath indexLocation = computeIndexLocation(containerPath); scheduleDocumentIndexing(document, containerPath, indexLocation, participant); } +public void addSource(SearchDocument document, IPath containerPath) { + if (JavaCore.getPlugin() == null) return; + SearchParticipant participant = SearchEngine.getDefaultSearchParticipant(); + IPath indexLocation = computeIndexLocation(containerPath); + scheduleDocumentIndexing(document, containerPath, indexLocation, participant); +} /* * Removes unused indexes from disk. */ @@ -380,7 +386,7 @@ for (int i = 0; i < entries.length; i++) { IClasspathEntry entry= entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) - indexLibrary(entry.getPath(), project); + indexLibrary(entry, javaProject); } } catch(JavaModelException e){ // cannot retrieve classpath info } @@ -394,6 +400,52 @@ * Trigger addition of a library to an index * Note: the actual operation is performed in background */ +public void indexLibrary(IClasspathEntry classpathEntry, IJavaProject requestingProject) { + + // Otherwise index it as a jar file + IPath path = classpathEntry.getPath(); + IndexRequest request = indexLibraryRequest(path); + if (request == null) return; + if (request instanceof AddJarFileToIndex) { + AddJarFileToIndex jarFileRequest = (AddJarFileToIndex) request; + jarFileRequest.setJavaProject(requestingProject); + jarFileRequest.setSourceMapper(classpathEntry); + } + if (!isJobWaiting(request)) { + request(request); + } +} +public void indexPackageFragmentRoot(IPackageFragmentRoot fragmentRoot) { + IPath path = fragmentRoot.getPath(); + IndexRequest request = indexLibraryRequest(path); + if (request == null) return; + if (request instanceof AddJarFileToIndex) { + AddJarFileToIndex jarFileRequest = (AddJarFileToIndex) request; + jarFileRequest.setSourceMapper(fragmentRoot); + } + if (!isJobWaiting(request)) { + request(request); + } +} +private IndexRequest indexLibraryRequest(IPath path) { + // requestingProject is no longer used to cancel jobs but leave it here just in case + if (JavaCore.getPlugin() == null) return null; + + Object target = JavaModel.getTarget(path, true); + IndexRequest request = null; + if (target instanceof IFile) { + request = new AddJarFileToIndex((IFile) target, this); + } else if (target instanceof File) { + request = new AddJarFileToIndex(path, this); + } else if (target instanceof IContainer) { + request = new IndexBinaryFolder((IContainer) target, this); + } + return request; +} +/** + * Trigger addition of a library to an index + * Note: the actual operation is performed in background + */ public void indexLibrary(IPath path, IProject requestingProject) { // requestingProject is no longer used to cancel jobs but leave it here just in case if (JavaCore.getPlugin() == null) return; @@ -419,10 +471,11 @@ */ public void indexSourceFolder(JavaProject javaProject, IPath sourceFolder, char[][] inclusionPatterns, char[][] exclusionPatterns) { IProject project = javaProject.getProject(); - if (this.jobEnd > this.jobStart) { + int priorityIndex = MAX_PRIORITY - HIGH_PRIORITY; + if (this.jobEnd[priorityIndex] > this.jobStart[priorityIndex]) { // skip it if a job to index the project is already in the queue IndexRequest request = new IndexAllProject(project, this); - if (isJobWaiting(request)) return; + if (isJobWaiting(request, HIGH_PRIORITY)) return; } request(new AddFolderToIndex(sourceFolder, project, inclusionPatterns, exclusionPatterns, this)); @@ -448,8 +501,12 @@ /** * No more job awaiting. */ -protected void notifyIdle(long idlingTime){ - if (idlingTime > 1000 && this.needToSave) saveIndexes(); +protected void notifyIdle(long idlingTime) { + if (this.needToSave) { +// System.out.println("Flush zip files!"); +// JavaModelManager.getJavaModelManager().flushZipFiles(); + if (idlingTime > 1000) saveIndexes(); + } } /** * Name of the background process @@ -602,10 +659,11 @@ */ public void removeSourceFolderFromIndex(JavaProject javaProject, IPath sourceFolder, char[][] inclusionPatterns, char[][] exclusionPatterns) { IProject project = javaProject.getProject(); - if (this.jobEnd > this.jobStart) { + int priorityIndex = MAX_PRIORITY - HIGH_PRIORITY; + if (this.jobEnd[priorityIndex] > this.jobStart[priorityIndex]) { // skip it if a job to index the project is already in the queue IndexRequest request = new IndexAllProject(project, this); - if (isJobWaiting(request)) return; + if (isJobWaiting(request, HIGH_PRIORITY)) return; } request(new RemoveFolderFromIndex(sourceFolder, inclusionPatterns, exclusionPatterns, project, this)); @@ -631,11 +689,13 @@ } synchronized (this) { IPath containerPath = new Path(index.containerPath); - if (this.jobEnd > this.jobStart) { - for (int i = this.jobEnd; i > this.jobStart; i--) { // skip the current job - IJob job = this.awaitingJobs[i]; - if (job instanceof IndexRequest) - if (((IndexRequest) job).containerPath.equals(containerPath)) return; + for (int priorityIndex = 0; priorityIndex <= MAX_PRIORITY; priorityIndex++) { + if (this.jobEnd[priorityIndex] > this.jobStart[priorityIndex]) { + for (int i = this.jobEnd[priorityIndex]; i > this.jobStart[priorityIndex]; i--) { // skip the current job + IJob job = this.awaitingJobs[priorityIndex][i]; + if (job instanceof IndexRequest) + if (((IndexRequest) job).containerPath.equals(containerPath)) return; + } } } IPath indexLocation = computeIndexLocation(containerPath); @@ -702,6 +762,9 @@ try { monitor.enterWrite(); // ask permission to write + if (((org.eclipse.jdt.internal.core.search.JavaSearchDocument)searchDocument).sourcePath != null) { + System.out.print(' '); + } indexDocument(searchDocument, searchParticipant, index, indexLocation); } finally { monitor.exitWrite(); // free write lock @@ -714,7 +777,7 @@ }); } -public String toString() { +public synchronized String toString() { StringBuffer buffer = new StringBuffer(10); buffer.append(super.toString()); buffer.append("In-memory indexes:\n"); //$NON-NLS-1$ Index: search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java,v retrieving revision 1.68 diff -u -r1.68 BinaryIndexer.java --- search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java 27 Jun 2008 16:03:49 -0000 1.68 +++ search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java 16 Oct 2008 16:39:29 -0000 @@ -27,6 +27,7 @@ import org.eclipse.jdt.internal.compiler.lookup.TagBits; import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; import org.eclipse.jdt.internal.compiler.util.SuffixConstants; +import org.eclipse.jdt.internal.core.search.JavaSearchDocument; import org.eclipse.jdt.internal.core.util.Util; public class BinaryIndexer extends AbstractIndexer implements SuffixConstants { @@ -618,7 +619,21 @@ final byte[] contents = this.document.getByteContents(); // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=107124 // contents can potentially be null if a IOException occurs while retrieving the contents - if (contents == null) return; + if (contents == null) { + // See if there's some source attached + if (this.document instanceof JavaSearchDocument) { + JavaSearchDocument javaSearchDocument = (JavaSearchDocument) this.document; + if (javaSearchDocument.sourcePath != null) { + char[] source = javaSearchDocument.getCharContents(); + if (source.length != 0) { + // the source exists, then prefer to index it instead of the class file + SourceIndexer sourceIndexer = new SourceIndexer(this.document); + sourceIndexer.indexDocument(); + } + } + } + return; + } final String path = this.document.getPath(); ClassFileReader reader = new ClassFileReader(contents, path == null ? null : path.toCharArray()); Index: search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java,v retrieving revision 1.75 diff -u -r1.75 AddJarFileToIndex.java --- search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java 27 Jun 2008 16:03:49 -0000 1.75 +++ search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java 16 Oct 2008 16:39:29 -0000 @@ -10,10 +10,11 @@ *******************************************************************************/ package org.eclipse.jdt.internal.core.search.indexing; -import java.io.File; import java.io.IOException; -import java.net.URI; +import java.util.ArrayList; import java.util.Enumeration; +import java.util.List; +import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -22,171 +23,345 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.search.IJavaSearchScope; import org.eclipse.jdt.core.search.SearchEngine; import org.eclipse.jdt.core.search.SearchParticipant; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; +import org.eclipse.jdt.internal.compiler.util.SuffixConstants; import org.eclipse.jdt.internal.compiler.util.Util; import org.eclipse.jdt.internal.core.JavaModelManager; +import org.eclipse.jdt.internal.core.PackageFragmentRoot; +import org.eclipse.jdt.internal.core.SourceMapper; import org.eclipse.jdt.internal.core.index.Index; import org.eclipse.jdt.internal.core.search.JavaSearchDocument; import org.eclipse.jdt.internal.core.search.processing.JobManager; +import org.eclipse.jdt.internal.core.util.HashtableOfArrayToObject; class AddJarFileToIndex extends IndexRequest { private static final char JAR_SEPARATOR = IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR.charAt(0); IFile resource; + SourceMapper sourceMapper; + IPath sourcePath; + IJavaProject javaProject; + IPackageFragmentRoot packageFragmentRoot; + private HashtableOfArrayToObject packageHandles = new HashtableOfArrayToObject(); + +public AddJarFileToIndex(IFile resource, IndexManager manager) { + super(resource.getFullPath(), manager); + this.resource = resource; +} +public AddJarFileToIndex(IPath jarPath, IndexManager manager) { + // external JAR scenario - no resource + super(jarPath, manager); +} - public AddJarFileToIndex(IFile resource, IndexManager manager) { - super(resource.getFullPath(), manager); - this.resource = resource; - } - public AddJarFileToIndex(IPath jarPath, IndexManager manager) { - // external JAR scenario - no resource - super(jarPath, manager); - } - public boolean equals(Object o) { - if (o instanceof AddJarFileToIndex) { - if (this.resource != null) - return this.resource.equals(((AddJarFileToIndex) o).resource); - if (this.containerPath != null) - return this.containerPath.equals(((AddJarFileToIndex) o).containerPath); +private IType createTypeFromJar(String classFilePath) throws JavaModelException { + String[] simpleNames = new Path(classFilePath).segments(); + String[] pkgName; + int length = simpleNames.length-1; + if (length > 0) { + pkgName = new String[length]; + System.arraycopy(simpleNames, 0, pkgName, 0, length); + } else { + pkgName = CharOperation.NO_STRINGS; + } + IPackageFragment pkgFragment= (IPackageFragment) this.packageHandles.get(pkgName); + if (pkgFragment == null) { + pkgFragment= ((PackageFragmentRoot)this.packageFragmentRoot).getPackageFragment(pkgName); + this.packageHandles.put(pkgName, pkgFragment); + } + return pkgFragment.getClassFile(simpleNames[length]).getType(); +} + +void setJavaProject(IJavaProject javaProject) { + this.javaProject = javaProject; +} + +void setSourceMapper(IClasspathEntry classpathEntry) { + if (this.javaProject != null) { + try { + IPackageFragmentRoot root= this.javaProject.findPackageFragmentRoot(classpathEntry.getPath()); + this.packageFragmentRoot = root; + } + catch (JavaModelException jme) { + // ignore } - return false; } - public int hashCode() { + this.sourcePath = classpathEntry.getSourceAttachmentPath(); + IPath rootPath = classpathEntry.getSourceAttachmentRootPath(); + if (this.packageFragmentRoot != null) { + try { + PackageFragmentRoot root = (PackageFragmentRoot) this.packageFragmentRoot; + if (this.sourcePath == null) { + this.sourcePath = root.sourceAttachmentPath(); + if (this.sourcePath == null) { + this.sourcePath = root.getPath(); + } + } + if (rootPath == null) { + rootPath = root.getSourceAttachmentRootPath(); + } + } catch (Exception e) { + // ignore + } + } + if (this.sourcePath != null) { + Map options = this.javaProject == null + ? JavaCore.getOptions() + : this.javaProject.getOptions(true); + this.sourceMapper = new SourceMapper( + this.sourcePath , + rootPath == null ? null : rootPath.toOSString(), + options); + } +} + +void setSourceMapper(IPackageFragmentRoot fragmentRoot) { + this.packageFragmentRoot = fragmentRoot; + if (this.javaProject == null) { + this.javaProject = fragmentRoot.getJavaProject(); + } + try { + this.sourcePath = ((PackageFragmentRoot)fragmentRoot).sourceAttachmentPath(); + if (this.sourcePath == null) { + this.sourcePath = fragmentRoot.getPath(); + } + IPath rootPath = ((PackageFragmentRoot)fragmentRoot).sourceAttachmentRootPath(); + this.sourceMapper = new SourceMapper( + this.sourcePath, + rootPath == null ? null : rootPath.toOSString(), + this.javaProject.getOptions(true)); + } catch (JavaModelException e) { + // skip + } +} + +public boolean equals(Object o) { + if (o instanceof AddJarFileToIndex) { if (this.resource != null) - return this.resource.hashCode(); + return this.resource.equals(((AddJarFileToIndex) o).resource); if (this.containerPath != null) - return this.containerPath.hashCode(); - return -1; + return this.containerPath.equals(((AddJarFileToIndex) o).containerPath); } - public boolean execute(IProgressMonitor progressMonitor) { + return false; +} +public int hashCode() { + if (this.resource != null) + return this.resource.hashCode(); + if (this.containerPath != null) + return this.containerPath.hashCode(); + return -1; +} +public boolean execute(IProgressMonitor progressMonitor) { - if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true; + if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true; - try { - // if index is already cached, then do not perform any check - // MUST reset the IndexManager if a jar file is changed - Index index = this.manager.getIndexForUpdate(this.containerPath, false, /*do not reuse index file*/ false /*do not create if none*/); - if (index != null) { - if (JobManager.VERBOSE) - org.eclipse.jdt.internal.core.util.Util.verbose("-> no indexing required (index already exists) for " + this.containerPath); //$NON-NLS-1$ - return true; - } + try { + // if index is already cached, then do not perform any check + // MUST reset the IndexManager if a jar file is changed + Index index = this.manager.getIndexForUpdate(this.containerPath, false, /*do not reuse index file*/ false /*do not create if none*/); + if (index != null) { + if (JobManager.VERBOSE) + org.eclipse.jdt.internal.core.util.Util.verbose("-> no indexing required (index already exists) for " + this.containerPath); //$NON-NLS-1$ + return true; + } - index = this.manager.getIndexForUpdate(this.containerPath, true, /*reuse index file*/ true /*create if none*/); - if (index == null) { - if (JobManager.VERBOSE) - org.eclipse.jdt.internal.core.util.Util.verbose("-> index could not be created for " + this.containerPath); //$NON-NLS-1$ - return true; - } - ReadWriteMonitor monitor = index.monitor; - if (monitor == null) { - if (JobManager.VERBOSE) - org.eclipse.jdt.internal.core.util.Util.verbose("-> index for " + this.containerPath + " just got deleted"); //$NON-NLS-1$//$NON-NLS-2$ - return true; // index got deleted since acquired - } - index.separator = JAR_SEPARATOR; - ZipFile zip = null; - try { - // this path will be a relative path to the workspace in case the zipfile in the workspace otherwise it will be a path in the - // local file system - Path zipFilePath = null; - - monitor.enterWrite(); // ask permission to write - if (this.resource != null) { - URI location = this.resource.getLocationURI(); - if (location == null) return false; - if (JavaModelManager.ZIP_ACCESS_VERBOSE) - System.out.println("(" + Thread.currentThread() + ") [AddJarFileToIndex.execute()] Creating ZipFile on " + location.getPath()); //$NON-NLS-1$ //$NON-NLS-2$ - File file = null; - try { - file = org.eclipse.jdt.internal.core.util.Util.toLocalFile(location, progressMonitor); - } catch (CoreException e) { - if (JobManager.VERBOSE) { - org.eclipse.jdt.internal.core.util.Util.verbose("-> failed to index " + location.getPath() + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$ - e.printStackTrace(); - } + index = this.manager.getIndexForUpdate(this.containerPath, true, /*reuse index file*/ true /*create if none*/); + if (index == null) { + if (JobManager.VERBOSE) + org.eclipse.jdt.internal.core.util.Util.verbose("-> index could not be created for " + this.containerPath); //$NON-NLS-1$ + return true; + } + ReadWriteMonitor monitor = index.monitor; + if (monitor == null) { + if (JobManager.VERBOSE) + org.eclipse.jdt.internal.core.util.Util.verbose("-> index for " + this.containerPath + " just got deleted"); //$NON-NLS-1$//$NON-NLS-2$ + return true; // index got deleted since acquired + } + index.separator = JAR_SEPARATOR; + ZipFile zip = null; + ZipFile sourceZip = null; + JavaModelManager modelManager = JavaModelManager.getJavaModelManager(); + modelManager.cacheZipFiles(); +// System.out.println("Current thread name while adding jar file '"+this.containerPath+"' to index: "+Thread.currentThread().getName()); + try { + // this path will be a relative path to the workspace in case the zipfile in the workspace otherwise it will be a path in the + // local file system + Path zipFilePath = null; + + monitor.enterWrite(); // ask permission to write + if (this.resource != null) { + IPath resourcePath = this.resource.getFullPath(); + if (JavaModelManager.ZIP_ACCESS_VERBOSE) + System.out.println("(" + Thread.currentThread() + ") [AddJarFileToIndex.execute()] Creating ZipFile on " + resourcePath); //$NON-NLS-1$ //$NON-NLS-2$ + /* + URI location = this.resource.getLocationURI(); + if (location == null) return false; + if (JavaModelManager.ZIP_ACCESS_VERBOSE) + System.out.println("(" + Thread.currentThread() + ") [AddJarFileToIndex.execute()] Creating ZipFile on " + location.getPath()); //$NON-NLS-1$ //$NON-NLS-2$ + File file = null; + try { + file = org.eclipse.jdt.internal.core.util.Util.toLocalFile(location, progressMonitor); + } catch (CoreException e) { + if (JobManager.VERBOSE) { + org.eclipse.jdt.internal.core.util.Util.verbose("-> failed to index " + location.getPath() + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$ + e.printStackTrace(); } - if (file == null) { - if (JobManager.VERBOSE) - org.eclipse.jdt.internal.core.util.Util.verbose("-> failed to index " + location.getPath() + " because the file could not be fetched"); //$NON-NLS-1$ //$NON-NLS-2$ - return false; + } + if (file == null) { + if (JobManager.VERBOSE) + org.eclipse.jdt.internal.core.util.Util.verbose("-> failed to index " + location.getPath() + " because the file could not be fetched"); //$NON-NLS-1$ //$NON-NLS-2$ + return false; + } + zip = new ZipFile(file); + */ + try { + zip = modelManager.getZipFile(resourcePath); + } catch (CoreException ce) { + if (JobManager.VERBOSE) { + org.eclipse.jdt.internal.core.util.Util.verbose("-> failed to index " + resourcePath + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$ + ce.printStackTrace(); } - zip = new ZipFile(file); - zipFilePath = (Path) this.resource.getFullPath().makeRelative(); - // absolute path relative to the workspace - } else { - if (JavaModelManager.ZIP_ACCESS_VERBOSE) - System.out.println("(" + Thread.currentThread() + ") [AddJarFileToIndex.execute()] Creating ZipFile on " + this.containerPath); //$NON-NLS-1$ //$NON-NLS-2$ - // external file -> it is ok to use toFile() - zip = new ZipFile(this.containerPath.toFile()); - zipFilePath = (Path) this.containerPath; - // path is already canonical since coming from a library classpath entry + return false; } + zipFilePath = (Path) resourcePath.makeRelative(); + // absolute path relative to the workspace - if (this.isCancelled) { - if (JobManager.VERBOSE) - org.eclipse.jdt.internal.core.util.Util.verbose("-> indexing of " + zip.getName() + " has been cancelled"); //$NON-NLS-1$ //$NON-NLS-2$ + // Get package fragment root if not already stored + if (this.packageFragmentRoot == null) { + IJavaElement javaElement = JavaCore.create(this.resource, this.javaProject); + if (javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT) { + this.packageFragmentRoot = (IPackageFragmentRoot) javaElement; + } + } + } else { + if (JavaModelManager.ZIP_ACCESS_VERBOSE) + System.out.println("(" + Thread.currentThread() + ") [AddJarFileToIndex.execute()] Creating ZipFile on " + this.containerPath); //$NON-NLS-1$ //$NON-NLS-2$ + // external file -> it is ok to use toFile() +// zip = new ZipFile(this.containerPath.toFile()); + try { + zip = modelManager.getZipFile(this.containerPath); + } catch (CoreException ce) { + if (JobManager.VERBOSE) { + org.eclipse.jdt.internal.core.util.Util.verbose("-> failed to index " + this.containerPath + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$ + ce.printStackTrace(); + } return false; } + zipFilePath = (Path) this.containerPath; + // path is already canonical since coming from a library classpath entry + } + if (this.isCancelled) { if (JobManager.VERBOSE) - org.eclipse.jdt.internal.core.util.Util.verbose("-> indexing " + zip.getName()); //$NON-NLS-1$ - long initialTime = System.currentTimeMillis(); + org.eclipse.jdt.internal.core.util.Util.verbose("-> indexing of " + zip.getName() + " has been cancelled"); //$NON-NLS-1$ //$NON-NLS-2$ + return false; + } - String[] paths = index.queryDocumentNames(""); // all file names //$NON-NLS-1$ - if (paths != null) { - int max = paths.length; - /* check integrity of the existing index file - * if the length is equal to 0, we want to index the whole jar again - * If not, then we want to check that there is no missing entry, if - * one entry is missing then we recreate the index - */ - String EXISTS = "OK"; //$NON-NLS-1$ - String DELETED = "DELETED"; //$NON-NLS-1$ - SimpleLookupTable indexedFileNames = new SimpleLookupTable(max == 0 ? 33 : max + 11); - for (int i = 0; i < max; i++) - indexedFileNames.put(paths[i], DELETED); - for (Enumeration e = zip.entries(); e.hasMoreElements();) { - // iterate each entry to index it - ZipEntry ze = (ZipEntry) e.nextElement(); - String zipEntryName = ze.getName(); - if (Util.isClassFileName(zipEntryName)) - indexedFileNames.put(zipEntryName, EXISTS); + if (JobManager.VERBOSE) + org.eclipse.jdt.internal.core.util.Util.verbose("-> indexing " + zip.getName()); //$NON-NLS-1$ + long initialTime = System.currentTimeMillis(); + + String[] paths = index.queryDocumentNames(""); // all file names //$NON-NLS-1$ + if (paths != null) { + int max = paths.length; + /* check integrity of the existing index file + * if the length is equal to 0, we want to index the whole jar again + * If not, then we want to check that there is no missing entry, if + * one entry is missing then we recreate the index + */ + String EXISTS = "OK"; //$NON-NLS-1$ + String DELETED = "DELETED"; //$NON-NLS-1$ + SimpleLookupTable indexedFileNames = new SimpleLookupTable(max == 0 ? 33 : max + 11); + for (int i = 0; i < max; i++) + indexedFileNames.put(paths[i], DELETED); + for (Enumeration e = zip.entries(); e.hasMoreElements();) { + // iterate each entry to index it + ZipEntry ze = (ZipEntry) e.nextElement(); + String zipEntryName = ze.getName(); + if (Util.isClassFileName(zipEntryName)) + indexedFileNames.put(zipEntryName, EXISTS); + } + boolean needToReindex = indexedFileNames.elementSize != max; // a new file was added + if (!needToReindex) { + Object[] valueTable = indexedFileNames.valueTable; + for (int i = 0, l = valueTable.length; i < l; i++) { + if (valueTable[i] == DELETED) { + needToReindex = true; // a file was deleted so re-index + break; + } } - boolean needToReindex = indexedFileNames.elementSize != max; // a new file was added if (!needToReindex) { - Object[] valueTable = indexedFileNames.valueTable; - for (int i = 0, l = valueTable.length; i < l; i++) { - if (valueTable[i] == DELETED) { - needToReindex = true; // a file was deleted so re-index - break; - } - } - if (!needToReindex) { - if (JobManager.VERBOSE) - org.eclipse.jdt.internal.core.util.Util.verbose("-> no indexing required (index is consistent with library) for " //$NON-NLS-1$ - + zip.getName() + " (" //$NON-NLS-1$ - + (System.currentTimeMillis() - initialTime) + "ms)"); //$NON-NLS-1$ - this.manager.saveIndex(index); // to ensure its placed into the saved state - return true; - } + if (JobManager.VERBOSE) + org.eclipse.jdt.internal.core.util.Util.verbose("-> no indexing required (index is consistent with library) for " //$NON-NLS-1$ + + zip.getName() + " (" //$NON-NLS-1$ + + (System.currentTimeMillis() - initialTime) + "ms)"); //$NON-NLS-1$ + this.manager.saveIndex(index); // to ensure its placed into the saved state + return true; } } + } - // Index the jar for the first time or reindex the jar in case the previous index file has been corrupted - // index already existed: recreate it so that we forget about previous entries - SearchParticipant participant = SearchEngine.getDefaultSearchParticipant(); - index = this.manager.recreateIndex(this.containerPath); - if (index == null) { - // failed to recreate index, see 73330 - this.manager.removeIndex(this.containerPath); - return false; - } - index.separator = JAR_SEPARATOR; + // Index the jar for the first time or reindex the jar in case the previous index file has been corrupted + // index already existed: recreate it so that we forget about previous entries + SearchParticipant participant = SearchEngine.getDefaultSearchParticipant(); + index = this.manager.recreateIndex(this.containerPath); + if (index == null) { + // failed to recreate index, see 73330 + this.manager.removeIndex(this.containerPath); + return false; + } + index.separator = JAR_SEPARATOR; + // Get source zip file if available + if (this.sourcePath != null) { + index.sourcePath = this.sourcePath.toString(); + try { + sourceZip = modelManager.getZipFile(this.sourcePath); + } catch (CoreException ce) { + // ignore + } + } + + // Read zip entries + if (zip == sourceZip) { + + // if sources are in the jar itself index both class and source entries in sequence + for (Enumeration e = zip.entries(); e.hasMoreElements();) { + if (this.isCancelled) { + if (JobManager.VERBOSE) + org.eclipse.jdt.internal.core.util.Util.verbose("-> indexing of " + zip.getName() + " has been cancelled"); //$NON-NLS-1$ //$NON-NLS-2$ + return false; + } + ZipEntry ze = (ZipEntry) e.nextElement(); + String zeName = ze.getName(); + if (Util.isClassFileName(zeName)) { + final byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip); + JavaSearchDocument searchDocument = new JavaSearchDocument(ze, zipFilePath, classFileBytes, participant); + this.manager.indexDocument(searchDocument, participant, index, this.containerPath); + } + else if (Util.isJavaFileName(zeName)) { + String documentPath = zipFilePath.toString() + IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR + zeName.substring(0, zeName.length()-SuffixConstants.SUFFIX_java.length) + SuffixConstants.SUFFIX_STRING_class; + JavaSearchDocument searchDocument = new JavaSearchDocument(documentPath, sourceZip, ze, this.sourcePath, participant); + this.manager.indexDocument(searchDocument, participant, index, this.containerPath); + } + } + } else { + // common case where there's no sources or they are in another location + List sourceFiles = new ArrayList(); + List sourceDocuments = new ArrayList(); for (Enumeration e = zip.entries(); e.hasMoreElements();) { if (this.isCancelled) { if (JobManager.VERBOSE) @@ -194,46 +369,113 @@ return false; } - // iterate each entry to index it + // only pay attention to the class file entries ZipEntry ze = (ZipEntry) e.nextElement(); - if (Util.isClassFileName(ze.getName())) { + String zeName = ze.getName(); + if (Util.isClassFileName(zeName)) { + + // read class file contents final byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip); - JavaSearchDocument entryDocument = new JavaSearchDocument(ze, zipFilePath, classFileBytes, participant); - this.manager.indexDocument(entryDocument, participant, index, this.containerPath); + String documentPath = zipFilePath + IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR + ze; + ClassFileReader classFileReader; + try { + classFileReader = new ClassFileReader(classFileBytes, documentPath.toCharArray()); + } catch (ClassFormatException e1) { + // invalid class file + continue; + } + + // index the class file + JavaSearchDocument searchDocument = new JavaSearchDocument(ze, zipFilePath, classFileBytes, participant); + this.manager.indexDocument(searchDocument, participant, index, this.containerPath); + + // try to get source + if (this.sourcePath != null) { + char[] sourceFileName = classFileReader.sourceFileName(); + if (sourceFileName != null) { + String sourceName = new String(sourceFileName); + if (!sourceFiles.contains(sourceName)) { + IType type = null; + try { + if (this.packageFragmentRoot != null) { + type = createTypeFromJar(zeName); + } + } catch (JavaModelException jme) { + // ignore + } + if (type != null) { + Object mappedSource = this.sourceMapper.findSourceFile(type, sourceName); + if (mappedSource != null) { + // a mapped source has been found create the java search document + // but do NOT index it now otherwise index entries could be overwritten + // in case of member classes + String typeName = type.getElementName(); + if (classFileReader.getEnclosingTypeName() != null) { + IType enclosingType = type.getDeclaringType(); + while (enclosingType != null) { + type = enclosingType; + enclosingType = type.getDeclaringType(); + } + typeName = type.getElementName(); + } + documentPath = zipFilePath.toString() + IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR + typeName + SuffixConstants.SUFFIX_STRING_class; + JavaSearchDocument document; + if (mappedSource instanceof IFile) { + document = new JavaSearchDocument(documentPath, (IFile)mappedSource, this.sourcePath, participant); + } else { + document = new JavaSearchDocument(documentPath, sourceZip, (ZipEntry) mappedSource, this.sourcePath, participant); + } + sourceDocuments.add(document); + sourceFiles.add(sourceName); + } + } + } + } + } } } - this.manager.saveIndex(index); - if (JobManager.VERBOSE) - org.eclipse.jdt.internal.core.util.Util.verbose("-> done indexing of " //$NON-NLS-1$ - + zip.getName() + " (" //$NON-NLS-1$ - + (System.currentTimeMillis() - initialTime) + "ms)"); //$NON-NLS-1$ - } finally { - if (zip != null) { - if (JavaModelManager.ZIP_ACCESS_VERBOSE) - System.out.println("(" + Thread.currentThread() + ") [AddJarFileToIndex.execute()] Closing ZipFile " + zip); //$NON-NLS-1$ //$NON-NLS-2$ - zip.close(); - } - monitor.exitWrite(); // free write lock - } - } catch (IOException e) { - if (JobManager.VERBOSE) { - org.eclipse.jdt.internal.core.util.Util.verbose("-> failed to index " + this.containerPath + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$ - e.printStackTrace(); + + // index source files if any (must be done after the indexing of class files + // as all document entries will be removed prior from the index...) + int size = sourceDocuments.size(); + for (int i=0; i done indexing of " //$NON-NLS-1$ + + zip.getName() + " (" //$NON-NLS-1$ + + (System.currentTimeMillis() - initialTime) + "ms)"); //$NON-NLS-1$ + } finally { + modelManager.flushZipFiles(); +// if (zip != null) { +// if (JavaModelManager.ZIP_ACCESS_VERBOSE) +// System.out.println("(" + Thread.currentThread() + ") [AddJarFileToIndex.execute()] Closing ZipFile " + zip); //$NON-NLS-1$ //$NON-NLS-2$ +// zip.close(); +// } + monitor.exitWrite(); // free write lock } - return true; - } - public String getJobFamily() { - if (this.resource != null) - return super.getJobFamily(); - return this.containerPath.toOSString(); // external jar - } - protected Integer updatedIndexState() { - return IndexManager.REBUILDING_STATE; - } - public String toString() { - return "indexing " + this.containerPath.toString(); //$NON-NLS-1$ + } catch (IOException e) { + if (JobManager.VERBOSE) { + org.eclipse.jdt.internal.core.util.Util.verbose("-> failed to index " + this.containerPath + " because of the following exception:"); //$NON-NLS-1$ //$NON-NLS-2$ + e.printStackTrace(); + } + this.manager.removeIndex(this.containerPath); + return false; } + return true; +} +public String getJobFamily() { + if (this.resource != null) + return super.getJobFamily(); + return this.containerPath.toOSString(); // external jar +} +protected Integer updatedIndexState() { + return IndexManager.REBUILDING_STATE; +} +public String toString() { + return "indexing " + this.containerPath.toString(); //$NON-NLS-1$ +} } Index: search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java,v retrieving revision 1.12 diff -u -r1.12 TypeNameMatchRequestorWrapper.java --- search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java 27 Jun 2008 16:04:09 -0000 1.12 +++ search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java 16 Oct 2008 16:39:28 -0000 @@ -105,7 +105,7 @@ int separatorIndex= path.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR); type = separatorIndex == -1 ? createTypeFromPath(path, new String(simpleTypeName), enclosingTypeNames) - : createTypeFromJar(path, separatorIndex); + : createTypeFromJar(path, separatorIndex, new String(simpleTypeName), enclosingTypeNames); // need to provide simpleTypeName and enclosing type names when the type has been found in attached source! } if (type != null) { this.requestor.acceptTypeNameMatch(new JavaSearchTypeNameMatch(type, modifiers)); @@ -114,7 +114,7 @@ // skip } } -private IType createTypeFromJar(String resourcePath, int separatorIndex) throws JavaModelException { +private IType createTypeFromJar(String resourcePath, int separatorIndex, String simpleTypeName, char[][] enclosingTypeNames) throws JavaModelException { // path to a class file inside a jar // Optimization: cache package fragment root handle and package handles if (this.lastPkgFragmentRootPath == null @@ -143,7 +143,20 @@ pkgFragment= ((PackageFragmentRoot) this.lastPkgFragmentRoot).getPackageFragment(pkgName); this.packageHandles.put(pkgName, pkgFragment); } - return pkgFragment.getClassFile(simpleNames[length]).getType(); + String simpleName= simpleNames[length]; + IClassFile classFile= pkgFragment.getClassFile(simpleName); + IType type = classFile.getType(); + int etnLength = enclosingTypeNames == null ? 0 : enclosingTypeNames.length; + if (etnLength > 0) { + if (etnLength > 0) { + for (int i=1; inull if source + * code cannot be found. + */ + public Object findSourceFile(IType type, IBinaryType info) { + if (!type.isBinary()) { + return null; + } + String simpleSourceFileName = ((BinaryType) type).getSourceFileName(info); + if (simpleSourceFileName == null) { + return null; + } + return findSourceFile(type, simpleSourceFileName); + } + + /** + * Locates and returns source code for the given (binary) type, in this + * SourceMapper's ZIP file, or returns null if source + * code cannot be found. + * The given simpleSourceFileName is the .java file name (without the enclosing + * folder) used to create the given type (e.g. "A.java" for x/y/A$Inner.class) + */ + public Object findSourceFile(IType type, String simpleSourceFileName) { + long time = 0; + if (VERBOSE) { + time = System.currentTimeMillis(); + } + PackageFragment pkgFrag = (PackageFragment) type.getPackageFragment(); + String name = org.eclipse.jdt.internal.core.util.Util.concatWith(pkgFrag.names, simpleSourceFileName, '/'); + + Object sourceFile = null; + + if (this.rootPath != null) { + sourceFile = getSourceFileForRootPath(this.rootPath, name); + } + + if (sourceFile == null) { + computeAllRootPaths(type); + if (this.rootPaths != null) { + loop: for (Iterator iterator = this.rootPaths.iterator(); iterator.hasNext(); ) { + String currentRootPath = (String) iterator.next(); + if (!currentRootPath.equals(this.rootPath)) { + sourceFile = getSourceFileForRootPath(currentRootPath, name); + if (sourceFile != null) { + // remember right root path + this.rootPath = currentRootPath; + break loop; + } + } + } + } + } + if (VERBOSE) { + System.out.println("spent " + (System.currentTimeMillis() - time) + "ms for " + type.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$ + } + return sourceFile; + } + + private Object getSourceFileForRootPath(String currentRootPath, String name) { + String newFullName; + if (!currentRootPath.equals(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH)) { + if (currentRootPath.endsWith("/")) { //$NON-NLS-1$ + newFullName = currentRootPath + name; + } else { + newFullName = currentRootPath + '/' + name; + } + } else { + newFullName = name; + } + return getSourceFile(newFullName); + } + + private Object getSourceFile(String fullName) { + Object target = JavaModel.getTarget(this.sourcePath, true); + if (target instanceof IContainer) { + IResource res = ((IContainer)target).findMember(fullName); + if (res instanceof IFile) { + return res; + } + } else { + // try to get the entry + ZipEntry entry = null; + ZipFile zip = null; + JavaModelManager manager = JavaModelManager.getJavaModelManager(); + try { + zip = manager.getZipFile(this.sourcePath); + entry = zip.getEntry(fullName); + if (entry != null) { + return entry; + } + } catch (CoreException e) { + return null; + } finally { + manager.closeZipFile(zip); // handle null case + } + } + return null; + } + + public ZipFile getSourceZipFile() { + JavaModelManager manager = JavaModelManager.getJavaModelManager(); + try { + return manager.getZipFile(this.sourcePath); + } catch (CoreException e) { + // ignore + } + return null; + } + } Index: model/org/eclipse/jdt/internal/core/ClasspathChange.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathChange.java,v retrieving revision 1.22 diff -u -r1.22 ClasspathChange.java --- model/org/eclipse/jdt/internal/core/ClasspathChange.java 9 Oct 2008 08:13:07 -0000 1.22 +++ model/org/eclipse/jdt/internal/core/ClasspathChange.java 16 Oct 2008 16:39:28 -0000 @@ -457,6 +457,8 @@ int newLength = newResolvedClasspath.length; int oldLength = this.oldResolvedClasspath.length; + + // First, look at removed classpath entries for (int i = 0; i < oldLength; i++) { int index = classpathContains(newResolvedClasspath, this.oldResolvedClasspath[i]); if (index == -1) { @@ -487,20 +489,22 @@ } } + // Then, look at created or changed classpath entries for (int i = 0; i < newLength; i++) { - int index = classpathContains(this.oldResolvedClasspath, newResolvedClasspath[i]); + IClasspathEntry entry = newResolvedClasspath[i]; + int index = classpathContains(this.oldResolvedClasspath, entry); if (index == -1) { // remote projects are not indexed in this project - if (newResolvedClasspath[i].getEntryKind() == IClasspathEntry.CPE_PROJECT){ + if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT){ continue; } - // Request indexing - int entryKind = newResolvedClasspath[i].getEntryKind(); + // Request indexing for the removed classpath entry + int entryKind = entry.getEntryKind(); switch (entryKind) { case IClasspathEntry.CPE_LIBRARY: boolean pathHasChanged = true; - IPath newPath = newResolvedClasspath[i].getPath(); + IPath newPath = entry.getPath(); for (int j = 0; j < oldLength; j++) { IClasspathEntry oldEntry = this.oldResolvedClasspath[j]; if (oldEntry.getPath().equals(newPath)) { @@ -509,11 +513,10 @@ } } if (pathHasChanged) { - indexManager.indexLibrary(newPath, this.project.getProject()); + indexManager.indexLibrary(entry, this.project); } break; case IClasspathEntry.CPE_SOURCE: - IClasspathEntry entry = newResolvedClasspath[i]; IPath path = entry.getPath(); char[][] inclusionPatterns = ((ClasspathEntry)entry).fullInclusionPatternChars(); char[][] exclusionPatterns = ((ClasspathEntry)entry).fullExclusionPatternChars(); @@ -521,6 +524,17 @@ break; } } + // since bug 12044, source attached are indexed instead of class files + // hence needs to verify whether the source attachment has changed + else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { + IPath srcPath = entry.getSourceAttachmentPath(); + IPath oldSrcPath = this.oldResolvedClasspath[index].getSourceAttachmentPath(); + if (srcPath == null && oldSrcPath != null) { + indexManager.removeIndex(entry.getPath()); + } else if (srcPath != null && !srcPath.equals(oldSrcPath)) { + indexManager.indexLibrary(entry, this.project); + } + } } } Index: model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java,v retrieving revision 1.133 diff -u -r1.133 PackageFragmentRoot.java --- model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java 27 Jun 2008 16:03:50 -0000 1.133 +++ model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java 16 Oct 2008 16:39:28 -0000 @@ -573,7 +573,16 @@ */ public IPath getSourceAttachmentPath() throws JavaModelException { if (getKind() != K_BINARY) return null; + return sourceAttachmentPath(); +} +/** + * @see IPackageFragmentRoot#getSourceAttachmentRootPath() + * Returns the same result but without opening the package fragment root. + * However, no verification is done on the package fragment root kind, hence + * provides an unpredictable result if it is not a {@link IPackageFragmentRoot#K_BINARY}. + */ +public IPath sourceAttachmentPath() throws JavaModelException { // 1) look source attachment property (set iff attachSource(...) was called IPath path = getPath(); String serverPathString= Util.getSourceAttachmentProperty(path); @@ -618,7 +627,16 @@ */ public IPath getSourceAttachmentRootPath() throws JavaModelException { if (getKind() != K_BINARY) return null; + return sourceAttachmentRootPath(); +} +/** + * @see IPackageFragmentRoot#getSourceAttachmentRootPath() + * Returns the same result but without opening the package fragment root. + * However, no verification is done on the package fragment root kind, hence + * provides an unpredictable result if it is not a {@link IPackageFragmentRoot#K_BINARY}. + */ +public IPath sourceAttachmentRootPath() throws JavaModelException { // 1) look source attachment property (set iff attachSource(...) was called IPath path = getPath(); String serverPathString= Util.getSourceAttachmentProperty(path); Index: search/org/eclipse/jdt/internal/core/index/Index.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/Index.java,v retrieving revision 1.31 diff -u -r1.31 Index.java --- search/org/eclipse/jdt/internal/core/index/Index.java 27 Jun 2008 16:04:14 -0000 1.31 +++ search/org/eclipse/jdt/internal/core/index/Index.java 16 Oct 2008 16:39:28 -0000 @@ -29,6 +29,7 @@ public class Index { public String containerPath; +public String sourcePath; public ReadWriteMonitor monitor; // Separator to use after the container path @@ -102,6 +103,9 @@ public String containerRelativePath(String documentPath) { int index = documentPath.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR); if (index == -1) { + if (this.sourcePath != null) { + return documentPath; + } index = this.containerPath.length(); if (documentPath.length() <= index) throw new IllegalArgumentException("Document path " + documentPath + " must be relative to " + this.containerPath); //$NON-NLS-1$ //$NON-NLS-2$ Index: search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java,v retrieving revision 1.319 diff -u -r1.319 MatchLocator.java --- search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 18 Sep 2008 15:24:57 -0000 1.319 +++ search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 16 Oct 2008 16:39:29 -0000 @@ -2470,7 +2470,12 @@ } else if (enclosingElement instanceof IMember) { IMember member = (IMember) parent; if (member.isBinary()) { - enclosingElement = ((IClassFile)this.currentPossibleMatch.openable).getType(); + IType topLevelType = ((IClassFile)this.currentPossibleMatch.openable).getType(); + if (type.name.equals(topLevelType.getElementName())) { + enclosingElement = topLevelType; + } else { + enclosingElement = topLevelType.getType(new String(type.name)); + } } else { enclosingElement = member.getType(new String(type.name), occurrenceCount); } #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/Requestor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Requestor.java,v retrieving revision 1.21 diff -u -r1.21 Requestor.java --- src/org/eclipse/jdt/core/tests/compiler/regression/Requestor.java 27 Jun 2008 16:04:44 -0000 1.21 +++ src/org/eclipse/jdt/core/tests/compiler/regression/Requestor.java 16 Oct 2008 16:39:32 -0000 @@ -20,6 +20,7 @@ import org.eclipse.jdt.internal.compiler.ClassFile; import org.eclipse.jdt.internal.compiler.CompilationResult; import org.eclipse.jdt.internal.compiler.ICompilerRequestor; +import org.eclipse.jdt.internal.compiler.util.SuffixConstants; public class Requestor extends Assert implements ICompilerRequestor { public boolean hasErrors = false; @@ -30,6 +31,7 @@ public ICompilerRequestor clientRequestor; public boolean showCategory = false; public boolean showWarningToken = false; + public boolean writeSource = false; public Requestor(boolean forceOutputGeneration, ICompilerRequestor clientRequestor, boolean showCategory, boolean showWarningToken) { this.forceOutputGeneration = forceOutputGeneration; @@ -52,10 +54,12 @@ for (int i = 0, fileCount = classFiles.length; i < fileCount; i++) { // retrieve the key and the corresponding classfile ClassFile classFile = classFiles[i]; - String relativeName = - new String(classFile.fileName()).replace('/', File.separatorChar) + ".class"; + String relativeName = new String(classFile.fileName()).replace('/', File.separatorChar); try { - org.eclipse.jdt.internal.compiler.util.Util.writeToDisk(true, this.outputPath, relativeName, classFile); + org.eclipse.jdt.internal.compiler.util.Util.writeToDisk(true, this.outputPath, relativeName+SuffixConstants.SUFFIX_STRING_class, classFile); + if (this.writeSource && !classFile.isNestedType) { + Util.writeToFile(unitResult.compilationUnit.getContents(), this.outputPath+File.separator+relativeName+SuffixConstants.SUFFIX_STRING_java); + } } catch(IOException e) { e.printStackTrace(); } Index: src/org/eclipse/jdt/core/tests/util/Util.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java,v retrieving revision 1.72 diff -u -r1.72 Util.java --- src/org/eclipse/jdt/core/tests/util/Util.java 9 Oct 2008 11:55:19 -0000 1.72 +++ src/org/eclipse/jdt/core/tests/util/Util.java 16 Oct 2008 16:39:32 -0000 @@ -155,6 +155,10 @@ compile(pathsAndContents, options, null, outputPath); } public static void compile(String[] pathsAndContents, Map options, String[] classpath, String outputPath) { + compile(pathsAndContents, options, classpath, outputPath, false/*do not write sources*/); + +} +public static void compile(String[] pathsAndContents, Map options, String[] classpath, String outputPath, boolean writeSource) { IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault()); Requestor requestor = new Requestor( @@ -163,6 +167,7 @@ false, /* show category */ false /* show warning token*/); requestor.outputPath = outputPath.endsWith(File.separator) ? outputPath : outputPath + File.separator; + requestor.writeSource = writeSource; String[] classLibs = getJavaClassLibs(); if (classpath != null) { @@ -336,11 +341,14 @@ createJar(pathsAndContents, null, options, null, jarPath); } public static void createJar(String[] pathsAndContents, String[] extraPathsAndContents, Map options, String[] classpath, String jarPath) throws IOException { + createJar(pathsAndContents, extraPathsAndContents, options, classpath, jarPath, false/*do not write source*/); +} +public static void createJar(String[] pathsAndContents, String[] extraPathsAndContents, Map options, String[] classpath, String jarPath, boolean writeSource) throws IOException { String classesPath = getOutputDirectory() + File.separator + "classes"; File classesDir = new File(classesPath); flushDirectoryContent(classesDir); if (pathsAndContents != null) { - compile(pathsAndContents, options, classpath, classesPath); + compile(pathsAndContents, options, classpath, classesPath, writeSource); } if (extraPathsAndContents != null) { for (int i = 0, l = extraPathsAndContents == null ? 0 : extraPathsAndContents.length; i < l; /* inc in loop */) { @@ -355,7 +363,10 @@ createJar(javaPathsAndContents, null, jarPath, compliance); } public static void createJar(String[] javaPathsAndContents, String[] extraPathsAndContents, String jarPath, String compliance) throws IOException { - createJar(javaPathsAndContents, extraPathsAndContents, getCompileOptions(compliance), null, jarPath); + createJar(javaPathsAndContents, extraPathsAndContents, getCompileOptions(compliance), null, jarPath, false/*do not write source*/); +} +public static void createJar(String[] javaPathsAndContents, String[] extraPathsAndContents, String jarPath, String compliance, boolean writeSource) throws IOException { + createJar(javaPathsAndContents, extraPathsAndContents, getCompileOptions(compliance), null, jarPath, writeSource); } public static void createSourceZip(String[] pathsAndContents, String zipPath) throws IOException { String sourcesPath = getOutputDirectory() + File.separator + "sources"; @@ -1242,6 +1253,26 @@ System.out.println(); return false; } +public static void writeToFile(char[] contents, String destinationFilePath) { + File destFile = new File(destinationFilePath); + FileOutputStream output = null; + try { + output = new FileOutputStream(destFile); + PrintWriter writer = new PrintWriter(output); + writer.print(contents); + writer.flush(); + } catch (IOException e) { + e.printStackTrace(); + return; + } finally { + if (output != null) { + try { + output.close(); + } catch (IOException e2) { + } + } + } +} public static void writeToFile(String contents, String destinationFilePath) { File destFile = new File(destinationFilePath); FileOutputStream output = null;