Java Code Examples for com.sun.tools.javac.util.Position#NOPOS
The following examples show how to use
com.sun.tools.javac.util.Position#NOPOS .
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: DocCommentParser.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
public DCDocComment parse() { String c = comment.getText(); buf = new char[c.length() + 1]; c.getChars(0, c.length(), buf, 0); buf[buf.length - 1] = EOI; buflen = buf.length - 1; bp = -1; nextChar(); List<DCTree> body = blockContent(); List<DCTree> tags = blockTags(); int pos = !body.isEmpty() ? body.head.pos : !tags.isEmpty() ? tags.head.pos : Position.NOPOS; DCDocComment dc = m.at(pos).newDocCommentTree(comment, body, tags); return dc; }
Example 2
Source File: TreeFinder.java From annotation-tools with MIT License | 6 votes |
@Override public Pair<ASTRecord, Integer> visitMethod(MethodTree node, Insertion ins) { dbug.debug("TypePositionFinder.visitMethod%n"); super.visitMethod(node, ins); JCMethodDecl jcnode = (JCMethodDecl) node; JCVariableDecl jcvar = (JCVariableDecl) node.getReceiverParameter(); if (jcvar != null) { return pathAndPos(jcvar); } int pos = Position.NOPOS; ASTRecord astPath = astRecord(jcnode) .extend(Tree.Kind.METHOD, ASTPath.PARAMETER, -1); if (node.getParameters().isEmpty()) { // no parameters; find first (uncommented) '(' after method name pos = findMethodName(jcnode); if (pos >= 0) { pos = getFirstInstanceAfter('(', pos); } if (++pos <= 0) { throw new RuntimeException("Couldn't find param opening paren for: " + jcnode); } } else { pos = ((JCTree) node.getParameters().get(0)).getStartPosition(); } return Pair.of(astPath, pos); }
Example 3
Source File: SourcePositionImpl.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public String toString() { // Backwards compatibility hack. ZipFileObjects use the format // zipfile(zipentry) but javadoc has been using zipfile/zipentry String fn = filename.getName(); if (fn.endsWith(")")) { int paren = fn.lastIndexOf("("); if (paren != -1) fn = fn.substring(0, paren) + File.separatorChar + fn.substring(paren + 1, fn.length() - 1); } if (position == Position.NOPOS) return fn; else return fn + ":" + line(); }
Example 4
Source File: SourcePositionImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public String toString() { // Backwards compatibility hack. ZipFileObjects use the format // zipfile(zipentry) but javadoc has been using zipfile/zipentry String fn = filename.getName(); if (fn.endsWith(")")) { int paren = fn.lastIndexOf("("); if (paren != -1) fn = fn.substring(0, paren) + File.separatorChar + fn.substring(paren + 1, fn.length() - 1); } if (position == Position.NOPOS) return fn; else return fn + ":" + line(); }
Example 5
Source File: SourcePositionImpl.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public String toString() { // Backwards compatibility hack. ZipFileObjects use the format // zipfile(zipentry) but javadoc has been using zipfile/zipentry String fn = filename.getName(); if (fn.endsWith(")")) { int paren = fn.lastIndexOf("("); if (paren != -1) fn = fn.substring(0, paren) + File.separatorChar + fn.substring(paren + 1, fn.length() - 1); } if (position == Position.NOPOS) return fn; else return fn + ":" + line(); }
Example 6
Source File: Test.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
void checkEndPos(CompilationUnitTree unit, Tree tree) { long sp = srcPosns.getStartPosition(unit, tree); long ep = srcPosns.getEndPosition(unit, tree); if (sp >= 0 && ep == Position.NOPOS) { error("endpos not set for " + tree.getKind() + " " + Pretty.toSimpleString(((JCTree) tree)) +", start:" + sp); } }
Example 7
Source File: DocTreeMaker.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override @DefinedBy(Api.COMPILER_TREE) public DCDocComment newDocCommentTree(List<? extends DocTree> fullBody, List<? extends DocTree> tags) { ListBuffer<DCTree> lb = new ListBuffer<>(); lb.addAll(cast(fullBody)); List<DCTree> fBody = lb.toList(); // A dummy comment to keep the diagnostics logic happy. Comment c = new Comment() { @Override public String getText() { return null; } @Override public int getSourcePos(int index) { return Position.NOPOS; } @Override public CommentStyle getStyle() { return CommentStyle.JAVADOC; } @Override public boolean isDeprecated() { return false; } }; Pair<List<DCTree>, List<DCTree>> pair = splitBody(fullBody); DCDocComment tree = new DCDocComment(c, fBody, pair.fst, pair.snd, cast(tags)); return tree; }
Example 8
Source File: Test.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
void checkEndPos(CompilationUnitTree unit, Tree tree) { long sp = srcPosns.getStartPosition(unit, tree); long ep = srcPosns.getEndPosition(unit, tree); if (sp >= 0 && ep == Position.NOPOS) { error("endpos not set for " + tree.getKind() + " " + Pretty.toSimpleString(((JCTree) tree)) +", start:" + sp); } }
Example 9
Source File: JavacSourcePosition.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
JavacSourcePosition(JavaFileObject sourcefile, int pos, Position.LineMap lineMap) { this.sourcefile = sourcefile; this.pos = pos; this.lineMap = (pos != Position.NOPOS) ? lineMap : null; }
Example 10
Source File: TreeFinder.java From annotation-tools with MIT License | 5 votes |
/** * Returns the start position of the method's name. In particular, * works properly for constructors, for which the name field in the * AST is always "<init>" instead of the name from the source. * * @param node AST node of method declaration * @return position of method name (from {@link JCMethodDecl#sym}) in source */ private int findMethodName(JCMethodDecl node) { String sym = node.sym.toString(); String name = sym.substring(0, sym.indexOf('(')); JCModifiers mods = node.getModifiers(); JCBlock body = node.body; if ((mods.flags & Flags.GENERATEDCONSTR) != 0) { return Position.NOPOS; } int nodeStart = node.getStartPosition(); int nodeEnd = node.getEndPosition(tree.endPositions); int nodeLength = nodeEnd - nodeStart; int modsLength = mods.getEndPosition(tree.endPositions) - mods.getStartPosition(); // can't trust string length! int bodyLength = body == null ? 1 : body.getEndPosition(tree.endPositions) - body.getStartPosition(); int start = nodeStart + modsLength; int end = nodeStart + nodeLength - bodyLength; int angle = name.lastIndexOf('>'); // check for type params if (angle >= 0) { name = name.substring(angle + 1); } try { CharSequence s = tree.getSourceFile().getCharContent(true); String regex = "\\b" + Pattern.quote(name) + "\\b"; // sufficient? Pattern pat = Pattern.compile(regex, Pattern.MULTILINE); Matcher mat = pat.matcher(s).region(start, end); return mat.find() ? mat.start() : Position.NOPOS; } catch (IOException e) { throw new RuntimeException(e); } }
Example 11
Source File: DocTreeMaker.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Create a tree maker with NOPOS as initial position. */ protected DocTreeMaker(Context context) { context.put(treeMakerKey, this); diags = JCDiagnostic.Factory.instance(context); this.pos = Position.NOPOS; trees = JavacTrees.instance(context); referenceParser = new ReferenceParser(ParserFactory.instance(context)); sentenceBreakTags = EnumSet.of(H1, H2, H3, H4, H5, H6, PRE, P); }
Example 12
Source File: JavacSourcePosition.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
JavacSourcePosition(JavaFileObject sourcefile, int pos, Position.LineMap lineMap) { this.sourcefile = sourcefile; this.pos = pos; this.lineMap = (pos != Position.NOPOS) ? lineMap : null; }
Example 13
Source File: DocTreeMaker.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** Reassign current position. */ public DocTreeMaker at(DiagnosticPosition pos) { this.pos = (pos == null ? Position.NOPOS : pos.getStartPosition()); return this; }
Example 14
Source File: DocTreeMaker.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** Create a tree maker with NOPOS as initial position. */ protected DocTreeMaker(Context context) { context.put(treeMakerKey, this); diags = JCDiagnostic.Factory.instance(context); this.pos = Position.NOPOS; }
Example 15
Source File: DocTreeMaker.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** Create a tree maker with NOPOS as initial position. */ protected DocTreeMaker(Context context) { context.put(treeMakerKey, this); diags = JCDiagnostic.Factory.instance(context); this.pos = Position.NOPOS; }
Example 16
Source File: PrettyCommentsPrinter.java From EasyMPermission with MIT License | 4 votes |
public boolean isEmptyStat(JCTree tree) { if (!(tree instanceof JCBlock)) return false; JCBlock block = (JCBlock) tree; return (Position.NOPOS == block.pos) && block.stats.isEmpty(); }
Example 17
Source File: DocTreeMaker.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** Reassign current position. */ public DocTreeMaker at(DiagnosticPosition pos) { this.pos = (pos == null ? Position.NOPOS : pos.getStartPosition()); return this; }
Example 18
Source File: DocTreeMaker.java From hottub with GNU General Public License v2.0 | 4 votes |
/** Reassign current position. */ public DocTreeMaker at(DiagnosticPosition pos) { this.pos = (pos == null ? Position.NOPOS : pos.getStartPosition()); return this; }
Example 19
Source File: NBParserFactory.java From netbeans with Apache License 2.0 | 4 votes |
public void resetErrorEndPos() { delegate.errorEndPos = Position.NOPOS; errorEndPos = delegate.errorEndPos; }
Example 20
Source File: CRTable.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** Constructor */ SourceRange() { startPos = Position.NOPOS; endPos = Position.NOPOS; }