Package de.jplag
Class Token
java.lang.Object
de.jplag.Token
This class represents a token in a source code. It can represent keywords, identifiers, syntactical structures etc.
What types of tokens there are depends on the specific language, meaning JPlag does not enforce a specific token set.
The language parsers decide what is a token and what is not.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intIndicates that the requested field has no value. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a token with column and length information.Token(TokenType type, File file, int line, int column, int length, CodeSemantics semantics) Creates a token with column, length and semantic information.Token(TokenType type, File file, TokenTrace trace) Creates a token with column and length information. -
Method Summary
Modifier and TypeMethodDescriptionstatic TokenCreates a token of typeFILE_ENDwithout information about line, column, and length.intReturns the character index which denotes where the code sections represented by this token starts in the line.getFile()intGives the length if the code sections represented by this token.intgetLine()Gives the line index denoting in which line the code sections represented by this token starts.getType()static TokensemanticFileEnd(File file) Creates a token of typeFILE_ENDwithout information about line, column, and length, but with semantic information.toString()
-
Field Details
-
NO_VALUE
public static final int NO_VALUEIndicates that the requested field has no value.- See Also:
-
-
Constructor Details
-
Token
Creates a token with column and length information.- Parameters:
type- is the token type.file- is the name of the source code file.line- is the line index in the source code where the token resides. Index is 1-based.column- is the column index, meaning where the token starts in the line. Index is 1-based.length- is the length of the token in the source code.
-
Token
Creates a token with column and length information.- Parameters:
type- is the token type.file- is the name of the source code file.trace- is the tracing information of the token, meaning line, column, and length.
-
Token
Creates a token with column, length and semantic information.- Parameters:
type- is the token type.file- is the name of the source code file.line- is the line index in the source code where the token resides. Index is 1-based.column- is the column index, meaning where the token starts in the line. Index is 1-based.length- is the length of the token in the source code.semantics- is a record containing semantic information about the token.
-
-
Method Details
-
fileEnd
Creates a token of typeFILE_ENDwithout information about line, column, and length.- Parameters:
file- is the name of the source code file.
-
semanticFileEnd
Creates a token of typeFILE_ENDwithout information about line, column, and length, but with semantic information.- Parameters:
file- is the name of the source code file.
-
getColumn
public int getColumn()Returns the character index which denotes where the code sections represented by this token starts in the line.- Returns:
- the character index in the line.
-
getFile
- Returns:
- the name of the file where the source code that the token represents is located in.
-
getLength
public int getLength()Gives the length if the code sections represented by this token.- Returns:
- the length in characters.
-
getLine
public int getLine()Gives the line index denoting in which line the code sections represented by this token starts.- Returns:
- the line index.
-
getType
- Returns:
- the type of the token.
-
toString
-
getSemantics
- Returns:
- the semantics of the token.
-