Java Code Examples for com.sun.tools.javac.tree.JCTree#getEndPosition()
The following examples show how to use
com.sun.tools.javac.tree.JCTree#getEndPosition() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompleteExpression.java From javaide with GNU General Public License v3.0 | 6 votes |
public void prepare(Editor editor, JCCompilationUnit ast) { mEditor = editor; mCursor = editor.getCursor(); mAst = ast; mEndPositions = ast.endPositions; List<JCTree> typeDecls = mAst.getTypeDecls(); for (JCTree typeDecl : typeDecls) { if (typeDecl instanceof JCTree.JCClassDecl) { int startPosition = typeDecl.getStartPosition(); int endPosition = typeDecl.getEndPosition(mEndPositions); if (startPosition <= mCursor && mCursor <= endPosition) { String simpleName = ((JCTree.JCClassDecl) typeDecl).getSimpleName().toString(); JCExpression packageName = ast.getPackageName(); mCurrentType = JavaClassManager.getInstance() .getParsedClass(packageName + "." + simpleName); } } } }
Example 2
Source File: CompilationUnitBuilder.java From j2cl with Apache License 2.0 | 6 votes |
/** Javac does not always report the end position of a construct. */ private int guessEndPosition(JCTree node) { int startCharacterPosition = node.getStartPosition(); int endCharacterPosition = node.getEndPosition(javacUnit.endPositions); if (endCharacterPosition == -1) { try { // Scan the source file for the end of an identifier. String src = javacUnit.sourcefile.getCharContent(true).toString(); endCharacterPosition = startCharacterPosition; while (endCharacterPosition < src.length() && Character.isJavaIdentifierPart(src.charAt(endCharacterPosition++))) {} } catch (IOException e) { throw internalCompilerError(e, "Error getting endPosition for: %s.", node); } } return endCharacterPosition; }
Example 3
Source File: TreeAnalyzer.java From meghanada-server with GNU General Public License v3.0 | 6 votes |
private static void analyzeAnnotationTree( final Source src, final EndPosTable endPosTable, final AnnotationTree at) { if (at instanceof JCTree.JCAnnotation) { JCTree.JCAnnotation anno = (JCTree.JCAnnotation) at; int startPos = anno.getPreferredPosition(); int endPos = anno.getEndPosition(endPosTable); JCTree annotationType = anno.getAnnotationType(); int annotationTypeEndPosition = annotationType.getEndPosition(endPosTable); Range range; if (endPos != annotationTypeEndPosition) { startPos = annotationTypeEndPosition; } range = Range.create(src, startPos + 1, endPos); Type type = anno.type; Annotation annotation; if (nonNull(type)) { annotation = new Annotation(type.toString(), startPos, range); } else { annotation = new Annotation(annotationType.toString(), startPos, range); } src.annotationMap.put(range.begin.line, annotation); } }
Example 4
Source File: ExpressionResolver.java From javaide with GNU General Public License v3.0 | 5 votes |
private boolean isCursorInsideTree(JCTree tree) { if (tree == null) { return false; } int startPosition = tree.getStartPosition(); int endPosition = tree.getEndPosition(mEndPositions); return startPosition <= mCursor && mCursor <= endPosition; }
Example 5
Source File: TypeResolver.java From javaide with GNU General Public License v3.0 | 4 votes |
private int getEndPosition(JCTree tree) { return tree.getEndPosition(mUnit.endPositions); }