List of usage examples for org.eclipse.jdt.internal.compiler.lookup MethodScope referenceMethodBinding
public MethodBinding referenceMethodBinding()
From source file:com.android.tools.lint.psi.EcjPsiManager.java
License:Apache License
@Nullable public PsiElement findElement(@Nullable Binding binding) { if (binding == null) { return null; }/*from w ww.j a v a 2 s .c o m*/ PsiElement element = mElementMap.get(binding); if (element != null) { return element; } if (binding instanceof ProblemReferenceBinding) { binding = ((ProblemReferenceBinding) binding).closestReferenceMatch(); if (binding != null) { return findElement(binding); } else { return null; } } if (binding instanceof WildcardBinding) { return findElement(((WildcardBinding) binding).actualType()); } if (binding instanceof ParameterizedTypeBinding) { TypeBinding typeBinding = ((ParameterizedTypeBinding) binding).original(); element = mElementMap.get(typeBinding); //noinspection PointlessBooleanExpression if (!RESOLVE_TO_BINARY && element == null && typeBinding != null && typeBinding.actualType() instanceof SourceTypeBinding) { return null; } return findElement(typeBinding); } if (binding instanceof ParameterizedMethodBinding) { ParameterizedMethodBinding methodBinding = (ParameterizedMethodBinding) binding; binding = methodBinding.original(); element = mElementMap.get(binding); //noinspection PointlessBooleanExpression if (!RESOLVE_TO_BINARY && element == null && methodBinding.isConstructor() && methodBinding.declaringClass != null && methodBinding.declaringClass.actualType() instanceof SourceTypeBinding) { // It's a local binding but there's no actual constructor there // (it's the default constructor) return null; } return findElement(binding); } if (binding instanceof ParameterizedFieldBinding) { ParameterizedFieldBinding fieldBinding = (ParameterizedFieldBinding) binding; binding = fieldBinding.original(); element = mElementMap.get(binding); //noinspection PointlessBooleanExpression if (!RESOLVE_TO_BINARY && element == null && fieldBinding.declaringClass != null && fieldBinding.declaringClass.actualType() instanceof SourceTypeBinding) { // It's a local binding but there's no actual constructor there // (it's the default constructor) return null; } return findElement(binding); } // No binding in map yet: the PSI file may not have been parsed yet. Attempt // to initialize these: if (binding instanceof FieldBinding) { ReferenceBinding declaringClass = ((FieldBinding) binding).declaringClass; if (declaringClass instanceof SourceTypeBinding) { PsiJavaFile file = mEcjResult.findFileContaining(declaringClass); //noinspection VariableNotUsedInsideIf if (file != null) { element = mElementMap.get(binding); if (element != null) { return element; } } } } else if (binding instanceof MethodBinding) { ReferenceBinding declaringClass = ((MethodBinding) binding).declaringClass; if (declaringClass instanceof SourceTypeBinding) { PsiJavaFile file = mEcjResult.findFileContaining(declaringClass); //noinspection VariableNotUsedInsideIf if (file != null) { element = mElementMap.get(binding); if (element != null) { return element; } } } } // Binary references. Computed on the fly for now since they are lightweight. if (binding instanceof MethodBinding) { MethodBinding methodBinding = (MethodBinding) binding; // Default constructor? Allow binding to binary! if (methodBinding.isConstructor() && (methodBinding.parameters == null || methodBinding.parameters.length == 0)) { return new EcjPsiBinaryMethod(this, methodBinding); } //noinspection PointlessBooleanExpression if (!RESOLVE_TO_BINARY && methodBinding.declaringClass instanceof SourceTypeBinding) { return null; } return new EcjPsiBinaryMethod(this, methodBinding); } else if (binding instanceof ReferenceBinding) { ReferenceBinding referenceBinding = (ReferenceBinding) binding; if (referenceBinding.compoundName == null) { // For example, TypeVariableBindings return null; } return new EcjPsiBinaryClass(this, referenceBinding); } else if (binding instanceof FieldBinding) { FieldBinding fieldBinding = (FieldBinding) binding; //noinspection PointlessBooleanExpression if (!RESOLVE_TO_BINARY && fieldBinding.declaringClass instanceof SourceTypeBinding) { return null; } return new EcjPsiBinaryField(this, fieldBinding); } else { // Search in AST, e.g. to resolve local variables etc if (binding instanceof LocalVariableBinding) { LocalVariableBinding lvb = (LocalVariableBinding) binding; Scope scope = lvb.declaringScope; while (scope != null) { if (scope instanceof MethodScope) { MethodScope methodScope = (MethodScope) scope; MethodBinding methodBinding = methodScope.referenceMethodBinding(); if (methodBinding != null) { PsiElement method = mElementMap.get(methodBinding); if (method != null) { PsiElement declaration = findElementWithBinding(method, lvb); if (declaration != null) { return declaration; } } } } scope = scope.parent; } } } return null; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.RoleTypeBinding.java
License:Open Source License
private void initialize(ReferenceBinding roleType, ITeamAnchor teamAnchor) { // FIXME(SH): is it OK to strip ParameterizedFields? if (teamAnchor instanceof ParameterizedFieldBinding) teamAnchor = ((ParameterizedFieldBinding) teamAnchor).original(); initializeDependentType(teamAnchor, -1); // role type bindings have no explicit value parameters // infer argument position. ITeamAnchor firstAnchorSegment = teamAnchor.getBestNamePath()[0]; if (firstAnchorSegment instanceof LocalVariableBinding && (((LocalVariableBinding) firstAnchorSegment).tagBits & TagBits.IsArgument) != 0) { LocalVariableBinding argumentBinding = (LocalVariableBinding) firstAnchorSegment; this._argumentPosition = argumentBinding.resolvedPosition; final MethodScope methodScope = argumentBinding.declaringScope.methodScope(); if (methodScope != null) // if scope is a callout, role method may not yet be resolved, defer: this._declaringMethod = new IMethodProvider() { private MethodBinding binding; public MethodBinding getMethod() { if (this.binding == null) this.binding = methodScope.referenceMethodBinding(); return this.binding; }// w ww . java2s . co m }; } // compute the team: if (CharOperation.equals(roleType.compoundName, IOTConstants.ORG_OBJECTTEAMS_TEAM_OTCONFINED)) // the following is needed in order to break the circularity // of roles extending the predefined Team.__OT__Confined (see class comment) this._staticallyKnownTeam = roleType.enclosingType(); else if (teamAnchor == NoAnchor) this._staticallyKnownTeam = roleType.enclosingType(); else teamAnchor.setStaticallyKnownTeam(this); assert (this._staticallyKnownTeam.isTeam()); // compute role class and role interface (by name manipulation): if (RoleSplitter.isClassPartName(roleType.sourceName)) { this._staticallyKnownRoleClass = roleType.getRealClass(); char[] typeName = RoleSplitter.getInterfacePartName(roleType.sourceName); this._staticallyKnownRoleType = this._staticallyKnownTeam.getMemberType(typeName); } else { this._staticallyKnownRoleType = roleType.getRealType(); char[] className = CharOperation.concat(OT_DELIM_NAME, this._staticallyKnownRoleType.sourceName); this._staticallyKnownRoleClass = this._staticallyKnownTeam.getMemberType(className); this._staticallyKnownRoleClass = transferTypeArguments(this._staticallyKnownRoleClass); } this._staticallyKnownRoleType = transferTypeArguments(this._staticallyKnownRoleType); this._declaredRoleType = this._staticallyKnownRoleType; // keep these consistent with _declaredRoleType: this.roleModel = this._declaredRoleType.roleModel; this._teamModel = this._declaredRoleType.getTeamModel(); assert TypeBinding.equalsEquals(this._staticallyKnownTeam.getRealClass(), roleType.enclosingType()) : "weakening not using WeakenedTypeBinding"; //$NON-NLS-1$ // some adjustments after all fields are known: if (TypeBinding.notEquals(this._staticallyKnownTeam, roleType.enclosingType())) this._staticallyKnownRoleType = this._staticallyKnownTeam.getMemberType(roleType.sourceName); if (this._staticallyKnownRoleClass != null) this.modifiers = this._staticallyKnownRoleClass.modifiers; // after we might have overwritten the modifiers restore some bits in the vein of ParameterizedTypeBinding: if (this.arguments != null) { this.modifiers |= ExtraCompilerModifiers.AccGenericSignature; } else if (this.enclosingType() != null) { this.modifiers |= (this.enclosingType().modifiers & ExtraCompilerModifiers.AccGenericSignature); this.tagBits |= this.enclosingType().tagBits & (TagBits.HasTypeVariable | TagBits.HasMissingType); } // record as known role type at teamAnchor and in our own cache registerAnchor(); }