List of usage examples for org.eclipse.jdt.internal.compiler.lookup MethodBinding original
public MethodBinding original()
From source file:com.codenvy.ide.ext.java.server.internal.codeassist.SelectionEngine.java
License:Open Source License
private void selectFrom(Binding binding, CompilationUnitDeclaration parsedUnit, ICompilationUnit unit, boolean isDeclaration) { if (binding instanceof TypeVariableBinding) { TypeVariableBinding typeVariableBinding = (TypeVariableBinding) binding; Binding enclosingElement = typeVariableBinding.declaringElement; this.noProposal = false; if (enclosingElement instanceof SourceTypeBinding) { SourceTypeBinding enclosingType = (SourceTypeBinding) enclosingElement; if (isLocal(enclosingType) && this.requestor instanceof SelectionRequestor) { ((SelectionRequestor) this.requestor).acceptLocalTypeParameter(typeVariableBinding); } else { this.requestor.acceptTypeParameter(enclosingType.qualifiedPackageName(), enclosingType.qualifiedSourceName(), typeVariableBinding.sourceName(), false, this.actualSelectionStart, this.actualSelectionEnd); }/*from www .j av a 2 s.c o m*/ } else if (enclosingElement instanceof MethodBinding) { MethodBinding enclosingMethod = (MethodBinding) enclosingElement; if (isLocal(enclosingMethod.declaringClass) && this.requestor instanceof SelectionRequestor) { ((SelectionRequestor) this.requestor).acceptLocalMethodTypeParameter(typeVariableBinding); } else { this.requestor.acceptMethodTypeParameter(enclosingMethod.declaringClass.qualifiedPackageName(), enclosingMethod.declaringClass.qualifiedSourceName(), enclosingMethod.isConstructor() ? enclosingMethod.declaringClass.sourceName() : enclosingMethod.selector, enclosingMethod.sourceStart(), enclosingMethod.sourceEnd(), typeVariableBinding.sourceName(), false, this.actualSelectionStart, this.actualSelectionEnd); } } this.acceptedAnswer = true; } else if (binding instanceof ReferenceBinding) { ReferenceBinding typeBinding = (ReferenceBinding) binding; if (typeBinding instanceof ProblemReferenceBinding) { TypeBinding closestMatch = typeBinding.closestMatch(); if (closestMatch instanceof ReferenceBinding) { typeBinding = (ReferenceBinding) closestMatch; } else { typeBinding = null; } } if (typeBinding == null) return; if (isLocal(typeBinding) && this.requestor instanceof SelectionRequestor) { this.noProposal = false; ((SelectionRequestor) this.requestor).acceptLocalType(typeBinding); } else { this.noProposal = false; this.requestor.acceptType(typeBinding.qualifiedPackageName(), typeBinding.qualifiedSourceName(), typeBinding.modifiers, false, typeBinding.computeUniqueKey(), this.actualSelectionStart, this.actualSelectionEnd); } this.acceptedAnswer = true; } else if (binding instanceof MethodBinding) { MethodBinding methodBinding = getCorrectMethodBinding((MethodBinding) binding); this.noProposal = false; boolean isValuesOrValueOf = false; if (binding instanceof SyntheticMethodBinding) { SyntheticMethodBinding syntheticMethodBinding = (SyntheticMethodBinding) binding; if (syntheticMethodBinding.purpose == SyntheticMethodBinding.EnumValues || syntheticMethodBinding.purpose == SyntheticMethodBinding.EnumValueOf) { isValuesOrValueOf = true; } } if (!isValuesOrValueOf && !methodBinding.isSynthetic()) { TypeBinding[] parameterTypes = methodBinding.original().parameters; int length = parameterTypes.length; char[][] parameterPackageNames = new char[length][]; char[][] parameterTypeNames = new char[length][]; String[] parameterSignatures = new String[length]; for (int i = 0; i < length; i++) { parameterPackageNames[i] = parameterTypes[i].qualifiedPackageName(); parameterTypeNames[i] = parameterTypes[i].qualifiedSourceName(); parameterSignatures[i] = new String(getSignature(parameterTypes[i])).replace('/', '.'); } TypeVariableBinding[] typeVariables = methodBinding.original().typeVariables; length = typeVariables == null ? 0 : typeVariables.length; char[][] typeParameterNames = new char[length][]; char[][][] typeParameterBoundNames = new char[length][][]; for (int i = 0; i < length; i++) { TypeVariableBinding typeVariable = typeVariables[i]; typeParameterNames[i] = typeVariable.sourceName; if (typeVariable.firstBound == null) { typeParameterBoundNames[i] = new char[0][]; } else if (TypeBinding.equalsEquals(typeVariable.firstBound, typeVariable.superclass)) { int boundCount = 1 + (typeVariable.superInterfaces == null ? 0 : typeVariable.superInterfaces.length); typeParameterBoundNames[i] = new char[boundCount][]; typeParameterBoundNames[i][0] = typeVariable.superclass.sourceName; for (int j = 1; j < boundCount; j++) { typeParameterBoundNames[i][j] = typeVariables[i].superInterfaces[j - 1].sourceName; } } else { int boundCount = typeVariable.superInterfaces == null ? 0 : typeVariable.superInterfaces.length; typeParameterBoundNames[i] = new char[boundCount][]; for (int j = 0; j < boundCount; j++) { typeParameterBoundNames[i][j] = typeVariables[i].superInterfaces[j].sourceName; } } } ReferenceBinding declaringClass = methodBinding.declaringClass; if (isLocal(declaringClass) && this.requestor instanceof SelectionRequestor) { ((SelectionRequestor) this.requestor).acceptLocalMethod(methodBinding); } else { this.requestor.acceptMethod(declaringClass.qualifiedPackageName(), declaringClass.qualifiedSourceName(), declaringClass.enclosingType() == null ? null : new String(getSignature(declaringClass.enclosingType())), methodBinding.isConstructor() ? declaringClass.sourceName() : methodBinding.selector, parameterPackageNames, parameterTypeNames, parameterSignatures, typeParameterNames, typeParameterBoundNames, methodBinding.isConstructor(), isDeclaration, methodBinding.computeUniqueKey(), this.actualSelectionStart, this.actualSelectionEnd); } } this.acceptedAnswer = true; } else if (binding instanceof FieldBinding) { FieldBinding fieldBinding = (FieldBinding) binding; ReferenceBinding declaringClass = fieldBinding.declaringClass; if (declaringClass != null) { // arraylength this.noProposal = false; if (isLocal(declaringClass) && this.requestor instanceof SelectionRequestor) { ((SelectionRequestor) this.requestor).acceptLocalField(fieldBinding); } else { // if the binding is a problem field binding, we want to make sure // we can retrieve the closestMatch if the problem reason is NotVisible FieldBinding currentFieldBinding = fieldBinding; while (currentFieldBinding instanceof ProblemFieldBinding) { ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) currentFieldBinding; if (problemFieldBinding.problemId() == ProblemReasons.NotVisible) { currentFieldBinding = problemFieldBinding.closestMatch; } else { currentFieldBinding = null; } } char[] fieldName = null; char[] key = null; if (currentFieldBinding != null) { fieldName = currentFieldBinding.name; key = currentFieldBinding.computeUniqueKey(); } else { fieldName = fieldBinding.name; key = fieldBinding.computeUniqueKey(); } this.requestor.acceptField(declaringClass.qualifiedPackageName(), declaringClass.qualifiedSourceName(), fieldName, false, key, this.actualSelectionStart, this.actualSelectionEnd); } this.acceptedAnswer = true; } } else if (binding instanceof LocalVariableBinding) { if (this.requestor instanceof SelectionRequestor) { ((SelectionRequestor) this.requestor).acceptLocalVariable((LocalVariableBinding) binding, unit); this.acceptedAnswer = true; } else { // open on the type of the variable selectFrom(((LocalVariableBinding) binding).type, parsedUnit, false); } } else if (binding instanceof ArrayBinding) { selectFrom(((ArrayBinding) binding).leafComponentType, parsedUnit, false); // open on the type of the array } else if (binding instanceof PackageBinding) { PackageBinding packageBinding = (PackageBinding) binding; this.noProposal = false; this.requestor.acceptPackage(packageBinding.readableName()); this.acceptedAnswer = true; } else if (binding instanceof BaseTypeBinding) { this.acceptedAnswer = true; } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.ConstructorLocator.java
License:Open Source License
public int resolveLevel(Binding binding) { if (binding == null) return INACCURATE_MATCH; if (!(binding instanceof MethodBinding)) return IMPOSSIBLE_MATCH; MethodBinding constructor = (MethodBinding) binding; int level = matchConstructor(constructor); if (level == IMPOSSIBLE_MATCH) { if (constructor != constructor.original()) { level = matchConstructor(constructor.original()); }/* ww w .j ava 2 s .c om*/ } return level; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodLocator.java
License:Open Source License
protected void reportDeclaration(MethodBinding methodBinding, MatchLocator locator, SimpleSet knownMethods) throws CoreException { ReferenceBinding declaringClass = methodBinding.declaringClass; IType type = locator.lookupType(declaringClass); if (type == null) return; // case of a secondary type // Report match for binary if (type.isBinary()) { IMethod method = null;//from w w w . jav a2s.c om TypeBinding[] parameters = methodBinding.original().parameters; int parameterLength = parameters.length; char[][] parameterTypes = new char[parameterLength][]; for (int i = 0; i < parameterLength; i++) { char[] typeName = parameters[i].qualifiedSourceName(); for (int j = 0, dim = parameters[i].dimensions(); j < dim; j++) { typeName = CharOperation.concat(typeName, new char[] { '[', ']' }); } parameterTypes[i] = typeName; } method = locator.createBinaryMethodHandle(type, methodBinding.selector, parameterTypes); if (method == null || knownMethods.addIfNotIncluded(method) == null) return; IResource resource = type.getResource(); if (resource == null) resource = type.getJavaProject().getProject(); IBinaryType info = locator.getBinaryInfo((org.eclipse.jdt.internal.core.ClassFile) type.getClassFile(), resource); locator.reportBinaryMemberDeclaration(resource, method, methodBinding, info, SearchMatch.A_ACCURATE); return; } // When source is available, report match if method is found in the declaring type IResource resource = type.getResource(); if (declaringClass instanceof ParameterizedTypeBinding) declaringClass = ((ParameterizedTypeBinding) declaringClass).genericType(); ClassScope scope = ((SourceTypeBinding) declaringClass).scope; if (scope != null) { TypeDeclaration typeDecl = scope.referenceContext; AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(methodBinding.original()); if (methodDecl != null) { // Create method handle from method declaration String methodName = new String(methodBinding.selector); Argument[] arguments = methodDecl.arguments; int length = arguments == null ? 0 : arguments.length; String[] parameterTypes = new String[length]; for (int i = 0; i < length; i++) { char[][] typeName = arguments[i].type.getParameterizedTypeName(); parameterTypes[i] = Signature.createTypeSignature(CharOperation.concatWith(typeName, '.'), false); } IMethod method = type.getMethod(methodName, parameterTypes); if (method == null || knownMethods.addIfNotIncluded(method) == null) return; // Create and report corresponding match int offset = methodDecl.sourceStart; this.match = new MethodDeclarationMatch(method, SearchMatch.A_ACCURATE, offset, methodDecl.sourceEnd - offset + 1, locator.getParticipant(), resource); locator.report(this.match); } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodLocator.java
License:Open Source License
public int resolveLevel(Binding binding) { if (binding == null) return INACCURATE_MATCH; if (!(binding instanceof MethodBinding)) return IMPOSSIBLE_MATCH; MethodBinding method = (MethodBinding) binding; boolean skipVerif = this.pattern.findDeclarations && this.mayBeGeneric; int methodLevel = matchMethod(method, skipVerif); if (methodLevel == IMPOSSIBLE_MATCH) { if (method != method.original()) methodLevel = matchMethod(method.original(), skipVerif); if (methodLevel == IMPOSSIBLE_MATCH) { return IMPOSSIBLE_MATCH; } else {// www. j a v a 2 s . c om method = method.original(); } } // declaring type if (this.pattern.declaringSimpleName == null && this.pattern.declaringQualification == null) return methodLevel; // since any declaring class will do boolean subType = !method.isStatic() && !method.isPrivate(); if (subType && this.pattern.declaringQualification != null && method.declaringClass != null && method.declaringClass.fPackage != null) { subType = CharOperation.compareWith(this.pattern.declaringQualification, method.declaringClass.fPackage.shortReadableName()) == 0; } int declaringLevel = subType ? resolveLevelAsSubtype(this.pattern.declaringSimpleName, this.pattern.declaringQualification, method.declaringClass, method.selector, null, method.declaringClass.qualifiedPackageName(), method.isDefault()) : resolveLevelForType(this.pattern.declaringSimpleName, this.pattern.declaringQualification, method.declaringClass); return (methodLevel & MATCH_LEVEL_MASK) > (declaringLevel & MATCH_LEVEL_MASK) ? declaringLevel : methodLevel; // return the weaker match }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodLocator.java
License:Open Source License
protected int resolveLevel(MessageSend messageSend) { MethodBinding method = messageSend.binding; if (method == null) { return INACCURATE_MATCH; }//ww w.java 2 s .c o m if (messageSend.resolvedType == null) { // Closest match may have different argument numbers when ProblemReason is NotFound // see MessageSend#resolveType(BlockScope) // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=97322 int argLength = messageSend.arguments == null ? 0 : messageSend.arguments.length; if (this.pattern.parameterSimpleNames == null || argLength == this.pattern.parameterSimpleNames.length) { return INACCURATE_MATCH; } return IMPOSSIBLE_MATCH; } int methodLevel = matchMethod(method, false); if (methodLevel == IMPOSSIBLE_MATCH) { if (method != method.original()) methodLevel = matchMethod(method.original(), false); if (methodLevel == IMPOSSIBLE_MATCH) return IMPOSSIBLE_MATCH; method = method.original(); } // receiver type if (this.pattern.declaringSimpleName == null && this.pattern.declaringQualification == null) return methodLevel; // since any declaring class will do int declaringLevel; if (isVirtualInvoke(method, messageSend) && (messageSend.actualReceiverType instanceof ReferenceBinding)) { ReferenceBinding methodReceiverType = (ReferenceBinding) messageSend.actualReceiverType; declaringLevel = resolveLevelAsSubtype(this.pattern.declaringSimpleName, this.pattern.declaringQualification, methodReceiverType, method.selector, method.parameters, methodReceiverType.qualifiedPackageName(), method.isDefault()); if (declaringLevel == IMPOSSIBLE_MATCH) { if (method.declaringClass == null || this.allSuperDeclaringTypeNames == null) { declaringLevel = INACCURATE_MATCH; } else { char[][][] superTypeNames = (method.isDefault() && this.pattern.focus == null) ? this.samePkgSuperDeclaringTypeNames : this.allSuperDeclaringTypeNames; if (superTypeNames != null && resolveLevelAsSuperInvocation(methodReceiverType, method.parameters, superTypeNames, true)) { declaringLevel = methodLevel // since this is an ACCURATE_MATCH so return the possibly weaker match | SUPER_INVOCATION_FLAVOR; // this is an overridden method => add flavor to returned level } } } if ((declaringLevel & FLAVORS_MASK) != 0) { // level got some flavors => return it return declaringLevel; } } else { declaringLevel = resolveLevelForType(this.pattern.declaringSimpleName, this.pattern.declaringQualification, method.declaringClass); } return (methodLevel & MATCH_LEVEL_MASK) > (declaringLevel & MATCH_LEVEL_MASK) ? declaringLevel : methodLevel; // return the weaker match }
From source file:com.google.gwt.dev.jjs.impl.ReferenceMapper.java
License:Apache License
public JMethod get(MethodBinding binding) { binding = binding.original(); String key = JdtUtil.signature(binding); JMethod sourceMethod = sourceMethods.get(key); if (sourceMethod != null) { assert !sourceMethod.isExternal(); return sourceMethod; }//from w w w .ja v a 2 s . c om JMethod method = methods.get(key); if (method == null) { if (binding.isConstructor()) { method = createConstructor(SourceOrigin.UNKNOWN, binding); } else { method = createMethod(SourceOrigin.UNKNOWN, binding, null); } assert binding instanceof SyntheticMethodBinding || method.isExternal(); methods.put(key, method); } return method; }
From source file:io.gige.compiler.internal.HackElements.java
License:Apache License
@Override public Map<? extends ExecutableElement, ? extends AnnotationValue> getElementValuesWithDefaults( AnnotationMirror a) {/*www . j a va 2 s . c o m*/ Map<? extends ExecutableElement, ? extends AnnotationValue> map = super.getElementValuesWithDefaults(a); if (a instanceof AnnotationMirrorImpl) { AnnotationMirrorImpl impl = (AnnotationMirrorImpl) a; ReferenceBinding annoType = impl._binding.getAnnotationType(); for (MethodBinding method : annoType.methods()) { MethodBinding originalMethod = method.original(); AbstractMethodDeclaration methodDeclaration = originalMethod.sourceMethod(); if (methodDeclaration instanceof AnnotationMethodDeclaration) { AnnotationMethodDeclaration amd = (AnnotationMethodDeclaration) methodDeclaration; Expression exp = amd.defaultValue; if (exp instanceof QualifiedNameReference) { QualifiedNameReference qae = (QualifiedNameReference) exp; qae.bits |= ASTNode.RestrictiveFlagMASK; } } } } return map; }
From source file:lombok.eclipse.agent.ExtensionMethodCompletionProposal.java
License:Open Source License
public void setMethodBinding(final MethodBinding method, final ASTNode node) { MethodBinding original = method.original(); TypeBinding[] parameters = Arrays.copyOf(method.parameters, method.parameters.length); method.parameters = Arrays.copyOfRange(method.parameters, 1, method.parameters.length); TypeBinding[] originalParameters = null; if (original != method) { originalParameters = Arrays.copyOf(method.original().parameters, method.original().parameters.length); method.original().parameters = Arrays.copyOfRange(method.original().parameters, 1, method.original().parameters.length); }// w w w . java 2 s .c om int length = method.parameters == null ? 0 : method.parameters.length; char[][] parameterPackageNames = new char[length][]; char[][] parameterTypeNames = new char[length][]; for (int i = 0; i < length; i++) { TypeBinding type = method.original().parameters[i]; parameterPackageNames[i] = type.qualifiedPackageName(); parameterTypeNames[i] = type.qualifiedSourceName(); } char[] completion = CharOperation.concat(method.selector, new char[] { '(', ')' }); setDeclarationSignature(CompletionEngine.getSignature(method.declaringClass)); setSignature(CompletionEngine.getSignature(method)); if (original != method) { setOriginalSignature(CompletionEngine.getSignature(original)); } setDeclarationPackageName(method.declaringClass.qualifiedPackageName()); setDeclarationTypeName(method.declaringClass.qualifiedSourceName()); setParameterPackageNames(parameterPackageNames); setParameterTypeNames(parameterTypeNames); setPackageName(method.returnType.qualifiedPackageName()); setTypeName(method.returnType.qualifiedSourceName()); setName(method.selector); setCompletion(completion); setFlags(method.modifiers & (~AccStatic)); int index = node.sourceEnd + 1; if (node instanceof CompletionOnQualifiedNameReference) { index -= ((CompletionOnQualifiedNameReference) node).completionIdentifier.length; } if (node instanceof CompletionOnMemberAccess) { index -= ((CompletionOnMemberAccess) node).token.length; } if (node instanceof CompletionOnSingleNameReference) { index -= ((CompletionOnSingleNameReference) node).token.length; } setReplaceRange(index, index); setTokenRange(index, index); setRelevance(100); method.parameters = parameters; if (original != method) { method.original().parameters = originalParameters; } }
From source file:org.conqat.engine.java.ecj.EcjUtils.java
License:Apache License
/** * Constructs a String representation of the given MethodBinding. The * notation is <declaringClassFQN>#<method signature>. *//*from w w w .j a v a2 s . c om*/ public static String methodBindingToString(MethodBinding methodBinding) { MethodBinding original = methodBinding.original(); ReferenceBinding declaringClass = original.declaringClass; return getFullQualifiedClassName(declaringClass) + "#" + new String(original.readableName()); }
From source file:org.conqat.engine.java.ecj.JavaMethodCallAnalyzerBase.java
License:Apache License
/** Process a method call */ private void process(MethodBinding binding, IJavaElement javaElement) { ReferenceBinding declaringClass = binding.original().declaringClass; String fqn = EcjUtils.getFullQualifiedClassName(declaringClass); if (declaringClassPatternList == null || declaringClassPatternList.emptyOrMatchesAny(fqn)) { processMethodCall(binding, javaElement); }// w w w . j ava 2s . com }