List of usage examples for org.eclipse.jdt.internal.compiler.lookup ReferenceBinding getMemberType
public ReferenceBinding getMemberType(char[] typeName)
From source file:com.codenvy.ide.ext.java.server.internal.codeassist.impl.Engine.java
License:Open Source License
protected boolean mustQualifyType(char[] packageName, char[] typeName, char[] enclosingTypeNames, int modifiers) { // If there are no types defined into the current CU yet. if (this.unitScope == null) return true; if (!this.importCachesInitialized) { initializeImportCaches();/*from w ww . ja va 2 s. c o m*/ } for (int i = 0; i < this.importCacheCount; i++) { char[][] importName = this.importsCache[i]; if (CharOperation.equals(typeName, importName[0])) { char[] fullyQualifiedTypeName = enclosingTypeNames == null || enclosingTypeNames.length == 0 ? CharOperation.concat(packageName, typeName, '.') : CharOperation.concat(CharOperation.concat(packageName, enclosingTypeNames, '.'), typeName, '.'); return !CharOperation.equals(fullyQualifiedTypeName, importName[1]); } } if ((enclosingTypeNames == null || enclosingTypeNames.length == 0) && CharOperation.equals(this.currentPackageName, packageName)) return false; char[] fullyQualifiedEnclosingTypeName = null; for (int i = 0; i < this.onDemandImportCacheCount; i++) { ImportBinding importBinding = this.onDemandImportsCache[i]; Binding resolvedImport = importBinding.resolvedImport; char[][] importName = importBinding.compoundName; char[] importFlatName = CharOperation.concatWith(importName, '.'); boolean isFound = false; // resolvedImport is a ReferenceBindng or a PackageBinding if (resolvedImport instanceof ReferenceBinding) { if (enclosingTypeNames != null && enclosingTypeNames.length != 0) { if (fullyQualifiedEnclosingTypeName == null) { fullyQualifiedEnclosingTypeName = CharOperation.concat(packageName, enclosingTypeNames, '.'); } if (CharOperation.equals(fullyQualifiedEnclosingTypeName, importFlatName)) { if (importBinding.isStatic()) { isFound = (modifiers & ClassFileConstants.AccStatic) != 0; } else { isFound = true; } } } } else { if (enclosingTypeNames == null || enclosingTypeNames.length == 0) { if (CharOperation.equals(packageName, importFlatName)) { if (importBinding.isStatic()) { isFound = (modifiers & ClassFileConstants.AccStatic) != 0; } else { isFound = true; } } } } // find potential conflict with another import if (isFound) { for (int j = 0; j < this.onDemandImportCacheCount; j++) { if (i != j) { ImportBinding conflictingImportBinding = this.onDemandImportsCache[j]; if (conflictingImportBinding.resolvedImport instanceof ReferenceBinding) { ReferenceBinding refBinding = (ReferenceBinding) conflictingImportBinding.resolvedImport; if (refBinding.getMemberType(typeName) != null) { return true; } } else { char[] conflictingImportName = CharOperation .concatWith(conflictingImportBinding.compoundName, '.'); if (this.nameEnvironment.nameLookup.findType(String.valueOf(typeName), String.valueOf(conflictingImportName), false, NameLookup.ACCEPT_ALL, false/*don't check restrictions*/) != null) { return true; } } } } return false; } } return true; }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
public ReferenceBinding findDirectMemberType(char[] typeName, ReferenceBinding enclosingType) { if ((enclosingType.tagBits & TagBits.HasNoMemberTypes) != 0) return null; // know it has no member types (nor inherited member types) ReferenceBinding enclosingReceiverType = enclosingReceiverType(); CompilationUnitScope unitScope = compilationUnitScope(); unitScope.recordReference(enclosingType, typeName); ReferenceBinding memberType = enclosingType.getMemberType(typeName); if (memberType != null) { unitScope.recordTypeReference(memberType); if (enclosingReceiverType == null) { if (memberType.canBeSeenBy(getCurrentPackage())) { return memberType; }// www . j a va 2s. c om // maybe some type in the compilation unit is extending some class in some package // and the selection is for some protected inner class of that superclass // https://bugs.eclipse.org/bugs/show_bug.cgi?id=235658 if (this instanceof CompilationUnitScope) { TypeDeclaration[] types = ((CompilationUnitScope) this).referenceContext.types; if (types != null) { for (int i = 0, max = types.length; i < max; i++) { if (memberType.canBeSeenBy(enclosingType, types[i].binding)) { return memberType; } } } } } else if (memberType.canBeSeenBy(enclosingType, enclosingReceiverType)) { return memberType; } return new ProblemReferenceBinding(new char[][] { typeName }, memberType, ProblemReasons.NotVisible); } return null; }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
public ReferenceBinding findMemberType(char[] typeName, ReferenceBinding enclosingType) { if ((enclosingType.tagBits & TagBits.HasNoMemberTypes) != 0) return null; // know it has no member types (nor inherited member types) ReferenceBinding enclosingSourceType = enclosingSourceType(); PackageBinding currentPackage = getCurrentPackage(); CompilationUnitScope unitScope = compilationUnitScope(); unitScope.recordReference(enclosingType, typeName); ReferenceBinding memberType = enclosingType.getMemberType(typeName); if (memberType != null) { unitScope.recordTypeReference(memberType); if (enclosingSourceType == null || (this.parent == unitScope && (enclosingSourceType.tagBits & TagBits.TypeVariablesAreConnected) == 0) ? memberType.canBeSeenBy(currentPackage) : memberType.canBeSeenBy(enclosingType, enclosingSourceType)) return memberType; return new ProblemReferenceBinding(new char[][] { typeName }, memberType, ProblemReasons.NotVisible); }/*from ww w . j a v a 2s . co m*/ // collect all superinterfaces of receiverType until the memberType is found in a supertype ReferenceBinding currentType = enclosingType; ReferenceBinding[] interfacesToVisit = null; int nextPosition = 0; ReferenceBinding visibleMemberType = null; boolean keepLooking = true; ReferenceBinding notVisible = null; // we could hold onto the not visible field for extra error reporting while (keepLooking) { ReferenceBinding[] itsInterfaces = currentType.superInterfaces(); if (itsInterfaces == null) { // needed for statically imported types which don't know their hierarchy yet ReferenceBinding sourceType = currentType.isParameterizedType() ? ((ParameterizedTypeBinding) currentType).genericType() : currentType; if (sourceType.isHierarchyBeingConnected()) return null; // looking for an undefined member type in its own superclass ref ((SourceTypeBinding) sourceType).scope.connectTypeHierarchy(); itsInterfaces = currentType.superInterfaces(); } if (itsInterfaces != null && itsInterfaces != Binding.NO_SUPERINTERFACES) { if (interfacesToVisit == null) { interfacesToVisit = itsInterfaces; nextPosition = interfacesToVisit.length; } else { int itsLength = itsInterfaces.length; if (nextPosition + itsLength >= interfacesToVisit.length) System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition); nextInterface: for (int a = 0; a < itsLength; a++) { ReferenceBinding next = itsInterfaces[a]; for (int b = 0; b < nextPosition; b++) if (next == interfacesToVisit[b]) continue nextInterface; interfacesToVisit[nextPosition++] = next; } } } if ((currentType = currentType.superclass()) == null) break; unitScope.recordReference(currentType, typeName); if ((memberType = currentType.getMemberType(typeName)) != null) { unitScope.recordTypeReference(memberType); keepLooking = false; if (enclosingSourceType == null ? memberType.canBeSeenBy(currentPackage) : memberType.canBeSeenBy(enclosingType, enclosingSourceType)) { if (visibleMemberType == null) visibleMemberType = memberType; else return new ProblemReferenceBinding(new char[][] { typeName }, visibleMemberType, ProblemReasons.Ambiguous); } else { notVisible = memberType; } } } // walk all visible interfaces to find ambiguous references if (interfacesToVisit != null) { ProblemReferenceBinding ambiguous = null; done: for (int i = 0; i < nextPosition; i++) { ReferenceBinding anInterface = interfacesToVisit[i]; unitScope.recordReference(anInterface, typeName); if ((memberType = anInterface.getMemberType(typeName)) != null) { unitScope.recordTypeReference(memberType); if (visibleMemberType == null) { visibleMemberType = memberType; } else { ambiguous = new ProblemReferenceBinding(new char[][] { typeName }, visibleMemberType, ProblemReasons.Ambiguous); break done; } } else { ReferenceBinding[] itsInterfaces = anInterface.superInterfaces(); if (itsInterfaces != null && itsInterfaces != Binding.NO_SUPERINTERFACES) { int itsLength = itsInterfaces.length; if (nextPosition + itsLength >= interfacesToVisit.length) System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition); nextInterface: for (int a = 0; a < itsLength; a++) { ReferenceBinding next = itsInterfaces[a]; for (int b = 0; b < nextPosition; b++) if (next == interfacesToVisit[b]) continue nextInterface; interfacesToVisit[nextPosition++] = next; } } } } if (ambiguous != null) return ambiguous; } if (visibleMemberType != null) return visibleMemberType; if (notVisible != null) return new ProblemReferenceBinding(new char[][] { typeName }, notVisible, ProblemReasons.NotVisible); return null; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.PrecedenceDeclaration.java
License:Open Source License
/** * Resolve an element of a precedence declaration. * * @param scope// w ww. j a v a2s . c o m * @param type * @param name * @return either CallinCalloutBinding or ReferenceBinding or null */ private Binding findCallinInType(Scope scope, ReferenceBinding type, char[] name, boolean typeAllowed) { if (type.isRole()) { Binding found = findCallinInRole(type, name); if (found != null) return found; } type = type.getRealClass(); if (type.isTeam()) { ReferenceBinding roleBinding = type.getMemberType(name); if (roleBinding != null) { if (!typeAllowed) { scope.problemReporter().illegalDeepRoleReferenceInPrecedence(this, type, roleBinding); return new ProblemReferenceBinding(name, roleBinding, ProblemReasons.NotVisible); } return roleBinding; } return null; } if (type.isRole()) return null; // tried before, no success. scope.problemReporter().illegalEnclosingForCallinName(this, type, name); return null; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.CallinPrecedenceAttribute.java
License:Open Source License
public void evaluateLateAttribute(ReferenceBinding enclosingType, int state) { if (state != ITranslationStates.STATE_LATE_ATTRIBUTES_EVALUATED) return;/* w w w . j a va2 s . c o m*/ CallinCalloutBinding[] mappings = new CallinCalloutBinding[this.callinNames.length]; for (int i = 0; i < this.callinNames.length; i++) { char[][] parts = CharOperation.splitOn('.', this.callinNames[i]); int j = 0; ReferenceBinding currentType = enclosingType; while (j < parts.length - 1) { currentType = currentType .getMemberType(CharOperation.concat(IOTConstants.OT_DELIM_NAME, parts[j++])); } if (currentType == null) // found in Dehla's error log. throw new InternalCompilerError( "Can't resolve type for precedence declaration " + new String(this.callinNames[i])); //$NON-NLS-1$ CallinCalloutBinding[] callinCallouts = currentType.callinCallouts; if (callinCallouts != null) { for (int k = 0; k < callinCallouts.length; k++) { if (callinCallouts[k].type == CallinCalloutBinding.CALLIN && CharOperation.equals(callinCallouts[k].name, parts[j])) { mappings[i] = callinCallouts[k]; break; } } } if (mappings[i] == null) throw new InternalCompilerError("Precedence attribute has unresolved method mapping"); //$NON-NLS-1$ } int len = enclosingType.precedences.length; if (len == 0) enclosingType.precedences = new PrecedenceBinding[1]; else System.arraycopy(enclosingType.precedences, 0, enclosingType.precedences = new PrecedenceBinding[len + 1], 0, len); enclosingType.precedences[len] = new PrecedenceBinding(enclosingType, mappings); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.OTDynCallinBindingsAttribute.java
License:Open Source License
/** * @param teamBinding where to add created bindings * @param mapping the mapping to reconstruct * @throws InternalCompilerError//from w w w .ja va 2 s . co m */ private static void createBinding(ReferenceBinding teamBinding, Mapping mapping) { ReferenceBinding roleBinding = teamBinding.getMemberType(mapping.roleClassName).getRealClass(); CallinCalloutBinding result = null; CallinCalloutBinding[] callinCallouts = roleBinding.callinCallouts; if (callinCallouts != null) { for (int i = 0; i < callinCallouts.length; i++) { if (CharOperation.equals(mapping.callinName, callinCallouts[i].name)) { // fill in details to existing binding: result = callinCallouts[i]; result.callinModifier = encodeCallinModifier(mapping.callinModifier); break; } } } if (result == null) result = new CallinCalloutBinding(roleBinding, mapping.callinName, encodeCallinModifier(mapping.callinModifier)); BaseMethod[] mappingBaseMethods = mapping.baseMethods; MethodBinding[] baseMethods = new MethodBinding[mappingBaseMethods.length]; ReferenceBinding currentType = roleBinding; char[] roleSignature = mapping.roleSignature; if (result.callinModifier == TerminalTokens.TokenNamereplace) { // ignore generalized return by truncating the signature: int closePos = CharOperation.indexOf(')', roleSignature); if (closePos > -1) roleSignature = CharOperation.subarray(roleSignature, 0, closePos + 1); } roleMethod: while (currentType != null) { MethodBinding[] methods = currentType.getMethods(mapping.roleSelector); for (int j = 0; j < methods.length; j++) { if (CharOperation.prefixEquals(roleSignature, MethodSpec.signature(methods[j], WeavingScheme.OTDRE))) { result._roleMethodBinding = methods[j]; break roleMethod; } } currentType = currentType.superclass(); } if (result._roleMethodBinding == null) throw new InternalCompilerError("role method specified in callin mapping does not exist " + mapping); //$NON-NLS-1$ int callinIdMax = 0; mappingBaseMethods: for (int i = 0; i < mappingBaseMethods.length; i++) { BaseMethod bm = mappingBaseMethods[i]; callinIdMax = Math.max(callinIdMax, bm.callinID); currentType = roleBinding.baseclass(); while (currentType != null) { MethodBinding[] methods = currentType.getMethods(bm.baseMethodName); for (int j = 0; j < methods.length; j++) { if (CharOperation.equals(bm.baseMethodSignature, methods[j].signature())) // TODO(SH): enhancing? / _isCallin? { baseMethods[i] = methods[j]; continue mappingBaseMethods; } } currentType = currentType.superclass(); } baseMethods[i] = new ProblemMethodBinding(bm.baseMethodName, null, roleBinding.baseclass(), ProblemReasons.NotFound); } result._baseMethods = baseMethods; result.callinIdMax = callinIdMax; teamBinding._teamModel.recordCallinId(callinIdMax); result.copyInheritanceSrc = findTSuperBinding(mapping.callinName, roleBinding); roleBinding.addCallinCallouts(new CallinCalloutBinding[] { result }); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.OTDynCallinBindingsAttribute.java
License:Open Source License
/** * Get a copy of this attribute with those bindings filtered out, * that are overridden in the current team. * @param teamBinding filter the attribute for this (sub)team * @return a filtered copy of this attribute or null, if no mappings remain after filtering *///from w w w .jav a 2 s . co m public OTDynCallinBindingsAttribute filteredCopy(ReferenceBinding teamBinding) { List<Mapping> filteredMappings = new ArrayList<Mapping>(); nextMapping: for (Mapping mapping : this.mappings) { if (mapping.callinName[0] != '<') { // only named callins can be overridden ReferenceBinding roleBinding = teamBinding.getMemberType(mapping.roleClassName).getRealClass(); for (CallinCalloutBinding callinCallout : roleBinding.callinCallouts) if (CharOperation.equals(callinCallout.name, mapping.callinName)) continue nextMapping; } // not found means not overridden filteredMappings.add(mapping); } if (filteredMappings.size() == 0) return null; return new OTDynCallinBindingsAttribute(teamBinding._teamModel, filteredMappings); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.TeamAnchor.java
License:Open Source License
public void setStaticallyKnownTeam(RoleTypeBinding rtb) { ReferenceBinding teamBinding = leafReferenceType(); if (teamBinding.isSynthInterface()) { // never use a synth interface as the team of a RTB ReferenceBinding outerTeam = teamBinding.enclosingType(); char[] teamName = CharOperation.concat(IOTConstants.OT_DELIM_NAME, teamBinding.internalName()); teamBinding = outerTeam.getMemberType(teamName); }//from w w w . ja v a 2 s . c o m rtb._staticallyKnownTeam = teamBinding; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.model.TeamModel.java
License:Open Source License
/** * Try to interpret teamCandidate as an enclosing team of roleType. * * @param teamCandidate// ww w .ja v a2 s . c om * @param roleType * @return the number of nesting levels that role type lies within teamCandidate, 0 if no match. */ public static int levelFromEnclosingTeam(ReferenceBinding teamCandidate, ReferenceBinding roleType) { int l = 1; if (teamCandidate == null) return 0; teamCandidate = normalizeTeam(teamCandidate); if (!teamCandidate.isTeam()) return 0; if (!roleType.isRole()) return 0; if (roleType.isParameterizedType()) roleType = ((ParameterizedTypeBinding) roleType).genericType(); ReferenceBinding roleOuter = (ReferenceBinding) roleType.enclosingType().erasure(); if (TypeBinding.equalsEquals(roleOuter, teamCandidate)) return 1; // shortcut if (teamCandidate.isRole()) { ReferenceBinding outerTeam = teamCandidate.enclosingType(); int l2 = levelFromEnclosingTeam(outerTeam, roleOuter); if (l2 > 0) { if (l2 == 1) roleOuter = outerTeam.getMemberType(roleOuter.internalName()); l = l2; } // else nested teamCandidate might extend a non-nested team. } ReferenceBinding member = teamCandidate.getMemberType(roleType.internalName()); if (member == null) { // several levels away, e.g., role nested (anonymous?): if (roleOuter.isRole()) { int l2 = levelFromEnclosingTeam(teamCandidate, roleOuter); if (l2 > 0) return l2 + 1; } return 0; } if (areTypesCompatible(teamCandidate, roleOuter)) return l; return 0; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.model.TeamModel.java
License:Open Source License
/** * Get the most suitable RoleTypeBinding for roleType in a tthis context defined by scope. * Strengthening reverses the effect of signature weakening. * * (Used for determining the statically known role type for lifting) * * @param site (guaranteed to be within the context of a team) * @param roleType (guaranteed to be a role or an array thereof) * @return found role - need not be a RoleTypeBinding *//* w w w .j av a 2 s. c om*/ public static TypeBinding strengthenRoleType(ReferenceBinding site, TypeBinding roleType) { ReferenceBinding enclosingTeam = site; enclosingTeam = normalizeTeam(enclosingTeam); if (!enclosingTeam.isTeam()) enclosingTeam = getEnclosingTeam(site); if (enclosingTeam == null) return roleType; // this site cannot strengthen the role type. if (roleType.isLocalType()) return roleType; int dimensions = roleType.dimensions(); ReferenceBinding roleRefType = (ReferenceBinding) roleType.leafComponentType(); ReferenceBinding roleEnclosing = roleRefType.enclosingType(); if (roleEnclosing.isRole() && TypeBinding.notEquals(roleEnclosing.erasure(), site.erasure())) { // first strengthen enclosing team if it is nested: ReferenceBinding strengthenedEnclosing = null; if (TypeBinding.notEquals(roleEnclosing.erasure().enclosingType(), enclosingTeam.erasure().enclosingType())) strengthenedEnclosing = (ReferenceBinding) strengthenRoleType(site, roleEnclosing); if (strengthenedEnclosing != null && TypeBinding.notEquals(strengthenedEnclosing.erasure(), site.erasure())) { // we indeed found a better site, so start over: return strengthenRoleType(strengthenedEnclosing, roleType); } } // check success: if (!(roleRefType.isRole() // need a role && areCompatibleEnclosings(enclosingTeam, roleEnclosing))) // teams must be compatible { if (enclosingTeam.isRole()) // try via outer team: return strengthenRoleType(enclosingTeam.enclosingType(), roleType); return roleType; } if (roleRefType instanceof RoleTypeBinding) { RoleTypeBinding rtb = (RoleTypeBinding) roleRefType; if (!(rtb._teamAnchor instanceof TThisBinding)) return roleType; // don't instantiate explicit team anchor. } // lookup adjusted role type: roleRefType = enclosingTeam.getMemberType(roleRefType.internalName()); if (roleRefType == null) { if (enclosingTeam.isBinaryBinding()) { ReferenceBinding current = enclosingTeam; // search a role type to report against (for aborting): while (current != null && current.isBinaryBinding()) current = current.enclosingType(); if (current != null) { Scope scope = ((SourceTypeBinding) current).scope; if (scope != null) { scope.problemReporter().missingRoleInBinaryTeam(roleType.constantPoolName(), enclosingTeam); return null; } } } if (Protections.hasClassKindProblem(enclosingTeam)) return roleType; // can't do better.. if (!enclosingTeam.isBinaryBinding()) { Scope scope = ((SourceTypeBinding) enclosingTeam.getRealType()).scope; scope.problemReporter().missingCopiedRole(roleType, enclosingTeam); } else if (!site.isBinaryBinding()) { Scope scope = ((SourceTypeBinding) site.getRealType()).scope; scope.problemReporter().missingCopiedRole(roleType, enclosingTeam); } else { throw new InternalCompilerError("could not find role " + String.valueOf(roleType.constantPoolName()) //$NON-NLS-1$ + " in " + String.valueOf(site.constantPoolName()) + " and could not report regularly"); //$NON-NLS-1$ //$NON-NLS-2$ } return roleType; // can't do better, but shouldn't reach here, because missingCopiedRole triggers AbortType. } VariableBinding anchor = enclosingTeam.getTeamModel().getTThis(); if (roleType.isParameterizedType()) { // consult original role type for type arguments & type annotations: ParameterizedTypeBinding ptb = (ParameterizedTypeBinding) roleType; TypeBinding parameterized = ptb.environment.createParameterizedType(roleRefType, ptb.arguments, anchor, -1, roleRefType.enclosingType(), ptb.getTypeAnnotations()); if (dimensions > 0) return ptb.environment.createArrayType(parameterized, dimensions); return parameterized; } return anchor.getRoleTypeBinding(roleRefType, dimensions); }