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; } }
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; }
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; }
/** Gets the symbol for a package. */ public static PackageSymbol getSymbol(PackageTree tree) { return ((JCPackageDecl) tree).packge; }