Example usage for org.eclipse.jdt.internal.compiler.ast MethodDeclaration tagAsHavingErrors

List of usage examples for org.eclipse.jdt.internal.compiler.ast MethodDeclaration tagAsHavingErrors

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.ast MethodDeclaration tagAsHavingErrors.

Prototype

@Override
    public void tagAsHavingErrors() 

Source Link

Usage

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CalloutImplementor.java

License:Open Source License

/**
 * Create the methodbody for callouts/*from  ww  w  . j  a va  2 s . co m*/
 */
void createCalloutMethodBody(MethodDeclaration roleMethodDeclaration,
        CalloutMappingDeclaration calloutBindingDeclaration) {
    if (!transformCalloutMethodBody(roleMethodDeclaration, calloutBindingDeclaration))
        roleMethodDeclaration.tagAsHavingErrors();
}

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

License:Open Source License

/**
* Generate creation methods for a given role constructor.
* for concrete R:// w  ww.j  a v a  2 s . co  m
*   R _OT$createR (mySignature) { return new __OT__R(myArgs); }
* for abstract R:
*    abstract R _OT$createR (mySignature);
* If role is inherited from super-Team, repeat creation method with
* same signature but creating an instance of the local role type.
*
* @param teamDeclaration   the team class to hold the creation method
* @param roleModel       the role to instantiate
 * @param constructor       use this as a template to create the creation method, may be null.
 * @param constructorBinding non-null representation of constructor
 * @param needMethodBody used to signal whether generating statements is required
* @return the creation method.
*/
public static MethodDeclaration createCreationMethod(TypeDeclaration teamDeclaration, RoleModel roleModel,
        ConstructorDeclaration constructor, MethodBinding constructorBinding, boolean needMethodBody) {

    int start, end;
    int modifiers;
    boolean hasError = false;
    if (constructor != null) {
        if (constructor.isTSuper || constructor.hasErrors())
            return null;
        if (constructor.isDefaultConstructor() && roleModel.hasBaseclassProblem())
            hasError = true;

        start = constructor.sourceStart;
        end = constructor.sourceEnd;
        modifiers = constructor.modifiers;
        constructorBinding = constructor.binding;
    } else {
        if (TSuperHelper.isTSuper(constructorBinding))
            return null;
        start = teamDeclaration.sourceStart;
        end = teamDeclaration.sourceEnd;
        modifiers = constructorBinding.modifiers;
    }
    int originalModifiers = -1;
    // creation method must access constructor, make it at least protected:
    if (constructorBinding != null && (constructorBinding.isDefault() || constructorBinding.isPrivate())) {
        originalModifiers = constructorBinding.modifiers;
        MethodModel.getModel(constructorBinding).storeModifiers(originalModifiers);
    }

    AstGenerator gen = new AstGenerator(start, end);
    gen.replaceableEnclosingClass = teamDeclaration.binding;

    Argument[] newArguments = null;
    // Arguments (construct from bindings, using dummy names):
    if (constructorBinding != null) {
        TypeBinding[] srcParams = constructorBinding.parameters;
        if (srcParams != null) {
            newArguments = AstConverter.createArgumentsFromParameters(srcParams, gen);
            if (srcParams.length == 1
                    && TypeBinding.equalsEquals(srcParams[0], roleModel.getInterfacePartBinding())) { // single argument of type of this role itself?
                if (constructorBinding.isPrivate() || constructorBinding.isDefault())
                    roleModel.getAst().scope.problemReporter()
                            .roleConstructorHiddenByLiftingConstructor(constructor);
            }
            if (Lifting.isLiftingCtor(constructorBinding)) {
                gen.addNonNullAnnotation(newArguments[0], teamDeclaration.scope.environment());
            }
        }
    }
    if (newArguments != null && constructorBinding != null && Lifting.isLiftingCtor(constructorBinding))
        newArguments[0].type.setBaseclassDecapsulation(DecapsulationState.REPORTED);

    // if we have source arguments, improve: use correct argument names:
    if (newArguments != null && constructor != null) {
        Argument[] srcArguments = constructor.arguments;
        if (srcArguments != null && srcArguments.length == newArguments.length)
            for (int i = 0; i < srcArguments.length; i++)
                newArguments[i].name = srcArguments[i].name;
    }
    TypeReference[] exceptions = null;
    if (constructor != null) {
        if (constructor.thrownExceptions != null)
            exceptions = AstClone.copyTypeArray(constructor.thrownExceptions);
    } else if (constructorBinding != null) {
        if (constructorBinding.thrownExceptions != Binding.NO_EXCEPTIONS)
            exceptions = AstClone.copyExceptions(constructorBinding, gen);
    } else {
        throw new InternalCompilerError("Either constructor or constructorBinding must be nonnull"); //$NON-NLS-1$
    }

    MethodDeclaration newMethod = internalCreateCreationMethod(teamDeclaration, roleModel, modifiers,
            newArguments, exceptions, needMethodBody && !hasError, start, end);
    if (hasError)
        newMethod.tagAsHavingErrors();

    if (newMethod != null) {
        MethodModel model = MethodModel.getModel(newMethod);
        model._srcCtor = constructorBinding;
        if (originalModifiers != -1)
            model.storeModifiers(originalModifiers);
    }

    if (newMethod != null && constructor != null)
        // faked source locations (binaries have no source poss, but compiled constructor has no errors.)
        AstClone.copySrcLocation(constructor, newMethod);

    return newMethod;
}