Example usage for org.eclipse.jdt.internal.compiler.lookup ClassScope problemReporter

List of usage examples for org.eclipse.jdt.internal.compiler.lookup ClassScope problemReporter

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.lookup ClassScope problemReporter.

Prototype

@Override
    public ProblemReporter problemReporter() 

Source Link

Usage

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.TypeAnchorReference.java

License:Open Source License

@Override
public TypeBinding resolveType(ClassScope classScope) {
    classScope.problemReporter().valueParamWrongPosition(this);
    return null;//  w  w  w .j a v a 2  s. co m
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.control.Dependencies.java

License:Open Source License

private static void checkMissingMethods(ReferenceBinding roleBinding, TypeDeclaration roleDecl) {
    if (roleBinding.isClass() && ((roleBinding.tagBits & TagBits.AnnotationInstantiation) != 0)) {
        InstantiationPolicy instantiationPolicy = RoleModel.getInstantiationPolicy(roleBinding);
        if (!instantiationPolicy.isAlways())
            return;
        ClassScope scope = roleDecl.scope;
        boolean missing = false;
        MethodBinding equals = roleBinding.getExactMethod(TypeConstants.EQUALS,
                new TypeBinding[] { scope.getJavaLangObject() }, scope.compilationUnitScope());
        if (equals == null || !equals.isValidBinding()
                || TypeBinding.notEquals(equals.declaringClass, roleBinding)) {
            missing = true;/*from  w w  w. j av a  2  s  . c o  m*/
        } else {
            MethodBinding hashCode = roleBinding.getExactMethod(TypeConstants.HASHCODE, Binding.NO_PARAMETERS,
                    scope.compilationUnitScope());
            if (hashCode == null || !hashCode.isValidBinding()
                    || TypeBinding.notEquals(hashCode.declaringClass, roleBinding))
                missing = true;
        }
        if (missing) {
            scope.problemReporter().missingEqualsHashCodeWithInstantation(scope.referenceContext,
                    instantiationPolicy);
        }
    }
    // copied abstract methods are not yet checked for callout inference (which is normally triggered from checkMethods()) 
    if (roleBinding.isClass() && roleDecl.methods != null) {
        for (AbstractMethodDeclaration method : roleDecl.methods) {
            if (((method.modifiers & ClassFileConstants.AccAbstract) != 0) && method.isCopied) {
                // inheriting abstract method in non-abstract role may require callout inference:
                CalloutImplementor coi = new CalloutImplementor(roleDecl.getRoleModel());
                MethodDeclaration callout = coi.generateInferredCallout(roleDecl, method.binding);
                if (callout != null)
                    roleDecl.scope.problemReporter().addingInferredCalloutForInherited(roleDecl, method.binding,
                            callout);
            }
        }
    }
}

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;
    if (instantiableBoundRootRoleNode == TreeNode.ProblemNode) {
        scope.problemReporter().overlappingRoleHierarchies(roleDecl, TreeNode.ProblemNode.toString());
        return null;
    }//from  w  w  w  . j  av  a  2  s  .  c o  m
    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.statemachine.copyinheritance.CopyInheritance.java

License:Open Source License

private static void checkRoleShadows(ClassScope scope, ReferenceBinding sourceType,
        TypeDeclaration memberDecl) {//  ww w  .j a  v  a2  s  .  c  om
    ReferenceBinding currentType = sourceType.enclosingType();
    char[] internalName = memberDecl.name;
    ReferenceBinding otherType;
    while (currentType != null) {
        otherType = scope.findMemberType(internalName, currentType);
        if (otherType != null && otherType.isValidBinding()) {
            if (TypeAnalyzer.isPredefinedRole(otherType))
                return;
            if (TSuperHelper.isMarkerInterface(otherType))
                return;
            scope.problemReporter().roleShadowsVisibleType(memberDecl, otherType);
            break;
        }
        currentType = currentType.enclosingType();
    }
    TypeBinding otherType2 = (TypeBinding) scope.compilationUnitScope().getTypeOrPackage(internalName,
            Binding.TYPE, false);
    if (otherType2 != null && otherType2.isValidBinding())
        scope.problemReporter().roleShadowsVisibleType(memberDecl, otherType2);
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.copyinheritance.TypeLevel.java

License:Open Source License

/**
 * After the superclasses of tsuper role and current role have been determined,
 * find out whether the new 'extends' clause was legal, and adjust superclass
 * if needed (ie., update references to roles of the super team).
 * @param destRoleDecl @pre: !isInterface()
 * @param destTeam/* ww  w  .  j  a va2s.  c o  m*/
 * @param tsuperRole (may be null)
 * @param obligations record here any sub-type relations that need checking after all roles have been adjusted 
 */
private static void checkAdjustSuperclass(TypeDeclaration destRoleDecl, ReferenceBinding destTeam,
        ReferenceBinding tsuperRole, ArrayList<SupertypeObligation> obligations) {
    ClassScope destScope = destRoleDecl.scope;

    ReferenceBinding inheritedSuperclass = null;
    ReferenceBinding newSuperclass = destRoleDecl.binding.superclass;
    boolean refineToTeam = false;
    if (tsuperRole != null) {
        inheritedSuperclass = tsuperRole.superclass();
        refineToTeam = !tsuperRole.isTeam() && destRoleDecl.isTeam();
        if (tsuperRole.isTeam() && !destRoleDecl.isTeam()) {
            destScope.problemReporter().regularOverridesTeam(destRoleDecl, tsuperRole);
            return;
        }
    }
    TypeReference newExtends = destRoleDecl.superclass;
    if (newExtends == null // no source-level "extends" -> investige implicit (binding-level) extends:
            && newSuperclass != null // either implicit super (j.l.Object or o.o.Team) or inherited from other tsuper
            && !refineToTeam // an implicit extends to org.objectteams.Team is NOT dropped if the tsuper was not a team
            && ((newSuperclass.id == TypeIds.T_JavaLangObject)
                    || destScope.isOrgObjectteamsTeam(newSuperclass))) // otherwise it was copied from a tsuper role
    {
        newSuperclass = null; // drop default 'extends java.lang.Object' or o.o.Team         
    }

    // extends __OT_Confined overriding nothing or __OT__Confined is OK:
    if ((newSuperclass != null && CharOperation.equals(newSuperclass.internalName(), IOTConstants.OTCONFINED))
            && (inheritedSuperclass == null
                    || CharOperation.equals(inheritedSuperclass.internalName(), IOTConstants.OTCONFINED)))
        return;

    if (newSuperclass != null && newSuperclass.isDirectRole()) {
        // check team compatibility
        if (!TeamModel.areCompatibleEnclosings(destTeam, newSuperclass.original().enclosingType())) {
            destScope.problemReporter().extendIncompatibleEnclosingTypes(destRoleDecl, newSuperclass,
                    newSuperclass.enclosingType());
            // set a meaningfull superclass instead:
            destRoleDecl.binding.superclass = (inheritedSuperclass != null) ? inheritedSuperclass
                    : destScope.getJavaLangObject();
            return;
        }
    }
    if (newSuperclass != null)
        newSuperclass = strengthenSuper(destTeam, newSuperclass);
    if (inheritedSuperclass != null) {
        inheritedSuperclass = strengthenSuper(destTeam, inheritedSuperclass);
        if (newSuperclass == null) {
            newSuperclass = inheritedSuperclass;
        } else if (TypeBinding.notEquals(newSuperclass, inheritedSuperclass)) {
            // is the old superclass actually a tsuper version of the new superclass?
            if (newSuperclass.roleModel == null
                    || !newSuperclass.roleModel.hasTSuperRole(inheritedSuperclass)) {
                SupertypeObligation oblig = new SupertypeObligation(newSuperclass, inheritedSuperclass,
                        newExtends, tsuperRole);
                // check now or later?
                if (obligations != null)
                    obligations.add(oblig);
                else
                    oblig.check(destRoleDecl);
            }
            destRoleDecl.getRoleModel()._refinesExtends = true;
        }
    }
    if (newSuperclass != null) {
        if (TypeBinding.equalsEquals(newSuperclass, destRoleDecl.binding)) {
            // a role extends its implicit super role: circularity!
            // error is already reported on behalf of the interface part (real circularity)
        } else {
            if (newSuperclass.isCompatibleWith(destRoleDecl.binding)) {
                // new super class is also a subclass of current
                destRoleDecl.scope.problemReporter().hierarchyCircularity(destRoleDecl.binding, newSuperclass,
                        destRoleDecl);
                destRoleDecl.binding.tagBits |= TagBits.HierarchyHasProblems;
                newSuperclass.tagBits |= TagBits.HierarchyHasProblems;
            } else {
                destRoleDecl.binding.superclass = destRoleDecl.binding.superclass
                        .transferTypeArguments(newSuperclass);
                destRoleDecl.scope.compilationUnitScope().recordSuperTypeReference(newSuperclass);
            }
        }
        // don't update AST: not needed beside error reporting
        // and then only the old node has source positions..
    }
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.RoleMigrationImplementor.java

License:Open Source License

/**
 * PHASE 1: check if <code>implements IXXXMigratable</code> is declared, and if so, check if this declaration is legal.
 *
 * @param sourceType      current (role?) type
 * @param superInterfaceRef implements reference
 * @param superInterface    resolved superinterface type
 * @param scope            class scope of current type
 * @return false if an IXXXMigratable declaration was found but detected to be illegal.
 */// ww  w.j a va 2  s  . c o  m
public static boolean checkMigratableInterfaces(SourceTypeBinding sourceType, TypeReference superInterfaceRef,
        ReferenceBinding superInterface, ClassScope scope) {
    if (CharOperation.equals(superInterface.compoundName, IOTConstants.ORG_OBJECTTEAMS_ITEAMMIGRATABLE)) {
        if (!sourceType.isRole()) {
            scope.problemReporter().migrateNonRole(superInterfaceRef, sourceType);
            return false;
        } else if (scope.referenceContext.baseclass != null) {
            scope.problemReporter().migrateBoundRole(superInterfaceRef, sourceType);
            return false;
        } else if (!sourceType.enclosingType().isFinal()) {
            scope.problemReporter().migrateWithinNonFinalTeam(superInterfaceRef, sourceType.enclosingType());
            return false;
        }
    }
    if (CharOperation.equals(superInterface.compoundName, IOTConstants.ORG_OBJECTTEAMS_IBASEMIGRATABLE)) {
        if (!sourceType.isRole()) {
            scope.problemReporter().baseMigrateNonRole(superInterfaceRef, sourceType);
            return false;
        } else if (scope.referenceContext.baseclass == null) {
            scope.problemReporter().baseMigrateUnboundRole(superInterfaceRef, sourceType);
            return false;
        }
    }
    return true;
}