mirror of
https://github.com/SuspiciousActivity/ByteEdit.git
synced 2026-08-13 17:56:17 +00:00
Added code folding and formatted all files
This commit is contained in:
1 parent
11570d6b95
commit
66cd1dbd3e
233 files changed
+82245
-118134
No files matched your search
@@ -1,9 +1,7 @@
|
||||
/*
|
||||
* 08/26/2004
|
||||
*
|
||||
* TokenMakerBase.java - A base class for token makers.
|
||||
*
|
||||
* This library is distributed under a modified BSD license. See the included
|
||||
* This library is distributed under a modified BSD license. See the included
|
||||
* RSyntaxTextArea.License.txt file for details.
|
||||
*/
|
||||
package org.fife.ui.rsyntaxtextarea;
|
||||
@@ -11,7 +9,6 @@ package org.fife.ui.rsyntaxtextarea;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.text.Segment;
|
||||
|
||||
|
||||
/**
|
||||
* Base class for token makers.
|
||||
*
|
||||
@@ -19,44 +16,38 @@ import javax.swing.text.Segment;
|
||||
* @version 1.0
|
||||
*/
|
||||
public abstract class TokenMakerBase implements TokenMaker {
|
||||
|
||||
|
||||
/**
|
||||
* The first token in the returned linked list.
|
||||
*/
|
||||
protected TokenImpl firstToken;
|
||||
|
||||
/**
|
||||
* Used in the creation of the linked list.
|
||||
*/
|
||||
protected TokenImpl currentToken;
|
||||
|
||||
/**
|
||||
* Used in the creation of the linked list.
|
||||
*/
|
||||
protected TokenImpl previousToken;
|
||||
|
||||
/**
|
||||
* The factory that gives us our tokens to use.
|
||||
*/
|
||||
private TokenFactory tokenFactory;
|
||||
|
||||
/**
|
||||
* Highlights occurrences of the current token in the editor, if it is
|
||||
* relevant.
|
||||
*/
|
||||
private OccurrenceMarker occurrenceMarker;
|
||||
|
||||
/**
|
||||
* "0" implies this is the "main" language being highlighted. Positive
|
||||
* "0" implies this is the "main" language being highlighted. Positive
|
||||
* values imply various "secondary" or "embedded" languages, such as CSS
|
||||
* or JavaScript in HTML. While this value is non-zero, tokens will be
|
||||
* or JavaScript in HTML. While this value is non-zero, tokens will be
|
||||
* generated with this language index so they can (possibly) be painted
|
||||
* differently, so "embedded" languages can be rendered with a special
|
||||
* background.
|
||||
*/
|
||||
private int languageIndex;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
@@ -64,18 +55,16 @@ public abstract class TokenMakerBase implements TokenMaker {
|
||||
firstToken = currentToken = previousToken = null;
|
||||
tokenFactory = new DefaultTokenFactory();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void addNullToken() {
|
||||
if (firstToken==null) {
|
||||
if (firstToken == null) {
|
||||
firstToken = tokenFactory.createToken();
|
||||
currentToken = firstToken;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
TokenImpl next = tokenFactory.createToken();
|
||||
currentToken.setNextToken(next);
|
||||
previousToken = currentToken;
|
||||
@@ -83,69 +72,67 @@ public abstract class TokenMakerBase implements TokenMaker {
|
||||
}
|
||||
currentToken.setLanguageIndex(languageIndex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds the token specified to the current linked list of tokens.
|
||||
*
|
||||
* @param segment <code>Segment</code> to get text from.
|
||||
* @param start Start offset in <code>segment</code> of token.
|
||||
* @param end End offset in <code>segment</code> of token.
|
||||
* @param tokenType The token's type.
|
||||
* @param startOffset The offset in the document at which this token
|
||||
* occurs.
|
||||
* @param segment
|
||||
* <code>Segment</code> to get text from.
|
||||
* @param start
|
||||
* Start offset in <code>segment</code> of token.
|
||||
* @param end
|
||||
* End offset in <code>segment</code> of token.
|
||||
* @param tokenType
|
||||
* The token's type.
|
||||
* @param startOffset
|
||||
* The offset in the document at which this token
|
||||
* occurs.
|
||||
*/
|
||||
public void addToken(Segment segment, int start, int end, int tokenType,
|
||||
int startOffset) {
|
||||
addToken(segment.array, start,end, tokenType, startOffset);
|
||||
public void addToken(Segment segment, int start, int end, int tokenType, int startOffset) {
|
||||
addToken(segment.array, start, end, tokenType, startOffset);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void addToken(char[] array, int start, int end, int tokenType,
|
||||
int startOffset) {
|
||||
public void addToken(char[] array, int start, int end, int tokenType, int startOffset) {
|
||||
addToken(array, start, end, tokenType, startOffset, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds the token specified to the current linked list of tokens.
|
||||
*
|
||||
* @param array The character array.
|
||||
* @param start The starting offset in the array.
|
||||
* @param end The ending offset in the array.
|
||||
* @param tokenType The token's type.
|
||||
* @param startOffset The offset in the document at which this token
|
||||
* occurs.
|
||||
* @param hyperlink Whether this token is a hyperlink.
|
||||
* @param array
|
||||
* The character array.
|
||||
* @param start
|
||||
* The starting offset in the array.
|
||||
* @param end
|
||||
* The ending offset in the array.
|
||||
* @param tokenType
|
||||
* The token's type.
|
||||
* @param startOffset
|
||||
* The offset in the document at which this token
|
||||
* occurs.
|
||||
* @param hyperlink
|
||||
* Whether this token is a hyperlink.
|
||||
*/
|
||||
public void addToken(char[] array, int start, int end, int tokenType,
|
||||
int startOffset, boolean hyperlink) {
|
||||
|
||||
if (firstToken==null) {
|
||||
firstToken = tokenFactory.createToken(array, start, end,
|
||||
startOffset, tokenType);
|
||||
public void addToken(char[] array, int start, int end, int tokenType, int startOffset, boolean hyperlink) {
|
||||
if (firstToken == null) {
|
||||
firstToken = tokenFactory.createToken(array, start, end, startOffset, tokenType);
|
||||
currentToken = firstToken; // previous token is still null.
|
||||
}
|
||||
else {
|
||||
TokenImpl next = tokenFactory.createToken(array, start,end,
|
||||
startOffset, tokenType);
|
||||
} else {
|
||||
TokenImpl next = tokenFactory.createToken(array, start, end, startOffset, tokenType);
|
||||
currentToken.setNextToken(next);
|
||||
previousToken = currentToken;
|
||||
currentToken = next;
|
||||
}
|
||||
|
||||
currentToken.setLanguageIndex(languageIndex);
|
||||
currentToken.setHyperlink(hyperlink);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the occurrence marker to use for this token maker. Subclasses
|
||||
* Returns the occurrence marker to use for this token maker. Subclasses
|
||||
* can override to use different implementations.
|
||||
*
|
||||
* @return The occurrence marker to use.
|
||||
@@ -153,25 +140,25 @@ public abstract class TokenMakerBase implements TokenMaker {
|
||||
protected OccurrenceMarker createOccurrenceMarker() {
|
||||
return new DefaultOccurrenceMarker();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the closest {@link TokenTypes "standard" token type} for a given
|
||||
* "internal" token type (e.g. one whose value is <code>< 0</code>).<p>
|
||||
* "internal" token type (e.g. one whose value is <code>< 0</code>).
|
||||
* <p>
|
||||
*
|
||||
* The default implementation returns <code>type</code> always, which
|
||||
* denotes that a mapping from internal token types to standard token types
|
||||
* is not defined; subclasses can override.
|
||||
*
|
||||
* @param type The token type.
|
||||
* @param type
|
||||
* The token type.
|
||||
* @return The closest "standard" token type.
|
||||
*/
|
||||
@Override
|
||||
public int getClosestStandardTokenTypeForInternalType(int type) {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether this programming language uses curly braces
|
||||
* ('<code>{</code>' and '<code>}</code>') to denote code blocks.
|
||||
@@ -179,21 +166,22 @@ public abstract class TokenMakerBase implements TokenMaker {
|
||||
* The default implementation returns <code>false</code>; subclasses can
|
||||
* override this method if necessary.
|
||||
*
|
||||
* @param languageIndex The language index at the offset in question.
|
||||
* Since some <code>TokenMaker</code>s effectively have nested
|
||||
* languages (such as JavaScript in HTML), this parameter tells the
|
||||
* <code>TokenMaker</code> what sub-language to look at.
|
||||
* @param languageIndex
|
||||
* The language index at the offset in question.
|
||||
* Since some <code>TokenMaker</code>s effectively have nested
|
||||
* languages (such as JavaScript in HTML), this parameter tells
|
||||
* the
|
||||
* <code>TokenMaker</code> what sub-language to look at.
|
||||
* @return Whether curly braces denote code blocks.
|
||||
*/
|
||||
@Override
|
||||
public boolean getCurlyBracesDenoteCodeBlocks(int languageIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns an action to handle "insert break" key presses (i.e. Enter).
|
||||
* The default implementation returns <code>null</code>. Subclasses
|
||||
* The default implementation returns <code>null</code>. Subclasses
|
||||
* can override.
|
||||
*
|
||||
* @return The default implementation always returns <code>null</code>.
|
||||
@@ -202,8 +190,7 @@ public abstract class TokenMakerBase implements TokenMaker {
|
||||
public Action getInsertBreakAction() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the current language index.
|
||||
*
|
||||
@@ -213,26 +200,20 @@ public abstract class TokenMakerBase implements TokenMaker {
|
||||
protected int getLanguageIndex() {
|
||||
return languageIndex;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getLastTokenTypeOnLine(Segment text, int initialTokenType) {
|
||||
|
||||
// Last parameter doesn't matter if we're not painting.
|
||||
Token t = getTokenList(text, initialTokenType, 0);
|
||||
|
||||
while (t.getNextToken()!=null) {
|
||||
while (t.getNextToken() != null) {
|
||||
t = t.getNextToken();
|
||||
}
|
||||
|
||||
return t.getType();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -240,61 +221,58 @@ public abstract class TokenMakerBase implements TokenMaker {
|
||||
public String[] getLineCommentStartAndEnd(int languageIndex) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether tokens of the specified type should have "mark
|
||||
* occurrences" enabled for the current programming language. The default
|
||||
* occurrences" enabled for the current programming language. The default
|
||||
* implementation returns true if <tt>type</tt> is {@link Token#IDENTIFIER}.
|
||||
* Subclasses can override this method to support other token types, such
|
||||
* as {@link Token#VARIABLE}.
|
||||
*
|
||||
* @param type The token type.
|
||||
* @param type
|
||||
* The token type.
|
||||
* @return Whether tokens of this type should have "mark occurrences"
|
||||
* enabled.
|
||||
*/
|
||||
@Override
|
||||
public boolean getMarkOccurrencesOfTokenType(int type) {
|
||||
return type==Token.IDENTIFIER;
|
||||
return type == Token.IDENTIFIER;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public OccurrenceMarker getOccurrenceMarker() {
|
||||
if (occurrenceMarker==null) {
|
||||
if (occurrenceMarker == null) {
|
||||
occurrenceMarker = createOccurrenceMarker();
|
||||
}
|
||||
return occurrenceMarker;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The default implementation returns <code>false</code> always. Languages
|
||||
* The default implementation returns <code>false</code> always. Languages
|
||||
* that wish to better support auto-indentation can override this method.
|
||||
*
|
||||
* @param token The token the previous line ends with.
|
||||
* @param token
|
||||
* The token the previous line ends with.
|
||||
* @return Whether the next line should be indented.
|
||||
*/
|
||||
@Override
|
||||
public boolean getShouldIndentNextLineAfter(Token token) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether a character could be part of an "identifier" token
|
||||
* in a specific language. The default implementation returns
|
||||
* in a specific language. The default implementation returns
|
||||
* <code>true</code> for letters, numbers, and certain symbols.
|
||||
*/
|
||||
@Override
|
||||
public boolean isIdentifierChar(int languageIndex, char ch) {
|
||||
return Character.isLetterOrDigit(ch) || ch=='_' || ch=='$';
|
||||
return Character.isLetterOrDigit(ch) || ch == '_' || ch == '$';
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The default implementation returns <code>false</code> always.
|
||||
* Subclasses that are highlighting a markup language should override this
|
||||
@@ -306,10 +284,9 @@ public abstract class TokenMakerBase implements TokenMaker {
|
||||
public boolean isMarkupLanguage() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Deletes the linked list of tokens so we can begin anew. This should
|
||||
* Deletes the linked list of tokens so we can begin anew. This should
|
||||
* never have to be called by the programmer, as it is automatically
|
||||
* called whenever the user calls
|
||||
* {@link #getLastTokenTypeOnLine(Segment, int)} or
|
||||
@@ -319,22 +296,20 @@ public abstract class TokenMakerBase implements TokenMaker {
|
||||
firstToken = currentToken = previousToken = null;
|
||||
tokenFactory.resetAllTokens();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets the language index to assign to tokens moving forward. This
|
||||
* Sets the language index to assign to tokens moving forward. This
|
||||
* property is used to designate tokens as being in "secondary" languages
|
||||
* (such as CSS or JavaScript in HTML).
|
||||
*
|
||||
* @param languageIndex The new language index. A value of
|
||||
* <code>0</code> denotes the "main" language, any positive value
|
||||
* denotes a specific secondary language. Negative values will
|
||||
* be treated as <code>0</code>.
|
||||
* @param languageIndex
|
||||
* The new language index. A value of
|
||||
* <code>0</code> denotes the "main" language, any positive value
|
||||
* denotes a specific secondary language. Negative values will
|
||||
* be treated as <code>0</code>.
|
||||
* @see #getLanguageIndex()
|
||||
*/
|
||||
protected void setLanguageIndex(int languageIndex) {
|
||||
this.languageIndex = Math.max(0, languageIndex);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user