Example usage for org.eclipse.jdt.internal.compiler.ast TrueLiteral TrueLiteral

List of usage examples for org.eclipse.jdt.internal.compiler.ast TrueLiteral TrueLiteral

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.ast TrueLiteral TrueLiteral.

Prototype

public TrueLiteral(int s, int e) 

Source Link

Usage

From source file:lombok.eclipse.handlers.ast.EclipseASTMaker.java

License:Open Source License

@Override
public ASTNode visitBooleanLiteral(final lombok.ast.BooleanLiteral node, final Void p) {
    final MagicLiteral literal;
    if (node.isTrue()) {
        literal = new TrueLiteral(0, 0);
    } else {/*  w  w  w  . ja  v a  2s.  c  om*/
        literal = new FalseLiteral(0, 0);
    }
    setGeneratedByAndCopyPos(literal, source, posHintOf(node));
    return literal;
}

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

License:Open Source License

public MethodDeclaration generateBuildMethod(String name, char[] staticName, TypeReference returnType,
        List<BuilderFieldData> builderFields, EclipseNode type, TypeReference[] thrownExceptions,
        boolean addCleaning, ASTNode source) {
    MethodDeclaration out = new MethodDeclaration(
            ((CompilationUnitDeclaration) type.top().get()).compilationResult);
    out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    List<Statement> statements = new ArrayList<Statement>();

    if (addCleaning) {
        FieldReference thisUnclean = new FieldReference(CLEAN_FIELD_NAME, 0);
        thisUnclean.receiver = new ThisReference(0, 0);
        Expression notClean = new UnaryExpression(thisUnclean, OperatorIds.NOT);
        MessageSend invokeClean = new MessageSend();
        invokeClean.selector = CLEAN_METHOD_NAME;
        statements.add(new IfStatement(notClean, invokeClean, 0, 0));
    }/*from   w ww. j a v a2s. c o  m*/

    for (BuilderFieldData bfd : builderFields) {
        if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) {
            bfd.singularData.getSingularizer().appendBuildCode(bfd.singularData, type, statements, bfd.name);
        }
    }

    List<Expression> args = new ArrayList<Expression>();
    for (BuilderFieldData bfd : builderFields) {
        args.add(new SingleNameReference(bfd.name, 0L));
    }

    if (addCleaning) {
        FieldReference thisUnclean = new FieldReference(CLEAN_FIELD_NAME, 0);
        thisUnclean.receiver = new ThisReference(0, 0);
        statements.add(new Assignment(thisUnclean, new TrueLiteral(0, 0), 0));
    }

    out.modifiers = ClassFileConstants.AccPublic;
    out.selector = name.toCharArray();
    out.thrownExceptions = copyTypes(thrownExceptions);
    out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    out.returnType = returnType;

    if (staticName == null) {
        AllocationExpression allocationStatement = new AllocationExpression();
        allocationStatement.type = copyType(out.returnType);
        allocationStatement.arguments = args.isEmpty() ? null : args.toArray(new Expression[args.size()]);
        statements.add(new ReturnStatement(allocationStatement, 0, 0));
    } else {
        MessageSend invoke = new MessageSend();
        invoke.selector = staticName;
        invoke.receiver = new SingleNameReference(type.up().getName().toCharArray(), 0);
        TypeParameter[] tps = ((TypeDeclaration) type.get()).typeParameters;
        if (tps != null) {
            TypeReference[] trs = new TypeReference[tps.length];
            for (int i = 0; i < trs.length; i++) {
                trs[i] = new SingleTypeReference(tps[i].name, 0);
            }
            invoke.typeArguments = trs;
        }
        invoke.arguments = args.isEmpty() ? null : args.toArray(new Expression[args.size()]);
        if (returnType instanceof SingleTypeReference
                && Arrays.equals(TypeConstants.VOID, ((SingleTypeReference) returnType).token)) {
            statements.add(invoke);
        } else {
            statements.add(new ReturnStatement(invoke, 0, 0));
        }
    }
    out.statements = statements.isEmpty() ? null : statements.toArray(new Statement[statements.size()]);
    out.traverse(new SetGeneratedByVisitor(source), (ClassScope) null);
    return out;
}

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

License:Open Source License

public MethodDeclaration createEquals(EclipseNode type, Collection<EclipseNode> fields, boolean callSuper,
        ASTNode source, FieldAccess fieldAccess, boolean needsCanEqual, List<Annotation> onParam) {
    int pS = source.sourceStart;
    int pE = source.sourceEnd;
    long p = (long) pS << 32 | pE;
    TypeDeclaration typeDecl = (TypeDeclaration) type.get();

    MethodDeclaration method = new MethodDeclaration(
            ((CompilationUnitDeclaration) type.top().get()).compilationResult);
    setGeneratedBy(method, source);/*from   w  w w  .j av  a 2s.c  o m*/
    method.modifiers = toEclipseModifier(AccessLevel.PUBLIC);
    method.returnType = TypeReference.baseTypeReference(TypeIds.T_boolean, 0);
    method.returnType.sourceStart = pS;
    method.returnType.sourceEnd = pE;
    setGeneratedBy(method.returnType, source);
    method.annotations = new Annotation[] { makeMarkerAnnotation(TypeConstants.JAVA_LANG_OVERRIDE, source) };
    method.selector = "equals".toCharArray();
    method.thrownExceptions = null;
    method.typeParameters = null;
    method.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG;
    method.bodyStart = method.declarationSourceStart = method.sourceStart = source.sourceStart;
    method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = source.sourceEnd;
    TypeReference objectRef = new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT,
            new long[] { p, p, p });
    setGeneratedBy(objectRef, source);
    method.arguments = new Argument[] { new Argument(new char[] { 'o' }, 0, objectRef, Modifier.FINAL) };
    method.arguments[0].sourceStart = pS;
    method.arguments[0].sourceEnd = pE;
    if (!onParam.isEmpty())
        method.arguments[0].annotations = onParam.toArray(new Annotation[0]);
    setGeneratedBy(method.arguments[0], source);

    List<Statement> statements = new ArrayList<Statement>();

    /* if (o == this) return true; */ {
        SingleNameReference oRef = new SingleNameReference(new char[] { 'o' }, p);
        setGeneratedBy(oRef, source);
        ThisReference thisRef = new ThisReference(pS, pE);
        setGeneratedBy(thisRef, source);
        EqualExpression otherEqualsThis = new EqualExpression(oRef, thisRef, OperatorIds.EQUAL_EQUAL);
        setGeneratedBy(otherEqualsThis, source);

        TrueLiteral trueLiteral = new TrueLiteral(pS, pE);
        setGeneratedBy(trueLiteral, source);
        ReturnStatement returnTrue = new ReturnStatement(trueLiteral, pS, pE);
        setGeneratedBy(returnTrue, source);
        IfStatement ifOtherEqualsThis = new IfStatement(otherEqualsThis, returnTrue, pS, pE);
        setGeneratedBy(ifOtherEqualsThis, source);
        statements.add(ifOtherEqualsThis);
    }

    /* if (!(o instanceof Outer.Inner.MyType) return false; */ {
        SingleNameReference oRef = new SingleNameReference(new char[] { 'o' }, p);
        setGeneratedBy(oRef, source);

        TypeReference typeReference = createTypeReference(type, p);
        setGeneratedBy(typeReference, source);

        InstanceOfExpression instanceOf = new InstanceOfExpression(oRef, typeReference);
        instanceOf.sourceStart = pS;
        instanceOf.sourceEnd = pE;
        setGeneratedBy(instanceOf, source);

        Expression notInstanceOf = new UnaryExpression(instanceOf, OperatorIds.NOT);
        setGeneratedBy(notInstanceOf, source);

        FalseLiteral falseLiteral = new FalseLiteral(pS, pE);
        setGeneratedBy(falseLiteral, source);

        ReturnStatement returnFalse = new ReturnStatement(falseLiteral, pS, pE);
        setGeneratedBy(returnFalse, source);

        IfStatement ifNotInstanceOf = new IfStatement(notInstanceOf, returnFalse, pS, pE);
        setGeneratedBy(ifNotInstanceOf, source);
        statements.add(ifNotInstanceOf);
    }

    char[] otherName = "other".toCharArray();

    /* MyType<?> other = (MyType<?>) o; */ {
        if (!fields.isEmpty() || needsCanEqual) {
            LocalDeclaration other = new LocalDeclaration(otherName, pS, pE);
            other.modifiers |= ClassFileConstants.AccFinal;
            setGeneratedBy(other, source);
            char[] typeName = typeDecl.name;
            TypeReference targetType;
            if (typeDecl.typeParameters == null || typeDecl.typeParameters.length == 0) {
                targetType = new SingleTypeReference(typeName, p);
                setGeneratedBy(targetType, source);
                other.type = new SingleTypeReference(typeName, p);
                setGeneratedBy(other.type, source);
            } else {
                TypeReference[] typeArgs = new TypeReference[typeDecl.typeParameters.length];
                for (int i = 0; i < typeArgs.length; i++) {
                    typeArgs[i] = new Wildcard(Wildcard.UNBOUND);
                    typeArgs[i].sourceStart = pS;
                    typeArgs[i].sourceEnd = pE;
                    setGeneratedBy(typeArgs[i], source);
                }
                targetType = new ParameterizedSingleTypeReference(typeName, typeArgs, 0, p);
                setGeneratedBy(targetType, source);
                other.type = new ParameterizedSingleTypeReference(typeName, copyTypes(typeArgs, source), 0, p);
                setGeneratedBy(other.type, source);
            }
            NameReference oRef = new SingleNameReference(new char[] { 'o' }, p);
            setGeneratedBy(oRef, source);
            other.initialization = makeCastExpression(oRef, targetType, source);
            statements.add(other);
        }
    }

    /* if (!other.canEqual((java.lang.Object) this)) return false; */ {
        if (needsCanEqual) {
            MessageSend otherCanEqual = new MessageSend();
            otherCanEqual.sourceStart = pS;
            otherCanEqual.sourceEnd = pE;
            setGeneratedBy(otherCanEqual, source);
            otherCanEqual.receiver = new SingleNameReference(otherName, p);
            setGeneratedBy(otherCanEqual.receiver, source);
            otherCanEqual.selector = "canEqual".toCharArray();

            ThisReference thisReference = new ThisReference(pS, pE);
            setGeneratedBy(thisReference, source);
            CastExpression castThisRef = makeCastExpression(thisReference,
                    generateQualifiedTypeRef(source, TypeConstants.JAVA_LANG_OBJECT), source);
            castThisRef.sourceStart = pS;
            castThisRef.sourceEnd = pE;

            otherCanEqual.arguments = new Expression[] { castThisRef };

            Expression notOtherCanEqual = new UnaryExpression(otherCanEqual, OperatorIds.NOT);
            setGeneratedBy(notOtherCanEqual, source);

            FalseLiteral falseLiteral = new FalseLiteral(pS, pE);
            setGeneratedBy(falseLiteral, source);

            ReturnStatement returnFalse = new ReturnStatement(falseLiteral, pS, pE);
            setGeneratedBy(returnFalse, source);

            IfStatement ifNotCanEqual = new IfStatement(notOtherCanEqual, returnFalse, pS, pE);
            setGeneratedBy(ifNotCanEqual, source);

            statements.add(ifNotCanEqual);
        }
    }

    /* if (!super.equals(o)) return false; */
    if (callSuper) {
        MessageSend callToSuper = new MessageSend();
        callToSuper.sourceStart = pS;
        callToSuper.sourceEnd = pE;
        setGeneratedBy(callToSuper, source);
        callToSuper.receiver = new SuperReference(pS, pE);
        setGeneratedBy(callToSuper.receiver, source);
        callToSuper.selector = "equals".toCharArray();
        SingleNameReference oRef = new SingleNameReference(new char[] { 'o' }, p);
        setGeneratedBy(oRef, source);
        callToSuper.arguments = new Expression[] { oRef };
        Expression superNotEqual = new UnaryExpression(callToSuper, OperatorIds.NOT);
        setGeneratedBy(superNotEqual, source);
        FalseLiteral falseLiteral = new FalseLiteral(pS, pE);
        setGeneratedBy(falseLiteral, source);
        ReturnStatement returnFalse = new ReturnStatement(falseLiteral, pS, pE);
        setGeneratedBy(returnFalse, source);
        IfStatement ifSuperEquals = new IfStatement(superNotEqual, returnFalse, pS, pE);
        setGeneratedBy(ifSuperEquals, source);
        statements.add(ifSuperEquals);
    }

    for (EclipseNode field : fields) {
        TypeReference fType = getFieldType(field, fieldAccess);
        char[] token = fType.getLastToken();
        Expression thisFieldAccessor = createFieldAccessor(field, fieldAccess, source);
        Expression otherFieldAccessor = createFieldAccessor(field, fieldAccess, source, otherName);

        if (fType.dimensions() == 0 && token != null) {
            if (Arrays.equals(TypeConstants.FLOAT, token)) {
                statements.add(generateCompareFloatOrDouble(thisFieldAccessor, otherFieldAccessor,
                        "Float".toCharArray(), source));
            } else if (Arrays.equals(TypeConstants.DOUBLE, token)) {
                statements.add(generateCompareFloatOrDouble(thisFieldAccessor, otherFieldAccessor,
                        "Double".toCharArray(), source));
            } else if (BUILT_IN_TYPES.contains(new String(token))) {
                EqualExpression fieldsNotEqual = new EqualExpression(thisFieldAccessor, otherFieldAccessor,
                        OperatorIds.NOT_EQUAL);
                setGeneratedBy(fieldsNotEqual, source);
                FalseLiteral falseLiteral = new FalseLiteral(pS, pE);
                setGeneratedBy(falseLiteral, source);
                ReturnStatement returnStatement = new ReturnStatement(falseLiteral, pS, pE);
                setGeneratedBy(returnStatement, source);
                IfStatement ifStatement = new IfStatement(fieldsNotEqual, returnStatement, pS, pE);
                setGeneratedBy(ifStatement, source);
                statements.add(ifStatement);
            } else /* objects */ {
                /* final java.lang.Object this$fieldName = this.fieldName; */
                /* final java.lang.Object other$fieldName = other.fieldName; */
                /* if (this$fieldName == null ? other$fieldName != null : !this$fieldName.equals(other$fieldName)) return false;; */
                char[] thisDollarFieldName = ("this$" + field.getName()).toCharArray();
                char[] otherDollarFieldName = ("other$" + field.getName()).toCharArray();

                statements.add(createLocalDeclaration(source, thisDollarFieldName,
                        generateQualifiedTypeRef(source, TypeConstants.JAVA_LANG_OBJECT), thisFieldAccessor));
                statements.add(createLocalDeclaration(source, otherDollarFieldName,
                        generateQualifiedTypeRef(source, TypeConstants.JAVA_LANG_OBJECT), otherFieldAccessor));

                SingleNameReference this1 = new SingleNameReference(thisDollarFieldName, p);
                setGeneratedBy(this1, source);
                SingleNameReference this2 = new SingleNameReference(thisDollarFieldName, p);
                setGeneratedBy(this2, source);
                SingleNameReference other1 = new SingleNameReference(otherDollarFieldName, p);
                setGeneratedBy(other1, source);
                SingleNameReference other2 = new SingleNameReference(otherDollarFieldName, p);
                setGeneratedBy(other2, source);

                NullLiteral nullLiteral = new NullLiteral(pS, pE);
                setGeneratedBy(nullLiteral, source);
                EqualExpression fieldIsNull = new EqualExpression(this1, nullLiteral, OperatorIds.EQUAL_EQUAL);
                nullLiteral = new NullLiteral(pS, pE);
                setGeneratedBy(nullLiteral, source);
                EqualExpression otherFieldIsntNull = new EqualExpression(other1, nullLiteral,
                        OperatorIds.NOT_EQUAL);
                MessageSend equalsCall = new MessageSend();
                equalsCall.sourceStart = pS;
                equalsCall.sourceEnd = pE;
                setGeneratedBy(equalsCall, source);
                equalsCall.receiver = this2;
                equalsCall.selector = "equals".toCharArray();
                equalsCall.arguments = new Expression[] { other2 };
                UnaryExpression fieldsNotEqual = new UnaryExpression(equalsCall, OperatorIds.NOT);
                fieldsNotEqual.sourceStart = pS;
                fieldsNotEqual.sourceEnd = pE;
                setGeneratedBy(fieldsNotEqual, source);
                ConditionalExpression fullEquals = new ConditionalExpression(fieldIsNull, otherFieldIsntNull,
                        fieldsNotEqual);
                fullEquals.sourceStart = pS;
                fullEquals.sourceEnd = pE;
                setGeneratedBy(fullEquals, source);
                FalseLiteral falseLiteral = new FalseLiteral(pS, pE);
                setGeneratedBy(falseLiteral, source);
                ReturnStatement returnStatement = new ReturnStatement(falseLiteral, pS, pE);
                setGeneratedBy(returnStatement, source);
                IfStatement ifStatement = new IfStatement(fullEquals, returnStatement, pS, pE);
                setGeneratedBy(ifStatement, source);
                statements.add(ifStatement);
            }
        } else if (fType.dimensions() > 0 && token != null) {
            MessageSend arraysEqualCall = new MessageSend();
            arraysEqualCall.sourceStart = pS;
            arraysEqualCall.sourceEnd = pE;
            setGeneratedBy(arraysEqualCall, source);
            arraysEqualCall.receiver = generateQualifiedNameRef(source, TypeConstants.JAVA, TypeConstants.UTIL,
                    "Arrays".toCharArray());
            if (fType.dimensions() > 1 || !BUILT_IN_TYPES.contains(new String(token))) {
                arraysEqualCall.selector = "deepEquals".toCharArray();
            } else {
                arraysEqualCall.selector = "equals".toCharArray();
            }
            arraysEqualCall.arguments = new Expression[] { thisFieldAccessor, otherFieldAccessor };
            UnaryExpression arraysNotEqual = new UnaryExpression(arraysEqualCall, OperatorIds.NOT);
            arraysNotEqual.sourceStart = pS;
            arraysNotEqual.sourceEnd = pE;
            setGeneratedBy(arraysNotEqual, source);
            FalseLiteral falseLiteral = new FalseLiteral(pS, pE);
            setGeneratedBy(falseLiteral, source);
            ReturnStatement returnStatement = new ReturnStatement(falseLiteral, pS, pE);
            setGeneratedBy(returnStatement, source);
            IfStatement ifStatement = new IfStatement(arraysNotEqual, returnStatement, pS, pE);
            setGeneratedBy(ifStatement, source);
            statements.add(ifStatement);
        }
    }

    /* return true; */ {
        TrueLiteral trueLiteral = new TrueLiteral(pS, pE);
        setGeneratedBy(trueLiteral, source);
        ReturnStatement returnStatement = new ReturnStatement(trueLiteral, pS, pE);
        setGeneratedBy(returnStatement, source);
        statements.add(returnStatement);
    }
    method.statements = statements.toArray(new Statement[statements.size()]);
    return method;
}

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

License:Open Source License

static MethodDeclaration createSetter(TypeDeclaration parent, EclipseNode fieldNode, String name,
        boolean shouldReturnThis, int modifier, EclipseNode sourceNode, List<Annotation> onMethod,
        List<Annotation> onParam) {
    FieldDeclaration field = (FieldDeclaration) fieldNode.get();
    ASTNode source = sourceNode.get();//from   w  ww.  ja  v a  2  s  .c  o m
    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long) pS << 32 | pE;
    MethodDeclaration method = new MethodDeclaration(parent.compilationResult);
    method.modifiers = modifier;
    if (shouldReturnThis) {
        method.returnType = cloneSelfType(fieldNode, source);
    }

    if (method.returnType == null) {
        method.returnType = TypeReference.baseTypeReference(TypeIds.T_void, 0);
        method.returnType.sourceStart = pS;
        method.returnType.sourceEnd = pE;
        shouldReturnThis = false;
    }
    Annotation[] deprecated = null;
    if (isFieldDeprecated(fieldNode)) {
        deprecated = new Annotation[] { generateDeprecatedAnnotation(source) };
    }
    method.annotations = copyAnnotations(source, onMethod.toArray(new Annotation[0]), deprecated);
    Argument param = new Argument(field.name, p, copyType(field.type, source), Modifier.FINAL);
    param.sourceStart = pS;
    param.sourceEnd = pE;
    method.arguments = new Argument[] { param };
    method.selector = name.toCharArray();
    method.binding = null;
    method.thrownExceptions = null;
    method.typeParameters = null;
    method.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    Expression fieldRef = createFieldAccessor(fieldNode, FieldAccess.ALWAYS_FIELD, source);
    NameReference fieldNameRef = new SingleNameReference(field.name, p);
    Assignment assignment = new Assignment(fieldRef, fieldNameRef, (int) p);
    assignment.sourceStart = pS;
    assignment.sourceEnd = assignment.statementEnd = pE;
    method.bodyStart = method.declarationSourceStart = method.sourceStart = source.sourceStart;
    method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = source.sourceEnd;

    Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN);
    Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN);
    List<Statement> statements = new ArrayList<Statement>(5);
    // if (nonNulls.length == 0) {
    // statements.add(assignment);
    // } else {
    // Statement nullCheck = generateNullCheck(field, sourceNode);
    // if (nullCheck != null) statements.add(nullCheck);
    // statements.add(assignment);
    // }
    //
    // if (shouldReturnThis) {
    // ThisReference thisRef = new ThisReference(pS, pE);
    // ReturnStatement returnThis = new ReturnStatement(thisRef, pS, pE);
    // statements.add(returnThis);
    // }

    /*
     * if (this.$field == $field) return;
     */ {
        Expression lfRef = createFieldAccessor(fieldNode, FieldAccess.ALWAYS_FIELD, source);
        setGeneratedBy(lfRef, source);
        NameReference fRef = new SingleNameReference(field.name, p);
        setGeneratedBy(lfRef, source);
        setGeneratedBy(fRef, source);
        EqualExpression otherEqualsThis = new EqualExpression(lfRef, fRef, OperatorIds.EQUAL_EQUAL);
        setGeneratedBy(otherEqualsThis, source);

        TrueLiteral trueLiteral = new TrueLiteral(pS, pE);
        setGeneratedBy(trueLiteral, source);
        ReturnStatement returnTrue = new ReturnStatement(null, pS, pE);
        setGeneratedBy(returnTrue, source);
        IfStatement ifOtherEqualsThis = new IfStatement(otherEqualsThis, returnTrue, pS, pE);
        setGeneratedBy(ifOtherEqualsThis, source);
        statements.add(ifOtherEqualsThis);
    }

    /* String fname = this.getClass().getDeclaredField("$field").getName(); */
    //      {
    //         // Left side
    //         LocalDeclaration fieldClass = new LocalDeclaration("fname".toCharArray(), pS, pE);
    //         fieldClass.modifiers |= Modifier.FINAL;
    //         fieldClass.type = new SingleTypeReference("String".toCharArray(), p);
    //         setGeneratedBy(fieldClass, source);
    //         // Right side - first call
    //         MessageSend getClass = new MessageSend();
    //         getClass.sourceStart = pS;
    //         getClass.sourceEnd = pE;
    //         setGeneratedBy(getClass, source);
    //         ThisReference thisReference = new ThisReference(pS, pE);
    //         setGeneratedBy(thisReference, source);
    //         getClass.receiver = thisReference;
    //         getClass.selector = "getClass".toCharArray();
    //         // Right side - second call
    //         MessageSend getDeclaredField = new MessageSend();
    //         getDeclaredField.sourceStart = pS;
    //         getDeclaredField.sourceEnd = pE;
    //         setGeneratedBy(getDeclaredField, source);
    //         getDeclaredField.receiver = getClass;
    //         getDeclaredField.selector = "getDeclaredField".toCharArray();
    //         // Arguments of the call
    //         getDeclaredField.arguments = new Expression[] {new StringLiteral(field.name, pS, pE, 0)};
    //         // Third call
    //         MessageSend getName = new MessageSend();
    //         getName.sourceStart = pS;
    //         getName.sourceEnd = pE;
    //         setGeneratedBy(getName, source);
    //         getName.receiver = getDeclaredField;
    //         getName.selector = "getName".toCharArray();
    //         // Assign right to left
    //         fieldClass.initialization = getName;
    //         statements.add(fieldClass);
    //      }
    //      
    //      
    //      /* Set<UpsortableSet> set = UpsortableSets.GLOBAL_UPSORTABLE
    //               .get(this.getClass().getName() + "." + field.getName());*/
    //      {
    //         //left hand of the assignment
    //         LocalDeclaration fieldClass = new LocalDeclaration("sets".toCharArray(), pS, pE);
    //         fieldClass.modifiers |= Modifier.FINAL;
    //         fieldClass.type = new SingleTypeReference("java.util.Set".toCharArray(), p);
    //         //Righthand
    //         MessageSend get = new MessageSend();
    //         get.sourceStart = pS;
    //         get.sourceEnd = pE;
    //         setGeneratedBy(get, source);
    //         FieldReference ref = new FieldReference("lombok.upsortable.UpsortableSets.GLOBAL_UPSORTABLE", pos)
    //         setGeneratedBy(thisReference, source);
    //         getClass.receiver = thisReference;
    //         getClass.selector = "getClass".toCharArray();
    //         //Assignment
    //      }
    method.statements = statements.toArray(new Statement[0]);
    param.annotations = copyAnnotations(source, nonNulls, nullables, onParam.toArray(new Annotation[0]));

    method.traverse(new SetGeneratedByVisitor(source), parent.scope);
    return method;
}

From source file:org.eclipse.ajdt.internal.core.parserbridge.CompilerASTNodeCompatibilityWrapper.java

License:Apache License

public static TrueLiteral createJDTTrueLiteral(
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.TrueLiteral ajdtLiteral)
        throws IllegalArgumentException, SecurityException, IllegalAccessException, InvocationTargetException,
        ClassNotFoundException, InstantiationException, NoSuchMethodException {
    return new TrueLiteral(ajdtLiteral.sourceStart, ajdtLiteral.sourceEnd);
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

protected void consumeToken(int type) {
    /* remember the last consumed value */
    /* try to minimize the number of build values */
    //   // clear the commentPtr of the scanner in case we read something different from a modifier
    //   switch(type) {
    //      case TokenNameabstract :
    //      case TokenNamestrictfp :
    //      case TokenNamefinal :
    //      case TokenNamenative :
    //      case TokenNameprivate :
    //      case TokenNameprotected :
    //      case TokenNamepublic :
    //      case TokenNametransient :
    //      case TokenNamevolatile :
    //      case TokenNamestatic :
    //      case TokenNamesynchronized :
    //         break;
    //      default:
    //         this.scanner.commentPtr = -1;
    //   }//from  www  .j ava 2s  .c o m
    //System.out.println(this.scanner.toStringAction(type));
    switch (type) {
    case TokenNameIdentifier:
        pushIdentifier();
        if (this.scanner.useAssertAsAnIndentifier
                && this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
            long positions = this.identifierPositionStack[this.identifierPtr];
            if (!this.statementRecoveryActivated)
                problemReporter().useAssertAsAnIdentifier((int) (positions >>> 32), (int) positions);
        }
        if (this.scanner.useEnumAsAnIndentifier
                && this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
            long positions = this.identifierPositionStack[this.identifierPtr];
            if (!this.statementRecoveryActivated)
                problemReporter().useEnumAsAnIdentifier((int) (positions >>> 32), (int) positions);
        }
        break;
    case TokenNameinterface:
        //'class' is pushing two int (positions) on the stack ==> 'interface' needs to do it too....
        pushOnIntStack(this.scanner.currentPosition - 1);
        pushOnIntStack(this.scanner.startPosition);
        break;
    case TokenNameabstract:
        checkAndSetModifiers(ClassFileConstants.AccAbstract);
        pushOnExpressionStackLengthStack(0);
        break;
    case TokenNamestrictfp:
        checkAndSetModifiers(ClassFileConstants.AccStrictfp);
        pushOnExpressionStackLengthStack(0);
        break;
    case TokenNamefinal:
        checkAndSetModifiers(ClassFileConstants.AccFinal);
        pushOnExpressionStackLengthStack(0);
        break;
    case TokenNamenative:
        checkAndSetModifiers(ClassFileConstants.AccNative);
        pushOnExpressionStackLengthStack(0);
        break;
    case TokenNameprivate:
        checkAndSetModifiers(ClassFileConstants.AccPrivate);
        pushOnExpressionStackLengthStack(0);
        break;
    case TokenNameprotected:
        checkAndSetModifiers(ClassFileConstants.AccProtected);
        pushOnExpressionStackLengthStack(0);
        break;
    case TokenNamepublic:
        checkAndSetModifiers(ClassFileConstants.AccPublic);
        pushOnExpressionStackLengthStack(0);
        break;
    case TokenNametransient:
        checkAndSetModifiers(ClassFileConstants.AccTransient);
        pushOnExpressionStackLengthStack(0);
        break;
    case TokenNamevolatile:
        checkAndSetModifiers(ClassFileConstants.AccVolatile);
        pushOnExpressionStackLengthStack(0);
        break;
    case TokenNamestatic:
        checkAndSetModifiers(ClassFileConstants.AccStatic);
        pushOnExpressionStackLengthStack(0);
        break;
    case TokenNamesynchronized:
        this.synchronizedBlockSourceStart = this.scanner.startPosition;
        checkAndSetModifiers(ClassFileConstants.AccSynchronized);
        pushOnExpressionStackLengthStack(0);
        break;
    //==============================
    case TokenNamevoid:
        pushIdentifier(-T_void);
        pushOnIntStack(this.scanner.currentPosition - 1);
        pushOnIntStack(this.scanner.startPosition);
        break;
    //push a default dimension while void is not part of the primitive
    //declaration baseType and so takes the place of a type without getting into
    //regular type parsing that generates a dimension on this.intStack
    case TokenNameboolean:
        pushIdentifier(-T_boolean);
        pushOnIntStack(this.scanner.currentPosition - 1);
        pushOnIntStack(this.scanner.startPosition);
        break;
    case TokenNamebyte:
        pushIdentifier(-T_byte);
        pushOnIntStack(this.scanner.currentPosition - 1);
        pushOnIntStack(this.scanner.startPosition);
        break;
    case TokenNamechar:
        pushIdentifier(-T_char);
        pushOnIntStack(this.scanner.currentPosition - 1);
        pushOnIntStack(this.scanner.startPosition);
        break;
    case TokenNamedouble:
        pushIdentifier(-T_double);
        pushOnIntStack(this.scanner.currentPosition - 1);
        pushOnIntStack(this.scanner.startPosition);
        break;
    case TokenNamefloat:
        pushIdentifier(-T_float);
        pushOnIntStack(this.scanner.currentPosition - 1);
        pushOnIntStack(this.scanner.startPosition);
        break;
    case TokenNameint:
        pushIdentifier(-T_int);
        pushOnIntStack(this.scanner.currentPosition - 1);
        pushOnIntStack(this.scanner.startPosition);
        break;
    case TokenNamelong:
        pushIdentifier(-T_long);
        pushOnIntStack(this.scanner.currentPosition - 1);
        pushOnIntStack(this.scanner.startPosition);
        break;
    case TokenNameshort:
        pushIdentifier(-T_short);
        pushOnIntStack(this.scanner.currentPosition - 1);
        pushOnIntStack(this.scanner.startPosition);
        break;
    //==============================
    case TokenNameIntegerLiteral:
        pushOnExpressionStack(IntLiteral.buildIntLiteral(this.scanner.getCurrentTokenSource(),
                this.scanner.startPosition, this.scanner.currentPosition - 1));
        break;
    case TokenNameLongLiteral:
        pushOnExpressionStack(LongLiteral.buildLongLiteral(this.scanner.getCurrentTokenSource(),
                this.scanner.startPosition, this.scanner.currentPosition - 1));
        break;
    case TokenNameFloatingPointLiteral:
        pushOnExpressionStack(new FloatLiteral(this.scanner.getCurrentTokenSource(), this.scanner.startPosition,
                this.scanner.currentPosition - 1));
        break;
    case TokenNameDoubleLiteral:
        pushOnExpressionStack(new DoubleLiteral(this.scanner.getCurrentTokenSource(),
                this.scanner.startPosition, this.scanner.currentPosition - 1));
        break;
    case TokenNameCharacterLiteral:
        pushOnExpressionStack(new CharLiteral(this.scanner.getCurrentTokenSource(), this.scanner.startPosition,
                this.scanner.currentPosition - 1));
        break;
    case TokenNameStringLiteral:
        StringLiteral stringLiteral;
        if (this.recordStringLiterals && this.checkExternalizeStrings
                && this.lastPosistion < this.scanner.currentPosition && !this.statementRecoveryActivated) {
            stringLiteral = createStringLiteral(this.scanner.getCurrentTokenSourceString(),
                    this.scanner.startPosition, this.scanner.currentPosition - 1, Util.getLineNumber(
                            this.scanner.startPosition, this.scanner.lineEnds, 0, this.scanner.linePtr));
            this.compilationUnit.recordStringLiteral(stringLiteral, this.currentElement != null);
        } else {
            stringLiteral = createStringLiteral(this.scanner.getCurrentTokenSourceString(),
                    this.scanner.startPosition, this.scanner.currentPosition - 1, 0);
        }
        pushOnExpressionStack(stringLiteral);
        break;
    case TokenNamefalse:
        pushOnExpressionStack(new FalseLiteral(this.scanner.startPosition, this.scanner.currentPosition - 1));
        break;
    case TokenNametrue:
        pushOnExpressionStack(new TrueLiteral(this.scanner.startPosition, this.scanner.currentPosition - 1));
        break;
    case TokenNamenull:
        pushOnExpressionStack(new NullLiteral(this.scanner.startPosition, this.scanner.currentPosition - 1));
        break;
    //============================
    case TokenNamesuper:
    case TokenNamethis:
        this.endPosition = this.scanner.currentPosition - 1;
        pushOnIntStack(this.scanner.startPosition);
        break;
    case TokenNameassert:
    case TokenNameimport:
    case TokenNamepackage:
    case TokenNamethrow:
    case TokenNamedo:
    case TokenNameif:
    case TokenNamefor:
    case TokenNameswitch:
    case TokenNametry:
    case TokenNamewhile:
    case TokenNamebreak:
    case TokenNamecontinue:
    case TokenNamereturn:
    case TokenNamecase:
        pushOnIntStack(this.scanner.startPosition);
        break;
    case TokenNamenew:
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=40954
        resetModifiers();
        pushOnIntStack(this.scanner.startPosition);
        break;
    case TokenNameclass:
        pushOnIntStack(this.scanner.currentPosition - 1);
        pushOnIntStack(this.scanner.startPosition);
        break;
    case TokenNameenum:
        pushOnIntStack(this.scanner.currentPosition - 1);
        pushOnIntStack(this.scanner.startPosition);
        break;
    case TokenNamedefault:
        pushOnIntStack(this.scanner.startPosition);
        pushOnIntStack(this.scanner.currentPosition - 1);
        break;
    //let extra semantic action decide when to push
    case TokenNameRBRACKET:
        this.endPosition = this.scanner.startPosition;
        this.endStatementPosition = this.scanner.currentPosition - 1;
        break;
    case TokenNameLBRACE:
        this.endStatementPosition = this.scanner.currentPosition - 1;
        //$FALL-THROUGH$
    case TokenNamePLUS:
    case TokenNameMINUS:
    case TokenNameNOT:
    case TokenNameTWIDDLE:
        this.endPosition = this.scanner.startPosition;
        break;
    case TokenNamePLUS_PLUS:
    case TokenNameMINUS_MINUS:
        this.endPosition = this.scanner.startPosition;
        this.endStatementPosition = this.scanner.currentPosition - 1;
        break;
    case TokenNameRBRACE:
    case TokenNameSEMICOLON:
        this.endStatementPosition = this.scanner.currentPosition - 1;
        this.endPosition = this.scanner.startPosition - 1;
        //the item is not part of the potential futur expression/statement
        break;
    case TokenNameRPAREN:
        // in order to handle ( expression) ////// (cast)expression///// foo(x)
        this.rParenPos = this.scanner.currentPosition - 1; // position of the end of right parenthesis (in case of unicode \u0029) lex00101
        break;
    case TokenNameLPAREN:
        this.lParenPos = this.scanner.startPosition;
        break;
    case TokenNameAT:
        pushOnIntStack(this.scanner.startPosition);
        break;
    case TokenNameQUESTION:
        pushOnIntStack(this.scanner.startPosition);
        pushOnIntStack(this.scanner.currentPosition - 1);
        break;
    case TokenNameLESS:
        pushOnIntStack(this.scanner.startPosition);
        break;
    case TokenNameELLIPSIS:
        pushOnIntStack(this.scanner.currentPosition - 1);
        break;
    case TokenNameEQUAL:
        if (this.currentElement != null && this.currentElement instanceof RecoveredAnnotation) {
            RecoveredAnnotation recoveredAnnotation = (RecoveredAnnotation) this.currentElement;
            if (recoveredAnnotation.memberValuPairEqualEnd == -1) {
                recoveredAnnotation.memberValuPairEqualEnd = this.scanner.currentPosition - 1;
            }
        }
        break;
    case TokenNameMULTIPLY:
        // star end position
        pushOnIntStack(this.scanner.currentPosition - 1);
        break;
    //  case TokenNameCOMMA :
    //  case TokenNameCOLON  :
    //  case TokenNameLBRACKET  :
    //  case TokenNameDOT :
    //  case TokenNameERROR :
    //  case TokenNameEOF  :
    //  case TokenNamecase  :
    //  case TokenNamecatch  :
    //  case TokenNameelse  :
    //  case TokenNameextends  :
    //  case TokenNamefinally  :
    //  case TokenNameimplements  :
    //  case TokenNamethrows  :
    //  case TokenNameinstanceof  :
    //  case TokenNameEQUAL_EQUAL  :
    //  case TokenNameLESS_EQUAL  :
    //  case TokenNameGREATER_EQUAL  :
    //  case TokenNameNOT_EQUAL  :
    //  case TokenNameLEFT_SHIFT  :
    //  case TokenNameRIGHT_SHIFT  :
    //  case TokenNameUNSIGNED_RIGHT_SHIFT :
    //  case TokenNamePLUS_EQUAL  :
    //  case TokenNameMINUS_EQUAL  :
    //  case TokenNameMULTIPLY_EQUAL  :
    //  case TokenNameDIVIDE_EQUAL  :
    //  case TokenNameAND_EQUAL  :
    //  case TokenNameOR_EQUAL  :
    //  case TokenNameXOR_EQUAL  :
    //  case TokenNameREMAINDER_EQUAL  :
    //  case TokenNameLEFT_SHIFT_EQUAL  :
    //  case TokenNameRIGHT_SHIFT_EQUAL  :
    //  case TokenNameUNSIGNED_RIGHT_SHIFT_EQUAL  :
    //  case TokenNameOR_OR  :
    //  case TokenNameAND_AND  :
    //  case TokenNameREMAINDER :
    //  case TokenNameXOR  :
    //  case TokenNameAND  :
    //  case TokenNameMULTIPLY :
    //  case TokenNameOR  :
    //  case TokenNameDIVIDE :
    //  case TokenNameGREATER  :
    }
}

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

License:Open Source License

public Literal booleanLiteral(boolean val) {
    MagicLiteral result = val ? new TrueLiteral(this.sourceStart, this.sourceEnd)
            : new FalseLiteral(this.sourceStart, this.sourceEnd);
    result.isGenerated = true;/* ww  w  . ja v  a  2  s.c om*/
    return result;
}

From source file:org.nabucco.framework.mda.model.java.ast.produce.JavaAstModelProducer.java

License:Open Source License

public Literal createLiteral(String value, LiteralType type) throws JavaModelException {

    value = (value != null) ? value : "";

    switch (type) {
    case TRUE_LITERAL:
        return new TrueLiteral(0, 0);
    case FALSE_LITERAL:
        return new FalseLiteral(0, 0);
    case NULL_LITERAL:
        return new NullLiteral(0, 0);
    case STRING_LITERAL:
        return new StringLiteral(value.toCharArray(), 0, 0, 0);
    case FLOAT_LITERAL:
        return new FloatLiteral(appendLiteralSuffix(LiteralType.FLOAT_LITERAL, value), 0, 0);
    case DOUBLE_LITERAL:
        return new DoubleLiteral(appendLiteralSuffix(LiteralType.DOUBLE_LITERAL, value), 0, 0);
    case INT_LITERAL:
        return new IntLiteral(value.toCharArray(), 0, 0);
    case CHAR_LITERAL:
        return new CharLiteral(value.toCharArray(), 0, 0);
    case LONG_LITERAL:
        return new LongLiteral(appendLiteralSuffix(LiteralType.LONG_LITERAL, value), 0, 0);
    case BOOLEAN_LITERAL:
        return Boolean.valueOf(value) ? new TrueLiteral(0, 0) : new FalseLiteral(0, 0);
    }//from  w w w  .  ja v  a2  s  . c  o m

    return null;
}

From source file:org.nabucco.framework.mda.template.java.extract.statement.JavaAstStatementExtractorVisitor.java

License:Open Source License

@Override
public boolean visit(TrueLiteral trueLiteral, BlockScope scope) {

    TrueLiteral trueCopy = new TrueLiteral(trueLiteral.sourceStart, trueLiteral.sourceEnd);
    this.statement = trueCopy;

    return false;
}