Example usage for org.eclipse.jdt.internal.compiler.lookup TypeBinding constantPoolName

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

Introduction

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

Prototype

public abstract char[] constantPoolName();

Source Link

Document

Answer the receiver's constant pool name.

Usage

From source file:com.google.gwt.dev.javac.JdtUtil.java

License:Apache License

public static String signature(TypeBinding binding) {
    if (binding.isBaseType()) {
        return String.valueOf(binding.sourceName());
    } else {/*  w ww .  ja  va2s  .c  o  m*/
        return String.valueOf(binding.constantPoolName());
    }
}

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

License:Open Source License

public SyntheticMethodBinding addSyntheticMethodForSwitchEnum(TypeBinding enumBinding) {
    if (this.synthetics == null)
        this.synthetics = new HashMap[MAX_SYNTHETICS];
    if (this.synthetics[SourceTypeBinding.METHOD_EMUL] == null)
        this.synthetics[SourceTypeBinding.METHOD_EMUL] = new HashMap(5);

    SyntheticMethodBinding accessMethod = null;
    char[] selector = CharOperation.concat(TypeConstants.SYNTHETIC_SWITCH_ENUM_TABLE,
            enumBinding.constantPoolName());
    CharOperation.replace(selector, '/', '$');
    final String key = new String(selector);
    SyntheticMethodBinding[] accessors = (SyntheticMethodBinding[]) this.synthetics[SourceTypeBinding.METHOD_EMUL]
            .get(key);/*from   w  w  w.  j  a va 2  s  .  c o  m*/
    // first add the corresponding synthetic field
    if (accessors == null) {
        // then create the synthetic method
        final SyntheticFieldBinding fieldBinding = addSyntheticFieldForSwitchEnum(selector, key);
        accessMethod = new SyntheticMethodBinding(fieldBinding, this, enumBinding, selector);
        this.synthetics[SourceTypeBinding.METHOD_EMUL].put(key, accessors = new SyntheticMethodBinding[2]);
        accessors[0] = accessMethod;
    } else {
        if ((accessMethod = accessors[0]) == null) {
            final SyntheticFieldBinding fieldBinding = addSyntheticFieldForSwitchEnum(selector, key);
            accessMethod = new SyntheticMethodBinding(fieldBinding, this, enumBinding, selector);
            accessors[0] = accessMethod;
        }
    }
    return accessMethod;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.model.TeamModel.java

License:Open Source License

/**
 * Get the most suitable RoleTypeBinding for roleType in a tthis context defined by scope.
 * Strengthening reverses the effect of signature weakening.
 *
 * (Used for determining the statically known role type for lifting)
 *
 * @param site     (guaranteed to be within the context of a team)
 * @param roleType (guaranteed to be a role or an array thereof)
 * @return found role - need not be a RoleTypeBinding
 *//*from   w  w w.  ja v a  2s  .  com*/
public static TypeBinding strengthenRoleType(ReferenceBinding site, TypeBinding roleType) {
    ReferenceBinding enclosingTeam = site;
    enclosingTeam = normalizeTeam(enclosingTeam);
    if (!enclosingTeam.isTeam())
        enclosingTeam = getEnclosingTeam(site);
    if (enclosingTeam == null)
        return roleType; // this site cannot strengthen the role type.
    if (roleType.isLocalType())
        return roleType;
    int dimensions = roleType.dimensions();
    ReferenceBinding roleRefType = (ReferenceBinding) roleType.leafComponentType();
    ReferenceBinding roleEnclosing = roleRefType.enclosingType();
    if (roleEnclosing.isRole() && TypeBinding.notEquals(roleEnclosing.erasure(), site.erasure())) {
        // first strengthen enclosing team if it is nested:
        ReferenceBinding strengthenedEnclosing = null;
        if (TypeBinding.notEquals(roleEnclosing.erasure().enclosingType(),
                enclosingTeam.erasure().enclosingType()))
            strengthenedEnclosing = (ReferenceBinding) strengthenRoleType(site, roleEnclosing);
        if (strengthenedEnclosing != null
                && TypeBinding.notEquals(strengthenedEnclosing.erasure(), site.erasure())) {
            // we indeed found a better site, so start over:
            return strengthenRoleType(strengthenedEnclosing, roleType);
        }
    }
    // check success:
    if (!(roleRefType.isRole() // need a role
            && areCompatibleEnclosings(enclosingTeam, roleEnclosing))) // teams must be compatible
    {
        if (enclosingTeam.isRole()) // try via outer team:
            return strengthenRoleType(enclosingTeam.enclosingType(), roleType);
        return roleType;
    }
    if (roleRefType instanceof RoleTypeBinding) {
        RoleTypeBinding rtb = (RoleTypeBinding) roleRefType;

        if (!(rtb._teamAnchor instanceof TThisBinding))
            return roleType; // don't instantiate explicit team anchor.
    }
    // lookup adjusted role type:
    roleRefType = enclosingTeam.getMemberType(roleRefType.internalName());
    if (roleRefType == null) {
        if (enclosingTeam.isBinaryBinding()) {
            ReferenceBinding current = enclosingTeam;
            // search a role type to report against (for aborting):
            while (current != null && current.isBinaryBinding())
                current = current.enclosingType();
            if (current != null) {
                Scope scope = ((SourceTypeBinding) current).scope;
                if (scope != null) {
                    scope.problemReporter().missingRoleInBinaryTeam(roleType.constantPoolName(), enclosingTeam);
                    return null;
                }
            }
        }
        if (Protections.hasClassKindProblem(enclosingTeam))
            return roleType; // can't do better..
        if (!enclosingTeam.isBinaryBinding()) {
            Scope scope = ((SourceTypeBinding) enclosingTeam.getRealType()).scope;
            scope.problemReporter().missingCopiedRole(roleType, enclosingTeam);
        } else if (!site.isBinaryBinding()) {
            Scope scope = ((SourceTypeBinding) site.getRealType()).scope;
            scope.problemReporter().missingCopiedRole(roleType, enclosingTeam);
        } else {
            throw new InternalCompilerError("could not find role " + String.valueOf(roleType.constantPoolName()) //$NON-NLS-1$
                    + " in " + String.valueOf(site.constantPoolName()) + " and could not report regularly"); //$NON-NLS-1$ //$NON-NLS-2$
        }
        return roleType; // can't do better, but shouldn't reach here, because missingCopiedRole triggers AbortType.
    }
    VariableBinding anchor = enclosingTeam.getTeamModel().getTThis();
    if (roleType.isParameterizedType()) {
        // consult original role type for type arguments & type annotations:
        ParameterizedTypeBinding ptb = (ParameterizedTypeBinding) roleType;
        TypeBinding parameterized = ptb.environment.createParameterizedType(roleRefType, ptb.arguments, anchor,
                -1, roleRefType.enclosingType(), ptb.getTypeAnnotations());
        if (dimensions > 0)
            return ptb.environment.createArrayType(parameterized, dimensions);
        return parameterized;
    }
    return anchor.getRoleTypeBinding(roleRefType, dimensions);
}