org.openide.src
Class SourceElement

java.lang.Object
  extended byorg.openide.src.Element
      extended byorg.openide.src.SourceElement
All Implemented Interfaces:
ElementProperties, Node.Cookie, Serializable

public final class SourceElement
extends Element

Describes an entire Java source file. Note that there is no standard in-memory implementation of this element; every user of the class is expected to have a reasonable implementation according to where the source file resides.

The source element should be parsed in the background using prepare() before any attempts are made to access its properties to read or to write, or to call print(org.openide.src.ElementPrinter); otherwise such accesses will block until the parse is finished.

See Also:
Serialized Form

Nested Class Summary
static interface SourceElement.Impl
          Pluggable behaviour for source elements.
 
Nested classes inherited from class org.openide.src.Element
Element.Impl2
 
Field Summary
static int STATUS_ERROR
          Status when the source element contains unrecoverable errors.
static int STATUS_NOT
          Status when the source element is not yet prepared.
static int STATUS_OK
          Status when the source element has been parsed and is error-free.
static int STATUS_PARTIAL
          Status when the source element contains minor errors.
 
Fields inherited from class org.openide.src.Element
impl, impl2
 
Fields inherited from interface org.openide.src.ElementProperties
PROP_ALL_CLASSES, PROP_BODY, PROP_CLASS_OR_INTERFACE, PROP_CLASSES, PROP_CONSTRUCTORS, PROP_EXCEPTIONS, PROP_FIELDS, PROP_IMPORTS, PROP_INIT_VALUE, PROP_INITIALIZERS, PROP_INTERFACES, PROP_JAVADOC, PROP_MEMBERS, PROP_METHODS, PROP_MODIFIERS, PROP_NAME, PROP_PACKAGE, PROP_PARAMETERS, PROP_RETURN, PROP_STATIC, PROP_STATUS, PROP_SUPERCLASS, PROP_TYPE, PROP_VALID
 
Constructor Summary
SourceElement(SourceElement.Impl impl)
          Create a new source element.
 
Method Summary
 void addClass(ClassElement el)
          Add a new top-level class.
 void addClasses(ClassElement[] els)
          Add some new top-level classes.
 void addImport(Import el)
          Add an import.
 void addImports(Import[] els)
          Add some imports.
 ClassElement[] getAllClasses()
          Get all classes recursively, both top-level and inner.
 ClassElement getClass(Identifier name)
          Find a top-level class by name.
 ClassElement[] getClasses()
          Get the top-level classes.
 Import[] getImports()
          Get all imports.
 Identifier getPackage()
          Get the package of this source file.
 int getStatus()
          Get the parsing status of the element.
 Task prepare()
          Begin parsing this source element.
 void print(ElementPrinter printer)
          Print this element (and all its subelements) into an element printer.
 void removeClass(ClassElement el)
          Remove an top-level class.
 void removeClasses(ClassElement[] els)
          Remove some top-level classes.
 void removeImport(Import el)
          Remove an import.
 void removeImports(Import[] els)
          Remove some imports.
 void runAtomic(Runnable run)
          Lock the underlaing document to have exclusive access to it and could make changes on this SourceElement.
 void runAtomicAsUser(Runnable run)
          Executes given runnable in "user mode" does not allowing any modifications to parts of text marked as guarded.
 void setClasses(ClassElement[] els)
          Set the top-level classes.
 void setImports(Import[] imprt)
          Set all imports.
 void setPackage(Identifier id)
          Set the package of this source file.
 
Methods inherited from class org.openide.src.Element
addPropertyChangeListener, addVetoableChangeListener, getCookie, markCurrent, removePropertyChangeListener, removeVetoableChangeListener, toString, writeReplace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STATUS_NOT

public static final int STATUS_NOT
Status when the source element is not yet prepared.

See Also:
Constant Field Values

STATUS_ERROR

public static final int STATUS_ERROR
Status when the source element contains unrecoverable errors.

See Also:
Constant Field Values

STATUS_PARTIAL

public static final int STATUS_PARTIAL
Status when the source element contains minor errors.

See Also:
Constant Field Values

STATUS_OK

public static final int STATUS_OK
Status when the source element has been parsed and is error-free.

See Also:
Constant Field Values
Constructor Detail

SourceElement

public SourceElement(SourceElement.Impl impl)
Create a new source element.

Parameters:
impl - the pluggable implementation
Method Detail

getStatus

public int getStatus()
Get the parsing status of the element. This is a non-blocking operation.

Returns:
one of STATUS_NOT, STATUS_ERROR, STATUS_PARTIAL, or STATUS_OK

prepare

public Task prepare()
Begin parsing this source element. This method is non-blocking; it only returns a task that can be used to control the ongoing parse. Initially the getStatus() should be STATUS_NOT, and change to one of the other three when parsing is complete, according to whether or not errors were encountered, and their severity.

Returns:
a task to control the preparation of the element

setPackage

public void setPackage(Identifier id)
                throws SourceException
Set the package of this source file.

Parameters:
id - the package name, or null to use the default package
Throws:
SourceException - if the operation cannot proceed

getPackage

public Identifier getPackage()
Get the package of this source file.

Returns:
the package name, or null if this source file is in the default package

getImports

public Import[] getImports()
Get all imports.

Returns:
the imports

setImports

public void setImports(Import[] imprt)
                throws SourceException
Set all imports. The old imports will be replaced.

Parameters:
imprt - the new imports
Throws:
SourceException - if the operation cannot proceed

addImport

public void addImport(Import el)
               throws SourceException
Add an import.

Parameters:
el - the import to add
Throws:
SourceException - if the operation cannot proceed

addImports

public void addImports(Import[] els)
                throws SourceException
Add some imports.

Parameters:
els - the imports to add
Throws:
SourceException - if the operation cannot proceed

removeImport

public void removeImport(Import el)
                  throws SourceException
Remove an import.

Parameters:
el - the import to remove
Throws:
SourceException - if the operation cannot proceed

removeImports

public void removeImports(Import[] els)
                   throws SourceException
Remove some imports.

Parameters:
els - the imports to remove
Throws:
SourceException - if the operation cannot proceed

addClass

public void addClass(ClassElement el)
              throws SourceException
Add a new top-level class.

Parameters:
el - the top-level class to add
Throws:
SourceException - if impossible

addClasses

public void addClasses(ClassElement[] els)
                throws SourceException
Add some new top-level classes.

Parameters:
els - the top-level classes to add
Throws:
SourceException - if impossible

removeClass

public void removeClass(ClassElement el)
                 throws SourceException
Remove an top-level class.

Parameters:
el - the top-level class to remove
Throws:
SourceException - if impossible

removeClasses

public void removeClasses(ClassElement[] els)
                   throws SourceException
Remove some top-level classes.

Parameters:
els - the top-level classes to remove
Throws:
SourceException - if impossible

setClasses

public void setClasses(ClassElement[] els)
                throws SourceException
Set the top-level classes. The old ones will be replaced.

Parameters:
els - the new top-level classes
Throws:
SourceException - if impossible

getClasses

public ClassElement[] getClasses()
Get the top-level classes.

Returns:
all top-level classes

getClass

public ClassElement getClass(Identifier name)
Find a top-level class by name.

Parameters:
name - the name to look for
Returns:
the class, or null if it does not exist

getAllClasses

public ClassElement[] getAllClasses()
Get all classes recursively, both top-level and inner.

Returns:
all classes

print

public void print(ElementPrinter printer)
           throws ElementPrinterInterruptException
Description copied from class: Element
Print this element (and all its subelements) into an element printer.

Specified by:
print in class Element
Parameters:
printer - the element printer
Throws:
ElementPrinterInterruptException - if the printer canceled the printing

runAtomic

public void runAtomic(Runnable run)
Lock the underlaing document to have exclusive access to it and could make changes on this SourceElement.

Parameters:
run - the action to run

runAtomicAsUser

public void runAtomicAsUser(Runnable run)
                     throws SourceException
Executes given runnable in "user mode" does not allowing any modifications to parts of text marked as guarded. The actions should be run as "atomic" so either happen all at once or none at all (if a guarded block should be modified).

Parameters:
run - the action to run
Throws:
SourceException - if a modification of guarded text occured and that is why no changes to the document has been done.

 

Built on May 3 2007.  |  Portions Copyright 1997-2005 Sun Microsystems, Inc. All rights reserved.