Java Code Examples for com.sun.tools.javac.tree.JCTree#getStartPosition()
The following examples show how to use
com.sun.tools.javac.tree.JCTree#getStartPosition() .
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: 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 4
Source File: TypeResolver.java From javaide with GNU General Public License v3.0 | 4 votes |
private boolean isChildOfParent(JCTree parent, JCTree child) { //scope of child inside parent return parent.getStartPosition() <= child.getStartPosition() && getEndPosition(parent) >= getEndPosition(child); }
Example 5
Source File: CompilationUnitBuilder.java From j2cl with Apache License 2.0 | 4 votes |
private SourcePosition getSourcePosition(String name, JCTree node) { int startCharacterPosition = node.getStartPosition(); int endCharacterPosition = guessEndPosition(node); return getSourcePosition(name, startCharacterPosition, endCharacterPosition); }