View | Details | Raw Unified | Return to bug 167743
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/JavaSearchMultipleProjectsTests.java (+53 lines)
Lines 865-868 Link Here
865
		deleteProject("P2");
865
		deleteProject("P2");
866
	}
866
	}
867
}
867
}
868
869
/**
870
 * @bug 167743: [search] Open Type Dialog cannot find types from projects migrated from 3.2.1 workspace
871
 * @test Ensure that types are found even in default package fragment root
872
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=167743"
873
 */
874
public void testBug167743() throws CoreException {
875
	try {
876
		IJavaProject p = createJavaProject("P");
877
		createFolder("/P/test");
878
		createFile(
879
			"/P/test/TestClass.java",
880
			"package test;\n" + 
881
			"public class Test {\n" + 
882
			"}\n"
883
		);
884
885
		// Search all type names with TypeNameMatchRequestor
886
		AbstractJavaSearchTests.TypeNameMatchCollector collector = new AbstractJavaSearchTests.TypeNameMatchCollector() {
887
			public String toString(){
888
				return toFullyQualifiedNamesString();
889
			}
890
		};
891
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { p });
892
		new SearchEngine().searchAllTypeNames(
893
			null,
894
			SearchPattern.R_EXACT_MATCH,
895
			new char[] { '*' },
896
			SearchPattern.R_PATTERN_MATCH,
897
			IJavaSearchConstants.TYPE,
898
			scope,
899
			collector,
900
			IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
901
			null);
902
		// Search all type names with TypeNameRequestor
903
		SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor();
904
		new SearchEngine().searchAllTypeNames(
905
			null,
906
			SearchPattern.R_EXACT_MATCH,
907
			new char[] { '*' },
908
			SearchPattern.R_PATTERN_MATCH,
909
			IJavaSearchConstants.TYPE,
910
			scope,
911
			requestor,
912
			IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
913
			null);
914
		// Should have same types with these 2 searches
915
		assertEquals("Invalid number of types found!", requestor.size(), collector.size());
916
		assertEquals("Found types sounds not to be correct", requestor.toString(), collector.toString());
917
	} finally {
918
		deleteProject("P");
919
	}
920
}
868
}
921
}
(-)src/org/eclipse/jdt/core/tests/model/SearchTests.java (+3 lines)
Lines 97-102 Link Here
97
			}
97
			}
98
			return buffer.toString();
98
			return buffer.toString();
99
		}
99
		}
100
		public int size() {
101
			return this.results.size();
102
		}
100
	}
103
	}
101
	class WaitingJob implements IJob {
104
	class WaitingJob implements IJob {
102
		static final int MAX_WAIT = 30000; // wait 30s max
105
		static final int MAX_WAIT = 30000; // wait 30s max
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (-42 lines)
Lines 11-17 Link Here
11
package org.eclipse.jdt.core.tests.model;
11
package org.eclipse.jdt.core.tests.model;
12
12
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.Arrays;
15
import java.util.List;
14
import java.util.List;
16
15
17
import junit.framework.Test;
16
import junit.framework.Test;
Lines 84-130 Link Here
84
	}
83
	}
85
}
84
}
86
85
87
class TypeNameMatchCollector extends TypeNameMatchRequestor {
88
	List matches = new ArrayList();
89
	public void acceptTypeNameMatch(TypeNameMatch match) {
90
		IType type = match.getType();
91
		if (type != null) {
92
			this.matches.add(type);
93
		}
94
	}
95
	public int size() {
96
		return this.matches.size();
97
	}
98
	private String toString(int kind) {
99
		int size = size();
100
		if (size == 0) return "";
101
		String[] strings = new String[size];
102
		for (int i=0; i<size; i++) {
103
			IType type = (IType) this.matches.get(i);
104
			switch (kind) {
105
				case 1: // fully qualified name
106
					strings[i] = type.getFullyQualifiedName();
107
					break;
108
				case 0:
109
				default:
110
					strings[i] = type.toString();
111
			}
112
		}
113
		Arrays.sort(strings);
114
		StringBuffer buffer = new StringBuffer();
115
		for (int i=0; i<size; i++) {
116
			if (i>0) buffer.append('\n');
117
			buffer.append(strings[i]);
118
		}
119
		return buffer.toString();
120
	}
121
	public String toString() {
122
		return toString(0);
123
	}
124
	public String toFullyQualifiedNamesString() {
125
		return toString(1);
126
	}
127
}
128
IJavaSearchScope getJavaSearchScopeBugs() {
86
IJavaSearchScope getJavaSearchScopeBugs() {
129
	return SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("JavaSearchBugs")});
87
	return SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("JavaSearchBugs")});
130
}
88
}
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java (+39 lines)
Lines 3692-3695 Link Here
3692
		"q1.AA",
3692
		"q1.AA",
3693
		requestor);
3693
		requestor);
3694
}
3694
}
3695
3696
/**
3697
 * @bug 160323: [search] TypeNameMatch: support hashCode/equals
3698
 * @test Ensure that match equals and hashCode methods return same values than those of stored {@link IType}.
3699
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=160323"
3700
 */
3701
public void testBug160323() throws CoreException {
3702
	// Search all type names with TypeNameMatchRequestor
3703
	TypeNameMatchCollector collector = new TypeNameMatchCollector() {
3704
		public String toString(){
3705
			return toFullyQualifiedNamesString();
3706
		}
3707
	};
3708
	new SearchEngine().searchAllTypeNames(
3709
		null,
3710
		SearchPattern.R_EXACT_MATCH,
3711
		null,
3712
		SearchPattern.R_PREFIX_MATCH,
3713
		IJavaSearchConstants.TYPE,
3714
		getJavaSearchScope(),
3715
		collector,
3716
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
3717
		null);
3718
	// Search all type names with TypeNameRequestor
3719
	SearchTests.SearchTypeNameRequestor requestor = new SearchTests.SearchTypeNameRequestor();
3720
	new SearchEngine().searchAllTypeNames(
3721
		null,
3722
		SearchPattern.R_EXACT_MATCH,
3723
		null,
3724
		SearchPattern.R_PREFIX_MATCH,
3725
		IJavaSearchConstants.TYPE,
3726
		getJavaSearchScope(),
3727
		requestor,
3728
		IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
3729
		null);
3730
	// Should have same types with these 2 searches
3731
	assertEquals("We should get some types!", requestor.size(), collector.size());
3732
	assertEquals("Found types sounds not to be correct", requestor.toString(), collector.toString());
3733
}
3695
}
3734
}
(-)src/org/eclipse/jdt/core/tests/model/AbstractJavaSearchTests.java (-1 / +44 lines)
Lines 13-18 Link Here
13
import java.io.File;
13
import java.io.File;
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.util.ArrayList;
15
import java.util.ArrayList;
16
import java.util.Arrays;
16
import java.util.List;
17
import java.util.List;
17
18
18
import org.eclipse.core.resources.*;
19
import org.eclipse.core.resources.*;
Lines 387-393 Link Here
387
		}
388
		}
388
	}
389
	}
389
	
390
	
390
	protected JavaSearchResultCollector resultCollector;
391
	static class TypeNameMatchCollector extends TypeNameMatchRequestor {
392
		List matches = new ArrayList();
393
		public void acceptTypeNameMatch(TypeNameMatch match) {
394
			IType type = match.getType();
395
			if (type != null) {
396
				this.matches.add(type);
397
			}
398
		}
399
		public int size() {
400
			return this.matches.size();
401
		}
402
		private String toString(int kind) {
403
			int size = size();
404
			if (size == 0) return "";
405
			String[] strings = new String[size];
406
			for (int i=0; i<size; i++) {
407
				IType type = (IType) this.matches.get(i);
408
				switch (kind) {
409
					case 1: // fully qualified name
410
						strings[i] = type.getFullyQualifiedName();
411
						break;
412
					case 0:
413
					default:
414
						strings[i] = type.toString();
415
				}
416
			}
417
			Arrays.sort(strings);
418
			StringBuffer buffer = new StringBuffer();
419
			for (int i=0; i<size; i++) {
420
				if (i>0) buffer.append('\n');
421
				buffer.append(strings[i]);
422
			}
423
			return buffer.toString();
424
		}
425
		public String toString() {
426
			return toString(0);
427
		}
428
		public String toFullyQualifiedNamesString() {
429
			return toString(1);
430
		}
431
	}
432
433
protected JavaSearchResultCollector resultCollector;
391
434
392
	public AbstractJavaSearchTests(String name) {
435
	public AbstractJavaSearchTests(String name) {
393
		this(name, 2);
436
		this(name, 2);
(-)workspace/JavaSearch/src/c11/A.java (+1 lines)
Lines 1-3 Link Here
1
package c11;
1
public class A {}
2
public class A {}
2
class A1 extends A {}
3
class A1 extends A {}
3
class A2 extends A {
4
class A2 extends A {
(-)search/org/eclipse/jdt/internal/core/search/JavaSearchScope.java (+3 lines)
Lines 583-588 Link Here
583
				return project.getPackageFragmentRoot(this.containerPaths[index]);
583
				return project.getPackageFragmentRoot(this.containerPaths[index]);
584
			}
584
			}
585
			Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), new Path(this.containerPaths[index]+'/'+this.relativePaths[index]), false);
585
			Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), new Path(this.containerPaths[index]+'/'+this.relativePaths[index]), false);
586
			if (target instanceof IProject) {
587
				return project.getPackageFragmentRoot((IProject) target);
588
			}
586
			if (target instanceof IResource) {
589
			if (target instanceof IResource) {
587
				IJavaElement element = JavaCore.create((IResource)target);
590
				IJavaElement element = JavaCore.create((IResource)target);
588
				return (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
591
				return (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);

Return to bug 167743