com.sun.tools.javac.util.Position Java Examples
The following examples show how to use
com.sun.tools.javac.util.Position.
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: DocImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Utility for subclasses which read HTML documentation files. */ String readHTMLDocumentation(InputStream input, FileObject filename) throws IOException { byte[] filecontents = new byte[input.available()]; try { DataInputStream dataIn = new DataInputStream(input); dataIn.readFully(filecontents); } finally { input.close(); } String encoding = env.getEncoding(); String rawDoc = (encoding!=null) ? new String(filecontents, encoding) : new String(filecontents); Pattern bodyPat = Pattern.compile("(?is).*<body\\b[^>]*>(.*)</body\\b.*"); Matcher m = bodyPat.matcher(rawDoc); if (m.matches()) { return m.group(1); } else { String key = rawDoc.matches("(?is).*<body\\b.*") ? "javadoc.End_body_missing_from_html_file" : "javadoc.Body_missing_from_html_file"; env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), key); return ""; } }
Example #2
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 #3
Source File: SourcePositionImpl.java From hottub 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: JavadocTool.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Construct a new javadoc tool. */ public static JavadocTool make0(Context context) { Messager messager = null; try { // force the use of Javadoc's class reader JavadocClassReader.preRegister(context); // force the use of Javadoc's own enter phase JavadocEnter.preRegister(context); // force the use of Javadoc's own member enter phase JavadocMemberEnter.preRegister(context); // force the use of Javadoc's own todo phase JavadocTodo.preRegister(context); // force the use of Messager as a Log messager = Messager.instance0(context); return new JavadocTool(context); } catch (CompletionFailure ex) { messager.error(Position.NOPOS, ex.getMessage()); return null; } }
Example #5
Source File: DocImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Utility for subclasses which read HTML documentation files. */ String readHTMLDocumentation(InputStream input, FileObject filename) throws IOException { byte[] filecontents = new byte[input.available()]; try { DataInputStream dataIn = new DataInputStream(input); dataIn.readFully(filecontents); } finally { input.close(); } String encoding = env.getEncoding(); String rawDoc = (encoding!=null) ? new String(filecontents, encoding) : new String(filecontents); Pattern bodyPat = Pattern.compile("(?is).*<body\\b[^>]*>(.*)</body\\b.*"); Matcher m = bodyPat.matcher(rawDoc); if (m.matches()) { return m.group(1); } else { String key = rawDoc.matches("(?is).*<body\\b.*") ? "javadoc.End_body_missing_from_html_file" : "javadoc.Body_missing_from_html_file"; env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), key); return ""; } }
Example #6
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 #7
Source File: SourcePositionImpl.java From openjdk-jdk8u-backup 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 #8
Source File: DocImpl.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Utility for subclasses which read HTML documentation files. */ String readHTMLDocumentation(InputStream input, FileObject filename) throws IOException { byte[] filecontents = new byte[input.available()]; try { DataInputStream dataIn = new DataInputStream(input); dataIn.readFully(filecontents); } finally { input.close(); } String encoding = env.getEncoding(); String rawDoc = (encoding!=null) ? new String(filecontents, encoding) : new String(filecontents); Pattern bodyPat = Pattern.compile("(?is).*<body\\b[^>]*>(.*)</body\\b.*"); Matcher m = bodyPat.matcher(rawDoc); if (m.matches()) { return m.group(1); } else { String key = rawDoc.matches("(?is).*<body\\b.*") ? "javadoc.End_body_missing_from_html_file" : "javadoc.Body_missing_from_html_file"; env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), key); return ""; } }
Example #9
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 #10
Source File: SourcePositionImpl.java From openjdk-jdk9 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) { int i = paren+1; if (fn.charAt(i) == '/') i++; fn = fn.substring(0, paren) + File.separatorChar + fn.substring(i, fn.length() - 1); } } if (position == Position.NOPOS) return fn; else return fn + ":" + line(); }
Example #11
Source File: JavadocTool.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Construct a new javadoc tool. */ public static JavadocTool make0(Context context) { Messager messager = null; try { // force the use of Javadoc's class reader JavadocClassReader.preRegister(context); // force the use of Javadoc's own enter phase JavadocEnter.preRegister(context); // force the use of Javadoc's own member enter phase JavadocMemberEnter.preRegister(context); // force the use of Javadoc's own todo phase JavadocTodo.preRegister(context); // force the use of Messager as a Log messager = Messager.instance0(context); return new JavadocTool(context); } catch (CompletionFailure ex) { messager.error(Position.NOPOS, ex.getMessage()); return null; } }
Example #12
Source File: JavadocTool.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Construct a new javadoc tool. */ public static JavadocTool make0(Context context) { Messager messager = null; try { // force the use of Javadoc's class reader JavadocClassReader.preRegister(context); // force the use of Javadoc's own enter phase JavadocEnter.preRegister(context); // force the use of Javadoc's own member enter phase JavadocMemberEnter.preRegister(context); // force the use of Javadoc's own todo phase JavadocTodo.preRegister(context); // force the use of Messager as a Log messager = Messager.instance0(context); return new JavadocTool(context); } catch (CompletionFailure ex) { messager.error(Position.NOPOS, ex.getMessage()); return null; } }
Example #13
Source File: DocCommentParser.java From openjdk-jdk9 with GNU General Public License v2.0 | 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 #14
Source File: DocImpl.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Utility for subclasses which read HTML documentation files. */ String readHTMLDocumentation(InputStream input, FileObject filename) throws IOException { byte[] filecontents = new byte[input.available()]; try { DataInputStream dataIn = new DataInputStream(input); dataIn.readFully(filecontents); } finally { input.close(); } String encoding = env.getEncoding(); String rawDoc = (encoding!=null) ? new String(filecontents, encoding) : new String(filecontents); Pattern bodyPat = Pattern.compile("(?is).*<body\\b[^>]*>(.*)</body\\b.*"); Matcher m = bodyPat.matcher(rawDoc); if (m.matches()) { return m.group(1); } else { String key = rawDoc.matches("(?is).*<body\\b.*") ? "javadoc.End_body_missing_from_html_file" : "javadoc.Body_missing_from_html_file"; env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), key); return ""; } }
Example #15
Source File: JavadocTool.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Construct a new javadoc tool. */ public static JavadocTool make0(Context context) { Messager messager = null; try { // force the use of Javadoc's class reader JavadocClassReader.preRegister(context); // force the use of Javadoc's own enter phase JavadocEnter.preRegister(context); // force the use of Javadoc's own member enter phase JavadocMemberEnter.preRegister(context); // force the use of Javadoc's own todo phase JavadocTodo.preRegister(context); // force the use of Messager as a Log messager = Messager.instance0(context); return new JavadocTool(context); } catch (CompletionFailure ex) { messager.error(Position.NOPOS, ex.getMessage()); return null; } }
Example #16
Source File: DocImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Utility for subclasses which read HTML documentation files. */ String readHTMLDocumentation(InputStream input, FileObject filename) throws IOException { byte[] filecontents = new byte[input.available()]; try { DataInputStream dataIn = new DataInputStream(input); dataIn.readFully(filecontents); } finally { input.close(); } String encoding = env.getEncoding(); String rawDoc = (encoding!=null) ? new String(filecontents, encoding) : new String(filecontents); Pattern bodyPat = Pattern.compile("(?is).*<body\\b[^>]*>(.*)</body\\b.*"); Matcher m = bodyPat.matcher(rawDoc); if (m.matches()) { return m.group(1); } else { String key = rawDoc.matches("(?is).*<body\\b.*") ? "javadoc.End_body_missing_from_html_file" : "javadoc.Body_missing_from_html_file"; env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), key); return ""; } }
Example #17
Source File: DocImpl.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Utility for subclasses which read HTML documentation files. */ String readHTMLDocumentation(InputStream input, FileObject filename) throws IOException { byte[] filecontents = new byte[input.available()]; try { DataInputStream dataIn = new DataInputStream(input); dataIn.readFully(filecontents); } finally { input.close(); } String encoding = env.getEncoding(); String rawDoc = (encoding!=null) ? new String(filecontents, encoding) : new String(filecontents); Pattern bodyPat = Pattern.compile("(?is).*<body\\b[^>]*>(.*)</body\\b.*"); Matcher m = bodyPat.matcher(rawDoc); if (m.matches()) { return m.group(1); } else { String key = rawDoc.matches("(?is).*<body\\b.*") ? "javadoc.End_body_missing_from_html_file" : "javadoc.Body_missing_from_html_file"; env.error(SourcePositionImpl.make(filename, Position.NOPOS, null), key); return ""; } }
Example #18
Source File: JavadocTool.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Construct a new javadoc tool. */ public static JavadocTool make0(Context context) { Messager messager = null; try { // force the use of Javadoc's class reader JavadocClassReader.preRegister(context); // force the use of Javadoc's own enter phase JavadocEnter.preRegister(context); // force the use of Javadoc's own member enter phase JavadocMemberEnter.preRegister(context); // force the use of Javadoc's own todo phase JavadocTodo.preRegister(context); // force the use of Messager as a Log messager = Messager.instance0(context); return new JavadocTool(context); } catch (CompletionFailure ex) { messager.error(Position.NOPOS, ex.getMessage()); return null; } }
Example #19
Source File: ExtensionTransformer.java From manifold with Apache License 2.0 | 6 votes |
private JCExpression classForNameCall( Type type, JCTree tree ) { TreeMaker make = _tp.getTreeMaker(); JavacElements javacElems = _tp.getElementUtil(); JCTree.JCMethodInvocation typeCall = make.Apply( List.nil(), memberAccess( make, javacElems, ReflectUtil.class.getName() + ".type" ), List.of( make.Literal( makeLiteralName( type ) ) ) ); typeCall.setPos( Position.NOPOS ); typeCall.type = _tp.getSymtab().classType; JCTree.JCFieldAccess newMethodSelect = (JCTree.JCFieldAccess)typeCall.getMethodSelect(); Symbol.ClassSymbol reflectMethodClassSym = IDynamicJdk.instance().getTypeElement( _tp.getContext(), _tp.getCompilationUnit(), ReflectUtil.class.getName() ); Symbol.MethodSymbol typeMethodSymbol = resolveMethod( tree.pos(), Names.instance( _tp.getContext() ).fromString( "type" ), reflectMethodClassSym.type, List.of( _tp.getSymtab().stringType ) ); newMethodSelect.sym = typeMethodSymbol; newMethodSelect.type = typeMethodSymbol.type; newMethodSelect.pos = tree.pos; assignTypes( newMethodSelect.selected, reflectMethodClassSym ); return typeCall; }
Example #20
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 #21
Source File: SourcePositionImpl.java From TencentKona-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 #22
Source File: JavadocTool.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Construct a new javadoc tool. */ public static JavadocTool make0(Context context) { Messager messager = null; try { // force the use of Javadoc's class finder JavadocClassFinder.preRegister(context); // force the use of Javadoc's own enter phase JavadocEnter.preRegister(context); // force the use of Javadoc's own member enter phase JavadocMemberEnter.preRegister(context); // force the use of Javadoc's own todo phase JavadocTodo.preRegister(context); // force the use of Messager as a Log messager = Messager.instance0(context); return new JavadocTool(context); } catch (CompletionFailure ex) { messager.error(Position.NOPOS, ex.getMessage()); return null; } }
Example #23
Source File: JavacSourcePosition.java From javaide with GNU General Public License v3.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 #24
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 #25
Source File: Test.java From hottub 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 #26
Source File: CRTable.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Compare the starting and the ending positions * of the source range and combines them assigning * the widest range to this. */ SourceRange mergeWith(SourceRange sr) { if (sr == null) return this; if (startPos == Position.NOPOS) startPos = sr.startPos; else if (sr.startPos != Position.NOPOS) startPos = (startPos < sr.startPos ? startPos : sr.startPos); if (endPos == Position.NOPOS) endPos = sr.endPos; else if (sr.endPos != Position.NOPOS) endPos = (endPos > sr.endPos ? endPos : sr.endPos); return this; }
Example #27
Source File: Checker.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public Boolean visitLiteral(LiteralTree tree, Trees trees) { TreePath path = getCurrentPath(); CompilationUnitTree unit = path.getCompilationUnit(); Position.LineMap lineMap = ((JCCompilationUnit)unit).lineMap; // long line = lineMap.getLineNumber(((JCTree)tree).pos/*trees.getSourcePositions().getStartPosition(tree)*/); // System.err.println(line + ": " + abbrev(tree)); Scope s = trees.getScope(path); if (tree.getKind() == Tree.Kind.STRING_LITERAL) check(s, tree.getValue().toString().trim()); return null; }
Example #28
Source File: Checker.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public Boolean visitLiteral(LiteralTree tree, Trees trees) { TreePath path = getCurrentPath(); CompilationUnitTree unit = path.getCompilationUnit(); Position.LineMap lineMap = ((JCCompilationUnit)unit).lineMap; // long line = lineMap.getLineNumber(((JCTree)tree).pos/*trees.getSourcePositions().getStartPosition(tree)*/); // System.err.println(line + ": " + abbrev(tree)); Scope s = trees.getScope(path); if (tree.getKind() == Tree.Kind.STRING_LITERAL) check(s, tree.getValue().toString().trim()); return null; }
Example #29
Source File: Test.java From openjdk-jdk8u 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 #30
Source File: JavacSourcePosition.java From openjdk-jdk8u 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; }