Example usage for org.eclipse.jdt.internal.compiler.lookup TypeConstants INT

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

Introduction

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

Prototype

null INT

To view the source code for org.eclipse.jdt.internal.compiler.lookup TypeConstants INT.

Click Source Link

Usage

From source file:lombok.eclipse.handlers.EclipseHandlerUtil.java

License:Open Source License

public static TypeReference makeType(TypeBinding binding, ASTNode pos, boolean allowCompound) {
    int dims = binding.dimensions();
    binding = binding.leafComponentType();

    // Primitives

    char[] base = null;

    switch (binding.id) {
    case TypeIds.T_int:
        base = TypeConstants.INT;
        break;//from  w w w  . j av  a2  s  .  c om
    case TypeIds.T_long:
        base = TypeConstants.LONG;
        break;
    case TypeIds.T_short:
        base = TypeConstants.SHORT;
        break;
    case TypeIds.T_byte:
        base = TypeConstants.BYTE;
        break;
    case TypeIds.T_double:
        base = TypeConstants.DOUBLE;
        break;
    case TypeIds.T_float:
        base = TypeConstants.FLOAT;
        break;
    case TypeIds.T_boolean:
        base = TypeConstants.BOOLEAN;
        break;
    case TypeIds.T_char:
        base = TypeConstants.CHAR;
        break;
    case TypeIds.T_void:
        base = TypeConstants.VOID;
        break;
    case TypeIds.T_null:
        return null;
    }

    if (base != null) {
        if (dims > 0) {
            TypeReference result = new ArrayTypeReference(base, dims, pos(pos));
            setGeneratedBy(result, pos);
            return result;
        }
        TypeReference result = new SingleTypeReference(base, pos(pos));
        setGeneratedBy(result, pos);
        return result;
    }

    if (binding.isAnonymousType()) {
        ReferenceBinding ref = (ReferenceBinding) binding;
        ReferenceBinding[] supers = ref.superInterfaces();
        if (supers == null || supers.length == 0)
            supers = new ReferenceBinding[] { ref.superclass() };
        if (supers[0] == null) {
            TypeReference result = new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, poss(pos, 3));
            setGeneratedBy(result, pos);
            return result;
        }
        return makeType(supers[0], pos, false);
    }

    if (binding instanceof CaptureBinding) {
        return makeType(((CaptureBinding) binding).wildcard, pos, allowCompound);
    }

    if (binding.isUnboundWildcard()) {
        if (!allowCompound) {
            TypeReference result = new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, poss(pos, 3));
            setGeneratedBy(result, pos);
            return result;
        } else {
            Wildcard out = new Wildcard(Wildcard.UNBOUND);
            setGeneratedBy(out, pos);
            out.sourceStart = pos.sourceStart;
            out.sourceEnd = pos.sourceEnd;
            return out;
        }
    }

    if (binding.isWildcard()) {
        WildcardBinding wildcard = (WildcardBinding) binding;
        if (wildcard.boundKind == Wildcard.EXTENDS) {
            if (!allowCompound) {
                return makeType(wildcard.bound, pos, false);
            } else {
                Wildcard out = new Wildcard(Wildcard.EXTENDS);
                setGeneratedBy(out, pos);
                out.bound = makeType(wildcard.bound, pos, false);
                out.sourceStart = pos.sourceStart;
                out.sourceEnd = pos.sourceEnd;
                return out;
            }
        } else if (allowCompound && wildcard.boundKind == Wildcard.SUPER) {
            Wildcard out = new Wildcard(Wildcard.SUPER);
            setGeneratedBy(out, pos);
            out.bound = makeType(wildcard.bound, pos, false);
            out.sourceStart = pos.sourceStart;
            out.sourceEnd = pos.sourceEnd;
            return out;
        } else {
            TypeReference result = new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, poss(pos, 3));
            setGeneratedBy(result, pos);
            return result;
        }
    }

    // Keep moving up via 'binding.enclosingType()' and gather generics from each binding. We stop after a local type, or a static type, or a top-level type.
    // Finally, add however many nullTypeArgument[] arrays as that are missing, inverse the list, toArray it, and use that as PTR's typeArgument argument.

    List<TypeReference[]> params = new ArrayList<TypeReference[]>();
    /* Calculate generics */ {
        TypeBinding b = binding;
        while (true) {
            boolean isFinalStop = b.isLocalType() || !b.isMemberType() || b.enclosingType() == null;

            TypeReference[] tyParams = null;
            if (b instanceof ParameterizedTypeBinding) {
                ParameterizedTypeBinding paramized = (ParameterizedTypeBinding) b;
                if (paramized.arguments != null) {
                    tyParams = new TypeReference[paramized.arguments.length];
                    for (int i = 0; i < tyParams.length; i++) {
                        tyParams[i] = makeType(paramized.arguments[i], pos, true);
                    }
                }
            }

            params.add(tyParams);
            if (isFinalStop)
                break;
            b = b.enclosingType();
        }
    }

    char[][] parts;

    if (binding.isTypeVariable()) {
        parts = new char[][] { binding.shortReadableName() };
    } else if (binding.isLocalType()) {
        parts = new char[][] { binding.sourceName() };
    } else {
        String[] pkg = new String(binding.qualifiedPackageName()).split("\\.");
        String[] name = new String(binding.qualifiedSourceName()).split("\\.");
        if (pkg.length == 1 && pkg[0].isEmpty())
            pkg = new String[0];
        parts = new char[pkg.length + name.length][];
        int ptr;
        for (ptr = 0; ptr < pkg.length; ptr++)
            parts[ptr] = pkg[ptr].toCharArray();
        for (; ptr < pkg.length + name.length; ptr++)
            parts[ptr] = name[ptr - pkg.length].toCharArray();
    }

    while (params.size() < parts.length)
        params.add(null);
    Collections.reverse(params);

    boolean isParamized = false;

    for (TypeReference[] tyParams : params) {
        if (tyParams != null) {
            isParamized = true;
            break;
        }
    }
    if (isParamized) {
        if (parts.length > 1) {
            TypeReference[][] typeArguments = params.toArray(new TypeReference[0][]);
            TypeReference result = new ParameterizedQualifiedTypeReference(parts, typeArguments, dims,
                    poss(pos, parts.length));
            setGeneratedBy(result, pos);
            return result;
        }
        TypeReference result = new ParameterizedSingleTypeReference(parts[0], params.get(0), dims, pos(pos));
        setGeneratedBy(result, pos);
        return result;
    }

    if (dims > 0) {
        if (parts.length > 1) {
            TypeReference result = new ArrayQualifiedTypeReference(parts, dims, poss(pos, parts.length));
            setGeneratedBy(result, pos);
            return result;
        }
        TypeReference result = new ArrayTypeReference(parts[0], dims, pos(pos));
        setGeneratedBy(result, pos);
        return result;
    }

    if (parts.length > 1) {
        TypeReference result = new QualifiedTypeReference(parts, poss(pos, parts.length));
        setGeneratedBy(result, pos);
        return result;
    }
    TypeReference result = new SingleTypeReference(parts[0], pos(pos));
    setGeneratedBy(result, pos);
    return result;
}

From source file:lombok.eclipse.handlers.HandleConstructor.java

License:Open Source License

private static Expression getDefaultExpr(TypeReference type, int s, int e) {
    char[] lastToken = type.getLastToken();
    if (Arrays.equals(TypeConstants.BOOLEAN, lastToken))
        return new FalseLiteral(s, e);
    if (Arrays.equals(TypeConstants.CHAR, lastToken))
        return new CharLiteral(new char[] { '\'', '\\', '0', '\'' }, s, e);
    if (Arrays.equals(TypeConstants.BYTE, lastToken) || Arrays.equals(TypeConstants.SHORT, lastToken)
            || Arrays.equals(TypeConstants.INT, lastToken))
        return IntLiteral.buildIntLiteral(new char[] { '0' }, s, e);
    if (Arrays.equals(TypeConstants.LONG, lastToken))
        return LongLiteral.buildLongLiteral(new char[] { '0', 'L' }, s, e);
    if (Arrays.equals(TypeConstants.FLOAT, lastToken))
        return new FloatLiteral(new char[] { '0', 'F' }, s, e);
    if (Arrays.equals(TypeConstants.DOUBLE, lastToken))
        return new DoubleLiteral(new char[] { '0', 'D' }, s, e);

    return new NullLiteral(s, e);
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lifting.ArrayTranslations.java

License:Open Source License

/**
 *    for(int i0=0;i0 < role.length;i0++)
 *   {//from   w ww . ja v  a  2s. c o m
 *      result = new Base[role.length][][];
 *      for(...){
 *         ...
 *            for(int i2=0;i2 < role[i0][i1].length;i2++){
 *                 result[i0][i1][i2] = translate(role[i0][i1][i2]);
 *             }
 *          ...
 *       }
 *   }
 * @param currentDimension counter for recursion only. invoke initially with 0.
 * @param arrayDimensions maximum of dimensions of the array
 * @return the new created ForStatement with all subcycles
 */
private ForStatement generateForStatement(int currentDimension, int arrayDimensions, AstGenerator gen) {

    Statement[] init = new Statement[1];
    char[] name = generateArrayIndexName(currentDimension);

    LocalDeclaration initializer = new LocalDeclaration(name, 0, 0);
    initializer.initialization = IntLiteral.buildIntLiteral("0".toCharArray(), 0, 0); //$NON-NLS-1$
    initializer.type = new SingleTypeReference(TypeConstants.INT, 0);
    init[0] = initializer;

    SingleNameReference condLeft = new SingleNameReference(name, 0);

    FieldReference condRight = new FieldReference(IOTConstants.LENGTH, 0);
    SingleNameReference roleNameReference = gen.singleNameReference(ROLE_ARRAY_ARG);
    decapsulationInput(roleNameReference);

    Expression lastArrayReference = roleNameReference;

    for (int idx = 0; idx < currentDimension; idx++) {
        SingleNameReference pos = new SingleNameReference(generateArrayIndexName(idx), 0);
        ArrayReference nextArray = new ArrayReference(lastArrayReference, pos);
        lastArrayReference = nextArray;
    }
    condRight.receiver = lastArrayReference;

    Expression cond = new BinaryExpression(condLeft, condRight, OperatorIds.LESS);
    Statement[] inc = new Statement[1];

    inc[0] = new PostfixExpression(new SingleNameReference(name, 0), IntLiteral.One, OperatorIds.PLUS, 0);

    Block action = new Block(0);

    // result = new Base[role.length][][];
    Assignment arrayInstantiation = generateArrayInstantiation(currentDimension + 1, arrayDimensions, gen);

    // if(r1 == null)continue;
    IfStatement ifStatement = generateIfStatement(currentDimension + 1, arrayDimensions);

    if (currentDimension < arrayDimensions - 1) {
        ForStatement innerForStatement = generateForStatement(currentDimension + 1, arrayDimensions, gen);
        action.statements = new Statement[3];
        action.statements[0] = ifStatement;
        action.statements[1] = arrayInstantiation;
        action.statements[2] = innerForStatement;
    } else {
        action.statements = new Statement[2];
        action.statements[0] = ifStatement;
        action.statements[1] = arrayInstantiation;
    }

    // for(;i0 < role.length;i0++)
    ForStatement outerForStatement = new ForStatement(init, cond, inc, action, true, 0, 0);

    return outerForStatement;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.MethodSignatureEnhancer.java

License:Open Source License

private Argument[] internalEnhanceArguments(Argument[] arguments, char[] namePrefix, boolean isWrapper,
        AstGenerator gen) {//from  w ww  .  j  a  va  2s  .  com
    int fullLen = this.ENHANCING_ARG_LEN;
    if (arguments != null)
        fullLen += arguments.length; // source arguments?
    Argument[] newArgs = new Argument[fullLen];
    TypeReference[] enhanceTypes =
            //{OTDyn: configurable:
            this.weavingScheme == WeavingScheme.OTDRE
                    ? new TypeReference[] { gen.qualifiedTypeReference(ORG_OBJECTTEAMS_IBOUNDBASE2), // _OT$baseArg
                            gen.qualifiedArrayTypeReference(ORG_OBJECTTEAMS_ITEAM, 1), // _OT$teams
                            gen.singleTypeReference(TypeConstants.INT), // _OT$index
                            new ArrayTypeReference(TypeConstants.INT, 1, gen.pos), // _OT$callinIds
                            gen.singleTypeReference(TypeConstants.INT), // _OT$boundMethodId
                            gen.qualifiedArrayTypeReference(JAVA_LANG_OBJECT, 1), // _OT$args
                    }
                    // SH}
                    // {OT/JamVM support:
                    : JAMVM_ASPECTBI
                            ? new TypeReference[] { gen.qualifiedTypeReference(JAVA_LANG_OBJECT),
                                    gen.singleTypeReference(TypeConstants.INT),
                                    gen.singleTypeReference(TypeConstants.INT),
                                    gen.qualifiedArrayTypeReference(JAVA_LANG_OBJECT, 1), }
                            // CH}
                            : new TypeReference[] { gen.qualifiedArrayTypeReference(ORG_OBJECTTEAMS_ITEAM, 1),
                                    new ArrayTypeReference(TypeConstants.INT, 1, gen.pos),
                                    gen.singleTypeReference(TypeConstants.INT),
                                    gen.singleTypeReference(TypeConstants.INT),
                                    gen.singleTypeReference(TypeConstants.INT),
                                    gen.qualifiedArrayTypeReference(JAVA_LANG_OBJECT, 1), };
    int prefixLen = 0;
    // base arg?
    if (isWrapper && arguments != null)
        newArgs[prefixLen++] = arguments[0];
    // enhancing args:
    for (int i = 0; i < this.ENHANCING_ARG_LEN; i++)
        newArgs[i + prefixLen] = gen.argument(CharOperation.concat(namePrefix, this.ENHANCING_ARG_NAMES[i]),
                enhanceTypes[i], AccFinal);
    // source args:
    if (arguments != null)
        System.arraycopy(arguments, prefixLen, newArgs, this.ENHANCING_ARG_LEN + prefixLen,
                arguments.length - prefixLen);

    return newArgs;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.TeamMethodGenerator.java

License:Open Source License

/** create field ASTs. */
@SuppressWarnings("nls")
void addFields(TypeDeclaration teamDecl, AstGenerator gen) {
    // private WeakHashMap<Thread, Boolean> _OT$activatedThreads = new WeakHashMap<Thread, Boolean>();
    addPrivateField(teamDecl, gen, weakHashMapTypeReference(gen), "_OT$activatedThreads".toCharArray(),
            gen.allocation(weakHashMapTypeReference(gen), null));

    // private Object _OT$registrationLock= new Object();
    addPrivateField(teamDecl, gen, gen.qualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT),
            "_OT$registrationLock".toCharArray(),
            gen.allocation(gen.qualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT), null));

    // private boolean _OT$lazyGlobalActiveFlag = false;
    addPrivateField(teamDecl, gen, gen.baseTypeReference(TypeConstants.BOOLEAN),
            "_OT$lazyGlobalActiveFlag".toCharArray(), gen.booleanLiteral(false));

    // private boolean _OT$isExecutingCallin = false;
    addPrivateField(teamDecl, gen, gen.baseTypeReference(TypeConstants.BOOLEAN),
            "_OT$isExecutingCallin".toCharArray(), gen.booleanLiteral(false));

    // private  int _OT$registrationState = _OT$UNREGISTERED;
    addPrivateField(teamDecl, gen, gen.baseTypeReference(TypeConstants.INT),
            "_OT$registrationState".toCharArray(), gen.intLiteral(0));

    // private boolean _OT$globalActive = false;
    addPrivateField(teamDecl, gen, gen.baseTypeReference(TypeConstants.BOOLEAN),
            "_OT$globalActive".toCharArray(), gen.booleanLiteral(false));

    // private ThreadLocal<Integer> _OT$implicitActivationsPerThread = new ThreadLocal<Integer>() {
    //       protected synchronized Integer initialValue() {
    //          return Integer.valueOf(0);
    //       }//  w  w  w . java 2s.c  om
    // };
    TypeDeclaration anonThreadLocal = gen.anonymousType(teamDecl.compilationResult);
    anonThreadLocal.methods = new MethodDeclaration[] {
            gen.method(teamDecl.compilationResult, AccProtected | AccSynchronized,
                    gen.qualifiedTypeReference(TypeConstants.JAVA_LANG_INTEGER), "initialValue".toCharArray(),
                    null/*arguments*/, new Statement[] { gen.returnStatement(gen.intLiteral(0)) // rely on autoboxing   
                    }) };
    addPrivateField(teamDecl, gen, threadLocalReference(gen), "_OT$implicitActivationsPerThread".toCharArray(),
            gen.anonymousAllocation(threadLocalReference(gen), null/*arguments*/, anonThreadLocal));
}