Example usage for org.eclipse.jdt.internal.compiler.lookup UnresolvedReferenceBinding getPackage

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

Introduction

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

Prototype

@Override
    public PackageBinding getPackage() 

Source Link

Usage

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator.java

License:Open Source License

public static TypeBinding maybeWrapUnqualifiedRoleType(final Scope scope, final ReferenceBinding site,
        TypeBinding typeToWrap, final ASTNode typedNode, ProblemReporter problemReporter) {
    assert (!(site == null));
    if (typeToWrap == null)
        return null;
    if (!typeToWrap.isValidBinding())
        return typeToWrap; // don't tamper with already broken type

    if (TSuperHelper.isMarkerInterface(typeToWrap))
        return typeToWrap;

    final TypeBinding originalType = typeToWrap;

    // consider arrays:
    int dimensions = typeToWrap.dimensions();
    typeToWrap = typeToWrap.leafComponentType();

    // consider parameterized:
    TypeBinding[] arguments = null;/*from  ww w .  ja v a2s  . c  o  m*/
    if (typeToWrap.isParameterizedType())
        arguments = ((ParameterizedTypeBinding) typeToWrap).arguments;

    // easy problems first:
    if (!(typeToWrap instanceof ReferenceBinding) || typeToWrap.isEnum())
        return originalType;

    if (typeToWrap instanceof UnresolvedReferenceBinding) {
        // defer wrapping until resolve():
        final UnresolvedReferenceBinding rawUnresolved = (UnresolvedReferenceBinding) typeToWrap;
        final ProblemReporter originalReporter = problemReporter;
        return new UnresolvedReferenceBinding(rawUnresolved.compoundName, rawUnresolved.getPackage()) {
            @Override
            public ReferenceBinding resolve(LookupEnvironment environment, boolean convertGenericToRawType) {
                ReferenceBinding type = rawUnresolved.resolve(environment, convertGenericToRawType);
                return (ReferenceBinding) maybeWrapUnqualifiedRoleType(scope, site, type, typedNode,
                        originalReporter);
            }

            @Override
            public boolean hasTypeAnnotations() {
                return rawUnresolved.hasTypeAnnotations();
            }

            @Override
            public boolean hasNullTypeAnnotations() {
                return rawUnresolved.hasNullTypeAnnotations();
            }

            @Override
            public AnnotationBinding[] getAnnotations() {
                return rawUnresolved.getAnnotations();
            }

            {
                this.tagBits = rawUnresolved.tagBits;
            }
        };
    }
    if (typeToWrap instanceof IntersectionTypeBinding18) { // FIXME (recurse?)
        return originalType;
    }
    ReferenceBinding refBinding = (ReferenceBinding) typeToWrap;
    if (!refBinding.isDirectRole()) {
        final ProblemReporter reporter = problemReporter;
        return originalType.maybeWrapRoleType(typedNode, new TypeArgumentUpdater() {
            public TypeBinding updateArg(ReferenceBinding arg) {
                return maybeWrapUnqualifiedRoleType(scope, site, arg, typedNode, reporter);
            }
        });
    }

    // already wrapped:
    if (typeToWrap instanceof RoleTypeBinding) {
        RoleTypeBinding roleType = (RoleTypeBinding) typeToWrap;
        if (!(roleType._teamAnchor instanceof TThisBinding)) {
            return originalType; // cannot improve
        } else {
            // do handle tthis RoleTypeBindings, too, because we might need to
            // set a new anchor
            // (but don't report errors, if this type is already acceptable).
            if (TeamModel.findEnclosingTeamContainingRole(site, roleType) != null)
                problemReporter = null;
        }
    }

    VariableBinding variableBinding = null;
    ReferenceBinding teamBinding = TeamModel.findEnclosingTeamContainingRole(site, refBinding);
    if (teamBinding != null)
        variableBinding = TThisBinding.getTThisForRole(refBinding, teamBinding);
    if (variableBinding == null)
        variableBinding = cannotWrapType(refBinding, problemReporter, typedNode);

    // handle problems (reported ones and yet unreported ones):
    assert (variableBinding != null);
    if (variableBinding == RoleTypeBinding.NoAnchor) {
        return originalType;
    } else if (!variableBinding.isFinal()) {
        if (problemReporter != null)
            problemReporter.anchorPathNotFinal(null, variableBinding, refBinding.sourceName()); // TODO
        return null;
    } else if (!(variableBinding instanceof TThisBinding) && !refBinding.isPublic()) {
        if (problemReporter != null)
            problemReporter.externalizingNonPublicRole(typedNode, refBinding);
        return null;
    }

    // delegate to the principal function:
    return getAnchoredType(scope, typedNode, variableBinding, refBinding, arguments, dimensions);
}