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

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

Introduction

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

Prototype

TypeBinding leafComponentType

To view the source code for org.eclipse.jdt.internal.compiler.lookup ArrayBinding leafComponentType.

Click Source Link

Usage

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

License:Open Source License

public MethodBinding findMethodForArray(ArrayBinding receiverType, char[] selector, TypeBinding[] argumentTypes,
        InvocationSite invocationSite) {

    TypeBinding leafType = receiverType.leafComponentType();
    if (leafType instanceof ReferenceBinding) {
        if (!((ReferenceBinding) leafType).canBeSeenBy(this))
            return new ProblemMethodBinding(selector, Binding.NO_PARAMETERS, (ReferenceBinding) leafType,
                    ProblemReasons.ReceiverTypeNotVisible);
    }// w  ww  .  jav a2  s . c o  m

    ReferenceBinding object = getJavaLangObject();
    MethodBinding methodBinding = object.getExactMethod(selector, argumentTypes, null);
    if (methodBinding != null) {
        // handle the method clone() specially... cannot be protected or throw exceptions
        if (argumentTypes == Binding.NO_PARAMETERS) {
            switch (selector[0]) {
            case 'c':
                if (CharOperation.equals(selector, TypeConstants.CLONE)) {
                    return environment().computeArrayClone(methodBinding);
                }
                break;
            case 'g':
                if (CharOperation.equals(selector, TypeConstants.GETCLASS)
                        && methodBinding.returnType.isParameterizedType()/*1.5*/) {
                    return environment().createGetClassMethod(receiverType, methodBinding, this);
                }
                break;
            }
        }
        if (methodBinding.canBeSeenBy(receiverType, invocationSite, this))
            return methodBinding;
    }
    methodBinding = findMethod(object, selector, argumentTypes, invocationSite);
    if (methodBinding == null)
        return new ProblemMethodBinding(selector, argumentTypes, ProblemReasons.NotFound);
    return methodBinding;
}

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) {/* www  .ja va 2  s .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.util.TypeAnalyzer.java

License:Open Source License

/**
 * Are type compatible possibly performing role type adjustment?
 * @param currentType//from   w  w  w .j  ava  2  s .c  o  m
 * @param subTeam
 * @param tsuperType
 * @param superTeam
 * @param matchKind
 * @return the answer
 */
public static boolean areTypesMatchable(TypeBinding currentType, ReferenceBinding subTeam,
        TypeBinding tsuperType, ReferenceBinding superTeam, int matchKind) {
    // be very defensive:
    if (currentType instanceof ProblemReferenceBinding) {
        TypeBinding closestMatch = ((ProblemReferenceBinding) currentType).closestMatch();
        if (closestMatch == null)
            return CharOperation.equals(currentType.sourceName(), tsuperType.sourceName());
        currentType = closestMatch;
    }
    if (tsuperType instanceof ProblemReferenceBinding) {
        TypeBinding closestMatch = ((ProblemReferenceBinding) tsuperType).closestMatch();
        if (closestMatch == null)
            return CharOperation.equals(currentType.sourceName(), tsuperType.sourceName());
        tsuperType = closestMatch;
    }

    // if it's array-types, compare dimension and extract leafComponentType
    if ((currentType instanceof ArrayBinding) || (tsuperType instanceof ArrayBinding)) {
        if (!(tsuperType instanceof ArrayBinding) || !(currentType instanceof ArrayBinding))
            return false;
        ArrayBinding currentArray = (ArrayBinding) currentType;
        ArrayBinding superArray = (ArrayBinding) tsuperType;
        if (currentArray.dimensions() != superArray.dimensions())
            return false;
        currentType = currentArray.leafComponentType();
        tsuperType = superArray.leafComponentType();
    }

    // guaranteed to be scalar now
    if (currentType instanceof ReferenceBinding) {
        if (currentType instanceof DependentTypeBinding)
            currentType = ((DependentTypeBinding) currentType).getRealType();
        if (!(tsuperType instanceof ReferenceBinding))
            return false;
        if (tsuperType instanceof DependentTypeBinding)
            tsuperType = ((DependentTypeBinding) tsuperType).getRealType();
        if (currentType.isParameterizedType() || tsuperType.isParameterizedType()) {
            // at least one type parameterized: get erasure(s)
            if (currentType.isParameterizedType()) {
                if (tsuperType.isParameterizedType()) {
                    // both parameterized: check parameters:
                    ParameterizedTypeBinding currentParameterized = ((ParameterizedTypeBinding) currentType);
                    ParameterizedTypeBinding tsuperParameterized = ((ParameterizedTypeBinding) tsuperType);
                    if (!CharOperation.equals(currentParameterized.genericTypeSignature,
                            tsuperParameterized.genericTypeSignature))
                        return false;
                } else if (!tsuperType.isRawType()) {
                    return false; // mismatch generic vs. non-generic
                }

            } else if (!currentType.isRawType()) {
                return false; // mismatch non-generic vs. generic
            }
            currentType = currentType.erasure();
            tsuperType = tsuperType.erasure();
        }
        if (currentType.isTypeVariable() && tsuperType.isTypeVariable())
            return TypeBinding.equalsEquals(currentType, tsuperType);

        char[][] tname1 = compoundNameOfReferenceType((ReferenceBinding) tsuperType, true, true);
        char[][] tname2 = compoundNameOfReferenceType((ReferenceBinding) currentType, true, true);
        if (CharOperation.equals(tname1, tname2)) {
            if (TypeBinding.notEquals(tsuperType, currentType) && tsuperType.isValidBinding()) // don't complain about different missing types
                throw new InternalCompilerError(
                        "different bindings for the same type??" + currentType + ':' + tsuperType); //$NON-NLS-1$
            return true;
        }
        if (matchKind == EXACT_MATCH_ONLY) {
            return false;
        } else {
            tname1 = splitTypeNameRelativeToTeam((ReferenceBinding) tsuperType, superTeam);
            tname2 = splitTypeNameRelativeToTeam((ReferenceBinding) currentType, subTeam);
            if (!CharOperation.equals(tname1, tname2))
                return false;
        }
    } else if (currentType instanceof BaseTypeBinding) {
        if (TypeBinding.notEquals(currentType, tsuperType))
            return false;
    } else {
        throw new InternalCompilerError("matching of unexpected type kind: " + currentType); //$NON-NLS-1$
    }
    return true;
}