Java 类com.sun.tools.javac.tree.JCTree.JCPackageDecl 实例源码

项目:openjdk9    文件:Modules.java   
private Location getModuleLocation(JCCompilationUnit tree) throws IOException {
    switch (tree.defs.head.getTag()) {
        case MODULEDEF:
            return getModuleLocation(tree.sourcefile, null);

        case PACKAGEDEF:
            JCPackageDecl pkg = (JCPackageDecl) tree.defs.head;
            return getModuleLocation(tree.sourcefile, TreeInfo.fullName(pkg.pid));

        default:
            // code in unnamed module
            return null;
    }
}
项目:incubator-netbeans    文件:CasualDiff.java   
protected int diffPackage(JCPackageDecl oldT, JCPackageDecl newT, int start) {
    int packageKeywordStart = start;
    JCExpression oldTPid = oldT != null ? oldT.pid : null;
    JCExpression newTPid = newT != null ? newT.pid : null;
    if (oldTPid != null) {
        tokenSequence.move(oldTPid.getStartPosition());
        moveToSrcRelevant(tokenSequence, Direction.BACKWARD);
        packageKeywordStart = tokenSequence.offset();
    }
    com.sun.tools.javac.util.List<JCAnnotation> oldTAnnotations = oldT != null ? oldT.annotations : com.sun.tools.javac.util.List.<JCAnnotation>nil();
    com.sun.tools.javac.util.List<JCAnnotation> newTAnnotations = newT != null ? newT.annotations : com.sun.tools.javac.util.List.<JCAnnotation>nil();
    //when adding first annotation, skip initial comments (typically a license):
    int localPointer = oldTAnnotations.isEmpty() && !newTAnnotations.isEmpty() ? packageKeywordStart : start;
    localPointer = diffAnnotationsLists(oldTAnnotations, newTAnnotations, localPointer, start);
    ChangeKind change = getChangeKind(oldTPid, newTPid);
    switch (change) {
        // packages are the same or not available, i.e. both are null
        case NOCHANGE:
            if (oldTPid != null) {
                localPointer = copyUpTo(localPointer, endPos(oldTPid));
            }
            break;

        // package statement is new, print the keyword and semicolon
        case INSERT:
            printer.printPackage(newTPid);
            break;

        // package statement was deleted.
        case DELETE:
            copyTo(localPointer, packageKeywordStart);
            tokenSequence.move(endPos(oldTPid));
            moveToSrcRelevant(tokenSequence, Direction.FORWARD);
            localPointer = tokenSequence.offset() + 1;
            // todo (#pf): check the declaration:
            // package org.netbeans /* aa */;
            break;

        // package statement was modified.
        case MODIFY:
            copyTo(localPointer, getOldPos(oldTPid));
            localPointer = endPos(oldTPid);
            printer.print(newTPid);
            diffInfo.put(getOldPos(oldTPid), NbBundle.getMessage(CasualDiff.class,"TXT_UpdatePackageStatement"));
            break;
    }
    return localPointer;
}
项目:openjdk-jdk10    文件:ToolEnvironment.java   
TreePath getTreePath(JCCompilationUnit toplevel, JCPackageDecl tree) {
    TreePath p = treePaths.get(tree);
    if (p == null)
        treePaths.put(tree, p = new TreePath(getTreePath(toplevel), tree));
    return p;
}
项目:openjdk-jdk10    文件:DocEnv.java   
TreePath getTreePath(JCCompilationUnit toplevel, JCPackageDecl tree) {
    TreePath p = treePaths.get(tree);
    if (p == null)
        treePaths.put(tree, p = new TreePath(getTreePath(toplevel), tree));
    return p;
}
项目:openjdk9    文件:DocEnv.java   
TreePath getTreePath(JCCompilationUnit toplevel, JCPackageDecl tree) {
    TreePath p = treePaths.get(tree);
    if (p == null)
        treePaths.put(tree, p = new TreePath(getTreePath(toplevel), tree));
    return p;
}
项目:openjdk9    文件:DocEnv.java   
TreePath getTreePath(JCCompilationUnit toplevel, JCPackageDecl tree) {
    TreePath p = treePaths.get(tree);
    if (p == null)
        treePaths.put(tree, p = new TreePath(getTreePath(toplevel), tree));
    return p;
}
项目:error-prone    文件:ASTHelpers.java   
/** Gets the symbol for a package. */
public static PackageSymbol getSymbol(PackageTree tree) {
  return ((JCPackageDecl) tree).packge;
}