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

Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java (-29 / +88 lines)
Lines 61-66 Link Here
61
import org.eclipse.jdt.internal.core.JavaElement;
61
import org.eclipse.jdt.internal.core.JavaElement;
62
import org.eclipse.jdt.internal.core.JavaModelManager;
62
import org.eclipse.jdt.internal.core.JavaModelManager;
63
import org.eclipse.jdt.internal.core.JavaProject;
63
import org.eclipse.jdt.internal.core.JavaProject;
64
import org.eclipse.jdt.internal.core.LocalVariable;
64
import org.eclipse.jdt.internal.core.NameLookup;
65
import org.eclipse.jdt.internal.core.NameLookup;
65
import org.eclipse.jdt.internal.core.Openable;
66
import org.eclipse.jdt.internal.core.Openable;
66
import org.eclipse.jdt.internal.core.PackageFragment;
67
import org.eclipse.jdt.internal.core.PackageFragment;
Lines 124-129 Link Here
124
// Cache for method handles
125
// Cache for method handles
125
HashSet methodHandles;
126
HashSet methodHandles;
126
127
128
// Inner-most local element to add while reporting search match
129
// when requestor requires it (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=110336)
130
// TODO (frederic) This field should be removed while implementing design for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=79866
131
private IJavaElement localElement = null;
132
127
/**
133
/**
128
 * An ast visitor that visits local type declarations.
134
 * An ast visitor that visits local type declarations.
129
 */
135
 */
Lines 165-171 Link Here
165
	}
171
	}
166
}
172
}
167
173
168
169
public static class WorkingCopyDocument extends JavaSearchDocument {
174
public static class WorkingCopyDocument extends JavaSearchDocument {
170
	public org.eclipse.jdt.core.ICompilationUnit workingCopy;
175
	public org.eclipse.jdt.core.ICompilationUnit workingCopy;
171
	WorkingCopyDocument(org.eclipse.jdt.core.ICompilationUnit workingCopy, SearchParticipant participant) {
176
	WorkingCopyDocument(org.eclipse.jdt.core.ICompilationUnit workingCopy, SearchParticipant participant) {
Lines 562-567 Link Here
562
	}
567
	}
563
	return ((IType) parent).getInitializer(occurrenceCount);
568
	return ((IType) parent).getInitializer(occurrenceCount);
564
}
569
}
570
/**
571
 * Create an handle for a local variable declartion (may be a local variable or type parameter).
572
 */
573
protected IJavaElement createHandle(AbstractVariableDeclaration variableDeclaration, IJavaElement parent) {
574
	switch (variableDeclaration.getKind()) {
575
		case AbstractVariableDeclaration.LOCAL_VARIABLE:
576
			return new LocalVariable((JavaElement)parent,
577
				new String(variableDeclaration.name),
578
				variableDeclaration.declarationSourceStart,
579
				variableDeclaration.declarationSourceEnd,
580
				variableDeclaration.sourceStart,
581
				variableDeclaration.sourceEnd,
582
				new String(variableDeclaration.type.resolvedType.signature())
583
			);
584
		case AbstractVariableDeclaration.TYPE_PARAMETER :
585
			return new org.eclipse.jdt.internal.core.TypeParameter((JavaElement)parent, new String(variableDeclaration.name));
586
	}
587
	return null;
588
}
565
/*
589
/*
566
 * Creates hierarchy resolver if needed. 
590
 * Creates hierarchy resolver if needed. 
567
 * Returns whether focus is visible.
591
 * Returns whether focus is visible.
Lines 1556-1562 Link Here
1556
		}
1580
		}
1557
		System.out.println("\tRaw: "+match.isRaw()); //$NON-NLS-1$
1581
		System.out.println("\tRaw: "+match.isRaw()); //$NON-NLS-1$
1558
	}
1582
	}
1583
	match.setLocalElement(this.localElement);
1559
	this.requestor.acceptSearchMatch(match);
1584
	this.requestor.acceptSearchMatch(match);
1585
	this.localElement = null;
1560
	if (BasicSearchEngine.VERBOSE)
1586
	if (BasicSearchEngine.VERBOSE)
1561
		this.resultCollectorTime += System.currentTimeMillis()-start;
1587
		this.resultCollectorTime += System.currentTimeMillis()-start;
1562
}
1588
}
Lines 1848-1853 Link Here
1848
		}
1874
		}
1849
	}
1875
	}
1850
1876
1877
	// report the type parameters
1878
	TypeParameter[] typeParameters = method.typeParameters();
1879
	if (typeParameters != null) {
1880
		if (enclosingElement == null) {
1881
			enclosingElement = createHandle(method, parent);
1882
		}
1883
		reportMatching(typeParameters, enclosingElement, parent, method.binding, nodeSet);
1884
	}
1885
1851
	// report annotations
1886
	// report annotations
1852
	if (method.annotations != null) {
1887
	if (method.annotations != null) {
1853
		if (enclosingElement == null) {
1888
		if (enclosingElement == null) {
Lines 1867-1872 Link Here
1867
					for (int i = 0, l = nodes.length; i < l; i++) {
1902
					for (int i = 0, l = nodes.length; i < l; i++) {
1868
						ASTNode node = nodes[i];
1903
						ASTNode node = nodes[i];
1869
						Integer level = (Integer) nodeSet.matchingNodes.removeKey(node);
1904
						Integer level = (Integer) nodeSet.matchingNodes.removeKey(node);
1905
						this.localElement = null;
1906
						if (method.scope != null /* no error */ && this.requestor.provideLocalElements()) {
1907
							LocalDeclaration localDecl = method.scope.findLocalVariableDeclaration(node.sourceStart);
1908
							if (localDecl != null) {
1909
								// Set local element as it's different from enclosing one
1910
								this.localElement = createHandle(localDecl, enclosingElement);
1911
							}
1912
						}
1870
						this.patternLocator.matchReportReference(node, enclosingElement, method.binding, level.intValue(), this);
1913
						this.patternLocator.matchReportReference(node, enclosingElement, method.binding, level.intValue(), this);
1871
					}
1914
					}
1872
					return;
1915
					return;
Lines 2121-2156 Link Here
2121
	}
2164
	}
2122
2165
2123
	boolean matchedClassContainer = (this.matchContainer & PatternLocator.CLASS_CONTAINER) != 0;
2166
	boolean matchedClassContainer = (this.matchContainer & PatternLocator.CLASS_CONTAINER) != 0;
2124
	
2167
2125
	// report the type parameters
2168
	// report the type parameters
2126
	if (type.typeParameters != null) {
2169
	if (type.typeParameters != null) {
2127
		for (int i=0, l=type.typeParameters.length; i<l; i++) {
2170
		reportMatching(type.typeParameters, enclosingElement, parent, type.binding, nodeSet);
2128
			TypeParameter typeParameter = type.typeParameters[i];
2129
			if (typeParameter != null) {
2130
				Integer level = (Integer) nodeSet.matchingNodes.removeKey(typeParameter);
2131
				if (level != null && matchedClassContainer) {
2132
					if (level.intValue() > -1 && enclosesElement) {
2133
						int offset = typeParameter.sourceStart;
2134
						SearchMatch match = this.patternLocator.newDeclarationMatch(typeParameter, enclosingElement, type.binding, level.intValue(), typeParameter.sourceEnd-offset+1, this);
2135
						report(match);
2136
					}
2137
				}
2138
				if (typeParameter.type != null) {
2139
					level = (Integer) nodeSet.matchingNodes.removeKey(typeParameter.type);
2140
					if (level != null && matchedClassContainer) {
2141
						this.patternLocator.matchReportReference(typeParameter.type, enclosingElement, type.binding, level.intValue(), this);
2142
					}
2143
				}
2144
				if (typeParameter.bounds != null) {
2145
					for (int j=0, b=typeParameter.bounds.length; j<b; j++) {
2146
						level = (Integer) nodeSet.matchingNodes.removeKey(typeParameter.bounds[j]);
2147
						if (level != null && matchedClassContainer) {
2148
							this.patternLocator.matchReportReference(typeParameter.bounds[j], enclosingElement, type.binding, level.intValue(), this);
2149
						}
2150
					}
2151
				}
2152
			}
2153
		}
2154
	}
2171
	}
2155
2172
2156
	// report annotations
2173
	// report annotations
Lines 2235-2240 Link Here
2235
		}
2252
		}
2236
	}
2253
	}
2237
}
2254
}
2255
/**
2256
 * Report matches in type parameters.
2257
 */
2258
protected void reportMatching(TypeParameter[] typeParameters, IJavaElement enclosingElement, IJavaElement parent, Binding binding, MatchingNodeSet nodeSet) throws CoreException {
2259
	if (typeParameters == null) return;
2260
	for (int i=0, l=typeParameters.length; i<l; i++) {
2261
		TypeParameter typeParameter = typeParameters[i];
2262
		if (typeParameter != null) {
2263
			Integer level = (Integer) nodeSet.matchingNodes.removeKey(typeParameter);
2264
			if (level != null) {
2265
				if (level.intValue() > -1 && encloses(enclosingElement)) {
2266
					int offset = typeParameter.sourceStart;
2267
					SearchMatch match = this.patternLocator.newDeclarationMatch(typeParameter, enclosingElement, binding, level.intValue(), typeParameter.sourceEnd-offset+1, this);
2268
					report(match);
2269
				}
2270
			}
2271
			if (typeParameter.type != null) {
2272
				level = (Integer) nodeSet.matchingNodes.removeKey(typeParameter.type);
2273
				if (level != null) {
2274
					this.localElement = null;
2275
					if (this.requestor.provideLocalElements()) {
2276
						// Set local element as it's different from enclosing one
2277
						this.localElement = createHandle(typeParameter, enclosingElement);
2278
					}
2279
					this.patternLocator.matchReportReference(typeParameter.type, enclosingElement, binding, level.intValue(), this);
2280
				}
2281
			}
2282
			if (typeParameter.bounds != null) {
2283
				for (int j=0, b=typeParameter.bounds.length; j<b; j++) {
2284
					level = (Integer) nodeSet.matchingNodes.removeKey(typeParameter.bounds[j]);
2285
					if (level != null) {
2286
						this.localElement = null;
2287
						if (this.requestor.provideLocalElements()) {
2288
							this.localElement = createHandle(typeParameter, enclosingElement);
2289
						}
2290
						this.patternLocator.matchReportReference(typeParameter.bounds[j], enclosingElement, binding, level.intValue(), this);
2291
					}
2292
				}
2293
			}
2294
		}
2295
	}
2296
}
2238
protected void reportMatchingSuper(TypeReference superReference, IJavaElement enclosingElement, Binding elementBinding, MatchingNodeSet nodeSet, boolean matchedClassContainer) throws CoreException {
2297
protected void reportMatchingSuper(TypeReference superReference, IJavaElement enclosingElement, Binding elementBinding, MatchingNodeSet nodeSet, boolean matchedClassContainer) throws CoreException {
2239
	ASTNode[] nodes = null;
2298
	ASTNode[] nodes = null;
2240
	if (superReference instanceof ParameterizedSingleTypeReference || superReference instanceof ParameterizedQualifiedTypeReference) {
2299
	if (superReference instanceof ParameterizedSingleTypeReference || superReference instanceof ParameterizedQualifiedTypeReference) {
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java (+49 lines)
Lines 299-304 Link Here
299
		}
299
		}
300
	}
300
	}
301
301
302
	/**
303
	 * Returns the declaration of most specific local containing a given position in its source range.
304
	 * This code does not recurse in nested types
305
	 */
306
	public LocalDeclaration findLocalVariableDeclaration(int position) {
307
308
		// local variable init
309
		int ilocal = 0, maxLocals = this.localIndex;
310
		boolean hasMoreVariables = maxLocals > 0;
311
312
		// scope init
313
		int iscope = 0, maxScopes = this.subscopeCount;
314
		boolean hasMoreScopes = maxScopes > 0;
315
316
		// iterate scopes and variables in parallel
317
		while (hasMoreVariables || hasMoreScopes) {
318
			if (hasMoreScopes
319
				&& (!hasMoreVariables || (subscopes[iscope].startIndex() <= ilocal))) {
320
				// consider subscope first
321
				Scope subscope = subscopes[iscope];
322
				if (subscope.kind == Scope.BLOCK_SCOPE) { // do not dive in nested types
323
					LocalDeclaration localDecl = ((BlockScope)subscope).findLocalVariableDeclaration(position);
324
					if (localDecl != null) {
325
						return localDecl;
326
					}
327
				}
328
				hasMoreScopes = ++iscope < maxScopes;
329
			} else {
330
				
331
				// consider variable first
332
				LocalVariableBinding local = locals[ilocal]; // if no local at all, will be locals[ilocal]==null
333
				if (local != null) {
334
					LocalDeclaration localDecl = local.declaration;
335
					if (localDecl != null) {
336
						if (localDecl.declarationSourceStart <= position) {
337
							if (position <= localDecl.declarationSourceEnd) {
338
								return localDecl;
339
							}
340
						} else {
341
							return null;
342
						}
343
					}
344
				}
345
				hasMoreVariables = ++ilocal < maxLocals;
346
			}
347
		}
348
		return null;
349
	}
350
	
302
	/* Note that it must never produce a direct access to the targetEnclosingType,
351
	/* Note that it must never produce a direct access to the targetEnclosingType,
303
	 * but instead a field sequence (this$2.this$1.this$0) so as to handle such a test case:
352
	 * but instead a field sequence (this$2.this$1.this$0) so as to handle such a test case:
304
	 *
353
	 *
(-)search/org/eclipse/jdt/core/search/SearchRequestor.java (+15 lines)
Lines 92-95 Link Here
92
	public void exitParticipant(SearchParticipant participant) {
92
	public void exitParticipant(SearchParticipant participant) {
93
		// do nothing
93
		// do nothing
94
	}
94
	}
95
	
96
	/**
97
	 * Returns whether search engine should provide local elements while
98
	 * performing requested query.
99
	 * 
100
	 * If sublcass overrides this method to return true instead, search engine then
101
	 * will store in each search match the innermost local element if different than
102
	 * the one already stored in element ({@link SearchMatch#getElement()}).
103
	 * 
104
	 * @see SearchMatch#getLocalElement()
105
	 * @since 3.2
106
	 */
107
	public boolean provideLocalElements() {
108
		return false;
109
	}
95
}
110
}
(-)search/org/eclipse/jdt/core/search/SearchMatch.java (-1 / +24 lines)
Lines 47-52 Link Here
47
	public static final int A_INACCURATE = 1;
47
	public static final int A_INACCURATE = 1;
48
48
49
	private Object element;
49
	private Object element;
50
	private Object localElement;
50
	private int length;
51
	private int length;
51
	private int offset;
52
	private int offset;
52
53
Lines 108-114 Link Here
108
109
109
	/**
110
	/**
110
	 * Returns the element of this search match.
111
	 * Returns the element of this search match.
111
	 * In case of a reference match, this is the inner-most enclosing element of the reference.
112
	 * In case of a reference match, this is the enclosing element of the reference.
112
	 * In case of a declaration match, this is the declaration.
113
	 * In case of a declaration match, this is the declaration.
113
	 * 
114
	 * 
114
	 * @return the element of the search match, or <code>null</code> if none
115
	 * @return the element of the search match, or <code>null</code> if none
Lines 118-123 Link Here
118
	}
119
	}
119
120
120
	/**
121
	/**
122
	 * Returns the innermost local element of this search match.
123
	 * In case of a reference match, this is the inner-most enclosing element of the reference.
124
	 * In case of a declaration match, this is always null.
125
	 * 
126
	 * @return the element of the search match, or <code>null</code> if none or there's
127
	 * 	no more inner-most enclosing than the element itself ({@link SearchMatch#getElement()}).
128
	 */
129
	public final Object getLocalElement() {
130
		return this.localElement;
131
	}
132
133
	/**
121
	 * Returns the length of this search match.
134
	 * Returns the length of this search match.
122
	 * 
135
	 * 
123
	 * @return the length of this search match, or -1 if unknown
136
	 * @return the length of this search match, or -1 if unknown
Lines 258-263 Link Here
258
	}
271
	}
259
272
260
	/**
273
	/**
274
	 * Sets the innert-most element of this search match.
275
	 * 
276
	 * @param element the inner-most local element that encloses or corresponds to the match,
277
	 * or <code>null</code> if none
278
	 */
279
	public final void setLocalElement (Object element) {
280
		this.localElement = element;
281
	}
282
283
	/**
261
	 * Sets whether this search match is inside a doc comment of a Java
284
	 * Sets whether this search match is inside a doc comment of a Java
262
	 * source file.
285
	 * source file.
263
	 * 
286
	 * 
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (-3 / +93 lines)
Lines 46-52 Link Here
46
//	org.eclipse.jdt.internal.codeassist.SelectionEngine.DEBUG = true;
46
//	org.eclipse.jdt.internal.codeassist.SelectionEngine.DEBUG = true;
47
//	TESTS_PREFIX =  "testBug110060";
47
//	TESTS_PREFIX =  "testBug110060";
48
//	TESTS_NAMES = new String[] { "testBug113671" };
48
//	TESTS_NAMES = new String[] { "testBug113671" };
49
//	TESTS_NUMBERS = new int[] { 114539 };
49
//	TESTS_NUMBERS = new int[] { 110336 };
50
//	TESTS_RANGE = new int[] { 83304, -1 };
50
//	TESTS_RANGE = new int[] { 83304, -1 };
51
	}
51
	}
52
52
Lines 57-62 Link Here
57
		matches.add(match);
57
		matches.add(match);
58
	}
58
	}
59
}
59
}
60
class LocalVariablesCollector extends JavaSearchResultCollector {
61
62
	protected IJavaElement getElement(SearchMatch match) {
63
		Object localElement= match.getLocalElement();
64
		if (localElement != null) {
65
			return (IJavaElement) localElement;
66
		}
67
		return super.getElement(match);
68
	}
69
70
	public boolean provideLocalElements() {
71
		return true;
72
	}
73
}
60
74
61
IJavaSearchScope getJavaSearchScopeBugs() {
75
IJavaSearchScope getJavaSearchScopeBugs() {
62
	return SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("JavaSearchBugs")});
76
	return SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("JavaSearchBugs")});
Lines 5268-5274 Link Here
5268
 * @test Bug 114539: [search] Internal error when refactoring code with errors
5282
 * @test Bug 114539: [search] Internal error when refactoring code with errors
5269
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=114539"
5283
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=114539"
5270
 */
5284
 */
5271
// Types search
5272
public void testBug114539() throws CoreException {
5285
public void testBug114539() throws CoreException {
5273
	workingCopies = new ICompilationUnit[2];
5286
	workingCopies = new ICompilationUnit[2];
5274
	workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b114539/Foo.java",
5287
	workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b114539/Foo.java",
Lines 5285-5293 Link Here
5285
	);
5298
	);
5286
	IField field = this.workingCopies[1].getType("Bar").getField("FOO");
5299
	IField field = this.workingCopies[1].getType("Bar").getField("FOO");
5287
	search(field, REFERENCES);
5300
	search(field, REFERENCES);
5288
	this.discard = false;
5289
	assertSearchResults(
5301
	assertSearchResults(
5290
		"src/b114539/Foo.java b114539.Foo.bar [FOO] POTENTIAL_MATCH"
5302
		"src/b114539/Foo.java b114539.Foo.bar [FOO] POTENTIAL_MATCH"
5291
	);
5303
	);
5292
}
5304
}
5305
5306
/**
5307
 * @test Bug 110336: [plan][search] Should optionaly return the local variable for type reference
5308
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=110336"
5309
 */
5310
public void testBug110336a() throws CoreException {
5311
	workingCopies = new ICompilationUnit[1];
5312
	workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b110336/Test.java",
5313
		"package b110336;\n" + 
5314
		"public class Test {\n" + 
5315
		"	<TP extends Test> void method(Class<Test> clazz) {\n" + 
5316
		"		Test localVar1 = new Test();\n" + 
5317
		"		Class<Test> localVar2 = new Class<Test>();\n" + 
5318
		"		localVar1.method(localVar2);\n" + 
5319
		"	}\n" + 
5320
		"}\n"
5321
	);
5322
	IType type = this.workingCopies[0].getType("Test");
5323
	LocalVariablesCollector collector = new LocalVariablesCollector();
5324
	search(type, REFERENCES, EXACT_RULE, getJavaSearchScopeBugs(), collector);
5325
	assertSearchResults(
5326
		"src/b110336/Test.java void b110336.Test.method(Class<Test>).TP [Test]\n" + 
5327
		"src/b110336/Test.java void b110336.Test.method(Class<Test>) [Test]\n" + 
5328
		"src/b110336/Test.java void b110336.Test.method(Class<Test>).localVar1 [Test]\n" + 
5329
		"src/b110336/Test.java void b110336.Test.method(Class<Test>).localVar1 [Test]\n" + 
5330
		"src/b110336/Test.java void b110336.Test.method(Class<Test>).localVar2 [Test]\n" + 
5331
		"src/b110336/Test.java void b110336.Test.method(Class<Test>).localVar2 [Test]",
5332
		collector
5333
	);
5334
}
5335
public void testBug110336b() throws CoreException {
5336
	workingCopies = new ICompilationUnit[1];
5337
	workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b110336/Test.java",
5338
		"package b110336;\n" + 
5339
		"public class Test {\n" + 
5340
		"	void method1(Test methodParam) {\n" + 
5341
		"		Test localVar1 = new Test(){\n" + 
5342
		"			Class c = Test.class;\n" + 
5343
		"			<TP extends Test> void foo(){\n" + 
5344
		"				Test o = (Test) null;\n" + 
5345
		"			}\n" + 
5346
		"		};\n" + 
5347
		"	}	\n" + 
5348
		"}\n"
5349
	);
5350
	IType type = this.workingCopies[0].getType("Test");
5351
	LocalVariablesCollector collector = new LocalVariablesCollector();
5352
	search(type, REFERENCES, EXACT_RULE, getJavaSearchScopeBugs(), collector);
5353
	assertSearchResults(
5354
		"src/b110336/Test.java void b110336.Test.method1(Test):<anonymous>#1 [Test]\n" + 
5355
		"src/b110336/Test.java void b110336.Test.method1(Test):<anonymous>#1.c [Test]\n" + 
5356
		"src/b110336/Test.java void void b110336.Test.method1(Test):<anonymous>#1.foo().TP [Test]\n" + 
5357
		"src/b110336/Test.java void void b110336.Test.method1(Test):<anonymous>#1.foo().o [Test]\n" + 
5358
		"src/b110336/Test.java void void b110336.Test.method1(Test):<anonymous>#1.foo().o [Test]\n" + 
5359
		"src/b110336/Test.java void b110336.Test.method1(Test) [Test]\n" + 
5360
		"src/b110336/Test.java void b110336.Test.method1(Test).localVar1 [Test]",
5361
		collector
5362
	);
5363
}
5364
public void testBug110336c() throws CoreException {
5365
	workingCopies = new ICompilationUnit[1];
5366
	workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b110336/Test.java",
5367
		"package b110336;\n" + 
5368
		"public class Test<TP extends X> {\n" + 
5369
		"	X x;\n" + 
5370
		"\n" + 
5371
		"}\n" + 
5372
		"class X {}\n"
5373
	);
5374
	IType type = this.workingCopies[0].getType("X");
5375
	LocalVariablesCollector collector = new LocalVariablesCollector();
5376
	search(type, REFERENCES, EXACT_RULE, getJavaSearchScopeBugs(), collector);
5377
	assertSearchResults(
5378
		"src/b110336/Test.java b110336.Test.TP [X]\n" + 
5379
		"src/b110336/Test.java b110336.Test.x [X]",
5380
		collector
5381
	);
5382
}
5293
}
5383
}
(-)src/org/eclipse/jdt/core/tests/model/AbstractJavaSearchTests.java (-1 / +22 lines)
Lines 58-64 Link Here
58
			count++;
58
			count++;
59
			try {
59
			try {
60
				IResource resource = match.getResource();
60
				IResource resource = match.getResource();
61
				IJavaElement element = (IJavaElement) match.getElement();
61
				IJavaElement element = getElement(match);
62
				line = new StringBuffer(getPathString(resource, element));
62
				line = new StringBuffer(getPathString(resource, element));
63
				if (this.showProject) {
63
				if (this.showProject) {
64
					IProject project = element.getJavaProject().getProject();
64
					IProject project = element.getJavaProject().getProject();
Lines 104-109 Link Here
104
					line.append(".");
104
					line.append(".");
105
					line.append(localVar.getElementName());
105
					line.append(localVar.getElementName());
106
					unit = (ICompilationUnit)localVar.getAncestor(IJavaElement.COMPILATION_UNIT);
106
					unit = (ICompilationUnit)localVar.getAncestor(IJavaElement.COMPILATION_UNIT);
107
				} else if (element instanceof ITypeParameter) {
108
					line.append(" ");
109
					ITypeParameter typeParam = (ITypeParameter)element;
110
					IJavaElement parent = typeParam.getParent();
111
					if (parent instanceof IType) {
112
						IType type = (IType)parent;
113
						append(type);
114
						unit = type.getCompilationUnit();
115
					} else if (parent instanceof IMethod) {
116
						IMethod method = (IMethod)parent;
117
						append(method);
118
						unit = method.getCompilationUnit();
119
					} else {
120
						line.append("<Unexpected kind of parent for type parameter>");
121
						unit = (ICompilationUnit)typeParam.getAncestor(IJavaElement.COMPILATION_UNIT);
122
					}
123
					line.append(".");
124
					line.append(typeParam.getElementName());
107
				} else if (element instanceof IImportDeclaration) {
125
				} else if (element instanceof IImportDeclaration) {
108
					IImportDeclaration importDeclaration = (IImportDeclaration)element;
126
					IImportDeclaration importDeclaration = (IImportDeclaration)element;
109
					unit = (ICompilationUnit)importDeclaration.getAncestor(IJavaElement.COMPILATION_UNIT);
127
					unit = (ICompilationUnit)importDeclaration.getAncestor(IJavaElement.COMPILATION_UNIT);
Lines 288-293 Link Here
288
				line.append(((SourceRefElement)type).occurrenceCount);
306
				line.append(((SourceRefElement)type).occurrenceCount);
289
			}
307
			}
290
		}
308
		}
309
		protected IJavaElement getElement(SearchMatch match) {
310
			return (IJavaElement) match.getElement();
311
		}
291
		protected String getPathString(IResource resource, IJavaElement element) {
312
		protected String getPathString(IResource resource, IJavaElement element) {
292
			String pathString;
313
			String pathString;
293
			if (resource != null) {
314
			if (resource != null) {

Return to bug 110336