List of usage examples for org.eclipse.jdt.internal.compiler.lookup TagBits HierarchyHasProblems
long HierarchyHasProblems
To view the source code for org.eclipse.jdt.internal.compiler.lookup TagBits HierarchyHasProblems.
Click Source Link
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java
License:Open Source License
protected boolean createHierarchyResolver(IType focusType, PossibleMatch[] possibleMatches) { // cache focus type if not a possible match char[][] compoundName = CharOperation.splitOn('.', focusType.getFullyQualifiedName().toCharArray()); boolean isPossibleMatch = false; for (int i = 0, length = possibleMatches.length; i < length; i++) { if (CharOperation.equals(possibleMatches[i].compoundName, compoundName)) { isPossibleMatch = true;// w w w . j ava 2 s. c o m break; } } if (!isPossibleMatch) { if (focusType.isBinary()) { try { cacheBinaryType(focusType, null); } catch (JavaModelException e) { return false; } } else { // cache all types in the focus' compilation unit (even secondary types) accept((ICompilationUnit) focusType.getCompilationUnit(), null /*TODO no access restriction*/); } } // resolve focus type this.hierarchyResolver = new HierarchyResolver(this.lookupEnvironment, null/*hierarchy is not going to be computed*/); ReferenceBinding binding = this.hierarchyResolver.setFocusType(compoundName); return binding != null && binding.isValidBinding() && (binding.tagBits & TagBits.HierarchyHasProblems) == 0; }
From source file:io.takari.maven.plugins.compile.jdt.ClassfileDigester.java
License:Open Source License
public byte[] digest(IBinaryType classFile) { // type level comparison // modifiers// ww w.ja v a 2 s . c o m updateInt(classFile.getModifiers()); // only consider a portion of the tagbits which indicate a structural change for dependents // e.g. @Override change has no influence outside long OnlyStructuralTagBits = TagBits.AnnotationTargetMASK // different @Target status ? | TagBits.AnnotationDeprecated // different @Deprecated status ? | TagBits.AnnotationRetentionMASK // different @Retention status ? | TagBits.HierarchyHasProblems; // different hierarchy status ? // meta-annotations updateLong(classFile.getTagBits() & OnlyStructuralTagBits); // annotations updateAnnotations(classFile.getAnnotations()); // generic signature updateChars(classFile.getGenericSignature()); // superclass updateChars(classFile.getSuperclassName()); // interfaces char[][] interfacesNames = classFile.getInterfaceNames(); if (interfacesNames != null) { for (int i = 0; i < interfacesNames.length; i++) { updateChars(interfacesNames[i]); } } // member types IBinaryNestedType[] memberTypes = classFile.getMemberTypes(); if (memberTypes != null) { for (int i = 0; i < memberTypes.length; i++) { updateChars(memberTypes[i].getName()); updateInt(memberTypes[i].getModifiers()); } } // fields FieldInfo[] fieldInfos = (FieldInfo[]) classFile.getFields(); if (fieldInfos != null) { for (int i = 0; i < fieldInfos.length; i++) { updateField(fieldInfos[i]); } } // methods MethodInfo[] methodInfos = (MethodInfo[]) classFile.getMethods(); if (methodInfos != null) { for (int i = 0; i < methodInfos.length; i++) { updateMethod(methodInfos[i]); } } // missing types char[][][] missingTypes = classFile.getMissingTypeNames(); if (missingTypes != null) { for (int i = 0; i < missingTypes.length; i++) { for (int j = 0; j < missingTypes[i].length; j++) { if (j > 0) { updateChar('.'); // don't ask why } updateChars(missingTypes[i][j]); } } } return digester.digest(); }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
/** * Connect type variable supertypes, and returns true if no problem was detected * @param typeParameters/*www. ja v a 2s . c o m*/ * @param checkForErasedCandidateCollisions */ protected boolean connectTypeVariables(TypeParameter[] typeParameters, boolean checkForErasedCandidateCollisions) { /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259 - We used to not bother with connecting type variables if source level is < 1.5. This creates problems in the reconciler if a 1.4 project references the generified API of a 1.5 project. The "current" project's source level cannot decide this question for some other project. Now, if we see type parameters at all, we assume that the concerned java element has some legitimate business with them. */ if (typeParameters == null || typeParameters.length == 0) return true; Map invocations = new HashMap(2); boolean noProblems = true; // preinitializing each type variable for (int i = 0, paramLength = typeParameters.length; i < paramLength; i++) { TypeParameter typeParameter = typeParameters[i]; TypeVariableBinding typeVariable = typeParameter.binding; if (typeVariable == null) return false; typeVariable.superclass = getJavaLangObject(); typeVariable.superInterfaces = Binding.NO_SUPERINTERFACES; // set firstBound to the binding of the first explicit bound in parameter declaration typeVariable.firstBound = null; // first bound used to compute erasure } nextVariable: for (int i = 0, paramLength = typeParameters.length; i < paramLength; i++) { TypeParameter typeParameter = typeParameters[i]; TypeVariableBinding typeVariable = typeParameter.binding; TypeReference typeRef = typeParameter.type; if (typeRef == null) continue nextVariable; boolean isFirstBoundTypeVariable = false; TypeBinding superType = this.kind == METHOD_SCOPE ? typeRef.resolveType((BlockScope) this, false/*no bound check*/) : typeRef.resolveType((ClassScope) this); if (superType == null) { typeVariable.tagBits |= TagBits.HierarchyHasProblems; } else { typeRef.resolvedType = superType; // hold onto the problem type firstBound: { switch (superType.kind()) { case Binding.ARRAY_TYPE: problemReporter().boundCannotBeArray(typeRef, superType); typeVariable.tagBits |= TagBits.HierarchyHasProblems; break firstBound; // do not keep first bound case Binding.TYPE_PARAMETER: isFirstBoundTypeVariable = true; TypeVariableBinding varSuperType = (TypeVariableBinding) superType; if (varSuperType.rank >= typeVariable.rank && varSuperType.declaringElement == typeVariable.declaringElement) { if (compilerOptions().complianceLevel <= ClassFileConstants.JDK1_6) { problemReporter().forwardTypeVariableReference(typeParameter, varSuperType); typeVariable.tagBits |= TagBits.HierarchyHasProblems; break firstBound; // do not keep first bound } } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=335751 if (compilerOptions().complianceLevel > ClassFileConstants.JDK1_6) { if (typeVariable.rank >= varSuperType.rank && varSuperType.declaringElement == typeVariable.declaringElement) { SimpleSet set = new SimpleSet(typeParameters.length); set.add(typeVariable); ReferenceBinding superBinding = varSuperType; while (superBinding instanceof TypeVariableBinding) { if (set.includes(superBinding)) { problemReporter().hierarchyCircularity(typeVariable, varSuperType, typeRef); typeVariable.tagBits |= TagBits.HierarchyHasProblems; break firstBound; // do not keep first bound } else { set.add(superBinding); superBinding = ((TypeVariableBinding) superBinding).superclass; } } } } break; default: if (((ReferenceBinding) superType).isFinal()) { problemReporter().finalVariableBound(typeVariable, typeRef); } break; } ReferenceBinding superRefType = (ReferenceBinding) superType; if (!superType.isInterface()) { typeVariable.superclass = superRefType; } else { typeVariable.superInterfaces = new ReferenceBinding[] { superRefType }; } typeVariable.tagBits |= superType.tagBits & TagBits.ContainsNestedTypeReferences; typeVariable.firstBound = superRefType; // first bound used to compute erasure } } TypeReference[] boundRefs = typeParameter.bounds; if (boundRefs != null) { nextBound: for (int j = 0, boundLength = boundRefs.length; j < boundLength; j++) { typeRef = boundRefs[j]; superType = this.kind == METHOD_SCOPE ? typeRef.resolveType((BlockScope) this, false) : typeRef.resolveType((ClassScope) this); if (superType == null) { typeVariable.tagBits |= TagBits.HierarchyHasProblems; continue nextBound; } else { typeVariable.tagBits |= superType.tagBits & TagBits.ContainsNestedTypeReferences; boolean didAlreadyComplain = !typeRef.resolvedType.isValidBinding(); if (isFirstBoundTypeVariable && j == 0) { problemReporter().noAdditionalBoundAfterTypeVariable(typeRef); typeVariable.tagBits |= TagBits.HierarchyHasProblems; didAlreadyComplain = true; //continue nextBound; - keep these bounds to minimize secondary errors } else if (superType.isArrayType()) { if (!didAlreadyComplain) { problemReporter().boundCannotBeArray(typeRef, superType); typeVariable.tagBits |= TagBits.HierarchyHasProblems; } continue nextBound; } else { if (!superType.isInterface()) { if (!didAlreadyComplain) { problemReporter().boundMustBeAnInterface(typeRef, superType); typeVariable.tagBits |= TagBits.HierarchyHasProblems; } continue nextBound; } } // check against superclass if (checkForErasedCandidateCollisions && typeVariable.firstBound == typeVariable.superclass) { if (hasErasedCandidatesCollisions(superType, typeVariable.superclass, invocations, typeVariable, typeRef)) { continue nextBound; } } // check against superinterfaces ReferenceBinding superRefType = (ReferenceBinding) superType; for (int index = typeVariable.superInterfaces.length; --index >= 0;) { ReferenceBinding previousInterface = typeVariable.superInterfaces[index]; if (previousInterface == superRefType) { problemReporter().duplicateBounds(typeRef, superType); typeVariable.tagBits |= TagBits.HierarchyHasProblems; continue nextBound; } if (checkForErasedCandidateCollisions) { if (hasErasedCandidatesCollisions(superType, previousInterface, invocations, typeVariable, typeRef)) { continue nextBound; } } } int size = typeVariable.superInterfaces.length; System.arraycopy(typeVariable.superInterfaces, 0, typeVariable.superInterfaces = new ReferenceBinding[size + 1], 0, size); typeVariable.superInterfaces[size] = superRefType; } } } noProblems &= (typeVariable.tagBits & TagBits.HierarchyHasProblems) == 0; } return noProblems; }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
protected boolean hasErasedCandidatesCollisions(TypeBinding one, TypeBinding two, Map invocations, ReferenceBinding type, ASTNode typeRef) { invocations.clear();/*from ww w . ja v a 2 s . co m*/ TypeBinding[] mecs = minimalErasedCandidates(new TypeBinding[] { one, two }, invocations); if (mecs != null) { nextCandidate: for (int k = 0, max = mecs.length; k < max; k++) { TypeBinding mec = mecs[k]; if (mec == null) continue nextCandidate; Object value = invocations.get(mec); if (value instanceof TypeBinding[]) { TypeBinding[] invalidInvocations = (TypeBinding[]) value; problemReporter().superinterfacesCollide(invalidInvocations[0].erasure(), typeRef, invalidInvocations[0], invalidInvocations[1]); type.tagBits |= TagBits.HierarchyHasProblems; return true; } } } return false; }
From source file:org.eclipse.jdt.internal.core.hierarchy.HierarchyResolver.java
License:Open Source License
private void fixSupertypeBindings() { for (int current = this.typeIndex; current >= 0; current--) { ReferenceBinding typeBinding = this.typeBindings[current]; if ((typeBinding.tagBits & TagBits.HierarchyHasProblems) == 0) continue; if (typeBinding instanceof SourceTypeBinding) { if (typeBinding instanceof LocalTypeBinding) { LocalTypeBinding localTypeBinding = (LocalTypeBinding) typeBinding; QualifiedAllocationExpression allocationExpression = localTypeBinding.scope.referenceContext.allocation; TypeReference type;//ww w. j a va 2 s . c o m if (allocationExpression != null && (type = allocationExpression.type) != null && type.resolvedType != null) { localTypeBinding.superclass = (ReferenceBinding) type.resolvedType; continue; } } ClassScope scope = ((SourceTypeBinding) typeBinding).scope; if (scope != null) { TypeDeclaration typeDeclaration = scope.referenceContext; TypeReference superclassRef = typeDeclaration == null ? null : typeDeclaration.superclass; TypeBinding superclass = superclassRef == null ? null : superclassRef.resolvedType; if (superclass != null) { superclass = superclass.closestMatch(); } if (superclass instanceof ReferenceBinding) { // ensure we are not creating a cycle (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=215681 ) if (!(subTypeOfType((ReferenceBinding) superclass, typeBinding))) { ((SourceTypeBinding) typeBinding).superclass = (ReferenceBinding) superclass; } } TypeReference[] superInterfaces = typeDeclaration == null ? null : typeDeclaration.superInterfaces; int length; ReferenceBinding[] interfaceBindings = typeBinding.superInterfaces(); if (superInterfaces != null && (length = superInterfaces.length) > (interfaceBindings == null ? 0 : interfaceBindings.length)) { // check for interfaceBindings being null (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=139689) interfaceBindings = new ReferenceBinding[length]; int index = 0; for (int i = 0; i < length; i++) { TypeBinding superInterface = superInterfaces[i].resolvedType; if (superInterface != null) { superInterface = superInterface.closestMatch(); } if (superInterface instanceof ReferenceBinding) { // ensure we are not creating a cycle (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=215681 ) if (!(subTypeOfType((ReferenceBinding) superInterface, typeBinding))) { interfaceBindings[index++] = (ReferenceBinding) superInterface; } } } if (index < length) System.arraycopy(interfaceBindings, 0, interfaceBindings = new ReferenceBinding[index], 0, index); ((SourceTypeBinding) typeBinding).superInterfaces = interfaceBindings; } } } else if (typeBinding instanceof BinaryTypeBinding) { try { typeBinding.superclass(); } catch (AbortCompilation e) { // allow subsequent call to superclass() to succeed so that we don't have to catch AbortCompilation everywhere ((BinaryTypeBinding) typeBinding).tagBits &= ~TagBits.HasUnresolvedSuperclass; this.builder.hierarchy.missingTypes.add(new String(typeBinding.superclass().sourceName())); this.hasMissingSuperClass = true; } try { typeBinding.superInterfaces(); } catch (AbortCompilation e) { // allow subsequent call to superInterfaces() to succeed so that we don't have to catch AbortCompilation everywhere ((BinaryTypeBinding) typeBinding).tagBits &= ~TagBits.HasUnresolvedSuperinterfaces; } } } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.LiftingTypeReference.java
License:Open Source License
@Override public TypeBinding resolveType(BlockScope scope, boolean checkBounds) { TypeBinding baseType = this.resolvedType = this.baseReference.resolveType(scope); if (this.roleReference.getTypeName().length > 1) { scope.problemReporter().qualifiedLiftingType(this.roleReference, scope.enclosingSourceType()); return invalidate(baseType); }// w w w .j a va2 s. co m TypeBinding roleType = this.roleReference.resolveType(scope); if (scope.kind != Scope.BLOCK_SCOPE) { // not a catch block? if (!TeamModel.isAnyTeam(scope.enclosingSourceType())) { scope.problemReporter().liftingTypeNotAllowedHere(scope.methodScope().referenceContext, this); return invalidate(roleType); } } if (baseType == null || baseType instanceof MissingTypeBinding) return invalidate(roleType); if (roleType == null || roleType instanceof MissingTypeBinding) return invalidate(baseType); if (roleType.isArrayType()) { baseType = baseType.leafComponentType(); roleType = roleType.leafComponentType(); } if (roleType.isBaseType()) { scope.problemReporter().primitiveTypeNotAllowedForLifting(scope.referenceType(), this.roleReference, roleType); return invalidate(roleType); } if (baseType.isBaseType()) { scope.problemReporter().primitiveTypeNotAllowedForLifting(scope.referenceType(), this.baseReference, baseType); return invalidate(roleType); } ReferenceBinding roleRefType = (ReferenceBinding) roleType; if (!roleRefType.isValidBinding()) // already reported. return invalidate(roleType); if (!roleRefType.isDirectRole()) { scope.problemReporter().needRoleInLiftingType(scope.referenceType(), this.roleReference, roleType); return invalidate(roleType); } if (roleRefType.isSynthInterface()) roleRefType = roleRefType.getRealClass(); if (roleRefType.roleModel.hasBaseclassProblem()) {// already reported for the role class. scope.referenceContext().tagAsHavingErrors(); // -> mark method as erroneous, too. return invalidate(roleType); } // TODO (SH): maybe look for bound sub-type? // Note (SH): calling baseclass() requires STATE_LENV_DONE_FIELDS_AND_METHODS: Dependencies.ensureBindingState(roleRefType, ITranslationStates.STATE_LENV_DONE_FIELDS_AND_METHODS); if (baseType.isTypeVariable() && ((TypeVariableBinding) baseType).roletype != null) { // resolving "<B base R> as R": roleRefType = ((TypeVariableBinding) baseType).roletype; // ambiguity is handled by _OT$lift_dynamic which may or may not declare LiftingFailedException } else if ((baseType.tagBits & TagBits.HierarchyHasProblems) != 0) { // already reported (?) } else { // static adjustment (OTJLD 2.3.2(a)): roleRefType = (ReferenceBinding) TeamModel.getRoleToLiftTo(scope, baseType, roleRefType, true, this); if (roleRefType == null) roleRefType = (ReferenceBinding) roleType; // revert unsuccessful adjustment if (roleRefType.baseclass() == null || RoleModel.hasTagBit(roleRefType, RoleModel.BaseclassHasProblems)) { scope.problemReporter().roleNotBoundCantLift(scope.referenceType(), this.roleReference, roleType); return invalidate(roleType); } if (baseType.isRole()) // see http://trac.objectteams.org/ot/ticket/73 baseType = RoleTypeCreator.maybeWrapUnqualifiedRoleType(baseType, scope.enclosingReceiverType()); if (baseType == null) return invalidate(roleType); Config oldConfig = Config.createOrResetConfig(this); try { // fetch role's base class and perform substitutions: ReferenceBinding roleBase = roleRefType.baseclass(); if (roleType.isParameterizedType()) { ParameterizedTypeBinding parameterizedRole = (ParameterizedTypeBinding) roleType; TypeBinding[] typeArgs = parameterizedRole.arguments; ITeamAnchor anchor = null; if (roleRefType.baseclass() instanceof RoleTypeBinding) anchor = ((RoleTypeBinding) roleRefType.baseclass())._teamAnchor; roleBase = parameterizedRole.environment.createParameterizedType( (ReferenceBinding) roleBase.original(), typeArgs, anchor, -1, roleBase.enclosingType(), roleBase.getTypeAnnotations()); } // THE compatibility check: if (!baseType.isCompatibleWith(roleBase) || Config.getLoweringRequired()) { scope.problemReporter().incompatibleBaseForRole(scope.referenceType(), this, roleType, baseType); return invalidate(roleType); } } finally { Config.removeOrRestore(oldConfig, this); } } return this.resolvedType; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.control.Dependencies.java
License:Open Source License
public static boolean needMethodBodies(TypeDeclaration type) { if (type.scope == null) return false; if (type.binding != null && (type.binding.tagBits & TagBits.HierarchyHasProblems) != 0) return false; // when type hierarchy is inconsistent expect grave errors, don't generate bodies. return type.scope.referenceCompilationUnit().parseMethodBodies; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lifting.DeclaredLifting.java
License:Open Source License
private static LocalDeclaration createLiftingStatement(Scope scope, Argument argument) { LiftingTypeReference ltr = (LiftingTypeReference) argument.type; int start = argument.type.sourceStart; int end = argument.type.sourceEnd; AstGenerator gen = new AstGenerator(start, end); // names://ww w. j ava2s. com char[] oldName = argument.name; char[] newName = CharOperation.concat(OT_DOLLAR_NAME, oldName); argument.updateName(newName); // MyRole obj = _OT$liftToMyRole(_OT$obj); (via PotentialLiftExpression) TypeBinding roleType = scope.getType(ltr.roleToken); ReferenceBinding roleRef = (ReferenceBinding) roleType; // using a PotentialLiftExpression allows us to defer type resolution. Expression liftCall = null; // spare the details during completion - see comment regarding local.declaration.initialization inside // InternalExtendedCompletionContext.searchVisibleVariablesAndMethods(Scope, ObjectVector, ObjectVector, ObjectVector, boolean) if (!Config.isUsingAssistParser()) { if (roleRef.isValidBinding() && roleRef.isRole() && (roleRef.tagBits & TagBits.HierarchyHasProblems) == 0 && !RoleModel.hasTagBit(roleRef, RoleModel.BaseclassHasProblems)) { Expression receiverTeam = ThisReference.implicitThis(); ReferenceBinding teamBinding = roleRef.enclosingType(); if (TypeBinding.notEquals(teamBinding, scope.enclosingSourceType())) receiverTeam = gen.qualifiedThisReference(teamBinding); if (roleRef.baseclass() == null) { // static adjustment (OTJLD 2.3.2(a)): ReferenceBinding baseType = null; if (scope.classScope() instanceof OTClassScope) { // try base scope first: CompilationUnitScope baseScope = ((OTClassScope) scope.classScope()) .getBaseImportScope(scope); if (baseScope != null) { baseType = (ReferenceBinding) baseScope.getType(ltr.baseTokens, ltr.baseTokens.length); baseScope.originalScope = null; } } if (baseType == null || !baseType.isValidBinding()) // fall back to normal scope: baseType = (ReferenceBinding) scope.getType(ltr.baseTokens, ltr.baseTokens.length); roleRef = (ReferenceBinding) TeamModel.getRoleToLiftTo(scope, baseType, roleRef, true, ltr); if (baseType.isTypeVariable() && roleRef == null) roleRef = (ReferenceBinding) roleType; // fall back to the declared type } if (roleRef != null) { if (ltr.baseReference.dimensions() > 0) roleType = scope.createArrayType(roleRef, ltr.baseReference.dimensions()); liftCall = new PotentialLiftExpression(receiverTeam, gen.singleNameReference(newName), ltr.roleReference); } // errors are reported by LiftingTypeReference.resolveType(). } } // assemble the variable decl: LocalDeclaration declaration = gen.localVariable(oldName, AstClone.copyTypeReference(ltr.roleReference), liftCall); // store local declaration in lifting type, // which may need to cancel some generated AST after resolve. // (cf. LiftingTypeReference.invalidate()) ltr.fakedArgument = declaration; return declaration; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lifting.Lifting.java
License:Open Source License
public ConstructorDeclaration createLiftToConstructorDeclaration(TreeNode roleNode, boolean needMethodBodies) { TreeNode instantiableBoundRootRoleNode = roleNode.getTopmostBoundParent(false); if (instantiableBoundRootRoleNode == null) return null; TypeDeclaration roleDecl = roleNode.getTreeObject().getAst(); ClassScope scope = roleDecl.scope;/*from ww w . ja v a 2 s.c o m*/ if (instantiableBoundRootRoleNode == TreeNode.ProblemNode) { scope.problemReporter().overlappingRoleHierarchies(roleDecl, TreeNode.ProblemNode.toString()); return null; } TypeDeclaration roleType = roleNode.getTreeObject().getAst(); ConstructorDeclaration existingConstructor = findLiftToConstructor(roleType); if (existingConstructor == null && !roleNode.hasBoundParent(false) && !roleNode.getTreeObject().isIgnoreFurtherInvestigation()) { ReferenceBinding parent = roleNode.getTreeObject().getBinding().superclass(); MethodBinding defCtor = parent.getExactConstructor(Binding.NO_PARAMETERS); boolean hasEmptyCtor = (defCtor != null) ? defCtor.isValidBinding() : (parent.getMethods(TypeConstants.INIT) == Binding.NO_METHODS); if (!hasEmptyCtor) { scope.problemReporter().missingEmptyCtorForLiftingCtor(roleDecl, parent); return null; } } // for determining the cache interfaces are allowed: this._boundRootRoleModel = roleNode.getTopmostBoundParent(true).getTreeObject(); if (this._boundRootRoleModel != null) roleNode.getTreeObject()._boundRootRole = this._boundRootRoleModel; TypeDeclaration teamTypeDeclaration = roleType.enclosingType; ReferenceBinding baseClassBinding = roleType.binding.baseclass(); if (baseClassBinding == null && ((roleType.binding.tagBits & TagBits.HierarchyHasProblems) != 0)) return null; // assume base class could not be resolved. AstGenerator gen = existingConstructor == null ? new AstGenerator(roleType) : new AstGenerator(existingConstructor); gen.replaceableEnclosingClass = roleType.binding.enclosingType(); // public MyRole(MyBase base) Argument arg; ConstructorDeclaration generatedConstructor = gen.constructor(teamTypeDeclaration.compilationResult, ClassFileConstants.AccPublic, roleType.name, new Argument[] { // (MyBase base) arg = gen.argument(BASE, // name gen.baseclassReference(baseClassBinding)) // type }); gen.addNonNullAnnotation(arg, scope.environment()); // default arg name is base. char[] baseArgName = BASE; if (existingConstructor != null) { if (existingConstructor.isCopied) { if (roleNode.getTreeObject().getImplicitSuperRole().isBound()) // parent must be class. return null; // copied constructor has everything we need. } // use the argument name of the existing constructor baseArgName = existingConstructor.arguments[0].name; } if (needMethodBodies) { if (instantiableBoundRootRoleNode == roleNode) genLiftToConstructorStatements(baseClassBinding, roleType, generatedConstructor, baseArgName, gen); else genLiftToConstructorSuperCall(baseClassBinding, roleType, generatedConstructor, baseArgName, gen); } this._boundRootRoleModel = null; if (existingConstructor != null) { //if constructor exists with same signature, merge statements. if (needMethodBodies) { // Also see Parser.parse(ConstructorDeclaration) for merging and // for checking illegal explicit super call. if (existingConstructor.statements != null) { int len1 = generatedConstructor.statements.length; int len2 = existingConstructor.statements.length; Statement[] newStatements = new Statement[len1 + len2]; System.arraycopy(generatedConstructor.statements, 0, newStatements, 0, len1); System.arraycopy(existingConstructor.statements, 0, newStatements, len1, len2); existingConstructor.setStatements(newStatements); } else { existingConstructor.setStatements(generatedConstructor.statements); } // Keep arguments. // If constructorCall is explicit keep it. if (existingConstructor.constructorCall == null || existingConstructor.constructorCall.isImplicitSuper()) existingConstructor.constructorCall = generatedConstructor.constructorCall; } return existingConstructor; } else { //otherhwise insert new constructor AstEdit.addMethod(roleType, generatedConstructor); return generatedConstructor; } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.AbstractOTReferenceBinding.java
License:Open Source License
public boolean isBoundBase() { if (this.isBoundBase) return true; if ((this.tagBits & TagBits.HierarchyHasProblems) != 0) return false; if (isInterface()) { for (ReferenceBinding superInterface : _this().superInterfaces()) if (superInterface != null && superInterface.isBoundBase()) return true; } else if (superclass() != null) { return superclass().isBoundBase(); }//from w w w . j a va 2s.co m return false; }