org.wurbelizer
Class SourceElement

java.lang.Object
  extended by org.wurbelizer.SourceElement

public class SourceElement
extends Object

A SourceElement represents a section within a SourceDocument.

Source elements belong to one of five categories (types):

Comment blocks or guarded blocks may contain other SourceSubElements. There are two kinds of sub elements: single-line and multi-line. Single line sub elements end at the end of the line where they started. A wurblet anchor is a single line sub element. Single line sub elements may be enlarged beyond the end of the line by a continuation line (double backslash at the end of line). Multi-line sub elements like here- or property-documents are terminated a special control sequence. Furthermore, all leading comment text starting each line will be cut off and will not become part of the contents of the sub element (works like a rectangular cut).


Nested Class Summary
static class SourceElement.Type
          type of source element
 
Constructor Summary
SourceElement(SourceDocument doc, SourceElement.Type type, int begin, int end)
          Creates a source element.
 
Method Summary
 boolean containsHereDocuments()
          Checks whether this element contains here-documents.
 boolean containsPropertyDocuments()
          Checks whether this element contains property documents.
 boolean containsWurblets()
          Checks whether this element contains wurblets.
 void deleteText(int startNdx, int endNdx)
          Removes characters in text and updates doc and all other elements.
 int getBegin()
          Gets the start/begin offset of this element within its document.
 int getEnd()
          Gets the end offset of this element within its document.
 String getGuardedName()
          Gets the guarded name if this is a guarded block.
 List<SourceHereSubElement> getHereDocuments()
          Gets the list of here-documents.
 List<SourcePropertySubElement> getPropertyDocuments()
          Gets the list of property documents.
 SourceDocument getSourceDocument()
          Gets the SourceDocument this element belongs to.
 String getText()
          Gets the contents of this element
 SourceElement.Type getType()
          Gets the type of this source element.
 List<SourceWurbletSubElement> getWurblets()
          Gets the list of wurblets.
 boolean isCode()
          Checks whether this element is a code block.
 boolean isComment()
          Checks whether this element is a comment.
 boolean isGuarded()
          Checks whether this element is a guarded block.
 boolean isWhiteEmpty()
          Checks whether this element contains only whitespaces.
 void setBegin(int begin)
          Sets the start/begin offset of this element within its document.
 void setEnd(int end)
          Sets the end offset of this element within its document.
 void setGuardedName(String guardedName)
          Sets the guarded name if this is a guarded block.
 String toString()
          Prints the name and line info of the element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SourceElement

public SourceElement(SourceDocument doc,
                     SourceElement.Type type,
                     int begin,
                     int end)
              throws SourceException
Creates a source element.

Parameters:
doc - the source document the element belongs to
type - the element's type, one one TYPE_....
begin - the start of the element within the document
end - the end of the element
Throws:
SourceException - if creating the element failed
Method Detail

getText

public String getText()
Gets the contents of this element

Returns:
the text of this element

isCode

public boolean isCode()
Checks whether this element is a code block.

Returns:
true if element contains sourcecode

isGuarded

public boolean isGuarded()
Checks whether this element is a guarded block.

Returns:
true if this is a guarded block

isComment

public boolean isComment()
Checks whether this element is a comment.

Returns:
true if this is a comment

containsWurblets

public boolean containsWurblets()
Checks whether this element contains wurblets.

Returns:
true if element contains a wurblet anchors

getWurblets

public List<SourceWurbletSubElement> getWurblets()
Gets the list of wurblets.

Returns:
list of wurblets

containsHereDocuments

public boolean containsHereDocuments()
Checks whether this element contains here-documents.

Returns:
true if element contains here-documents

getHereDocuments

public List<SourceHereSubElement> getHereDocuments()
Gets the list of here-documents.

Returns:
the list of here-Documents

containsPropertyDocuments

public boolean containsPropertyDocuments()
Checks whether this element contains property documents.

Returns:
true if element contains property-documents

getPropertyDocuments

public List<SourcePropertySubElement> getPropertyDocuments()
Gets the list of property documents.

Returns:
the list of property-Documents

isWhiteEmpty

public boolean isWhiteEmpty()
Checks whether this element contains only whitespaces.

Returns:
true if element contains only whitespaces or newlines

getSourceDocument

public SourceDocument getSourceDocument()
Gets the SourceDocument this element belongs to.

Returns:
the source document

getType

public SourceElement.Type getType()
Gets the type of this source element.

Returns:
the type.

getBegin

public int getBegin()
Gets the start/begin offset of this element within its document.

Returns:
the begin offset

setBegin

public void setBegin(int begin)
Sets the start/begin offset of this element within its document.

Parameters:
begin - the start of this element

getEnd

public int getEnd()
Gets the end offset of this element within its document.

Returns:
the end of this element

setEnd

public void setEnd(int end)
Sets the end offset of this element within its document.

Parameters:
end - the end of this element

deleteText

public void deleteText(int startNdx,
                       int endNdx)
Removes characters in text and updates doc and all other elements.

Parameters:
startNdx - the offset to start (relative to the element)
endNdx - the offset to end (relative to the element)

getGuardedName

public String getGuardedName()
Gets the guarded name if this is a guarded block.

Returns:
the guardedname of this comment block

setGuardedName

public void setGuardedName(String guardedName)
Sets the guarded name if this is a guarded block.

Parameters:
guardedName - the guardedname of this comment block

toString

public String toString()
Prints the name and line info of the element.

Overrides:
toString in class Object
Returns:
the string for diagnostics


Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de