Index: src/org/netbeans/api/java/source/ElementUtilities.java =================================================================== RCS file: /cvs/java/source/src/org/netbeans/api/java/source/ElementUtilities.java,v retrieving revision 1.13 diff -u -r1.13 ElementUtilities.java --- src/org/netbeans/api/java/source/ElementUtilities.java 14 Jun 2007 11:48:36 -0000 1.13 +++ src/org/netbeans/api/java/source/ElementUtilities.java 14 Jun 2007 19:38:39 -0000 @@ -118,14 +118,6 @@ } /** - * - * The package element which indirectly encloses this element.. - */ - public PackageElement packageElement(Element element) { - return delegate.packageElement(element); - } - - /** * Returns the implementation of a method in class origin; null if none exists. */ public Element getImplementationOf(ExecutableElement method, TypeElement origin) { @@ -390,27 +382,6 @@ } /** - * Returns true if the specified element is referenced by a specified tree. - */ - public boolean referenced(Element e, Element parent) { - return delegate.referenced(e, parent); - } - - /** - * Returns true if the element is assigned by a specified tree. - */ - public boolean assigned(Element e, Element parent) { - return delegate.assigned(e, parent); - } - - /** - * Returns true if the element is a parameter for a specified method. - */ - public boolean parameter(Element e, Element parent) { - return delegate.parameter(e, parent); - } - - /** * Returns true if the element is declared (directly or indirectly) local * to a method or variable initializer. Also true for fields of inner * classes which are in turn local to a method or variable initializer. @@ -434,14 +405,6 @@ return delegate.isMemberOf(e, type); } - /** - * Returns the fully qualified name of this element, which is its - * simple name with its owner(s) prepended. - */ - public CharSequence getFullName(Element element) { - return delegate.getFullName(element); - } - /** * Returns the parent method which the specified method overrides, or null * if the method does not override a parent class method. Index: src/org/netbeans/api/java/source/SourceUtils.java =================================================================== RCS file: /cvs/java/source/src/org/netbeans/api/java/source/SourceUtils.java,v retrieving revision 1.34 diff -u -r1.34 SourceUtils.java --- src/org/netbeans/api/java/source/SourceUtils.java 14 Jun 2007 14:54:52 -0000 1.34 +++ src/org/netbeans/api/java/source/SourceUtils.java 14 Jun 2007 19:38:39 -0000 @@ -93,37 +93,6 @@ private SourceUtils() {} - /** - * @deprecated Use {@link com.sun.source.util.Trees#getTree(Element)} instead. - */ - public static Tree treeFor(CompilationInfo info, Element element) { - Context ctx = getSourceContextFor(info.getClasspathInfo(), Phase.ELEMENTS_RESOLVED, element); - if (ctx != null) { - Element e = getSourceElementFor(element, ctx); - if (e != null) - return JavacElements.instance(ctx).getTree((Symbol)e); - } - return null; - } - - /** - * @deprecated Use {@link com.sun.source.util.Trees#getPath(Element)} instead. - */ - public static TreePath pathFor(CompilationInfo info, Element element) { - Context ctx = getSourceContextFor(info.getClasspathInfo(), Phase.ELEMENTS_RESOLVED, element); - if (ctx != null) { - Element e = getSourceElementFor(element, ctx); - if (e != null) - return JavacTrees.instance(ctx).getPath(e); - } - return null; - } - - public static Element getImplementationOf(CompilationInfo info, ExecutableElement method, TypeElement origin) { - Context c = ((JavacTaskImpl) info.getJavacTask()).getContext(); - return ((MethodSymbol)method).implementation((TypeSymbol)origin, com.sun.tools.javac.code.Types.instance(c), true); - } - public static boolean checkTypesAssignable(CompilationInfo info, TypeMirror from, TypeMirror to) { Context c = ((JavacTaskImpl) info.getJavacTask()).getContext(); if (from.getKind() == TypeKind.DECLARED) { @@ -195,9 +164,6 @@ return (TypeElement)ec; } - private static EnumSet JAVA_JFO_KIND = EnumSet.of(Kind.CLASS, Kind.SOURCE); - - /**Resolve full qualified name in the given context. Adds import statement as necessary. * Returns name that resolved to a given FQN in given context (either simple name * or full qualified name). Handles import conflicts. @@ -308,7 +274,7 @@ * * */ - public static CompilationUnitTree addImports(CompilationUnitTree cut, List toImport, TreeMaker make) + private static CompilationUnitTree addImports(CompilationUnitTree cut, List toImport, TreeMaker make) throws IOException { // do not modify the list given by the caller (may be reused or immutable). toImport = new ArrayList(toImport); @@ -342,42 +308,12 @@ /** * Returns a {@link FileObject} in which the Element is defined. - * Element must be defined in source file - * @param element for which the {@link FileObject} should be located - * @return the defining {@link FileObject} or null if it cannot be - * found in any source file. - */ - public static FileObject getFile(Element element) { - if (element == null) { - throw new IllegalArgumentException ("Cannot pass null as an argument of the SourceUtils.getFile"); //NOI18N - } - Element prev = null; - while (element.getKind() != ElementKind.PACKAGE) { - prev = element; - element = element.getEnclosingElement(); - } - if (prev == null || (!prev.getKind().isClass() && !prev.getKind().isInterface())) - return null; - ClassSymbol clsSym = (ClassSymbol)prev; - URI uri; - if (clsSym.completer != null) - clsSym.complete(); - if (clsSym.sourcefile != null && (uri=clsSym.sourcefile.toUri())!= null && uri.isAbsolute()) { - try { - return URLMapper.findFileObject(uri.toURL()); - } catch (MalformedURLException ex) { - ex.printStackTrace(); - } - } - return null; - } - - /** - * Returns a {@link FileObject} in which the Element is defined. * @param element for which the {@link FileObject} should be located * @param cpInfo the classpaths context * @return the defining {@link FileObject} or null if it cannot be * found + * + * @deprecated use {@link getFile(ElementHandle, ClasspathInfo)} */ public static FileObject getFile (Element element, ClasspathInfo cpInfo) { try { @@ -714,6 +650,7 @@ * Waits for the end of the initial scan, this helper method * is designed for tests which require to wait for end of initial scan. * @throws InterruptedException is thrown when the waiting thread is interrupted. + * @deprecated use {@link JavaSource#runWhenScanFinished} */ public static void waitScanFinished () throws InterruptedException { RepositoryUpdater.getDefault().waitScanFinished(); @@ -969,72 +906,4 @@ // --------------- End of getFile () helper methods ------------------------------ - private static Context getSourceContextFor(ClasspathInfo cpInfo, final JavaSource.Phase phase, Element element) { - try { - FileObject fo = getFile(element, cpInfo); - if (fo != null) { - JavaSource js = JavaSource.forFileObject(fo); - if (js != null) { - final Context[] ret = new Context[1]; - js.runUserActionTask(new CancellableTask() { - public void cancel() { - } - public void run(CompilationController controller) throws Exception { - controller.toPhase(phase); - ret[0] = controller.getJavacTask().getContext(); - } - },true); - return ret[0]; - } - } - } catch (IOException ex) { - Exceptions.printStackTrace(ex); - } - return null; - } - - private static Element getSourceElementFor(Element element, Context ctx) { - Symbol sym = (Symbol)element; - Symtab symbolTable = Symtab.instance(ctx); - Name.Table nameTable = Name.Table.instance(ctx); - Symbol owner = sym.owner; - ClassSymbol enclCls = sym.enclClass(); - Name name = nameTable.fromString(enclCls.flatname.toString()); - ClassSymbol cls = symbolTable.classes.get(name); - if (enclCls == sym) - return cls; - if (cls != null && owner == enclCls) { - com.sun.tools.javac.code.Scope.Entry e = cls.members().lookup(nameTable.fromString(sym.name.toString())); - while (e.scope != null) { - if (e.sym.kind == sym.kind && (e.sym.flags_field & Flags.SYNTHETIC) == 0 && - e.sym.type.toString().equals(sym.type.toString())) - return e.sym; - e = e.next(); - } - } else if (cls != null && owner.kind == Kinds.MTH && sym.kind == Kinds.VAR) { - com.sun.tools.javac.code.Scope.Entry e = cls.members().lookup(nameTable.fromString(owner.name.toString())); - Symbol newOwner = null; - while (e.scope != null) { - if (e.sym.kind == owner.kind && (e.sym.flags_field & Flags.SYNTHETIC) == 0 && - e.sym.type.toString().equals(owner.type.toString())) { - newOwner = e.sym; - break; - } - e = e.next(); - } - if (newOwner != null && newOwner.kind == Kinds.MTH) { - int i = 0; - for (com.sun.tools.javac.util.List l = ((MethodSymbol)owner).params; l.nonEmpty(); l = l.tail) { - i++; - if (sym == l.head) - break; - } - for (com.sun.tools.javac.util.List l = ((MethodSymbol)newOwner).params; l.nonEmpty(); l = l.tail) { - if (--i == 0) - return l.head; - } - } - } - return null; - } }