org.netbeans.modules.java.source 0.80.1 17

org.netbeans.api.java.source
Class SourceUtils

java.lang.Object
  extended by org.netbeans.api.java.source.SourceUtils

public class SourceUtils
extends Object


Method Summary
static boolean checkTypesAssignable(CompilationInfo info, TypeMirror from, TypeMirror to)
           
static List<? extends Completion> getAttributeValueCompletions(CompilationInfo info, Element element, AnnotationMirror annotation, ExecutableElement member, String userText)
          Returns a list of completions for an annotation attribute value suggested by annotation processors.
static TypeMirror getBound(WildcardType wildcardType)
           
static Set<URL> getDependentRoots(URL root)
          Returns the dependent source path roots for given source root.
static TypeElement getEnclosingTypeElement(Element element)
          Deprecated. use ElementUtilities.enclosingTypeElement(javax.lang.model.element.Element)
static FileObject getFile(Element element, ClasspathInfo cpInfo)
          Deprecated. use getFile(ElementHandle, ClasspathInfo)
static FileObject getFile(ElementHandle<? extends Element> handle, ClasspathInfo cpInfo)
          Returns a FileObject of the source file in which the handle is declared.
static URL getJavadoc(Element element, ClasspathInfo cpInfo)
          Finds URL of a javadoc page for given element when available.
static TokenSequence<org.netbeans.api.java.lexer.JavaTokenId> getJavaTokenSequence(TokenHierarchy hierarchy, int offset)
           
static Collection<ElementHandle<TypeElement>> getMainClasses(FileObject fo)
          Returns classes declared in the given source file which have the main method.
static Collection<ElementHandle<TypeElement>> getMainClasses(FileObject[] sourceRoots)
          Returns classes declared under the given source roots which have the main method.
static TypeElement getOutermostEnclosingTypeElement(Element element)
           
static boolean isMainClass(String qualifiedName, ClasspathInfo cpInfo)
          Returns true when the class contains main method.
static boolean isMainClass(String qualifiedName, ClasspathInfo cpInfo, boolean optimistic)
          Returns true when the class contains main method.
static boolean isMainMethod(ExecutableElement method)
          Returns true if the method is a main method
static boolean isScanInProgress()
          Tests whether the initial scan is in progress.
static WildcardType resolveCapturedType(TypeMirror type)
           
static String resolveImport(CompilationInfo info, TreePath context, String fqn)
          Resolve full qualified name in the given context.
static void waitScanFinished()
          Deprecated. use JavaSource.runWhenScanFinished(org.netbeans.api.java.source.Task, boolean)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getJavaTokenSequence

public static TokenSequence<org.netbeans.api.java.lexer.JavaTokenId> getJavaTokenSequence(TokenHierarchy hierarchy,
                                                                                          int offset)
Since:
0.21

checkTypesAssignable

public static boolean checkTypesAssignable(CompilationInfo info,
                                           TypeMirror from,
                                           TypeMirror to)

getBound

public static TypeMirror getBound(WildcardType wildcardType)

getAttributeValueCompletions

public static List<? extends Completion> getAttributeValueCompletions(CompilationInfo info,
                                                                      Element element,
                                                                      AnnotationMirror annotation,
                                                                      ExecutableElement member,
                                                                      String userText)
Returns a list of completions for an annotation attribute value suggested by annotation processors.

Parameters:
info - the CompilationInfo used to resolve annotation processors
element - the element being annotated
annotation - the (perhaps partial) annotation being applied to the element
member - the annotation member to return possible completions for
userText - source code text to be completed
Returns:
suggested completions to the annotation member
Since:
0.57

getEnclosingTypeElement

@Deprecated
public static TypeElement getEnclosingTypeElement(Element element)
                                           throws IllegalArgumentException
Deprecated. use ElementUtilities.enclosingTypeElement(javax.lang.model.element.Element)

Returns the type element within which this member or constructor is declared. Does not accept packages If this is the declaration of a top-level type (a non-nested class or interface), returns null.

Returns:
the type declaration within which this member or constructor is declared, or null if there is none
Throws:
IllegalArgumentException - if the provided element is a package element

getOutermostEnclosingTypeElement

public static TypeElement getOutermostEnclosingTypeElement(Element element)

resolveImport

public static String resolveImport(CompilationInfo info,
                                   TreePath context,
                                   String fqn)
                            throws NullPointerException,
                                   IOException
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.
Note: if the info passed to this method is not an instance of WorkingCopy, missing import statement is added from a separate modification task executed asynchronously.
Note: after calling this method, it is not permitted to rewrite copy.getCompilationUnit().

Parameters:
info - CompilationInfo over which the method should work
context - in which the fully qualified should be resolved
fqn - the fully qualified name to resolve
Returns:
either a simple name or a FQN that will resolve to given fqn in given context
Throws:
NullPointerException
IOException

getFile

public static FileObject getFile(Element element,
                                 ClasspathInfo cpInfo)
Deprecated. use getFile(ElementHandle, ClasspathInfo)

Returns a FileObject in which the Element is defined.

Parameters:
element - for which the FileObject should be located
cpInfo - the classpaths context
Returns:
the defining FileObject or null if it cannot be found

getFile

public static FileObject getFile(ElementHandle<? extends Element> handle,
                                 ClasspathInfo cpInfo)
Returns a FileObject of the source file in which the handle is declared.

Parameters:
handle - to find the FileObject for
cpInfo - classpaths for resolving handle
Returns:
FileObject or null when the source file cannot be found

getJavadoc

public static URL getJavadoc(Element element,
                             ClasspathInfo cpInfo)
Finds URL of a javadoc page for given element when available. This method uses JavadocForBinaryQuery to find the javadoc page for the give element. For PackageElement it returns the package-summary.html for given package.

Parameters:
element - to find the Javadoc for
cpInfo - classpaths used to resolve (currently unused)
Returns:
the URL of the javadoc page or null when the javadoc is not available.

isScanInProgress

public static boolean isScanInProgress()
Tests whether the initial scan is in progress.


waitScanFinished

public static void waitScanFinished()
                             throws InterruptedException
Deprecated. use JavaSource.runWhenScanFinished(org.netbeans.api.java.source.Task, boolean)

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.

getDependentRoots

public static Set<URL> getDependentRoots(URL root)
Returns the dependent source path roots for given source root. It returns all the open project source roots which have either direct or transitive dependency on the given source root.

Parameters:
root - to find the dependent roots for
Returns:
Set of URLs containing at least the incoming root, never returns null.
Since:
0.10

getMainClasses

public static Collection<ElementHandle<TypeElement>> getMainClasses(FileObject fo)
Returns classes declared in the given source file which have the main method.

Parameters:
fo - source file
Returns:
the classes containing main method
Throws:
IllegalArgumentException - when file does not exist or is not a java source file.

isMainClass

public static boolean isMainClass(String qualifiedName,
                                  ClasspathInfo cpInfo)
Returns true when the class contains main method.

Parameters:
qualifiedName - the fully qualified name of class
cpInfo - the classpath used to resolve the class
Returns:
true when the class contains a main method

isMainClass

public static boolean isMainClass(String qualifiedName,
                                  ClasspathInfo cpInfo,
                                  boolean optimistic)
Returns true when the class contains main method.

Parameters:
qualifiedName - the fully qualified name of class
cpInfo - the classpath used to resolve the class
optimistic - when true does only index check without parsing the file. The optimistic check is faster but it works only for source file not for binaries for which index does not exist. It also does not handle inheritance of the main method.
Returns:
true when the class contains a main method
Since:
0.71

isMainMethod

public static boolean isMainMethod(ExecutableElement method)
Returns true if the method is a main method

Parameters:
method - to be checked
Returns:
true when the method is a main method

getMainClasses

public static Collection<ElementHandle<TypeElement>> getMainClasses(FileObject[] sourceRoots)
Returns classes declared under the given source roots which have the main method.

Parameters:
sourceRoots - the source roots
Returns:
the classes containing the main methods Currently this method is not optimized and may be slow

resolveCapturedType

public static WildcardType resolveCapturedType(TypeMirror type)
Since:
0.24

org.netbeans.modules.java.source 0.80.1 17

Built on December 5 2011.  |  Portions Copyright 1997-2011 Sun Microsystems, Inc. All rights reserved.