Example usage for org.eclipse.jdt.internal.compiler.lookup Scope createArrayType

List of usage examples for org.eclipse.jdt.internal.compiler.lookup Scope createArrayType

Introduction

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

Prototype

public ArrayBinding createArrayType(TypeBinding type, int dimension) 

Source Link

Usage

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://from   ww w.ja v a 2  s .  c  om
    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.model.TeamModel.java

License:Open Source License

/**
 * performs role type strengthening, preforms static adjustment (OTJLD 2.3.3(a).
 * Respects arrays and checks compatibility.
 * @param scope client context, guaranteed to be a team or a role
 * @param provided/*  w  w w . j av a  2s  .  c  om*/
 * @param required
 * @param doAdjust should the adjusted role be returned (as opposed to just the strengthened)?
 * @param location where to report errors against
 * @return an exact role or null
 */
public static TypeBinding getRoleToLiftTo(Scope scope, TypeBinding provided, TypeBinding required,
        boolean doAdjust, ASTNode location) {
    ReferenceBinding requiredRef = null;
    if (required.isArrayType() && (required.leafComponentType() instanceof ReferenceBinding)) {
        requiredRef = (ReferenceBinding) required.leafComponentType();
    } else if (required instanceof ReferenceBinding) {
        requiredRef = (ReferenceBinding) required;
    }
    if (requiredRef != null && requiredRef.isRole()) {
        requiredRef = (ReferenceBinding) strengthenRoleType(scope.enclosingSourceType(), requiredRef);
        ReferenceBinding foundRole = null;
        if (requiredRef.baseclass() == null) {
            foundRole = adjustRoleToLiftTo(scope, provided, requiredRef, location);
            if (foundRole != null && !doAdjust)
                foundRole = requiredRef; // successful but revert to unadjusted
        } else {
            if (!provided.leafComponentType().isBaseType()) {
                ReferenceBinding providedLeaf = (ReferenceBinding) provided.leafComponentType();
                providedLeaf = RoleTypeCreator.maybeInstantiateFromPlayedBy(scope, providedLeaf);
                if (providedLeaf.isCompatibleWith(requiredRef.baseclass())
                        && required.dimensions() == provided.dimensions()) {
                    foundRole = requiredRef;
                }
            }
            // FIXME(SH): unneeded?
            //            // just check definite binding ambiguity:
            //            adjustRoleToLiftTo(scope, provided, requiredRef, location);
        }
        if (foundRole != null) {
            // success by translation
            if (required.dimensions() == 0)
                return foundRole;
            else
                return scope.createArrayType(foundRole, required.dimensions());
        }
    }
    return null;
}

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

License:Open Source License

/** Get Typebindings for all enhancing arguments. */
private static TypeBinding[] getEnhancingArgTypes(Scope scope) {
    //{OTDyn: configurable:
    if (scope.compilerOptions().weavingScheme == WeavingScheme.OTDRE)
        return new TypeBinding[] { scope.getType(IOTConstants.ORG_OBJECTTEAMS_IBOUNDBASE2, 3), // _OT$baseArg
                scope.createArrayType(scope.getOrgObjectteamsITeam(), 1), // _OT$teams
                TypeBinding.INT, // _OT$index
                scope.createArrayType(TypeBinding.INT, 1), // _OT$callinIds
                TypeBinding.INT, // _OT$boundMethodId 
                scope.createArrayType(scope.getJavaLangObject(), 1), // _OT$args            
        };//w  ww  . j a v a  2s. c o  m
    // SH}
    // {OT/JamVM support:
    else if (JAMVM_ASPECTBI)
        return new TypeBinding[] { scope.getJavaLangObject(), // _OT$teamIterator
                TypeBinding.INT, // _OT$bindIdx
                TypeBinding.INT, // _OT$baseMethodTag
                scope.createArrayType(scope.getJavaLangObject(), 1), // _OT$unusedArgs
        };
    // CH}
    return new TypeBinding[] { scope.createArrayType(scope.getOrgObjectteamsITeam(), 1), // _OT$teams
            scope.createArrayType(TypeBinding.INT, 1), // _OT$teamIDs
            TypeBinding.INT, // _OT$idx
            TypeBinding.INT, // _OT$bindIdx
            TypeBinding.INT, // _OT$baseMethodTag
            scope.createArrayType(scope.getJavaLangObject(), 1), // _OT$unusedArgs
    };
}