List of usage examples for org.eclipse.jdt.core IJavaElement METHOD
int METHOD
To view the source code for org.eclipse.jdt.core IJavaElement METHOD.
Click Source Link
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.ConstructorLocator.java
License:Open Source License
protected int referenceType() { return IJavaElement.METHOD; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java
License:Open Source License
public SearchMatch newDeclarationMatch(IJavaElement element, Binding binding, int accuracy, int offset, int length, SearchParticipant participant, IResource resource) { switch (element.getElementType()) { case IJavaElement.PACKAGE_FRAGMENT: return new PackageDeclarationMatch(element, accuracy, offset, length, participant, resource); case IJavaElement.TYPE: return new TypeDeclarationMatch(binding == null ? element : ((JavaElement) element).resolved(binding), accuracy, offset, length, participant, resource); case IJavaElement.FIELD: return new FieldDeclarationMatch(binding == null ? element : ((JavaElement) element).resolved(binding), accuracy, offset, length, participant, resource); case IJavaElement.METHOD: return new MethodDeclarationMatch(binding == null ? element : ((JavaElement) element).resolved(binding), accuracy, offset, length, participant, resource); case IJavaElement.LOCAL_VARIABLE: return new LocalVariableDeclarationMatch(element, accuracy, offset, length, participant, resource); case IJavaElement.PACKAGE_DECLARATION: return new PackageDeclarationMatch(element, accuracy, offset, length, participant, resource); case IJavaElement.TYPE_PARAMETER: return new TypeParameterDeclarationMatch(element, accuracy, offset, length, participant, resource); default:/*from ww w . jav a 2s . com*/ return null; } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodLocator.java
License:Open Source License
/** * @see PatternLocator#matchReportReference(org.eclipse.jdt.internal.compiler.ast.ASTNode, org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.internal.compiler.lookup.Binding, int, MatchLocator) *///from www. java 2s .co m protected void matchReportReference(ASTNode reference, IJavaElement element, IJavaElement localElement, IJavaElement[] otherElements, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException { MethodBinding methodBinding = (reference instanceof MessageSend) ? ((MessageSend) reference).binding : ((elementBinding instanceof MethodBinding) ? (MethodBinding) elementBinding : null); if (this.isDeclarationOfReferencedMethodsPattern) { if (methodBinding == null) return; // need exact match to be able to open on type ref if (accuracy != SearchMatch.A_ACCURATE) return; // element that references the method must be included in the enclosing element DeclarationOfReferencedMethodsPattern declPattern = (DeclarationOfReferencedMethodsPattern) this.pattern; while (element != null && !declPattern.enclosingElement.equals(element)) element = element.getParent(); if (element != null) { reportDeclaration(methodBinding, locator, declPattern.knownMethods); } } else { MethodReferenceMatch methodReferenceMatch = locator.newMethodReferenceMatch(element, elementBinding, accuracy, -1, -1, false /*not constructor*/, false/*not synthetic*/, reference); methodReferenceMatch.setLocalElement(localElement); this.match = methodReferenceMatch; if (this.pattern.findReferences && reference instanceof MessageSend) { IJavaElement focus = this.pattern.focus; // verify closest match if pattern was bound // (see bug 70827) if (focus != null && focus.getElementType() == IJavaElement.METHOD) { if (methodBinding != null && methodBinding.declaringClass != null) { boolean isPrivate = Flags.isPrivate(((IMethod) focus).getFlags()); if (isPrivate && !CharOperation.equals(methodBinding.declaringClass.sourceName, focus.getParent().getElementName().toCharArray())) { return; // finally the match was not possible } } } matchReportReference((MessageSend) reference, locator, accuracy, ((MessageSend) reference).binding); } else { if (reference instanceof SingleMemberAnnotation) { reference = ((SingleMemberAnnotation) reference).memberValuePairs()[0]; this.match.setImplicit(true); } int offset = reference.sourceStart; int length = reference.sourceEnd - offset + 1; this.match.setOffset(offset); this.match.setLength(length); locator.report(this.match); } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.TypeReferenceLocator.java
License:Open Source License
void matchReportReference(Expression expr, int lastIndex, TypeBinding refBinding, MatchLocator locator) throws CoreException { // Look if there's a need to special report for parameterized type if (refBinding.isParameterizedType() || refBinding.isRawType()) { // Try to refine accuracy ParameterizedTypeBinding parameterizedBinding = (ParameterizedTypeBinding) refBinding; updateMatch(parameterizedBinding, this.pattern.getTypeArguments(), this.pattern.hasTypeParameters(), 0, locator);/* ww w .jav a2 s . c om*/ // See whether it is necessary to report or not if (this.match.getRule() == 0) return; // impossible match boolean report = (this.isErasureMatch && this.match.isErasure()) || (this.isEquivalentMatch && this.match.isEquivalent()) || this.match.isExact(); if (!report) return; // Make a special report for parameterized types if necessary if (refBinding.isParameterizedType() && this.pattern.hasTypeArguments()) { TypeReference typeRef = null; TypeReference[] typeArguments = null; if (expr instanceof ParameterizedQualifiedTypeReference) { typeRef = (ParameterizedQualifiedTypeReference) expr; typeArguments = ((ParameterizedQualifiedTypeReference) expr).typeArguments[lastIndex]; } else if (expr instanceof ParameterizedSingleTypeReference) { typeRef = (ParameterizedSingleTypeReference) expr; typeArguments = ((ParameterizedSingleTypeReference) expr).typeArguments; } if (typeRef != null) { locator.reportAccurateParameterizedTypeReference(this.match, typeRef, lastIndex, typeArguments); return; } } } else if (this.pattern.hasTypeArguments()) { // binding has no type params, compatible erasure if pattern does this.match.setRule(SearchPattern.R_ERASURE_MATCH); } // Report match if (expr instanceof ArrayTypeReference) { locator.reportAccurateTypeReference(this.match, expr, this.pattern.simpleName); return; } if (refBinding.isLocalType()) { // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=82673 LocalTypeBinding local = (LocalTypeBinding) refBinding.erasure(); IJavaElement focus = this.pattern.focus; if (focus != null && local.enclosingMethod != null && focus.getParent().getElementType() == IJavaElement.METHOD) { IMethod method = (IMethod) focus.getParent(); if (!CharOperation.equals(local.enclosingMethod.selector, method.getElementName().toCharArray())) { return; } } } if (this.pattern.simpleName == null) { this.match.setOffset(expr.sourceStart); this.match.setLength(expr.sourceEnd - expr.sourceStart + 1); } locator.report(this.match); }
From source file:com.codenvy.ide.ext.java.server.internal.core.SourceMapper.java
License:Open Source License
/** * Returns the SourceRange for the name of the given element, or * {-1, -1} if no source range is known for the name of the element. *//* w ww .j a v a2 s . c o m*/ public SourceRange getNameRange(IJavaElement element) { switch (element.getElementType()) { case IJavaElement.METHOD: if (((IMember) element).isBinary()) { IJavaElement[] el = getUnqualifiedMethodHandle((IMethod) element, false); if (el[1] != null && this.sourceRanges.get(el[0]) == null) { element = getUnqualifiedMethodHandle((IMethod) element, true)[0]; } else { element = el[0]; } } break; case IJavaElement.TYPE_PARAMETER: IJavaElement parent = element.getParent(); if (parent.getElementType() == IJavaElement.METHOD) { IMethod method = (IMethod) parent; if (method.isBinary()) { IJavaElement[] el = getUnqualifiedMethodHandle(method, false); if (el[1] != null && this.sourceRanges.get(el[0]) == null) { method = (IMethod) getUnqualifiedMethodHandle(method, true)[0]; } else { method = (IMethod) el[0]; } element = method.getTypeParameter(element.getElementName()); } } break; case IJavaElement.LOCAL_VARIABLE: LocalVariableElementKey key = new LocalVariableElementKey(element.getParent(), element.getElementName()); SourceRange[] ranges = (SourceRange[]) this.parametersRanges.get(key); if (ranges == null) { return UNKNOWN_RANGE; } else { return ranges[1]; } } SourceRange[] ranges = (SourceRange[]) this.sourceRanges.get(element); if (ranges == null) { return UNKNOWN_RANGE; } else { return ranges[1]; } }
From source file:com.codenvy.ide.ext.java.server.internal.core.SourceMapper.java
License:Open Source License
/** * Returns the <code>SourceRange</code> for the given element, or * {-1, -1} if no source range is known for the element. *//* w w w . j ava 2s .c o m*/ public SourceRange getSourceRange(IJavaElement element) { switch (element.getElementType()) { case IJavaElement.METHOD: if (((IMember) element).isBinary()) { IJavaElement[] el = getUnqualifiedMethodHandle((IMethod) element, false); if (el[1] != null && this.sourceRanges.get(el[0]) == null) { element = getUnqualifiedMethodHandle((IMethod) element, true)[0]; } else { element = el[0]; } } break; case IJavaElement.TYPE_PARAMETER: IJavaElement parent = element.getParent(); if (parent.getElementType() == IJavaElement.METHOD) { IMethod method = (IMethod) parent; if (method.isBinary()) { IJavaElement[] el = getUnqualifiedMethodHandle(method, false); if (el[1] != null && this.sourceRanges.get(el[0]) == null) { method = (IMethod) getUnqualifiedMethodHandle(method, true)[0]; } else { method = (IMethod) el[0]; } element = method.getTypeParameter(element.getElementName()); } } break; case IJavaElement.LOCAL_VARIABLE: LocalVariableElementKey key = new LocalVariableElementKey(element.getParent(), element.getElementName()); SourceRange[] ranges = (SourceRange[]) this.parametersRanges.get(key); if (ranges == null) { return UNKNOWN_RANGE; } else { return ranges[0]; } } SourceRange[] ranges = (SourceRange[]) this.sourceRanges.get(element); if (ranges == null) { return UNKNOWN_RANGE; } else { return ranges[0]; } }
From source file:com.codenvy.ide.ext.java.server.internal.core.SourceType.java
License:Open Source License
public IJavaElement getPrimaryElement(boolean checkOwner) { if (checkOwner) { CompilationUnit cu = (CompilationUnit) getAncestor(COMPILATION_UNIT); if (cu.isPrimary()) return this; }/* w ww . j a va 2s. co m*/ IJavaElement primaryParent = this.parent.getPrimaryElement(false); switch (primaryParent.getElementType()) { case IJavaElement.COMPILATION_UNIT: return ((ICompilationUnit) primaryParent).getType(this.name); case IJavaElement.TYPE: return ((IType) primaryParent).getType(this.name); case IJavaElement.FIELD: case IJavaElement.INITIALIZER: case IJavaElement.METHOD: return ((IMember) primaryParent).getType(this.name, this.occurrenceCount); } return this; }
From source file:com.codenvy.ide.ext.java.server.internal.core.SourceType.java
License:Open Source License
/** * @see org.eclipse.jdt.core.IType#isLocal() *///from w ww . ja va 2 s . c o m public boolean isLocal() { switch (this.parent.getElementType()) { case IJavaElement.METHOD: case IJavaElement.INITIALIZER: case IJavaElement.FIELD: return true; default: return false; } }
From source file:com.codenvy.ide.ext.java.server.internal.core.util.ASTNodeFinder.java
License:Open Source License
public TypeDeclaration findType(IType typeHandle) { IJavaElement parent = typeHandle.getParent(); final char[] typeName = typeHandle.getElementName().toCharArray(); final int occurenceCount = ((SourceType) typeHandle).occurrenceCount; final boolean findAnonymous = typeName.length == 0; class Visitor extends ASTVisitor { TypeDeclaration result;//from www . j a va 2s . c o m int count = 0; public boolean visit(TypeDeclaration typeDeclaration, BlockScope scope) { if (this.result != null) return false; if ((typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) { if (findAnonymous && ++this.count == occurenceCount) { this.result = typeDeclaration; } } else { if (!findAnonymous && CharOperation.equals(typeName, typeDeclaration.name)) { this.result = typeDeclaration; } } return false; // visit only one level } } switch (parent.getElementType()) { case IJavaElement.COMPILATION_UNIT: TypeDeclaration[] types = this.unit.types; if (types != null) { for (int i = 0, length = types.length; i < length; i++) { TypeDeclaration type = types[i]; if (CharOperation.equals(typeName, type.name)) { return type; } } } break; case IJavaElement.TYPE: TypeDeclaration parentDecl = findType((IType) parent); if (parentDecl == null) return null; types = parentDecl.memberTypes; if (types != null) { for (int i = 0, length = types.length; i < length; i++) { TypeDeclaration type = types[i]; if (CharOperation.equals(typeName, type.name)) { return type; } } } break; case IJavaElement.FIELD: FieldDeclaration fieldDecl = findField((IField) parent); if (fieldDecl == null) return null; Visitor visitor = new Visitor(); fieldDecl.traverse(visitor, null); return visitor.result; case IJavaElement.INITIALIZER: Initializer initializer = findInitializer((IInitializer) parent); if (initializer == null) return null; visitor = new Visitor(); initializer.traverse(visitor, null); return visitor.result; case IJavaElement.METHOD: AbstractMethodDeclaration methodDecl = findMethod((IMethod) parent); if (methodDecl == null) return null; visitor = new Visitor(); methodDecl.traverse(visitor, (ClassScope) null); return visitor.result; } return null; }
From source file:com.codenvy.ide.ext.java.server.internal.core.util.HandleFactory.java
License:Open Source License
/** * Create handle by adding child to parent obtained by recursing into parent scopes. *///from ww w .ja va 2 s. c o m private IJavaElement createElement(Scope scope, int elementPosition, ICompilationUnit unit, HashSet existingElements, HashMap knownScopes) { IJavaElement newElement = (IJavaElement) knownScopes.get(scope); if (newElement != null) return newElement; switch (scope.kind) { case Scope.COMPILATION_UNIT_SCOPE: newElement = unit; break; case Scope.CLASS_SCOPE: IJavaElement parentElement = createElement(scope.parent, elementPosition, unit, existingElements, knownScopes); switch (parentElement.getElementType()) { case IJavaElement.COMPILATION_UNIT: newElement = ((ICompilationUnit) parentElement) .getType(new String(scope.enclosingSourceType().sourceName)); break; case IJavaElement.TYPE: newElement = ((IType) parentElement).getType(new String(scope.enclosingSourceType().sourceName)); break; case IJavaElement.FIELD: case IJavaElement.INITIALIZER: case IJavaElement.METHOD: IMember member = (IMember) parentElement; if (member.isBinary()) { return null; } else { newElement = member.getType(new String(scope.enclosingSourceType().sourceName), 1); // increment occurrence count if collision is detected if (newElement != null) { while (!existingElements.add(newElement)) ((SourceRefElement) newElement).occurrenceCount++; } } break; } if (newElement != null) { knownScopes.put(scope, newElement); } break; case Scope.METHOD_SCOPE: IType parentType = (IType) createElement(scope.parent, elementPosition, unit, existingElements, knownScopes); MethodScope methodScope = (MethodScope) scope; if (methodScope.isInsideInitializer()) { // inside field or initializer, must find proper one TypeDeclaration type = methodScope.referenceType(); int occurenceCount = 1; int length = type.fields == null ? 0 : type.fields.length; for (int i = 0; i < length; i++) { FieldDeclaration field = type.fields[i]; if (field.declarationSourceStart <= elementPosition && elementPosition <= field.declarationSourceEnd) { switch (field.getKind()) { case AbstractVariableDeclaration.FIELD: case AbstractVariableDeclaration.ENUM_CONSTANT: newElement = parentType.getField(new String(field.name)); break; case AbstractVariableDeclaration.INITIALIZER: newElement = parentType.getInitializer(occurenceCount); break; } break; } else if (field.getKind() == AbstractVariableDeclaration.INITIALIZER) { occurenceCount++; } } } else { // method element AbstractMethodDeclaration method = methodScope.referenceMethod(); newElement = parentType.getMethod(new String(method.selector), Util.typeParameterSignatures(method)); if (newElement != null) { knownScopes.put(scope, newElement); } } break; case Scope.BLOCK_SCOPE: // standard block, no element per se newElement = createElement(scope.parent, elementPosition, unit, existingElements, knownScopes); break; } return newElement; }