org.netbeans.modules.parsing.api/1 1.26.0 2

org.netbeans.modules.parsing.api
Class Snapshot

java.lang.Object
  extended by org.netbeans.modules.parsing.api.Snapshot

public final class Snapshot
extends Object

Snapshot represents some part of text. Snapshot can be created from Source representing file or document, or from some other Snapshot. So Snapshot can represent some block of code written in different language embedded inside some top level language too. It can contain some generated parts of code that is not contained in the original file. Snapshot is immutable. It means that Snapshot created from document opened in editor contains some copy of original text. You do not need to call Snapshot methods under any locks, but on other hand Snapshot may not be up to date.


Method Summary
 Embedding create(CharSequence charSequence, String mimeType)
          Creates a new embedding for given charSequence.
 Embedding create(int offset, int length, String mimeType)
          Creates a new embedding form part of this snapshot defined by offset and length.
 int getEmbeddedOffset(int originalOffset)
          Gets an offset in this snapshot corresponding to an offset in the original source.
 MimePath getMimePath()
          Returns this snapshot's mime path.
 String getMimeType()
          Returns this snapshot's mime type.
 int getOriginalOffset(int snapshotOffset)
          Gets an offset in the original source corresponding to an offset in this snapshot.
 Source getSource()
          Returns source this snapshot has originally been created from.
 CharSequence getText()
          Returns content of this snapshot.
 TokenHierarchy<?> getTokenHierarchy()
          Get the TokenHierarchy lexed from this snapshot.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

create

public Embedding create(int offset,
                        int length,
                        String mimeType)
Creates a new embedding form part of this snapshot defined by offset and length.

Parameters:
offset - A start offset of the new embedding. Start offset is relative to the current snapshot.
length - A length of the new embedding.
mimeType - Mime type of the new embedding.
Returns:
The new embedding.
Throws:
IndexOutOfBoundsException - when bounds of the new embedding exceeds original snapshot.

create

public Embedding create(CharSequence charSequence,
                        String mimeType)
Creates a new embedding for given charSequence.

Parameters:
charSequence - A text of new embedding.
mimeType - Mime type of the new embedding.
Returns:
The new embedding.

getText

public CharSequence getText()
Returns content of this snapshot.

Returns:
text of this snapshot

getMimeType

public String getMimeType()
Returns this snapshot's mime type.

Returns:
this snapshot mime type.

getMimePath

public MimePath getMimePath()
Returns this snapshot's mime path.

Returns:
this snapshot mime type.

getTokenHierarchy

public TokenHierarchy<?> getTokenHierarchy()
Get the TokenHierarchy lexed from this snapshot.

Returns:
TokenHierarchy created by a Lexer registered for this Snapshot's mime type or null if there is no such Lexer.
Since:
1.1

getOriginalOffset

public int getOriginalOffset(int snapshotOffset)
Gets an offset in the original source corresponding to an offset in this snapshot. The method will return -1 if snapshotOffset can't be translated back to the original source. For example on the snapshotOffset is in a "virtual" area of text. That is in a text generated by some EmbeddingProvider, which has no representation in the top level source code.

Parameters:
snapshotOffset - The offset in this snapshot.
Returns:
The offset in the original source or -1.

getEmbeddedOffset

public int getEmbeddedOffset(int originalOffset)
Gets an offset in this snapshot corresponding to an offset in the original source. The method can return -1 if originalOffset points to an area in the original source, which is not part of this snapshot.

Parameters:
originalOffset - The offset in the original source.
Returns:
The offset in this snapshot or -1.

getSource

public Source getSource()
Returns source this snapshot has originally been created from.

Returns:
a source this snapshot has originally been created from.

toString

public String toString()
Overrides:
toString in class Object

org.netbeans.modules.parsing.api/1 1.26.0 2

Built on November 22 2009.  |  Portions Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.