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

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

Introduction

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

Prototype

@Override
    public void resolveStatements() 

Source Link

Usage

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

License:Open Source License

/**
* For each role (bound or unbound) generate
*       public org.objectteams.Team _OT$getTeam()
* If roleType is an interface generate the abstract interface method.
*
* @param roleType the role to operate on
* @return the binding of the created method or null
*//*from w  w w.  ja va2 s  .  c om*/
public static @Nullable MethodBinding createGetTeamMethod(TypeDeclaration roleType) {
    MethodBinding existingMethod = TypeAnalyzer.findMethod(roleType.initializerScope, roleType.binding,
            _OT_GETTEAM, Binding.NO_PARAMETERS);
    if (existingMethod != null && existingMethod.isValidBinding()) {
        // is already covered by inheritance (copy or extends)
        if (roleType.isInterface() == existingMethod.isAbstract())
            return null;
    }

    AstGenerator gen = roleType.baseclass != null
            ? new AstGenerator(roleType.baseclass.sourceStart, roleType.baseclass.sourceEnd)
            : new AstGenerator(roleType.sourceStart, roleType.sourceEnd);

    ReferenceBinding teamType = null;
    LookupEnvironment environment = roleType.scope.environment();
    try {
        environment.missingClassFileLocation = roleType;
        teamType = roleType.scope.getOrgObjectteamsITeam();
    } finally {
        environment.missingClassFileLocation = null;
    }

    int flags = AccPublic;
    if (roleType.isInterface())
        flags |= AccAbstract | AccSemicolonBody;

    MethodDeclaration getTeam = gen.method(roleType.compilationResult, flags, teamType, _OT_GETTEAM, null);
    AstEdit.addMethod(roleType, getTeam);

    if ((flags & AccSemicolonBody) == 0) {
        int depth = roleType.binding.depth() - 1;
        getTeam.setStatements(new Statement[] { gen.returnStatement(
                gen.fieldReference(gen.thisReference(), (OUTER_THIS_PREFIX + depth).toCharArray())) });
        if (StateMemento.hasMethodResolveStarted(roleType.binding))
            getTeam.resolveStatements();
    }
    return getTeam.binding;
}

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

License:Open Source License

/**
 * @return either a newly created method or a valid, existing one.
 *//*w w w .ja  v  a2 s .  co m*/
private static MethodBinding createGetBaseMethod(TypeDeclaration roleType, ReferenceBinding baseType,
        char[] methodName, int flags) {
    if (roleType == null)
        return null; // sanity check, null can be caused by binary ifc-part in a source role.
    MethodBinding existingMethod = null;
    AbstractMethodDeclaration decl = TypeAnalyzer.findMethodDecl(roleType, methodName, 0);
    if (decl != null)
        existingMethod = decl.binding;
    if (existingMethod == null)
        existingMethod = TypeAnalyzer.findMethod(roleType.initializerScope, roleType.binding.superclass(),
                methodName, Binding.NO_PARAMETERS);
    if (existingMethod != null && existingMethod.isValidBinding()) { // valid method exists
        if (existingMethod.isAbstract() == roleType.isInterface()) // abstractness is correct
            if (TypeBinding.equalsEquals(existingMethod.declaringClass, roleType.binding)// declared here
                    || existingMethod.returnType.isCompatibleWith(baseType)) // inherited but compatible
                return existingMethod;
    }

    AstGenerator gen = roleType.baseclass != null
            ? new AstGenerator(roleType.baseclass.sourceStart, roleType.baseclass.sourceEnd)
            : new AstGenerator(roleType.sourceStart, roleType.sourceEnd);
    gen.replaceableEnclosingClass = roleType.binding.enclosingType();

    TypeReference baseclassReference; // must set in if or else
    TypeParameter methodParam = null;
    Statement bodyStatement; // must set in if or else
    if (baseType != null) {
        baseclassReference = gen.baseclassReference(baseType);
        bodyStatement = gen.returnStatement(gen.castExpression(gen.singleNameReference(_OT_BASE),
                baseclassReference, CastExpression.DO_WRAP));
    } else {
        // this role is not bound but create a generic getBase method for use via a <B base R> type:
        final char[] paramName = "_OT$AnyBase".toCharArray(); //$NON-NLS-1$ used only for this one declaration.
        methodParam = gen.baseBoundedTypeParameter(paramName, roleType.binding);
        baseclassReference = gen.singleTypeReference(paramName);
        final char[][] ABSTRACT_METHOD = new char[][] { "java".toCharArray(), //$NON-NLS-1$
                "lang".toCharArray(), //$NON-NLS-1$
                "AbstractMethodError".toCharArray() }; //$NON-NLS-1$
        bodyStatement = gen.throwStatement(gen.allocation(gen.qualifiedTypeReference(ABSTRACT_METHOD), null));
    }
    MethodDeclaration getBase = gen.method(roleType.compilationResult, flags, baseclassReference, methodName,
            null);

    if (methodParam != null)
        getBase.typeParameters = new TypeParameter[] { methodParam };

    AstEdit.addMethod(roleType, getBase);
    for (ReferenceBinding tsuperRole : roleType.getRoleModel().getTSuperRoleBindings()) {
        for (MethodBinding tsuperMethod : tsuperRole.getMethods(_OT_GETBASE))
            getBase.binding.addOverriddenTSuper(tsuperMethod);
    }

    if (methodParam != null)
        roleType.getRoleModel().unimplementedGetBase = getBase.binding;

    if ((flags & AccSemicolonBody) == 0) {
        getBase.setStatements(new Statement[] { bodyStatement });
        if (StateMemento.hasMethodResolveStarted(roleType.binding))
            getBase.resolveStatements();
    }
    return getBase.binding;
}