Example usage for org.eclipse.jdt.internal.compiler.lookup ArrayBinding ArrayBinding

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

Introduction

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

Prototype

public ArrayBinding(TypeBinding type, int dimensions, LookupEnvironment environment) 

Source Link

Usage

From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java

License:Open Source License

public ArrayBinding createArrayType(TypeBinding type, int dimension) {
    if (type.isValidBinding())
        return environment().createArrayType(type, dimension);
    // do not cache obvious invalid types
    return new ArrayBinding(type, dimension, environment());
}

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

License:Open Source License

private TypeBinding internalResolveType(BlockScope scope, TypeBinding providedType, boolean testOnly) {
    this.resolvedType = this.expectedType; // be optimistic.
    TypeBinding compatibleType = compatibleType(scope, providedType);
    if (compatibleType != null)
        return testOnly ? null : compatibleType;

    TypeBinding roleSideType;//  www  .j a v  a 2s .co  m
    TypeBinding baseType;
    if (providedType.isArrayType()) {
        if (!(this.expectedType instanceof ArrayBinding))
            throw new InternalCompilerError("mapping array to scalar"); //$NON-NLS-1$
        baseType = providedType.leafComponentType();
        roleSideType = this.expectedType.leafComponentType();
    } else {
        baseType = providedType;
        roleSideType = this.expectedType;
    }
    ReferenceBinding roleType = null;
    if (!(baseType instanceof ReferenceBinding)) {
        return testOnly ? null : reportIncompatibility(scope, providedType);
    } else {
        roleType = (ReferenceBinding) roleSideType;
        if (!roleType.isDirectRole() || !(baseType instanceof ReferenceBinding))
            return testOnly ? null : reportIncompatibility(scope, providedType);
    }

    // reset Config, because below we want to check loweringRequired.
    Config oldConfig = Config.createOrResetConfig(this);
    try {
        ReferenceBinding expectedBase = roleType.baseclass();
        if (expectedBase != null && expectedBase.isParameterizedType())
            expectedBase = (ReferenceBinding) expectedBase.erasure();
        if (expectedBase == null // roleType is assigned unless incompatibilityFound, in which case we return above
                || !baseType.isCompatibleWith(expectedBase)) {
            TypeBinding adjustedRole = TeamModel.getRoleToLiftTo(scope, baseType, roleType, true,
                    this.expression);
            if (adjustedRole != null) {
                this.expectedType = adjustedRole;
            } else {
                if (providedType.isTypeVariable()) {
                    ReferenceBinding roleBound = ((TypeVariableBinding) providedType).roletype;
                    if (roleBound != null && roleBound.isRole()) {
                        generateDynamicLiftCall(scope, roleBound);
                        return this.resolvedType;
                    }
                }

                scope.problemReporter().typeMismatchErrorPotentialLift(this.expression, providedType,
                        this.expectedType, baseType);
                this.resolvedType = null;
                return null;
            }
        }
        if (roleType.isHierarchyInconsistent() || roleType.roleModel.hasBaseclassProblem()) {
            if (testOnly)
                return null;
            // don't install unresolvable liftcall
            scope.problemReporter().referenceContext.tagAsHavingErrors();
            return this.resolvedType;
        }
        if (Config.getLoweringRequired())
            throw new InternalCompilerError("Lifting would also require lowering!"); //$NON-NLS-1$
    } finally {
        Config.removeOrRestore(oldConfig, this);
    }
    if (testOnly)
        return this.expectedType;

    TypeBinding expectedBaseclass = ((ReferenceBinding) this.expectedType.leafComponentType()).baseclass();
    if (this.expectedType.isArrayType())
        expectedBaseclass = new ArrayBinding(expectedBaseclass, this.expectedType.dimensions(),
                scope.environment());
    // further conversions (cast for generic)?
    checkOtherConversions(scope, expectedBaseclass, providedType);

    // successfully recognized the need for lifting, create the lift-call now:

    // propagate the need for translation:
    if (this.liftingConfirmJob != null)
        this.liftingConfirmJob.run();

    this.rawExpression = this.expression;
    this.operator = "lift"; // redundant; //$NON-NLS-1$
    this.expression = genLiftCall(scope, providedType);
    return this.resolvedType;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.ConstantPoolObjectMapper.java

License:Open Source License

public static TypeBinding mapClass(ReferenceBinding srcTeamBinding, TypeBinding typeBinding,
        ReferenceBinding dstTeam) {/*from   w w w  . j  a  v a  2s  .c  o m*/
    boolean isArrayBinding = typeBinding instanceof ArrayBinding;
    int dimension = 0;
    TypeBinding originalType = typeBinding;
    if (isArrayBinding) {
        ArrayBinding formerType = (ArrayBinding) typeBinding;
        typeBinding = formerType.leafComponentType();
        dimension = formerType.dimensions;

        if (typeBinding.isBaseType())
            return formerType; // no need to map array of basetype
    }
    ReferenceBinding refTypeBinding = (ReferenceBinding) typeBinding;
    // if Binding points at Role-Field of Superteamclass, then mapping must be done
    if (isMappableClass(refTypeBinding)) {
        refTypeBinding = (ReferenceBinding) refTypeBinding.erasure();
        ReferenceBinding refTeamBinding = getTeam(refTypeBinding);
        if (refTeamBinding != null) {
            if (srcTeamBinding != null) {
                srcTeamBinding = (ReferenceBinding) srcTeamBinding.erasure();
                TypeBinding newBinding = null;
                ReferenceBinding currentSrcTeam = srcTeamBinding;
                ReferenceBinding currentDstTeam = dstTeam;
                while (currentSrcTeam != null && currentDstTeam != null) {
                    if (TypeBinding.equalsEquals(refTeamBinding, currentSrcTeam)) {
                        // mapping the enclosing team which is nested in an outer team?
                        if (TypeBinding.equalsEquals(refTypeBinding, refTeamBinding) && refTypeBinding.isRole())
                            newBinding = currentDstTeam;
                        else
                            newBinding = searchRoleClass(refTypeBinding, currentDstTeam);
                        break;
                    }
                    // try dependent refinement of base classes:
                    ReferenceBinding srcBase = currentSrcTeam.baseclass();
                    if (srcBase != null && (srcBase.isTeam() || srcBase.isRole())) {
                        if (TypeBinding.equalsEquals(srcBase, refTypeBinding))
                            newBinding = currentDstTeam.baseclass();
                        else
                            newBinding = searchRoleClass(refTypeBinding, currentDstTeam.baseclass());
                        if (newBinding != null)
                            break;
                    }
                    // the common team to start searching might be an enclosing:
                    if (!currentSrcTeam.isRole())
                        break;
                    currentSrcTeam = currentSrcTeam.enclosingType();
                    currentDstTeam = currentDstTeam.enclosingType();
                }
                if (newBinding != null) {
                    if (isArrayBinding) {
                        // have no scope so can't use Scope.createArray(),
                        // which otherwise should be used throughout.
                        try {
                            newBinding = new ArrayBinding(newBinding, dimension, Config.getLookupEnvironment());
                        } catch (NotConfiguredException e) {
                            e.logWarning("Cannot create array binding"); //$NON-NLS-1$
                        }
                    }
                    return newBinding;
                }
            }
        }
    }
    return originalType;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.DependentTypeBinding.java

License:Open Source License

public ArrayBinding getArrayType(int dims) {
    if ((this._arrayBindings == null) || (this._arrayBindings.length < dims)) {
        ArrayBinding[] oldArrays = this._arrayBindings;
        this._arrayBindings = new ArrayBinding[dims];
        if (oldArrays != null)
            System.arraycopy(oldArrays, 0, this._arrayBindings, 0, oldArrays.length);
    }/*w  w  w  .  j  a v  a2 s. c om*/
    if (this._arrayBindings[dims - 1] == null)
        this._arrayBindings[dims - 1] = new ArrayBinding(this, dims, this.environment);
    return this._arrayBindings[dims - 1];
}