/** * Gets a created package. * * @param qualifiedName the package to search * @return a found package or null */ public CtPackage get(String qualifiedName) { if (qualifiedName.contains(CtType.INNERTTYPE_SEPARATOR)) { throw new RuntimeException("Invalid package name " + qualifiedName); } StringTokenizer token = new StringTokenizer(qualifiedName, CtPackage.PACKAGE_SEPARATOR); CtPackage current = rootPackage; if (token.hasMoreElements()) { current = current.getPackage(token.nextToken()); while (token.hasMoreElements() && current != null) { current = current.getPackage(token.nextToken()); } } return current; }
/** * Gets or creates a package. * * @param qualifiedName the full name of the package */ public CtPackage getOrCreate(String qualifiedName) { StringTokenizer token = new StringTokenizer(qualifiedName, CtPackage.PACKAGE_SEPARATOR); CtPackage last = rootPackage; while (token.hasMoreElements()) { String name = token.nextToken(); CtPackage next = last.getPackage(name); if (next == null) { next = factory.Core().createPackage(); next.setSimpleName(name); next.setParent(last); last.getPackages().add(next); } last = next; } return last; }