List of usage examples for org.eclipse.jdt.internal.compiler.ast PostfixExpression PostfixExpression
public PostfixExpression(Expression lhs, Expression expression, int operator, int pos)
From source file:lombok.eclipse.handlers.ast.EclipseASTMaker.java
License:Open Source License
@Override public ASTNode visitUnary(final lombok.ast.Unary node, final Void p) { final String operator = node.getOperator(); final int opCode; if (UNARY_OPERATORS.containsKey(operator)) { opCode = UNARY_OPERATORS.get(operator); } else {// w w w.j a v a 2 s. c om throw new IllegalStateException(String.format("Unknown unary operator '%s'", operator)); } final Expression unaryExpression; if (Is.oneOf(operator, "++X", "--X")) { unaryExpression = new PrefixExpression(build(node.getExpression(), Expression.class), IntLiteral.One, opCode, 0); } else if (Is.oneOf(operator, "X++", "X--")) { unaryExpression = new PostfixExpression(build(node.getExpression(), Expression.class), IntLiteral.One, opCode, 0); } else { unaryExpression = new UnaryExpression(build(node.getExpression(), Expression.class), opCode); } setGeneratedByAndCopyPos(unaryExpression, source, posHintOf(node)); return unaryExpression; }
From source file:lombok.eclipse.handlers.singulars.EclipseJavaUtilSingularizer.java
License:Open Source License
protected List<Statement> createJavaUtilSimpleCreationAndFillStatements(SingularData data, EclipseNode builderType, boolean mapMode, boolean defineVar, boolean addInitialCapacityArg, boolean nullGuard, String targetType) { char[] varName = mapMode ? (new String(data.getPluralName()) + "$key").toCharArray() : data.getPluralName(); Statement createStat;// w w w .java 2s . c o m { // pluralName = new java.util.TargetType(initialCap); Expression[] constructorArgs = null; if (addInitialCapacityArg) { // this.varName.size() < MAX_POWER_OF_2 ? 1 + this.varName.size() + (this.varName.size() - 3) / 3 : Integer.MAX_VALUE; // lessThanCutOff = this.varName.size() < MAX_POWER_OF_2 Expression lessThanCutoff = new BinaryExpression(getSize(builderType, varName, nullGuard), makeIntLiteral("0x40000000".toCharArray(), null), OperatorIds.LESS); FieldReference integerMaxValue = new FieldReference("MAX_VALUE".toCharArray(), 0L); integerMaxValue.receiver = new QualifiedNameReference(TypeConstants.JAVA_LANG_INTEGER, NULL_POSS, 0, 0); Expression sizeFormulaLeft = new BinaryExpression(makeIntLiteral(new char[] { '1' }, null), getSize(builderType, varName, nullGuard), OperatorIds.PLUS); Expression sizeFormulaRightLeft = new BinaryExpression(getSize(builderType, varName, nullGuard), makeIntLiteral(new char[] { '3' }, null), OperatorIds.MINUS); Expression sizeFormulaRight = new BinaryExpression(sizeFormulaRightLeft, makeIntLiteral(new char[] { '3' }, null), OperatorIds.DIVIDE); Expression sizeFormula = new BinaryExpression(sizeFormulaLeft, sizeFormulaRight, OperatorIds.PLUS); Expression cond = new ConditionalExpression(lessThanCutoff, sizeFormula, integerMaxValue); constructorArgs = new Expression[] { cond }; } TypeReference targetTypeRef = new QualifiedTypeReference( new char[][] { TypeConstants.JAVA, TypeConstants.UTIL, targetType.toCharArray() }, NULL_POSS); targetTypeRef = addTypeArgs(mapMode ? 2 : 1, false, builderType, targetTypeRef, data.getTypeArgs()); AllocationExpression constructorCall = new AllocationExpression(); constructorCall.type = targetTypeRef; constructorCall.arguments = constructorArgs; if (defineVar) { TypeReference localShadowerType = new QualifiedTypeReference(fromQualifiedName(data.getTargetFqn()), NULL_POSS); localShadowerType = addTypeArgs(mapMode ? 2 : 1, false, builderType, localShadowerType, data.getTypeArgs()); LocalDeclaration localShadowerDecl = new LocalDeclaration(data.getPluralName(), 0, 0); localShadowerDecl.type = localShadowerType; localShadowerDecl.initialization = constructorCall; createStat = localShadowerDecl; } else { createStat = new Assignment(new SingleNameReference(data.getPluralName(), 0L), constructorCall, 0); } } Statement fillStat; { if (mapMode) { // for (int $i = 0; $i < this.pluralname$key.size(); i++) pluralname.put(this.pluralname$key.get($i), this.pluralname$value.get($i)); char[] iVar = new char[] { '$', 'i' }; MessageSend pluralnameDotPut = new MessageSend(); pluralnameDotPut.selector = new char[] { 'p', 'u', 't' }; pluralnameDotPut.receiver = new SingleNameReference(data.getPluralName(), 0L); FieldReference thisDotKey = new FieldReference(varName, 0L); thisDotKey.receiver = new ThisReference(0, 0); FieldReference thisDotValue = new FieldReference( (new String(data.getPluralName()) + "$value").toCharArray(), 0L); thisDotValue.receiver = new ThisReference(0, 0); MessageSend keyArg = new MessageSend(); keyArg.receiver = thisDotKey; keyArg.arguments = new Expression[] { new SingleNameReference(iVar, 0L) }; keyArg.selector = new char[] { 'g', 'e', 't' }; MessageSend valueArg = new MessageSend(); valueArg.receiver = thisDotValue; valueArg.arguments = new Expression[] { new SingleNameReference(iVar, 0L) }; valueArg.selector = new char[] { 'g', 'e', 't' }; pluralnameDotPut.arguments = new Expression[] { keyArg, valueArg }; LocalDeclaration forInit = new LocalDeclaration(iVar, 0, 0); forInit.type = TypeReference.baseTypeReference(TypeIds.T_int, 0); forInit.initialization = makeIntLiteral(new char[] { '0' }, null); Expression checkExpr = new BinaryExpression(new SingleNameReference(iVar, 0L), getSize(builderType, varName, nullGuard), OperatorIds.LESS); Expression incrementExpr = new PostfixExpression(new SingleNameReference(iVar, 0L), IntLiteral.One, OperatorIds.PLUS, 0); fillStat = new ForStatement(new Statement[] { forInit }, checkExpr, new Statement[] { incrementExpr }, pluralnameDotPut, true, 0, 0); } else { // pluralname.addAll(this.pluralname); MessageSend pluralnameDotAddAll = new MessageSend(); pluralnameDotAddAll.selector = new char[] { 'a', 'd', 'd', 'A', 'l', 'l' }; pluralnameDotAddAll.receiver = new SingleNameReference(data.getPluralName(), 0L); FieldReference thisDotPluralname = new FieldReference(varName, 0L); thisDotPluralname.receiver = new ThisReference(0, 0); pluralnameDotAddAll.arguments = new Expression[] { thisDotPluralname }; fillStat = pluralnameDotAddAll; } if (nullGuard) { FieldReference thisDotField = new FieldReference(varName, 0L); thisDotField.receiver = new ThisReference(0, 0); Expression cond = new EqualExpression(thisDotField, new NullLiteral(0, 0), OperatorIds.NOT_EQUAL); fillStat = new IfStatement(cond, fillStat, 0, 0); } } Statement unmodifiableStat; { // pluralname = Collections.unmodifiableInterfaceType(pluralname); Expression arg = new SingleNameReference(data.getPluralName(), 0L); MessageSend invoke = new MessageSend(); invoke.arguments = new Expression[] { arg }; invoke.selector = ("unmodifiable" + data.getTargetSimpleType()).toCharArray(); invoke.receiver = new QualifiedNameReference(JAVA_UTIL_COLLECTIONS, NULL_POSS, 0, 0); unmodifiableStat = new Assignment(new SingleNameReference(data.getPluralName(), 0L), invoke, 0); } return Arrays.asList(createStat, fillStat, unmodifiableStat); }
From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java
License:Open Source License
protected void consumeUnaryExpression(int op, boolean post) { // PreIncrementExpression ::= '++' PushPosition UnaryExpression // PreDecrementExpression ::= '--' PushPosition UnaryExpression // ++ and -- operators //optimize the push/pop //this.intStack has the position of the operator when prefix Expression leftHandSide = this.expressionStack[this.expressionPtr]; if (leftHandSide instanceof Reference) { // ++foo()++ is unvalid if (post) { this.expressionStack[this.expressionPtr] = new PostfixExpression(leftHandSide, IntLiteral.One, op, this.endStatementPosition); } else {/*ww w. j av a2s .c om*/ this.expressionStack[this.expressionPtr] = new PrefixExpression(leftHandSide, IntLiteral.One, op, this.intStack[this.intPtr--]); } } else { //the ++ or the -- is NOT taken into account if code gen proceeds if (!post) { this.intPtr--; } if (!this.statementRecoveryActivated) problemReporter().invalidUnaryExpression(leftHandSide); } }
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 w w . ja va2 s .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.nabucco.framework.mda.template.java.extract.statement.JavaAstStatementExtractorVisitor.java
License:Open Source License
@Override public boolean visit(PostfixExpression postfixExpression, BlockScope scope) { Expression lhs = copy(postfixExpression.lhs, scope); Expression expression = copy(postfixExpression.expression, scope); PostfixExpression postfixCopy = new PostfixExpression(lhs, expression, postfixExpression.operator, postfixExpression.sourceEnd); this.statement = postfixCopy; return false; }