View | Details | Raw Unified | Return to bug 186415 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceSearchTests.java (-1 / +97 lines)
Lines 12-17 Link Here
12
12
13
import java.io.PrintStream;
13
import java.io.PrintStream;
14
import java.text.NumberFormat;
14
import java.text.NumberFormat;
15
import java.util.ArrayList;
16
import java.util.List;
15
17
16
import junit.framework.Test;
18
import junit.framework.Test;
17
19
Lines 19-24 Link Here
19
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.core.runtime.Path;
22
import org.eclipse.core.runtime.Path;
21
import org.eclipse.jdt.core.IJavaElement;
23
import org.eclipse.jdt.core.IJavaElement;
24
import org.eclipse.jdt.core.IPackageFragment;
22
import org.eclipse.jdt.core.search.*;
25
import org.eclipse.jdt.core.search.*;
23
import org.eclipse.jdt.core.tests.model.AbstractJavaModelTests;
26
import org.eclipse.jdt.core.tests.model.AbstractJavaModelTests;
24
import org.eclipse.jdt.internal.core.search.processing.IJob;
27
import org.eclipse.jdt.internal.core.search.processing.IJob;
Lines 161-167 Link Here
161
		}
164
		}
162
	}
165
	}
163
	
166
	
164
	protected void search(String patternString, int searchFor, int limitTo, IJavaSearchScope scope, JavaSearchResultCollector resultCollector) throws CoreException {
167
	protected void search(String patternString, int searchFor, int limitTo, IJavaSearchScope scope, SearchRequestor resultCollector) throws CoreException {
165
		int matchMode = patternString.indexOf('*') != -1 || patternString.indexOf('?') != -1
168
		int matchMode = patternString.indexOf('*') != -1 || patternString.indexOf('?') != -1
166
			? SearchPattern.R_PATTERN_MATCH
169
			? SearchPattern.R_PATTERN_MATCH
167
			: SearchPattern.R_EXACT_MATCH;
170
			: SearchPattern.R_EXACT_MATCH;
Lines 660-663 Link Here
660
		commitMeasurements();
663
		commitMeasurements();
661
		assertPerformance();
664
		assertPerformance();
662
	}
665
	}
666
667
	/**
668
	 * Performance tests for search: Package Declarations on workspace scope.
669
	 */
670
	public void testSearchPackageDeclarationsWorkspace() throws CoreException {
671
		tagAsSummary("Search workspace package declarations", false); // do NOT put in fingerprint
672
673
		// Wait for indexing end
674
		AbstractJavaModelTests.waitUntilIndexesReady();
675
676
		// Warm up
677
		IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
678
		String name = "*";
679
		JavaSearchResultCollector resultCollector = new JavaSearchResultCollector();
680
		if (true) {
681
		for (int i=0 ; i<WARMUP_COUNT; i++) {
682
			search(name, PACKAGE, DECLARATIONS, scope, resultCollector);
683
			if (i==0) {
684
				System.out.println("	- "+INT_FORMAT.format(resultCollector.count)+" package declarations in workspace.");
685
			}
686
		}
687
		} else {
688
			org.eclipse.jdt.core.tests.model.AbstractJavaSearchTests.JavaSearchResultCollector searchCollector = new org.eclipse.jdt.core.tests.model.AbstractJavaSearchTests.JavaSearchResultCollector(true);
689
			for (int i=0 ; i<1; i++) {
690
				search(name, PACKAGE, DECLARATIONS, scope, searchCollector);
691
				if (i==0) {
692
					System.out.println("	- "+INT_FORMAT.format(searchCollector.count)+" package declarations in workspace.");
693
					System.out.println(searchCollector.toString());
694
				}
695
			}
696
		}
697
698
		// Measures
699
		for (int i=0; i<MEASURES_COUNT; i++) {
700
			cleanCategoryTableCache(false, scope, resultCollector);
701
			runGc();
702
			startMeasuring();
703
			// TODO (frederic) increase time for this test in next version as bug 183062 fix make its time around 2ms!
704
			for (int j=0; j<10; j++)
705
				search(name, PACKAGE, DECLARATIONS, scope, resultCollector);
706
			stopMeasuring();
707
		}
708
		
709
		// Commit
710
		commitMeasurements();
711
		assertPerformance();
712
	}
713
714
	/**
715
	 * Performance tests for search: Simulate a Goto Package action.
716
	 * This action searches all package declarations on the entire workspace.
717
	 */
718
	public void _testGotoPackage() throws CoreException {
719
		tagAsSummary("Search package declarations", true); // put in fingerprint
720
721
		// Wait for indexing end
722
		AbstractJavaModelTests.waitUntilIndexesReady();
723
724
		// Warm up
725
		IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
726
		String name = "*";
727
		final List packageList= new ArrayList();
728
		SearchRequestor requestor = new SearchRequestor() {
729
			public void acceptSearchMatch(SearchMatch match) throws CoreException {
730
				IJavaElement enclosingElement= (IJavaElement) match.getElement();
731
				enclosingElement.getElementName();
732
				IPackageFragment pkg= (IPackageFragment) enclosingElement;
733
				if (pkg.getCompilationUnits().length == 0 && pkg.getClassFiles().length == 0) {
734
					return;
735
				}
736
				packageList.add(enclosingElement);
737
			}
738
		};
739
		for (int i=0 ; i<WARMUP_COUNT; i++) {
740
			search(name, PACKAGE, DECLARATIONS, scope, requestor);
741
			if (i==0) {
742
				System.out.println("	- "+INT_FORMAT.format(packageList.size())+" package declarations in workspace.");
743
			}
744
		}
745
746
		// Measures
747
		for (int i=0; i<MEASURES_COUNT; i++) {
748
			cleanCategoryTableCache(false, scope, new JavaSearchResultCollector());
749
			runGc();
750
			startMeasuring();
751
			search(name, PACKAGE, DECLARATIONS, scope, requestor);
752
			stopMeasuring();
753
		}
754
		
755
		// Commit
756
		commitMeasurements();
757
		assertPerformance();
758
	}
663
}
759
}
(-)search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java (-20 / +29 lines)
Lines 1235-1276 Link Here
1235
			return;
1235
			return;
1236
		}
1236
		}
1237
		PackageDeclarationPattern pkgPattern = (PackageDeclarationPattern) searchPattern;
1237
		PackageDeclarationPattern pkgPattern = (PackageDeclarationPattern) searchPattern;
1238
		IPath[] scopeProjectsAndJars = this.scope.enclosingProjectsAndJars();
1238
		boolean isWorkspaceScope = this.scope == JavaModelManager.getJavaModelManager().getWorkspaceScope();
1239
		int scopeLength = scopeProjectsAndJars.length;
1239
		IPath[] scopeProjectsAndJars =  isWorkspaceScope ? null : this.scope.enclosingProjectsAndJars();
1240
		int scopeLength = isWorkspaceScope ? 0 : scopeProjectsAndJars.length;
1240
		IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
1241
		IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
1242
		SimpleSet packages = new SimpleSet();
1241
		for (int i = 0, length = projects.length; i < length; i++) {
1243
		for (int i = 0, length = projects.length; i < length; i++) {
1242
			IJavaProject javaProject = projects[i];
1243
			// Verify that project belongs to the scope
1244
			// Verify that project belongs to the scope
1244
			boolean found = false;
1245
			if (!isWorkspaceScope) {
1245
			for (int j=0; j<scopeLength; j++) {
1246
				boolean found = false;
1246
				if (projects[i].getPath().equals(scopeProjectsAndJars[j])) {
1247
				for (int j=0; j<scopeLength; j++) {
1247
					found = true;
1248
					if (projects[i].getPath().equals(scopeProjectsAndJars[j])) {
1248
					break;
1249
						found = true;
1250
						break;
1251
					}
1249
				}
1252
				}
1253
				if (!found) continue;
1250
			}
1254
			}
1251
			if (!found) continue;
1255
			// Get all project package fragment names
1252
			this.nameLookup = ((JavaProject) projects[i]).newNameLookup(this.workingCopies);
1256
			this.nameLookup = ((JavaProject) projects[i]).newNameLookup(this.workingCopies);
1253
			IPackageFragment[] packageFragments = this.nameLookup.findPackageFragments(new String(pkgPattern.pkgName), true, true);
1257
			IPackageFragment[] packageFragments = this.nameLookup.findPackageFragments(new String(pkgPattern.pkgName), true, true);
1254
			int pLength = packageFragments == null ? 0 : packageFragments.length;
1258
			int pLength = packageFragments == null ? 0 : packageFragments.length;
1259
			// Report matches avoiding duplicate names
1255
			for (int p=0; p<pLength; p++) {
1260
			for (int p=0; p<pLength; p++) {
1256
				IPackageFragment fragment = packageFragments[p];
1261
				IPackageFragment fragment = packageFragments[p];
1257
				IResource resource = fragment.getResource();
1262
				if (packages.addIfNotIncluded(fragment) == null) continue;
1258
				if (resource == null) // case of a file in an external jar
1263
				if (encloses(fragment)) {
1259
					resource = javaProject.getProject();
1264
					IResource resource = fragment.getResource();
1260
				try {
1265
					if (resource == null) // case of a file in an external jar
1261
					if (encloses(fragment)) {
1266
						resource = fragment.getJavaProject().getProject();
1262
						SearchMatch match = new PackageDeclarationMatch(fragment, SearchMatch.A_ACCURATE, -1, -1, participant, resource);
1267
					try {
1263
						report(match);
1268
						if (encloses(fragment)) {
1269
							SearchMatch match = new PackageDeclarationMatch(fragment, SearchMatch.A_ACCURATE, -1, -1, participant, resource);
1270
							report(match);
1271
						}
1272
					} catch (JavaModelException e) {
1273
						throw e;
1274
					} catch (CoreException e) {
1275
						throw new JavaModelException(e);
1264
					}
1276
					}
1265
				} catch (JavaModelException e) {
1266
					throw e;
1267
				} catch (CoreException e) {
1268
					throw new JavaModelException(e);
1269
				}
1277
				}
1270
			}
1278
			}
1271
		}
1279
		}
1272
	}
1280
	}
1273
}
1281
}
1282
//*/
1274
protected IType lookupType(ReferenceBinding typeBinding) {
1283
protected IType lookupType(ReferenceBinding typeBinding) {
1275
	if (typeBinding == null) return null;
1284
	if (typeBinding == null) return null;
1276
1285
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (-8 / +91 lines)
Lines 3784-3791 Link Here
3784
		"	}\n" + 
3784
		"	}\n" + 
3785
		"}\n"
3785
		"}\n"
3786
	);
3786
	);
3787
	IPath pathDef = new Path("/JavaSearchBugs/src/b97606/pack/def");
3787
	IPath rootPath = new Path("/JavaSearchBugs/src/b97606");
3788
	IPath pathRef = new Path("/JavaSearchBugs/src/b97606/pack/ref");
3788
	IPath pathDef = rootPath.append("pack").append("def");
3789
	IPath pathRef = rootPath.append("pack").append("ref");
3789
	try {
3790
	try {
3790
		createFolder(pathDef);
3791
		createFolder(pathDef);
3791
		createFolder(pathRef);
3792
		createFolder(pathRef);
Lines 3803-3810 Link Here
3803
		);
3804
		);
3804
	}
3805
	}
3805
	finally {
3806
	finally {
3806
		deleteFolder(pathDef);
3807
		deleteFolder(rootPath);
3807
		deleteFolder(pathRef);
3808
	}
3808
	}
3809
}
3809
}
3810
public void testBug97606b() throws CoreException {
3810
public void testBug97606b() throws CoreException {
Lines 3837-3844 Link Here
3837
		"	}\n" + 
3837
		"	}\n" + 
3838
		"}\n"
3838
		"}\n"
3839
	);
3839
	);
3840
	IPath pathDef = new Path("/JavaSearchBugs/src/b97606/pack/def");
3840
	IPath rootPath = new Path("/JavaSearchBugs/src/b97606");
3841
	IPath pathRef = new Path("/JavaSearchBugs/src/b97606/pack/ref");
3841
	IPath pathDef = rootPath.append("pack").append("def");
3842
	IPath pathRef = rootPath.append("pack").append("ref");
3842
	try {
3843
	try {
3843
		createFolder(pathDef);
3844
		createFolder(pathDef);
3844
		createFolder(pathRef);
3845
		createFolder(pathRef);
Lines 3856-3863 Link Here
3856
		);
3857
		);
3857
	}
3858
	}
3858
	finally {
3859
	finally {
3859
		deleteFolder(pathDef);
3860
		deleteFolder(rootPath);
3860
		deleteFolder(pathRef);
3861
	}
3861
	}
3862
}
3862
}
3863
3863
Lines 7913-7916 Link Here
7913
	}
7913
	}
7914
}
7914
}
7915
7915
7916
/**
7917
 * @bug 185452 [search] for all packages seems hung
7918
 * @test Ensure that all package declarations are found only once
7919
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=185452"
7920
 */
7921
public void testBug185452() throws CoreException {
7922
	JavaSearchResultCollector packageCollector = new JavaSearchResultCollector(true);
7923
	search(
7924
		"*", 
7925
		PACKAGE,
7926
		DECLARATIONS, 
7927
		SearchEngine.createWorkspaceScope(), 
7928
		packageCollector);
7929
	assertSearchResults(
7930
		""+ getExternalJCLPathString("1.5") + " \n" + 
7931
		""+ getExternalJCLPathString("1.5") + " java\n" + 
7932
		""+ getExternalJCLPathString("1.5") + " java.io\n" + 
7933
		""+ getExternalJCLPathString("1.5") + " java.lang\n" + 
7934
		""+ getExternalJCLPathString("1.5") + " java.lang.annotation\n" + 
7935
		"lib \n" + 
7936
		"lib/JavaSearch15.jar  [No source]\n" + 
7937
		"lib/JavaSearch15.jar g1 [No source]\n" + 
7938
		"lib/JavaSearch15.jar g1.t [No source]\n" + 
7939
		"lib/JavaSearch15.jar g1.t.s [No source]\n" + 
7940
		"lib/JavaSearch15.jar g1.t.s.def [No source]\n" + 
7941
		"lib/JavaSearch15.jar g5 [No source]\n" + 
7942
		"lib/JavaSearch15.jar g5.c [No source]\n" + 
7943
		"lib/JavaSearch15.jar g5.c.def [No source]\n" + 
7944
		"lib/JavaSearch15.jar g5.m [No source]\n" + 
7945
		"lib/JavaSearch15.jar g5.m.def [No source]\n" + 
7946
		"lib/b110422.jar  [No source]\n" + 
7947
		"lib/b110422.jar b110422 [No source]\n" + 
7948
		"lib/b123679.jar  [No source]\n" + 
7949
		"lib/b123679.jar pack [No source]\n" + 
7950
		"lib/b123679.jar test [No source]\n" + 
7951
		"lib/b124469.jar  [No source]\n" + 
7952
		"lib/b124469.jar pack [No source]\n" + 
7953
		"lib/b124469.jar test [No source]\n" + 
7954
		"lib/b124645.jar  [No source]\n" + 
7955
		"lib/b124645.jar test [No source]\n" + 
7956
		"lib/b124645.jar xy [No source]\n" + 
7957
		"lib/b125178.jar  [No source]\n" + 
7958
		"lib/b125178.jar pack [No source]\n" + 
7959
		"lib/b125178.jar pack.age [No source]\n" + 
7960
		"lib/b126330.jar  [No source]\n" + 
7961
		"lib/b128877.jar  [No source]\n" + 
7962
		"lib/b128877.jar pack [No source]\n" + 
7963
		"lib/b137984.jar  [No source]\n" + 
7964
		"lib/b140156.jar  [No source]\n" + 
7965
		"lib/b164791.jar  [No source]\n" + 
7966
		"lib/b164791.jar pack [No source]\n" + 
7967
		"lib/b164791.jar test [No source]\n" + 
7968
		"lib/b166348.jar  [No source]\n" + 
7969
		"lib/b166348.jar pack [No source]\n" + 
7970
		"lib/b166348.jar test [No source]\n" + 
7971
		"lib/b86293.jar  [No source]\n" + 
7972
		"lib/b87627.jar  [No source]\n" + 
7973
		"lib/b87627.jar b87627 [No source]\n" + 
7974
		"lib/b89848 b89848\n" + 
7975
		"lib/b95152.jar  [No source]\n" + 
7976
		"lib/b95152.jar b95152 [No source]\n" + 
7977
		"lib/test75816.jar  [No source]\n" + 
7978
		"lib/test81556.jar  [No source]\n" + 
7979
		"lib/test81556.jar b81556 [No source]\n" + 
7980
		"lib/test81556.jar b81556.b [No source]\n" + 
7981
		"src \n" + 
7982
		"src/b108088 b108088\n" + 
7983
		"src/b123679 b123679\n" + 
7984
		"src/b123679/pack b123679.pack\n" + 
7985
		"src/b123679/test b123679.test\n" + 
7986
		"src/b124645 b124645\n" + 
7987
		"src/b124645/test b124645.test\n" + 
7988
		"src/b124645/xy b124645.xy\n" + 
7989
		"src/b127628 b127628\n" + 
7990
		"src/b137984 b137984\n" + 
7991
		"src/b163984 b163984\n" + 
7992
		"src/b81556 b81556\n" + 
7993
		"src/b81556/a b81556.a\n" + 
7994
		"src/b86380 b86380\n" + 
7995
		"src/b95794 b95794",
7996
		packageCollector);
7997
}
7998
7916
}
7999
}

Return to bug 186415