List of usage examples for org.eclipse.jdt.internal.compiler.util Util getLineNumber
public static int getLineNumber(int position, int[] lineEnds, int g, int d)
From source file:com.google.gwt.dev.javac.GWTProblem.java
License:Open Source License
public static void recordProblem(ASTNode node, CompilationResult compResult, String message, HelpInfo helpInfo, int problemSeverity) { int[] lineEnds = compResult.getLineSeparatorPositions(); int startLine = Util.getLineNumber(node.sourceStart(), lineEnds, 0, lineEnds.length - 1); int startColumn = Util.searchColumnNumber(lineEnds, startLine, node.sourceStart()); recordProblem(node.sourceStart(), node.sourceEnd(), startLine, startColumn, compResult, message, helpInfo, problemSeverity);/*from w w w.ja v a2 s . c om*/ }
From source file:com.google.gwt.dev.javac.JsniCollector.java
License:Open Source License
public static JsFunction parseJsniFunction(AbstractMethodDeclaration method, String unitSource, String enclosingType, String fileName, JsProgram jsProgram) { CompilationResult compResult = method.compilationResult; int[] indexes = compResult.lineSeparatorPositions; int startLine = Util.getLineNumber(method.sourceStart, indexes, 0, indexes.length - 1); SourceInfo info = SourceOrigin.create(method.sourceStart, method.bodyEnd, startLine, fileName); // Handle JSNI block String jsniCode = unitSource.substring(method.bodyStart, method.bodyEnd + 1); int startPos = jsniCode.indexOf("/*-{"); int endPos = jsniCode.lastIndexOf("}-*/"); if (startPos < 0 && endPos < 0) { reportJsniError(info, method,// w w w . j ava 2 s . co m "Native methods require a JavaScript implementation enclosed with /*-{ and }-*/"); return null; } if (startPos < 0) { reportJsniError(info, method, "Unable to find start of native block; begin your JavaScript block with: /*-{"); return null; } if (endPos < 0) { reportJsniError(info, method, "Unable to find end of native block; terminate your JavaScript block with: }-*/"); return null; } startPos += 3; // move up to open brace endPos += 1; // move past close brace jsniCode = jsniCode.substring(startPos, endPos); // Here we parse it as an anonymous function, but we will give it a // name later when we generate the JavaScript during code generation. // StringBuilder functionSource = new StringBuilder("function ("); boolean first = true; if (method.arguments != null) { for (Argument arg : method.arguments) { if (first) { first = false; } else { functionSource.append(','); } functionSource.append(arg.binding.name); } } functionSource.append(") "); int functionHeaderLength = functionSource.length(); functionSource.append(jsniCode); StringReader sr = new StringReader(functionSource.toString()); // Absolute start and end position of braces in original source. int absoluteJsStartPos = method.bodyStart + startPos; int absoluteJsEndPos = absoluteJsStartPos + jsniCode.length(); // Adjust the points the JS parser sees to account for the synth header. int jsStartPos = absoluteJsStartPos - functionHeaderLength; int jsEndPos = absoluteJsEndPos - functionHeaderLength; // To compute the start line, count lines from point to point. int jsLine = info.getStartLine() + countLines(indexes, info.getStartPos(), absoluteJsStartPos); SourceInfo jsInfo = SourceOrigin.create(jsStartPos, jsEndPos, jsLine, info.getFileName()); try { List<JsStatement> result = JsParser.parse(jsInfo, jsProgram.getScope(), sr); JsExprStmt jsExprStmt = (JsExprStmt) result.get(0); return (JsFunction) jsExprStmt.getExpression(); } catch (IOException e) { throw new InternalCompilerException( "Internal error parsing JSNI in '" + enclosingType + '.' + method.toString() + '\'', e); } catch (JsParserException e) { int problemCharPos = computeAbsoluteProblemPosition(indexes, e.getSourceDetail()); SourceInfo errorInfo = SourceOrigin.create(problemCharPos, problemCharPos, e.getSourceDetail().getLine(), info.getFileName()); reportJsniError(errorInfo, method, e.getMessage()); return null; } }
From source file:com.google.gwt.dev.javac.JsniMethodCollector.java
License:Apache License
public static JsFunction parseJsniFunction(AbstractMethodDeclaration method, String unitSource, String enclosingType, SourceInfo baseInfo, JsScope scope) { CompilationResult compResult = method.compilationResult; int[] indexes = compResult.lineSeparatorPositions; int startLine = Util.getLineNumber(method.sourceStart, indexes, 0, indexes.length - 1); SourceInfo info = baseInfo.makeChild( SourceOrigin.create(method.sourceStart, method.bodyEnd, startLine, baseInfo.getFileName())); // Handle JSNI block String jsniCode = unitSource.substring(method.bodyStart, method.bodyEnd + 1); int startPos = jsniCode.indexOf("/*-{"); int endPos = jsniCode.lastIndexOf("}-*/"); if (startPos < 0 && endPos < 0) { reportJsniError(info, method,//from w ww . j a v a 2 s. c om "Native methods require a JavaScript implementation enclosed with /*-{ and }-*/"); return null; } if (startPos < 0) { reportJsniError(info, method, "Unable to find start of native block; begin your JavaScript block with: /*-{"); return null; } if (endPos < 0) { reportJsniError(info, method, "Unable to find end of native block; terminate your JavaScript block with: }-*/"); return null; } startPos += 3; // move up to open brace endPos += 1; // move past close brace jsniCode = jsniCode.substring(startPos, endPos); // Here we parse it as an anonymous function, but we will give it a // name later when we generate the JavaScript during code generation. // StringBuilder functionSource = new StringBuilder("function ("); boolean first = true; if (method.arguments != null) { for (Argument arg : method.arguments) { if (first) { first = false; } else { functionSource.append(','); } functionSource.append(arg.binding.name); } } functionSource.append(") "); int functionHeaderLength = functionSource.length(); functionSource.append(jsniCode); StringReader sr = new StringReader(functionSource.toString()); // Absolute start and end position of braces in original source. int absoluteJsStartPos = method.bodyStart + startPos; int absoluteJsEndPos = absoluteJsStartPos + jsniCode.length(); // Adjust the points the JS parser sees to account for the synth header. int jsStartPos = absoluteJsStartPos - functionHeaderLength; int jsEndPos = absoluteJsEndPos - functionHeaderLength; // To compute the start line, count lines from point to point. int jsLine = info.getStartLine() + countLines(indexes, info.getStartPos(), absoluteJsStartPos); SourceInfo jsInfo = baseInfo .makeChild(SourceOrigin.create(jsStartPos, jsEndPos, jsLine, baseInfo.getFileName())); try { List<JsStatement> result = JsParser.parse(jsInfo, scope, sr); JsExprStmt jsExprStmt = (JsExprStmt) result.get(0); return (JsFunction) jsExprStmt.getExpression(); } catch (IOException e) { throw new InternalCompilerException( "Internal error parsing JSNI in '" + enclosingType + '.' + method.toString() + '\'', e); } catch (JsParserException e) { int problemCharPos = computeAbsoluteProblemPosition(indexes, e.getSourceDetail()); SourceInfo errorInfo = SourceOrigin.create(problemCharPos, problemCharPos, e.getSourceDetail().getLine(), info.getFileName()); // Strip the file/line header because reportJsniError will add that. String msg = e.getMessage(); int pos = msg.indexOf(": "); msg = msg.substring(pos + 2); reportJsniError(errorInfo, method, msg); return null; } }
From source file:com.google.gwt.dev.jjs.impl.GwtAstBuilder.java
License:Apache License
SourceInfo makeSourceInfo(AbstractMethodDeclaration x) {
int startLine = Util.getLineNumber(x.sourceStart, curCud.separatorPositions, 0,
curCud.separatorPositions.length - 1);
return SourceOrigin.create(x.sourceStart, x.bodyEnd, startLine, sourceMapPath);
}
From source file:com.google.gwt.dev.jjs.impl.GwtAstBuilder.java
License:Apache License
SourceInfo makeSourceInfo(ASTNode x) {
int startLine = Util.getLineNumber(x.sourceStart, curCud.separatorPositions, 0,
curCud.separatorPositions.length - 1);
return SourceOrigin.create(x.sourceStart, x.sourceEnd, startLine, sourceMapPath);
}
From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java
License:Open Source License
protected void consumeEnterVariable() { // EnterVariable ::= $empty // do nothing by default char[] identifierName = this.identifierStack[this.identifierPtr]; long namePosition = this.identifierPositionStack[this.identifierPtr]; int extendedDimension = this.intStack[this.intPtr--]; AbstractVariableDeclaration declaration; // create the ast node boolean isLocalDeclaration = this.nestedMethod[this.nestedType] != 0; if (isLocalDeclaration) { // create the local variable declarations declaration = createLocalDeclaration(identifierName, (int) (namePosition >>> 32), (int) namePosition); } else {//from ww w. jav a2 s . c o m // create the field declaration declaration = createFieldDeclaration(identifierName, (int) (namePosition >>> 32), (int) namePosition); } this.identifierPtr--; this.identifierLengthPtr--; TypeReference type; int variableIndex = this.variablesCounter[this.nestedType]; int typeDim = 0; if (variableIndex == 0) { // first variable of the declaration (FieldDeclaration or LocalDeclaration) if (isLocalDeclaration) { declaration.declarationSourceStart = this.intStack[this.intPtr--]; declaration.modifiers = this.intStack[this.intPtr--]; // consume annotations int length; if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) { System.arraycopy(this.expressionStack, (this.expressionPtr -= length) + 1, declaration.annotations = new Annotation[length], 0, length); } type = getTypeReference(typeDim = this.intStack[this.intPtr--]); // type dimension if (declaration.declarationSourceStart == -1) { // this is true if there is no modifiers for the local variable declaration declaration.declarationSourceStart = type.sourceStart; } pushOnAstStack(type); } else { type = getTypeReference(typeDim = this.intStack[this.intPtr--]); // type dimension pushOnAstStack(type); declaration.declarationSourceStart = this.intStack[this.intPtr--]; declaration.modifiers = this.intStack[this.intPtr--]; // consume annotations int length; if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) { System.arraycopy(this.expressionStack, (this.expressionPtr -= length) + 1, declaration.annotations = new Annotation[length], 0, length); } // Store javadoc only on first declaration as it is the same for all ones FieldDeclaration fieldDeclaration = (FieldDeclaration) declaration; fieldDeclaration.javadoc = this.javadoc; } this.javadoc = null; } else { type = (TypeReference) this.astStack[this.astPtr - variableIndex]; typeDim = type.dimensions(); AbstractVariableDeclaration previousVariable = (AbstractVariableDeclaration) this.astStack[this.astPtr]; declaration.declarationSourceStart = previousVariable.declarationSourceStart; declaration.modifiers = previousVariable.modifiers; final Annotation[] annotations = previousVariable.annotations; if (annotations != null) { final int annotationsLength = annotations.length; System.arraycopy(annotations, 0, declaration.annotations = new Annotation[annotationsLength], 0, annotationsLength); } } if (extendedDimension == 0) { declaration.type = type; } else { int dimension = typeDim + extendedDimension; declaration.type = copyDims(type, dimension); } this.variablesCounter[this.nestedType]++; pushOnAstStack(declaration); // recovery if (this.currentElement != null) { if (!(this.currentElement instanceof RecoveredType) && (this.currentToken == TokenNameDOT //|| declaration.modifiers != 0 || (Util.getLineNumber(declaration.type.sourceStart, this.scanner.lineEnds, 0, this.scanner.linePtr) != Util.getLineNumber((int) (namePosition >>> 32), this.scanner.lineEnds, 0, this.scanner.linePtr)))) { this.lastCheckPoint = (int) (namePosition >>> 32); this.restartRecovery = true; return; } if (isLocalDeclaration) { LocalDeclaration localDecl = (LocalDeclaration) this.astStack[this.astPtr]; this.lastCheckPoint = localDecl.sourceEnd + 1; this.currentElement = this.currentElement.add(localDecl, 0); } else { FieldDeclaration fieldDecl = (FieldDeclaration) this.astStack[this.astPtr]; this.lastCheckPoint = fieldDecl.sourceEnd + 1; this.currentElement = this.currentElement.add(fieldDecl, 0); } this.lastIgnoredToken = -1; } }
From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java
License:Open Source License
protected void consumeMethodHeaderName(boolean isAnnotationMethod) { // MethodHeaderName ::= Modifiersopt Type 'Identifier' '(' // AnnotationMethodHeaderName ::= Modifiersopt Type 'Identifier' '(' // RecoveryMethodHeaderName ::= Modifiersopt Type 'Identifier' '(' MethodDeclaration md = null;/* ww w .j a va2 s .c om*/ if (isAnnotationMethod) { md = new AnnotationMethodDeclaration(this.compilationUnit.compilationResult); this.recordStringLiterals = false; } else { md = new MethodDeclaration(this.compilationUnit.compilationResult); } //name md.selector = this.identifierStack[this.identifierPtr]; long selectorSource = this.identifierPositionStack[this.identifierPtr--]; this.identifierLengthPtr--; //type md.returnType = getTypeReference(this.intStack[this.intPtr--]); //modifiers md.declarationSourceStart = this.intStack[this.intPtr--]; md.modifiers = this.intStack[this.intPtr--]; // consume annotations int length; if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) { System.arraycopy(this.expressionStack, (this.expressionPtr -= length) + 1, md.annotations = new Annotation[length], 0, length); } // javadoc md.javadoc = this.javadoc; this.javadoc = null; //highlight starts at selector start md.sourceStart = (int) (selectorSource >>> 32); pushOnAstStack(md); md.sourceEnd = this.lParenPos; md.bodyStart = this.lParenPos + 1; this.listLength = 0; // initialize this.listLength before reading parameters/throws // recovery if (this.currentElement != null) { if (this.currentElement instanceof RecoveredType //|| md.modifiers != 0 || (Util.getLineNumber(md.returnType.sourceStart, this.scanner.lineEnds, 0, this.scanner.linePtr) == Util.getLineNumber(md.sourceStart, this.scanner.lineEnds, 0, this.scanner.linePtr))) { this.lastCheckPoint = md.bodyStart; this.currentElement = this.currentElement.add(md, 0); this.lastIgnoredToken = -1; } else { this.lastCheckPoint = md.sourceStart; this.restartRecovery = true; } } }
From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java
License:Open Source License
protected void consumeMethodHeaderNameWithTypeParameters(boolean isAnnotationMethod) { // MethodHeaderName ::= Modifiersopt TypeParameters Type 'Identifier' '(' // AnnotationMethodHeaderName ::= Modifiersopt TypeParameters Type 'Identifier' '(' // RecoveryMethodHeaderName ::= Modifiersopt TypeParameters Type 'Identifier' '(' MethodDeclaration md = null;//from w ww. ja v a 2 s .c o m if (isAnnotationMethod) { md = new AnnotationMethodDeclaration(this.compilationUnit.compilationResult); this.recordStringLiterals = false; } else { md = new MethodDeclaration(this.compilationUnit.compilationResult); } //name md.selector = this.identifierStack[this.identifierPtr]; long selectorSource = this.identifierPositionStack[this.identifierPtr--]; this.identifierLengthPtr--; //type md.returnType = getTypeReference(this.intStack[this.intPtr--]); // consume type parameters int length = this.genericsLengthStack[this.genericsLengthPtr--]; this.genericsPtr -= length; System.arraycopy(this.genericsStack, this.genericsPtr + 1, md.typeParameters = new TypeParameter[length], 0, length); //modifiers md.declarationSourceStart = this.intStack[this.intPtr--]; md.modifiers = this.intStack[this.intPtr--]; // consume annotations if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) { System.arraycopy(this.expressionStack, (this.expressionPtr -= length) + 1, md.annotations = new Annotation[length], 0, length); } // javadoc md.javadoc = this.javadoc; this.javadoc = null; //highlight starts at selector start md.sourceStart = (int) (selectorSource >>> 32); pushOnAstStack(md); md.sourceEnd = this.lParenPos; md.bodyStart = this.lParenPos + 1; this.listLength = 0; // initialize this.listLength before reading parameters/throws // recovery if (this.currentElement != null) { boolean isType; if ((isType = this.currentElement instanceof RecoveredType) //|| md.modifiers != 0 || (Util.getLineNumber(md.returnType.sourceStart, this.scanner.lineEnds, 0, this.scanner.linePtr) == Util.getLineNumber(md.sourceStart, this.scanner.lineEnds, 0, this.scanner.linePtr))) { if (isType) { ((RecoveredType) this.currentElement).pendingTypeParameters = null; } this.lastCheckPoint = md.bodyStart; this.currentElement = this.currentElement.add(md, 0); this.lastIgnoredToken = -1; } else { this.lastCheckPoint = md.sourceStart; this.restartRecovery = true; } } }
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; // }//w w w .j ava 2 s . 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.jdt.internal.compiler.parser.Parser.java
License:Open Source License
public int flushCommentsDefinedPriorTo(int position) { int lastCommentIndex = this.scanner.commentPtr; if (lastCommentIndex < 0) return position; // no comment // compute the index of the first obsolete comment int index = lastCommentIndex; int validCount = 0; while (index >= 0) { int commentEnd = this.scanner.commentStops[index]; if (commentEnd < 0) commentEnd = -commentEnd; // negative end position for non-javadoc comments if (commentEnd <= position) { break; }/*from ww w . ja v a2s . c o m*/ index--; validCount++; } // if the source at <position> is immediately followed by a line comment, then // flush this comment and shift <position> to the comment end. if (validCount > 0) { int immediateCommentEnd = -this.scanner.commentStops[index + 1]; //non-javadoc comment end positions are negative if (immediateCommentEnd > 0) { // only tolerating non-javadoc comments // is there any line break until the end of the immediate comment ? (thus only tolerating line comment) immediateCommentEnd--; // comment end in one char too far if (Util.getLineNumber(position, this.scanner.lineEnds, 0, this.scanner.linePtr) == Util .getLineNumber(immediateCommentEnd, this.scanner.lineEnds, 0, this.scanner.linePtr)) { position = immediateCommentEnd; validCount--; // flush this comment index++; } } } if (index < 0) return position; // no obsolete comment switch (validCount) { case 0: // do nothing break; // move valid comment infos, overriding obsolete comment infos case 2: this.scanner.commentStarts[0] = this.scanner.commentStarts[index + 1]; this.scanner.commentStops[0] = this.scanner.commentStops[index + 1]; this.scanner.commentTagStarts[0] = this.scanner.commentTagStarts[index + 1]; this.scanner.commentStarts[1] = this.scanner.commentStarts[index + 2]; this.scanner.commentStops[1] = this.scanner.commentStops[index + 2]; this.scanner.commentTagStarts[1] = this.scanner.commentTagStarts[index + 2]; break; case 1: this.scanner.commentStarts[0] = this.scanner.commentStarts[index + 1]; this.scanner.commentStops[0] = this.scanner.commentStops[index + 1]; this.scanner.commentTagStarts[0] = this.scanner.commentTagStarts[index + 1]; break; default: System.arraycopy(this.scanner.commentStarts, index + 1, this.scanner.commentStarts, 0, validCount); System.arraycopy(this.scanner.commentStops, index + 1, this.scanner.commentStops, 0, validCount); System.arraycopy(this.scanner.commentTagStarts, index + 1, this.scanner.commentTagStarts, 0, validCount); } this.scanner.commentPtr = validCount - 1; return position; }