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) { |