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: SourcePositionImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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 #2
Source File: TreeFinder.java    From annotation-tools with MIT License 6 votes vote down vote up
@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: JavadocTool.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 *  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 #4
Source File: DocImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #5
Source File: JavadocTool.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 *  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 #6
Source File: SourcePositionImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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 #7
Source File: SourcePositionImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
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 vote down vote up
/**
 * 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-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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: JavadocTool.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 *  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 #11
Source File: DocImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #12
Source File: DocCommentParser.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #13
Source File: DocImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #14
Source File: SourcePositionImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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 #15
Source File: JavadocTool.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 *  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-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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: SourcePositionImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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 #18
Source File: DocCommentParser.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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 #19
Source File: DocImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #20
Source File: JavadocTool.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 *  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 #21
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 6 votes vote down vote up
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 #22
Source File: JavadocTool.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 *  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: ClassDocImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the source position of the entity, or null if
 * no position is available.
 */
@Override
public SourcePosition position() {
    if (tsym.sourcefile == null) return null;
    return SourcePositionImpl.make(tsym.sourcefile,
                                   (tree==null) ? Position.NOPOS : tree.pos,
                                   lineMap);
}
 
Example #24
Source File: JavacSourcePosition.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
JavacSourcePosition(JavaFileObject sourcefile,
                    int pos,
                    Position.LineMap lineMap) {
    this.sourcefile = sourcefile;
    this.pos = pos;
    this.lineMap = (pos != Position.NOPOS) ? lineMap : null;
}
 
Example #25
Source File: JavacSourcePosition.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
JavacSourcePosition(JavaFileObject sourcefile,
                    int pos,
                    Position.LineMap lineMap) {
    this.sourcefile = sourcefile;
    this.pos = pos;
    this.lineMap = (pos != Position.NOPOS) ? lineMap : null;
}
 
Example #26
Source File: Test.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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 #27
Source File: Checker.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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: RootDocImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the source position of the entity, or null if
 * no position is available.
 */
@Override
public SourcePosition position() {
    JavaFileObject path;
    return ((path = getOverviewPath()) == null) ?
        null :
        SourcePositionImpl.make(path, Position.NOPOS, null);
}
 
Example #29
Source File: RootDocImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the source position of the entity, or null if
 * no position is available.
 */
@Override
public SourcePosition position() {
    JavaFileObject path;
    return ((path = getOverviewPath()) == null) ?
        null :
        SourcePositionImpl.make(path, Position.NOPOS, null);
}
 
Example #30
Source File: ClassDocImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the source position of the entity, or null if
 * no position is available.
 */
@Override
public SourcePosition position() {
    if (tsym.sourcefile == null) return null;
    return SourcePositionImpl.make(tsym.sourcefile,
                                   (tree==null) ? Position.NOPOS : tree.pos,
                                   lineMap);
}