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

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/PackageFragment.java (-2 / +14 lines)
Lines 57-65 Link Here
57
57
58
	public String[] names;
58
	public String[] names;
59
59
60
	private static final short NOT_INITIALIZED = -1;
61
	private static final short VALID = 0;
62
	private static final short INVALID = 1;
63
	
64
	private short packageValid;
65
60
protected PackageFragment(PackageFragmentRoot root, String[] names) {
66
protected PackageFragment(PackageFragmentRoot root, String[] names) {
61
	super(root);
67
	super(root);
62
	this.names = names;
68
	this.names = names;
69
	this.packageValid = NOT_INITIALIZED;
63
}
70
}
64
/**
71
/**
65
 * @see Openable
72
 * @see Openable
Lines 390-403 Link Here
390
public boolean isDefaultPackage() {
397
public boolean isDefaultPackage() {
391
	return this.names.length == 0;
398
	return this.names.length == 0;
392
}
399
}
393
private boolean isValidPackageName() {
400
public boolean isValidPackageName() {
401
	if (this.packageValid != NOT_INITIALIZED) 
402
		return (this.packageValid == VALID);
394
	JavaProject javaProject = (JavaProject) getJavaProject();
403
	JavaProject javaProject = (JavaProject) getJavaProject();
395
	String sourceLevel = javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
404
	String sourceLevel = javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
396
	String complianceLevel = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
405
	String complianceLevel = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
397
	for (int i = 0, length = this.names.length; i < length; i++) {
406
	for (int i = 0, length = this.names.length; i < length; i++) {
398
		if (!Util.isValidFolderNameForPackage(this.names[i], sourceLevel, complianceLevel))
407
		if (!Util.isValidFolderNameForPackage(this.names[i], sourceLevel, complianceLevel)) {
408
			this.packageValid = INVALID;
399
			return false;
409
			return false;
410
		}	
400
	}
411
	}
412
	this.packageValid = VALID;
401
	return true;
413
	return true;
402
}
414
}
403
/**
415
/**
(-)search/org/eclipse/jdt/internal/core/search/TypeNameMatchRequestorWrapper.java (-1 / +3 lines)
Lines 27-32 Link Here
27
import org.eclipse.jdt.core.search.TypeNameRequestor;
27
import org.eclipse.jdt.core.search.TypeNameRequestor;
28
import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
28
import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
29
import org.eclipse.jdt.internal.core.Openable;
29
import org.eclipse.jdt.internal.core.Openable;
30
import org.eclipse.jdt.internal.core.PackageFragment;
30
import org.eclipse.jdt.internal.core.PackageFragmentRoot;
31
import org.eclipse.jdt.internal.core.PackageFragmentRoot;
31
import org.eclipse.jdt.internal.core.util.HandleFactory;
32
import org.eclipse.jdt.internal.core.util.HandleFactory;
32
import org.eclipse.jdt.internal.core.util.HashtableOfArrayToObject;
33
import org.eclipse.jdt.internal.core.util.HashtableOfArrayToObject;
Lines 116-122 Link Here
116
		// Accept match if the type has been found
117
		// Accept match if the type has been found
117
		if (type != null) {
118
		if (type != null) {
118
			// hierarchy scopes require one more check:
119
			// hierarchy scopes require one more check:
119
			if (!(this.scope instanceof HierarchyScope) || ((HierarchyScope)this.scope).enclosesFineGrained(type)) {
120
			if ((!(this.scope instanceof HierarchyScope) || ((HierarchyScope) this.scope).enclosesFineGrained(type))
121
				&& ((PackageFragment) type.getPackageFragment()).isValidPackageName()) {
120
122
121
				// Create the match
123
				// Create the match
122
				final JavaSearchTypeNameMatch match = new JavaSearchTypeNameMatch(type, modifiers);
124
				final JavaSearchTypeNameMatch match = new JavaSearchTypeNameMatch(type, modifiers);
(-)search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java (+19 lines)
Lines 1689-1694 Link Here
1689
	return this.currentPossibleMatch.document.getParticipant();
1689
	return this.currentPossibleMatch.document.getParticipant();
1690
}
1690
}
1691
1691
1692
protected boolean filterMatch(SearchMatch match) {
1693
	
1694
	// should not look for classes with invalid package names
1695
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=293861
1696
	IJavaElement element = (IJavaElement)match.getElement();	
1697
	if (! (element instanceof PackageFragment)) 
1698
		element = this.currentPossibleMatch.openable.getParent();	
1699
	if (element != null  && !((PackageFragment)element).isValidPackageName()) {
1700
		if (BasicSearchEngine.VERBOSE) {
1701
			System.out.println("Filtering out the match " + match.getResource() + " as the packageName is not valid"); //$NON-NLS-1$ //$NON-NLS-2$
1702
		}
1703
		return true;
1704
	}	
1705
	return false;
1706
}
1707
1692
protected void report(SearchMatch match) throws CoreException {
1708
protected void report(SearchMatch match) throws CoreException {
1693
	if (match == null) {
1709
	if (match == null) {
1694
		if (BasicSearchEngine.VERBOSE) {
1710
		if (BasicSearchEngine.VERBOSE) {
Lines 1696-1701 Link Here
1696
		}
1712
		}
1697
		return;
1713
		return;
1698
	}
1714
	}
1715
	if (filterMatch(match)) {
1716
		return;
1717
	}
1699
	long start = -1;
1718
	long start = -1;
1700
	if (BasicSearchEngine.VERBOSE) {
1719
	if (BasicSearchEngine.VERBOSE) {
1701
		start = System.currentTimeMillis();
1720
		start = System.currentTimeMillis();
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+44 lines)
Lines 11070-11073 Link Here
11070
		removeClasspathEntry(JAVA_PROJECT, new Path(libPath));
11070
		removeClasspathEntry(JAVA_PROJECT, new Path(libPath));
11071
	}
11071
	}
11072
}
11072
}
11073
/**
11074
 * @bug 293861: Problem with refactoring when existing jar with invalid package names
11075
 * @test Ensure that the search doesn't return classes with invalid package names
11076
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=293861"
11077
 */
11078
public void testBug293861a() throws CoreException {
11079
	try 
11080
	{
11081
		IJavaProject project = createJavaProject("P");
11082
		addClasspathEntry(project, JavaCore.newLibraryEntry(new Path("/JavaSearchBugs/lib/b293861.jar"), null, null));
11083
		int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS;
11084
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask);
11085
				
11086
		search("b293861TestFunc", IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, scope);
11087
		assertSearchResults("No search results expected", "", this.resultCollector);
11088
	} finally {
11089
		deleteProject("P");
11090
	}
11091
}
11092
11093
/*
11094
 * SearchEngine#searchAllTypeNames should also not return classes with invalid package names
11095
 */
11096
public void testBug293861b() throws CoreException {
11097
	try
11098
	{
11099
		IJavaProject project = createJavaProject("P");
11100
		addClasspathEntry(project, JavaCore.newLibraryEntry(new Path("/JavaSearchBugs/lib/b293861.jar"), null, null));
11101
		int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS;
11102
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask);
11103
		
11104
		TypeNameMatchCollector collector = new TypeNameMatchCollector();
11105
		new SearchEngine().searchAllTypeNames(
11106
				null,
11107
				new char[][] {"b293861Test".toCharArray()},
11108
				scope,
11109
				collector,
11110
				IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
11111
				null);
11112
		assertSearchResults("No search results expected", "", collector);		
11113
	} finally {
11114
		deleteProject("P");
11115
	}
11116
}
11073
}
11117
}

Return to bug 293861