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

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

Introduction

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

Prototype

public final TypeBinding getType(char[] name) 

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:/*www  .  ja  va2  s .c o m*/
    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.util.TSuperHelper.java

License:Open Source License

public static TypeBinding getMarkerInterface(Scope scope, ReferenceBinding superteam) {
    return scope.getType(TSuperHelper.getTSuperMarkName(superteam));
}

From source file:org.eclipse.recommenders.internal.chain.rcp.TypeBindingAnalyzer.java

License:Open Source License

public static List<Optional<TypeBinding>> resolveBindingsForExpectedTypes(
        final IRecommendersCompletionContext ctx, final Scope scope) {
    final InternalCompletionContext context = (InternalCompletionContext) ctx.getJavaContext().getCoreContext();
    final ASTNode parent = context.getCompletionNodeParent();
    final List<Optional<TypeBinding>> bindings = Lists.newLinkedList();
    if (parent instanceof LocalDeclaration) {
        bindings.add(Optional.fromNullable(((LocalDeclaration) parent).type.resolvedType));
    } else if (parent instanceof ReturnStatement) {
        bindings.add(resolveReturnStatement(context));
    } else if (parent instanceof FieldDeclaration) {
        bindings.add(Optional.fromNullable(((FieldDeclaration) parent).type.resolvedType));
    } else if (parent instanceof Assignment) {
        bindings.add(Optional.fromNullable(((Assignment) parent).resolvedType));
    } else if (isCompletionOnMethodParameter(context)) {
        for (final ITypeName type : ctx.getExpectedTypeNames()) {
            bindings.add(Optional.of(scope.getType(type.getClassName().toCharArray())));
        }/*from  w  ww  .ja  va  2 s.  com*/
    } else {
        log(WARNING_CANNOT_USE_AS_PARENT_OF_COMPLETION_LOCATION, parent.getClass());
    }
    return bindings;
}