List of usage examples for org.eclipse.jdt.internal.compiler.ast IntLiteral buildIntLiteral
public static IntLiteral buildIntLiteral(char[] token, int s, int e)
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.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 w w w.j a v a 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.ast.LiftingTypeReference.java
License:Open Source License
private TypeBinding invalidate(TypeBinding variableType) { if (this.fakedArgument != null && variableType != null) { int start = this.roleReference.sourceStart; int end = this.roleReference.sourceEnd; Expression nullValue = null; if (variableType.isBaseType()) { char[] tok = new char[] { '0' }; switch (variableType.id) { case TypeIds.T_boolean: nullValue = new FalseLiteral(start, end); break; case TypeIds.T_char: nullValue = new CharLiteral(tok, start, end); break; case TypeIds.T_double: nullValue = new DoubleLiteral(tok, start, end); break; case TypeIds.T_float: nullValue = new FloatLiteral(tok, start, end); break; case TypeIds.T_int: nullValue = IntLiteral.buildIntLiteral(tok, start, end); break; case TypeIds.T_long: nullValue = LongLiteral.buildLongLiteral(tok, start, end); break; }/* www. j a v a 2 s . c o m*/ } else { nullValue = new NullLiteral(start, end); } this.fakedArgument.initialization = nullValue; if (variableType.isValidBinding()) this.fakedArgument.type = new AstGenerator(this).typeReference(variableType); } return null; }
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. j a v a2 s . co 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.util.AstGenerator.java
License:Open Source License
public IntLiteral intLiteral(int val) { IntLiteral result = IntLiteral.buildIntLiteral(String.valueOf(val).toCharArray(), this.sourceStart, this.sourceEnd); return result; }