Fixes and updates

This commit is contained in:
Nico committed 2021-03-07 15:22:55 +01:00
1 parent d1710ea6a5
commit fb4da77359
211 files changed
+45363 -45571

No files matched your search

@@ -30,18 +30,18 @@ import org.fife.ui.rtextarea.RTextArea;
* @version 1.0
*/
public abstract class AbstractJFlexCTokenMaker extends AbstractJFlexTokenMaker {
private final Action INSERT_BREAK_ACTION;
private static final Pattern MLC_PATTERN = Pattern.compile("([ \\t]*)(/?[\\*]+)([ \\t]*)");
protected AbstractJFlexCTokenMaker() {
INSERT_BREAK_ACTION = createInsertBreakAction();
}
/**
* Creates and returns the action to use when the user inserts a newline.
* The default implementation intelligently closes multi-line comments.
* Subclasses can override.
* Creates and returns the action to use when the user inserts a newline. The
* default implementation intelligently closes multi-line comments. Subclasses
* can override.
*
* @return The action.
* @see #getInsertBreakAction()
@@ -49,10 +49,10 @@ public abstract class AbstractJFlexCTokenMaker extends AbstractJFlexTokenMaker {
protected Action createInsertBreakAction() {
return new CStyleInsertBreakAction();
}
/**
* Returns <code>true</code> always as C-style languages use curly braces
* to denote code blocks.
* Returns <code>true</code> always as C-style languages use curly braces to
* denote code blocks.
*
* @return <code>true</code> always.
*/
@@ -60,11 +60,10 @@ public abstract class AbstractJFlexCTokenMaker extends AbstractJFlexTokenMaker {
public boolean getCurlyBracesDenoteCodeBlocks(int languageIndex) {
return true;
}
/**
* Returns an action to handle "insert break" key presses (i.e. Enter).
* An action is returned that handles newlines differently in multi-line
* comments.
* Returns an action to handle "insert break" key presses (i.e. Enter). An
* action is returned that handles newlines differently in multi-line comments.
*
* @return The action.
*/
@@ -72,7 +71,7 @@ public abstract class AbstractJFlexCTokenMaker extends AbstractJFlexTokenMaker {
public Action getInsertBreakAction() {
return INSERT_BREAK_ACTION;
}
/**
* {@inheritDoc}
*/
@@ -80,7 +79,7 @@ public abstract class AbstractJFlexCTokenMaker extends AbstractJFlexTokenMaker {
public boolean getMarkOccurrencesOfTokenType(int type) {
return type == Token.IDENTIFIER || type == Token.FUNCTION;
}
/**
* {@inheritDoc}
*/
@@ -92,19 +91,17 @@ public abstract class AbstractJFlexCTokenMaker extends AbstractJFlexTokenMaker {
}
return false;
}
/**
* Returns whether a given token is an internal token type that represents
* an MLC or documentation comment continuing on to the next line. This is
* done by languages such as JavaScript that are a little more verbose
* than necessary so that their code can be copy-and-pasted into other
* <code>TokenMaker</code>s that use them as nested languages (such as
* HTML, JSP, etc.).
* Returns whether a given token is an internal token type that represents an
* MLC or documentation comment continuing on to the next line. This is done by
* languages such as JavaScript that are a little more verbose than necessary so
* that their code can be copy-and-pasted into other <code>TokenMaker</code>s
* that use them as nested languages (such as HTML, JSP, etc.).
*
* @param t
* The token to check. This cannot be <code>null</code>.
* @return Whether the token is an internal token representing the end of
* a line for an MLC/doc comment continuing on to the next line.
* @param t The token to check. This cannot be <code>null</code>.
* @return Whether the token is an internal token representing the end of a line
* for an MLC/doc comment continuing on to the next line.
*/
private boolean isInternalEolTokenForMLCs(Token t) {
int type = t.getType();
@@ -114,13 +111,13 @@ public abstract class AbstractJFlexCTokenMaker extends AbstractJFlexTokenMaker {
}
return false;
}
/**
* Action that knows how to special-case inserting a newline in a
* multi-line comment for languages like C and Java.
* Action that knows how to special-case inserting a newline in a multi-line
* comment for languages like C and Java.
*/
protected class CStyleInsertBreakAction extends RSyntaxTextAreaEditorKit.InsertBreakAction {
@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
if (!textArea.isEditable() || !textArea.isEnabled()) {
@@ -141,13 +138,12 @@ public abstract class AbstractJFlexCTokenMaker extends AbstractJFlexTokenMaker {
handleInsertBreak(rsta, true);
}
}
/**
* Returns whether the MLC token containing <code>offs</code> appears
* to have a "nested" comment (i.e., contains "<code>/*</code>"
* somewhere inside of it). This implies that it is likely a "new" MLC
* and needs to be closed. While not foolproof, this is usually good
* enough of a sign.
* Returns whether the MLC token containing <code>offs</code> appears to have a
* "nested" comment (i.e., contains "<code>/*</code>" somewhere inside of it).
* This implies that it is likely a "new" MLC and needs to be closed. While not
* foolproof, this is usually good enough of a sign.
*
* @param textArea
* @param line
@@ -183,7 +179,7 @@ public abstract class AbstractJFlexCTokenMaker extends AbstractJFlexTokenMaker {
}
return true; // No match - MLC goes to the end of the file
}
private void insertBreakInMLC(ActionEvent e, RSyntaxTextArea textArea, int line) {
Matcher m = null;
int start = -1;
@@ -11,35 +11,32 @@ import javax.swing.text.Segment;
/**
* Base class for JFlex-generated token makers. This class attempts to factor
* out all common code from these classes. Many methods <em>almost</em> could
* be factored out into this class, but cannot because they reference JFlex
* out all common code from these classes. Many methods <em>almost</em> could be
* factored out into this class, but cannot because they reference JFlex
* variables that we cannot access from this class.
*
* @author Robert Futrell
* @version 0.1
*/
public abstract class AbstractJFlexTokenMaker extends TokenMakerBase {
protected Segment s;
protected int start; // Just for states.
protected int offsetShift; // As parser always starts at 0, but our line
// doesn't.
/**
* Declared here so we can define overloads that refer to this method.
*
* @param newState
* The new JFlex state to enter.
* @param newState The new JFlex state to enter.
*/
public abstract void yybegin(int newState);
/**
* Starts a new JFlex state and changes the current language index.
*
* @param state
* The new JFlex state to enter.
* @param languageIndex
* The new language index.
* @param state The new JFlex state to enter.
* @param languageIndex The new language index.
*/
protected void yybegin(int state, int languageIndex) {
yybegin(state);
@@ -8,9 +8,9 @@ package org.fife.ui.rsyntaxtextarea;
/**
* An abstract implementation of the
* {@link org.fife.ui.rsyntaxtextarea.TokenMaker} interface. It should
* be overridden for every language for which you want to provide
* syntax highlighting.
* {@link org.fife.ui.rsyntaxtextarea.TokenMaker} interface. It should be
* overridden for every language for which you want to provide syntax
* highlighting.
* <p>
*
* @see Token
@@ -19,34 +19,33 @@ package org.fife.ui.rsyntaxtextarea;
* @version 0.2
*/
public abstract class AbstractTokenMaker extends TokenMakerBase {
/**
* Hash table of words to highlight and what token type they are.
* The keys are the words to highlight, and their values are the
* token types, for example, <code>Token.RESERVED_WORD</code> or
* <code>Token.FUNCTION</code>.
* Hash table of words to highlight and what token type they are. The keys are
* the words to highlight, and their values are the token types, for example,
* <code>Token.RESERVED_WORD</code> or <code>Token.FUNCTION</code>.
*/
protected TokenMap wordsToHighlight;
/**
* Constructor.
*/
public AbstractTokenMaker() {
wordsToHighlight = getWordsToHighlight();
}
/**
* Returns the words to highlight for this programming language.
*
* @return A <code>TokenMap</code> containing the words to highlight for
* this programming language.
* @return A <code>TokenMap</code> containing the words to highlight for this
* programming language.
*/
public abstract TokenMap getWordsToHighlight();
/**
* Removes the token last added from the linked list of tokens. The
* programmer should never have to call this directly; it can be called
* by subclasses of <code>TokenMaker</code> if necessary.
* Removes the token last added from the linked list of tokens. The programmer
* should never have to call this directly; it can be called by subclasses of
* <code>TokenMaker</code> if necessary.
*/
public void removeLastToken() {
if (previousToken == null) {
@@ -18,15 +18,14 @@ import java.util.Set;
* @version 1.0
*/
public abstract class AbstractTokenMakerFactory extends TokenMakerFactory {
/**
* A mapping from keys to the names of {@link TokenMaker} implementation
* class names. When {@link #getTokenMaker(String)} is called with a key
* defined in this map, a <code>TokenMaker</code> of the corresponding type
* is returned.
* A mapping from keys to the names of {@link TokenMaker} implementation class
* names. When {@link #getTokenMaker(String)} is called with a key defined in
* this map, a <code>TokenMaker</code> of the corresponding type is returned.
*/
private Map<String, Object> tokenMakerMap;
/**
* Constructor.
*/
@@ -34,14 +33,13 @@ public abstract class AbstractTokenMakerFactory extends TokenMakerFactory {
tokenMakerMap = new HashMap<String, Object>();
initTokenMakerMap();
}
/**
* Returns a {@link TokenMaker} for the specified key.
*
* @param key
* The key.
* @return The corresponding <code>TokenMaker</code>, or <code>null</code>
* if none matches the specified key.
* @param key The key.
* @return The corresponding <code>TokenMaker</code>, or <code>null</code> if
* none matches the specified key.
*/
@Override
protected TokenMaker getTokenMakerImpl(String key) {
@@ -57,18 +55,18 @@ public abstract class AbstractTokenMakerFactory extends TokenMakerFactory {
}
return null;
}
/**
* Populates the mapping from keys to instances of
* <code>TokenMakerCreator</code>s. Subclasses should override this method
* and call one of the <code>putMapping</code> overloads to register
* <code>TokenMakerCreator</code>s. Subclasses should override this method and
* call one of the <code>putMapping</code> overloads to register
* {@link TokenMaker}s for syntax constants.
*
* @see #putMapping(String, String)
* @see #putMapping(String, String, ClassLoader)
*/
protected abstract void initTokenMakerMap();
/**
* {@inheritDoc}
*/
@@ -76,50 +74,45 @@ public abstract class AbstractTokenMakerFactory extends TokenMakerFactory {
public Set<String> keySet() {
return tokenMakerMap.keySet();
}
/**
* Adds a mapping from a key to a <code>TokenMaker</code> implementation
* class name.
* Adds a mapping from a key to a <code>TokenMaker</code> implementation class
* name.
*
* @param key
* The key.
* @param className
* The <code>TokenMaker</code> class name.
* @param key The key.
* @param className The <code>TokenMaker</code> class name.
* @see #putMapping(String, String, ClassLoader)
*/
public void putMapping(String key, String className) {
putMapping(key, className, null);
}
/**
* Adds a mapping from a key to a <code>TokenMaker</code> implementation
* class name.
* Adds a mapping from a key to a <code>TokenMaker</code> implementation class
* name.
*
* @param key
* The key.
* @param className
* The <code>TokenMaker</code> class name.
* @param cl
* The class loader to use when loading the class.
* @param key The key.
* @param className The <code>TokenMaker</code> class name.
* @param cl The class loader to use when loading the class.
* @see #putMapping(String, String)
*/
public void putMapping(String key, String className, ClassLoader cl) {
tokenMakerMap.put(key, new TokenMakerCreator(className, cl));
}
/**
* Wrapper that handles the creation of TokenMaker instances.
*/
private static class TokenMakerCreator {
private String className;
private ClassLoader cl;
public TokenMakerCreator(String className, ClassLoader cl) {
this.className = className;
this.cl = cl != null ? cl : getClass().getClassLoader();
}
public TokenMaker create() throws Exception {
return (TokenMaker) Class.forName(className, true, cl).newInstance();
}
@@ -17,44 +17,39 @@ import java.util.EventObject;
* @version 1.0
*/
public class ActiveLineRangeEvent extends EventObject {
private int min;
private int max;
/**
* Constructor.
*
* @param source
* The text area.
* @param min
* The first line in the active line range, or
* <code>-1</code> if the line range is being cleared.
* @param max
* The last line in the active line range, or
* <code>-1</code> if the line range is being cleared.
* @param source The text area.
* @param min The first line in the active line range, or <code>-1</code> if
* the line range is being cleared.
* @param max The last line in the active line range, or <code>-1</code> if
* the line range is being cleared.
*/
public ActiveLineRangeEvent(RSyntaxTextArea source, int min, int max) {
super(source);
this.min = min;
this.max = max;
}
/**
* Returns the last line in the active line range.
*
* @return The last line, or <code>-1</code> if the range is being
* cleared.
* @return The last line, or <code>-1</code> if the range is being cleared.
* @see #getMin()
*/
public int getMax() {
return max;
}
/**
* Returns the first line in the active line range.
*
* @return The first line, or <code>-1</code> if the range is being
* cleared.
* @return The first line, or <code>-1</code> if the range is being cleared.
* @see #getMax()
*/
public int getMin() {
@@ -13,29 +13,27 @@ import java.util.EventListener;
* Listens for "active line range" events from an <code>RSyntaxTextArea</code>.
* If a text area contains some semantic knowledge of the programming language
* being edited, it may broadcast {@link ActiveLineRangeEvent}s whenever the
* caret moves into a new "block" of code. Listeners can listen for these
* events and respond accordingly.
* caret moves into a new "block" of code. Listeners can listen for these events
* and respond accordingly.
* <p>
*
* See the <code>RSTALanguageSupport</code> project at
* <a href="http://fifesoft.com">http://fifesoft.com</a> for some
* <code>LanguageSupport</code> implementations that may broadcast these
* events. Note that if an RSTA/LanguageSupport does not support broadcasting
* these events, the listener will simply never receive any notifications.
* <code>LanguageSupport</code> implementations that may broadcast these events.
* Note that if an RSTA/LanguageSupport does not support broadcasting these
* events, the listener will simply never receive any notifications.
*
* @author Robert Futrell
* @version 1.0
*/
public interface ActiveLineRangeListener extends EventListener {
/**
* Called whenever the "active line range" changes.
*
* @param e
* Information about the line range change. If there is no longer
* an "active line range," the "minimum" and "maximum" line
* values
* should both be <code>-1</code>.
* @param e Information about the line range change. If there is no longer an
* "active line range," the "minimum" and "maximum" line values should
* both be <code>-1</code>.
*/
void activeLineRangeChanged(ActiveLineRangeEvent e);
}
@@ -13,14 +13,14 @@ import javax.swing.text.Caret;
import org.fife.ui.rtextarea.SmartHighlightPainter;
/**
* The default implementation of {@link OccurrenceMarker}. It goes through
* the document and marks all instances of the specified token.
* The default implementation of {@link OccurrenceMarker}. It goes through the
* document and marks all instances of the specified token.
*
* @author Robert Futrell
* @version 1.0
*/
class DefaultOccurrenceMarker implements OccurrenceMarker {
/**
* {@inheritDoc}
*/
@@ -45,7 +45,7 @@ class DefaultOccurrenceMarker implements OccurrenceMarker {
}
return t;
}
/**
* {@inheritDoc}
*/
@@ -53,7 +53,7 @@ class DefaultOccurrenceMarker implements OccurrenceMarker {
public boolean isValidType(RSyntaxTextArea textArea, Token t) {
return textArea.getMarkOccurrencesOfTokenType(t.getType());
}
/**
* {@inheritDoc}
*/
@@ -61,21 +61,18 @@ class DefaultOccurrenceMarker implements OccurrenceMarker {
public void markOccurrences(RSyntaxDocument doc, Token t, RSyntaxTextAreaHighlighter h, SmartHighlightPainter p) {
markOccurrencesOfToken(doc, t, h, p);
}
/**
* Highlights all instances of tokens identical to <code>t</code> in the
* specified document.
*
* @param doc
* The document.
* @param t
* The document whose relevant occurrences should be marked.
* @param h
* The highlighter to add the highlights to.
* @param p
* The painter for the highlights.
* @param doc The document.
* @param t The document whose relevant occurrences should be marked.
* @param h The highlighter to add the highlights to.
* @param p The painter for the highlights.
*/
public static final void markOccurrencesOfToken(RSyntaxDocument doc, Token t, RSyntaxTextAreaHighlighter h, SmartHighlightPainter p) {
public static final void markOccurrencesOfToken(RSyntaxDocument doc, Token t, RSyntaxTextAreaHighlighter h,
SmartHighlightPainter p) {
char[] lexeme = t.getLexeme().toCharArray();
int type = t.getType();
int lineCount = doc.getDefaultRootElement().getElementCount();
@@ -10,46 +10,43 @@ import javax.swing.text.Segment;
/**
* This class generates tokens for a {@link TokenMaker}. This class is here
* because it reuses tokens when they aren't needed anymore to prevent
* This class doesn't actually create new tokens every time
* <code>createToken</code> is called. Instead, it internally keeps a stack of
* available already-created tokens. When more tokens are needed to properly
* display a line, more tokens are added to the available stack. This saves
* from needless repetitive memory allocation. However, it makes it IMPERATIVE
* that users call <code>resetTokenList</code> when creating a new token list so
* that the token maker can keep an accurate list of available tokens.
* because it reuses tokens when they aren't needed anymore to prevent This
* class doesn't actually create new tokens every time <code>createToken</code>
* is called. Instead, it internally keeps a stack of available already-created
* tokens. When more tokens are needed to properly display a line, more tokens
* are added to the available stack. This saves from needless repetitive memory
* allocation. However, it makes it IMPERATIVE that users call
* <code>resetTokenList</code> when creating a new token list so that the token
* maker can keep an accurate list of available tokens.
* <p>
*
* NOTE: This class should only be used by {@link TokenMaker}; nobody else
* needs it!
* NOTE: This class should only be used by {@link TokenMaker}; nobody else needs
* it!
*
* @author Robert Futrell
* @version 0.1
*/
class DefaultTokenFactory implements TokenFactory {
private int size;
private int increment;
private TokenImpl[] tokenList;
private int currentFreeToken;
protected static final int DEFAULT_START_SIZE = 30;
protected static final int DEFAULT_INCREMENT = 10;
/**
* Constructor.
*/
DefaultTokenFactory() {
this(DEFAULT_START_SIZE, DEFAULT_INCREMENT);
}
/**
* Constructor.
*
* @param size
* The initial number of tokens in this factory.
* @param increment
* How many tokens to increment by when the stack gets
* empty.
* @param size The initial number of tokens in this factory.
* @param increment How many tokens to increment by when the stack gets empty.
*/
DefaultTokenFactory(int size, int increment) {
this.size = size;
@@ -61,10 +58,10 @@ class DefaultTokenFactory implements TokenFactory {
tokenList[i] = new TokenImpl();
}
}
/**
* Adds tokens to the internal token list. This is called whenever a
* request is made and no more tokens are available.
* Adds tokens to the internal token list. This is called whenever a request is
* made and no more tokens are available.
*/
private void augmentTokenList() {
TokenImpl[] temp = new TokenImpl[size + increment];
@@ -76,37 +73,35 @@ class DefaultTokenFactory implements TokenFactory {
}
// System.err.println("... size up to: " + size);
}
/**
* {@inheritDoc}
*/
@Override
public TokenImpl createToken() {
TokenImpl token = tokenList[currentFreeToken];
token.text = null;
token.setType(Token.NULL);
token.setOffset(-1);
token.setNextToken(null);
currentFreeToken++;
if (currentFreeToken == size) {
token.reset();
if (++currentFreeToken == size) {
augmentTokenList();
}
return token;
}
/**
* {@inheritDoc}
*/
@Override
public TokenImpl createToken(final Segment line, final int beg, final int end, final int startOffset, final int type) {
public TokenImpl createToken(final Segment line, final int beg, final int end, final int startOffset,
final int type) {
return createToken(line.array, beg, end, startOffset, type);
}
/**
* {@inheritDoc}
*/
@Override
public TokenImpl createToken(final char[] line, final int beg, final int end, final int startOffset, final int type) {
public TokenImpl createToken(final char[] line, final int beg, final int end, final int startOffset,
final int type) {
TokenImpl token = tokenList[currentFreeToken];
token.set(line, beg, end, startOffset, type);
currentFreeToken++;
@@ -115,11 +110,11 @@ class DefaultTokenFactory implements TokenFactory {
}
return token;
}
/**
* Resets the state of this token maker. This method should be called
* by the <code>TokenMaker</code> every time a token list is generated for
* a new line so the tokens can be reused.
* Resets the state of this token maker. This method should be called by the
* <code>TokenMaker</code> every time a token list is generated for a new line
* so the tokens can be reused.
*/
@Override
public void resetAllTokens() {
@@ -15,7 +15,7 @@ package org.fife.ui.rsyntaxtextarea;
* @version 1.0
*/
class DefaultTokenMakerFactory extends AbstractTokenMakerFactory implements SyntaxConstants {
/**
* {@inheritDoc}
*/
@@ -20,22 +20,22 @@ import javax.swing.text.TabExpander;
* @version 1.0
*/
class DefaultTokenPainter implements TokenPainter {
/**
* Rectangle used for filling token backgrounds.
*/
private Rectangle2D.Float bgRect;
/**
* Micro-optimization; buffer used to compute tab width. If the width is
* correct it's not re-allocated, to prevent lots of very small garbage.
* Only used when painting tab lines.
* Micro-optimization; buffer used to compute tab width. If the width is correct
* it's not re-allocated, to prevent lots of very small garbage. Only used when
* painting tab lines.
*/
private static char[] tabBuf;
DefaultTokenPainter() {
bgRect = new Rectangle2D.Float();
}
/**
* {@inheritDoc}
*/
@@ -43,57 +43,51 @@ class DefaultTokenPainter implements TokenPainter {
public final float paint(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e) {
return paint(token, g, x, y, host, e, 0);
}
/**
* {@inheritDoc}
*/
@Override
public float paint(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, float clipStart) {
public float paint(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e,
float clipStart) {
return paintImpl(token, g, x, y, host, e, clipStart, false, false);
}
/**
* {@inheritDoc}
*/
@Override
public float paint(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, float clipStart, boolean paintBG) {
public float paint(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e,
float clipStart, boolean paintBG) {
return paintImpl(token, g, x, y, host, e, clipStart, !paintBG, false);
}
/**
* Paints the background of a token.
*
* @param x
* The x-coordinate of the token.
* @param y
* The y-coordinate of the token.
* @param width
* The width of the token (actually, the width of the part of
* the token to paint).
* @param height
* The height of the token.
* @param g
* The graphics context with which to paint.
* @param fontAscent
* The ascent of the token's font.
* @param host
* The text area.
* @param color
* The color with which to paint.
* @param x The x-coordinate of the token.
* @param y The y-coordinate of the token.
* @param width The width of the token (actually, the width of the part of
* the token to paint).
* @param height The height of the token.
* @param g The graphics context with which to paint.
* @param fontAscent The ascent of the token's font.
* @param host The text area.
* @param color The color with which to paint.
*/
protected void paintBackground(float x, float y, float width, float height, Graphics2D g, int fontAscent, RSyntaxTextArea host,
Color color) {
protected void paintBackground(float x, float y, float width, float height, Graphics2D g, int fontAscent,
RSyntaxTextArea host, Color color) {
g.setColor(color);
bgRect.setRect(x, y - fontAscent, width, height);
// g.fill(bgRect);
g.fillRect((int) x, (int) (y - fontAscent), (int) width, (int) height);
}
/**
* Does the dirty-work of actually painting the token.
*/
protected float paintImpl(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, float clipStart,
boolean selected, boolean useSTC) {
protected float paintImpl(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e,
float clipStart, boolean selected, boolean useSTC) {
int origX = (int) x;
int textOffs = token.getTextOffset();
char[] text = token.getTextArray();
@@ -107,22 +101,22 @@ class DefaultTokenPainter implements TokenPainter {
FontMetrics fm = host.getFontMetricsForTokenType(token.getType());
for (int i = textOffs; i < end; i++) {
switch (text[i]) {
case '\t':
nextX = e.nextTabStop(x + fm.charsWidth(text, flushIndex, flushLen), 0);
if (bg != null) {
paintBackground(x, y, nextX - x, fm.getHeight(), g, fm.getAscent(), host, bg);
}
if (flushLen > 0) {
g.setColor(fg);
g.drawChars(text, flushIndex, flushLen, (int) x, (int) y);
flushLen = 0;
}
flushIndex = i + 1;
x = nextX;
break;
default:
flushLen += 1;
break;
case '\t':
nextX = e.nextTabStop(x + fm.charsWidth(text, flushIndex, flushLen), 0);
if (bg != null) {
paintBackground(x, y, nextX - x, fm.getHeight(), g, fm.getAscent(), host, bg);
}
if (flushLen > 0) {
g.setColor(fg);
g.drawChars(text, flushIndex, flushLen, (int) x, (int) y);
flushLen = 0;
}
flushIndex = i + 1;
x = nextX;
break;
default:
flushLen += 1;
break;
}
}
nextX = x + fm.charsWidth(text, flushIndex, flushLen);
@@ -152,48 +146,43 @@ class DefaultTokenPainter implements TokenPainter {
}
return nextX;
}
/**
* {@inheritDoc}
*/
@Override
public float paintSelected(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, boolean useSTC) {
public float paintSelected(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e,
boolean useSTC) {
return paintSelected(token, g, x, y, host, e, 0, useSTC);
}
/**
* {@inheritDoc}
*/
@Override
public float paintSelected(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, float clipStart,
boolean useSTC) {
public float paintSelected(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e,
float clipStart, boolean useSTC) {
return paintImpl(token, g, x, y, host, e, clipStart, true, useSTC);
}
/**
* Paints dotted "tab" lines; that is, lines that show where your caret
* would go to on the line if you hit "tab". This visual effect is usually
* done in the leading whitespace token(s) of lines.
* Paints dotted "tab" lines; that is, lines that show where your caret would go
* to on the line if you hit "tab". This visual effect is usually done in the
* leading whitespace token(s) of lines.
*
* @param token
* The token to render.
* @param x
* The starting x-offset of this token. It is assumed that this
* is the left margin of the text area (may be non-zero due to
* insets), since tab lines are only painted for leading
* whitespace.
* @param y
* The baseline where this token was painted.
* @param endX
* The ending x-offset of this token.
* @param g
* The graphics context.
* @param e
* Used to expand tabs.
* @param host
* The text area.
* @param token The token to render.
* @param x The starting x-offset of this token. It is assumed that this is
* the left margin of the text area (may be non-zero due to
* insets), since tab lines are only painted for leading
* whitespace.
* @param y The baseline where this token was painted.
* @param endX The ending x-offset of this token.
* @param g The graphics context.
* @param e Used to expand tabs.
* @param host The text area.
*/
protected void paintTabLines(Token token, int x, int y, int endX, Graphics2D g, TabExpander e, RSyntaxTextArea host) {
protected void paintTabLines(Token token, int x, int y, int endX, Graphics2D g, TabExpander e,
RSyntaxTextArea host) {
// We allow tab lines to be painted in more than just Token.WHITESPACE,
// i.e. for MLC's and Token.IDENTIFIERS (for TokenMakers that return
// whitespace as identifiers for performance). But we only paint tab
@@ -13,30 +13,27 @@ package org.fife.ui.rsyntaxtextarea;
* @version 1.0
*/
public class DocumentRange implements Comparable<DocumentRange> {
private int startOffs;
private int endOffs;
/**
* Constructor.
*
* @param startOffs
* The starting offset in the document, inclusive.
* @param endOffs
* The ending offset in the document, exclusive.
* @throws IllegalArgumentException
* If <code>endOffs</code> is less than
* <code>startOffs</code>, or either argument is less than zero.
* @param startOffs The starting offset in the document, inclusive.
* @param endOffs The ending offset in the document, exclusive.
* @throws IllegalArgumentException If <code>endOffs</code> is less than
* <code>startOffs</code>, or either argument
* is less than zero.
*/
public DocumentRange(int startOffs, int endOffs) {
set(startOffs, endOffs);
}
/**
* Compares this document range to another.
*
* @param other
* Another document range.
* @param other Another document range.
* @return How the two should be sorted relative to each other.
*/
@Override
@@ -50,14 +47,13 @@ public class DocumentRange implements Comparable<DocumentRange> {
}
return endOffs - other.endOffs;
}
/**
* Returns whether this document range is equal to another one.
*
* @param other
* Another object, presumably a document range.
* @return Whether <code>other</code> is also a document range, and equal
* to this one.
* @param other Another object, presumably a document range.
* @return Whether <code>other</code> is also a document range, and equal to
* this one.
*/
@Override
public boolean equals(Object other) {
@@ -69,7 +65,7 @@ public class DocumentRange implements Comparable<DocumentRange> {
}
return false;
}
/**
* Gets the end offset of the range.
*
@@ -79,7 +75,7 @@ public class DocumentRange implements Comparable<DocumentRange> {
public int getEndOffset() {
return endOffs;
}
/**
* Gets the starting offset of the range.
*
@@ -89,7 +85,7 @@ public class DocumentRange implements Comparable<DocumentRange> {
public int getStartOffset() {
return startOffs;
}
/**
* Overridden simply as a best practice, since {@link #equals(Object)} is
* overridden.
@@ -100,29 +96,26 @@ public class DocumentRange implements Comparable<DocumentRange> {
public int hashCode() {
return startOffs + endOffs;
}
/**
* Returns whether this document range has zero length. This can happen,
* for example, with regex searches of forms like
* <code>"foo|"</code>, where the right-hand sub-expression matches empty
* strings.
* Returns whether this document range has zero length. This can happen, for
* example, with regex searches of forms like <code>"foo|"</code>, where the
* right-hand sub-expression matches empty strings.
*
* @return Whether this document range has zero length.
*/
public boolean isZeroLength() {
return startOffs == endOffs;
}
/**
* Sets the document range.
*
* @param start
* The new start value, inclusive.
* @param end
* The new end value, exclusive.
* @throws IllegalArgumentException
* If <code>end</code> is less than
* <code>start</code>, or either argument is less than zero.
* @param start The new start value, inclusive.
* @param end The new end value, exclusive.
* @throws IllegalArgumentException If <code>end</code> is less than
* <code>start</code>, or either argument is
* less than zero.
*/
public void set(int start, int end) {
if (start < 0 || end < 0) {
@@ -134,7 +127,7 @@ public class DocumentRange implements Comparable<DocumentRange> {
this.startOffs = start;
this.endOffs = end;
}
/**
* Returns a string representation of this object.
*
@@ -144,12 +137,11 @@ public class DocumentRange implements Comparable<DocumentRange> {
public String toString() {
return "[DocumentRange: " + startOffs + "-" + endOffs + "]";
}
/**
* Translates this document range by a given amount.
*
* @param amount
* The amount to translate this range by.
* @param amount The amount to translate this range by.
* @return This (modified) range.
*/
public DocumentRange translate(int amount) {
+113 -130
View File
@@ -39,16 +39,15 @@ import org.fife.ui.rsyntaxtextarea.parser.TaskTagParser.TaskNotice;
import org.fife.ui.rtextarea.RTextArea;
/**
* A component to sit alongside an {@link RSyntaxTextArea} that displays
* colored markers for locations of interest (parser errors, marked
* occurrences, etc.).
* A component to sit alongside an {@link RSyntaxTextArea} that displays colored
* markers for locations of interest (parser errors, marked occurrences, etc.).
* <p>
*
* <code>ErrorStrip</code>s display <code>ParserNotice</code>s from
* {@link Parser}s. Currently, the only way to get lines flagged in this
* component is to register a <code>Parser</code> on an RSyntaxTextArea and
* return <code>ParserNotice</code>s for each line to display an icon for.
* The severity of each notice must be at least the threshold set by
* return <code>ParserNotice</code>s for each line to display an icon for. The
* severity of each notice must be at least the threshold set by
* {@link #setLevelThreshold(org.fife.ui.rsyntaxtextarea.parser.ParserNotice.Level)}
* to be displayed in this error strip. The default threshold is
* {@link org.fife.ui.rsyntaxtextarea.parser.ParserNotice.Level#WARNING}.
@@ -76,7 +75,7 @@ import org.fife.ui.rtextarea.RTextArea;
// are now "empty").
//
public class ErrorStrip extends JPanel {
/**
* The text area.
*/
@@ -86,23 +85,23 @@ public class ErrorStrip extends JPanel {
*/
private transient Listener listener;
/**
* Whether "marked occurrences" in the text area should be shown in this
* error strip.
* Whether "marked occurrences" in the text area should be shown in this error
* strip.
*/
private boolean showMarkedOccurrences;
/**
* Whether markers for "mark all" highlights should be shown in this
* error strip.
* Whether markers for "mark all" highlights should be shown in this error
* strip.
*/
private boolean showMarkAll;
/**
* Mapping of colors to brighter colors. This is kept to prevent
* unnecessary creation of the same Colors over and over.
* Mapping of colors to brighter colors. This is kept to prevent unnecessary
* creation of the same Colors over and over.
*/
private Map<Color, Color> brighterColors;
/**
* Only notices of this severity (or worse) will be displayed in this
* error strip.
* Only notices of this severity (or worse) will be displayed in this error
* strip.
*/
private ParserNotice.Level levelThreshold;
/**
@@ -130,12 +129,11 @@ public class ErrorStrip extends JPanel {
*/
private static final int PREFERRED_WIDTH = 14;
private static final ResourceBundle MSG = ResourceBundle.getBundle("org.fife.ui.rsyntaxtextarea.ErrorStrip");
/**
* Constructor.
*
* @param textArea
* The text area we are examining.
* @param textArea The text area we are examining.
*/
public ErrorStrip(RSyntaxTextArea textArea) {
this.textArea = textArea;
@@ -150,10 +148,10 @@ public class ErrorStrip extends JPanel {
setCaretMarkerColor(Color.BLACK);
setMarkerToolTipProvider(null); // Install default
}
/**
* Overridden so we only start listening for parser notices when this
* component (and presumably the text area) are visible.
* Overridden so we only start listening for parser notices when this component
* (and presumably the text area) are visible.
*/
@Override
public void addNotify() {
@@ -165,7 +163,7 @@ public class ErrorStrip extends JPanel {
textArea.addPropertyChangeListener(RSyntaxTextArea.MARK_ALL_OCCURRENCES_CHANGED_PROPERTY, listener);
refreshMarkers();
}
/**
* Manually manages layout since this component uses no layout manager.
*/
@@ -177,12 +175,11 @@ public class ErrorStrip extends JPanel {
}
listener.caretUpdate(null); // Force recalculation of caret line pos
}
/**
* Returns a "brighter" color.
*
* @param c
* The color.
* @param c The color.
* @return A brighter color.
*/
private Color getBrighterColor(Color c) {
@@ -201,7 +198,7 @@ public class ErrorStrip extends JPanel {
}
return brighter;
}
/**
* returns the color to use when painting the caret marker.
*
@@ -211,7 +208,7 @@ public class ErrorStrip extends JPanel {
public Color getCaretMarkerColor() {
return caretMarkerColor;
}
/**
* Returns whether the caret's position should be drawn.
*
@@ -221,7 +218,7 @@ public class ErrorStrip extends JPanel {
public boolean getFollowCaret() {
return followCaret;
}
/**
* {@inheritDoc}
*/
@@ -230,11 +227,11 @@ public class ErrorStrip extends JPanel {
int height = textArea.getPreferredScrollableViewportSize().height;
return new Dimension(PREFERRED_WIDTH, height);
}
/**
* Returns the minimum severity a parser notice must be for it to be
* displayed in this error strip. This will be one of the constants
* defined in the <code>ParserNotice</code> class.
* Returns the minimum severity a parser notice must be for it to be displayed
* in this error strip. This will be one of the constants defined in the
* <code>ParserNotice</code> class.
*
* @return The minimum severity.
* @see #setLevelThreshold(org.fife.ui.rsyntaxtextarea.parser.ParserNotice.Level)
@@ -242,7 +239,7 @@ public class ErrorStrip extends JPanel {
public ParserNotice.Level getLevelThreshold() {
return levelThreshold;
}
/**
* Returns whether "mark all" highlights are shown in this error strip.
*
@@ -252,7 +249,7 @@ public class ErrorStrip extends JPanel {
public boolean getShowMarkAll() {
return showMarkAll;
}
/**
* Returns whether marked occurrences are shown in this error strip.
*
@@ -262,7 +259,7 @@ public class ErrorStrip extends JPanel {
public boolean getShowMarkedOccurrences() {
return showMarkedOccurrences;
}
/**
* {@inheritDoc}
*/
@@ -276,13 +273,12 @@ public class ErrorStrip extends JPanel {
}
return text;
}
/**
* Returns the y-offset in this component corresponding to a line in the
* text component.
* Returns the y-offset in this component corresponding to a line in the text
* component.
*
* @param line
* The line.
* @param line The line.
* @return The y-offset.
* @see #yToLine(int)
*/
@@ -291,12 +287,11 @@ public class ErrorStrip extends JPanel {
float lineCount = textArea.getLineCount();
return (int) (((line - 1) / (lineCount - 1)) * (h - 2));
}
/**
* Overridden to (possibly) draw the caret's position.
*
* @param g
* The graphics context.
* @param g The graphics context.
*/
@Override
protected void paintComponent(Graphics g) {
@@ -306,12 +301,11 @@ public class ErrorStrip extends JPanel {
g.fillRect(0, caretLineY, getWidth(), 2);
}
}
/**
* Returns a possibly brighter component for a color.
*
* @param i
* An RGB component for a color (0-255).
* @param i An RGB component for a color (0-255).
* @return A possibly brighter value for the component.
*/
private static int possiblyBrighter(int i) {
@@ -320,7 +314,7 @@ public class ErrorStrip extends JPanel {
}
return i;
}
/**
* Refreshes the markers displayed in this error strip.
*/
@@ -354,16 +348,13 @@ public class ErrorStrip extends JPanel {
revalidate();
repaint();
}
/**
* Adds markers for a list of ranges in the document.
*
* @param ranges
* The list of ranges in the document.
* @param markerMap
* A mapping from line number to <code>Marker</code>.
* @param color
* The color to use for the markers.
* @param ranges The list of ranges in the document.
* @param markerMap A mapping from line number to <code>Marker</code>.
* @param color The color to use for the markers.
*/
private void addMarkersForRanges(List<DocumentRange> ranges, Map<Integer, Marker> markerMap, Color color) {
for (DocumentRange range : ranges) {
@@ -388,7 +379,7 @@ public class ErrorStrip extends JPanel {
}
}
}
/**
* {@inheritDoc}
*/
@@ -401,12 +392,11 @@ public class ErrorStrip extends JPanel {
textArea.removePropertyChangeListener(RSyntaxTextArea.MARKED_OCCURRENCES_CHANGED_PROPERTY, listener);
textArea.removePropertyChangeListener(RSyntaxTextArea.MARK_ALL_OCCURRENCES_CHANGED_PROPERTY, listener);
}
/**
* Sets the color to use when painting the caret marker.
*
* @param color
* The new caret marker color.
* @param color The new caret marker color.
* @see #getCaretMarkerColor()
*/
public void setCaretMarkerColor(Color color) {
@@ -415,12 +405,11 @@ public class ErrorStrip extends JPanel {
listener.caretUpdate(null); // Force repaint
}
}
/**
* Toggles whether the caret's current location should be drawn.
*
* @param follow
* Whether the caret's current location should be followed.
* @param follow Whether the caret's current location should be followed.
* @see #getFollowCaret()
*/
public void setFollowCaret(boolean follow) {
@@ -434,15 +423,14 @@ public class ErrorStrip extends JPanel {
listener.caretUpdate(null); // Possibly repaint
}
}
/**
* Sets the minimum severity a parser notice must be for it to be displayed
* in this error strip. This should be one of the constants defined in
* the <code>ParserNotice</code> class. The default value is
* Sets the minimum severity a parser notice must be for it to be displayed in
* this error strip. This should be one of the constants defined in the
* <code>ParserNotice</code> class. The default value is
* {@link org.fife.ui.rsyntaxtextarea.parser.ParserNotice.Level#WARNING}.
*
* @param level
* The new severity threshold.
* @param level The new severity threshold.
* @see #getLevelThreshold()
* @see ParserNotice
*/
@@ -452,25 +440,23 @@ public class ErrorStrip extends JPanel {
refreshMarkers();
}
}
/**
* Sets the provider of tool tips for markers in this error strip.
* Applications can use this method to control the content and format of
* the tool tip descriptions of line markers.
* Sets the provider of tool tips for markers in this error strip. Applications
* can use this method to control the content and format of the tool tip
* descriptions of line markers.
*
* @param provider
* The provider. If this is <code>null</code>, a default
* implementation will be used.
* @param provider The provider. If this is <code>null</code>, a default
* implementation will be used.
*/
public void setMarkerToolTipProvider(ErrorStripMarkerToolTipProvider provider) {
markerToolTipProvider = provider != null ? provider : new DefaultErrorStripMarkerToolTipProvider();
}
/**
* Sets whether "mark all" highlights are shown in this error strip.
*
* @param show
* Whether to show markers for "mark all" highlights.
* @param show Whether to show markers for "mark all" highlights.
* @see #getShowMarkAll()
*/
public void setShowMarkAll(boolean show) {
@@ -481,12 +467,11 @@ public class ErrorStrip extends JPanel {
}
}
}
/**
* Sets whether marked occurrences are shown in this error strip.
*
* @param show
* Whether to show marked occurrences.
* @param show Whether to show marked occurrences.
* @see #getShowMarkedOccurrences()
*/
public void setShowMarkedOccurrences(boolean show) {
@@ -497,13 +482,12 @@ public class ErrorStrip extends JPanel {
}
}
}
/**
* Returns the line in the text area corresponding to a y-offset in this
* component.
*
* @param y
* The y-offset.
* @param y The y-offset.
* @return The line.
* @see #lineToY(int)
*/
@@ -516,15 +500,15 @@ public class ErrorStrip extends JPanel {
}
return line;
}
/**
* The default implementation of the provider of tool tips for markers in
* an error strip.
* The default implementation of the provider of tool tips for markers in an
* error strip.
*
* @author predi
*/
private static class DefaultErrorStripMarkerToolTipProvider implements ErrorStripMarkerToolTipProvider {
@Override
public String getToolTipText(List<ParserNotice> notices) {
String text = null;
@@ -545,34 +529,33 @@ public class ErrorStrip extends JPanel {
return text;
}
}
/**
* Returns tool tip text for the markers in an {@link ErrorStrip} that
* denote one or more parser notices.
* Returns tool tip text for the markers in an {@link ErrorStrip} that denote
* one or more parser notices.
*
* @author predi
*/
public interface ErrorStripMarkerToolTipProvider {
/**
* Returns the tool tip text for a marker in an <code>ErrorStrip</code>
* that denotes a given list of parser notices.
* Returns the tool tip text for a marker in an <code>ErrorStrip</code> that
* denotes a given list of parser notices.
*
* @param notices
* The list of parser notices.
* @return The tool tip text. This may be HTML. Returning
* <code>null</code> will result in no tool tip being displayed.
* @param notices The list of parser notices.
* @return The tool tip text. This may be HTML. Returning <code>null</code> will
* result in no tool tip being displayed.
*/
String getToolTipText(List<ParserNotice> notices);
}
/**
* Listens for events in the error strip and its markers.
*/
private class Listener extends MouseAdapter implements PropertyChangeListener, CaretListener {
private Rectangle visibleRect = new Rectangle();
@Override
public void caretUpdate(CaretEvent e) {
if (getFollowCaret()) {
@@ -587,7 +570,7 @@ public class ErrorStrip extends JPanel {
}
}
}
@Override
public void mouseClicked(MouseEvent e) {
Component source = (Component) e.getSource();
@@ -605,7 +588,7 @@ public class ErrorStrip extends JPanel {
}
}
}
@Override
public void propertyChange(PropertyChangeEvent e) {
String propName = e.getPropertyName();
@@ -636,30 +619,30 @@ public class ErrorStrip extends JPanel {
}
}
}
/**
* A notice that wraps a "marked occurrence" instance.
*/
private class MarkedOccurrenceNotice implements ParserNotice {
private DocumentRange range;
private Color color;
MarkedOccurrenceNotice(DocumentRange range, Color color) {
this.range = range;
this.color = color;
}
@Override
public int compareTo(ParserNotice other) {
return 0; // Value doesn't matter
}
@Override
public boolean containsPosition(int pos) {
return pos >= range.getStartOffset() && pos < range.getEndOffset();
}
@Override
public boolean equals(Object o) {
// FindBugs - Define equals() when defining compareTo()
@@ -668,12 +651,12 @@ public class ErrorStrip extends JPanel {
}
return compareTo((ParserNotice) o) == 0;
}
@Override
public Color getColor() {
return color;
}
/**
* {@inheritDoc}
*/
@@ -681,17 +664,17 @@ public class ErrorStrip extends JPanel {
public boolean getKnowsOffsetAndLength() {
return true;
}
@Override
public int getLength() {
return range.getEndOffset() - range.getStartOffset();
}
@Override
public Level getLevel() {
return Level.INFO; // Won't matter
}
@Override
public int getLine() {
try {
@@ -700,7 +683,7 @@ public class ErrorStrip extends JPanel {
return 0;
}
}
@Override
public String getMessage() {
String text = null;
@@ -713,40 +696,40 @@ public class ErrorStrip extends JPanel {
}
return text;
}
@Override
public int getOffset() {
return range.getStartOffset();
}
@Override
public Parser getParser() {
return null;
}
@Override
public boolean getShowInEditor() {
return false; // Value doesn't matter
}
@Override
public String getToolTipText() {
return null;
}
@Override
public int hashCode() { // FindBugs, since we override equals()
return 0; // Value doesn't matter for us.
}
}
/**
* A "marker" in this error strip, representing one or more notices.
*/
private class Marker extends JComponent {
private List<ParserNotice> notices;
Marker(ParserNotice notice) {
notices = new ArrayList<ParserNotice>(1); // Usually just 1
addNotice(notice);
@@ -754,11 +737,11 @@ public class ErrorStrip extends JPanel {
setSize(getPreferredSize());
ToolTipManager.sharedInstance().registerComponent(this);
}
public void addNotice(ParserNotice notice) {
notices.add(notice);
}
public boolean containsMarkedOccurence() {
boolean result = false;
for (int i = 0; i < notices.size(); i++) {
@@ -769,7 +752,7 @@ public class ErrorStrip extends JPanel {
}
return result;
}
public Color getColor() {
// Return the color for the highest-level parser.
Color c = null;
@@ -782,18 +765,18 @@ public class ErrorStrip extends JPanel {
}
return c;
}
@Override
public Dimension getPreferredSize() {
int w = PREFERRED_WIDTH - 4; // 2-pixel empty border
return new Dimension(w, 5);
}
@Override
public String getToolTipText() {
return markerToolTipProvider.getToolTipText(Collections.unmodifiableList(notices));
}
protected void mouseClicked(MouseEvent e) {
ParserNotice pn = notices.get(0);
int offs = pn.getOffset();
@@ -812,7 +795,7 @@ public class ErrorStrip extends JPanel {
}
}
}
@Override
protected void paintComponent(Graphics g) {
// TODO: Give "priorities" and always pick color of a notice with
@@ -829,14 +812,14 @@ public class ErrorStrip extends JPanel {
g.setColor(borderColor);
g.drawRect(0, 0, w - 1, h - 1);
}
@Override
public void removeNotify() {
super.removeNotify();
ToolTipManager.sharedInstance().unregisterComponent(this);
removeMouseListener(listener);
}
public void updateLocation() {
int line = notices.get(0).getLine();
int y = lineToY(line);
@@ -20,17 +20,16 @@ import java.io.OutputStream;
* @version 1.0
*/
class FileFileLocation extends FileLocation {
/**
* The file. This may or may not actually exist.
*/
private File file;
/**
* Constructor.
*
* @param file
* The local file.
* @param file The local file.
*/
FileFileLocation(File file) {
try {
@@ -40,7 +39,7 @@ class FileFileLocation extends FileLocation {
this.file = file;
}
}
/**
* {@inheritDoc}
*/
@@ -48,7 +47,7 @@ class FileFileLocation extends FileLocation {
protected long getActualLastModified() {
return file.lastModified();
}
/**
* Returns the full path to the file.
*
@@ -59,7 +58,7 @@ class FileFileLocation extends FileLocation {
public String getFileFullPath() {
return file.getAbsolutePath();
}
/**
* {@inheritDoc}
*/
@@ -67,7 +66,7 @@ class FileFileLocation extends FileLocation {
public String getFileName() {
return file.getName();
}
/**
* {@inheritDoc}
*/
@@ -75,7 +74,7 @@ class FileFileLocation extends FileLocation {
protected InputStream getInputStream() throws IOException {
return new FileInputStream(file);
}
/**
* {@inheritDoc}
*/
@@ -83,7 +82,7 @@ class FileFileLocation extends FileLocation {
protected OutputStream getOutputStream() throws IOException {
return new FileOutputStream(file);
}
/**
* Always returns <code>true</code>.
*
@@ -94,10 +93,10 @@ class FileFileLocation extends FileLocation {
public boolean isLocal() {
return true;
}
/**
* Since file locations of this type are guaranteed to be local, this
* method returns whether the file exists.
* Since file locations of this type are guaranteed to be local, this method
* returns whether the file exists.
*
* @return Whether this local file actually exists.
* @see #isLocal()
@@ -14,23 +14,23 @@ import java.net.MalformedURLException;
import java.net.URL;
/**
* Holds the location of a local or remote file. This provides a common way
* to read, write, and check properties of both local and remote files.
* Holds the location of a local or remote file. This provides a common way to
* read, write, and check properties of both local and remote files.
*
* @author Robert Futrell
* @version 1.0
*/
public abstract class FileLocation {
/**
* Creates a {@link FileLocation} instance for the specified local file.
*
* @param fileFullPath
* The full path to a local file.
* @param fileFullPath The full path to a local file.
* @return The file's location.
*/
public static FileLocation create(String fileFullPath) {
if (fileFullPath.startsWith("http://") || fileFullPath.startsWith("https://") || fileFullPath.startsWith("ftp://")) {
if (fileFullPath.startsWith("http://") || fileFullPath.startsWith("https://")
|| fileFullPath.startsWith("ftp://")) {
try {
return new URLFileLocation(new URL(fileFullPath));
} catch (MalformedURLException mue) {
@@ -39,23 +39,21 @@ public abstract class FileLocation {
}
return new FileFileLocation(new File(fileFullPath));
}
/**
* Creates a {@link FileLocation} instance for the specified local file.
*
* @param file
* A local file.
* @param file A local file.
* @return The file's location.
*/
public static FileLocation create(File file) {
return new FileFileLocation(file);
}
/**
* Creates a {@link FileLocation} instance for the specified file.
*
* @param url
* The URL of a file.
* @param url The URL of a file.
* @return The file's location.
*/
public static FileLocation create(URL url) {
@@ -64,25 +62,25 @@ public abstract class FileLocation {
}
return new URLFileLocation(url);
}
/**
* Returns the last time this file was modified, or
* {@link TextEditorPane#LAST_MODIFIED_UNKNOWN} if this value cannot be
* computed (such as for a remote file).
* {@link TextEditorPane#LAST_MODIFIED_UNKNOWN} if this value cannot be computed
* (such as for a remote file).
*
* @return The last time this file was modified.
*/
protected abstract long getActualLastModified();
/**
* Returns the full path to the file. This will be stripped of
* sensitive information such as passwords for remote files.
* Returns the full path to the file. This will be stripped of sensitive
* information such as passwords for remote files.
*
* @return The full path to the file.
* @see #getFileName()
*/
public abstract String getFileFullPath();
/**
* Returns the name of the file.
*
@@ -90,26 +88,24 @@ public abstract class FileLocation {
* @see #getFileFullPath()
*/
public abstract String getFileName();
/**
* Opens an input stream for reading from this file.
*
* @return The input stream.
* @throws IOException
* If the file does not exist, or some other IO error
* occurs.
* @throws IOException If the file does not exist, or some other IO error
* occurs.
*/
protected abstract InputStream getInputStream() throws IOException;
/**
* Opens an output stream for writing this file.
*
* @return An output stream.
* @throws IOException
* If an IO error occurs.
* @throws IOException If an IO error occurs.
*/
protected abstract OutputStream getOutputStream() throws IOException;
/**
* Returns whether this file location is a local file.
*
@@ -117,16 +113,15 @@ public abstract class FileLocation {
* @see #isLocalAndExists()
*/
public abstract boolean isLocal();
/**
* Returns whether this file location is a local file that already
* exists.
* Returns whether this file location is a local file that already exists.
*
* @return Whether this file is local and actually exists.
* @see #isLocal()
*/
public abstract boolean isLocalAndExists();
/**
* Returns whether this file location is a remote location.
*
@@ -28,17 +28,16 @@ import org.fife.ui.rtextarea.IconRowHeader;
* @version 1.0
*/
public class FoldingAwareIconRowHeader extends IconRowHeader {
/**
* Constructor.
*
* @param textArea
* The parent text area.
* @param textArea The parent text area.
*/
public FoldingAwareIconRowHeader(RSyntaxTextArea textArea) {
super(textArea);
}
/**
* {@inheritDoc}
*/
@@ -160,11 +159,11 @@ public class FoldingAwareIconRowHeader extends IconRowHeader {
}
}
}
/**
* Paints icons when line wrapping is enabled. Note that this does not
* override the parent class's implementation to avoid this version being
* called when line wrapping is disabled.
* Paints icons when line wrapping is enabled. Note that this does not override
* the parent class's implementation to avoid this version being called when
* line wrapping is disabled.
*/
private void paintComponentWrapped(Graphics g) {
// The variables we use are as follows:
@@ -20,49 +20,49 @@ import javax.swing.text.Element;
import org.fife.ui.rtextarea.SmartHighlightPainter;
/**
* Marks occurrences of the current token for HTML. Tags that require a
* closing tag have their "opposite" tag closed.
* Marks occurrences of the current token for HTML. Tags that require a closing
* tag have their "opposite" tag closed.
*
* @author Robert Futrell
* @version 1.0
*/
public class HtmlOccurrenceMarker implements OccurrenceMarker {
private static final char[] CLOSE_TAG_START = { '<', '/' };
private static final char[] TAG_SELF_CLOSE = { '/', '>' };
private static final Set<String> TAGS_REQUIRING_CLOSING = getRequiredClosingTags();
public static final Set<String> getRequiredClosingTags() {
final String[] tags = { "html", "head", "title", "style", "script", "noscript", "body", "section", "nav", "article", "aside", "h1",
"h2", "h3", "h4", "h5", "h6", "header", "footer", "address", "pre", "dialog", "blockquote", "ol", "ul", "dl", "a", "q",
"cite", "em", "strong", "small", "mark", "dfn", "abbr", "time", "progress", "meter", "code", "var", "samp", "kbd", "sub",
"sup", "span", "i", "b", "bdo", "ruby", "rt", "rp", "ins", "del", "figure", "iframe", "object", "video", "audio", "canvas",
"map", "table", "caption", "form", "fieldset", "label", "button", "select", "datalist", "textarea", "output", "details",
"bb", "menu", "legend", "div",
final String[] tags = { "html", "head", "title", "style", "script", "noscript", "body", "section", "nav",
"article", "aside", "h1", "h2", "h3", "h4", "h5", "h6", "header", "footer", "address", "pre", "dialog",
"blockquote", "ol", "ul", "dl", "a", "q", "cite", "em", "strong", "small", "mark", "dfn", "abbr",
"time", "progress", "meter", "code", "var", "samp", "kbd", "sub", "sup", "span", "i", "b", "bdo",
"ruby", "rt", "rp", "ins", "del", "figure", "iframe", "object", "video", "audio", "canvas", "map",
"table", "caption", "form", "fieldset", "label", "button", "select", "datalist", "textarea", "output",
"details", "bb", "menu", "legend", "div",
// Obsolete elements
"acronym", "applet", "big", "blink", "center", "dir", "font", "frame", "frameset", "isindex", "listing", "marquee", "nobr",
"noembed", "noframes", "plaintext", "s", "spacer", "strike", "tt", "u", "xmp", };
"acronym", "applet", "big", "blink", "center", "dir", "font", "frame", "frameset", "isindex", "listing",
"marquee", "nobr", "noembed", "noframes", "plaintext", "s", "spacer", "strike", "tt", "u", "xmp", };
return new HashSet<String>(Arrays.asList(tags));
}
/**
* If the caret is inside of a tag, this method returns the token
* representing the tag name; otherwise, <code>null</code> is returned.
* If the caret is inside of a tag, this method returns the token representing
* the tag name; otherwise, <code>null</code> is returned.
* <p>
*
* Currently, this method only checks for tag names on the same line as
* the caret, for simplicity. In the future it could check prior lines
* until the tag name is found.
* Currently, this method only checks for tag names on the same line as the
* caret, for simplicity. In the future it could check prior lines until the tag
* name is found.
*
* @param textArea
* The text area.
* @param occurrenceMarker
* The occurrence marker.
* @return The token to mark occurrences of. Note that, if the
* specified occurrence marker identifies tokens other than
* tag names, these other element types may be returned.
* @param textArea The text area.
* @param occurrenceMarker The occurrence marker.
* @return The token to mark occurrences of. Note that, if the specified
* occurrence marker identifies tokens other than tag names, these other
* element types may be returned.
*/
public static final Token getTagNameTokenForCaretOffset(RSyntaxTextArea textArea, OccurrenceMarker occurrenceMarker) {
public static final Token getTagNameTokenForCaretOffset(RSyntaxTextArea textArea,
OccurrenceMarker occurrenceMarker) {
// Get the tag name token.
// For now, we only check for tags on the current line, for simplicity.
int dot = textArea.getCaretPosition();
@@ -93,7 +93,7 @@ public class HtmlOccurrenceMarker implements OccurrenceMarker {
}
return toMark;
}
/**
* {@inheritDoc}
*/
@@ -101,7 +101,7 @@ public class HtmlOccurrenceMarker implements OccurrenceMarker {
public Token getTokenToMark(RSyntaxTextArea textArea) {
return getTagNameTokenForCaretOffset(textArea, this);
}
/**
* {@inheritDoc}
*/
@@ -109,7 +109,7 @@ public class HtmlOccurrenceMarker implements OccurrenceMarker {
public boolean isValidType(RSyntaxTextArea textArea, Token t) {
return textArea.getMarkOccurrencesOfTokenType(t.getType());
}
/**
* {@inheritDoc}
*/
@@ -254,15 +254,15 @@ public class HtmlOccurrenceMarker implements OccurrenceMarker {
} while (curLine >= 0);
}
}
/**
* Used internally when searching backward for a matching "open" tag.
*/
private static class Entry {
private boolean open;
private Token t;
Entry(boolean open, Token t) {
this.open = open;
this.t = t;
@@ -28,17 +28,14 @@ package org.fife.ui.rsyntaxtextarea;
* @version 1.0
*/
public interface LinkGenerator {
/**
* If a region of text under the mouse position should be considered a
* hyperlink, a result object is returned. This object describes what
* region of text is the link, and what action to perform if the link is
* clicked.
* hyperlink, a result object is returned. This object describes what region of
* text is the link, and what action to perform if the link is clicked.
*
* @param textArea
* The text component.
* @param offs
* The offset in the document under the mouse position.
* @param textArea The text component.
* @param offs The offset in the document under the mouse position.
* @return The link information, or <code>null</code> if no link is at the
* specified offset.
*/
@@ -23,19 +23,19 @@ import javax.swing.event.HyperlinkEvent;
* @see SelectRegionLinkGeneratorResult
*/
public interface LinkGeneratorResult {
/**
* Executes the action associated with this object. If the result is a
* URL to open, a standard hyperlink event can be returned. Alternatively,
* <code>null</code> can be returned and the action performed in this
* method itself.
* Executes the action associated with this object. If the result is a URL to
* open, a standard hyperlink event can be returned. Alternatively,
* <code>null</code> can be returned and the action performed in this method
* itself.
*
* @return The hyperlink event to broadcast from the text area, or
* <code>null</code> if the action's behavior occurs in this method
* directly.
*/
HyperlinkEvent execute();
/**
* Returns the starting offset of the link specified by the parent
* <code>LinkGenerator</code>.
@@ -19,15 +19,15 @@ import javax.swing.text.Caret;
import org.fife.ui.rtextarea.SmartHighlightPainter;
/**
* Marks all occurrences of the token at the current caret position, if it is
* an identifier.
* Marks all occurrences of the token at the current caret position, if it is an
* identifier.
*
* @author Robert Futrell
* @version 1.0
* @see OccurrenceMarker
*/
class MarkOccurrencesSupport implements CaretListener, ActionListener {
private RSyntaxTextArea textArea;
private Timer timer;
private SmartHighlightPainter p;
@@ -39,36 +39,33 @@ class MarkOccurrencesSupport implements CaretListener, ActionListener {
* The default delay.
*/
static final int DEFAULT_DELAY_MS = 1000;
/**
* Constructor. Creates a listener with a 1 second delay.
*/
MarkOccurrencesSupport() {
this(DEFAULT_DELAY_MS);
}
/**
* Constructor.
*
* @param delay
* The delay between when the caret last moves and when the
* text should be scanned for matching occurrences. This should
* be in milliseconds.
* @param delay The delay between when the caret last moves and when the text
* should be scanned for matching occurrences. This should be in
* milliseconds.
*/
MarkOccurrencesSupport(int delay) {
this(delay, DEFAULT_COLOR);
}
/**
* Constructor.
*
* @param delay
* The delay between when the caret last moves and when the
* text should be scanned for matching occurrences. This should
* be in milliseconds.
* @param color
* The color to use to mark the occurrences. This cannot be
* <code>null</code>.
* @param delay The delay between when the caret last moves and when the text
* should be scanned for matching occurrences. This should be in
* milliseconds.
* @param color The color to use to mark the occurrences. This cannot be
* <code>null</code>.
*/
MarkOccurrencesSupport(int delay, Color color) {
timer = new Timer(delay, this);
@@ -76,18 +73,17 @@ class MarkOccurrencesSupport implements CaretListener, ActionListener {
p = new SmartHighlightPainter();
setColor(color);
}
/**
* Called after the caret has been moved and a fixed time delay has
* elapsed. This locates and highlights all occurrences of the identifier
* at the caret position, if any.
* Called after the caret has been moved and a fixed time delay has elapsed.
* This locates and highlights all occurrences of the identifier at the caret
* position, if any.
* <p>
*
* Callers should not call this method directly, but should rather prefer
* {@link #doMarkOccurrences()} to mark occurrences.
*
* @param e
* The event.
* @param e The event.
* @see #doMarkOccurrences()
*/
@Override
@@ -124,18 +120,17 @@ class MarkOccurrencesSupport implements CaretListener, ActionListener {
textArea.fireMarkedOccurrencesChanged();
}
}
/**
* Called when the caret moves in the text area.
*
* @param e
* The event.
* @param e The event.
*/
@Override
public void caretUpdate(CaretEvent e) {
timer.restart();
}
/**
* Removes all highlights added to the text area by this listener.
*/
@@ -145,16 +140,15 @@ class MarkOccurrencesSupport implements CaretListener, ActionListener {
h.clearMarkOccurrencesHighlights();
}
}
/**
* Immediately marks all occurrences of the token at the current caret
* position.
* Immediately marks all occurrences of the token at the current caret position.
*/
public void doMarkOccurrences() {
timer.stop();
actionPerformed(null);
}
/**
* Returns the color being used to mark occurrences.
*
@@ -164,7 +158,7 @@ class MarkOccurrencesSupport implements CaretListener, ActionListener {
public Color getColor() {
return (Color) p.getPaint();
}
/**
* Returns the delay, in milliseconds.
*
@@ -174,7 +168,7 @@ class MarkOccurrencesSupport implements CaretListener, ActionListener {
public int getDelay() {
return timer.getDelay();
}
/**
* Returns whether a border is painted around marked occurrences.
*
@@ -185,13 +179,12 @@ class MarkOccurrencesSupport implements CaretListener, ActionListener {
public boolean getPaintBorder() {
return p.getPaintBorder();
}
/**
* Installs this listener on a text area. If it is already installed on
* another text area, it is uninstalled first.
* Installs this listener on a text area. If it is already installed on another
* text area, it is uninstalled first.
*
* @param textArea
* The text area to install on.
* @param textArea The text area to install on.
*/
public void install(RSyntaxTextArea textArea) {
if (this.textArea != null) {
@@ -203,12 +196,11 @@ class MarkOccurrencesSupport implements CaretListener, ActionListener {
setColor(textArea.getMarkOccurrencesColor());
}
}
/**
* Sets the color to use when marking occurrences.
*
* @param color
* The color to use.
* @param color The color to use.
* @see #getColor()
* @see #setPaintBorder(boolean)
*/
@@ -219,25 +211,23 @@ class MarkOccurrencesSupport implements CaretListener, ActionListener {
caretUpdate(null); // Force a highlight repaint.
}
}
/**
* Sets the delay between the last caret position change and when the
* text is scanned for matching identifiers. A delay is needed to prevent
* repeated scanning while the user is typing.
* Sets the delay between the last caret position change and when the text is
* scanned for matching identifiers. A delay is needed to prevent repeated
* scanning while the user is typing.
*
* @param delay
* The new delay.
* @param delay The new delay.
* @see #getDelay()
*/
public void setDelay(int delay) {
timer.setInitialDelay(delay);
}
/**
* Toggles whether a border is painted around marked highlights.
*
* @param paint
* Whether to paint a border.
* @param paint Whether to paint a border.
* @see #getPaintBorder()
* @see #setColor(Color)
*/
@@ -249,10 +239,10 @@ class MarkOccurrencesSupport implements CaretListener, ActionListener {
}
}
}
/**
* Uninstalls this listener from the current text area. Does nothing if
* it not currently installed on any text area.
* Uninstalls this listener from the current text area. Does nothing if it not
* currently installed on any text area.
*
* @see #install(RSyntaxTextArea)
*/
@@ -41,11 +41,11 @@ import org.fife.ui.rsyntaxtextarea.focusabletip.TipUtil;
* @version 1.0
*/
class MatchedBracketPopup extends JWindow {
private RSyntaxTextArea textArea;
private transient Listener listener;
private static final int LEFT_EMPTY_BORDER = 5;
MatchedBracketPopup(Window parent, RSyntaxTextArea textArea, int offsToRender) {
super(parent);
this.textArea = textArea;
@@ -59,7 +59,7 @@ class MatchedBracketPopup extends JWindow {
listener = new Listener();
setLocation();
}
/**
* Overridden to ensure this popup stays in a specific size range.
*/
@@ -71,7 +71,7 @@ class MatchedBracketPopup extends JWindow {
}
return size;
}
private String getText(int offsToRender) {
int line = 0;
try {
@@ -110,7 +110,7 @@ class MatchedBracketPopup extends JWindow {
}
return sb.toString();
}
/**
* Adds key bindings to this popup.
*/
@@ -121,10 +121,9 @@ class MatchedBracketPopup extends JWindow {
im.put(escapeKS, "onEscape");
am.put("onEscape", new EscapeAction());
}
/**
* Positions this popup to be in the top right-hand corner of the parent
* editor.
* Positions this popup to be in the top right-hand corner of the parent editor.
*/
private void setLocation() {
Point topLeft = textArea.getVisibleRect().getLocation();
@@ -132,23 +131,23 @@ class MatchedBracketPopup extends JWindow {
topLeft.y = Math.max(topLeft.y - 24, 0);
setLocation(topLeft.x - LEFT_EMPTY_BORDER, topLeft.y);
}
/**
* Action performed when Escape is pressed in this popup.
*/
private class EscapeAction extends AbstractAction {
@Override
public void actionPerformed(ActionEvent e) {
listener.uninstallAndHide();
}
}
/**
* Listens for events in this popup.
*/
private class Listener extends WindowAdapter implements ComponentListener {
Listener() {
addWindowFocusListener(this);
// If anything happens to the "parent" window, hide this popup
@@ -157,42 +156,42 @@ class MatchedBracketPopup extends JWindow {
parent.addWindowListener(this);
parent.addComponentListener(this);
}
@Override
public void componentResized(ComponentEvent e) {
uninstallAndHide();
}
@Override
public void componentMoved(ComponentEvent e) {
uninstallAndHide();
}
@Override
public void componentShown(ComponentEvent e) {
uninstallAndHide();
}
@Override
public void componentHidden(ComponentEvent e) {
uninstallAndHide();
}
@Override
public void windowActivated(WindowEvent e) {
checkForParentWindowEvent(e);
}
@Override
public void windowLostFocus(WindowEvent e) {
uninstallAndHide();
}
@Override
public void windowIconified(WindowEvent e) {
checkForParentWindowEvent(e);
}
private boolean checkForParentWindowEvent(WindowEvent e) {
if (e.getSource() == getParent()) {
uninstallAndHide();
@@ -200,7 +199,7 @@ class MatchedBracketPopup extends JWindow {
}
return false;
}
private void uninstallAndHide() {
Window parent = (Window) getParent();
parent.removeWindowFocusListener(this);
@@ -10,52 +10,44 @@ import org.fife.ui.rtextarea.SmartHighlightPainter;
/**
* An <code>OccurrenceMarker</code> is called when the caret stops moving after
* a short period. If the current {@link TokenMaker} returns an instance of
* this class, it is told to mark all occurrences of the identifier at the
* caret position.
* a short period. If the current {@link TokenMaker} returns an instance of this
* class, it is told to mark all occurrences of the identifier at the caret
* position.
*
* @author Robert Futrell
* @version 1.0
*/
public interface OccurrenceMarker {
/**
* Returns the token to mark occurrences, of, provided it matches the
* criteria put forth by {@link #isValidType(RSyntaxTextArea, Token)}.
* For most languages, this method should return the token at the caret
* position.
* Returns the token to mark occurrences, of, provided it matches the criteria
* put forth by {@link #isValidType(RSyntaxTextArea, Token)}. For most
* languages, this method should return the token at the caret position.
*
* @param textArea
* The text area.
* @return The token to (possibly) mark occurrences of, or
* <code>null</code> if none.
* @param textArea The text area.
* @return The token to (possibly) mark occurrences of, or <code>null</code> if
* none.
*/
Token getTokenToMark(RSyntaxTextArea textArea);
/**
* Returns whether the specified token is a type that we can do a
* "mark occurrences" of. Typically, this will delegate to
* Returns whether the specified token is a type that we can do a "mark
* occurrences" of. Typically, this will delegate to
* {@link RSyntaxTextArea#getMarkOccurrencesOfTokenType(int)}.
*
* @param textArea
* The text area.
* @param t
* The token.
* @param textArea The text area.
* @param t The token.
* @return Whether we should mark all occurrences of this token.
*/
boolean isValidType(RSyntaxTextArea textArea, Token t);
/**
* Called when occurrences of a token should be marked.
*
* @param doc
* The document.
* @param t
* The document whose relevant occurrences should be marked.
* @param h
* The highlighter to add the highlights to.
* @param p
* The painter for the highlights.
* @param doc The document.
* @param t The document whose relevant occurrences should be marked.
* @param h The highlighter to add the highlights to.
* @param p The painter for the highlights.
*/
void markOccurrences(RSyntaxDocument doc, Token t, RSyntaxTextAreaHighlighter h, SmartHighlightPainter p);
}
+116 -153
View File
@@ -46,7 +46,7 @@ import org.fife.ui.rtextarea.RTextAreaHighlighter.HighlightInfo;
* @version 0.9
*/
class ParserManager implements DocumentListener, ActionListener, HyperlinkListener, PropertyChangeListener {
private RSyntaxTextArea textArea;
private List<Parser> parsers;
private Timer timer;
@@ -55,20 +55,21 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
private Position firstOffsetModded;
private Position lastOffsetModded;
/**
* Mapping of notices to their highlights in the editor. Can't use a Map
* since parsers could return two <code>ParserNotice</code>s that compare
* equally via <code>equals()</code>. Real-world example: The Perl
* compiler will return 2+ identical error messages if the same error is
* committed in a single line more than once.
* Mapping of notices to their highlights in the editor. Can't use a Map since
* parsers could return two <code>ParserNotice</code>s that compare equally via
* <code>equals()</code>. Real-world example: The Perl compiler will return 2+
* identical error messages if the same error is committed in a single line more
* than once.
*/
private List<NoticeHighlightPair> noticeHighlightPairs;
/**
* Painter used to underline errors.
*/
private SquiggleUnderlineHighlightPainter parserErrorHighlightPainter = new SquiggleUnderlineHighlightPainter(Color.RED);
private SquiggleUnderlineHighlightPainter parserErrorHighlightPainter = new SquiggleUnderlineHighlightPainter(
Color.RED);
/**
* If this system property is set to <code>true</code>, debug messages
* will be printed to stdout to help diagnose parsing issues.
* If this system property is set to <code>true</code>, debug messages will be
* printed to stdout to help diagnose parsing issues.
*/
private static final String PROPERTY_DEBUG_PARSING = "rsta.debugParsing";
/**
@@ -76,31 +77,26 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
*/
private static final boolean DEBUG_PARSING;
/**
* The default delay between the last key press and when the document
* is parsed, in milliseconds.
* The default delay between the last key press and when the document is parsed,
* in milliseconds.
*/
private static final int DEFAULT_DELAY_MS = 1250;
/**
* Constructor.
*
* @param textArea
* The text area whose document the parser will be
* parsing.
* @param textArea The text area whose document the parser will be parsing.
*/
ParserManager(RSyntaxTextArea textArea) {
this(DEFAULT_DELAY_MS, textArea);
}
/**
* Constructor.
*
* @param delay
* The delay between the last key press and when the document
* is parsed.
* @param textArea
* The text area whose document the parser will be
* parsing.
* @param delay The delay between the last key press and when the document is
* parsed.
* @param textArea The text area whose document the parser will be parsing.
*/
ParserManager(int delay, RSyntaxTextArea textArea) {
this.textArea = textArea;
@@ -111,12 +107,11 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
timer.setRepeats(false);
running = true;
}
/**
* Called when the timer fires (e.g. it's time to parse the document).
*
* @param e
* The event.
* @param e The event.
*/
@Override
public void actionPerformed(ActionEvent e) {
@@ -132,7 +127,8 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
RSyntaxDocument doc = (RSyntaxDocument) textArea.getDocument();
Element root = doc.getDefaultRootElement();
int firstLine = firstOffsetModded == null ? 0 : root.getElementIndex(firstOffsetModded.getOffset());
int lastLine = lastOffsetModded == null ? root.getElementCount() - 1 : root.getElementIndex(lastOffsetModded.getOffset());
int lastLine = lastOffsetModded == null ? root.getElementCount() - 1
: root.getElementIndex(lastOffsetModded.getOffset());
firstOffsetModded = lastOffsetModded = null;
if (DEBUG_PARSING) {
System.out.println("[DEBUG]: Minimum lines to parse: " + firstLine + "-" + lastLine);
@@ -158,13 +154,11 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
System.out.println("Total parsing time: " + time + " seconds");
}
}
/**
* Adds a parser for the text area.
*
* @param parser
* The new parser. If this is <code>null</code>, nothing
* happens.
* @param parser The new parser. If this is <code>null</code>, nothing happens.
* @see #getParser(int)
* @see #removeParser(Parser)
*/
@@ -183,13 +177,12 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
}
}
}
/**
* Adds highlights for a list of parser notices. Any current notices
* from the same Parser, in the same parsed range, are removed.
* Adds highlights for a list of parser notices. Any current notices from the
* same Parser, in the same parsed range, are removed.
*
* @param res
* The result of a parsing.
* @param res The result of a parsing.
* @see #clearParserNoticeHighlights()
*/
private void addParserNoticeHighlights(ParseResult res) {
@@ -227,16 +220,16 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
System.out.println("[DEBUG]: Done adding parser notices from " + res.getParser());
}
}
/**
* Called when the document is modified.
*
* @param e
* The document event.
* @param e The document event.
*/
@Override
public void changedUpdate(DocumentEvent e) {}
public void changedUpdate(DocumentEvent e) {
}
private void clearParserNoticeHighlights() {
RSyntaxTextAreaHighlighter h = (RSyntaxTextAreaHighlighter) textArea.getHighlighter();
if (h != null) {
@@ -246,12 +239,11 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
noticeHighlightPairs.clear();
}
}
/**
* Removes all parser notice highlights for a specific parser.
*
* @param parser
* The parser whose highlights to remove.
* @param parser The parser whose highlights to remove.
*/
private void clearParserNoticeHighlights(Parser parser) {
RSyntaxTextAreaHighlighter h = (RSyntaxTextAreaHighlighter) textArea.getHighlighter();
@@ -268,7 +260,7 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
}
}
}
/**
* Removes all parsers and any highlights they have created.
*
@@ -280,20 +272,18 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
parsers.clear();
textArea.fireParserNoticesChange();
}
/**
* Forces the given {@link Parser} to re-parse the content of this text
* area.
* Forces the given {@link Parser} to re-parse the content of this text area.
* <p>
*
* This method can be useful when a <code>Parser</code> can be configured
* as to what notices it returns. For example, if a Java language parser
* can be configured to set whether no serialVersionUID is a warning,
* error, or ignored, this method can be called after changing the expected
* notice type to have the document re-parsed.
* This method can be useful when a <code>Parser</code> can be configured as to
* what notices it returns. For example, if a Java language parser can be
* configured to set whether no serialVersionUID is a warning, error, or
* ignored, this method can be called after changing the expected notice type to
* have the document re-parsed.
*
* @param parser
* The index of the <code>Parser</code> to re-run.
* @param parser The index of the <code>Parser</code> to re-run.
* @see #getParser(int)
*/
public void forceReparsing(int parser) {
@@ -313,10 +303,10 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
doc.readUnlock();
}
}
/**
* Returns the delay between the last "concurrent" edit and when the
* document is re-parsed.
* Returns the delay between the last "concurrent" edit and when the document is
* re-parsed.
*
* @return The delay, in milliseconds.
* @see #setDelay(int)
@@ -324,12 +314,11 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
public int getDelay() {
return timer.getDelay();
}
/**
* Returns the specified parser.
*
* @param index
* The index of the parser.
* @param index The index of the parser.
* @return The parser.
* @see #getParserCount()
* @see #addParser(Parser)
@@ -338,7 +327,7 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
public Parser getParser(int index) {
return parsers.get(index);
}
/**
* Returns the number of registered parsers.
*
@@ -347,14 +336,12 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
public int getParserCount() {
return parsers.size();
}
/**
* Returns a list of the current parser notices for this text area.
* This method (like most Swing methods) should only be called on the
* EDT.
* Returns a list of the current parser notices for this text area. This method
* (like most Swing methods) should only be called on the EDT.
*
* @return The list of notices. This will be an empty list if there are
* none.
* @return The list of notices. This will be an empty list if there are none.
*/
public List<ParserNotice> getParserNotices() {
List<ParserNotice> notices = new ArrayList<ParserNotice>();
@@ -365,15 +352,13 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
}
return notices;
}
/**
* Returns the tool tip to display for a mouse event at the given
* location. This method is overridden to give a registered parser a
* chance to display a tool tip (such as an error description when the
* mouse is over an error highlight).
* Returns the tool tip to display for a mouse event at the given location. This
* method is overridden to give a registered parser a chance to display a tool
* tip (such as an error description when the mouse is over an error highlight).
*
* @param e
* The mouse event.
* @param e The mouse event.
* @return The tool tip to display, and possibly a hyperlink event handler.
*/
public ToolTipInfo getToolTipText(MouseEvent e) {
@@ -385,19 +370,12 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
int pos = textArea.viewToModel(p);
/*
* Highlighter.Highlight[] highlights = textArea.getHighlighter().
* getHighlights();
* for (int i=0; i<highlights.length; i++) {
* Highlighter.Highlight h = highlights[i];
* //if (h instanceof ParserNoticeHighlight) {
* // ParserNoticeHighlight pnh = (ParserNoticeHighlight)h;
* int start = h.getStartOffset();
* int end = h.getEndOffset();
* if (start<=pos && end>=pos) {
* //return pnh.getMessage();
* return textArea.getText(start, end-start);
* }
* //}
* }
* getHighlights(); for (int i=0; i<highlights.length; i++) {
* Highlighter.Highlight h = highlights[i]; //if (h instanceof
* ParserNoticeHighlight) { // ParserNoticeHighlight pnh =
* (ParserNoticeHighlight)h; int start = h.getStartOffset(); int end =
* h.getEndOffset(); if (start<=pos && end>=pos) { //return pnh.getMessage();
* return textArea.getText(start, end-start); } //} }
*/
if (noticeHighlightPairs != null) {
for (NoticeHighlightPair pair : noticeHighlightPairs) {
@@ -418,25 +396,23 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
URL imageBase = parserForTip == null ? null : parserForTip.getImageBase();
return new ToolTipInfo(tip, listener, imageBase);
}
/**
* Called when the document is modified.
*
* @param e
* The document event.
* @param e The document event.
*/
public void handleDocumentEvent(DocumentEvent e) {
if (running && parsers.size() > 0) {
timer.restart();
}
}
/**
* Called when the user clicks a hyperlink in a
* {@link org.fife.ui.rsyntaxtextarea.focusabletip.FocusableTip}.
*
* @param e
* The event.
* @param e The event.
*/
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
@@ -444,12 +420,11 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
parserForTip.getHyperlinkListener().linkClicked(textArea, e);
}
}
/**
* Called when the document is modified.
*
* @param e
* The document event.
* @param e The document event.
*/
@Override
public void insertUpdate(DocumentEvent e) {
@@ -469,14 +444,12 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
}
handleDocumentEvent(e);
}
/**
* Returns whether a parser notice contains the specified offset.
*
* @param notice
* The notice.
* @param offs
* The offset.
* @param notice The notice.
* @param offs The offset.
* @return Whether the notice contains the offset.
*/
private boolean noticeContainsPosition(ParserNotice notice, int offs) {
@@ -492,20 +465,18 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
Element elem = root.getElement(line);
return elem != null && offs >= elem.getStartOffset() && offs < elem.getEndOffset();
}
/**
* Since <code>viewToModel()</code> returns the <em>closest</em> model
* position, and the position doesn't <em>necessarily</em> contain the
* point passed in as an argument, this method checks whether the point is
* indeed contained in the view rectangle for the specified offset.
* Since <code>viewToModel()</code> returns the <em>closest</em> model position,
* and the position doesn't <em>necessarily</em> contain the point passed in as
* an argument, this method checks whether the point is indeed contained in the
* view rectangle for the specified offset.
*
* @param notice
* The parser notice.
* @param p
* The point possibly contained in the view range of the
* parser notice.
* @return Whether the parser notice actually contains the specified point
* in the view.
* @param notice The parser notice.
* @param p The point possibly contained in the view range of the parser
* notice.
* @return Whether the parser notice actually contains the specified point in
* the view.
*/
private boolean noticeContainsPointInView(ParserNotice notice, Point p) {
try {
@@ -543,12 +514,11 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
return true;
}
}
/**
* Called when a property we're interested in changes.
*
* @param e
* The property change event.
* @param e The property change event.
*/
@Override
public void propertyChange(PropertyChangeEvent e) {
@@ -565,12 +535,11 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
}
}
}
/**
* Removes a parser.
*
* @param parser
* The parser to remove.
* @param parser The parser to remove.
* @return Whether the parser was found.
* @see #addParser(Parser)
* @see #getParser(int)
@@ -583,13 +552,12 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
}
return removed;
}
/**
* Removes all parser notices (and clears highlights in the editor) from
* a particular parser.
* Removes all parser notices (and clears highlights in the editor) from a
* particular parser.
*
* @param parser
* The parser.
* @param parser The parser.
*/
private void removeParserNotices(Parser parser) {
if (noticeHighlightPairs != null) {
@@ -603,14 +571,13 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
}
}
}
/**
* Removes any currently stored notices (and the corresponding highlights
* from the editor) from the same Parser, and in the given line range,
* as in the results.
* Removes any currently stored notices (and the corresponding highlights from
* the editor) from the same Parser, and in the given line range, as in the
* results.
*
* @param res
* The results.
* @param res The results.
*/
private void removeParserNotices(ParseResult res) {
if (noticeHighlightPairs != null) {
@@ -632,12 +599,11 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
}
}
}
/**
* Called when the document is modified.
*
* @param e
* The document event.
* @param e The document event.
*/
@Override
public void removeUpdate(DocumentEvent e) {
@@ -658,7 +624,7 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
}
handleDocumentEvent(e);
}
/**
* Restarts parsing the document.
*
@@ -668,14 +634,13 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
timer.restart();
running = true;
}
/**
* Sets the delay between the last "concurrent" edit and when the document
* is re-parsed.
* Sets the delay between the last "concurrent" edit and when the document is
* re-parsed.
*
* @param millis
* The new delay, in milliseconds. This must be greater
* than <code>0</code>.
* @param millis The new delay, in milliseconds. This must be greater than
* <code>0</code>.
* @see #getDelay()
*/
public void setDelay(int millis) {
@@ -688,20 +653,18 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
timer.start();
}
}
/**
* Returns whether a parser notice should be removed, based on a parse
* result.
* Returns whether a parser notice should be removed, based on a parse result.
*
* @param notice
* The notice in question.
* @param res
* The result.
* @param notice The notice in question.
* @param res The result.
* @return Whether the notice should be removed.
*/
private boolean shouldRemoveNotice(ParserNotice notice, ParseResult res) {
if (DEBUG_PARSING) {
System.out.println("[DEBUG]: ... ... shouldRemoveNotice " + notice + ": " + (notice.getParser() == res.getParser()));
System.out.println(
"[DEBUG]: ... ... shouldRemoveNotice " + notice + ": " + (notice.getParser() == res.getParser()));
}
// NOTE: We must currently remove all notices for the parser. Parser
// implementors are required to parse the entire document each parsing
@@ -712,7 +675,7 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
// return same_parser && (in_reparsed_range || in_deleted_end_of_doc)
return notice.getParser() == res.getParser();
}
/**
* Stops parsing the document.
*
@@ -722,21 +685,21 @@ class ParserManager implements DocumentListener, ActionListener, HyperlinkListen
timer.stop();
running = false;
}
/**
* Mapping of a parser notice to its highlight in the editor.
*/
private static class NoticeHighlightPair {
private ParserNotice notice;
private HighlightInfo highlight;
NoticeHighlightPair(ParserNotice notice, HighlightInfo highlight) {
this.notice = notice;
this.highlight = highlight;
}
}
static {
boolean debugParsing = false;
try {
@@ -12,48 +12,45 @@ import javax.swing.JWindow;
/**
* A hook allowing hosting applications to decorate JWindows created by the
* AutoComplete library. For example, you could use the
* <a href="http://jgoodies.com/">JGoodies</a> library to add drop shadows
* to the windows.
* <a href="http://jgoodies.com/">JGoodies</a> library to add drop shadows to
* the windows.
*
* @author Robert Futrell
* @version 1.0
*/
public abstract class PopupWindowDecorator {
/**
* The singleton instance of this class.
*/
private static PopupWindowDecorator decorator;
/**
* Callback called whenever an appropriate JWindow is created by the
* AutoComplete library. Implementations can decorate the window however
* they see fit.
* AutoComplete library. Implementations can decorate the window however they
* see fit.
*
* @param window
* The newly-created window.
* @param window The newly-created window.
*/
public abstract void decorate(JWindow window);
/**
* Returns the singleton instance of this class. This should only be
* called on the EDT.
* Returns the singleton instance of this class. This should only be called on
* the EDT.
*
* @return The singleton instance of this class, or <code>null</code>
* for none.
* @return The singleton instance of this class, or <code>null</code> for none.
* @see #set(PopupWindowDecorator)
*/
public static PopupWindowDecorator get() {
return decorator;
}
/**
* Sets the singleton instance of this class. This should only be called
* on the EDT.
* Sets the singleton instance of this class. This should only be called on the
* EDT.
*
* @param decorator
* The new instance of this class. This may be
* <code>null</code>.
* @param decorator The new instance of this class. This may be
* <code>null</code>.
* @see #get()
*/
public static void set(PopupWindowDecorator decorator) {
+20 -28
View File
@@ -17,46 +17,38 @@ import javax.swing.text.BadLocationException;
* @version 1.0
*/
interface RSTAView {
/**
* Returns the y-coordinate of the specified line.
* <p>
*
* This method is quicker than using traditional
* <code>modelToView(int)</code> calls, as the entire bounding box isn't
* computed.
* This method is quicker than using traditional <code>modelToView(int)</code>
* calls, as the entire bounding box isn't computed.
*
* @param alloc
* The area the text area can render into.
* @param line
* The line number.
* @return The y-coordinate of the top of the line, or <code>-1</code> if
* this text area doesn't yet have a positive size or the line is
* hidden (i.e. from folding).
* @throws BadLocationException
* If <code>line</code> isn't a valid line
* number for this document.
* @param alloc The area the text area can render into.
* @param line The line number.
* @return The y-coordinate of the top of the line, or <code>-1</code> if this
* text area doesn't yet have a positive size or the line is hidden
* (i.e. from folding).
* @throws BadLocationException If <code>line</code> isn't a valid line number
* for this document.
*/
int yForLine(Rectangle alloc, int line) throws BadLocationException;
/**
* Returns the y-coordinate of the line containing a specified offset.
* <p>
*
* This method is quicker than using traditional
* <code>modelToView(int)</code> calls, as the entire bounding box isn't
* computed.
* This method is quicker than using traditional <code>modelToView(int)</code>
* calls, as the entire bounding box isn't computed.
*
* @param alloc
* The area the text area can render into.
* @param offs
* The offset info the document.
* @return The y-coordinate of the top of the offset, or <code>-1</code> if
* this text area doesn't yet have a positive size or the line is
* hidden (i.e. from folding).
* @throws BadLocationException
* If <code>offs</code> isn't a valid offset
* into the document.
* @param alloc The area the text area can render into.
* @param offs The offset info the document.
* @return The y-coordinate of the top of the offset, or <code>-1</code> if this
* text area doesn't yet have a positive size or the line is hidden
* (i.e. from folding).
* @throws BadLocationException If <code>offs</code> isn't a valid offset into
* the document.
*/
int yForLineContaining(Rectangle alloc, int offs) throws BadLocationException;
}
@@ -49,10 +49,9 @@ import me.ByteEdit.edit.JavaAssemblyTokenMaker;
* @version 1.0
*/
public class RSyntaxDocument extends RDocument implements Iterable<Token>, SyntaxConstants {
/**
* Creates a {@link TokenMaker} appropriate for a given programming
* language.
* Creates a {@link TokenMaker} appropriate for a given programming language.
*/
private transient TokenMakerFactory tokenMakerFactory;
/**
@@ -64,8 +63,7 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
*/
private String syntaxStyle;
/**
* Array of values representing the "last token type" on each line. This is
* used
* Array of values representing the "last token type" on each line. This is used
* in cases such as multi-line comments: if the previous line ended with an
* (unclosed) multi-line comment, we can use this knowledge and start the
* current line's syntax highlighting in multi-line comment state.
@@ -77,35 +75,28 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
private transient int tokenRetrievalCount = 0;
private transient Segment s;
/**
* If this is set to <code>true</code>, debug information about how much
* token
* If this is set to <code>true</code>, debug information about how much token
* caching is helping is printed to stdout.
*/
private static final boolean DEBUG_TOKEN_CACHING = false;
/**
* Constructs a plain text document. A default root element is created, and
* the
* Constructs a plain text document. A default root element is created, and the
* tab size set to 5.
*
* @param syntaxStyle
* The syntax highlighting scheme to use.
* @param syntaxStyle The syntax highlighting scheme to use.
*/
public RSyntaxDocument(String syntaxStyle) {
this(null, syntaxStyle);
}
/**
* Constructs a plain text document. A default root element is created, and
* the
* Constructs a plain text document. A default root element is created, and the
* tab size set to 5.
*
* @param tmf
* The <code>TokenMakerFactory</code> for this document. If this
* is
* <code>null</code>, a default factory is used.
* @param syntaxStyle
* The syntax highlighting scheme to use.
* @param tmf The <code>TokenMakerFactory</code> for this document. If
* this is <code>null</code>, a default factory is used.
* @param syntaxStyle The syntax highlighting scheme to use.
*/
public RSyntaxDocument(TokenMakerFactory tmf, String syntaxStyle) {
putProperty(tabSizeAttribute, Integer.valueOf(5));
@@ -115,27 +106,23 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
setTokenMakerFactory(tmf);
setSyntaxStyle(syntaxStyle);
}
/**
* Alerts all listeners to this document of an insertion. This is overridden
* so
* Alerts all listeners to this document of an insertion. This is overridden so
* we can update our syntax highlighting stuff.
* <p>
* The syntax highlighting stuff has to be here instead of in
* <code>insertUpdate</code> because <code>insertUpdate</code> is not called
* by
* <code>insertUpdate</code> because <code>insertUpdate</code> is not called by
* the undo/redo actions, but this method is.
*
* @param e
* The change.
* @param e The change.
*/
@Override
protected void fireInsertUpdate(DocumentEvent e) {
cachedTokenList = null;
/*
* Now that the text is actually inserted into the content and element
* structure, we can update our token elements and
* "last tokens on lines"
* structure, we can update our token elements and "last tokens on lines"
* structure.
*/
Element lineMap = getDefaultRootElement();
@@ -174,23 +161,20 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
// Let all listeners know about the insertion.
super.fireInsertUpdate(e);
}
/**
* This method is called AFTER the content has been inserted into the
* document
* This method is called AFTER the content has been inserted into the document
* and the element structure has been updated.
* <p>
* The syntax-highlighting updates need to be done here (as opposed to an
* override of <code>postRemoveUpdate</code>) as this method is called in
* response to undo/redo events, whereas <code>postRemoveUpdate</code> is
* not.
* response to undo/redo events, whereas <code>postRemoveUpdate</code> is not.
* <p>
* Now that the text is actually inserted into the content and element
* structure, we can update our token elements and "last tokens on lines"
* structure.
*
* @param chng
* The change that occurred.
* @param chng The change that occurred.
* @see #removeUpdate
*/
@Override
@@ -240,26 +224,22 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
// Let all of our listeners know about the removal.
super.fireRemoveUpdate(chng);
}
/**
* Returns the closest {@link TokenTypes "standard" token type} for a given
* "internal" token type (e.g. one whose value is <code>&lt; 0</code>).
*
* @param type
* The token type.
* @return The closest "standard" token type. If a mapping is not defined
* for
* @param type The token type.
* @return The closest "standard" token type. If a mapping is not defined for
* this language, then <code>type</code> is returned.
*/
public int getClosestStandardTokenTypeForInternalType(int type) {
return tokenMaker.getClosestStandardTokenTypeForInternalType(type);
}
/**
* Returns whether closing markup tags should be automatically completed.
* This
* method only returns <code>true</code> if {@link #getLanguageIsMarkup()}
* also
* Returns whether closing markup tags should be automatically completed. This
* method only returns <code>true</code> if {@link #getLanguageIsMarkup()} also
* returns <code>true</code>.
*
* @return Whether markup closing tags should be automatically completed.
@@ -269,26 +249,24 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
// TODO: Remove terrible dependency on AbstractMarkupTokenMaker
return getLanguageIsMarkup() && ((AbstractMarkupTokenMaker) tokenMaker).getCompleteCloseTags();
}
/**
* Returns whether the current programming language uses curly braces
* ('<code>{</code>' and '<code>}</code>') to denote code blocks.
*
* @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.
*/
public boolean getCurlyBracesDenoteCodeBlocks(int languageIndex) {
return tokenMaker.getCurlyBracesDenoteCodeBlocks(languageIndex);
}
/**
* Returns whether the current language is a markup language, such as HTML,
* XML
* Returns whether the current language is a markup language, such as HTML, XML
* or PHP.
*
* @return Whether the current language is a markup language.
@@ -296,50 +274,42 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
public boolean getLanguageIsMarkup() {
return tokenMaker.isMarkupLanguage();
}
/**
* Returns the token type of the last token on the given line.
*
* @param line
* The line to inspect.
* @return The token type of the last token on the specified line. If the
* line
* @param line The line to inspect.
* @return The token type of the last token on the specified line. If the line
* is invalid, an exception is thrown.
*/
public int getLastTokenTypeOnLine(int line) {
return lastTokensOnLines.get(line);
}
/**
* Returns the text to place at the beginning and end of a line to "comment"
* it
* Returns the text to place at the beginning and end of a line to "comment" it
* in this programming language.
*
* @return The start and end strings to add to a line to "comment" it out. A
* <code>null</code> value for either means there is no string to
* add
* for that part. A value of <code>null</code> for the array means
* this
* <code>null</code> value for either means there is no string to add
* for that part. A value of <code>null</code> for the array means this
* language does not support commenting/uncommenting lines.
*/
public String[] getLineCommentStartAndEnd(int languageIndex) {
return tokenMaker.getLineCommentStartAndEnd(languageIndex);
}
/**
* Returns whether tokens of the specified type should have "mark
* occurrences"
* Returns whether tokens of the specified type should have "mark occurrences"
* enabled for the current programming language.
*
* @param type
* The token type.
* @return Whether tokens of this type should have "mark occurrences"
* enabled.
* @param type The token type.
* @return Whether tokens of this type should have "mark occurrences" enabled.
*/
boolean getMarkOccurrencesOfTokenType(int type) {
return tokenMaker.getMarkOccurrencesOfTokenType(type);
}
/**
* Returns the occurrence marker for the current language.
*
@@ -348,13 +318,12 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
OccurrenceMarker getOccurrenceMarker() {
return tokenMaker.getOccurrenceMarker();
}
/**
* This method returns whether auto indentation should be done if Enter is
* pressed at the end of the specified line.
*
* @param line
* The line to check.
* @param line The line to check.
* @return Whether an extra indentation should be done.
*/
public boolean getShouldIndentNextLine(int line) {
@@ -362,7 +331,7 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
t = t.getLastNonCommentNonWhitespaceToken();
return tokenMaker.getShouldIndentNextLineAfter(t);
}
/**
* Returns the syntax style being used.
*
@@ -372,16 +341,14 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
public String getSyntaxStyle() {
return syntaxStyle;
}
/**
* Returns a token list for the specified segment of text representing the
* specified line number. This method is basically a wrapper for
* <code>tokenMaker.getTokenList</code> that takes into account the last
* token
* <code>tokenMaker.getTokenList</code> that takes into account the last token
* on the previous line to assure token accuracy.
*
* @param line
* The line number of <code>text</code> in the document, &gt;= 0.
* @param line The line number of <code>text</code> in the document, &gt;= 0.
* @return A token list representing the specified line.
*/
public final Token getTokenListForLine(int line) {
@@ -412,7 +379,7 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
cachedTokenList = tokenMaker.getTokenList(s, initialTokenType, startOffset);
return cachedTokenList;
}
boolean insertBreakSpecialHandling(ActionEvent e) {
Action a = tokenMaker.getInsertBreakAction();
if (a != null) {
@@ -421,28 +388,23 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
}
return false;
}
/**
* Returns whether a character could be part of an "identifier" token in a
* specific language. This is used to identify such things as the bounds of
* the
* specific language. This is used to identify such things as the bounds of the
* "word" to select on double-clicking.
*
* @param languageIndex
* The language index the character was found in.
* @param ch
* The character.
* @param languageIndex The language index the character was found in.
* @param ch The character.
* @return Whether the character could be part of an "identifier" token.
*/
public boolean isIdentifierChar(int languageIndex, char ch) {
return tokenMaker.isIdentifierChar(languageIndex, ch);
}
/**
* Returns an iterator over the paintable tokens in this document. Results
* are
* undefined if this document is modified while the iterator is being
* iterated
* Returns an iterator over the paintable tokens in this document. Results are
* undefined if this document is modified while the iterator is being iterated
* through, so this should only be used on the EDT.
* <p>
*
@@ -455,12 +417,11 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
public Iterator<Token> iterator() {
return new TokenIterator(this);
}
/**
* Deserializes a document.
*
* @param in
* The stream to read from.
* @param in The stream to read from.
* @throws ClassNotFoundException
* @throws IOException
*/
@@ -476,16 +437,13 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
lastTokensOnLines = new DynamicIntArray(lineCount);
setSyntaxStyle(syntaxStyle); // Actually install (transient) TokenMaker
}
/**
* Makes our private <code>Segment s</code> point to the text in our
* document
* referenced by the specified element. Note that <code>line</code> MUST be
* a
* Makes our private <code>Segment s</code> point to the text in our document
* referenced by the specified element. Note that <code>line</code> MUST be a
* valid line number in the document.
*
* @param line
* The line number you want to get.
* @param line The line number you want to get.
*/
private void setSharedSegment(int line) {
Element map = getDefaultRootElement();
@@ -504,20 +462,17 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
throw new InternalError("Text range not in document: " + startOffset + "-" + endOffset);
}
}
/**
* Sets the syntax style being used for syntax highlighting in this
* document.
* Sets the syntax style being used for syntax highlighting in this document.
* What styles are supported by a document is determined by its
* {@link TokenMakerFactory}. By default, all <code>RSyntaxDocument</code>s
* support all languages built into <code>RSyntaxTextArea</code>.
*
* @param styleKey
* The new style to use, such as
* {@link SyntaxConstants#SYNTAX_STYLE_JAVA}. If this style is
* not
* known or supported by this document, then
* {@link SyntaxConstants#SYNTAX_STYLE_NONE} is used.
* @param styleKey The new style to use, such as
* {@link SyntaxConstants#SYNTAX_STYLE_JAVA}. If this style is
* not known or supported by this document, then
* {@link SyntaxConstants#SYNTAX_STYLE_NONE} is used.
* @see #setSyntaxStyle(TokenMaker)
* @see #getSyntaxStyle()
*/
@@ -530,15 +485,13 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
updateSyntaxHighlightingInformation();
this.syntaxStyle = styleKey;
}
/**
* Sets the syntax style being used for syntax highlighting in this
* document.
* Sets the syntax style being used for syntax highlighting in this document.
* You should call this method if you've created a custom token maker for a
* language not normally supported by <code>RSyntaxTextArea</code>.
*
* @param tokenMaker
* The new token maker to use.
* @param tokenMaker The new token maker to use.
* @see #setSyntaxStyle(String)
*/
public void setSyntaxStyle(TokenMaker tokenMaker) {
@@ -546,35 +499,28 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
updateSyntaxHighlightingInformation();
this.syntaxStyle = "text/unknown"; // TODO: Make me public?
}
/**
* Sets the token maker factory used by this document.
*
* @param tmf
* The <code>TokenMakerFactory</code> for this document. If this
* is
* @param tmf The <code>TokenMakerFactory</code> for this document. If this is
* <code>null</code>, a default factory is used.
*/
public void setTokenMakerFactory(TokenMakerFactory tmf) {
tokenMakerFactory = tmf != null ? tmf : TokenMakerFactory.getDefaultInstance();
}
/**
* Loops through the last-tokens-on-lines array from a specified point
* onward,
* updating last-token values until they stop changing. This should be
* called
* when lines are updated/inserted/removed, as doing so may cause lines
* below to
* Loops through the last-tokens-on-lines array from a specified point onward,
* updating last-token values until they stop changing. This should be called
* when lines are updated/inserted/removed, as doing so may cause lines below to
* change color.
*
* @param line
* The first line to check for a change in last-token value.
* @param numLines
* The number of lines in the document.
* @param previousTokenType
* The last-token value of the line just before
* <code>line</code>.
* @param line The first line to check for a change in last-token
* value.
* @param numLines The number of lines in the document.
* @param previousTokenType The last-token value of the line just before
* <code>line</code>.
* @return The last line that needs repainting.
*/
private int updateLastTokensBelow(int line, int numLines, int previousTokenType) {
@@ -627,7 +573,7 @@ public class RSyntaxDocument extends RDocument implements Iterable<Token>, Synta
}
return line;
}
/**
* Updates internal state information; e.g. the "last tokens on lines" data.
* After this, a changed update is fired to let listeners know that the
File diff suppressed because it is too large. Load diff
@@ -27,8 +27,8 @@ import org.fife.ui.rtextarea.SmartHighlightPainter;
/**
* The highlighter implementation used by {@link RSyntaxTextArea}s. It knows to
* always paint "marked occurrences" highlights below selection highlights,
* and squiggle underline highlights above all other highlights.
* always paint "marked occurrences" highlights below selection highlights, and
* squiggle underline highlights above all other highlights.
* <p>
*
* Most of this code is copied from javax.swing.text.DefaultHighlighter;
@@ -38,22 +38,22 @@ import org.fife.ui.rtextarea.SmartHighlightPainter;
* @version 1.0
*/
public class RSyntaxTextAreaHighlighter extends RTextAreaHighlighter {
/**
* Marked occurrences in the document (to be painted separately from
* other highlights).
* Marked occurrences in the document (to be painted separately from other
* highlights).
*/
private List<SyntaxLayeredHighlightInfoImpl> markedOccurrences;
/**
* Highlights from document parsers. These should be painted "on top of"
* all other highlights to ensure they are always above the selection.
* Highlights from document parsers. These should be painted "on top of" all
* other highlights to ensure they are always above the selection.
*/
private List<SyntaxLayeredHighlightInfoImpl> parserHighlights;
/**
* The default color used for parser notices when none is specified.
*/
private static final Color DEFAULT_PARSER_NOTICE_COLOR = Color.RED;
/**
* Constructor.
*/
@@ -62,7 +62,7 @@ public class RSyntaxTextAreaHighlighter extends RTextAreaHighlighter {
parserHighlights = new ArrayList<SyntaxLayeredHighlightInfoImpl>(0); // Often
// unused
}
/**
* Adds a special "marked occurrence" highlight.
*
@@ -88,12 +88,11 @@ public class RSyntaxTextAreaHighlighter extends RTextAreaHighlighter {
mapper.damageRange(textArea, start, end);
return i;
}
/**
* Adds a highlight from a parser.
*
* @param notice
* The notice from a {@link Parser}.
* @param notice The notice from a {@link Parser}.
* @return A tag with which to reference the highlight.
* @throws BadLocationException
* @see #clearParserHighlights()
@@ -128,7 +127,7 @@ public class RSyntaxTextAreaHighlighter extends RTextAreaHighlighter {
mapper.damageRange(textArea, start, end);
return i;
}
/**
* Removes all "marked occurrences" highlights from the view.
*
@@ -142,7 +141,7 @@ public class RSyntaxTextAreaHighlighter extends RTextAreaHighlighter {
}
markedOccurrences.clear();
}
/**
* Removes all parser highlights.
*
@@ -157,12 +156,11 @@ public class RSyntaxTextAreaHighlighter extends RTextAreaHighlighter {
}
parserHighlights.clear();
}
/**
* Removes all of the highlights for a specific parser.
*
* @param parser
* The parser.
* @param parser The parser.
*/
public void clearParserHighlights(Parser parser) {
Iterator<SyntaxLayeredHighlightInfoImpl> i = parserHighlights.iterator();
@@ -176,7 +174,7 @@ public class RSyntaxTextAreaHighlighter extends RTextAreaHighlighter {
}
}
}
/**
* {@inheritDoc}
*/
@@ -186,10 +184,10 @@ public class RSyntaxTextAreaHighlighter extends RTextAreaHighlighter {
markedOccurrences.clear();
parserHighlights.clear();
}
/**
* Returns a list of "marked occurrences" in the text area. If there are
* no marked occurrences, this will be an empty list.
* Returns a list of "marked occurrences" in the text area. If there are no
* marked occurrences, this will be an empty list.
*
* @return The list of marked occurrences, or an empty list if none. The
* contents of this list will be of type {@link DocumentRange}.
@@ -210,19 +208,19 @@ public class RSyntaxTextAreaHighlighter extends RTextAreaHighlighter {
}
return list;
}
@Override
public void paintLayeredHighlights(Graphics g, int lineStart, int lineEnd, Shape viewBounds, JTextComponent editor, View view) {
public void paintLayeredHighlights(Graphics g, int lineStart, int lineEnd, Shape viewBounds, JTextComponent editor,
View view) {
paintListLayered(g, lineStart, lineEnd, viewBounds, editor, view, markedOccurrences);
super.paintLayeredHighlights(g, lineStart, lineEnd, viewBounds, editor, view);
paintListLayered(g, lineStart, lineEnd, viewBounds, editor, view, parserHighlights);
}
/**
* Removes a parser highlight from this view.
*
* @param tag
* The reference to the highlight.
* @param tag The reference to the highlight.
* @see #addParserHighlight(ParserNotice,
* javax.swing.text.Highlighter.HighlightPainter)
*/
@@ -230,16 +228,15 @@ public class RSyntaxTextAreaHighlighter extends RTextAreaHighlighter {
repaintListHighlight(tag);
parserHighlights.remove(tag);
}
/**
* Highlight info implementation used for parser notices and marked
* occurrences.
* Highlight info implementation used for parser notices and marked occurrences.
*/
private static class SyntaxLayeredHighlightInfoImpl extends LayeredHighlightInfoImpl {
private ParserNotice notice;// Color color; // Used only by Parser
// highlights.
@Override
public Color getColor() {
// return color;
@@ -252,11 +249,11 @@ public class RSyntaxTextAreaHighlighter extends RTextAreaHighlighter {
}
return color;
}
@Override
public String toString() {
return "[SyntaxLayeredHighlightInfoImpl: " + "startOffs=" + getStartOffset() + ", endOffs=" + getEndOffset() + ", color="
+ getColor() + "]";
return "[SyntaxLayeredHighlightInfoImpl: " + "startOffs=" + getStartOffset() + ", endOffs=" + getEndOffset()
+ ", color=" + getColor() + "]";
}
}
}
@@ -27,34 +27,33 @@ import org.fife.ui.rtextarea.RTextArea;
import org.fife.ui.rtextarea.RTextAreaUI;
/**
* UI used by <code>RSyntaxTextArea</code>. This allows us to implement
* syntax highlighting.
* UI used by <code>RSyntaxTextArea</code>. This allows us to implement syntax
* highlighting.
*
* @author Robert Futrell
* @version 0.1
*/
public class RSyntaxTextAreaUI extends RTextAreaUI {
private static final String SHARED_ACTION_MAP_NAME = "RSyntaxTextAreaUI.actionMap";
private static final String SHARED_INPUT_MAP_NAME = "RSyntaxTextAreaUI.inputMap";
private static final EditorKit DEFAULT_KIT = new RSyntaxTextAreaEditorKit();
public static ComponentUI createUI(JComponent ta) {
return new RSyntaxTextAreaUI(ta);
}
/**
* Constructor.
*/
public RSyntaxTextAreaUI(JComponent rSyntaxTextArea) {
super(rSyntaxTextArea);
}
/**
* Creates the view for an element.
*
* @param elem
* The element.
* @param elem The element.
* @return The view.
*/
@Override
@@ -72,7 +71,7 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
}
return null;
}
/**
* Creates the highlighter to use for syntax text areas.
*
@@ -82,11 +81,11 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
protected Highlighter createHighlighter() {
return new RSyntaxTextAreaHighlighter();
}
/**
* Returns the name to use to cache/fetch the shared action map. This
* should be overridden by subclasses if the subclass has its own custom
* editor kit to install, so its actions get picked up.
* Returns the name to use to cache/fetch the shared action map. This should be
* overridden by subclasses if the subclass has its own custom editor kit to
* install, so its actions get picked up.
*
* @return The name of the cached action map.
*/
@@ -94,12 +93,11 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
protected String getActionMapName() {
return SHARED_ACTION_MAP_NAME;
}
/**
* Fetches the EditorKit for the UI.
*
* @param tc
* The text component for which this UI is installed.
* @param tc The text component for which this UI is installed.
* @return The editor capabilities.
* @see javax.swing.plaf.TextUI#getEditorKit
*/
@@ -107,16 +105,16 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
public EditorKit getEditorKit(JTextComponent tc) {
return DEFAULT_KIT;
}
/**
* Get the InputMap to use for the UI.
* <p>
*
* This method is not named <code>getInputMap()</code> because there is
* a package-private method in <code>BasicTextAreaUI</code> with that name.
* Thus, creating a new method with that name causes certain compilers to
* issue warnings that you are not actually overriding the original method
* (since it is package-private).
* This method is not named <code>getInputMap()</code> because there is a
* package-private method in <code>BasicTextAreaUI</code> with that name. Thus,
* creating a new method with that name causes certain compilers to issue
* warnings that you are not actually overriding the original method (since it
* is package-private).
*/
@Override
protected InputMap getRTextAreaInputMap() {
@@ -132,18 +130,17 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
map.setParent(shared);
return map;
}
@Override
protected void paintEditorAugmentations(Graphics g) {
super.paintEditorAugmentations(g);
paintMatchedBracket(g);
}
/**
* Paints the "matched bracket", if any.
*
* @param g
* The graphics context.
* @param g The graphics context.
*/
protected void paintMatchedBracket(Graphics g) {
RSyntaxTextArea rsta = (RSyntaxTextArea) textArea;
@@ -160,7 +157,7 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
}
}
}
protected void paintMatchedBracketImpl(Graphics g, RSyntaxTextArea rsta, Rectangle r) {
// We must add "-1" to the height because otherwise we'll paint below
// the region that gets invalidated.
@@ -183,13 +180,12 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
g.drawRect(r.x, r.y, r.width, r.height - 1);
}
}
/**
* Gets called whenever a bound property is changed on this UI's
* <code>RSyntaxTextArea</code>.
*
* @param e
* The property change event.
* @param e The property change event.
*/
@Override
protected void propertyChange(PropertyChangeEvent e) {
@@ -204,7 +200,7 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
super.propertyChange(e);
}
}
/**
* Updates the view. This should be called when the underlying
* <code>RSyntaxTextArea</code> changes its syntax editing style.
@@ -212,14 +208,13 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
public void refreshSyntaxHighlighting() {
modelChanged();
}
/**
* Returns the y-coordinate of the specified line.
* <p>
*
* This method is quicker than using traditional
* <code>modelToView(int)</code> calls, as the entire bounding box isn't
* computed.
* This method is quicker than using traditional <code>modelToView(int)</code>
* calls, as the entire bounding box isn't computed.
*/
@Override
public int yForLine(int line) throws BadLocationException {
@@ -230,7 +225,7 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
}
return -1;
}
/**
* Returns the y-coordinate of the line containing a specified offset.
* <p>
File diff suppressed because it is too large. Load diff
+89 -101
View File
@@ -20,25 +20,24 @@ import java.io.StringReader;
* Gets the plain text version of RTF documents.
* <p>
*
* This is used by <code>RtfTransferable</code> to return the plain text
* version of the transferable when the receiver does not support RTF.
* This is used by <code>RtfTransferable</code> to return the plain text version
* of the transferable when the receiver does not support RTF.
*
* @author Robert Futrell
* @version 1.0
*/
final class RtfToText {
private Reader r;
private StringBuilder sb;
private StringBuilder controlWord;
private int blockCount;
private boolean inControlWord;
/**
* Private constructor.
*
* @param r
* The reader to read RTF text from.
* @param r The reader to read RTF text from.
*/
private RtfToText(Reader r) {
this.r = r;
@@ -47,15 +46,14 @@ final class RtfToText {
blockCount = 0;
inControlWord = false;
}
/**
* Converts the RTF text read from this converter's <code>Reader</code>
* into plain text. It is the caller's responsibility to close the
* reader after this method is called.
* Converts the RTF text read from this converter's <code>Reader</code> into
* plain text. It is the caller's responsibility to close the reader after this
* method is called.
*
* @return The plain text.
* @throws IOException
* If an IO error occurs.
* @throws IOException If an IO error occurs.
*/
private String convert() throws IOException {
// Skip over first curly brace as the whole file is in '{' and '}'
@@ -66,76 +64,76 @@ final class RtfToText {
while ((i = r.read()) != -1) {
char ch = (char) i;
switch (ch) {
case '{':
if (inControlWord && controlWord.length() == 0) { // "\{"
sb.append('{');
controlWord.setLength(0);
inControlWord = false;
} else {
blockCount++;
}
break;
case '}':
if (inControlWord && controlWord.length() == 0) { // "\}"
sb.append('}');
controlWord.setLength(0);
inControlWord = false;
} else {
blockCount--;
}
break;
case '\\':
if (blockCount == 0) {
if (inControlWord) {
if (controlWord.length() == 0) { // "\\"
sb.append('\\');
controlWord.setLength(0);
inControlWord = false;
} else {
endControlWord();
inControlWord = true;
}
case '{':
if (inControlWord && controlWord.length() == 0) { // "\{"
sb.append('{');
controlWord.setLength(0);
inControlWord = false;
} else {
blockCount++;
}
break;
case '}':
if (inControlWord && controlWord.length() == 0) { // "\}"
sb.append('}');
controlWord.setLength(0);
inControlWord = false;
} else {
blockCount--;
}
break;
case '\\':
if (blockCount == 0) {
if (inControlWord) {
if (controlWord.length() == 0) { // "\\"
sb.append('\\');
controlWord.setLength(0);
inControlWord = false;
} else {
endControlWord();
inControlWord = true;
}
} else {
inControlWord = true;
}
break;
case ' ':
if (blockCount == 0) {
if (inControlWord) {
endControlWord();
} else {
sb.append(' ');
}
}
break;
case ' ':
if (blockCount == 0) {
if (inControlWord) {
endControlWord();
} else {
sb.append(' ');
}
break;
case '\r':
case '\n':
if (blockCount == 0) {
if (inControlWord) {
endControlWord();
}
// Otherwise, ignore
}
break;
case '\r':
case '\n':
if (blockCount == 0) {
if (inControlWord) {
endControlWord();
}
break;
default:
if (blockCount == 0) {
if (inControlWord) {
controlWord.append(ch);
} else {
sb.append(ch);
}
// Otherwise, ignore
}
break;
default:
if (blockCount == 0) {
if (inControlWord) {
controlWord.append(ch);
} else {
sb.append(ch);
}
break;
}
break;
}
}
return sb.toString();
}
/**
* Ends a control word. Checks whether it is a common one that affects
* the plain text output (such as "<code>par</code>" or "<code>tab</code>")
* and updates the text buffer accordingly.
* Ends a control word. Checks whether it is a common one that affects the plain
* text output (such as "<code>par</code>" or "<code>tab</code>") and updates
* the text buffer accordingly.
*/
private void endControlWord() {
String word = controlWord.toString();
@@ -147,58 +145,50 @@ final class RtfToText {
controlWord.setLength(0);
inControlWord = false;
}
/**
* Converts the contents of the specified byte array representing
* an RTF document into plain text.
* Converts the contents of the specified byte array representing an RTF
* document into plain text.
*
* @param rtf
* The byte array representing an RTF document.
* @param rtf The byte array representing an RTF document.
* @return The contents of the RTF document, in plain text.
* @throws IOException
* If an IO error occurs.
* @throws IOException If an IO error occurs.
*/
public static String getPlainText(byte[] rtf) throws IOException {
return getPlainText(new ByteArrayInputStream(rtf));
}
/**
* Converts the contents of the specified RTF file to plain text.
*
* @param file
* The RTF file to convert.
* @param file The RTF file to convert.
* @return The contents of the file, in plain text.
* @throws IOException
* If an IO error occurs.
* @throws IOException If an IO error occurs.
*/
public static String getPlainText(File file) throws IOException {
return getPlainText(new BufferedReader(new FileReader(file)));
}
/**
* Converts the contents of the specified input stream to plain text.
* The input stream will be closed when this method returns.
* Converts the contents of the specified input stream to plain text. The input
* stream will be closed when this method returns.
*
* @param in
* The input stream to convert. This will be closed when this
* method returns.
* @param in The input stream to convert. This will be closed when this method
* returns.
* @return The contents of the stream, in plain text.
* @throws IOException
* If an IO error occurs.
* @throws IOException If an IO error occurs.
*/
public static String getPlainText(InputStream in) throws IOException {
return getPlainText(new InputStreamReader(in, "US-ASCII"));
}
/**
* Converts the contents of the specified <code>Reader</code> to plain text.
*
* @param r
* The <code>Reader</code>. This will be closed when this method
* returns.
* @param r The <code>Reader</code>. This will be closed when this method
* returns.
* @return The contents of the <code>Reader</code>, in plain text.
* @throws IOException
* If an IO error occurs.
* @throws IOException If an IO error occurs.
*/
private static String getPlainText(Reader r) throws IOException {
try {
@@ -208,15 +198,13 @@ final class RtfToText {
r.close();
}
}
/**
* Converts the contents of the specified String to plain text.
*
* @param rtf
* A string whose contents represent an RTF document.
* @param rtf A string whose contents represent an RTF document.
* @return The contents of the String, in plain text.
* @throws IOException
* If an IO error occurs.
* @throws IOException If an IO error occurs.
*/
public static String getPlainText(String rtf) throws IOException {
return getPlainText(new StringReader(rtf));
+102 -135
View File
@@ -27,12 +27,10 @@ import org.fife.ui.rtextarea.RTextArea;
* </ul>
*
* The RTF generated isn't really "optimized," but it will do, especially for
* small amounts of text, such as what's common when copy-and-pasting. It
* tries to be sufficient for the use case of copying syntax highlighted
* code:
* small amounts of text, such as what's common when copy-and-pasting. It tries
* to be sufficient for the use case of copying syntax highlighted code:
* <ul>
* <li>It assumes that tokens changing foreground color often is fairly
* common.
* <li>It assumes that tokens changing foreground color often is fairly common.
* <li>It assumes that background highlighting is fairly uncommon.
* </ul>
*
@@ -40,7 +38,7 @@ import org.fife.ui.rtextarea.RTextArea;
* @version 1.0
*/
public class RtfGenerator {
private List<Font> fontList;
private List<Color> colorList;
private StringBuilder document;
@@ -53,16 +51,15 @@ public class RtfGenerator {
/**
* Java2D assumes a 72 dpi screen resolution, but on Windows the screen
* resolution is either 96 dpi or 120 dpi, depending on your font display
* settings. This is an attempt to make the RTF generated match the
* size of what's displayed in the RSyntaxTextArea.
* settings. This is an attempt to make the RTF generated match the size of
* what's displayed in the RSyntaxTextArea.
*/
private int screenRes;
/**
* The default font size for RTF. This is point size, in half
* points.
* The default font size for RTF. This is point size, in half points.
*/
private static final int DEFAULT_FONT_SIZE = 12;// 24;
/**
* Constructor.
*/
@@ -72,7 +69,7 @@ public class RtfGenerator {
document = new StringBuilder();
reset();
}
/**
* Adds a newline to the RTF document.
*
@@ -83,87 +80,68 @@ public class RtfGenerator {
document.append('\n'); // Just for ease of reading RTF.
lastWasControlWord = false;
}
/**
* Appends styled text to the RTF document being generated.
*
* @param text
* The text to append.
* @param f
* The font of the text. If this is <code>null</code>, the
* default font is used.
* @param fg
* The foreground of the text. If this is <code>null</code>,
* the default foreground color is used.
* @param bg
* The background color of the text. If this is
* <code>null</code>, the default background color is used.
* @param text The text to append.
* @param f The font of the text. If this is <code>null</code>, the default
* font is used.
* @param fg The foreground of the text. If this is <code>null</code>, the
* default foreground color is used.
* @param bg The background color of the text. If this is <code>null</code>,
* the default background color is used.
* @see #appendNewline()
*/
public void appendToDoc(String text, Font f, Color fg, Color bg) {
appendToDoc(text, f, fg, bg, false);
}
/**
* Appends styled text to the RTF document being generated.
*
* @param text
* The text to append.
* @param f
* The font of the text. If this is <code>null</code>, the
* default font is used.
* @param bg
* The background color of the text. If this is
* <code>null</code>, the default background color is used.
* @param underline
* Whether the text should be underlined.
* @param text The text to append.
* @param f The font of the text. If this is <code>null</code>, the
* default font is used.
* @param bg The background color of the text. If this is
* <code>null</code>, the default background color is used.
* @param underline Whether the text should be underlined.
* @see #appendNewline()
*/
public void appendToDocNoFG(String text, Font f, Color bg, boolean underline) {
appendToDoc(text, f, null, bg, underline, false);
}
/**
* Appends styled text to the RTF document being generated.
*
* @param text
* The text to append.
* @param f
* The font of the text. If this is <code>null</code>, the
* default font is used.
* @param fg
* The foreground of the text. If this is <code>null</code>,
* the default foreground color is used.
* @param bg
* The background color of the text. If this is
* <code>null</code>, the default background color is used.
* @param underline
* Whether the text should be underlined.
* @param text The text to append.
* @param f The font of the text. If this is <code>null</code>, the
* default font is used.
* @param fg The foreground of the text. If this is <code>null</code>,
* the default foreground color is used.
* @param bg The background color of the text. If this is
* <code>null</code>, the default background color is used.
* @param underline Whether the text should be underlined.
* @see #appendNewline()
*/
public void appendToDoc(String text, Font f, Color fg, Color bg, boolean underline) {
appendToDoc(text, f, fg, bg, underline, true);
}
/**
* Appends styled text to the RTF document being generated.
*
* @param text
* The text to append.
* @param f
* The font of the text. If this is <code>null</code>, the
* default font is used.
* @param fg
* The foreground of the text. If this is <code>null</code>,
* the default foreground color is used.
* @param bg
* The background color of the text. If this is
* <code>null</code>, the default background color is used.
* @param underline
* Whether the text should be underlined.
* @param setFG
* Whether the foreground specified by <code>fg</code> should
* be honored (if it is non-<code>null</code>).
* @param text The text to append.
* @param f The font of the text. If this is <code>null</code>, the
* default font is used.
* @param fg The foreground of the text. If this is <code>null</code>,
* the default foreground color is used.
* @param bg The background color of the text. If this is
* <code>null</code>, the default background color is used.
* @param underline Whether the text should be underlined.
* @param setFG Whether the foreground specified by <code>fg</code> should
* be honored (if it is non-<code>null</code>).
* @see #appendNewline()
*/
public void appendToDoc(String text, Font f, Color fg, Color bg, boolean underline, boolean setFG) {
@@ -248,70 +226,65 @@ public class RtfGenerator {
}
}
}
/**
* Appends some text to a buffer, with special care taken for special
* characters as defined by the RTF spec.
* Appends some text to a buffer, with special care taken for special characters
* as defined by the RTF spec.
*
* <ul>
* <li>All tab characters are replaced with the string
* "<code>\tab</code>"
* <li>All tab characters are replaced with the string "<code>\tab</code>"
* <li>'\', '{' and '}' are changed to "\\", "\{" and "\}"
* </ul>
*
* @param text
* The text to append (with tab chars substituted).
* @param sb
* The buffer to append to.
* @param text The text to append (with tab chars substituted).
* @param sb The buffer to append to.
*/
private void escapeAndAdd(StringBuilder sb, String text) {
int count = text.length();
for (int i = 0; i < count; i++) {
char ch = text.charAt(i);
switch (ch) {
case '\t':
// Micro-optimization: for syntax highlighting with
// tab indentation, there are often multiple tabs
// back-to-back at the start of lines, so don't put
// spaces between each "\tab".
case '\t':
// Micro-optimization: for syntax highlighting with
// tab indentation, there are often multiple tabs
// back-to-back at the start of lines, so don't put
// spaces between each "\tab".
sb.append("\\tab");
while ((++i < count) && text.charAt(i) == '\t') {
sb.append("\\tab");
while ((++i < count) && text.charAt(i) == '\t') {
sb.append("\\tab");
}
sb.append(' ');
i--; // We read one too far.
break;
case '\\':
case '{':
case '}':
sb.append('\\').append(ch);
break;
default:
if (ch <= 127) {
sb.append(ch);
} else {
sb.append("\\u").append((int) ch);
}
break;
}
sb.append(' ');
i--; // We read one too far.
break;
case '\\':
case '{':
case '}':
sb.append('\\').append(ch);
break;
default:
if (ch <= 127) {
sb.append(ch);
} else {
sb.append("\\u").append((int) ch);
}
break;
}
}
}
/**
* Returns a font point size, adjusted for the current screen resolution.
* <p>
*
* Java2D assumes 72 dpi. On systems with larger dpi (Windows, GTK, etc.),
* font rendering will appear too small if we simply return a Java "Font"
* object's getSize() value. We need to adjust it for the screen
* resolution.
* Java2D assumes 72 dpi. On systems with larger dpi (Windows, GTK, etc.), font
* rendering will appear too small if we simply return a Java "Font" object's
* getSize() value. We need to adjust it for the screen resolution.
*
* @param pointSize
* A Java Font's point size, as returned from
* <code>getSize2D()</code>.
* @return The font point size, adjusted for the current screen resolution.
* This will allow other applications to render fonts the same
* size as they appear in the Java application.
* @param pointSize A Java Font's point size, as returned from
* <code>getSize2D()</code>.
* @return The font point size, adjusted for the current screen resolution. This
* will allow other applications to render fonts the same size as they
* appear in the Java application.
*/
private int fixFontSize(float pointSize) {
if (screenRes != 72) { // Java2D assumes 72 dpi
@@ -319,15 +292,13 @@ public class RtfGenerator {
}
return (int) pointSize;
}
/**
* Returns the index of the specified item in a list. If the item
* is not in the list, it is added, and its new index is returned.
* Returns the index of the specified item in a list. If the item is not in the
* list, it is added, and its new index is returned.
*
* @param list
* The list (possibly) containing the item.
* @param item
* The item to get the index of.
* @param list The list (possibly) containing the item.
* @param item The item to get the index of.
* @return The index of the item.
*/
private static int getColorIndex(List<Color> list, Color item) {
@@ -338,7 +309,7 @@ public class RtfGenerator {
}
return pos;
}
private String getColorTableRtf() {
// Example:
// "{\\colortbl ;\\red255\\green0\\blue0;\\red0\\green0\\blue255; }"
@@ -353,20 +324,17 @@ public class RtfGenerator {
sb.append("}");
return sb.toString();
}
/**
* Returns the index of the specified font in a list of fonts. This
* method only checks for a font by its family name; its attributes such
* as bold and italic are ignored.
* Returns the index of the specified font in a list of fonts. This method only
* checks for a font by its family name; its attributes such as bold and italic
* are ignored.
* <p>
*
* If the font is not in the list, it is added, and its new index is
* returned.
* If the font is not in the list, it is added, and its new index is returned.
*
* @param list
* The list (possibly) containing the font.
* @param font
* The font to get the index of.
* @param list The list (possibly) containing the font.
* @param font The font to get the index of.
* @return The index of the font.
*/
private static int getFontIndex(List<Font> list, Font font) {
@@ -380,7 +348,7 @@ public class RtfGenerator {
list.add(font);
return list.size() - 1;
}
private String getFontTableRtf() {
// Example:
// "{\\fonttbl{\\f0\\fmodern\\fcharset0 Courier;}}"
@@ -402,10 +370,10 @@ public class RtfGenerator {
sb.append('}');
return sb.toString();
}
/**
* Returns a good "default" monospaced font to use when Java's logical
* font "Monospaced" is found.
* Returns a good "default" monospaced font to use when Java's logical font
* "Monospaced" is found.
*
* @return The monospaced font family to use.
*/
@@ -416,7 +384,7 @@ public class RtfGenerator {
}
return family;
}
/**
* Returns the RTF document created by this generator.
*
@@ -440,10 +408,9 @@ public class RtfGenerator {
// System.err.println("*** " + sb.length());
return sb.toString();
}
/**
* Resets this generator. All document information and content is
* cleared.
* Resets this generator. All document information and content is cleared.
*/
public void reset() {
fontList.clear();
@@ -14,17 +14,16 @@ import java.io.IOException;
import java.io.StringReader;
/**
* Object used during copy/paste and DnD operations to represent RTF text.
* It can return the text being moved as either RTF or plain text. This
* class is basically the same as
* <code>java.awt.datatransfer.StringSelection</code>, except that it can also
* return the text as RTF.
* Object used during copy/paste and DnD operations to represent RTF text. It
* can return the text being moved as either RTF or plain text. This class is
* basically the same as <code>java.awt.datatransfer.StringSelection</code>,
* except that it can also return the text as RTF.
*
* @author Robert Futrell
* @version 1.0
*/
class RtfTransferable implements Transferable {
/**
* The RTF data, in bytes (the RTF is 7-bit ascii).
*/
@@ -32,19 +31,19 @@ class RtfTransferable implements Transferable {
/**
* The "flavors" the text can be returned as.
*/
private static final DataFlavor[] FLAVORS = { new DataFlavor("text/rtf", "RTF"), DataFlavor.stringFlavor, DataFlavor.plainTextFlavor // deprecated
private static final DataFlavor[] FLAVORS = { new DataFlavor("text/rtf", "RTF"), DataFlavor.stringFlavor,
DataFlavor.plainTextFlavor // deprecated
};
/**
* Constructor.
*
* @param data
* The RTF data.
* @param data The RTF data.
*/
RtfTransferable(byte[] data) {
this.data = data;
}
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (flavor.equals(FLAVORS[0])) { // RTF
@@ -61,12 +60,12 @@ class RtfTransferable implements Transferable {
throw new UnsupportedFlavorException(flavor);
}
}
@Override
public DataFlavor[] getTransferDataFlavors() {
return FLAVORS.clone();
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
for (int i = 0; i < FLAVORS.length; i++) {
@@ -11,28 +11,28 @@ package org.fife.ui.rsyntaxtextarea;
import javax.swing.event.HyperlinkEvent;
/**
* A link generator result that selects a region of text in the text area.
* This will typically be used by IDE-style applications, to provide support
* for "linking" the use of a variable in a document to its declaration.
* A link generator result that selects a region of text in the text area. This
* will typically be used by IDE-style applications, to provide support for
* "linking" the use of a variable in a document to its declaration.
*
* @author Robert Futrell
* @version 1.0
* @see LinkGenerator
*/
public class SelectRegionLinkGeneratorResult implements LinkGeneratorResult {
private RSyntaxTextArea textArea;
private int sourceOffset;
private int selStart;
private int selEnd;
public SelectRegionLinkGeneratorResult(RSyntaxTextArea textArea, int sourceOffset, int selStart, int selEnd) {
this.textArea = textArea;
this.sourceOffset = sourceOffset;
this.selStart = selStart;
this.selEnd = selEnd;
}
/**
* Selects the text in the text area.
*/
@@ -41,7 +41,7 @@ public class SelectRegionLinkGeneratorResult implements LinkGeneratorResult {
textArea.select(selStart, selEnd);
return null;
}
/**
* {@inheritDoc}
*/
@@ -32,37 +32,29 @@ import org.fife.ui.rtextarea.ChangeableHighlightPainter;
* @version 1.0
*/
public class SquiggleUnderlineHighlightPainter extends ChangeableHighlightPainter {
private static final int AMT = 2;
/**
* Constructor.
*
* @param color
* The color of the squiggle. This cannot be
* <code>null</code>.
* @param color The color of the squiggle. This cannot be <code>null</code>.
*/
public SquiggleUnderlineHighlightPainter(Color color) {
super(color);
setPaint(color);
}
/**
* Paints a portion of a highlight.
*
* @param g
* the graphics context
* @param offs0
* the starting model offset &gt;= 0
* @param offs1
* the ending model offset &gt;= offs1
* @param bounds
* the bounding box of the view, which is not
* necessarily the region to paint.
* @param c
* the editor
* @param view
* View painting for
* @param g the graphics context
* @param offs0 the starting model offset &gt;= 0
* @param offs1 the ending model offset &gt;= offs1
* @param bounds the bounding box of the view, which is not necessarily the
* region to paint.
* @param c the editor
* @param view View painting for
* @return region drawing occurred in
*/
@Override
@@ -92,14 +84,12 @@ public class SquiggleUnderlineHighlightPainter extends ChangeableHighlightPainte
// Only if exception
return null;
}
/**
* Paints a squiggle underneath text in the specified rectangle.
*
* @param g
* The graphics context with which to paint.
* @param r
* The rectangle containing the text.
* @param g The graphics context with which to paint.
* @param r The rectangle containing the text.
*/
protected void paintSquiggle(Graphics g, Rectangle r) {
int x = r.x;
@@ -8,8 +8,8 @@ package org.fife.ui.rsyntaxtextarea;
/**
* Constants that define the different programming languages understood by
* <code>RSyntaxTextArea</code>. These constants are the values you can pass
* to {@link RSyntaxTextArea#setSyntaxEditingStyle(String)} to get syntax
* <code>RSyntaxTextArea</code>. These constants are the values you can pass to
* {@link RSyntaxTextArea#setSyntaxEditingStyle(String)} to get syntax
* highlighting.
* <p>
*
@@ -25,7 +25,7 @@ package org.fife.ui.rsyntaxtextarea;
* @version 1.0
*/
public interface SyntaxConstants {
/**
* Style meaning don't syntax highlight anything.
*/
@@ -123,8 +123,8 @@ public interface SyntaxConstants {
*/
String SYNTAX_STYLE_JSON = "text/json";
/**
* Style for highlighting .jshintrc files (JSON with comments, so can be
* used for other times when you want this behavior).
* Style for highlighting .jshintrc files (JSON with comments, so can be used
* for other times when you want this behavior).
*/
String SYNTAX_STYLE_JSON_WITH_COMMENTS = "text/jshintrc";
/**
+207 -268
View File
@@ -30,14 +30,14 @@ import org.fife.ui.rsyntaxtextarea.folding.FoldManager;
/**
* The <code>javax.swing.text.View</code> object used by {@link RSyntaxTextArea}
* when word wrap is disabled. It implements syntax highlighting for
* programming languages using the colors and font styles specified by the
* when word wrap is disabled. It implements syntax highlighting for programming
* languages using the colors and font styles specified by the
* <code>RSyntaxTextArea</code>.
* <p>
*
* You don't really have to do anything to use this class, as
* {@link RSyntaxTextAreaUI} automatically sets the text area's view to be
* an instance of this class if word wrap is disabled.
* {@link RSyntaxTextAreaUI} automatically sets the text area's view to be an
* instance of this class if word wrap is disabled.
* <p>
*
* The tokens that specify how to paint the syntax-highlighted text are gleaned
@@ -47,7 +47,7 @@ import org.fife.ui.rsyntaxtextarea.folding.FoldManager;
* @version 0.3
*/
public class SyntaxView extends View implements TabExpander, TokenOrientedView, RSTAView {
/**
* The default font used by the text area. If this changes we need to
* recalculate the longest line.
@@ -58,9 +58,9 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
*/
private FontMetrics metrics;
/**
* The current longest line. This is used to calculate the preferred width
* of the view. Since the calculation is potentially expensive, we try to
* avoid it by stashing which line is currently the longest.
* The current longest line. This is used to calculate the preferred width of
* the view. Since the calculation is potentially expensive, we try to avoid it
* by stashing which line is currently the longest.
*/
private Element longLine;
private float longLineWidth;
@@ -78,30 +78,28 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
private int clipStart;
private int clipEnd;
/**
* Temporary token used when we need to "modify" tokens for rendering
* purposes. Since tokens returned from RSyntaxDocuments are treated as
* immutable, we use this temporary token to do that work.
* Temporary token used when we need to "modify" tokens for rendering purposes.
* Since tokens returned from RSyntaxDocuments are treated as immutable, we use
* this temporary token to do that work.
*/
private TokenImpl tempToken;
/**
* Constructs a new <code>SyntaxView</code> wrapped around an element.
*
* @param elem
* The element representing the text to display.
* @param elem The element representing the text to display.
*/
public SyntaxView(Element elem) {
super(elem);
tempToken = new TokenImpl();
}
/**
* Iterate over the lines represented by the child elements
* of the element this view represents, looking for the line
* that is the longest. The <em>longLine</em> variable is updated to
* represent the longest line contained. The <em>font</em> variable
* is updated to indicate the font used to calculate the
* longest line.
* Iterate over the lines represented by the child elements of the element this
* view represents, looking for the line that is the longest. The
* <em>longLine</em> variable is updated to represent the longest line
* contained. The <em>font</em> variable is updated to indicate the font used to
* calculate the longest line.
*/
void calculateLongestLine() {
Component c = getContainer();
@@ -119,37 +117,30 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
}
}
/**
* Gives notification from the document that attributes were changed
* in a location that this view is responsible for.
* Gives notification from the document that attributes were changed in a
* location that this view is responsible for.
*
* @param changes
* the change information from the associated document
* @param a
* the current allocation of the view
* @param f
* the factory to use to rebuild if the view has children
* @param changes the change information from the associated document
* @param a the current allocation of the view
* @param f the factory to use to rebuild if the view has children
* @see View#changedUpdate
*/
@Override
public void changedUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
updateDamage(changes, a, f);
}
/**
* Repaint the given line range.
*
* @param line0
* The starting line number to repaint. This must
* be a valid line number in the model.
* @param line1
* The ending line number to repaint. This must
* be a valid line number in the model.
* @param a
* The region allocated for the view to render into.
* @param host
* The component hosting the view (used to call repaint).
* @param line0 The starting line number to repaint. This must be a valid line
* number in the model.
* @param line1 The ending line number to repaint. This must be a valid line
* number in the model.
* @param a The region allocated for the view to render into.
* @param host The component hosting the view (used to call repaint).
*/
protected void damageLineRange(int line0, int line1, Shape a, Component host) {
if (a != null) {
@@ -163,23 +154,17 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
}
}
/**
* Draws the passed-in text using syntax highlighting for the current
* language. It is assumed that the entire line is either not in a
* selected region, or painting with a selection-foreground color is turned
* off.
* Draws the passed-in text using syntax highlighting for the current language.
* It is assumed that the entire line is either not in a selected region, or
* painting with a selection-foreground color is turned off.
*
* @param painter
* The painter to render the tokens.
* @param token
* The list of tokens to draw.
* @param g
* The graphics context in which to draw.
* @param x
* The x-coordinate at which to draw.
* @param y
* The y-coordinate at which to draw.
* @param painter The painter to render the tokens.
* @param token The list of tokens to draw.
* @param g The graphics context in which to draw.
* @param x The x-coordinate at which to draw.
* @param y The y-coordinate at which to draw.
* @return The x-coordinate representing the end of the painted text.
*/
private float drawLine(TokenPainter painter, Token token, Graphics2D g, float x, float y, int line) {
@@ -199,29 +184,23 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
// Return the x-coordinate at the end of the painted text.
return nextX;
}
/**
* Draws the passed-in text using syntax highlighting for the current
* language. Tokens are checked for being in a selected region, and are
* rendered appropriately if they are.
* Draws the passed-in text using syntax highlighting for the current language.
* Tokens are checked for being in a selected region, and are rendered
* appropriately if they are.
*
* @param painter
* The painter to render the tokens.
* @param token
* The list of tokens to draw.
* @param g
* The graphics context in which to draw.
* @param x
* The x-coordinate at which to draw.
* @param y
* The y-coordinate at which to draw.
* @param selStart
* The start of the selection.
* @param selEnd
* The end of the selection.
* @param painter The painter to render the tokens.
* @param token The list of tokens to draw.
* @param g The graphics context in which to draw.
* @param x The x-coordinate at which to draw.
* @param y The y-coordinate at which to draw.
* @param selStart The start of the selection.
* @param selEnd The end of the selection.
* @return The x-coordinate representing the end of the painted text.
*/
private float drawLineWithSelection(TokenPainter painter, Token token, Graphics2D g, float x, float y, int selStart, int selEnd) {
private float drawLineWithSelection(TokenPainter painter, Token token, Graphics2D g, float x, float y, int selStart,
int selEnd) {
float nextX = x; // The x-value at the end of our text.
boolean useSTC = host.getUseSelectedTextColor();
while (token != null && token.isPaintable() && nextX < clipEnd) {
@@ -281,90 +260,81 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
// Return the x-coordinate at the end of the painted text.
return nextX;
}
/**
* Calculates the width of the line represented by the given element.
*
* @param line
* The line for which to get the length.
* @param lineNumber
* The line number of the specified line in the document.
* @param line The line for which to get the length.
* @param lineNumber The line number of the specified line in the document.
* @return The width of the line.
*/
private float getLineWidth(int lineNumber) {
Token tokenList = ((RSyntaxDocument) getDocument()).getTokenListForLine(lineNumber);
return RSyntaxUtilities.getTokenListWidth(tokenList, (RSyntaxTextArea) getContainer(), this);
}
/**
* Provides a way to determine the next visually represented model
* location that one might place a caret. Some views may not be visible,
* they might not be in the same order found in the model, or they just
* might not allow access to some of the locations in the model.
* Provides a way to determine the next visually represented model location that
* one might place a caret. Some views may not be visible, they might not be in
* the same order found in the model, or they just might not allow access to
* some of the locations in the model.
*
* @param pos
* the position to convert &gt;= 0
* @param a
* the allocated region to render into
* @param direction
* the direction from the current position that can
* be thought of as the arrow keys typically found on a keyboard.
* This may be SwingConstants.WEST, SwingConstants.EAST,
* SwingConstants.NORTH, or SwingConstants.SOUTH.
* @return the location within the model that best represents the next
* location visual position.
* @param pos the position to convert &gt;= 0
* @param a the allocated region to render into
* @param direction the direction from the current position that can be thought
* of as the arrow keys typically found on a keyboard. This may
* be SwingConstants.WEST, SwingConstants.EAST,
* SwingConstants.NORTH, or SwingConstants.SOUTH.
* @return the location within the model that best represents the next location
* visual position.
* @exception BadLocationException
* @exception IllegalArgumentException
* for an invalid direction
* @exception IllegalArgumentException for an invalid direction
*/
@Override
public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet)
throws BadLocationException {
return RSyntaxUtilities.getNextVisualPositionFrom(pos, b, a, direction, biasRet, this);
}
/**
* Determines the preferred span for this view along an
* axis.
* Determines the preferred span for this view along an axis.
*
* @param axis
* may be either View.X_AXIS or View.Y_AXIS
* @return the span the view would like to be rendered into &gt;= 0.
* Typically the view is told to render into the span
* that is returned, although there is no guarantee.
* The parent may choose to resize or break the view.
* @exception IllegalArgumentException
* for an invalid axis
* @param axis may be either View.X_AXIS or View.Y_AXIS
* @return the span the view would like to be rendered into &gt;= 0. Typically
* the view is told to render into the span that is returned, although
* there is no guarantee. The parent may choose to resize or break the
* view.
* @exception IllegalArgumentException for an invalid axis
*/
@Override
public float getPreferredSpan(int axis) {
updateMetrics();
switch (axis) {
case View.X_AXIS:
float span = longLineWidth + getRhsCorrection(); // fudge factor
if (host.getEOLMarkersVisible()) {
span += metrics.charWidth('\u00B6');
}
return span;
case View.Y_AXIS:
// We update lineHeight here as when this method is first
// called, lineHeight isn't initialized. If we don't do it
// here, we get no vertical scrollbar (as lineHeight==0).
lineHeight = host != null ? host.getLineHeight() : lineHeight;
// return getElement().getElementCount() * lineHeight;
int visibleLineCount = getElement().getElementCount();
if (host.isCodeFoldingEnabled()) {
visibleLineCount -= host.getFoldManager().getHiddenLineCount();
}
return visibleLineCount * (float) lineHeight;
default:
throw new IllegalArgumentException("Invalid axis: " + axis);
case View.X_AXIS:
float span = longLineWidth + getRhsCorrection(); // fudge factor
if (host.getEOLMarkersVisible()) {
span += metrics.charWidth('\u00B6');
}
return span;
case View.Y_AXIS:
// We update lineHeight here as when this method is first
// called, lineHeight isn't initialized. If we don't do it
// here, we get no vertical scrollbar (as lineHeight==0).
lineHeight = host != null ? host.getLineHeight() : lineHeight;
// return getElement().getElementCount() * lineHeight;
int visibleLineCount = getElement().getElementCount();
if (host.isCodeFoldingEnabled()) {
visibleLineCount -= host.getFoldManager().getHiddenLineCount();
}
return visibleLineCount * (float) lineHeight;
default:
throw new IllegalArgumentException("Invalid axis: " + axis);
}
}
/**
* Workaround for JTextComponents allowing the caret to be rendered
* entirely off-screen if the entire "previous" character fit entirely.
* Workaround for JTextComponents allowing the caret to be rendered entirely
* off-screen if the entire "previous" character fit entirely.
*
* @return The amount of space to add to the x-axis preferred span.
*/
@@ -375,7 +345,7 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
return rhsCorrection;
}
/**
* Returns the tab size set for the document, defaulting to 5.
*
@@ -386,19 +356,17 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
int size = (i != null) ? i.intValue() : 5;
return size;
}
/**
* Returns a token list for the <i>physical</i> line above the physical
* line containing the specified offset into the document. Note that for
* this plain (non-wrapped) view, this is simply the token list for the
* logical line above the line containing <code>offset</code>, since lines
* are not wrapped.
* Returns a token list for the <i>physical</i> line above the physical line
* containing the specified offset into the document. Note that for this plain
* (non-wrapped) view, this is simply the token list for the logical line above
* the line containing <code>offset</code>, since lines are not wrapped.
*
* @param offset
* The offset in question.
* @return A token list for the physical (and in this view, logical) line
* before this one. If <code>offset</code> is in the first line in
* the document, <code>null</code> is returned.
* @param offset The offset in question.
* @return A token list for the physical (and in this view, logical) line before
* this one. If <code>offset</code> is in the first line in the
* document, <code>null</code> is returned.
*/
@Override
public Token getTokenListForPhysicalLineAbove(int offset) {
@@ -422,19 +390,17 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
// return document.getTokenListForLine(line);
return null;
}
/**
* Returns a token list for the <i>physical</i> line below the physical
* line containing the specified offset into the document. Note that for
* this plain (non-wrapped) view, this is simply the token list for the
* logical line below the line containing <code>offset</code>, since lines
* are not wrapped.
* Returns a token list for the <i>physical</i> line below the physical line
* containing the specified offset into the document. Note that for this plain
* (non-wrapped) view, this is simply the token list for the logical line below
* the line containing <code>offset</code>, since lines are not wrapped.
*
* @param offset
* The offset in question.
* @return A token list for the physical (and in this view, logical) line
* after this one. If <code>offset</code> is in the last physical
* line in the document, <code>null</code> is returned.
* @param offset The offset in question.
* @return A token list for the physical (and in this view, logical) line after
* this one. If <code>offset</code> is in the last physical line in the
* document, <code>null</code> is returned.
*/
@Override
public Token getTokenListForPhysicalLineBelow(int offset) {
@@ -459,31 +425,26 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
// return document.getTokenListForLine(line+1);
return null;
}
/**
* Gives notification that something was inserted into the document
* in a location that this view is responsible for.
* Gives notification that something was inserted into the document in a
* location that this view is responsible for.
*
* @param changes
* The change information from the associated document.
* @param a
* The current allocation of the view.
* @param f
* The factory to use to rebuild if the view has children.
* @param changes The change information from the associated document.
* @param a The current allocation of the view.
* @param f The factory to use to rebuild if the view has children.
*/
@Override
public void insertUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
updateDamage(changes, a, f);
}
/**
* Determine the rectangle that represents the given line.
*
* @param a
* The region allocated for the view to render into
* @param line
* The line number to find the region of. This must
* be a valid line number in the model.
* @param a The region allocated for the view to render into
* @param line The line number to find the region of. This must be a valid line
* number in the model.
*/
protected Rectangle lineToRect(Shape a, int line) {
Rectangle r = null;
@@ -503,19 +464,16 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
return r;
}
/**
* Provides a mapping from the document model coordinate space
* to the coordinate space of the view mapped to it.
* Provides a mapping from the document model coordinate space to the coordinate
* space of the view mapped to it.
*
* @param pos
* the position to convert &gt;= 0
* @param a
* the allocated region to render into
* @param pos the position to convert &gt;= 0
* @param a the allocated region to render into
* @return the bounding box of the given position
* @exception BadLocationException
* if the given position does not
* represent a valid location in the associated document
* @exception BadLocationException if the given position does not represent a
* valid location in the associated document
* @see View#modelToView
*/
@Override
@@ -535,48 +493,43 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
lineArea = tokenList.listOffsetToView((RSyntaxTextArea) getContainer(), this, pos, tabBase, lineArea);
return lineArea;
}
/**
* Provides a mapping, for a given region, from the document model
* coordinate space to the view coordinate space. The specified region is
* created as a union of the first and last character positions.
* Provides a mapping, for a given region, from the document model coordinate
* space to the view coordinate space. The specified region is created as a
* union of the first and last character positions.
* <p>
*
* This is implemented to subtract the width of the second character, as
* this view's <code>modelToView</code> actually returns the width of the
* character instead of "1" or "0" like the View implementations in
* <code>javax.swing.text</code>. Thus, if we don't override this method,
* the <code>View</code> implementation will return one character's width
* too much for its consumers (implementations of
* This is implemented to subtract the width of the second character, as this
* view's <code>modelToView</code> actually returns the width of the character
* instead of "1" or "0" like the View implementations in
* <code>javax.swing.text</code>. Thus, if we don't override this method, the
* <code>View</code> implementation will return one character's width too much
* for its consumers (implementations of
* <code>javax.swing.text.Highlighter</code>).
*
* @param p0
* the position of the first character (&gt;=0)
* @param b0
* The bias of the first character position, toward the previous
* character or the next character represented by the offset, in
* case the position is a boundary of two views; <code>b0</code>
* will have one of these values:
* <ul>
* <li><code>Position.Bias.Forward</code>
* <li><code>Position.Bias.Backward</code>
* </ul>
* @param p1
* the position of the last character (&gt;=0)
* @param b1
* the bias for the second character position, defined
* one of the legal values shown above
* @param a
* the area of the view, which encompasses the requested region
* @return the bounding box which is a union of the region specified
* by the first and last character positions
* @exception BadLocationException
* if the given position does
* not represent a valid location in the associated document
* @exception IllegalArgumentException
* if <code>b0</code> or
* <code>b1</code> are not one of the
* legal <code>Position.Bias</code> values listed above
* @param p0 the position of the first character (&gt;=0)
* @param b0 The bias of the first character position, toward the previous
* character or the next character represented by the offset, in case
* the position is a boundary of two views; <code>b0</code> will have
* one of these values:
* <ul>
* <li><code>Position.Bias.Forward</code>
* <li><code>Position.Bias.Backward</code>
* </ul>
* @param p1 the position of the last character (&gt;=0)
* @param b1 the bias for the second character position, defined one of the
* legal values shown above
* @param a the area of the view, which encompasses the requested region
* @return the bounding box which is a union of the region specified by the
* first and last character positions
* @exception BadLocationException if the given position does not represent
* a valid location in the associated
* document
* @exception IllegalArgumentException if <code>b0</code> or <code>b1</code> are
* not one of the legal
* <code>Position.Bias</code> values listed
* above
* @see View#viewToModel
*/
@Override
@@ -618,17 +571,15 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
return r0;
}
/**
* Returns the next tab stop position after a given reference position.
* This implementation does not support things like centering so it
* ignores the tabOffset argument.
* Returns the next tab stop position after a given reference position. This
* implementation does not support things like centering so it ignores the
* tabOffset argument.
*
* @param x
* the current position &gt;= 0
* @param tabOffset
* the position within the text stream
* that the tab occurred at &gt;= 0.
* @param x the current position &gt;= 0
* @param tabOffset the position within the text stream that the tab occurred at
* &gt;= 0.
* @return the tab stop, measured in points &gt;= 0
*/
@Override
@@ -639,15 +590,13 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
int ntabs = (((int) x) - tabBase) / tabSize;
return tabBase + ((ntabs + 1f) * tabSize);
}
/**
* Actually paints the text area. Only lines that have been damaged are
* repainted.
*
* @param g
* The graphics context with which to paint.
* @param a
* The allocated region in which to render.
* @param g The graphics context with which to paint.
* @param a The allocated region in which to render.
*/
@Override
public void paint(Graphics g, Shape a) {
@@ -726,15 +675,13 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
// System.out.println("SyntaxView: lines painted=" + count);
}
/**
* If the passed-in line is longer than the current longest line, then
* the longest line is updated.
* If the passed-in line is longer than the current longest line, then the
* longest line is updated.
*
* @param line
* The line to test against the current longest.
* @param lineNumber
* The line number of the passed-in line.
* @param line The line to test against the current longest.
* @param lineNumber The line number of the passed-in line.
* @return <code>true</code> iff the current longest line was updated.
*/
private boolean possiblyUpdateLongLine(Element line, int lineNumber) {
@@ -746,36 +693,31 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
return false;
}
/**
* Gives notification that something was removed from the document
* in a location that this view is responsible for.
* Gives notification that something was removed from the document in a location
* that this view is responsible for.
*
* @param changes
* the change information from the associated document
* @param a
* the current allocation of the view
* @param f
* the factory to use to rebuild if the view has children
* @param changes the change information from the associated document
* @param a the current allocation of the view
* @param f the factory to use to rebuild if the view has children
*/
@Override
public void removeUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
updateDamage(changes, a, f);
}
@Override
public void setSize(float width, float height) {
super.setSize(width, height);
updateMetrics();
}
/**
* Repaint the region of change covered by the given document
* event. Damages the line that begins the range to cover
* the case when the insert/remove is only on one line.
* If lines are added or removed, damages the whole
* view. The longest line is checked to see if it has
* changed.
* Repaint the region of change covered by the given document event. Damages the
* line that begins the range to cover the case when the insert/remove is only
* on one line. If lines are added or removed, damages the whole view. The
* longest line is checked to see if it has changed.
*/
protected void updateDamage(DocumentEvent changes, Shape a, ViewFactory f) {
Component host = getContainer();
@@ -841,7 +783,7 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
}
}
/**
* Checks to see if the font metrics and longest line are up-to-date.
*/
@@ -854,19 +796,16 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
calculateLongestLine();
}
}
/**
* Provides a mapping from the view coordinate space to the logical
* coordinate space of the model.
* Provides a mapping from the view coordinate space to the logical coordinate
* space of the model.
*
* @param fx
* the X coordinate &gt;= 0
* @param fy
* the Y coordinate &gt;= 0
* @param a
* the allocated region to render into
* @return the location within the model that best represents the
* given point in the view &gt;= 0
* @param fx the X coordinate &gt;= 0
* @param fy the Y coordinate &gt;= 0
* @param a the allocated region to render into
* @return the location within the model that best represents the given point in
* the view &gt;= 0
*/
@Override
public int viewToModel(float fx, float fy, Shape a, Position.Bias[] bias) {
@@ -918,7 +857,7 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
} // End of else.
}
/**
* {@inheritDoc}
*/
@@ -941,7 +880,7 @@ public class SyntaxView extends View implements TabExpander, TokenOrientedView,
}
return -1;
}
/**
* {@inheritDoc}
*/
@@ -28,8 +28,8 @@ import org.fife.io.UnicodeWriter;
import org.fife.ui.rtextarea.RTextAreaEditorKit;
/**
* An extension of {@link org.fife.ui.rsyntaxtextarea.RSyntaxTextArea}
* that adds information about the file being edited, such as:
* An extension of {@link org.fife.ui.rsyntaxtextarea.RSyntaxTextArea} that adds
* information about the file being edited, such as:
*
* <ul>
* <li>Its name and location.
@@ -43,10 +43,10 @@ import org.fife.ui.rtextarea.RTextAreaEditorKit;
* Loading and saving is also built into the editor.
* <p>
*
* When saving UTF-8 files, whether or not a BOM is written is controlled by
* the {@link UnicodeWriter} class.
* Use {@link UnicodeWriter#setWriteUtf8BOM(boolean)} to toggle writing BOMs
* for UTF-8 files.
* When saving UTF-8 files, whether or not a BOM is written is controlled by the
* {@link UnicodeWriter} class. Use
* {@link UnicodeWriter#setWriteUtf8BOM(boolean)} to toggle writing BOMs for
* UTF-8 files.
* <p>
*
* Both local and remote files (e.g. ftp) are supported. See the
@@ -57,11 +57,11 @@ import org.fife.ui.rtextarea.RTextAreaEditorKit;
* @see FileLocation
*/
public class TextEditorPane extends RSyntaxTextArea implements DocumentListener {
private static final long serialVersionUID = 1L;
/**
* Property change event fired when the file path this text area references
* is updated.
* Property change event fired when the file path this text area references is
* updated.
*
* @see #load(FileLocation, String)
* @see #saveAs(FileLocation)
@@ -103,9 +103,8 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
*/
private boolean dirty;
/**
* The last time this file was modified on disk, for local files.
* For remote files, this value should always be
* {@link #LAST_MODIFIED_UNKNOWN}.
* The last time this file was modified on disk, for local files. For remote
* files, this value should always be {@link #LAST_MODIFIED_UNKNOWN}.
*/
private long lastSaveOrLoadTime;
/**
@@ -116,34 +115,31 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
* The default name given to files if none is specified in a constructor.
*/
private static final String DEFAULT_FILE_NAME = "Untitled.txt";
/**
* Constructor. The file will be given a default name.
*/
public TextEditorPane() {
this(INSERT_MODE);
}
/**
* Constructor. The file will be given a default name.
*
* @param textMode
* Either <code>INSERT_MODE</code> or
* <code>OVERWRITE_MODE</code>.
* @param textMode Either <code>INSERT_MODE</code> or
* <code>OVERWRITE_MODE</code>.
*/
public TextEditorPane(int textMode) {
this(textMode, false);
}
/**
* Creates a new <code>TextEditorPane</code>. The file will be given
* a default name.
* Creates a new <code>TextEditorPane</code>. The file will be given a default
* name.
*
* @param textMode
* Either <code>INSERT_MODE</code> or
* <code>OVERWRITE_MODE</code>.
* @param wordWrapEnabled
* Whether or not to use word wrap in this pane.
* @param textMode Either <code>INSERT_MODE</code> or
* <code>OVERWRITE_MODE</code>.
* @param wordWrapEnabled Whether or not to use word wrap in this pane.
*/
public TextEditorPane(int textMode, boolean wordWrapEnabled) {
super(textMode);
@@ -154,69 +150,58 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
ioe.printStackTrace();
}
}
/**
* Creates a new <code>TextEditorPane</code>.
*
* @param textMode
* Either <code>INSERT_MODE</code> or
* <code>OVERWRITE_MODE</code>.
* @param wordWrapEnabled
* Whether or not to use word wrap in this pane.
* @param loc
* The location of the text file being edited. If this value
* is <code>null</code>, a file named "Untitled.txt" in the
* current
* directory is used.
* @throws IOException
* If an IO error occurs reading the file at
* <code>loc</code>. This of course won't happen if
* <code>loc</code> is <code>null</code>.
* @param textMode Either <code>INSERT_MODE</code> or
* <code>OVERWRITE_MODE</code>.
* @param wordWrapEnabled Whether or not to use word wrap in this pane.
* @param loc The location of the text file being edited. If this
* value is <code>null</code>, a file named
* "Untitled.txt" in the current directory is used.
* @throws IOException If an IO error occurs reading the file at
* <code>loc</code>. This of course won't happen if
* <code>loc</code> is <code>null</code>.
*/
public TextEditorPane(int textMode, boolean wordWrapEnabled, FileLocation loc) throws IOException {
this(textMode, wordWrapEnabled, loc, null);
}
/**
* Creates a new <code>TextEditorPane</code>.
*
* @param textMode
* Either <code>INSERT_MODE</code> or
* <code>OVERWRITE_MODE</code>.
* @param wordWrapEnabled
* Whether or not to use word wrap in this pane.
* @param loc
* The location of the text file being edited. If this value
* is <code>null</code>, a file named "Untitled.txt" in the
* current
* directory is used. This file is displayed as empty even if it
* actually exists.
* @param defaultEnc
* The default encoding to use when opening the file,
* if the file is not Unicode. If this value is
* <code>null</code>,
* a system default value is used.
* @throws IOException
* If an IO error occurs reading the file at
* <code>loc</code>. This of course won't happen if
* <code>loc</code> is <code>null</code>.
* @param textMode Either <code>INSERT_MODE</code> or
* <code>OVERWRITE_MODE</code>.
* @param wordWrapEnabled Whether or not to use word wrap in this pane.
* @param loc The location of the text file being edited. If this
* value is <code>null</code>, a file named
* "Untitled.txt" in the current directory is used. This
* file is displayed as empty even if it actually exists.
* @param defaultEnc The default encoding to use when opening the file, if
* the file is not Unicode. If this value is
* <code>null</code>, a system default value is used.
* @throws IOException If an IO error occurs reading the file at
* <code>loc</code>. This of course won't happen if
* <code>loc</code> is <code>null</code>.
*/
public TextEditorPane(int textMode, boolean wordWrapEnabled, FileLocation loc, String defaultEnc) throws IOException {
public TextEditorPane(int textMode, boolean wordWrapEnabled, FileLocation loc, String defaultEnc)
throws IOException {
super(textMode);
setLineWrap(wordWrapEnabled);
init(loc, defaultEnc);
}
/**
* Callback for when styles in the current document change.
* This method is never called.
* Callback for when styles in the current document change. This method is never
* called.
*
* @param e
* The document event.
* @param e The document event.
*/
@Override
public void changedUpdate(DocumentEvent e) {}
public void changedUpdate(DocumentEvent e) {
}
/**
* Returns the default encoding for this operating system.
*
@@ -239,7 +224,7 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
}
return encoding;
}
/**
* Returns the encoding to use when reading or writing this file.
*
@@ -249,7 +234,7 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
public String getEncoding() {
return charSet;
}
/**
* Returns the full path to this document.
*
@@ -258,7 +243,7 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
public String getFileFullPath() {
return loc == null ? null : loc.getFileFullPath();
}
/**
* Returns the file name of this document.
*
@@ -267,61 +252,58 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
public String getFileName() {
return loc == null ? null : loc.getFileName();
}
/**
* Returns the timestamp for when this file was last loaded or saved
* <em>by this editor pane</em>. If the file has been modified on disk by
* another process after it was loaded into this editor pane, this method
* will not return the actual file's last modified time.
* Returns the timestamp for when this file was last loaded or saved <em>by this
* editor pane</em>. If the file has been modified on disk by another process
* after it was loaded into this editor pane, this method will not return the
* actual file's last modified time.
* <p>
*
* For remote files, this method will always return
* {@link #LAST_MODIFIED_UNKNOWN}.
*
* @return The timestamp when this file was last loaded or saved by this
* editor pane, if it is a local file, or
* {@link #LAST_MODIFIED_UNKNOWN} if it is a remote file.
* @return The timestamp when this file was last loaded or saved by this editor
* pane, if it is a local file, or {@link #LAST_MODIFIED_UNKNOWN} if it
* is a remote file.
* @see #isModifiedOutsideEditor()
*/
public long getLastSaveOrLoadTime() {
return lastSaveOrLoadTime;
}
/**
* Returns the line separator used when writing this file (e.g.
* "<code>\n</code>", "<code>\r\n</code>", or "<code>\r</code>").
* <p>
*
* Note that this value is an <code>Object</code> and not a
* <code>String</code> as that is the way the {@link Document} interface
* defines its property values. If you always use
* {@link #setLineSeparator(String)} to modify this value, then the value
* returned from this method will always be a <code>String</code>.
* Note that this value is an <code>Object</code> and not a <code>String</code>
* as that is the way the {@link Document} interface defines its property
* values. If you always use {@link #setLineSeparator(String)} to modify this
* value, then the value returned from this method will always be a
* <code>String</code>.
*
* @return The line separator. If this value is <code>null</code>, then
* the system default line separator is used (usually the value
* of <code>System.getProperty("line.separator")</code>).
* @return The line separator. If this value is <code>null</code>, then the
* system default line separator is used (usually the value of
* <code>System.getProperty("line.separator")</code>).
* @see #setLineSeparator(String)
* @see #setLineSeparator(String, boolean)
*/
public Object getLineSeparator() {
return getDocument().getProperty(RTextAreaEditorKit.EndOfLineStringProperty);
}
/**
* Initializes this editor with the specified file location.
*
* @param loc
* The file location. If this is <code>null</code>, a default
* location is used and an empty file is displayed.
* @param defaultEnc
* The default encoding to use when opening the file,
* if the file is not Unicode. If this value is
* <code>null</code>,
* a system default value is used.
* @throws IOException
* If an IO error occurs reading from <code>loc</code>.
* If <code>loc</code> is <code>null</code>, this cannot happen.
* @param loc The file location. If this is <code>null</code>, a default
* location is used and an empty file is displayed.
* @param defaultEnc The default encoding to use when opening the file, if the
* file is not Unicode. If this value is <code>null</code>, a
* system default value is used.
* @throws IOException If an IO error occurs reading from <code>loc</code>. If
* <code>loc</code> is <code>null</code>, this cannot
* happen.
*/
private void init(FileLocation loc, String defaultEnc) throws IOException {
if (loc == null) {
@@ -347,12 +329,11 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
}
setDirty(false);
}
/**
* Callback for when text is inserted into the document.
*
* @param e
* Information on the insertion.
* @param e Information on the insertion.
*/
@Override
public void insertUpdate(DocumentEvent e) {
@@ -360,7 +341,7 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
setDirty(true);
}
}
/**
* Returns whether or not the text in this editor has unsaved changes.
*
@@ -370,7 +351,7 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
public boolean isDirty() {
return dirty;
}
/**
* Returns whether this file is a local file.
*
@@ -379,7 +360,7 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
public boolean isLocal() {
return loc.isLocal();
}
/**
* Returns whether this is a local file that already exists.
*
@@ -388,25 +369,24 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
public boolean isLocalAndExists() {
return loc.isLocalAndExists();
}
/**
* Returns whether the text file has been modified outside of this editor
* since the last load or save operation. Note that if this is a remote
* file, this method will always return <code>false</code>.
* Returns whether the text file has been modified outside of this editor since
* the last load or save operation. Note that if this is a remote file, this
* method will always return <code>false</code>.
* <p>
*
* This method may be used by applications to implement a reloading
* feature, where the user is prompted to reload a file if it has been
* modified since their last open or save.
* This method may be used by applications to implement a reloading feature,
* where the user is prompted to reload a file if it has been modified since
* their last open or save.
*
* @return Whether the text file has been modified outside of this
* editor.
* @return Whether the text file has been modified outside of this editor.
* @see #getLastSaveOrLoadTime()
*/
public boolean isModifiedOutsideEditor() {
return loc.getActualLastModified() > getLastSaveOrLoadTime();
}
/**
* Returns whether or not the text area should be treated as read-only.
*
@@ -416,22 +396,18 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
public boolean isReadOnly() {
return readOnly;
}
/**
* Loads the specified file in this editor. This method fires a property
* change event of type {@link #FULL_PATH_PROPERTY}.
* Loads the specified file in this editor. This method fires a property change
* event of type {@link #FULL_PATH_PROPERTY}.
*
* @param loc
* The location of the file to load. This cannot be
* <code>null</code>.
* @param defaultEnc
* The encoding to use when loading/saving the file.
* This encoding will only be used if the file is not Unicode.
* If this value is <code>null</code>, the system default
* encoding
* is used.
* @throws IOException
* If an IO error occurs.
* @param loc The location of the file to load. This cannot be
* <code>null</code>.
* @param defaultEnc The encoding to use when loading/saving the file. This
* encoding will only be used if the file is not Unicode. If
* this value is <code>null</code>, the system default
* encoding is used.
* @throws IOException If an IO error occurs.
* @see #save()
* @see #saveAs(FileLocation)
*/
@@ -468,25 +444,24 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
discardAllEdits();
firePropertyChange(FULL_PATH_PROPERTY, old, getFileFullPath());
}
/**
* Reloads this file from disk. The file must exist for this operation
* to not throw an exception.
* Reloads this file from disk. The file must exist for this operation to not
* throw an exception.
* <p>
*
* The file's "dirty" state will be set to <code>false</code> after this
* operation. If this is a local file, its "last modified" time is
* updated to reflect that of the actual file.
* operation. If this is a local file, its "last modified" time is updated to
* reflect that of the actual file.
* <p>
*
* Note that if the file has been modified on disk, and is now a Unicode
* encoding when before it wasn't (or if it is a different Unicode now),
* this will cause this {@link TextEditorPane}'s encoding to change.
* Otherwise, the file's encoding will stay the same.
* encoding when before it wasn't (or if it is a different Unicode now), this
* will cause this {@link TextEditorPane}'s encoding to change. Otherwise, the
* file's encoding will stay the same.
*
* @throws IOException
* If the file does not exist, or if an IO error
* occurs reading the file.
* @throws IOException If the file does not exist, or if an IO error occurs
* reading the file.
* @see #isLocalAndExists()
*/
public void reload() throws IOException {
@@ -504,12 +479,11 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
syncLastSaveOrLoadTimeToActualFile();
discardAllEdits(); // Prevent user from being able to undo the reload
}
/**
* Called whenever text is removed from this editor.
*
* @param e
* The document event.
* @param e The document event.
*/
@Override
public void removeUpdate(DocumentEvent e) {
@@ -517,16 +491,15 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
setDirty(true);
}
}
/**
* Saves the file in its current encoding.
* <p>
*
* The text area's "dirty" state is set to <code>false</code>, and if
* this is a local file, its "last modified" time is updated.
* The text area's "dirty" state is set to <code>false</code>, and if this is a
* local file, its "last modified" time is updated.
*
* @throws IOException
* If an IO error occurs.
* @throws IOException If an IO error occurs.
* @see #saveAs(FileLocation)
* @see #load(FileLocation, String)
*/
@@ -535,15 +508,13 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
setDirty(false);
syncLastSaveOrLoadTimeToActualFile();
}
/**
* Saves this file in a new local location. This method fires a property
* change event of type {@link #FULL_PATH_PROPERTY}.
* Saves this file in a new local location. This method fires a property change
* event of type {@link #FULL_PATH_PROPERTY}.
*
* @param loc
* The location to save to.
* @throws IOException
* If an IO error occurs.
* @param loc The location to save to.
* @throws IOException If an IO error occurs.
* @see #save()
* @see #load(FileLocation, String)
*/
@@ -556,14 +527,12 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
lastSaveOrLoadTime = loc.getActualLastModified();
firePropertyChange(FULL_PATH_PROPERTY, old, getFileFullPath());
}
/**
* Saves the text in this editor to the specified location.
*
* @param loc
* The location to save to.
* @throws IOException
* If an IO error occurs.
* @param loc The location to save to.
* @throws IOException If an IO error occurs.
*/
private void saveImpl(FileLocation loc) throws IOException {
OutputStream out = loc.getOutputStream();
@@ -574,23 +543,22 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
w.close();
}
}
/**
* Sets whether or not this text in this editor has unsaved changes.
* This fires a property change event of type {@link #DIRTY_PROPERTY}.
* Sets whether or not this text in this editor has unsaved changes. This fires
* a property change event of type {@link #DIRTY_PROPERTY}.
* <p>
*
* Applications will usually have no need to call this method directly; the
* only time you might have a need to call this method directly is if you
* have to initialize an instance of TextEditorPane with content that does
* not come from a file. <code>TextEditorPane</code> automatically sets its
* own dirty flag when its content is edited, when its encoding is changed,
* or when its line ending property is changed. It is cleared whenever
* <code>load()</code>, <code>reload()</code>, <code>save()</code>, or
* <code>saveAs()</code> are called.
* Applications will usually have no need to call this method directly; the only
* time you might have a need to call this method directly is if you have to
* initialize an instance of TextEditorPane with content that does not come from
* a file. <code>TextEditorPane</code> automatically sets its own dirty flag
* when its content is edited, when its encoding is changed, or when its line
* ending property is changed. It is cleared whenever <code>load()</code>,
* <code>reload()</code>, <code>save()</code>, or <code>saveAs()</code> are
* called.
*
* @param dirty
* Whether or not the text has been modified.
* @param dirty Whether or not the text has been modified.
* @see #isDirty()
*/
public void setDirty(boolean dirty) {
@@ -599,12 +567,11 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
firePropertyChange(DIRTY_PROPERTY, !dirty, dirty);
}
}
/**
* Sets the document for this editor.
*
* @param doc
* The new document.
* @param doc The new document.
*/
@Override
public void setDocument(Document doc) {
@@ -615,19 +582,16 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
super.setDocument(doc);
doc.addDocumentListener(this);
}
/**
* Sets the encoding to use when reading or writing this file. This
* method sets the editor's dirty flag when the encoding is changed, and
* fires a property change event of type {@link #ENCODING_PROPERTY}.
* Sets the encoding to use when reading or writing this file. This method sets
* the editor's dirty flag when the encoding is changed, and fires a property
* change event of type {@link #ENCODING_PROPERTY}.
*
* @param encoding
* The new encoding.
* @throws UnsupportedCharsetException
* If the encoding is not supported.
* @throws NullPointerException
* If <code>encoding</code> is
* <code>null</code>.
* @param encoding The new encoding.
* @throws UnsupportedCharsetException If the encoding is not supported.
* @throws NullPointerException If <code>encoding</code> is
* <code>null</code>.
* @see #getEncoding()
*/
public void setEncoding(String encoding) {
@@ -643,50 +607,43 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
setDirty(true);
}
}
/**
* Sets the line separator sequence to use when this file is saved (e.g.
* "<code>\n</code>", "<code>\r\n</code>" or "<code>\r</code>").
*
* Besides parameter checking, this method is preferred over
* <code>getDocument().putProperty()</code> because it sets the editor's
* dirty flag when the line separator is changed.
* <code>getDocument().putProperty()</code> because it sets the editor's dirty
* flag when the line separator is changed.
*
* @param separator
* The new line separator.
* @throws NullPointerException
* If <code>separator</code> is
* <code>null</code>.
* @throws IllegalArgumentException
* If <code>separator</code> is not one
* of "<code>\n</code>", "<code>\r\n</code>" or
* "<code>\r</code>".
* @param separator The new line separator.
* @throws NullPointerException If <code>separator</code> is
* <code>null</code>.
* @throws IllegalArgumentException If <code>separator</code> is not one of
* "<code>\n</code>", "<code>\r\n</code>" or
* "<code>\r</code>".
* @see #getLineSeparator()
*/
public void setLineSeparator(String separator) {
setLineSeparator(separator, true);
}
/**
* Sets the line separator sequence to use when this file is saved (e.g.
* "<code>\n</code>", "<code>\r\n</code>" or "<code>\r</code>").
*
* Besides parameter checking, this method is preferred over
* <code>getDocument().putProperty()</code> because can set the editor's
* dirty flag when the line separator is changed.
* <code>getDocument().putProperty()</code> because can set the editor's dirty
* flag when the line separator is changed.
*
* @param separator
* The new line separator.
* @param setDirty
* Whether the dirty flag should be set if the line
* separator is changed.
* @throws NullPointerException
* If <code>separator</code> is
* <code>null</code>.
* @throws IllegalArgumentException
* If <code>separator</code> is not one
* of "<code>\n</code>", "<code>\r\n</code>" or
* "<code>\r</code>".
* @param separator The new line separator.
* @param setDirty Whether the dirty flag should be set if the line separator
* is changed.
* @throws NullPointerException If <code>separator</code> is
* <code>null</code>.
* @throws IllegalArgumentException If <code>separator</code> is not one of
* "<code>\n</code>", "<code>\r\n</code>" or
* "<code>\r</code>".
* @see #getLineSeparator()
*/
public void setLineSeparator(String separator, boolean setDirty) {
@@ -705,13 +662,12 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
}
}
}
/**
* Sets whether or not this text area should be treated as read-only.
* This fires a property change event of type {@link #READ_ONLY_PROPERTY}.
* Sets whether or not this text area should be treated as read-only. This fires
* a property change event of type {@link #READ_ONLY_PROPERTY}.
*
* @param readOnly
* Whether or not the document is read-only.
* @param readOnly Whether or not the document is read-only.
* @see #isReadOnly()
*/
public void setReadOnly(boolean readOnly) {
@@ -720,16 +676,16 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
firePropertyChange(READ_ONLY_PROPERTY, !readOnly, readOnly);
}
}
/**
* Syncs this text area's "last saved or loaded" time to that of the file
* being edited, if that file is local and exists. If the file is
* remote or is local but does not yet exist, nothing happens.
* Syncs this text area's "last saved or loaded" time to that of the file being
* edited, if that file is local and exists. If the file is remote or is local
* but does not yet exist, nothing happens.
* <p>
*
* You normally do not have to call this method, as the "last saved or
* loaded" time for {@link TextEditorPane}s is kept up-to-date internally
* during such operations as {@link #save()}, {@link #reload()}, etc.
* You normally do not have to call this method, as the "last saved or loaded"
* time for {@link TextEditorPane}s is kept up-to-date internally during such
* operations as {@link #save()}, {@link #reload()}, etc.
*
* @see #getLastSaveOrLoadTime()
* @see #isModifiedOutsideEditor()
@@ -739,7 +695,7 @@ public class TextEditorPane extends RSyntaxTextArea implements DocumentListener
lastSaveOrLoadTime = loc.getActualLastModified();
}
}
public static void main(String[] args) throws Exception {
try {
TextEditorPane textArea = new TextEditorPane();
+191 -244
View File
@@ -38,195 +38,173 @@ import javax.swing.text.TabExpander;
* @version 0.3
*/
public interface Token extends TokenTypes {
/**
* Appends HTML code for painting this token, using the given text area's
* color scheme.
* Appends HTML code for painting this token, using the given text area's color
* scheme.
*
* @param sb
* The buffer to append to.
* @param textArea
* The text area whose color scheme to use.
* @param fontFamily
* Whether to include the font family in the HTML for
* this token. You can pass <code>false</code> for this parameter
* if, for example, you are making all your HTML be monospaced,
* and don't want any crazy fonts being used in the editor to be
* reflected in your HTML.
* @param sb The buffer to append to.
* @param textArea The text area whose color scheme to use.
* @param fontFamily Whether to include the font family in the HTML for this
* token. You can pass <code>false</code> for this parameter
* if, for example, you are making all your HTML be
* monospaced, and don't want any crazy fonts being used in
* the editor to be reflected in your HTML.
* @return The buffer appended to.
* @see #getHTMLRepresentation(RSyntaxTextArea)
*/
StringBuilder appendHTMLRepresentation(StringBuilder sb, RSyntaxTextArea textArea, boolean fontFamily);
/**
* Appends HTML code for painting this token, using the given text area's
* color scheme.
* Appends HTML code for painting this token, using the given text area's color
* scheme.
*
* @param sb
* The buffer to append to.
* @param textArea
* The text area whose color scheme to use.
* @param fontFamily
* Whether to include the font family in the HTML for
* this token. You can pass <code>false</code> for this parameter
* if, for example, you are making all your HTML be monospaced,
* and don't want any crazy fonts being used in the editor to be
* reflected in your HTML.
* @param tabsToSpaces
* Whether to convert tabs into spaces.
* @param sb The buffer to append to.
* @param textArea The text area whose color scheme to use.
* @param fontFamily Whether to include the font family in the HTML for this
* token. You can pass <code>false</code> for this parameter
* if, for example, you are making all your HTML be
* monospaced, and don't want any crazy fonts being used in
* the editor to be reflected in your HTML.
* @param tabsToSpaces Whether to convert tabs into spaces.
* @return The buffer appended to.
* @see #getHTMLRepresentation(RSyntaxTextArea)
*/
StringBuilder appendHTMLRepresentation(StringBuilder sb, RSyntaxTextArea textArea, boolean fontFamily, boolean tabsToSpaces);
StringBuilder appendHTMLRepresentation(StringBuilder sb, RSyntaxTextArea textArea, boolean fontFamily,
boolean tabsToSpaces);
/**
* Returns the character at the specified offset in the token.
*
* @param index
* The index. This should be in the range
* <code>0-({@link #length()}-1)</code>.
* @param index The index. This should be in the range
* <code>0-({@link #length()}-1)</code>.
* @return The character.
* @see #length()
*/
char charAt(int index);
/**
* Returns whether the token straddles the specified position in the
* document.
* Returns whether the token straddles the specified position in the document.
*
* @param pos
* The position in the document to check.
* @param pos The position in the document to check.
* @return Whether the specified position is straddled by this token.
*/
boolean containsPosition(int pos);
/**
* Returns the position in the token's internal char array corresponding
* to the specified document position.
* Returns the position in the token's internal char array corresponding to the
* specified document position.
* <p>
* Note that this method does NOT do any bounds checking; you can pass in
* a document position that does not correspond to a position in this
* token, and you will not receive an Exception or any other notification;
* it is up to the caller to ensure valid input.
* Note that this method does NOT do any bounds checking; you can pass in a
* document position that does not correspond to a position in this token, and
* you will not receive an Exception or any other notification; it is up to the
* caller to ensure valid input.
*
* @param pos
* A position in the document that is represented by this token.
* @return The corresponding token position &gt;= <code>textOffset</code>
* and &lt; <code>textOffset+textCount</code>.
* @param pos A position in the document that is represented by this token.
* @return The corresponding token position &gt;= <code>textOffset</code> and
* &lt; <code>textOffset+textCount</code>.
* @see #tokenToDocument
*/
int documentToToken(int pos);
/**
* Returns whether this token's lexeme ends with the specified characters.
*
* @param ch
* The characters.
* @param ch The characters.
* @return Whether this token's lexeme ends with the specified characters.
* @see #startsWith(char[])
*/
boolean endsWith(char[] ch);
/**
* Returns the end offset of this token in the document (exclusive). In
* other words, the token ranges from
* <code>[getOffset(), getEndOffset())</code>.
* Returns the end offset of this token in the document (exclusive). In other
* words, the token ranges from <code>[getOffset(), getEndOffset())</code>.
*
* @return The end offset of this token.
* @see #getOffset()
*/
int getEndOffset();
/**
* Returns a <code>String</code> containing HTML code for painting this
* token, using the given text area's color scheme.
* Returns a <code>String</code> containing HTML code for painting this token,
* using the given text area's color scheme.
*
* @param textArea
* The text area whose color scheme to use.
* @param textArea The text area whose color scheme to use.
* @return The HTML representation of the token.
* @see #appendHTMLRepresentation(StringBuilder, RSyntaxTextArea, boolean)
*/
String getHTMLRepresentation(RSyntaxTextArea textArea);
/**
* Returns the language index of this token.
*
* @return The language index. A value of <code>0</code> denotes the
* "main" language, any positive value denotes a specific secondary
* language.
* @return The language index. A value of <code>0</code> denotes the "main"
* language, any positive value denotes a specific secondary language.
* @see #setLanguageIndex(int)
*/
int getLanguageIndex();
/**
* Returns the last token in this list that is not whitespace or a
* comment.
* Returns the last token in this list that is not whitespace or a comment.
*
* @return The last non-comment, non-whitespace token, or <code>null</code>
* if there isn't one.
* @return The last non-comment, non-whitespace token, or <code>null</code> if
* there isn't one.
*/
Token getLastNonCommentNonWhitespaceToken();
/**
* Returns the last paintable token in this token list, or <code>null</code>
* if there is no paintable token.
* Returns the last paintable token in this token list, or <code>null</code> if
* there is no paintable token.
*
* @return The last paintable token in this token list.
*/
Token getLastPaintableToken();
/**
* Returns the text of this token, as a string.
* <p>
*
* Note that this method isn't used much by the
* <code>ryntaxtextarea</code> package internally, as it tries to limit
* memory allocation.
* Note that this method isn't used much by the <code>ryntaxtextarea</code>
* package internally, as it tries to limit memory allocation.
*
* @return The text of this token.
*/
String getLexeme();
/**
* Determines the offset into this token list (i.e., into the
* document) that covers pixel location <code>x</code> if the token list
* starts at pixel location <code>x0</code>
* Determines the offset into this token list (i.e., into the document) that
* covers pixel location <code>x</code> if the token list starts at pixel
* location <code>x0</code>
* <p>
* .
* This method will return the document position "closest" to the
* x-coordinate (i.e., if they click on the "right-half" of the
* <code>w</code> in <code>awe</code>, the caret will be placed in
* between the <code>w</code> and <code>e</code>; similarly, clicking on
* the left-half places the caret between the <code>a</code> and
* <code>w</code>). This makes it useful for methods such as
* <code>viewToModel</code> found in <code>javax.swing.text.View</code>
* . This method will return the document position "closest" to the x-coordinate
* (i.e., if they click on the "right-half" of the <code>w</code> in
* <code>awe</code>, the caret will be placed in between the <code>w</code> and
* <code>e</code>; similarly, clicking on the left-half places the caret between
* the <code>a</code> and <code>w</code>). This makes it useful for methods such
* as <code>viewToModel</code> found in <code>javax.swing.text.View</code>
* subclasses.
*
* @param textArea
* The text area from which the token list was derived.
* @param e
* How to expand tabs.
* @param x0
* The pixel x-location that is the beginning of
* <code>tokenList</code>.
* @param x
* The pixel-position for which you want to get the corresponding
* offset.
* @return The position (in the document, NOT into the token list!) that
* covers the pixel location. If <code>tokenList</code> is
* <code>null</code> or has type <code>Token.NULL</code>, then
* <code>-1</code> is returned; the caller should recognize this and
* return the actual end position of the (empty) line.
* @param textArea The text area from which the token list was derived.
* @param e How to expand tabs.
* @param x0 The pixel x-location that is the beginning of
* <code>tokenList</code>.
* @param x The pixel-position for which you want to get the
* corresponding offset.
* @return The position (in the document, NOT into the token list!) that covers
* the pixel location. If <code>tokenList</code> is <code>null</code> or
* has type <code>Token.NULL</code>, then <code>-1</code> is returned;
* the caller should recognize this and return the actual end position
* of the (empty) line.
*/
int getListOffset(RSyntaxTextArea textArea, TabExpander e, float x0, float x);
/**
* Returns the token after this one in the linked list.
*
* @return The next token.
*/
Token getNextToken();
/**
* Returns the offset into the document at which this token resides.
*
@@ -234,49 +212,43 @@ public interface Token extends TokenTypes {
* @see #getEndOffset()
*/
int getOffset();
/**
* Returns the position in the document that represents the last character
* in the token that will fit into <code>endBeforeX-startX</code> pixels.
* For example, if you're using a monospaced 8-pixel-per-character font,
* have the token "while" and <code>startX</code> is <code>0</code> and
* Returns the position in the document that represents the last character in
* the token that will fit into <code>endBeforeX-startX</code> pixels. For
* example, if you're using a monospaced 8-pixel-per-character font, have the
* token "while" and <code>startX</code> is <code>0</code> and
* <code>endBeforeX</code> is <code>30</code>, this method will return the
* document position of the "i" in "while", because the "i" ends at pixel
* <code>24</code>, while the "l" ends at <code>32</code>. If not even the
* first character fits in <code>endBeforeX-startX</code>, the first
* character's position is still returned so calling methods don't go into
* infinite loops.
* <code>24</code>, while the "l" ends at <code>32</code>. If not even the first
* character fits in <code>endBeforeX-startX</code>, the first character's
* position is still returned so calling methods don't go into infinite loops.
*
* @param textArea
* The text area in which this token is being painted.
* @param e
* How to expand tabs.
* @param startX
* The x-coordinate at which the token will be painted. This
* is needed because of tabs.
* @param endBeforeX
* The x-coordinate for which you want to find the last
* character of <code>t</code> which comes before it.
* @return The last document position that will fit in the specified amount
* of pixels.
* @param textArea The text area in which this token is being painted.
* @param e How to expand tabs.
* @param startX The x-coordinate at which the token will be painted. This
* is needed because of tabs.
* @param endBeforeX The x-coordinate for which you want to find the last
* character of <code>t</code> which comes before it.
* @return The last document position that will fit in the specified amount of
* pixels.
*/
/*
* @see #getTokenListOffsetBeforeX
* FIXME: This method does not compute correctly! It needs to be abstract
* and implemented by subclasses.
* @see #getTokenListOffsetBeforeX FIXME: This method does not compute
* correctly! It needs to be abstract and implemented by subclasses.
*/
int getOffsetBeforeX(RSyntaxTextArea textArea, TabExpander e, float startX, float endBeforeX);
/**
* Returns the character array backing the lexeme of this token. This
* value should be treated as read-only.
* Returns the character array backing the lexeme of this token. This value
* should be treated as read-only.
*
* @return A character array containing the lexeme of this token.
* @see #getTextOffset()
* @see #length()
*/
char[] getTextArray();
/**
* Returns the offset into the character array of the lexeme in
* {@link #getTextArray()}.
@@ -285,7 +257,7 @@ public interface Token extends TokenTypes {
* @see #getTextArray()
*/
int getTextOffset();
/**
* Returns the type of this token.
*
@@ -294,47 +266,39 @@ public interface Token extends TokenTypes {
* @see #setType(int)
*/
int getType();
/**
* Returns the width of this token given the specified parameters.
*
* @param textArea
* The text area in which the token is being painted.
* @param e
* Describes how to expand tabs. This parameter cannot be
* <code>null</code>.
* @param x0
* The pixel-location at which the token begins. This is needed
* because of tabs.
* @param textArea The text area in which the token is being painted.
* @param e Describes how to expand tabs. This parameter cannot be
* <code>null</code>.
* @param x0 The pixel-location at which the token begins. This is needed
* because of tabs.
* @return The width of the token, in pixels.
* @see #getWidthUpTo
*/
float getWidth(RSyntaxTextArea textArea, TabExpander e, float x0);
/**
* Returns the width of a specified number of characters in this token.
* For example, for the token "while", specifying a value of <code>3</code>
* here returns the width of the "whi" portion of the token.
* Returns the width of a specified number of characters in this token. For
* example, for the token "while", specifying a value of <code>3</code> here
* returns the width of the "whi" portion of the token.
*
* @param numChars
* The number of characters for which to get the width.
* @param textArea
* The text area in which the token is being painted.
* @param e
* How to expand tabs. This value cannot be <code>null</code>.
* @param x0
* The pixel-location at which this token begins. This is needed
* because of tabs.
* @param numChars The number of characters for which to get the width.
* @param textArea The text area in which the token is being painted.
* @param e How to expand tabs. This value cannot be <code>null</code>.
* @param x0 The pixel-location at which this token begins. This is needed
* because of tabs.
* @return The width of the specified number of characters in this token.
* @see #getWidth
*/
float getWidthUpTo(int numChars, RSyntaxTextArea textArea, TabExpander e, float x0);
/**
* Returns whether this token's lexeme matches a specific character array.
*
* @param lexeme
* The lexeme to check for.
* @param lexeme The lexeme to check for.
* @return Whether this token has that lexeme.
* @see #is(int, char[])
* @see #is(int, String)
@@ -342,19 +306,17 @@ public interface Token extends TokenTypes {
* @see #startsWith(char[])
*/
boolean is(char[] lexeme);
/**
* Returns whether this token is of the specified type, with the specified
* lexeme.
* <p>
* This method is preferred over the other overload in performance-critical
* code where this operation may be called frequently, since it does not
* involve any String allocations.
* This method is preferred over the other overload in performance-critical code
* where this operation may be called frequently, since it does not involve any
* String allocations.
*
* @param type
* The type to check for.
* @param lexeme
* The lexeme to check for.
* @param type The type to check for.
* @param lexeme The lexeme to check for.
* @return Whether this token has that type and lexeme.
* @see #is(int, String)
* @see #is(char[])
@@ -362,26 +324,24 @@ public interface Token extends TokenTypes {
* @see #startsWith(char[])
*/
boolean is(int type, char[] lexeme);
/**
* Returns whether this token is of the specified type, with the specified
* lexeme.
* <p>
* The other overload of this method is preferred over this one in
* performance-critical code, as this one involves a String allocation
* while the other does not.
* performance-critical code, as this one involves a String allocation while the
* other does not.
*
* @param type
* The type to check for.
* @param lexeme
* The lexeme to check for.
* @param type The type to check for.
* @param lexeme The lexeme to check for.
* @return Whether this token has that type and lexeme.
* @see #is(int, char[])
* @see #isSingleChar(int, char)
* @see #startsWith(char[])
*/
boolean is(int type, String lexeme);
/**
* Returns whether this token is a comment.
*
@@ -390,7 +350,7 @@ public interface Token extends TokenTypes {
* @see #isCommentOrWhitespace()
*/
boolean isComment();
/**
* Returns whether this token is a comment or whitespace.
*
@@ -399,7 +359,7 @@ public interface Token extends TokenTypes {
* @see #isWhitespace()
*/
boolean isCommentOrWhitespace();
/**
* Returns whether this token is a hyperlink.
*
@@ -407,23 +367,23 @@ public interface Token extends TokenTypes {
* @see #setHyperlink(boolean)
*/
boolean isHyperlink();
/**
* Returns whether this token is an identifier.
*
* @return Whether this token is an identifier.
*/
boolean isIdentifier();
/**
* Returns whether this token is a {@link #SEPARATOR} representing a single
* left curly brace.
* Returns whether this token is a {@link #SEPARATOR} representing a single left
* curly brace.
*
* @return Whether this token is a left curly brace.
* @see #isRightCurly()
*/
boolean isLeftCurly();
/**
* Returns whether this token is a {@link #SEPARATOR} representing a single
* right curly brace.
@@ -432,41 +392,38 @@ public interface Token extends TokenTypes {
* @see #isLeftCurly()
*/
boolean isRightCurly();
/**
* Returns whether or not this token is "paintable;" i.e., whether or not
* the type of this token is one such that it has an associated syntax
* style. What this boils down to is whether the token type is greater
* than <code>Token.NULL</code>.
* Returns whether or not this token is "paintable;" i.e., whether or not the
* type of this token is one such that it has an associated syntax style. What
* this boils down to is whether the token type is greater than
* <code>Token.NULL</code>.
*
* @return Whether or not this token is paintable.
*/
boolean isPaintable();
/**
* Returns whether this token is the specified single character.
*
* @param ch
* The character to check for.
* @param ch The character to check for.
* @return Whether this token's lexeme is the single character specified.
* @see #isSingleChar(int, char)
*/
boolean isSingleChar(char ch);
/**
* Returns whether this token is the specified single character, and of a
* specific type.
*
* @param type
* The token type.
* @param ch
* The character to check for.
* @param type The token type.
* @param ch The character to check for.
* @return Whether this token is of the specified type, and with a lexeme
* Equaling the single character specified.
* @see #isSingleChar(char)
*/
boolean isSingleChar(int type, char ch);
/**
* Returns whether or not this token is whitespace.
*
@@ -475,7 +432,7 @@ public interface Token extends TokenTypes {
* @see #isCommentOrWhitespace()
*/
boolean isWhitespace();
/**
* Returns the length of this token.
*
@@ -483,87 +440,77 @@ public interface Token extends TokenTypes {
* @see #getOffset()
*/
int length();
/**
* Returns the bounding box for the specified document location. The
* location must be in the specified token list; if it isn't,
* <code>null</code> is returned.
* Returns the bounding box for the specified document location. The location
* must be in the specified token list; if it isn't, <code>null</code> is
* returned.
*
* @param textArea
* The text area from which the token list was derived.
* @param e
* How to expand tabs.
* @param pos
* The position in the document for which to get the bounding
* box in the view.
* @param x0
* The pixel x-location that is the beginning of
* <code>tokenList</code>.
* @param rect
* The rectangle in which we'll be returning the results. This
* object is reused to keep from frequent memory allocations.
* @param textArea The text area from which the token list was derived.
* @param e How to expand tabs.
* @param pos The position in the document for which to get the bounding
* box in the view.
* @param x0 The pixel x-location that is the beginning of
* <code>tokenList</code>.
* @param rect The rectangle in which we'll be returning the results. This
* object is reused to keep from frequent memory allocations.
* @return The bounding box for the specified position in the model.
*/
Rectangle listOffsetToView(RSyntaxTextArea textArea, TabExpander e, int pos, int x0, Rectangle rect);
/**
* Sets whether this token is a hyperlink.
*
* @param hyperlink
* Whether this token is a hyperlink.
* @param hyperlink Whether this token is a hyperlink.
* @see #isHyperlink()
*/
void setHyperlink(boolean hyperlink);
/**
* Sets the language index for this token. If this value is positive, it
* denotes a specific "secondary" language this token represents (such as
* JavaScript code or CSS embedded in an HTML file). If this value is
* <code>0</code>, this token is in the "main" language being edited.
* Negative values are invalid and treated as <code>0</code>.
* Sets the language index for this token. If this value is positive, it denotes
* a specific "secondary" language this token represents (such as JavaScript
* code or CSS embedded in an HTML file). If this value is <code>0</code>, this
* token is in the "main" language being edited. Negative values are invalid and
* 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>.
* @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()
*/
void setLanguageIndex(int languageIndex);
/**
* Sets the type of this token.
*
* @param type
* The new token type.
* @param type The new token type.
* @see TokenTypes
* @see #getType()
*/
void setType(int type);
/**
* Returns whether this token starts with the specified characters.
*
* @param chars
* The characters.
* @param chars The characters.
* @return Whether this token starts with those characters.
* @see #endsWith(char[])
* @see #is(int, char[])
*/
boolean startsWith(char[] chars);
/**
* Returns the position in the document corresponding to the specified
* position in this token's internal char array (<code>textOffset</code> -
* Returns the position in the document corresponding to the specified position
* in this token's internal char array (<code>textOffset</code> -
* <code>textOffset+textCount-1</code>).
* <p>
* Note that this method does NOT do any bounds checking; you can pass in
* an invalid token position, and you will not receive an Exception or any
* other indication that the returned document position is invalid. It is
* up to the user to ensure valid input.
* Note that this method does NOT do any bounds checking; you can pass in an
* invalid token position, and you will not receive an Exception or any other
* indication that the returned document position is invalid. It is up to the
* user to ensure valid input.
*
* @param pos
* A position in the token's internal char array
* @param pos A position in the token's internal char array
* (<code>textOffset</code> - <code>textOffset+textCount</code>).
* @return The corresponding position in the document.
* @see #documentToToken(int)
@@ -15,52 +15,42 @@ import javax.swing.text.Segment;
* @version 0.1
*/
interface TokenFactory {
/**
* Returns a null token.
*
* @return A null token.
*/
TokenImpl createToken();
/**
* Returns a token.
*
* @param line
* The segment from which to get the token's text.
* @param beg
* The starting offset of the token's text in the segment.
* @param end
* The ending offset of the token's text in the segment.
* @param startOffset
* The offset in the document of the token.
* @param type
* The type of token.
* @param line The segment from which to get the token's text.
* @param beg The starting offset of the token's text in the segment.
* @param end The ending offset of the token's text in the segment.
* @param startOffset The offset in the document of the token.
* @param type The type of token.
* @return The token.
*/
TokenImpl createToken(final Segment line, final int beg, final int end, final int startOffset, final int type);
/**
* Returns a token.
*
* @param line
* The char array from which to get the token's text.
* @param beg
* The starting offset of the token's text in the char array.
* @param end
* The ending offset of the token's text in the char array.
* @param startOffset
* The offset in the document of the token.
* @param type
* The type of token.
* @param line The char array from which to get the token's text.
* @param beg The starting offset of the token's text in the char array.
* @param end The ending offset of the token's text in the char array.
* @param startOffset The offset in the document of the token.
* @param type The type of token.
* @return The token.
*/
TokenImpl createToken(final char[] line, final int beg, final int end, final int startOffset, final int type);
/**
* Resets the state of this token maker. This method should be called
* by the <code>TokenMaker</code> every time a token list is generated for
* a new line so the tokens can be reused.
* Resets the state of this token maker. This method should be called by the
* <code>TokenMaker</code> every time a token list is generated for a new line
* so the tokens can be reused.
*/
void resetAllTokens();
}
@@ -16,16 +16,15 @@ import java.util.Iterator;
* @version 1.0
*/
class TokenIterator implements Iterator<Token> {
private RSyntaxDocument doc;
private int curLine;
private Token token;
/**
* Constructor.
*
* @param doc
* The document whose tokens we should iterate over.
* @param doc The document whose tokens we should iterate over.
*/
TokenIterator(RSyntaxDocument doc) {
this.doc = doc;
@@ -36,11 +35,11 @@ class TokenIterator implements Iterator<Token> {
loadTokenListForCurLine();
}
}
private int getLineCount() {
return doc.getDefaultRootElement().getElementCount();
}
/**
* Returns whether any more paintable tokens are in the document.
*
@@ -51,7 +50,7 @@ class TokenIterator implements Iterator<Token> {
public boolean hasNext() {
return token != null;
}
private void loadTokenListForCurLine() {
token = doc.getTokenListForLine(curLine);
if (token != null && !token.isPaintable()) {
@@ -59,7 +58,7 @@ class TokenIterator implements Iterator<Token> {
token = null;
}
}
/**
* Returns the next paintable token in the document.
*
@@ -96,13 +95,12 @@ class TokenIterator implements Iterator<Token> {
}
return t;
}
/**
* Always throws {@link UnsupportedOperationException}, as
* <code>Token</code> removal is not supported.
* Always throws {@link UnsupportedOperationException}, as <code>Token</code>
* removal is not supported.
*
* @throws UnsupportedOperationException
* always.
* @throws UnsupportedOperationException always.
*/
@Override
public void remove() {
+84 -106
View File
@@ -12,8 +12,8 @@ import javax.swing.text.Segment;
/**
* An implementation of <code>TokenMaker</code> is a class that turns text into
* a linked list of <code>Token</code>s for syntax highlighting
* in a particular language.
* a linked list of <code>Token</code>s for syntax highlighting in a particular
* language.
*
* @see Token
* @see AbstractTokenMaker
@@ -22,164 +22,142 @@ import javax.swing.text.Segment;
* @version 0.2
*/
public interface TokenMaker {
/**
* Adds a null token to the end of the current linked list of tokens.
* This should be put at the end of the linked list whenever the last
* token on the current line is NOT a multi-line token.
* Adds a null token to the end of the current linked list of tokens. This
* should be put at the end of the linked list whenever the last token on the
* current line is NOT a multi-line token.
*/
public void addNullToken();
/**
* Adds the token specified to the current linked list of tokens.
*
* @param array
* The character array from which to get the text.
* @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 array The character array from which to get the text.
* @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(char[] array, int start, int end, int tokenType, int startOffset);
/**
* Returns the closest {@link TokenTypes "standard" token type} for a given
* "internal" token type (e.g. one whose value is <code>&lt; 0</code>).
*
* @param type
* The token type.
* @return The closest "standard" token type. If a mapping is not defined
* for this language, then <code>type</code> is returned.
* @param type The token type.
* @return The closest "standard" token type. If a mapping is not defined for
* this language, then <code>type</code> is returned.
*/
public int getClosestStandardTokenTypeForInternalType(int type);
/**
* Returns whether this programming language uses curly braces
* ('<code>{</code>' and '<code>}</code>') to denote code blocks.
* Returns whether this programming language uses curly braces ('<code>{</code>'
* and '<code>}</code>') to denote code blocks.
*
* @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.
*/
public boolean getCurlyBracesDenoteCodeBlocks(int languageIndex);
/**
* Returns the last token on this line's type if the token is "unfinished",
* or {@link Token#NULL} if it was finished. For example, if C-style
* syntax highlighting is being implemented, and <code>text</code>
* contained a line of code that contained the beginning of a comment but
* no end-comment marker ("*\/"), then this method would return
* {@link Token#COMMENT_MULTILINE} for that line. This is useful
* for doing syntax highlighting.
* Returns the last token on this line's type if the token is "unfinished", or
* {@link Token#NULL} if it was finished. For example, if C-style syntax
* highlighting is being implemented, and <code>text</code> contained a line of
* code that contained the beginning of a comment but no end-comment marker
* ("*\/"), then this method would return {@link Token#COMMENT_MULTILINE} for
* that line. This is useful for doing syntax highlighting.
*
* @param text
* The line of tokens to examine.
* @param initialTokenType
* The token type to start with (i.e., the value
* of <code>getLastTokenTypeOnLine</code> for the line before
* <code>text</code>).
* @return The last token on this line's type, or {@link Token#NULL}
* if the line was completed.
* @param text The line of tokens to examine.
* @param initialTokenType The token type to start with (i.e., the value of
* <code>getLastTokenTypeOnLine</code> for the line
* before <code>text</code>).
* @return The last token on this line's type, or {@link Token#NULL} if the line
* was completed.
*/
public int getLastTokenTypeOnLine(Segment text, int initialTokenType);
/**
* Returns the text to place at the beginning and end of a
* line to "comment" it in this programming language.
* Returns the text to place at the beginning and end of a line to "comment" it
* in this programming language.
*
* @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 The start and end strings to add to a line to "comment"
* it out. A <code>null</code> value for either means there
* is no string to add for that part. A value of
* <code>null</code> for the array means this language
* does not support commenting/uncommenting lines.
* @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 The start and end strings to add to a line to "comment" it out. A
* <code>null</code> value for either means there is no string to add
* for that part. A value of <code>null</code> for the array means this
* language does not support commenting/uncommenting lines.
*/
public String[] getLineCommentStartAndEnd(int languageIndex);
/**
* Returns an action to handle "insert break" key presses (i.e. Enter).
*
* @return The action, or <code>null</code> if the default action should
* be used.
* @return The action, or <code>null</code> if the default action should be
* used.
*/
public Action getInsertBreakAction();
/**
* Returns whether tokens of the specified type should have "mark
* occurrences" enabled for the current programming language.
* Returns whether tokens of the specified type should have "mark occurrences"
* enabled for the current programming language.
*
* @param type
* The token type.
* @return Whether tokens of this type should have "mark occurrences"
* enabled.
* @param type The token type.
* @return Whether tokens of this type should have "mark occurrences" enabled.
*/
public boolean getMarkOccurrencesOfTokenType(int type);
/**
* Returns the object in charge of marking all occurrences of the token
* at the current caret position, if it is a relevant token. If
* <code>null</code> is returned, a default <code>OccurrenceMarker</code>
* is used.
* Returns the object in charge of marking all occurrences of the token at the
* current caret position, if it is a relevant token. If <code>null</code> is
* returned, a default <code>OccurrenceMarker</code> is used.
*
* @return The occurrence marker for this language, or <code>null</code>
* for none.
* @return The occurrence marker for this language, or <code>null</code> for
* none.
*/
public OccurrenceMarker getOccurrenceMarker();
/**
* If a line ends in the specified token, this method returns whether
* a new line inserted after that line should be indented.
* If a line ends in the specified token, this method returns whether a new line
* inserted after that line should be indented.
*
* @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.
*/
public boolean getShouldIndentNextLineAfter(Token token);
/**
* Returns the first token in the linked list of tokens generated
* from <code>text</code>. This method must be implemented by
* subclasses so they can correctly implement syntax highlighting.
* Returns the first token in the linked list of tokens generated from
* <code>text</code>. This method must be implemented by subclasses so they can
* correctly implement syntax highlighting.
*
* @param text
* The text from which to get tokens.
* @param initialTokenType
* The token type we should start with.
* @param startOffset
* The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing
* the syntax highlighted text.
* @param text The text from which to get tokens.
* @param initialTokenType The token type we should start with.
* @param startOffset The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing the syntax
* highlighted text.
*/
public Token getTokenList(Segment text, int initialTokenType, int startOffset);
/**
* Returns whether a character could be part of an "identifier" token
* in a specific language. This is used to identify such things as the
* bounds of the "word" to select on double-clicking.
* Returns whether a character could be part of an "identifier" token in a
* specific language. This is used to identify such things as the bounds of the
* "word" to select on double-clicking.
*
* @param languageIndex
* The language index the character was found in.
* @param ch
* The character.
* @param languageIndex The language index the character was found in.
* @param ch The character.
* @return Whether the character could be part of an "identifier" token.
*/
public boolean isIdentifierChar(int languageIndex, char ch);
/**
* Returns whether this language is a markup language.
*
@@ -16,7 +16,7 @@ import javax.swing.text.Segment;
* @version 1.0
*/
public abstract class TokenMakerBase implements TokenMaker {
/**
* The first token in the returned linked list.
*/
@@ -34,20 +34,18 @@ public abstract class TokenMakerBase implements TokenMaker {
*/
private TokenFactory tokenFactory;
/**
* Highlights occurrences of the current token in the editor, if it is
* relevant.
* 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
* values imply various "secondary" or "embedded" languages, such as CSS
* 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.
* "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 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.
*/
@@ -55,7 +53,7 @@ public abstract class TokenMakerBase implements TokenMaker {
firstToken = currentToken = previousToken = null;
tokenFactory = new DefaultTokenFactory();
}
/**
* {@inheritDoc}
*/
@@ -72,26 +70,20 @@ 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);
}
/**
* {@inheritDoc}
*/
@@ -99,23 +91,16 @@ public abstract class TokenMakerBase implements TokenMaker {
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) {
@@ -130,59 +115,56 @@ public abstract class TokenMakerBase implements TokenMaker {
currentToken.setLanguageIndex(languageIndex);
currentToken.setHyperlink(hyperlink);
}
/**
* Returns the occurrence marker to use for this token maker. Subclasses
* can override to use different implementations.
* Returns the occurrence marker to use for this token maker. Subclasses can
* override to use different implementations.
*
* @return The occurrence marker to use.
*/
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>&lt; 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.
* 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.
* Returns whether this programming language uses curly braces ('<code>{</code>'
* and '<code>}</code>') to denote code blocks.
*
* 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
* can override.
* Returns an action to handle "insert break" key presses (i.e. Enter). The
* default implementation returns <code>null</code>. Subclasses can override.
*
* @return The default implementation always returns <code>null</code>.
*/
@@ -190,7 +172,7 @@ public abstract class TokenMakerBase implements TokenMaker {
public Action getInsertBreakAction() {
return null;
}
/**
* Returns the current language index.
*
@@ -200,7 +182,7 @@ public abstract class TokenMakerBase implements TokenMaker {
protected int getLanguageIndex() {
return languageIndex;
}
/**
* {@inheritDoc}
*/
@@ -213,7 +195,7 @@ public abstract class TokenMakerBase implements TokenMaker {
}
return t.getType();
}
/**
* {@inheritDoc}
*/
@@ -221,24 +203,22 @@ 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
* 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}.
* Returns whether tokens of the specified type should have "mark 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.
* @return Whether tokens of this type should have "mark occurrences"
* enabled.
* @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;
}
/**
* {@inheritDoc}
*/
@@ -249,34 +229,33 @@ public abstract class TokenMakerBase implements TokenMaker {
}
return occurrenceMarker;
}
/**
* The default implementation returns <code>false</code> always. Languages
* that wish to better support auto-indentation can override this method.
* 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
* <code>true</code> for letters, numbers, and certain symbols.
* Returns whether a character could be part of an "identifier" token 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 == '$';
}
/**
* The default implementation returns <code>false</code> always.
* Subclasses that are highlighting a markup language should override this
* method to return <code>true</code>.
* The default implementation returns <code>false</code> always. Subclasses that
* are highlighting a markup language should override this method to return
* <code>true</code>.
*
* @return <code>false</code> always.
*/
@@ -284,29 +263,27 @@ public abstract class TokenMakerBase implements TokenMaker {
public boolean isMarkupLanguage() {
return false;
}
/**
* 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
* 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
* {@link #getTokenList(Segment, int, int)}.
*/
protected void resetTokenList() {
firstToken = currentToken = previousToken = null;
tokenFactory.resetAllTokens();
}
/**
* 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).
* 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) {
@@ -18,10 +18,9 @@ import org.fife.ui.rsyntaxtextarea.modes.PlainTextTokenMaker;
* @version 1.0
*/
public abstract class TokenMakerFactory {
/**
* If this system property is set, a custom <code>TokenMakerFactory</code>
* of
* If this system property is set, a custom <code>TokenMakerFactory</code> of
* the specified class will be used as the default token maker factory.
*/
public static final String PROPERTY_DEFAULT_TOKEN_MAKER_FACTORY = "TokenMakerFactory";
@@ -29,7 +28,7 @@ public abstract class TokenMakerFactory {
* The singleton default <code>TokenMakerFactory</code> instance.
*/
private static TokenMakerFactory DEFAULT_INSTANCE;
/**
* Returns the default <code>TokenMakerFactory</code> instance. This is the
* factory used by all {@link RSyntaxDocument}s by default.
@@ -59,12 +58,11 @@ public abstract class TokenMakerFactory {
}
return DEFAULT_INSTANCE;
}
/**
* Returns a {@link TokenMaker} for the specified key.
*
* @param key
* The key.
* @param key The key.
* @return The corresponding <code>TokenMaker</code>, or
* {@link PlainTextTokenMaker} if none matches the specified key.
*/
@@ -75,36 +73,31 @@ public abstract class TokenMakerFactory {
}
return tm;
}
/**
* Returns a {@link TokenMaker} for the specified key.
*
* @param key
* The key.
* @return The corresponding <code>TokenMaker</code>, or <code>null</code>
* if
* @param key The key.
* @return The corresponding <code>TokenMaker</code>, or <code>null</code> if
* none matches the specified key.
*/
protected abstract TokenMaker getTokenMakerImpl(String key);
/**
* Returns the set of keys that this factory maps to token makers.
*
* @return The set of keys.
*/
public abstract Set<String> keySet();
/**
* Sets the default <code>TokenMakerFactory</code> instance. This is the
* factory
* Sets the default <code>TokenMakerFactory</code> instance. This is the factory
* used by all future {@link RSyntaxDocument}s by default.
* <code>RSyntaxDocument</code>s that have already been created are not
* affected.
*
* @param tmf
* The factory.
* @throws IllegalArgumentException
* If <code>tmf</code> is <code>null</code>.
* @param tmf The factory.
* @throws IllegalArgumentException If <code>tmf</code> is <code>null</code>.
* @see #getDefaultInstance()
*/
public static synchronized void setDefaultInstance(TokenMakerFactory tmf) {
+65 -85
View File
@@ -10,8 +10,8 @@ package org.fife.ui.rsyntaxtextarea;
import javax.swing.text.Segment;
/**
* A hash table for reserved words, etc. defined by a {@link TokenMaker}.
* This class is designed for the quick lookup of tokens, as it can compare
* A hash table for reserved words, etc. defined by a {@link TokenMaker}. This
* class is designed for the quick lookup of tokens, as it can compare
* <code>Segment</code>s without the need to allocate a new string.
* <p>
*
@@ -27,98 +27,86 @@ import javax.swing.text.Segment;
* @version 0.6
*/
public class TokenMap {
private int size;
private TokenMapToken[] tokenMap;
private boolean ignoreCase;
private static final int DEFAULT_TOKEN_MAP_SIZE = 52;
/**
* Constructs a new token map that is case-sensitive.
*/
public TokenMap() {
this(DEFAULT_TOKEN_MAP_SIZE);
}
/**
* Constructs a new token map that is case-sensitive.
*
* @param size
* The size of the token map.
* @param size The size of the token map.
*/
public TokenMap(int size) {
this(size, false);
}
/**
* Constructs a new token map.
*
* @param ignoreCase
* Whether or not this token map should ignore case
* when comparing tokens.
* @param ignoreCase Whether or not this token map should ignore case when
* comparing tokens.
*/
public TokenMap(boolean ignoreCase) {
this(DEFAULT_TOKEN_MAP_SIZE, ignoreCase);
}
/**
* Constructs a new token map.
*
* @param size
* The size of the token map.
* @param ignoreCase
* Whether or not this token map should ignore case
* when comparing tokens.
* @param size The size of the token map.
* @param ignoreCase Whether or not this token map should ignore case when
* comparing tokens.
*/
public TokenMap(int size, boolean ignoreCase) {
this.size = size;
tokenMap = new TokenMapToken[size];
this.ignoreCase = ignoreCase;
}
/**
* Adds a token to a specified bucket in the token map.
*
* @param bucket
* The bucket in which to add the token.
* @param token
* The token to add.
* @param bucket The bucket in which to add the token.
* @param token The token to add.
*/
private void addTokenToBucket(int bucket, TokenMapToken token) {
TokenMapToken old = tokenMap[bucket];
token.nextToken = old;
tokenMap[bucket] = token;
}
/**
* Returns the token type associated with the given text, if the given
* text is in this token map. If it isn't, <code>-1</code> is returned.
* Returns the token type associated with the given text, if the given text is
* in this token map. If it isn't, <code>-1</code> is returned.
*
* @param text
* The segment from which to get the text to compare.
* @param start
* The starting index in the segment of the text.
* @param end
* The ending index in the segment of the text.
* @return The token type associated with the given text, or
* <code>-1</code> if this token was not specified in this map.
* @param text The segment from which to get the text to compare.
* @param start The starting index in the segment of the text.
* @param end The ending index in the segment of the text.
* @return The token type associated with the given text, or <code>-1</code> if
* this token was not specified in this map.
*/
public int get(Segment text, int start, int end) {
return get(text.array, start, end);
}
/**
* Returns the token type associated with the given text, if the given
* text is in this token map. If it isn't, <code>-1</code> is returned.
* Returns the token type associated with the given text, if the given text is
* in this token map. If it isn't, <code>-1</code> is returned.
*
* @param array1
* An array of characters containing the text.
* @param start
* The starting index in the array of the text.
* @param end
* The ending index in the array of the text.
* @return The token type associated with the given text, or
* <code>-1</code> if this token was not specified in this map.
* @param array1 An array of characters containing the text.
* @param start The starting index in the array of the text.
* @param end The ending index in the array of the text.
* @return The token type associated with the given text, or <code>-1</code> if
* this token was not specified in this map.
*/
public int get(char[] array1, int start, int end) {
int length1 = end - start + 1;
@@ -129,14 +117,13 @@ public class TokenMap {
int offset1;
int length;
/*
* We check whether or not to ignore case before doing any looping to
* minimize the number of extraneous comparisons we do. This makes
* for slightly redundant code, but it'll be a little more efficient.
* We check whether or not to ignore case before doing any looping to minimize
* the number of extraneous comparisons we do. This makes for slightly redundant
* code, but it'll be a little more efficient.
*/
// If matches are case-sensitive (C, C++, Java, etc.)...
if (!ignoreCase) {
mainLoop:
while (token != null) {
mainLoop: while (token != null) {
if (token.length == length1) {
array2 = token.text;
offset2 = token.offset;
@@ -157,8 +144,7 @@ public class TokenMap {
// Note that all tokens saved in this map were converted to
// lower-case already.
else {
mainLoop2:
while (token != null) {
mainLoop2: while (token != null) {
if (token.length == length1) {
array2 = token.text;
offset2 = token.offset;
@@ -178,40 +164,36 @@ public class TokenMap {
// Didn't match any of the tokens in the bucket.
return -1;
}
/**
* Returns the hash code for a given string.
*
* @param text
* The text to hash.
* @param offset
* The offset into the text at which to start hashing.
* @param length
* The last character in the text to hash.
* @param text The text to hash.
* @param offset The offset into the text at which to start hashing.
* @param length The last character in the text to hash.
* @return The hash code.
*/
private int getHashCode(char[] text, int offset, int length) {
return (RSyntaxUtilities.toLowerCase(text[offset]) + RSyntaxUtilities.toLowerCase(text[offset + length - 1])) % size;
return (RSyntaxUtilities.toLowerCase(text[offset]) + RSyntaxUtilities.toLowerCase(text[offset + length - 1]))
% size;
}
/**
* Returns whether this token map ignores case when checking for tokens.
* This property is set in the constructor and cannot be changed, as this
* is an intrinsic property of a particular programming language.
* Returns whether this token map ignores case when checking for tokens. This
* property is set in the constructor and cannot be changed, as this is an
* intrinsic property of a particular programming language.
*
* @return Whether or not this token maker is ignoring case.
*/
protected boolean isIgnoringCase() {
return ignoreCase;
}
/**
* Adds a string to this token map.
*
* @param string
* The string to add.
* @param tokenType
* The type of token the string is.
* @param string The string to add.
* @param tokenType The type of token the string is.
*/
public void put(final String string, final int tokenType) {
if (isIgnoringCase()) {
@@ -220,44 +202,42 @@ public class TokenMap {
put(string.toCharArray(), tokenType);
}
}
/**
* Adds a string to this token map. The char array passed-in will be used
* as the actual data for the token, so it may well be modified (such as
* lower-casing it if <code>ignoreCase</code> is <code>true</code>). This
* shouldn't be an issue though as this method is only called from the
* public <code>put</code> method, which allocates a new char array.
* Adds a string to this token map. The char array passed-in will be used as the
* actual data for the token, so it may well be modified (such as lower-casing
* it if <code>ignoreCase</code> is <code>true</code>). This shouldn't be an
* issue though as this method is only called from the public <code>put</code>
* method, which allocates a new char array.
*
* @param string
* The string to add.
* @param tokenType
* The type of token the string is.
* @param string The string to add.
* @param tokenType The type of token the string is.
*/
private void put(char[] string, int tokenType) {
int hashCode = getHashCode(string, 0, string.length);
addTokenToBucket(hashCode, new TokenMapToken(string, tokenType));
}
/**
* The "token" used by a token map. Note that this isn't the same thing
* as the {@link Token} class, but it's basically a 1-1 correspondence
* for reserved words, etc.
* The "token" used by a token map. Note that this isn't the same thing as the
* {@link Token} class, but it's basically a 1-1 correspondence for reserved
* words, etc.
*/
private static final class TokenMapToken {
private char[] text;
private int offset;
private int length;
private int tokenType;
private TokenMapToken nextToken;
private TokenMapToken(char[] text, int tokenType) {
this.text = text;
this.offset = 0;
this.length = text.length;
this.tokenType = tokenType;
}
@Override
public String toString() {
return "[TokenMapToken: " + new String(text, offset, length) + "]";
@@ -22,36 +22,32 @@ package org.fife.ui.rsyntaxtextarea;
* @version 0.1
*/
public interface TokenOrientedView {
/**
* Returns a token list for the <i>physical</i> line above the physical
* line containing the specified offset into the document. Note that for
* a plain (non-wrapped) view, this is simply the token list for the
* logical line above the line containing <code>offset</code>, since lines
* are not wrapped. For a wrapped view, this may or may not be tokens from
* the same line.
* Returns a token list for the <i>physical</i> line above the physical line
* containing the specified offset into the document. Note that for a plain
* (non-wrapped) view, this is simply the token list for the logical line above
* the line containing <code>offset</code>, since lines are not wrapped. For a
* wrapped view, this may or may not be tokens from the same line.
*
* @param offset
* The offset in question.
* @return A token list for the physical (and in this view, logical) line
* before this one. If no physical line is above the one
* containing <code>offset</code>, <code>null</code> is returned.
* @param offset The offset in question.
* @return A token list for the physical (and in this view, logical) line before
* this one. If no physical line is above the one containing
* <code>offset</code>, <code>null</code> is returned.
*/
Token getTokenListForPhysicalLineAbove(int offset);
/**
* Returns a token list for the <i>physical</i> line below the physical
* line containing the specified offset into the document. Note that for
* a plain (non-wrapped) view, this is simply the token list for the
* logical line below the line containing <code>offset</code>, since lines
* are not wrapped. For a wrapped view, this may or may not be tokens from
* the same line.
* Returns a token list for the <i>physical</i> line below the physical line
* containing the specified offset into the document. Note that for a plain
* (non-wrapped) view, this is simply the token list for the logical line below
* the line containing <code>offset</code>, since lines are not wrapped. For a
* wrapped view, this may or may not be tokens from the same line.
*
* @param offset
* The offset in question.
* @return A token list for the physical (and in this view, logical) line
* after this one. If no physical line is after the one
* containing <code>offset</code>, <code>null</code> is returned.
* @param offset The offset in question.
* @return A token list for the physical (and in this view, logical) line after
* this one. If no physical line is after the one containing
* <code>offset</code>, <code>null</code> is returned.
*/
Token getTokenListForPhysicalLineBelow(int offset);
}
@@ -11,129 +11,99 @@ import java.awt.Graphics2D;
import javax.swing.text.TabExpander;
/**
* Renders tokens in an instance of {@link RSyntaxTextArea}. One instance
* may render tokens "regularly," another may render visible whitespace, for
* Renders tokens in an instance of {@link RSyntaxTextArea}. One instance may
* render tokens "regularly," another may render visible whitespace, for
* example.
*
* @author Robert Futrell
* @version 1.0
*/
interface TokenPainter {
/**
* Paints this token.
*
* @param token
* The token to render.
* @param g
* The graphics context in which to paint.
* @param x
* The x-coordinate at which to paint.
* @param y
* The y-coordinate at which to paint.
* @param host
* The text area this token is in.
* @param e
* How to expand tabs.
* @param token The token to render.
* @param g The graphics context in which to paint.
* @param x The x-coordinate at which to paint.
* @param y The y-coordinate at which to paint.
* @param host The text area this token is in.
* @param e How to expand tabs.
* @return The x-coordinate representing the end of the painted text.
*/
float paint(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e);
/**
* Paints this token.
*
* @param token
* The token to render.
* @param g
* The graphics context in which to paint.
* @param x
* The x-coordinate at which to paint.
* @param y
* The y-coordinate at which to paint.
* @param host
* The text area this token is in.
* @param e
* How to expand tabs.
* @param clipStart
* The left boundary of the clip rectangle in which we're
* painting. This optimizes painting by allowing us to not paint
* paint when this token is "to the left" of the clip rectangle.
* @param token The token to render.
* @param g The graphics context in which to paint.
* @param x The x-coordinate at which to paint.
* @param y The y-coordinate at which to paint.
* @param host The text area this token is in.
* @param e How to expand tabs.
* @param clipStart The left boundary of the clip rectangle in which we're
* painting. This optimizes painting by allowing us to not
* paint paint when this token is "to the left" of the clip
* rectangle.
* @return The x-coordinate representing the end of the painted text.
*/
float paint(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, float clipStart);
/**
* Paints this token.
*
* @param token
* The token to render.
* @param g
* The graphics context in which to paint.
* @param x
* The x-coordinate at which to paint.
* @param y
* The y-coordinate at which to paint.
* @param host
* The text area this token is in.
* @param e
* How to expand tabs.
* @param clipStart
* The left boundary of the clip rectangle in which we're
* painting. This optimizes painting by allowing us to not paint
* paint when this token is "to the left" of the clip rectangle.
* @param paintBG
* Whether to paint the background.
* @param token The token to render.
* @param g The graphics context in which to paint.
* @param x The x-coordinate at which to paint.
* @param y The y-coordinate at which to paint.
* @param host The text area this token is in.
* @param e How to expand tabs.
* @param clipStart The left boundary of the clip rectangle in which we're
* painting. This optimizes painting by allowing us to not
* paint paint when this token is "to the left" of the clip
* rectangle.
* @param paintBG Whether to paint the background.
* @return The x-coordinate representing the end of the painted text.
*/
float paint(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, float clipStart, boolean paintBG);
float paint(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, float clipStart,
boolean paintBG);
/**
* Paints this token as it should appear in a selected region of text
* (assuming painting with a selection-foreground color is enabled in the
* parent <code>RSyntaxTextArea</code>).
* Paints this token as it should appear in a selected region of text (assuming
* painting with a selection-foreground color is enabled in the parent
* <code>RSyntaxTextArea</code>).
*
* @param token
* The token to render.
* @param g
* The graphics context in which to paint.
* @param x
* The x-coordinate at which to paint.
* @param y
* The y-coordinate at which to paint.
* @param host
* The text area this token is in.
* @param e
* How to expand tabs.
* @param useSTC
* Whether to use the text area's "selected text color."
* @param token The token to render.
* @param g The graphics context in which to paint.
* @param x The x-coordinate at which to paint.
* @param y The y-coordinate at which to paint.
* @param host The text area this token is in.
* @param e How to expand tabs.
* @param useSTC Whether to use the text area's "selected text color."
* @return The x-coordinate representing the end of the painted text.
*/
float paintSelected(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, boolean useSTC);
float paintSelected(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e,
boolean useSTC);
/**
* Paints this token as it should appear in a selected region of text
* (assuming painting with a selection-foreground color is enabled in the
* parent <code>RSyntaxTextArea</code>).
* Paints this token as it should appear in a selected region of text (assuming
* painting with a selection-foreground color is enabled in the parent
* <code>RSyntaxTextArea</code>).
*
* @param token
* The token to render.
* @param g
* The graphics context in which to paint.
* @param x
* The x-coordinate at which to paint.
* @param y
* The y-coordinate at which to paint.
* @param host
* The text area this token is in.
* @param e
* How to expand tabs.
* @param clipStart
* The left boundary of the clip rectangle in which we're
* painting. This optimizes painting by allowing us to not paint
* paint when this token is "to the left" of the clip rectangle.
* @param useSTC
* Whether to use the text area's "selected text color."
* @param token The token to render.
* @param g The graphics context in which to paint.
* @param x The x-coordinate at which to paint.
* @param y The y-coordinate at which to paint.
* @param host The text area this token is in.
* @param e How to expand tabs.
* @param clipStart The left boundary of the clip rectangle in which we're
* painting. This optimizes painting by allowing us to not
* paint paint when this token is "to the left" of the clip
* rectangle.
* @param useSTC Whether to use the text area's "selected text color."
* @return The x-coordinate representing the end of the painted text.
*/
float paintSelected(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, float clipStart, boolean useSTC);
float paintSelected(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e,
float clipStart, boolean useSTC);
}
@@ -11,17 +11,17 @@ package org.fife.ui.rsyntaxtextarea;
* <p>
*
* Note that all valid token types are &gt;= 0, so extensions of the TokenMaker
* class are free to internally use all ints &lt; 0 ONLY for "end-of-line"
* style markers; they are ignored by painting implementations.
* class are free to internally use all ints &lt; 0 ONLY for "end-of-line" style
* markers; they are ignored by painting implementations.
*
* @author Robert Futrell
* @version 1.0
*/
public interface TokenTypes {
/**
* Tokens of type <code>NULL</code> mark the end of lines with no
* multi-line token at the end (such as a block comment in C++).
* Tokens of type <code>NULL</code> mark the end of lines with no multi-line
* token at the end (such as a block comment in C++).
*/
int NULL = 0;
int COMMENT_EOL = 1;
@@ -18,7 +18,7 @@ import java.net.URL;
* @version 1.0
*/
class URLFileLocation extends FileLocation {
/**
* URL of the remote file.
*/
@@ -32,22 +32,21 @@ class URLFileLocation extends FileLocation {
* removed).
*/
private String fileName;
/**
* Constructor.
*
* @param url
* The URL of the file.
* @param url The URL of the file.
*/
URLFileLocation(URL url) {
this.url = url;
fileFullPath = createFileFullPath();
fileName = createFileName();
}
/**
* Creates a "prettied-up" URL to use. This will be stripped of
* sensitive information such as passwords.
* Creates a "prettied-up" URL to use. This will be stripped of sensitive
* information such as passwords.
*
* @return The full path to use.
*/
@@ -56,7 +55,7 @@ class URLFileLocation extends FileLocation {
fullPath = fullPath.replaceFirst("://([^:]+)(?:.+)@", "://$1@");
return fullPath;
}
/**
* Creates the "prettied-up" filename to use.
*
@@ -71,11 +70,11 @@ class URLFileLocation extends FileLocation {
}
return fileName;
}
/**
* Returns the last time this file was modified, or
* {@link TextEditorPane#LAST_MODIFIED_UNKNOWN} if this value cannot be
* computed (such as for a remote file).
* {@link TextEditorPane#LAST_MODIFIED_UNKNOWN} if this value cannot be computed
* (such as for a remote file).
*
* @return The last time this file was modified. This will always be
* {@link TextEditorPane#LAST_MODIFIED_UNKNOWN} for URL's.
@@ -84,7 +83,7 @@ class URLFileLocation extends FileLocation {
protected long getActualLastModified() {
return TextEditorPane.LAST_MODIFIED_UNKNOWN;
}
/**
* {@inheritDoc}
*/
@@ -92,7 +91,7 @@ class URLFileLocation extends FileLocation {
public String getFileFullPath() {
return fileFullPath;
}
/**
* {@inheritDoc}
*/
@@ -100,7 +99,7 @@ class URLFileLocation extends FileLocation {
public String getFileName() {
return fileName;
}
/**
* {@inheritDoc}
*/
@@ -108,7 +107,7 @@ class URLFileLocation extends FileLocation {
protected InputStream getInputStream() throws IOException {
return url.openStream();
}
/**
* {@inheritDoc}
*/
@@ -116,7 +115,7 @@ class URLFileLocation extends FileLocation {
protected OutputStream getOutputStream() throws IOException {
return url.openConnection().getOutputStream();
}
/**
* Returns whether this file location is a local file.
*
@@ -127,11 +126,11 @@ class URLFileLocation extends FileLocation {
public boolean isLocal() {
return "file".equalsIgnoreCase(url.getProtocol());
}
/**
* Returns whether this file location is a local file and already
* exists. This method always returns <code>false</code> since we
* cannot check this value easily.
* Returns whether this file location is a local file and already exists. This
* method always returns <code>false</code> since we cannot check this value
* easily.
*
* @return <code>false</code> always.
* @see #isLocal()
@@ -20,13 +20,11 @@ import javax.swing.text.TabExpander;
* The current implementation paints as follows:
* <ul>
* <li>The first tab or space, if any, is found in the token.</li>
* <li>If a tab was found, all characters up to it are painted as a
* group.</li>
* <li>If a space was found, all characters up to and including it are
* painted (it is painted with a special symbol to denote it as
* a space).</li>
* <li>If neither a tab nor a whitespace was found, all characters in the
* token are painted.</li>
* <li>If a tab was found, all characters up to it are painted as a group.</li>
* <li>If a space was found, all characters up to and including it are painted
* (it is painted with a special symbol to denote it as a space).</li>
* <li>If neither a tab nor a whitespace was found, all characters in the token
* are painted.</li>
* <li>Repeat until all characters are painted.</li>
* </ul>
* This means that rendering hints are applied to all groups of characters
@@ -46,13 +44,13 @@ import javax.swing.text.TabExpander;
* @version 1.0
*/
class VisibleWhitespaceTokenPainter extends DefaultTokenPainter {
/**
* {@inheritDoc}
*/
@Override
protected float paintImpl(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, float clipStart,
boolean selected, boolean useSTC) {
protected float paintImpl(Token token, Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e,
float clipStart, boolean selected, boolean useSTC) {
int origX = (int) x;
int textOffs = token.getTextOffset();
char[] text = token.getTextArray();
@@ -68,65 +66,65 @@ class VisibleWhitespaceTokenPainter extends DefaultTokenPainter {
int height = fm.getHeight();
for (int i = textOffs; i < end; i++) {
switch (text[i]) {
case '\t':
// Fill in background.
nextX = x + fm.charsWidth(text, flushIndex, flushLen);
float nextNextX = e.nextTabStop(nextX, 0);
if (bg != null) {
paintBackground(x, y, nextNextX - x, height, g, ascent, host, bg);
}
g.setColor(fg);
// Paint chars cached before the tab.
if (flushLen > 0) {
g.drawChars(text, flushIndex, flushLen, (int) x, (int) y);
flushLen = 0;
}
flushIndex = i + 1;
// Draw an arrow representing the tab.
int halfHeight = height / 2;
int quarterHeight = halfHeight / 2;
int ymid = (int) y - ascent + halfHeight;
g.drawLine((int) nextX, ymid, (int) nextNextX, ymid);
g.drawLine((int) nextNextX, ymid, (int) nextNextX - 4, ymid - quarterHeight);
g.drawLine((int) nextNextX, ymid, (int) nextNextX - 4, ymid + quarterHeight);
x = nextNextX;
break;
case ' ':
// NOTE: There is a little bit of a "fudge factor"
// here when "smooth text" is enabled, as "width"
// below may well not be the width given to the space
// by fm.charsWidth() (it depends on how it places the
// space with respect to the preceding character).
// But, we assume the approximation is close enough for
// our drawing a dot for the space.
// "flushLen+1" ensures text is aligned correctly (or,
// aligned the same as in getWidth()).
nextX = x + fm.charsWidth(text, flushIndex, flushLen + 1);
int width = fm.charWidth(' ');
// Paint background.
if (bg != null) {
paintBackground(x, y, nextX - x, height, g, ascent, host, bg);
}
g.setColor(fg);
// Paint chars before space.
if (flushLen > 0) {
g.drawChars(text, flushIndex, flushLen, (int) x, (int) y);
flushLen = 0;
}
// Paint a dot representing the space.
int dotX = (int) (nextX - width / 2f); // "2.0f" for
// FindBugs
int dotY = (int) (y - ascent + height / 2f); // Ditto
g.drawLine(dotX, dotY, dotX, dotY);
flushIndex = i + 1;
x = nextX;
break;
case '\f':
// ???
// fall-through for now.
default:
flushLen += 1;
break;
case '\t':
// Fill in background.
nextX = x + fm.charsWidth(text, flushIndex, flushLen);
float nextNextX = e.nextTabStop(nextX, 0);
if (bg != null) {
paintBackground(x, y, nextNextX - x, height, g, ascent, host, bg);
}
g.setColor(fg);
// Paint chars cached before the tab.
if (flushLen > 0) {
g.drawChars(text, flushIndex, flushLen, (int) x, (int) y);
flushLen = 0;
}
flushIndex = i + 1;
// Draw an arrow representing the tab.
int halfHeight = height / 2;
int quarterHeight = halfHeight / 2;
int ymid = (int) y - ascent + halfHeight;
g.drawLine((int) nextX, ymid, (int) nextNextX, ymid);
g.drawLine((int) nextNextX, ymid, (int) nextNextX - 4, ymid - quarterHeight);
g.drawLine((int) nextNextX, ymid, (int) nextNextX - 4, ymid + quarterHeight);
x = nextNextX;
break;
case ' ':
// NOTE: There is a little bit of a "fudge factor"
// here when "smooth text" is enabled, as "width"
// below may well not be the width given to the space
// by fm.charsWidth() (it depends on how it places the
// space with respect to the preceding character).
// But, we assume the approximation is close enough for
// our drawing a dot for the space.
// "flushLen+1" ensures text is aligned correctly (or,
// aligned the same as in getWidth()).
nextX = x + fm.charsWidth(text, flushIndex, flushLen + 1);
int width = fm.charWidth(' ');
// Paint background.
if (bg != null) {
paintBackground(x, y, nextX - x, height, g, ascent, host, bg);
}
g.setColor(fg);
// Paint chars before space.
if (flushLen > 0) {
g.drawChars(text, flushIndex, flushLen, (int) x, (int) y);
flushLen = 0;
}
// Paint a dot representing the space.
int dotX = (int) (nextX - width / 2f); // "2.0f" for
// FindBugs
int dotY = (int) (y - ascent + height / 2f); // Ditto
g.drawLine(dotX, dotY, dotX, dotY);
flushIndex = i + 1;
x = nextX;
break;
case '\f':
// ???
// fall-through for now.
default:
flushLen += 1;
break;
}
}
nextX = x + fm.charsWidth(text, flushIndex, flushLen);
@@ -43,7 +43,7 @@ import org.fife.ui.rtextarea.Gutter;
* @version 0.2
*/
public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView {
private boolean widthChanging;
private int tabBase;
private int tabSize;
@@ -67,17 +67,16 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
// */
// private static final char[] eolMarker = { '.' };
/**
* The width of this view cannot be below this amount, as if the width
* is ever 0 (really a bug), we'll go into an infinite loop.
* The width of this view cannot be below this amount, as if the width is ever 0
* (really a bug), we'll go into an infinite loop.
*/
private static final int MIN_WIDTH = 20;
/**
* Creates a new WrappedSyntaxView. Lines will be wrapped
* on character boundaries.
* Creates a new WrappedSyntaxView. Lines will be wrapped on character
* boundaries.
*
* @param elem
* the element underlying the view
* @param elem the element underlying the view
*/
public WrappedSyntaxView(Element elem) {
super(elem, Y_AXIS);
@@ -87,14 +86,12 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
tempRect = new Rectangle();
lineCountTempToken = new TokenImpl();
}
/**
* This is called by the nested wrapped line
* views to determine the break location. This can
* be reimplemented to alter the breaking behavior.
* It will either break at word or character boundaries
* depending upon the break argument given at
* construction.
* This is called by the nested wrapped line views to determine the break
* location. This can be reimplemented to alter the breaking behavior. It will
* either break at word or character boundaries depending upon the break
* argument given at construction.
*/
protected int calculateBreakPosition(int p0, Token tokenList, float x0) {
// System.err.println("------ beginning calculateBreakPosition()
@@ -143,7 +140,7 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
// return p;
return p + 1;
}
// private int getBreakLocation(Token t, FontMetrics fm, int x0, int x,
// TabExpander e) {
// Segment s = new Segment();
@@ -153,27 +150,24 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
// return t.offset + Utilities.getBreakLocation(s, fm, x0, x, e, t.offset);
// }
/**
* Gives notification from the document that attributes were changed
* in a location that this view is responsible for.
* Gives notification from the document that attributes were changed in a
* location that this view is responsible for.
*
* @param e
* the change information from the associated document
* @param a
* the current allocation of the view
* @param f
* the factory to use to rebuild if the view has children
* @param e the change information from the associated document
* @param a the current allocation of the view
* @param f the factory to use to rebuild if the view has children
* @see View#changedUpdate
*/
@Override
public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
updateChildren(e, a);
}
/**
* Sets the allocation rectangle for a given line's view, but sets the
* y value to the passed-in value. This should be used instead of
* {@link #childAllocation(int, Rectangle)} since it allows you to account
* for hidden lines in collapsed fold regions.
* Sets the allocation rectangle for a given line's view, but sets the y value
* to the passed-in value. This should be used instead of
* {@link #childAllocation(int, Rectangle)} since it allows you to account for
* hidden lines in collapsed fold regions.
*
* @param line
* @param y
@@ -192,25 +186,20 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
alloc.y -= margin.top;
}
}
/**
* Draws a single view (i.e., a line of text for a wrapped view),
* wrapping the text onto multiple lines if necessary.
* Draws a single view (i.e., a line of text for a wrapped view), wrapping the
* text onto multiple lines if necessary.
*
* @param painter
* The painter to use to render tokens.
* @param g
* The graphics context in which to paint.
* @param r
* The rectangle in which to paint.
* @param view
* The <code>View</code> to paint.
* @param fontHeight
* The height of the font being used.
* @param y
* The y-coordinate at which to begin painting.
* @param painter The painter to use to render tokens.
* @param g The graphics context in which to paint.
* @param r The rectangle in which to paint.
* @param view The <code>View</code> to paint.
* @param fontHeight The height of the font being used.
* @param y The y-coordinate at which to begin painting.
*/
protected void drawView(TokenPainter painter, Graphics2D g, Rectangle r, View view, int fontHeight, int y, int line) {
protected void drawView(TokenPainter painter, Graphics2D g, Rectangle r, View view, int fontHeight, int y,
int line) {
float x = r.x;
LayeredHighlighter h = (LayeredHighlighter) host.getHighlighter();
RSyntaxDocument document = (RSyntaxDocument) getDocument();
@@ -262,31 +251,23 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
g.drawString("\u00B6", x, (float) y - fontHeight);
}
}
/**
* Draws a single view (i.e., a line of text for a wrapped view), wrapping
* the text onto multiple lines if necessary. Any selected text is
* rendered with the editor's "selected text" color.
* Draws a single view (i.e., a line of text for a wrapped view), wrapping the
* text onto multiple lines if necessary. Any selected text is rendered with the
* editor's "selected text" color.
*
* @param painter
* The painter to use to render tokens.
* @param g
* The graphics context in which to paint.
* @param r
* The rectangle in which to paint.
* @param view
* The <code>View</code> to paint.
* @param fontHeight
* The height of the font being used.
* @param y
* The y-coordinate at which to begin painting.
* @param selStart
* The start of the selection.
* @param selEnd
* The end of the selection.
* @param painter The painter to use to render tokens.
* @param g The graphics context in which to paint.
* @param r The rectangle in which to paint.
* @param view The <code>View</code> to paint.
* @param fontHeight The height of the font being used.
* @param y The y-coordinate at which to begin painting.
* @param selStart The start of the selection.
* @param selEnd The end of the selection.
*/
protected void drawViewWithSelection(TokenPainter painter, Graphics2D g, Rectangle r, View view, int fontHeight, int y, int selStart,
int selEnd) {
protected void drawViewWithSelection(TokenPainter painter, Graphics2D g, Rectangle r, View view, int fontHeight,
int y, int selStart, int selEnd) {
float x = r.x;
boolean useSTC = host.getUseSelectedTextColor();
LayeredHighlighter h = (LayeredHighlighter) host.getHighlighter();
@@ -363,7 +344,8 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
if (token != null && token.isPaintable() && token.getOffset() < p) {
int tokenOffset = token.getOffset();
Token orig = token;
token = new TokenImpl(drawSeg, tokenOffset - start, p - 1 - start, tokenOffset, token.getType(), token.getLanguageIndex());
token = new TokenImpl(drawSeg, tokenOffset - start, p - 1 - start, tokenOffset, token.getType(),
token.getLanguageIndex());
token.setLanguageIndex(token.getLanguageIndex());
// Selection starts in this token
if (token.containsPosition(selStart)) {
@@ -422,19 +404,16 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
g.drawString("\u00B6", x, (float) y - fontHeight);
}
}
/**
* Fetches the allocation for the given child view.
* <p>
* Overridden to account for code folding.
*
* @param index
* The index of the child, &gt;= 0 &amp;&amp;&lt; getViewCount().
* @param a
* The allocation to this view
* @return The allocation to the child; or <code>null</code> if
* <code>a</code> is <code>null</code>; or <code>null</code> if the
* layout is invalid
* @param index The index of the child, &gt;= 0 &amp;&amp;&lt; getViewCount().
* @param a The allocation to this view
* @return The allocation to the child; or <code>null</code> if <code>a</code>
* is <code>null</code>; or <code>null</code> if the layout is invalid
*/
@Override
public Shape getChildAllocation(int index, Shape a) {
@@ -451,16 +430,14 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
return null;
}
/**
* Fetches the allocation for the given child view to render into.
* <p>
* Overridden to account for lines hidden by collapsed folded regions.
*
* @param line
* The index of the child, &gt;= 0 &amp;&amp;&lt; getViewCount()
* @param a
* The allocation to this view
* @param line The index of the child, &gt;= 0 &amp;&amp;&lt; getViewCount()
* @param a The allocation to this view
* @return The allocation to the child
*/
public Shape getChildAllocationImpl(int line, Shape a) {
@@ -480,21 +457,17 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
childAllocation2(line, y, alloc);
return alloc;
}
/**
* Determines the maximum span for this view along an
* axis. This is implemented to provide the superclass
* behavior after first making sure that the current font
* metrics are cached (for the nested lines which use
* the metrics to determine the height of the potentially
* wrapped lines).
* Determines the maximum span for this view along an axis. This is implemented
* to provide the superclass behavior after first making sure that the current
* font metrics are cached (for the nested lines which use the metrics to
* determine the height of the potentially wrapped lines).
*
* @param axis
* may be either View.X_AXIS or View.Y_AXIS
* @return the span the view would like to be rendered into.
* Typically the view is told to render into the span
* that is returned, although there is no guarantee.
* The parent may choose to resize or break the view.
* @param axis may be either View.X_AXIS or View.Y_AXIS
* @return the span the view would like to be rendered into. Typically the view
* is told to render into the span that is returned, although there is
* no guarantee. The parent may choose to resize or break the view.
* @see View#getMaximumSpan
*/
@Override
@@ -506,21 +479,17 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
return span;
}
/**
* Determines the minimum span for this view along an
* axis. This is implemented to provide the superclass
* behavior after first making sure that the current font
* metrics are cached (for the nested lines which use
* the metrics to determine the height of the potentially
* wrapped lines).
* Determines the minimum span for this view along an axis. This is implemented
* to provide the superclass behavior after first making sure that the current
* font metrics are cached (for the nested lines which use the metrics to
* determine the height of the potentially wrapped lines).
*
* @param axis
* may be either View.X_AXIS or View.Y_AXIS
* @return the span the view would like to be rendered into.
* Typically the view is told to render into the span
* that is returned, although there is no guarantee.
* The parent may choose to resize or break the view.
* @param axis may be either View.X_AXIS or View.Y_AXIS
* @return the span the view would like to be rendered into. Typically the view
* is told to render into the span that is returned, although there is
* no guarantee. The parent may choose to resize or break the view.
* @see View#getMinimumSpan
*/
@Override
@@ -532,21 +501,17 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
return span;
}
/**
* Determines the preferred span for this view along an
* axis. This is implemented to provide the superclass
* behavior after first making sure that the current font
* metrics are cached (for the nested lines which use
* the metrics to determine the height of the potentially
* wrapped lines).
* Determines the preferred span for this view along an axis. This is
* implemented to provide the superclass behavior after first making sure that
* the current font metrics are cached (for the nested lines which use the
* metrics to determine the height of the potentially wrapped lines).
*
* @param axis
* may be either View.X_AXIS or View.Y_AXIS
* @return the span the view would like to be rendered into.
* Typically the view is told to render into the span
* that is returned, although there is no guarantee.
* The parent may choose to resize or break the view.
* @param axis may be either View.X_AXIS or View.Y_AXIS
* @return the span the view would like to be rendered into. Typically the view
* is told to render into the span that is returned, although there is
* no guarantee. The parent may choose to resize or break the view.
* @see View#getPreferredSpan
*/
@Override
@@ -573,7 +538,7 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
return span;
}
/**
* Returns the tab size set for the document, defaulting to 5.
*
@@ -584,7 +549,7 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
int size = (i != null) ? i.intValue() : 5;
return size;
}
/**
* Overridden to allow for folded regions.
*/
@@ -610,18 +575,15 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
childAllocation2(lineCount - 1, curY, alloc);
return getView(lineCount - 1);
}
/**
* Gives notification that something was inserted into the
* document in a location that this view is responsible for.
* This is implemented to simply update the children.
* Gives notification that something was inserted into the document in a
* location that this view is responsible for. This is implemented to simply
* update the children.
*
* @param changes
* The change information from the associated document.
* @param a
* the current allocation of the view
* @param f
* the factory to use to rebuild if the view has children
* @param changes The change information from the associated document.
* @param a the current allocation of the view
* @param f the factory to use to rebuild if the view has children
* @see View#insertUpdate
*/
@Override
@@ -634,17 +596,14 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
v.insertUpdate(changes, alloc, f);
}
}
/**
* Loads all of the children to initialize the view.
* This is called by the <code>setParent</code> method.
* Subclasses can re-implement this to initialize their
* child views in a different manner. The default
* implementation creates a child view for each
* child element.
* Loads all of the children to initialize the view. This is called by the
* <code>setParent</code> method. Subclasses can re-implement this to initialize
* their child views in a different manner. The default implementation creates a
* child view for each child element.
*
* @param f
* the view factory
* @param f the view factory
*/
@Override
protected void loadChildren(ViewFactory f) {
@@ -658,7 +617,7 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
replace(0, 0, added);
}
}
@Override
public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
if (!isAllocationValid()) {
@@ -691,48 +650,43 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
throw new BadLocationException("Position not represented by view", pos);
}
/**
* Provides a mapping, for a given region, from the document model
* coordinate space to the view coordinate space. The specified region is
* created as a union of the first and last character positions.
* Provides a mapping, for a given region, from the document model coordinate
* space to the view coordinate space. The specified region is created as a
* union of the first and last character positions.
* <p>
*
* This is implemented to subtract the width of the second character, as
* this view's <code>modelToView</code> actually returns the width of the
* character instead of "1" or "0" like the View implementations in
* <code>javax.swing.text</code>. Thus, if we don't override this method,
* the <code>View</code> implementation will return one character's width
* too much for its consumers (implementations of
* This is implemented to subtract the width of the second character, as this
* view's <code>modelToView</code> actually returns the width of the character
* instead of "1" or "0" like the View implementations in
* <code>javax.swing.text</code>. Thus, if we don't override this method, the
* <code>View</code> implementation will return one character's width too much
* for its consumers (implementations of
* <code>javax.swing.text.Highlighter</code>).
*
* @param p0
* the position of the first character (&gt;=0)
* @param b0
* The bias of the first character position, toward the previous
* character or the next character represented by the offset, in
* case the position is a boundary of two views; <code>b0</code>
* will have one of these values:
* <ul>
* <li><code>Position.Bias.Forward</code>
* <li><code>Position.Bias.Backward</code>
* </ul>
* @param p1
* the position of the last character (&gt;=0)
* @param b1
* the bias for the second character position, defined
* one of the legal values shown above
* @param a
* the area of the view, which encompasses the requested region
* @return the bounding box which is a union of the region specified
* by the first and last character positions
* @exception BadLocationException
* if the given position does
* not represent a valid location in the associated document
* @exception IllegalArgumentException
* if <code>b0</code> or
* <code>b1</code> are not one of the
* legal <code>Position.Bias</code> values listed above
* @param p0 the position of the first character (&gt;=0)
* @param b0 The bias of the first character position, toward the previous
* character or the next character represented by the offset, in case
* the position is a boundary of two views; <code>b0</code> will have
* one of these values:
* <ul>
* <li><code>Position.Bias.Forward</code>
* <li><code>Position.Bias.Backward</code>
* </ul>
* @param p1 the position of the last character (&gt;=0)
* @param b1 the bias for the second character position, defined one of the
* legal values shown above
* @param a the area of the view, which encompasses the requested region
* @return the bounding box which is a union of the region specified by the
* first and last character positions
* @exception BadLocationException if the given position does not represent
* a valid location in the associated
* document
* @exception IllegalArgumentException if <code>b0</code> or <code>b1</code> are
* not one of the legal
* <code>Position.Bias</code> values listed
* above
* @see View#viewToModel
*/
@Override
@@ -774,17 +728,15 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
return r0;
}
/**
* Returns the next tab stop position after a given reference position.
* This implementation does not support things like centering so it
* ignores the tabOffset argument.
* Returns the next tab stop position after a given reference position. This
* implementation does not support things like centering so it ignores the
* tabOffset argument.
*
* @param x
* the current position &gt;= 0
* @param tabOffset
* the position within the text stream
* that the tab occurred at &gt;= 0.
* @param x the current position &gt;= 0
* @param tabOffset the position within the text stream that the tab occurred at
* &gt;= 0.
* @return the tab stop, measured in points &gt;= 0
*/
@Override
@@ -795,14 +747,12 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
int ntabs = ((int) x - tabBase) / tabSize;
return tabBase + ((ntabs + 1f) * tabSize);
}
/**
* Paints the word-wrapped text.
*
* @param g
* The graphics context in which to paint.
* @param a
* The shape (usually a rectangle) in which to paint.
* @param g The graphics context in which to paint.
* @param a The shape (usually a rectangle) in which to paint.
*/
@Override
public void paint(Graphics g, Shape a) {
@@ -854,18 +804,15 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
}
}
/**
* Gives notification that something was removed from the
* document in a location that this view is responsible for.
* This is implemented to simply update the children.
* Gives notification that something was removed from the document in a location
* that this view is responsible for. This is implemented to simply update the
* children.
*
* @param changes
* The change information from the associated document.
* @param a
* the current allocation of the view
* @param f
* the factory to use to rebuild if the view has children
* @param changes The change information from the associated document.
* @param a the current allocation of the view
* @param f the factory to use to rebuild if the view has children
* @see View#removeUpdate
*/
@Override
@@ -878,20 +825,16 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
v.removeUpdate(changes, alloc, f);
}
}
/**
* Makes a <code>Segment</code> point to the text in our
* document between the given positions. Note that the positions MUST be
* valid positions in the document.
* Makes a <code>Segment</code> point to the text in our document between the
* given positions. Note that the positions MUST be valid positions in the
* document.
*
* @param p0
* The first position in the document.
* @param p1
* The second position in the document.
* @param document
* The document from which you want to get the text.
* @param seg
* The segment in which to load the text.
* @param p0 The first position in the document.
* @param p1 The second position in the document.
* @param document The document from which you want to get the text.
* @param seg The segment in which to load the text.
*/
private void setSegment(int p0, int p1, Document document, Segment seg) {
try {
@@ -904,15 +847,13 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
ble.printStackTrace();
}
}
/**
* Sets the size of the view. This should cause layout of the view along
* the given axis, if it has any layout duties.
* Sets the size of the view. This should cause layout of the view along the
* given axis, if it has any layout duties.
*
* @param width
* the width &gt;= 0
* @param height
* the height &gt;= 0
* @param width the width &gt;= 0
* @param height the height &gt;= 0
*/
@Override
public void setSize(float width, float height) {
@@ -926,10 +867,9 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
super.setSize(width, height);
widthChanging = false;
}
/**
* Update the child views in response to a
* document event.
* Update the child views in response to a document event.
*/
void updateChildren(DocumentEvent e, Shape a) {
Element elem = getElement();
@@ -962,14 +902,14 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
// update font metrics which may be used by the child views
updateMetrics();
}
final void updateMetrics() {
Component host = getContainer();
Font f = host.getFont();
metrics = host.getFontMetrics(f); // Metrics for the default font.
tabSize = getTabSize() * metrics.charWidth('m');
}
@Override
public int viewToModel(float x, float y, Shape a, Position.Bias[] bias) {
int offs = -1;
@@ -992,7 +932,7 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
return offs;
}
/**
* {@inheritDoc}
*/
@@ -1001,7 +941,7 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
return yForLineContaining(alloc, getElement().getElement(line).getStartOffset());
// return alloc.y + getOffset(Y_AXIS, line);
}
/**
* {@inheritDoc}
*/
@@ -1024,25 +964,23 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
return -1;
}
/**
* Simple view of a line that wraps if it doesn't
* fit within the horizontal space allocated.
* This class tries to be lightweight by carrying little
* state of it's own and sharing the state of the outer class
* with it's siblings.
* Simple view of a line that wraps if it doesn't fit within the horizontal
* space allocated. This class tries to be lightweight by carrying little state
* of it's own and sharing the state of the outer class with it's siblings.
*/
class WrappedLine extends View {
private int nlines;
WrappedLine(Element elem) {
super(elem);
}
/**
* Calculate the number of lines that will be rendered
* by logical line when it is wrapped.
* Calculate the number of lines that will be rendered by logical line when it
* is wrapped.
*/
final int calculateLineCount() {
int nlines = 0;
@@ -1062,7 +1000,8 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
for (int p0 = startOffset; p0 < p1;) {
// System.err.println("... ... " + p0 + ", " + p1);
nlines += 1;
TokenSubList subList = TokenUtils.getSubTokenList(tokenList, p0, WrappedSyntaxView.this, textArea, x0, lineCountTempToken);
TokenSubList subList = TokenUtils.getSubTokenList(tokenList, p0, WrappedSyntaxView.this, textArea, x0,
lineCountTempToken);
x0 = subList != null ? subList.x : x0;
tokenList = subList != null ? subList.tokenList : null;
int p = calculateBreakPosition(p0, tokenList, x0);
@@ -1075,81 +1014,68 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
// System.err.println("... ... ... new p0==" + p0);
}
/*
* int numLines = 0;
* try {
* numLines = textArea.getLineCount();
* } catch (BadLocationException ble) {
* ble.printStackTrace();
* }
* System.err.
* println(">>> >>> calculated number of lines for this view (line "
* + line + "/" + numLines + ": " + nlines);
* int numLines = 0; try { numLines = textArea.getLineCount(); } catch
* (BadLocationException ble) { ble.printStackTrace(); } System.err.
* println(">>> >>> calculated number of lines for this view (line " + line +
* "/" + numLines + ": " + nlines);
*/
return nlines;
}
/**
* Determines the preferred span for this view along an
* axis.
* Determines the preferred span for this view along an axis.
*
* @param axis
* may be either X_AXIS or Y_AXIS
* @return the span the view would like to be rendered into.
* Typically the view is told to render into the span
* that is returned, although there is no guarantee.
* The parent may choose to resize or break the view.
* @param axis may be either X_AXIS or Y_AXIS
* @return the span the view would like to be rendered into. Typically the view
* is told to render into the span that is returned, although there is
* no guarantee. The parent may choose to resize or break the view.
* @see View#getPreferredSpan
*/
@Override
public float getPreferredSpan(int axis) {
switch (axis) {
case View.X_AXIS:
float width = getWidth();
if (width == Integer.MAX_VALUE) {
// We have been initially set to MAX_VALUE, but we don't
// want this as our preferred.
return 100f;
}
return width;
case View.Y_AXIS:
if (nlines == 0 || widthChanging) {
nlines = calculateLineCount();
}
int h = nlines * ((RSyntaxTextArea) getContainer()).getLineHeight();
return h;
default:
throw new IllegalArgumentException("Invalid axis: " + axis);
case View.X_AXIS:
float width = getWidth();
if (width == Integer.MAX_VALUE) {
// We have been initially set to MAX_VALUE, but we don't
// want this as our preferred.
return 100f;
}
return width;
case View.Y_AXIS:
if (nlines == 0 || widthChanging) {
nlines = calculateLineCount();
}
int h = nlines * ((RSyntaxTextArea) getContainer()).getLineHeight();
return h;
default:
throw new IllegalArgumentException("Invalid axis: " + axis);
}
}
/**
* Renders using the given rendering surface and area on that
* surface. The view may need to do layout and create child
* views to enable itself to render into the given allocation.
* Renders using the given rendering surface and area on that surface. The view
* may need to do layout and create child views to enable itself to render into
* the given allocation.
*
* @param g
* the rendering surface to use
* @param a
* the allocated region to render into
* @param g the rendering surface to use
* @param a the allocated region to render into
* @see View#paint
*/
@Override
public void paint(Graphics g, Shape a) {
// This is done by drawView() above.
}
/**
* Provides a mapping from the document model coordinate space
* to the coordinate space of the view mapped to it.
* Provides a mapping from the document model coordinate space to the coordinate
* space of the view mapped to it.
*
* @param pos
* the position to convert
* @param a
* the allocated region to render into
* @param pos the position to convert
* @param a the allocated region to render into
* @return the bounding box of the given position is returned
* @exception BadLocationException
* if the given position does not
* represent a valid location in the associated document.
* @exception BadLocationException if the given position does not represent a
* valid location in the associated document.
*/
@Override
public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
@@ -1170,13 +1096,15 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
Token tokenList = doc.getTokenListForLine(line);
float x0 = alloc.x;// 0;
while (p0 < p1) {
TokenSubList subList = TokenUtils.getSubTokenList(tokenList, p0, WrappedSyntaxView.this, textArea, x0, lineCountTempToken);
TokenSubList subList = TokenUtils.getSubTokenList(tokenList, p0, WrappedSyntaxView.this, textArea, x0,
lineCountTempToken);
x0 = subList != null ? subList.x : x0;
tokenList = subList != null ? subList.tokenList : null;
int p = calculateBreakPosition(p0, tokenList, x0);
if ((pos >= p0) && (testP < p)) {// pos < p)) {
// it's in this line
alloc = RSyntaxUtilities.getLineWidthUpTo(textArea, s, p0, pos, WrappedSyntaxView.this, alloc, alloc.x);
alloc = RSyntaxUtilities.getLineWidthUpTo(textArea, s, p0, pos, WrappedSyntaxView.this, alloc,
alloc.x);
// System.err.println("--- end modelToView ---");
return alloc;
}
@@ -1184,7 +1112,8 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
if (p == p1 - 1 && pos == p1 - 1) {
// Wants end.
if (pos > p0) {
alloc = RSyntaxUtilities.getLineWidthUpTo(textArea, s, p0, pos, WrappedSyntaxView.this, alloc, alloc.x);
alloc = RSyntaxUtilities.getLineWidthUpTo(textArea, s, p0, pos, WrappedSyntaxView.this, alloc,
alloc.x);
}
// System.err.println("--- end modelToView ---");
return alloc;
@@ -1195,19 +1124,16 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
}
throw new BadLocationException(null, pos);
}
/**
* Provides a mapping from the view coordinate space to the logical
* coordinate space of the model.
* Provides a mapping from the view coordinate space to the logical coordinate
* space of the model.
*
* @param fx
* the X coordinate
* @param fy
* the Y coordinate
* @param a
* the allocated region to render into
* @return the location within the model that best represents the
* given point in the view
* @param fx the X coordinate
* @param fy the Y coordinate
* @param a the allocated region to render into
* @return the location within the model that best represents the given point in
* the view
* @see View#viewToModel
*/
@Override
@@ -1247,8 +1173,8 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
// We can always use alloc.x since we always break
// lines so they start at the beginning of a physical
// line.
TokenSubList subList = TokenUtils.getSubTokenList(tlist, p0, WrappedSyntaxView.this, textArea, alloc.x,
lineCountTempToken);
TokenSubList subList = TokenUtils.getSubTokenList(tlist, p0, WrappedSyntaxView.this, textArea,
alloc.x, lineCountTempToken);
tlist = subList != null ? subList.tokenList : null;
int p = calculateBreakPosition(p0, tlist, alloc.x);
// If desired view position is in this physical chunk.
@@ -1281,7 +1207,7 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
return getEndOffset() - 1;
} // End of else.
}
private void handleDocumentEvent(DocumentEvent e, Shape a, ViewFactory f) {
int n = calculateLineCount();
if (this.nlines != n) {
@@ -1303,12 +1229,12 @@ public class WrappedSyntaxView extends BoxView implements TabExpander, RSTAView
c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
}
}
@Override
public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f) {
handleDocumentEvent(e, a, f);
}
@Override
public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f) {
handleDocumentEvent(e, a, f);
@@ -9,8 +9,8 @@ import javax.swing.text.Element;
// import javax.swing.text.View;
/**
* Replacement for the old <code>WrappedSyntaxView</code> class, designed to
* be faster with large wrapped documents. Heavily based off of
* Replacement for the old <code>WrappedSyntaxView</code> class, designed to be
* faster with large wrapped documents. Heavily based off of
* <code>BoxView</code>, but streamlined to only care about the y-axis, and
* takes code folding into account.
* <p>
@@ -25,7 +25,7 @@ public class WrappedSyntaxView2 {// extends CompositeView {
// private int[] cachedOffsets;
// private int[] cachedSpans;
// private boolean sizeRequirementsValid;
public WrappedSyntaxView2(Element root) {
// super(root);
// tempRect = new Rectangle();
@@ -21,10 +21,10 @@ import org.fife.ui.rtextarea.SmartHighlightPainter;
* @version 1.0
*/
public class XmlOccurrenceMarker implements OccurrenceMarker {
private static final char[] CLOSE_TAG_START = { '<', '/' };
private static final char[] TAG_SELF_CLOSE = { '/', '>' };
/**
* {@inheritDoc}
*/
@@ -32,7 +32,7 @@ public class XmlOccurrenceMarker implements OccurrenceMarker {
public Token getTokenToMark(RSyntaxTextArea textArea) {
return HtmlOccurrenceMarker.getTagNameTokenForCaretOffset(textArea, this);
}
/**
* {@inheritDoc}
*/
@@ -40,7 +40,7 @@ public class XmlOccurrenceMarker implements OccurrenceMarker {
public boolean isValidType(RSyntaxTextArea textArea, Token t) {
return textArea.getMarkOccurrencesOfTokenType(t.getType());
}
/**
* {@inheritDoc}
*/
@@ -173,15 +173,15 @@ public class XmlOccurrenceMarker implements OccurrenceMarker {
} while (curLine >= 0);
}
}
/**
* Used internally when searching backward for a matching "open" tag.
*/
private static class Entry {
private boolean open;
private Token t;
Entry(boolean open, Token t) {
this.open = open;
this.t = t;
@@ -33,14 +33,14 @@ import javax.swing.event.MouseInputAdapter;
import org.fife.ui.rsyntaxtextarea.PopupWindowDecorator;
/**
* A focusable tool tip, similar to those found in Eclipse. The user
* can click in the tip and it becomes a "real," resizable window.
* A focusable tool tip, similar to those found in Eclipse. The user can click
* in the tip and it becomes a "real," resizable window.
*
* @author Robert Futrell
* @version 1.0
*/
public class FocusableTip {
private JTextArea textArea;
private TipWindow tipWindow;
private URL imageBase;
@@ -49,8 +49,8 @@ public class FocusableTip {
private String lastText;
private Dimension maxSize; // null to automatic.
/**
* The screen bounds in which the mouse has to stay for the currently
* displayed tip to stay visible.
* The screen bounds in which the mouse has to stay for the currently displayed
* tip to stay visible.
*/
private Rectangle tipVisibleBounds;
/**
@@ -61,18 +61,19 @@ public class FocusableTip {
* Margin from mouse cursor at which to draw focusable tip.
*/
private static final int Y_MARGIN = 12;
private static final ResourceBundle MSG = ResourceBundle.getBundle("org.fife.ui.rsyntaxtextarea.focusabletip.FocusableTip");
private static final ResourceBundle MSG = ResourceBundle
.getBundle("org.fife.ui.rsyntaxtextarea.focusabletip.FocusableTip");
public FocusableTip(JTextArea textArea, HyperlinkListener listener) {
setTextArea(textArea);
this.hyperlinkListener = listener;
textAreaListener = new TextAreaListener();
tipVisibleBounds = new Rectangle();
}
/**
* Compute the bounds in which the user can move the mouse without the
* tip window disappearing.
* Compute the bounds in which the user can move the mouse without the tip
* window disappearing.
*/
private void computeTipVisibleBounds() {
// Compute area that the mouse can move in without hiding the
@@ -84,7 +85,7 @@ public class FocusableTip {
r.setLocation(p);
tipVisibleBounds.setBounds(r.x, r.y - 15, r.width, r.height + 15 * 2);
}
private void createAndShowTipWindow(final MouseEvent e, final String text) {
Window owner = SwingUtilities.getWindowAncestor(textArea);
tipWindow = new TipWindow(owner, this, text);
@@ -100,7 +101,7 @@ public class FocusableTip {
// See http://forums.sun.com/thread.jspa?forumID=57&threadID=574810
// for a discussion.
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// If a new FocusableTip is requested while another one is
@@ -148,7 +149,7 @@ public class FocusableTip {
}
});
}
/**
* Returns the base URL to use when loading images in this focusable tip.
*
@@ -158,7 +159,7 @@ public class FocusableTip {
public URL getImageBase() {
return imageBase;
}
/**
* The maximum size for unfocused tool tips.
*
@@ -169,18 +170,17 @@ public class FocusableTip {
public Dimension getMaxSize() {
return maxSize;
}
/**
* Returns localized text for the given key.
*
* @param key
* The key into the resource bundle.
* @param key The key into the resource bundle.
* @return The localized text.
*/
static String getString(String key) {
return MSG.getString(key);
}
/**
* Disposes of the focusable tip currently displayed, if any.
*/
@@ -194,41 +194,39 @@ public class FocusableTip {
textArea.requestFocus();
}
}
void removeListeners() {
// System.out.println("DEBUG: Removing text area listeners");
textAreaListener.uninstall();
}
/**
* Sets the base URL to use when loading images in this focusable tip.
*
* @param url
* The base URL to use.
* @param url The base URL to use.
* @see #getImageBase()
*/
public void setImageBase(URL url) {
imageBase = url;
}
/**
* Sets the maximum size for unfocused tool tips.
*
* @param maxSize
* The new maximum size. A value of <code>null</code> will
* cause a default size to be used.
* @param maxSize The new maximum size. A value of <code>null</code> will cause
* a default size to be used.
* @see #getMaxSize()
*/
public void setMaxSize(Dimension maxSize) {
this.maxSize = maxSize;
}
private void setTextArea(JTextArea textArea) {
this.textArea = textArea;
// Is okay to do multiple times.
ToolTipManager.sharedInstance().registerComponent(textArea);
}
public void toolTipRequested(MouseEvent e, String text) {
if (text == null || text.length() == 0) {
possiblyDisposeOfTipWindow();
@@ -240,12 +238,13 @@ public class FocusableTip {
createAndShowTipWindow(e, text);
}
}
/**
* Listens for events in a text area.
*/
private class TextAreaListener extends MouseInputAdapter implements CaretListener, ComponentListener, FocusListener, KeyListener {
private class TextAreaListener extends MouseInputAdapter
implements CaretListener, ComponentListener, FocusListener, KeyListener {
@Override
public void caretUpdate(CaretEvent e) {
Object source = e.getSource();
@@ -253,30 +252,31 @@ public class FocusableTip {
possiblyDisposeOfTipWindow();
}
}
@Override
public void componentHidden(ComponentEvent e) {
handleComponentEvent(e);
}
@Override
public void componentMoved(ComponentEvent e) {
handleComponentEvent(e);
}
@Override
public void componentResized(ComponentEvent e) {
handleComponentEvent(e);
}
@Override
public void componentShown(ComponentEvent e) {
handleComponentEvent(e);
}
@Override
public void focusGained(FocusEvent e) {}
public void focusGained(FocusEvent e) {
}
@Override
public void focusLost(FocusEvent e) {
// Only dispose of tip if it wasn't the TipWindow that was clicked
@@ -284,16 +284,17 @@ public class FocusableTip {
// calling SwingUtilities.getWindowAncestor() to guard against an
// NPE.
Component c = e.getOppositeComponent();
boolean tipClicked = (c instanceof TipWindow) || (c != null && SwingUtilities.getWindowAncestor(c) instanceof TipWindow);
boolean tipClicked = (c instanceof TipWindow)
|| (c != null && SwingUtilities.getWindowAncestor(c) instanceof TipWindow);
if (!tipClicked) {
possiblyDisposeOfTipWindow();
}
}
private void handleComponentEvent(ComponentEvent e) {
possiblyDisposeOfTipWindow();
}
public void install(JTextArea textArea) {
textArea.addCaretListener(this);
textArea.addComponentListener(this);
@@ -302,7 +303,7 @@ public class FocusableTip {
textArea.addMouseListener(this);
textArea.addMouseMotionListener(this);
}
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
@@ -314,25 +315,27 @@ public class FocusableTip {
}
}
}
@Override
public void keyReleased(KeyEvent e) {}
public void keyReleased(KeyEvent e) {
}
@Override
public void keyTyped(KeyEvent e) {}
public void keyTyped(KeyEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
// possiblyDisposeOfTipWindow();
}
@Override
public void mouseMoved(MouseEvent e) {
if (tipVisibleBounds == null || !tipVisibleBounds.contains(e.getPoint())) {
possiblyDisposeOfTipWindow();
}
}
public void uninstall() {
textArea.removeCaretListener(this);
textArea.removeComponentListener(this);
@@ -30,16 +30,16 @@ import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities;
* @version 1.0
*/
public final class TipUtil {
private TipUtil() {}
private TipUtil() {
}
/**
* Returns a hex string for the specified color, suitable for HTML.
*
* @param c
* The color.
* @return The string representation, in the form "<code>#rrggbb</code>",
* or <code>null</code> if <code>c</code> is <code>null</code>.
* @param c The color.
* @return The string representation, in the form "<code>#rrggbb</code>", or
* <code>null</code> if <code>c</code> is <code>null</code>.
*/
private static String getHexString(Color c) {
if (c == null) {
@@ -63,16 +63,14 @@ public final class TipUtil {
sb.append(Integer.toHexString(b));
return sb.toString();
}
/**
* Returns the screen coordinates for the monitor that contains the
* specified point. This is useful for setups with multiple monitors,
* to ensure that popup windows are positioned properly.
* Returns the screen coordinates for the monitor that contains the specified
* point. This is useful for setups with multiple monitors, to ensure that popup
* windows are positioned properly.
*
* @param x
* The x-coordinate, in screen coordinates.
* @param y
* The y-coordinate, in screen coordinates.
* @param x The x-coordinate, in screen coordinates.
* @param y The y-coordinate, in screen coordinates.
* @return The bounds of the monitor that contains the specified point.
*/
public static Rectangle getScreenBoundsForPoint(int x, int y) {
@@ -90,7 +88,7 @@ public final class TipUtil {
// If point is outside all monitors, default to default monitor (?)
return env.getMaximumWindowBounds();
}
/**
* Returns the default background color to use for tool tip windows.
*
@@ -113,7 +111,7 @@ public final class TipUtil {
}
return c;
}
/**
* Returns the border used by tool tips in this look and feel.
*
@@ -129,20 +127,19 @@ public final class TipUtil {
}
return border;
}
/**
* Returns whether a color is a Nimbus DerivedColor, which is troublesome
* in that it doesn't use its RGB values (uses HSB instead?) and so
* querying them is useless.
* Returns whether a color is a Nimbus DerivedColor, which is troublesome in
* that it doesn't use its RGB values (uses HSB instead?) and so querying them
* is useless.
*
* @param c
* The color to check.
* @param c The color to check.
* @return Whether it is a DerivedColor
*/
private static boolean isDerivedColor(Color c) {
return c != null && c.getClass().getName().endsWith(".DerivedColor");
}
/**
* Returns whether the Nimbus Look and Feel is installed.
*
@@ -151,14 +148,13 @@ public final class TipUtil {
private static boolean isNimbusLookAndFeel() {
return UIManager.getLookAndFeel().getName().equals("Nimbus");
}
/**
* Tweaks a <code>JEditorPane</code> so it can be used to render the
* content in a focusable pseudo-tool tip. It is assumed that the editor
* pane is using an <code>HTMLDocument</code>.
* Tweaks a <code>JEditorPane</code> so it can be used to render the content in
* a focusable pseudo-tool tip. It is assumed that the editor pane is using an
* <code>HTMLDocument</code>.
*
* @param textArea
* The editor pane to tweak.
* @param textArea The editor pane to tweak.
*/
public static void tweakTipEditorPane(JEditorPane textArea) {
// Jump through a few hoops to get things looking nice in Nimbus
@@ -198,21 +194,18 @@ public final class TipUtil {
Color linkFG = RSyntaxUtilities.getHyperlinkForeground();
doc.getStyleSheet().addRule("a { color: " + getHexString(linkFG) + "; }");
}
/**
* Sets the default font for an HTML document (e.g., in a tool tip
* displaying HTML). This is here because when rendering HTML,
* {@code setFont()} is not honored.
* Sets the default font for an HTML document (e.g., in a tool tip displaying
* HTML). This is here because when rendering HTML, {@code setFont()} is not
* honored.
*
* @param doc
* The document to modify.
* @param font
* The font to use.
* @param fg
* The default foreground color.
* @param doc The document to modify.
* @param font The font to use.
* @param fg The default foreground color.
*/
public static void setFont(HTMLDocument doc, Font font, Color fg) {
doc.getStyleSheet().addRule("body { font-family: " + font.getFamily() + "; font-size: " + font.getSize() + "pt" + "; color: "
+ getHexString(fg) + "; }");
doc.getStyleSheet().addRule("body { font-family: " + font.getFamily() + "; font-size: " + font.getSize() + "pt"
+ "; color: " + getHexString(fg) + "; }");
}
}
@@ -50,21 +50,19 @@ import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities;
* @version 1.0
*/
class TipWindow extends JWindow implements ActionListener {
private FocusableTip ft;
private JEditorPane textArea;
private String text;
private transient TipListener tipListener;
private transient HyperlinkListener userHyperlinkListener;
private static TipWindow visibleInstance;
/**
* Constructor.
*
* @param owner
* The parent window.
* @param msg
* The text of the tool tip. This can be HTML.
* @param owner The parent window.
* @param msg The text of the tool tip. This can be HTML.
*/
TipWindow(Window owner, FocusableTip ft, String msg) {
super(owner);
@@ -85,7 +83,7 @@ class TipWindow extends JWindow implements ActionListener {
}
textArea.addMouseListener(tipListener);
textArea.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
@@ -101,7 +99,7 @@ class TipWindow extends JWindow implements ActionListener {
// InputMap/ActionMap combo doesn't work for JWindows (even when
// using the JWindow's JRootPane), so we'll resort to KeyListener
KeyAdapter ka = new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
@@ -121,7 +119,7 @@ class TipWindow extends JWindow implements ActionListener {
visibleInstance = this;
}
}
@Override
public void actionPerformed(ActionEvent e) {
if (!getFocusableWindowState()) {
@@ -130,7 +128,7 @@ class TipWindow extends JWindow implements ActionListener {
textArea.removeMouseListener(tipListener);
pack();
addWindowFocusListener(new WindowAdapter() {
@Override
public void windowLostFocus(WindowEvent e) {
ft.possiblyDisposeOfTipWindow();
@@ -142,7 +140,7 @@ class TipWindow extends JWindow implements ActionListener {
}
}
}
/**
* Disposes of this window.
*/
@@ -157,10 +155,10 @@ class TipWindow extends JWindow implements ActionListener {
ft.removeListeners();
super.dispose();
}
/**
* Workaround for JEditorPane not returning its proper preferred size
* when rendering HTML until after layout already done. See
* Workaround for JEditorPane not returning its proper preferred size when
* rendering HTML until after layout already done. See
* http://forums.sun.com/thread.jspa?forumID=57&threadID=574810 for a
* discussion.
*/
@@ -195,11 +193,11 @@ class TipWindow extends JWindow implements ActionListener {
}
pack(); // Must re-pack to calculate proper size.
}
public String getText() {
return text;
}
private void setBottomPanel() {
final JPanel panel = new JPanel(new BorderLayout());
panel.add(new JSeparator(), BorderLayout.NORTH);
@@ -209,9 +207,9 @@ class TipWindow extends JWindow implements ActionListener {
sg.applyComponentOrientation(sg.getComponentOrientation()); // Workaround
panel.add(sg, BorderLayout.LINE_END);
MouseInputAdapter adapter = new MouseInputAdapter() {
private Point lastPoint;
@Override
public void mouseDragged(MouseEvent e) {
Point p = e.getPoint();
@@ -225,7 +223,7 @@ class TipWindow extends JWindow implements ActionListener {
lastPoint = p;
}
}
@Override
public void mousePressed(MouseEvent e) {
lastPoint = e.getPoint();
@@ -272,13 +270,12 @@ class TipWindow extends JWindow implements ActionListener {
}
cp.add(panel, BorderLayout.SOUTH);
}
/**
* Sets the listener for hyperlink events in this tip window.
*
* @param listener
* The new listener. The old listener (if any) is
* removed. A value of <code>null</code> means "no listener."
* @param listener The new listener. The old listener (if any) is removed. A
* value of <code>null</code> means "no listener."
*/
public void setHyperlinkListener(HyperlinkListener listener) {
// We've added a separate listener, so remove only the user's.
@@ -290,19 +287,20 @@ class TipWindow extends JWindow implements ActionListener {
textArea.addHyperlinkListener(userHyperlinkListener);
}
}
/**
* Listens for events in this window.
*/
private final class TipListener extends MouseAdapter {
private TipListener() {}
private TipListener() {
}
@Override
public void mousePressed(MouseEvent e) {
actionPerformed(null); // Manually create "real" window
}
@Override
public void mouseExited(MouseEvent e) {
// Since we registered this listener on the child components of
@@ -15,24 +15,23 @@ import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.Token;
/**
* A basic fold parser that can be used for languages such as C, that use
* curly braces to denote code blocks. This parser searches for curly brace
* pairs and creates code folds out of them. It can also optionally find
* C-style multi-line comments ("<code>/* ... *&#47;</code>") and make them
* foldable as well.
* A basic fold parser that can be used for languages such as C, that use curly
* braces to denote code blocks. This parser searches for curly brace pairs and
* creates code folds out of them. It can also optionally find C-style
* multi-line comments ("<code>/* ... *&#47;</code>") and make them foldable as
* well.
* <p>
*
* This parser knows nothing about language semantics; it uses
* <code>RSyntaxTextArea</code>'s syntax highlighting tokens to identify
* curly braces. By default, it looks for single-char tokens of type
* <code>RSyntaxTextArea</code>'s syntax highlighting tokens to identify curly
* braces. By default, it looks for single-char tokens of type
* {@link Token#SEPARATOR}, with lexemes '<code>{</code>' or '<code>}</code>'.
* If your {@link org.fife.ui.rsyntaxtextarea.TokenMaker} uses a different token
* type for curly braces, you should override the {@link #isLeftCurly(Token)}
* and
* {@link #isRightCurly(Token)} methods with your own definitions. In theory,
* you could extend this fold parser to parse languages that use completely
* different tokens than curly braces to denote foldable regions by overriding
* those two methods.
* and {@link #isRightCurly(Token)} methods with your own definitions. In
* theory, you could extend this fold parser to parse languages that use
* completely different tokens than curly braces to denote foldable regions by
* overriding those two methods.
* <p>
*
* Note also that this class may impose somewhat of a performance penalty on
@@ -43,7 +42,7 @@ import org.fife.ui.rsyntaxtextarea.Token;
* @version 1.0
*/
public class CurlyFoldParser implements FoldParser {
/**
* Whether to scan for C-style multi-line comments and make them foldable.
*/
@@ -60,31 +59,29 @@ public class CurlyFoldParser implements FoldParser {
* Ending of a multi-line comment in C, C++, Java, etc.
*/
protected static final char[] C_MLC_END = "*/".toCharArray();
/**
* Creates a fold parser that identifies foldable regions via curly braces
* as well as C-style multi-line comments.
* Creates a fold parser that identifies foldable regions via curly braces as
* well as C-style multi-line comments.
*/
public CurlyFoldParser() {
this(true, false);
}
/**
* Constructor.
*
* @param cStyleMultiLineComments
* Whether to scan for C-style multi-line
* comments and make them foldable.
* @param java
* Whether this parser is folding Java. This adds extra
* parsing rules, such as grouping all import statements into a
* fold section.
* @param cStyleMultiLineComments Whether to scan for C-style multi-line
* comments and make them foldable.
* @param java Whether this parser is folding Java. This adds
* extra parsing rules, such as grouping all
* import statements into a fold section.
*/
public CurlyFoldParser(boolean cStyleMultiLineComments, boolean java) {
this.foldableMultiLineComments = cStyleMultiLineComments;
this.java = java;
}
/**
* Returns whether multi-line comments are foldable with this parser.
*
@@ -94,7 +91,7 @@ public class CurlyFoldParser implements FoldParser {
public boolean getFoldableMultiLineComments() {
return foldableMultiLineComments;
}
/**
* {@inheritDoc}
*/
@@ -256,38 +253,35 @@ public class CurlyFoldParser implements FoldParser {
}
return folds;
}
/**
* Returns whether the token is a left curly brace. This method exists
* so subclasses can provide their own curly brace definition.
* Returns whether the token is a left curly brace. This method exists so
* subclasses can provide their own curly brace definition.
*
* @param t
* The token.
* @param t The token.
* @return Whether it is a left curly brace.
* @see #isRightCurly(Token)
*/
public boolean isLeftCurly(Token t) {
return t.isLeftCurly();
}
/**
* Returns whether the token is a right curly brace. This method exists
* so subclasses can provide their own curly brace definition.
* Returns whether the token is a right curly brace. This method exists so
* subclasses can provide their own curly brace definition.
*
* @param t
* The token.
* @param t The token.
* @return Whether it is a right curly brace.
* @see #isLeftCurly(Token)
*/
public boolean isRightCurly(Token t) {
return t.isRightCurly();
}
/**
* Sets whether multi-line comments are foldable with this parser.
*
* @param foldable
* Whether multi-line comments are foldable.
* @param foldable Whether multi-line comments are foldable.
* @see #getFoldableMultiLineComments()
*/
public void setFoldableMultiLineComments(boolean foldable) {
@@ -28,16 +28,16 @@ import org.fife.ui.rsyntaxtextarea.parser.Parser;
import org.fife.ui.rtextarea.RDocument;
/**
* The default implementation of a fold manager. Besides keeping track of
* folds, this class behaves as follows:
* The default implementation of a fold manager. Besides keeping track of folds,
* this class behaves as follows:
*
* <ul>
* <li>If text containing a newline is inserted in a collapsed fold,
* that fold, and any ancestor folds, are expanded. This ensures that
* modified text is always visible to the user.
* <li>If the text area's {@link RSyntaxTextArea#SYNTAX_STYLE_PROPERTY}
* changes, the current fold parser is uninstalled, and one appropriate
* for the new language, if any, is installed.
* <li>If text containing a newline is inserted in a collapsed fold, that fold,
* and any ancestor folds, are expanded. This ensures that modified text is
* always visible to the user.
* <li>If the text area's {@link RSyntaxTextArea#SYNTAX_STYLE_PROPERTY} changes,
* the current fold parser is uninstalled, and one appropriate for the new
* language, if any, is installed.
* </ul>
*
* The folding strategy to use is retrieved from {@link FoldParserManager}.
@@ -46,7 +46,7 @@ import org.fife.ui.rtextarea.RDocument;
* @version 1.0
*/
public class DefaultFoldManager implements FoldManager {
private RSyntaxTextArea textArea;
private Parser rstaParser;
private FoldParser foldParser;
@@ -54,12 +54,11 @@ public class DefaultFoldManager implements FoldManager {
private boolean codeFoldingEnabled;
private PropertyChangeSupport support;
private Listener l;
/**
* Constructor.
*
* @param textArea
* The text area whose folds we are managing.
* @param textArea The text area whose folds we are managing.
*/
public DefaultFoldManager(RSyntaxTextArea textArea) {
this.textArea = textArea;
@@ -71,17 +70,17 @@ public class DefaultFoldManager implements FoldManager {
folds = new ArrayList<Fold>();
updateFoldParser();
}
@Override
public void addPropertyChangeListener(PropertyChangeListener l) {
support.addPropertyChangeListener(l);
}
@Override
public void clear() {
folds.clear();
}
@Override
public boolean ensureOffsetNotInClosedFold(int offs) {
boolean foldsOpened = false;
@@ -98,7 +97,7 @@ public class DefaultFoldManager implements FoldManager {
}
return foldsOpened;
}
@Override
public Fold getDeepestFoldContaining(int offs) {
Fold deepestFold = null;
@@ -113,7 +112,7 @@ public class DefaultFoldManager implements FoldManager {
}
return deepestFold;
}
@Override
public Fold getDeepestOpenFoldContaining(int offs) {
Fold deepestFold = null;
@@ -131,22 +130,22 @@ public class DefaultFoldManager implements FoldManager {
}
return deepestFold;
}
@Override
public Fold getFold(int index) {
return folds.get(index);
}
@Override
public int getFoldCount() {
return folds.size();
}
@Override
public Fold getFoldForLine(int line) {
return getFoldForLineImpl(null, folds, line);
}
private Fold getFoldForLineImpl(Fold parent, List<Fold> folds, int line) {
int low = 0;
int high = folds.size() - 1;
@@ -170,7 +169,7 @@ public class DefaultFoldManager implements FoldManager {
}
return null; // No fold for this line
}
@Override
public int getHiddenLineCount() {
int count = 0;
@@ -179,12 +178,12 @@ public class DefaultFoldManager implements FoldManager {
}
return count;
}
@Override
public int getHiddenLineCountAbove(int line) {
return getHiddenLineCountAbove(line, false);
}
@Override
public int getHiddenLineCountAbove(int line, boolean physical) {
int count = 0;
@@ -197,27 +196,21 @@ public class DefaultFoldManager implements FoldManager {
}
return count;
}
/**
* Returns the number of lines "hidden" by collapsed folds above the
* specified line.
* Returns the number of lines "hidden" by collapsed folds above the specified
* line.
*
* @param fold
* The current fold in the recursive algorithm. It and its
* children are examined.
* @param line
* The line.
* @param physical
* Whether <code>line</code> is the number of a physical
* line (i.e. visible, not code-folded), or a logical one (i.e.
* any
* line from the model). If <code>line</code> was determined by a
* raw line calculation (i.e.
* <code>(visibleTopY / lineHeight)</code>),
* this value should be <code>true</code>. It should be
* <code>false</code> when it was calculated from an offset in
* the
* document (for example).
* @param fold The current fold in the recursive algorithm. It and its
* children are examined.
* @param line The line.
* @param physical Whether <code>line</code> is the number of a physical line
* (i.e. visible, not code-folded), or a logical one (i.e. any
* line from the model). If <code>line</code> was determined by
* a raw line calculation (i.e.
* <code>(visibleTopY / lineHeight)</code>), this value should
* be <code>true</code>. It should be <code>false</code> when it
* was calculated from an offset in the document (for example).
* @return The number of lines hidden in folds that are descendants of
* <code>fold</code>, or <code>fold</code> itself, above
* <code>line</code>.
@@ -239,7 +232,7 @@ public class DefaultFoldManager implements FoldManager {
}
return count;
}
@Override
public int getLastVisibleLine() {
int lastLine = textArea.getLineCount() - 1;
@@ -268,7 +261,7 @@ public class DefaultFoldManager implements FoldManager {
}
return lastLine;
}
@Override
public int getVisibleLineAbove(int line) {
if (line <= 0 || line >= textArea.getLineCount()) {
@@ -279,7 +272,7 @@ public class DefaultFoldManager implements FoldManager {
} while (line >= 0 && isLineHidden(line));
return line;
}
@Override
public int getVisibleLineBelow(int line) {
int lineCount = textArea.getLineCount();
@@ -291,7 +284,7 @@ public class DefaultFoldManager implements FoldManager {
} while (line < lineCount && isLineHidden(line));
return line == lineCount ? -1 : line;
}
// private static int binaryFindFoldContainingLine(int line) {
//
// List allFolds;
@@ -320,17 +313,17 @@ public class DefaultFoldManager implements FoldManager {
public boolean isCodeFoldingEnabled() {
return codeFoldingEnabled;
}
@Override
public boolean isCodeFoldingSupportedAndEnabled() {
return codeFoldingEnabled && foldParser != null;
}
@Override
public boolean isFoldStartLine(int line) {
return getFoldForLine(line) != null;
}
@Override
public boolean isLineHidden(int line) {
for (Fold fold : folds) {
@@ -344,7 +337,7 @@ public class DefaultFoldManager implements FoldManager {
}
return false;
}
private boolean isLineHiddenImpl(Fold parent, int line) {
for (int i = 0; i < parent.getChildCount(); i++) {
Fold child = parent.getChild(i);
@@ -358,7 +351,7 @@ public class DefaultFoldManager implements FoldManager {
}
return false;
}
private void keepFoldState(Fold newFold, List<Fold> oldFolds) {
int previousLoc = Collections.binarySearch(oldFolds, newFold);
// System.out.println(newFold + " => " + previousLoc);
@@ -379,7 +372,7 @@ public class DefaultFoldManager implements FoldManager {
}
}
}
private void keepFoldStates(List<Fold> newFolds, List<Fold> oldFolds) {
for (Fold newFold : newFolds) {
keepFoldState(newFold, folds);
@@ -389,12 +382,12 @@ public class DefaultFoldManager implements FoldManager {
}
}
}
@Override
public void removePropertyChangeListener(PropertyChangeListener l) {
support.removePropertyChangeListener(l);
}
@Override
public void reparse() {
if (codeFoldingEnabled && foldParser != null) {
@@ -414,7 +407,7 @@ public class DefaultFoldManager implements FoldManager {
folds.clear();
}
}
@Override
public void setCodeFoldingEnabled(boolean enabled) {
if (enabled != codeFoldingEnabled) {
@@ -424,7 +417,7 @@ public class DefaultFoldManager implements FoldManager {
}
if (enabled) {
rstaParser = new AbstractParser() {
@Override
public ParseResult parse(RSyntaxDocument doc, String style) {
reparse();
@@ -441,28 +434,29 @@ public class DefaultFoldManager implements FoldManager {
}
}
}
@Override
public void setFolds(List<Fold> folds) {
this.folds = folds;
}
/**
* Updates the fold parser to be the one appropriate for the language
* currently being highlighted.
* Updates the fold parser to be the one appropriate for the language currently
* being highlighted.
*/
private void updateFoldParser() {
foldParser = FoldParserManager.get().getFoldParser(textArea.getSyntaxEditingStyle());
}
/**
* Listens for events in the text editor.
*/
private class Listener implements DocumentListener, PropertyChangeListener {
@Override
public void changedUpdate(DocumentEvent e) {}
public void changedUpdate(DocumentEvent e) {
}
@Override
public void insertUpdate(DocumentEvent e) {
// Adding text containing a newline to the visible line of a folded
@@ -481,7 +475,7 @@ public class DefaultFoldManager implements FoldManager {
}
}
}
@Override
public void propertyChange(PropertyChangeEvent e) {
String name = e.getPropertyName();
@@ -502,7 +496,7 @@ public class DefaultFoldManager implements FoldManager {
reparse();
}
}
@Override
public void removeUpdate(DocumentEvent e) {
// Removing text from the visible line of a folded Fold causes that
+106 -129
View File
@@ -34,7 +34,7 @@ import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
* @version 1.0
*/
public class Fold implements Comparable<Fold> {
private int type;
private RSyntaxTextArea textArea;
private Position startOffs;
@@ -47,23 +47,20 @@ public class Fold implements Comparable<Fold> {
private int cachedStartLine;
private int lastEndOffs = -1;
private int cachedEndLine;
public Fold(int type, RSyntaxTextArea textArea, int startOffs) throws BadLocationException {
this.type = type;
this.textArea = textArea;
this.startOffs = textArea.getDocument().createPosition(startOffs);
}
/**
* Creates a fold that is a child of this one.
*
* @param type
* The type of fold.
* @param startOffs
* The starting offset of the fold.
* @param type The type of fold.
* @param startOffs The starting offset of the fold.
* @return The child fold.
* @throws BadLocationException
* If <code>startOffs</code> is invalid.
* @throws BadLocationException If <code>startOffs</code> is invalid.
* @see FoldType
*/
public Fold createChild(int type, int startOffs) throws BadLocationException {
@@ -75,12 +72,11 @@ public class Fold implements Comparable<Fold> {
children.add(child);
return child;
}
/**
* Two folds are considered equal if they start at the same offset.
*
* @param otherFold
* Another fold to compare this one to.
* @param otherFold Another fold to compare this one to.
* @return How this fold compares to the other.
*/
@Override
@@ -92,15 +88,14 @@ public class Fold implements Comparable<Fold> {
}
return result;
}
/**
* Returns whether the specified line would be hidden in this fold. Since
* RSTA displays the "first" line in a fold, this means that the line must
* must be between <code>(getStartLine()+1)</code> and
* <code>getEndLine()</code>, inclusive.
* Returns whether the specified line would be hidden in this fold. Since RSTA
* displays the "first" line in a fold, this means that the line must must be
* between <code>(getStartLine()+1)</code> and <code>getEndLine()</code>,
* inclusive.
*
* @param line
* The line to check.
* @param line The line to check.
* @return Whether the line would be hidden if this fold is collapsed.
* @see #containsOffset(int)
* @see #containsOrStartsOnLine(int)
@@ -108,27 +103,25 @@ public class Fold implements Comparable<Fold> {
public boolean containsLine(int line) {
return line > getStartLine() && line <= getEndLine();
}
/**
* Returns whether the given line is in the range
* <code>[getStartLine(), getEndLine()]</code>, inclusive.
*
* @param line
* The line to check.
* @param line The line to check.
* @return Whether this fold contains, or starts on, the line.
* @see #containsLine(int)
*/
public boolean containsOrStartsOnLine(int line) {
return line >= getStartLine() && line <= getEndLine();
}
/**
* Returns whether the specified offset is "inside" the fold. This method
* returns <code>true</code> if the offset is greater than the fold start
* offset, and no further than the last offset of the last folded line.
*
* @param offs
* The offset to check.
* @param offs The offset to check.
* @return Whether the offset is "inside" the fold.
* @see #containsLine(int)
*/
@@ -142,12 +135,11 @@ public class Fold implements Comparable<Fold> {
}
return contained;
}
/**
* Two folds are considered equal if they have the same starting offset.
*
* @param otherFold
* Another fold to compare this one to.
* @param otherFold Another fold to compare this one to.
* @return Whether the two folds are equal.
* @see #compareTo(Fold)
*/
@@ -155,19 +147,18 @@ public class Fold implements Comparable<Fold> {
public boolean equals(Object otherFold) {
return otherFold instanceof Fold && compareTo((Fold) otherFold) == 0;
}
/**
* Returns a specific child fold.
*
* @param index
* The index of the child fold.
* @param index The index of the child fold.
* @return The child fold.
* @see #getChildCount()
*/
public Fold getChild(int index) {
return children.get(index);
}
/**
* Returns the number of child folds.
*
@@ -177,42 +168,39 @@ public class Fold implements Comparable<Fold> {
public int getChildCount() {
return children == null ? 0 : children.size();
}
/**
* Returns the array of child folds. This is a shallow copy.
*
* @return The array of child folds, or <code>null</code> if there are
* none.
* @return The array of child folds, or <code>null</code> if there are none.
*/
List<Fold> getChildren() {
return children;
}
/**
* Returns the number of collapsed lines under this fold. If this fold
* is collapsed, this method returns {@link #getLineCount()}, otherwise
* it returns the sum of all collapsed lines of all child folds of this
* one.
* Returns the number of collapsed lines under this fold. If this fold is
* collapsed, this method returns {@link #getLineCount()}, otherwise it returns
* the sum of all collapsed lines of all child folds of this one.
* <p>
*
* The value returned is cached, so this method returns quickly and
* shouldn't affect performance.
* The value returned is cached, so this method returns quickly and shouldn't
* affect performance.
*
* @return The number of collapsed lines under this fold.
*/
public int getCollapsedLineCount() {
return collapsed ? getLineCount() : childCollapsedLineCount;
}
/**
* Returns the "deepest" fold containing the specified offset. It is
* assumed that it's already been verified that <code>offs</code> is indeed
* contained in this fold.
* Returns the "deepest" fold containing the specified offset. It is assumed
* that it's already been verified that <code>offs</code> is indeed contained in
* this fold.
*
* @param offs
* The offset.
* @return The fold, or <code>null</code> if no child fold also contains
* the offset.
* @param offs The offset.
* @return The fold, or <code>null</code> if no child fold also contains the
* offset.
* @see FoldManager#getDeepestFoldContaining(int)
*/
Fold getDeepestFoldContaining(int offs) {
@@ -226,16 +214,14 @@ public class Fold implements Comparable<Fold> {
}
return deepestFold;
}
/**
* Returns the "deepest" open fold containing the specified offset. It
* is assumed that it's already been verified that <code>offs</code> is
* indeed contained in this fold.
* Returns the "deepest" open fold containing the specified offset. It is
* assumed that it's already been verified that <code>offs</code> is indeed
* contained in this fold.
*
* @param offs
* The offset.
* @return The fold, or <code>null</code> if no open fold contains the
* offset.
* @param offs The offset.
* @return The fold, or <code>null</code> if no open fold contains the offset.
* @see FoldManager#getDeepestOpenFoldContaining(int)
*/
Fold getDeepestOpenFoldContaining(int offs) {
@@ -252,16 +238,15 @@ public class Fold implements Comparable<Fold> {
}
return deepestFold;
}
/**
* Returns the end line of this fold. For example, in languages such as
* C and Java, this might be the line containing the closing curly brace of
* a code block.
* Returns the end line of this fold. For example, in languages such as C and
* Java, this might be the line containing the closing curly brace of a code
* block.
* <p>
*
* The value returned by this method will automatically update as the
* text area's contents are modified, to track the ending line of the
* code block.
* The value returned by this method will automatically update as the text
* area's contents are modified, to track the ending line of the code block.
*
* @return The end line of this code block.
* @see #getEndOffset()
@@ -276,27 +261,25 @@ public class Fold implements Comparable<Fold> {
Element root = textArea.getDocument().getDefaultRootElement();
return cachedEndLine = root.getElementIndex(endOffs);
}
/**
* Returns the end offset of this fold. For example, in languages such as
* C and Java, this might be the offset of the closing curly brace of a
* code block.
* Returns the end offset of this fold. For example, in languages such as C and
* Java, this might be the offset of the closing curly brace of a code block.
* <p>
*
* The value returned by this method will automatically update as the
* text area's contents are modified, to track the ending offset of the
* code block.
* The value returned by this method will automatically update as the text
* area's contents are modified, to track the ending offset of the code block.
*
* @return The end offset of this code block, or {@link Integer#MAX_VALUE}
* if this fold region isn't closed properly. The latter causes
* this fold to collapsed all lines through the end of the file.
* @return The end offset of this code block, or {@link Integer#MAX_VALUE} if
* this fold region isn't closed properly. The latter causes this fold
* to collapsed all lines through the end of the file.
* @see #getEndLine()
* @see #getStartOffset()
*/
public int getEndOffset() {
return endOffs != null ? endOffs.getOffset() : Integer.MAX_VALUE;
}
/**
* Returns the type of fold this is. This will be one of the values in
* {@link FoldType}, or a user-defined value.
@@ -306,7 +289,7 @@ public class Fold implements Comparable<Fold> {
public int getFoldType() {
return type;
}
/**
* Returns whether this fold has any child folds.
*
@@ -316,12 +299,12 @@ public class Fold implements Comparable<Fold> {
public boolean getHasChildFolds() {
return getChildCount() > 0;
}
/**
* Returns the last child fold.
*
* @return The last child fold, or <code>null</code> if this fold does not
* have any children.
* @return The last child fold, or <code>null</code> if this fold does not have
* any children.
* @see #getChild(int)
* @see #getHasChildFolds()
*/
@@ -329,10 +312,9 @@ public class Fold implements Comparable<Fold> {
int childCount = getChildCount();
return childCount == 0 ? null : getChild(childCount - 1);
}
/**
* Returns the number of lines that are hidden when this fold is
* collapsed.
* Returns the number of lines that are hidden when this fold is collapsed.
*
* @return The number of lines hidden.
* @see #getStartLine()
@@ -341,25 +323,23 @@ public class Fold implements Comparable<Fold> {
public int getLineCount() {
return getEndLine() - getStartLine();
}
/**
* Returns the parent fold of this one.
*
* @return The parent fold, or <code>null</code> if this is a top-level
* fold.
* @return The parent fold, or <code>null</code> if this is a top-level fold.
*/
public Fold getParent() {
return parent;
}
/**
* Returns the starting line of this fold region. This is the only line
* in the fold region that is not hidden when a fold is collapsed.
* Returns the starting line of this fold region. This is the only line in the
* fold region that is not hidden when a fold is collapsed.
* <p>
*
* The value returned by this method will automatically update as the
* text area's contents are modified, to track the starting line of the
* code block.
* The value returned by this method will automatically update as the text
* area's contents are modified, to track the starting line of the code block.
*
* @return The starting line of the code block.
* @see #getEndLine()
@@ -374,16 +354,15 @@ public class Fold implements Comparable<Fold> {
Element root = textArea.getDocument().getDefaultRootElement();
return cachedStartLine = root.getElementIndex(startOffs);
}
/**
* Returns the starting offset of this fold region. For example, for
* languages such as C and Java, this would be the offset of the opening
* curly brace of a code block.
* Returns the starting offset of this fold region. For example, for languages
* such as C and Java, this would be the offset of the opening curly brace of a
* code block.
* <p>
*
* The value returned by this method will automatically update as the
* text area's contents are modified, to track the starting offset of the
* code block.
* The value returned by this method will automatically update as the text
* area's contents are modified, to track the starting offset of the code block.
*
* @return The start offset of this fold.
* @see #getStartLine()
@@ -392,12 +371,12 @@ public class Fold implements Comparable<Fold> {
public int getStartOffset() {
return startOffs.getOffset();
}
@Override
public int hashCode() {
return getStartLine();
}
/**
* Returns whether this fold is collapsed.
*
@@ -408,11 +387,11 @@ public class Fold implements Comparable<Fold> {
public boolean isCollapsed() {
return collapsed;
}
/**
* Returns whether this fold is entirely on a single line. In general,
* a {@link FoldParser} should not remember fold regions all on a single
* line, since there's really nothing to fold.
* Returns whether this fold is entirely on a single line. In general, a
* {@link FoldParser} should not remember fold regions all on a single line,
* since there's really nothing to fold.
*
* @return Whether this fold is on a single line.
* @see #removeFromParent()
@@ -420,11 +399,11 @@ public class Fold implements Comparable<Fold> {
public boolean isOnSingleLine() {
return getStartLine() == getEndLine();
}
/**
* Removes this fold from its parent. This should only be called by
* {@link FoldParser} implementations if they determine that a fold is all
* on a single line (and thus shouldn't be remembered) after creating it.
* {@link FoldParser} implementations if they determine that a fold is all on a
* single line (and thus shouldn't be remembered) after creating it.
*
* @return Whether this fold had a parent to be removed from.
* @see #isOnSingleLine()
@@ -437,17 +416,16 @@ public class Fold implements Comparable<Fold> {
}
return false;
}
private void removeMostRecentChild() {
children.remove(children.size() - 1);
}
/**
* Sets whether this <code>Fold</code> is collapsed. Calling this method
* will update both the text area and all <code>Gutter</code> components.
* Sets whether this <code>Fold</code> is collapsed. Calling this method will
* update both the text area and all <code>Gutter</code> components.
*
* @param collapsed
* Whether this fold should be collapsed.
* @param collapsed Whether this fold should be collapsed.
* @see #isCollapsed()
* @see #toggleCollapsedState()
*/
@@ -487,24 +465,22 @@ public class Fold implements Comparable<Fold> {
textArea.foldToggled(this);
}
}
/**
* Sets the ending offset of this fold, such as the closing curly brace
* of a code block in C or Java. {@link FoldParser} implementations should
* call this on an existing <code>Fold</code> upon finding its end. If
* this method isn't called, then this <code>Fold</code> is considered to
* have no end, i.e., it will collapse everything to the end of the file.
* Sets the ending offset of this fold, such as the closing curly brace of a
* code block in C or Java. {@link FoldParser} implementations should call this
* on an existing <code>Fold</code> upon finding its end. If this method isn't
* called, then this <code>Fold</code> is considered to have no end, i.e., it
* will collapse everything to the end of the file.
*
* @param endOffs
* The end offset of this fold.
* @throws BadLocationException
* If <code>endOffs</code> is not a valid
* location in the text area.
* @param endOffs The end offset of this fold.
* @throws BadLocationException If <code>endOffs</code> is not a valid location
* in the text area.
*/
public void setEndOffset(int endOffs) throws BadLocationException {
this.endOffs = textArea.getDocument().createPosition(endOffs);
}
/**
* Toggles the collapsed state of this fold.
*
@@ -513,7 +489,7 @@ public class Fold implements Comparable<Fold> {
public void toggleCollapsedState() {
setCollapsed(!collapsed);
}
private void updateChildCollapsedLineCount(int count) {
childCollapsedLineCount += count;
// if (childCollapsedLineCount>getLineCount()) {
@@ -523,7 +499,7 @@ public class Fold implements Comparable<Fold> {
parent.updateChildCollapsedLineCount(count);
}
}
/**
* Overridden for debugging purposes.
*
@@ -531,6 +507,7 @@ public class Fold implements Comparable<Fold> {
*/
@Override
public String toString() {
return "[Fold: " + "startOffs=" + getStartOffset() + ", endOffs=" + getEndOffset() + ", collapsed=" + collapsed + "]";
return "[Fold: " + "startOffs=" + getStartOffset() + ", endOffs=" + getEndOffset() + ", collapsed=" + collapsed
+ "]";
}
}
@@ -11,51 +11,47 @@ import java.util.ArrayList;
import java.util.List;
/**
* Collapses folds based on their type. You can create an instance of this
* class to collapse all comment blocks when opening a new file, for example.
* Collapses folds based on their type. You can create an instance of this class
* to collapse all comment blocks when opening a new file, for example.
*
* @author Robert Futrell
* @version 1.0
*/
public class FoldCollapser {
private List<Integer> typesToCollapse;
/**
* Creates an instance that collapses all comment blocks.
*/
public FoldCollapser() {
this(FoldType.COMMENT);
}
/**
* Creates an instance that collapses all blocks of the specified
* type.
* Creates an instance that collapses all blocks of the specified type.
*
* @param typeToCollapse
* The type to collapse.
* @param typeToCollapse The type to collapse.
* @see FoldType
*/
public FoldCollapser(int typeToCollapse) {
typesToCollapse = new ArrayList<Integer>(3);
addTypeToCollapse(typeToCollapse);
}
/**
* Adds a type of fold to collapse.
*
* @param typeToCollapse
* The type of fold to collapse.
* @param typeToCollapse The type of fold to collapse.
*/
public void addTypeToCollapse(int typeToCollapse) {
typesToCollapse.add(Integer.valueOf(typeToCollapse));
}
/**
* Collapses any relevant folds known by the fold manager.
*
* @param fm
* The fold manager.
* @param fm The fold manager.
*/
public void collapseFolds(FoldManager fm) {
for (int i = 0; i < fm.getFoldCount(); i++) {
@@ -63,13 +59,11 @@ public class FoldCollapser {
collapseImpl(fold);
}
}
/**
* Collapses the specified fold, and any of its child folds, as
* appropriate.
* Collapses the specified fold, and any of its child folds, as appropriate.
*
* @param fold
* The fold to examine.
* @param fold The fold to examine.
* @see #getShouldCollapse(Fold)
*/
protected void collapseImpl(Fold fold) {
@@ -80,12 +74,11 @@ public class FoldCollapser {
collapseImpl(fold.getChild(i));
}
}
/**
* Returns whether a specific fold should be collapsed.
*
* @param fold
* The fold to examine.
* @param fold The fold to examine.
* @return Whether the fold should be collapsed.
*/
public boolean getShouldCollapse(Fold fold) {
@@ -21,67 +21,61 @@ import java.util.List;
* @see DefaultFoldManager
*/
public interface FoldManager {
/**
* Property fired when folds have been updated.
*/
String PROPERTY_FOLDS_UPDATED = "FoldsUpdated";
/**
* Adds a property change listener to this fold manager.
*
* @param l
* The new listener.
* @param l The new listener.
* @see #removePropertyChangeListener(PropertyChangeListener)
*/
void addPropertyChangeListener(PropertyChangeListener l);
/**
* Removes all folds.
*/
void clear();
/**
* Ensures that the specified offset is not hidden in a collapsed fold.
* Any folds containing this offset that are collapsed will be expanded.
* Ensures that the specified offset is not hidden in a collapsed fold. Any
* folds containing this offset that are collapsed will be expanded.
*
* @param offs
* The offset.
* @param offs The offset.
* @return Whether any folds had to be opened.
* @see #getDeepestFoldContaining(int)
*/
boolean ensureOffsetNotInClosedFold(int offs);
/**
* Returns the "deepest" nested fold containing the specified offset.
*
* @param offs
* The offset.
* @return The deepest fold containing the offset, or <code>null</code> if
* no fold contains the offset.
* @param offs The offset.
* @return The deepest fold containing the offset, or <code>null</code> if no
* fold contains the offset.
*/
Fold getDeepestFoldContaining(int offs);
/**
* Returns the "deepest" open fold containing the specified offset.
*
* @param offs
* The offset.
* @return The fold, or <code>null</code> if no open fold contains the
* offset.
* @param offs The offset.
* @return The fold, or <code>null</code> if no open fold contains the offset.
*/
Fold getDeepestOpenFoldContaining(int offs);
/**
* Returns a specific top-level fold, which may have child folds.
*
* @param index
* The index of the fold.
* @param index The index of the fold.
* @return The fold.
* @see #getFoldCount()
*/
Fold getFold(int index);
/**
* Returns the number of top-level folds.
*
@@ -89,18 +83,17 @@ public interface FoldManager {
* @see #getFold(int)
*/
int getFoldCount();
/**
* Returns the fold region that starts at the specified line.
*
* @param line
* The line number.
* @return The fold, or <code>null</code> if the line is not the start
* of a fold region.
* @param line The line number.
* @return The fold, or <code>null</code> if the line is not the start of a fold
* region.
* @see #isFoldStartLine(int)
*/
Fold getFoldForLine(int line);
/**
* Returns the total number of hidden (folded) lines.
*
@@ -108,127 +101,112 @@ public interface FoldManager {
* @see #getHiddenLineCountAbove(int)
*/
int getHiddenLineCount();
/**
* Returns the number of lines "hidden" by collapsed folds above the
* specified line.
* Returns the number of lines "hidden" by collapsed folds above the specified
* line.
*
* @param line
* The line. This is the line number for a logical line.
* For the line number of a physical line (i.e. visible, not
* folded),
* use <code>getHiddenLineCountAbove(int, true)</code>.
* @param line The line. This is the line number for a logical line. For the
* line number of a physical line (i.e. visible, not folded), use
* <code>getHiddenLineCountAbove(int, true)</code>.
* @return The number of lines hidden in folds above <code>line</code>.
* @see #getHiddenLineCountAbove(int, boolean)
*/
int getHiddenLineCountAbove(int line);
/**
* Returns the number of lines "hidden" by collapsed folds above the
* specified line.
* Returns the number of lines "hidden" by collapsed folds above the specified
* line.
*
* @param line
* The line.
* @param physical
* Whether <code>line</code> is the number of a physical
* line (i.e. visible, not code-folded), or a logical one (i.e.
* any
* line from the model). If <code>line</code> was determined by a
* raw line calculation (i.e.
* <code>(visibleTopY / lineHeight)</code>),
* this value should be <code>true</code>. It should be
* <code>false</code> when it was calculated from an offset in
* the
* document (for example).
* @param line The line.
* @param physical Whether <code>line</code> is the number of a physical line
* (i.e. visible, not code-folded), or a logical one (i.e. any
* line from the model). If <code>line</code> was determined by
* a raw line calculation (i.e.
* <code>(visibleTopY / lineHeight)</code>), this value should
* be <code>true</code>. It should be <code>false</code> when it
* was calculated from an offset in the document (for example).
* @return The number of lines hidden in folds above <code>line</code>.
*/
int getHiddenLineCountAbove(int line, boolean physical);
/**
* Returns the last visible line in the text area, taking into account
* folds.
* Returns the last visible line in the text area, taking into account folds.
*
* @return The last visible line.
*/
int getLastVisibleLine();
int getVisibleLineAbove(int line);
int getVisibleLineBelow(int line);
/**
* Returns whether code folding is enabled. Note that only certain
* languages support code folding; those that do not will ignore this
* property.
* Returns whether code folding is enabled. Note that only certain languages
* support code folding; those that do not will ignore this property.
*
* @return Whether code folding is enabled.
* @see #setCodeFoldingEnabled(boolean)
*/
boolean isCodeFoldingEnabled();
/**
* Returns <code>true</code> if and only if code folding is enabled for
* this text area, AND folding is supported for the language it is editing.
* Whether or not folding is supported for a language depends on whether
* a fold parser is registered for that language with the
* <code>FoldParserManager</code>.
* Returns <code>true</code> if and only if code folding is enabled for this
* text area, AND folding is supported for the language it is editing. Whether
* or not folding is supported for a language depends on whether a fold parser
* is registered for that language with the <code>FoldParserManager</code>.
*
* @return Whether folding is supported and enabled for this text area.
* @see FoldParserManager
*/
boolean isCodeFoldingSupportedAndEnabled();
/**
* Returns whether the specified line contains the start of a fold region.
*
* @param line
* The line.
* @param line The line.
* @return Whether the line contains the start of a fold region.
* @see #getFoldForLine(int)
*/
boolean isFoldStartLine(int line);
/**
* Returns whether a line is hidden in a collapsed fold.
*
* @param line
* The line to check.
* @param line The line to check.
* @return Whether the line is hidden in a collapsed fold.
*/
boolean isLineHidden(int line);
/**
* Removes a property change listener from this fold manager.
*
* @param l
* The listener to remove.
* @param l The listener to remove.
* @see #addPropertyChangeListener(PropertyChangeListener)
*/
void removePropertyChangeListener(PropertyChangeListener l);
/**
* Forces an immediate reparsing for folds, if folding is enabled. This
* usually does not need to be called by the programmer, since fold
* parsing is done automatically by RSTA.
* Forces an immediate reparsing for folds, if folding is enabled. This usually
* does not need to be called by the programmer, since fold parsing is done
* automatically by RSTA.
*/
void reparse();
/**
* Sets whether code folding is enabled. Note that only certain
* languages will support code folding out of the box. Those languages
* which do not support folding will ignore this property.
* Sets whether code folding is enabled. Note that only certain languages will
* support code folding out of the box. Those languages which do not support
* folding will ignore this property.
*
* @param enabled
* Whether code folding should be enabled.
* @param enabled Whether code folding should be enabled.
* @see #isCodeFoldingEnabled()
*/
void setCodeFoldingEnabled(boolean enabled);
/**
* Sets the folds for this fold manager.
*
* @param folds
* The new folds. This should not be <code>null</code>.
* @param folds The new folds. This should not be <code>null</code>.
*/
void setFolds(List<Fold> folds);
}
@@ -13,9 +13,9 @@ import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
/**
* Locates folds in a document. If you are implementing a language that has
* sections of source code that can be logically "folded," you can create an
* instance of this interface that locates those regions and represents them
* as {@link Fold}s. <code>RSyntaxTextArea</code> knows how to take it from
* there and implement code folding in the editor.
* instance of this interface that locates those regions and represents them as
* {@link Fold}s. <code>RSyntaxTextArea</code> knows how to take it from there
* and implement code folding in the editor.
*
* @author Robert Futrell
* @version 1.0
@@ -23,14 +23,13 @@ import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
* @see XmlFoldParser
*/
public interface FoldParser {
/**
* Returns a list of all folds in the text area.
*
* @param textArea
* The text area whose contents should be analyzed.
* @return The list of folds. If this method returns <code>null</code>,
* it is treated as if no folds were found.
* @param textArea The text area whose contents should be analyzed.
* @return The list of folds. If this method returns <code>null</code>, it is
* treated as if no folds were found.
*/
List<Fold> getFolds(RSyntaxTextArea textArea);
}
@@ -23,38 +23,35 @@ import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
* @version 1.0
*/
public final class FoldParserManager implements SyntaxConstants {
/**
* Map from syntax styles to fold parsers.
*/
private Map<String, FoldParser> foldParserMap;
private static final FoldParserManager INSTANCE = new FoldParserManager();
/**
* Private constructor to prevent instantiation.
*/
private FoldParserManager() {
foldParserMap = createFoldParserMap();
}
/**
* Adds a mapping from a syntax style to a fold parser. The parser
* specified will be shared among all RSTA instances editing that language,
* so it should be stateless (which should not be difficult for a fold
* parser). You can also override the fold parser for built-in languages,
* such as <code>SYNTAX_STYLE_JAVA</code>, with your own parser
* implementations.
* Adds a mapping from a syntax style to a fold parser. The parser specified
* will be shared among all RSTA instances editing that language, so it should
* be stateless (which should not be difficult for a fold parser). You can also
* override the fold parser for built-in languages, such as
* <code>SYNTAX_STYLE_JAVA</code>, with your own parser implementations.
*
* @param syntaxStyle
* The syntax style.
* @param parser
* The parser.
* @param syntaxStyle The syntax style.
* @param parser The parser.
* @see SyntaxConstants
*/
public void addFoldParserMapping(String syntaxStyle, FoldParser parser) {
foldParserMap.put(syntaxStyle, parser);
}
/**
* Creates the syntax style-to-fold parser mapping for built-in languages.
*
@@ -89,7 +86,7 @@ public final class FoldParserManager implements SyntaxConstants {
map.put(SYNTAX_STYLE_XML, new XmlFoldParser());
return map;
}
/**
* Returns the singleton instance of this class.
*
@@ -98,16 +95,15 @@ public final class FoldParserManager implements SyntaxConstants {
public static FoldParserManager get() {
return INSTANCE;
}
/**
* Returns a fold parser to use for an editor highlighting code of a
* specific language.
* Returns a fold parser to use for an editor highlighting code of a specific
* language.
*
* @param syntaxStyle
* A value from {@link SyntaxConstants}, such as
* <code>SYNTAX_STYLE_JAVA</code>.
* @return A fold parser to use, or <code>null</code> if none is registered
* for the language.
* @param syntaxStyle A value from {@link SyntaxConstants}, such as
* <code>SYNTAX_STYLE_JAVA</code>.
* @return A fold parser to use, or <code>null</code> if none is registered for
* the language.
*/
public FoldParser getFoldParser(String syntaxStyle) {
return foldParserMap.get(syntaxStyle);
@@ -26,7 +26,7 @@ package org.fife.ui.rsyntaxtextarea.folding;
* @see Fold
*/
public interface FoldType {
/**
* Denotes a <code>Fold</code> as being a region of code.
*/
@@ -36,17 +36,17 @@ public interface FoldType {
*/
int COMMENT = 1;
/**
* Denotes a <code>Fold</code> as being a section of import statements
* (Java), include statements (C), etc.
* Denotes a <code>Fold</code> as being a section of import statements (Java),
* include statements (C), etc.
*/
int IMPORTS = 2;
/**
* Users building advanced editors such as IDE's, that want to allow their
* users to auto-expand/collapse foldable regions of a specific type other
* than comments, should define their custom fold types using values
* <code>FOLD_TYPE_USER_DEFINED_MIN + <em>n</em></code>. That way, if
* new default fold types are added to this interface in the future, your
* code won't suddenly break when upgrading to a new version of RSTA.
* Users building advanced editors such as IDE's, that want to allow their users
* to auto-expand/collapse foldable regions of a specific type other than
* comments, should define their custom fold types using values
* <code>FOLD_TYPE_USER_DEFINED_MIN + <em>n</em></code>. That way, if new
* default fold types are added to this interface in the future, your code won't
* suddenly break when upgrading to a new version of RSTA.
*/
int FOLD_TYPE_USER_DEFINED_MIN = 1000;
}
@@ -19,16 +19,16 @@ import org.fife.ui.rsyntaxtextarea.Token;
/**
* Fold parser for HTML 5, PHP and JSP. For HTML, we currently don't fold
* <em>everything</em> possible, just the "big" stuff. For PHP, we only fold
* the "big" HTML stuff and PHP regions, not code blocks in the actual PHP.
* For JSP we only fold the "big" HTML stuff and JSP blocks, not anything in
* the actual Java code.
* <em>everything</em> possible, just the "big" stuff. For PHP, we only fold the
* "big" HTML stuff and PHP regions, not code blocks in the actual PHP. For JSP
* we only fold the "big" HTML stuff and JSP blocks, not anything in the actual
* Java code.
*
* @author Robert Futrell
* @version 1.0
*/
public class HtmlFoldParser implements FoldParser {
/**
* Constant denoting we're folding HTML.
*/
@@ -46,8 +46,8 @@ public class HtmlFoldParser implements FoldParser {
*/
private final int language;
/**
* The set of tags we allow to be folded. These are tags that must have
* explicit close tags in both HTML 4 and HTML 5.
* The set of tags we allow to be folded. These are tags that must have explicit
* close tags in both HTML 4 and HTML 5.
*/
private static final Set<String> FOLDABLE_TAGS;
private static final char[] MARKUP_CLOSING_TAG_START = "</".toCharArray();
@@ -83,12 +83,11 @@ public class HtmlFoldParser implements FoldParser {
FOLDABLE_TAGS.add("td");
FOLDABLE_TAGS.add("ul");
}
/**
* Constructor.
*
* @param language
* The language to fold, such as {@link #LANGUAGE_PHP}.
* @param language The language to fold, such as {@link #LANGUAGE_PHP}.
*/
public HtmlFoldParser(int language) {
if (language < LANGUAGE_HTML && language > LANGUAGE_JSP) {
@@ -96,7 +95,7 @@ public class HtmlFoldParser implements FoldParser {
}
this.language = language;
}
/**
* {@inheritDoc}
*/
@@ -194,7 +193,8 @@ public class HtmlFoldParser implements FoldParser {
}
// Starting a JSP comment that ends on a later
// line...
else if (language == LANGUAGE_JSP && t.startsWith(JSP_COMMENT_START) && !t.endsWith(JSP_COMMENT_END)) {
else if (language == LANGUAGE_JSP && t.startsWith(JSP_COMMENT_START)
&& !t.endsWith(JSP_COMMENT_END)) {
if (currentFold == null) {
currentFold = new Fold(FoldType.COMMENT, textArea, t.getOffset());
folds.add(currentFold);
@@ -258,22 +258,17 @@ public class HtmlFoldParser implements FoldParser {
}
return folds;
}
/**
* Grabs the token representing the closing of a tag (i.e.
* "<code>&gt;</code>" or "<code>/&gt;</code>"). This should only be
* called after a tag name has been parsed, to ensure the "closing" of
* other tags is not identified.
* Grabs the token representing the closing of a tag (i.e. "<code>&gt;</code>"
* or "<code>/&gt;</code>"). This should only be called after a tag name has
* been parsed, to ensure the "closing" of other tags is not identified.
*
* @param tagNameToken
* The token denoting the name of the tag.
* @param textArea
* The text area whose contents are being parsed.
* @param line
* The line we're currently on.
* @param info
* On return, information about the closing of the tag is
* returned in this object.
* @param tagNameToken The token denoting the name of the tag.
* @param textArea The text area whose contents are being parsed.
* @param line The line we're currently on.
* @param info On return, information about the closing of the tag is
* returned in this object.
* @return The line number of the closing tag token.
*/
private int getTagCloseInfo(Token tagNameToken, RSyntaxTextArea textArea, int line, TagCloseInfo info) {
@@ -291,16 +286,13 @@ public class HtmlFoldParser implements FoldParser {
} while (++line < textArea.getLineCount() && (t = textArea.getTokenListForLine(line)) != null);
return line;
}
/**
* Returns whether a closing tag ("<code>&lt;/...&gt;</code>") with a
* specific name is the closing tag of our current fold region.
* Returns whether a closing tag ("<code>&lt;/...&gt;</code>") with a specific
* name is the closing tag of our current fold region.
*
* @param tagNameStack
* The stack of fold regions.
* @param tagNameToken
* The tag name of the most recently parsed closing
* tag.
* @param tagNameStack The stack of fold regions.
* @param tagNameToken The tag name of the most recently parsed closing tag.
* @return Whether it's the end of the current fold region.
*/
private static boolean isEndOfLastFold(Stack<String> tagNameStack, Token tagNameToken) {
@@ -309,48 +301,45 @@ public class HtmlFoldParser implements FoldParser {
}
return false;
}
/**
* Returns whether a tag is one we allow as a foldable region.
*
* @param tagNameToken
* The tag's name token. This may be <code>null</code>.
* @param tagNameToken The tag's name token. This may be <code>null</code>.
* @return Whether this tag can be a foldable region.
*/
private static boolean isFoldableTag(Token tagNameToken) {
return tagNameToken != null && FOLDABLE_TAGS.contains(tagNameToken.getLexeme().toLowerCase());
}
/**
* If this fold has a parent fold, this method removes it from its parent.
* Otherwise, it's assumed to be the most recent (top-level) fold in the
* <code>folds</code> list, and is removed from that.
*
* @param fold
* The fold to remove.
* @param folds
* The list of top-level folds.
* @param fold The fold to remove.
* @param folds The list of top-level folds.
*/
private static void removeFold(Fold fold, List<Fold> folds) {
if (!fold.removeFromParent()) {
folds.remove(folds.size() - 1);
}
}
/**
* A simple wrapper for the token denoting the closing of a tag (i.e.
* "<code>&gt;</code>" or "<code>/&gt;</code>").
*/
private static class TagCloseInfo {
private Token closeToken;
private int line;
public void reset() {
closeToken = null;
line = -1;
}
@Override
public String toString() {
return "[TagCloseInfo: " + "closeToken=" + closeToken + ", line=" + line + "]";
@@ -25,10 +25,10 @@ import org.fife.ui.rsyntaxtextarea.TokenTypes;
* @version 1.0
*/
public class JsonFoldParser implements FoldParser {
private static final Object OBJECT_BLOCK = new Object();
private static final Object ARRAY_BLOCK = new Object();
/**
* {@inheritDoc}
*/
@@ -95,39 +95,35 @@ public class JsonFoldParser implements FoldParser {
}
return folds;
}
/**
* Returns whether a token is the left bracket token.
*
* @param t
* The token.
* @param t The token.
* @return Whether the token is the left bracket token.
* @see #isRightBracket(Token)
*/
private static boolean isLeftBracket(Token t) {
return t.getType() == TokenTypes.SEPARATOR && t.isSingleChar('[');
}
/**
* Returns whether a token is the right bracket token.
*
* @param t
* The token.
* @param t The token.
* @return Whether the token is the right bracket token.
* @see #isLeftBracket(Token)
*/
private static boolean isRightBracket(Token t) {
return t.getType() == TokenTypes.SEPARATOR && t.isSingleChar(']');
}
/**
* If the specified value is on top of the stack, pop it off and return
* <code>true</code>. Otherwise, return <code>false</code>.
*
* @param stack
* The stack.
* @param value
* The value to check for.
* @param stack The stack.
* @param value The value to check for.
* @return Whether the value was found on top of the stack.
*/
private static boolean popOffTop(Stack<Object> stack, Object value) {
@@ -16,17 +16,17 @@ import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.Token;
/**
* A fold parser for LaTeX documents. This is likely incomplete and/or not
* quite right; feedback is appreciated.
* A fold parser for LaTeX documents. This is likely incomplete and/or not quite
* right; feedback is appreciated.
*
* @author Robert Futrell
* @version 1.0
*/
public class LatexFoldParser implements FoldParser {
private static final char[] BEGIN = "\\begin".toCharArray();
private static final char[] END = "\\end".toCharArray();
/**
* {@inheritDoc}
*/
@@ -15,12 +15,12 @@ import org.fife.ui.rsyntaxtextarea.Token;
* @version 1.0
*/
public class LispFoldParser extends CurlyFoldParser {
@Override
public boolean isLeftCurly(Token t) {
return t.isSingleChar(Token.SEPARATOR, '(');
}
@Override
public boolean isRightCurly(Token t) {
return t.isSingleChar(Token.SEPARATOR, ')');
@@ -27,17 +27,17 @@ import org.fife.ui.rsyntaxtextarea.Token;
* @version 1.0
*/
public class NsisFoldParser implements FoldParser {
private static final char[] KEYWORD_FUNCTION = "Function".toCharArray();
private static final char[] KEYWORD_FUNCTION_END = "FunctionEnd".toCharArray();
private static final char[] KEYWORD_SECTION = "Section".toCharArray();
private static final char[] KEYWORD_SECTION_END = "SectionEnd".toCharArray();
protected static final char[] C_MLC_END = "*/".toCharArray();
private static boolean foundEndKeyword(char[] keyword, Token t, Stack<char[]> endWordStack) {
return t.is(Token.RESERVED_WORD, keyword) && !endWordStack.isEmpty() && keyword == endWordStack.peek();
}
/**
* {@inheritDoc}
*/
@@ -23,11 +23,11 @@ import org.fife.ui.rsyntaxtextarea.Token;
* @version 1.0
*/
public class XmlFoldParser implements FoldParser {
private static final char[] MARKUP_CLOSING_TAG_START = { '<', '/' };
private static final char[] MARKUP_SHORT_TAG_END = { '/', '>' };
private static final char[] MLC_END = { '-', '-', '>' };
/**
* {@inheritDoc}
*/
@@ -103,16 +103,14 @@ public class XmlFoldParser implements FoldParser {
}
return folds;
}
/**
* If this fold has a parent fold, this method removes it from its parent.
* Otherwise, it's assumed to be the most recent (top-level) fold in the
* <code>folds</code> list, and is removed from that.
*
* @param fold
* The fold to remove.
* @param folds
* The list of top-level folds.
* @param fold The fold to remove.
* @param folds The list of top-level folds.
*/
private static void removeFold(Fold fold, List<Fold> folds) {
if (!fold.removeFromParent()) {
@@ -16,14 +16,14 @@ import org.fife.ui.rsyntaxtextarea.AbstractJFlexTokenMaker;
* @version 1.0
*/
public abstract class AbstractMarkupTokenMaker extends AbstractJFlexTokenMaker {
/**
* Returns whether markup close tags should be completed.
*
* @return Whether closing markup tags are to be completed.
*/
public abstract boolean getCompleteCloseTags();
/**
* {@inheritDoc}
*/
@@ -31,7 +31,7 @@ public abstract class AbstractMarkupTokenMaker extends AbstractJFlexTokenMaker {
public String[] getLineCommentStartAndEnd(int languageIndex) {
return new String[] { "<!--", "-->" };
}
/**
* Overridden to return <code>true</code>.
*
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -19,16 +19,15 @@ import org.fife.ui.rsyntaxtextarea.TokenImpl;
*
* This implementation was created using
* <a href="http://www.jflex.de/">JFlex</a> 1.4.1; however, the generated file
* was modified for performance. Memory allocation needs to be almost
* completely removed to be competitive with the handwritten lexers (subclasses
* of <code>AbstractTokenMaker</code>, so this class has been modified so that
* was modified for performance. Memory allocation needs to be almost completely
* removed to be competitive with the handwritten lexers (subclasses of
* <code>AbstractTokenMaker</code>, so this class has been modified so that
* Strings are never allocated (via yytext()), and the scanner never has to
* worry about refilling its buffer (needlessly copying chars around).
* We can achieve this because RText always scans exactly 1 line of tokens at a
* time, and hands the scanner this line as an array of characters (a Segment
* really). Since tokens contain pointers to char arrays instead of Strings
* holding their contents, there is no need for allocating new memory for
* Strings.
* worry about refilling its buffer (needlessly copying chars around). We can
* achieve this because RText always scans exactly 1 line of tokens at a time,
* and hands the scanner this line as an array of characters (a Segment really).
* Since tokens contain pointers to char arrays instead of Strings holding their
* contents, there is no need for allocating new memory for Strings.
* <p>
*
* The actual algorithm generated for scanning has, of course, not been
@@ -38,16 +37,16 @@ import org.fife.ui.rsyntaxtextarea.TokenImpl;
* If you wish to regenerate this file yourself, keep in mind the following:
* <ul>
* <li>The generated <code>BBCodeTokenMaker.java</code> file will contain two
* definitions of both <code>zzRefill</code> and <code>yyreset</code>.
* You should hand-delete the second of each definition (the ones
* generated by the lexer), as these generated methods modify the input
* buffer, which we'll never have to do.</li>
* <li>You should also change the declaration/definition of zzBuffer to NOT
* be initialized. This is a needless memory allocation for us since we
* will be pointing the array somewhere else anyway.</li>
* definitions of both <code>zzRefill</code> and <code>yyreset</code>. You
* should hand-delete the second of each definition (the ones generated by the
* lexer), as these generated methods modify the input buffer, which we'll never
* have to do.</li>
* <li>You should also change the declaration/definition of zzBuffer to NOT be
* initialized. This is a needless memory allocation for us since we will be
* pointing the array somewhere else anyway.</li>
* <li>You should NOT call <code>yylex()</code> on the generated scanner
* directly; rather, you should use <code>getTokenList</code> as you would
* with any other <code>TokenMaker</code> instance.</li>
* directly; rather, you should use <code>getTokenList</code> as you would with
* any other <code>TokenMaker</code> instance.</li>
* </ul>
*
* @author Robert Futrell
@@ -55,7 +54,7 @@ import org.fife.ui.rsyntaxtextarea.TokenImpl;
*
*/
public class BBCodeTokenMaker extends AbstractMarkupTokenMaker {
/** This character denotes the end of file */
public static final int YYEOF = -1;
/** lexical states */
@@ -75,15 +74,16 @@ public class BBCodeTokenMaker extends AbstractMarkupTokenMaker {
* Translates DFA states to action switch labels.
*/
private static final int[] ZZ_ACTION = zzUnpackAction();
private static final String ZZ_ACTION_PACKED_0 = "\2\0\1\1\1\2\1\3\1\4\1\5\1\6\1\7" + "\4\10\6\5\1\11\1\12\1\4\23\5";
private static final String ZZ_ACTION_PACKED_0 = "\2\0\1\1\1\2\1\3\1\4\1\5\1\6\1\7"
+ "\4\10\6\5\1\11\1\12\1\4\23\5";
private static int[] zzUnpackAction() {
int[] result = new int[41];
int offset = 0;
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAction(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -97,23 +97,24 @@ public class BBCodeTokenMaker extends AbstractMarkupTokenMaker {
}
return j;
}
/**
* Translates a state to a row index in the transition table
*/
private static final int[] ZZ_ROWMAP = zzUnpackRowMap();
private static final String ZZ_ROWMAP_PACKED_0 = "\0\0\0\31\0\62\0\113\0\144\0\175\0\226\0\144"
+ "\0\144\0\226\0\257\0\310\0\341\0\372\0\u0113\0\u012c" + "\0\u0145\0\u015e\0\u0177\0\u0190\0\144\0\144\0\u01a9\0\u01c2"
+ "\0\144\0\226\0\257\0\310\0\341\0\372\0\u0113\0\u012c"
+ "\0\u0145\0\u015e\0\u0177\0\u0190\0\144\0\144\0\u01a9\0\u01c2"
+ "\0\u01db\0\u01f4\0\u020d\0\u0226\0\u023f\0\u0258\0\u0271\0\u028a"
+ "\0\u02a3\0\u02bc\0\u02d5\0\u02ee\0\u0307\0\u0320\0\u0339\0\u0352" + "\0\u036b";
private static int[] zzUnpackRowMap() {
int[] result = new int[41];
int offset = 0;
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
return result;
}
private static int zzUnpackRowMap(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -124,29 +125,33 @@ public class BBCodeTokenMaker extends AbstractMarkupTokenMaker {
}
return j;
}
/**
* The transition table of the DFA
*/
private static final int[] ZZ_TRANS = zzUnpackTrans();
private static final String ZZ_TRANS_PACKED_0 = "\1\3\1\4\1\5\1\6\25\3\1\7\1\4\1\0" + "\1\10\1\11\1\12\1\13\1\14\1\15\2\7\1\16"
+ "\1\17\1\20\3\7\1\21\1\7\1\22\1\23\2\7" + "\1\24\1\25\1\3\3\0\25\3\1\0\1\4\107\0" + "\1\26\1\0\1\7\4\0\22\7\2\0\1\7\4\0"
+ "\15\7\1\27\4\7\2\0\1\7\4\0\10\7\1\12" + "\1\17\10\7\2\0\1\7\4\0\1\7\1\30\20\7" + "\2\0\1\7\4\0\5\7\1\31\1\7\1\32\12\7"
+ "\2\0\1\7\4\0\10\7\1\12\11\7\2\0\1\7" + "\4\0\1\7\1\12\20\7\2\0\1\7\4\0\2\7" + "\1\33\17\7\2\0\1\7\4\0\20\7\1\34\1\7"
+ "\2\0\1\7\4\0\7\7\1\35\12\7\6\0\1\11" + "\24\0\1\7\4\0\16\7\1\12\3\7\2\0\1\7" + "\4\0\4\7\1\36\15\7\2\0\1\7\4\0\12\7"
+ "\1\37\7\7\2\0\1\7\4\0\10\7\1\40\11\7" + "\2\0\1\7\4\0\7\7\1\41\12\7\2\0\1\7" + "\4\0\1\7\1\42\20\7\2\0\1\7\4\0\2\7"
+ "\1\43\17\7\2\0\1\7\4\0\5\7\1\12\14\7" + "\2\0\1\7\4\0\13\7\1\44\6\7\2\0\1\7" + "\4\0\7\7\1\45\12\7\2\0\1\7\4\0\13\7"
+ "\1\36\6\7\2\0\1\7\4\0\21\7\1\46\2\0" + "\1\7\4\0\13\7\1\47\6\7\2\0\1\7\4\0" + "\5\7\1\45\14\7\2\0\1\7\4\0\11\7\1\12"
+ "\10\7\2\0\1\7\4\0\5\7\1\50\14\7\2\0" + "\1\7\4\0\2\7\1\51\17\7\2\0\1\7\4\0" + "\7\7\1\12\12\7\2\0\1\7\4\0\1\36\21\7"
+ "\2\0";
private static final String ZZ_TRANS_PACKED_0 = "\1\3\1\4\1\5\1\6\25\3\1\7\1\4\1\0"
+ "\1\10\1\11\1\12\1\13\1\14\1\15\2\7\1\16" + "\1\17\1\20\3\7\1\21\1\7\1\22\1\23\2\7"
+ "\1\24\1\25\1\3\3\0\25\3\1\0\1\4\107\0" + "\1\26\1\0\1\7\4\0\22\7\2\0\1\7\4\0"
+ "\15\7\1\27\4\7\2\0\1\7\4\0\10\7\1\12" + "\1\17\10\7\2\0\1\7\4\0\1\7\1\30\20\7"
+ "\2\0\1\7\4\0\5\7\1\31\1\7\1\32\12\7" + "\2\0\1\7\4\0\10\7\1\12\11\7\2\0\1\7"
+ "\4\0\1\7\1\12\20\7\2\0\1\7\4\0\2\7" + "\1\33\17\7\2\0\1\7\4\0\20\7\1\34\1\7"
+ "\2\0\1\7\4\0\7\7\1\35\12\7\6\0\1\11" + "\24\0\1\7\4\0\16\7\1\12\3\7\2\0\1\7"
+ "\4\0\4\7\1\36\15\7\2\0\1\7\4\0\12\7" + "\1\37\7\7\2\0\1\7\4\0\10\7\1\40\11\7"
+ "\2\0\1\7\4\0\7\7\1\41\12\7\2\0\1\7" + "\4\0\1\7\1\42\20\7\2\0\1\7\4\0\2\7"
+ "\1\43\17\7\2\0\1\7\4\0\5\7\1\12\14\7" + "\2\0\1\7\4\0\13\7\1\44\6\7\2\0\1\7"
+ "\4\0\7\7\1\45\12\7\2\0\1\7\4\0\13\7" + "\1\36\6\7\2\0\1\7\4\0\21\7\1\46\2\0"
+ "\1\7\4\0\13\7\1\47\6\7\2\0\1\7\4\0" + "\5\7\1\45\14\7\2\0\1\7\4\0\11\7\1\12"
+ "\10\7\2\0\1\7\4\0\5\7\1\50\14\7\2\0" + "\1\7\4\0\2\7\1\51\17\7\2\0\1\7\4\0"
+ "\7\7\1\12\12\7\2\0\1\7\4\0\1\36\21\7" + "\2\0";
private static int[] zzUnpackTrans() {
int[] result = new int[900];
int offset = 0;
offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
return result;
}
private static int zzUnpackTrans(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -161,7 +166,7 @@ public class BBCodeTokenMaker extends AbstractMarkupTokenMaker {
}
return j;
}
/* error codes */
private static final int ZZ_UNKNOWN_ERROR = 0;
private static final int ZZ_NO_MATCH = 1;
@@ -174,14 +179,14 @@ public class BBCodeTokenMaker extends AbstractMarkupTokenMaker {
*/
private static final int[] ZZ_ATTRIBUTE = zzUnpackAttribute();
private static final String ZZ_ATTRIBUTE_PACKED_0 = "\2\0\2\1\1\11\2\1\2\11\13\1\2\11\23\1";
private static int[] zzUnpackAttribute() {
int[] result = new int[41];
int offset = 0;
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAttribute(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -195,7 +200,7 @@ public class BBCodeTokenMaker extends AbstractMarkupTokenMaker {
}
return j;
}
/** the input device */
private java.io.Reader zzReader;
/** the current state of the DFA */
@@ -203,8 +208,8 @@ public class BBCodeTokenMaker extends AbstractMarkupTokenMaker {
/** the current lexical state */
private int zzLexicalState = YYINITIAL;
/**
* this buffer contains the current text to be matched and is
* the source of the yytext() string
* this buffer contains the current text to be matched and is the source of the
* yytext() string
*/
private char zzBuffer[];
/** the textposition at the last accepting state */
@@ -214,75 +219,67 @@ public class BBCodeTokenMaker extends AbstractMarkupTokenMaker {
/** startRead marks the beginning of the yytext() string in the buffer */
private int zzStartRead;
/**
* endRead marks the last character in the buffer, that has been read
* from input
* endRead marks the last character in the buffer, that has been read from input
*/
private int zzEndRead;
/** zzAtEOF == true <=> the scanner is at the EOF */
private boolean zzAtEOF;
/* user code: */
/**
* Token type specific to BBCodeTokenMaker; this signals that the user has
* ended a line with an unclosed tag; thus a new line is beginning
* still inside of the tag.
* Token type specific to BBCodeTokenMaker; this signals that the user has ended
* a line with an unclosed tag; thus a new line is beginning still inside of the
* tag.
*/
public static final int INTERNAL_INTAG = -1;
/**
* Whether closing markup tags are automatically completed for BBCode.
*/
private static boolean completeCloseTags = true;
/**
* Constructor. This must be here because JFlex does not generate a
* no-parameter constructor.
* Constructor. This must be here because JFlex does not generate a no-parameter
* constructor.
*/
public BBCodeTokenMaker() {}
public BBCodeTokenMaker() {
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType
* The token's type.
* @param tokenType The token's type.
*/
private void addToken(int tokenType) {
addToken(zzStartRead, zzMarkedPos - 1, tokenType);
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType
* The token's type.
* @param tokenType The token's type.
*/
private void addToken(int start, int end, int tokenType) {
int so = start + offsetShift;
addToken(zzBuffer, start, end, tokenType, so);
}
/**
* 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 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.
*/
@Override
public void addToken(char[] array, int start, int end, int tokenType, int startOffset) {
super.addToken(array, start, end, tokenType, startOffset);
zzStartRead = zzMarkedPos;
}
/**
* Sets whether markup close tags should be completed. The default value
* for BBCode is <code>true</code>.
* Sets whether markup close tags should be completed. The default value for
* BBCode is <code>true</code>.
*
* @return Whether closing markup tags are completed.
* @see #setCompleteCloseTags(boolean)
@@ -291,7 +288,7 @@ public class BBCodeTokenMaker extends AbstractMarkupTokenMaker {
public boolean getCompleteCloseTags() {
return completeCloseTags;
}
/**
* Returns <code>null</code> since BBCode has no comments.
*
@@ -301,21 +298,18 @@ public class BBCodeTokenMaker extends AbstractMarkupTokenMaker {
public String[] getLineCommentStartAndEnd(int languageIndex) {
return null;
}
/**
* Returns the first token in the linked list of tokens generated
* from <code>text</code>. This method must be implemented by
* subclasses so they can correctly implement syntax highlighting.
* Returns the first token in the linked list of tokens generated from
* <code>text</code>. This method must be implemented by subclasses so they can
* correctly implement syntax highlighting.
*
* @param text
* The text from which to get tokens.
* @param initialTokenType
* The token type we should start with.
* @param startOffset
* The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing
* the syntax highlighted text.
* @param text The text from which to get tokens.
* @param initialTokenType The token type we should start with.
* @param startOffset The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing the syntax
* highlighted text.
*/
@Override
public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
@@ -324,12 +318,12 @@ public class BBCodeTokenMaker extends AbstractMarkupTokenMaker {
// Start off in the proper state.
int state = Token.NULL;
switch (initialTokenType) {
case INTERNAL_INTAG:
state = INTAG;
start = text.offset;
break;
default:
state = Token.NULL;
case INTERNAL_INTAG:
state = INTAG;
start = text.offset;
break;
default:
state = Token.NULL;
}
s = text;
try {
@@ -341,47 +335,44 @@ public class BBCodeTokenMaker extends AbstractMarkupTokenMaker {
return new TokenImpl();
}
}
/**
* Sets whether markup close tags should be completed.
*
* @param complete
* Whether closing markup tags are completed.
* @param complete Whether closing markup tags are completed.
* @see #getCompleteCloseTags()
*/
public static void setCompleteCloseTags(boolean complete) {
completeCloseTags = complete;
}
/**
* Refills the input buffer.
*
* @return <code>true</code> if EOF was reached, otherwise
* <code>false</code>.
* @return <code>true</code> if EOF was reached, otherwise <code>false</code>.
*/
private boolean zzRefill() {
return zzCurrentPos >= s.offset + s.count;
}
/**
* Resets the scanner to read from a new input stream.
* Does not close the old reader.
* Resets the scanner to read from a new input stream. Does not close the old
* reader.
*
* All internal variables are reset, the old input stream
* <b>cannot</b> be reused (internal buffer is discarded and lost).
* Lexical state is set to <tt>YY_INITIAL</tt>.
* All internal variables are reset, the old input stream <b>cannot</b> be
* reused (internal buffer is discarded and lost). Lexical state is set to
* <tt>YY_INITIAL</tt>.
*
* @param reader
* the new input stream
* @param reader the new input stream
*/
public final void yyreset(java.io.Reader reader) {
// 's' has been updated.
zzBuffer = s.array;
/*
* We replaced the line below with the two below it because zzRefill
* no longer "refills" the buffer (since the way we do it, it's always
* "full" the first time through, since it points to the segment's
* array). So, we assign zzEndRead here.
* We replaced the line below with the two below it because zzRefill no longer
* "refills" the buffer (since the way we do it, it's always "full" the first
* time through, since it points to the segment's array). So, we assign
* zzEndRead here.
*/
// zzStartRead = zzEndRead = s.offset;
zzStartRead = s.offset;
@@ -391,34 +382,31 @@ public class BBCodeTokenMaker extends AbstractMarkupTokenMaker {
zzReader = reader;
zzAtEOF = false;
}
/**
* Creates a new scanner
* There is also a java.io.InputStream version of this constructor.
* Creates a new scanner There is also a java.io.InputStream version of this
* constructor.
*
* @param in
* the java.io.Reader to read input from.
* @param in the java.io.Reader to read input from.
*/
public BBCodeTokenMaker(java.io.Reader in) {
this.zzReader = in;
}
/**
* Creates a new scanner.
* There is also java.io.Reader version of this constructor.
* Creates a new scanner. There is also java.io.Reader version of this
* constructor.
*
* @param in
* the java.io.Inputstream to read input from.
* @param in the java.io.Inputstream to read input from.
*/
public BBCodeTokenMaker(java.io.InputStream in) {
this(new java.io.InputStreamReader(in));
}
/**
* Unpacks the compressed character translation table.
*
* @param packed
* the packed character translation table
* @param packed the packed character translation table
* @return the unpacked character translation table
*/
private static char[] zzUnpackCMap(String packed) {
@@ -434,7 +422,7 @@ public class BBCodeTokenMaker extends AbstractMarkupTokenMaker {
}
return map;
}
/**
* Closes the input stream.
*/
@@ -444,69 +432,64 @@ public class BBCodeTokenMaker extends AbstractMarkupTokenMaker {
if (zzReader != null)
zzReader.close();
}
/**
* Returns the current lexical state.
*/
public final int yystate() {
return zzLexicalState;
}
/**
* Enters a new lexical state
*
* @param newState
* the new lexical state
* @param newState the new lexical state
*/
@Override
public final void yybegin(int newState) {
zzLexicalState = newState;
}
/**
* Returns the text matched by the current regular expression.
*/
public final String yytext() {
return new String(zzBuffer, zzStartRead, zzMarkedPos - zzStartRead);
}
/**
* Returns the character at position <tt>pos</tt> from the
* matched text.
* Returns the character at position <tt>pos</tt> from the matched text.
*
* It is equivalent to yytext().charAt(pos), but faster
*
* @param pos
* the position of the character to fetch.
* A value from 0 to yylength()-1.
* @param pos the position of the character to fetch. A value from 0 to
* yylength()-1.
*
* @return the character at position pos
*/
public final char yycharat(int pos) {
return zzBuffer[zzStartRead + pos];
}
/**
* Returns the length of the matched text region.
*/
public final int yylength() {
return zzMarkedPos - zzStartRead;
}
/**
* Reports an error that occured while scanning.
*
* In a wellformed scanner (no or only correct usage of
* yypushback(int) and a match-all fallback rule) this method
* will only be called with things that "Can't Possibly Happen".
* If this method is called, something is seriously wrong
* (e.g. a JFlex bug producing a faulty scanner etc.).
* In a wellformed scanner (no or only correct usage of yypushback(int) and a
* match-all fallback rule) this method will only be called with things that
* "Can't Possibly Happen". If this method is called, something is seriously
* wrong (e.g. a JFlex bug producing a faulty scanner etc.).
*
* Usual syntax/scanner level error handling should be done
* in error fallback rules.
* Usual syntax/scanner level error handling should be done in error fallback
* rules.
*
* @param errorCode
* the code of the errormessage to display
* @param errorCode the code of the errormessage to display
*/
private void zzScanError(int errorCode) {
String message;
@@ -517,29 +500,27 @@ public class BBCodeTokenMaker extends AbstractMarkupTokenMaker {
}
throw new Error(message);
}
/**
* Pushes the specified amount of characters back into the input stream.
*
* They will be read again by then next call of the scanning method
*
* @param number
* the number of characters to be read again.
* This number must not be greater than yylength()!
* @param number the number of characters to be read again. This number must not
* be greater than yylength()!
*/
public void yypushback(int number) {
if (number > yylength())
zzScanError(ZZ_PUSHBACK_2BIG);
zzMarkedPos -= number;
}
/**
* Resumes scanning until the next regular expression is matched,
* the end of input is encountered or an I/O-Error occurs.
* Resumes scanning until the next regular expression is matched, the end of
* input is encountered or an I/O-Error occurs.
*
* @return the next token
* @exception java.io.IOException
* if any I/O-Error occurs
* @exception java.io.IOException if any I/O-Error occurs
*/
public org.fife.ui.rsyntaxtextarea.Token yylex() throws java.io.IOException {
int zzInput;
@@ -558,8 +539,7 @@ public class BBCodeTokenMaker extends AbstractMarkupTokenMaker {
zzAction = -1;
zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
zzState = zzLexicalState;
zzForAction:
{
zzForAction: {
while (true) {
if (zzCurrentPosL < zzEndReadL)
zzInput = zzBufferL[zzCurrentPosL++];
@@ -599,82 +579,81 @@ public class BBCodeTokenMaker extends AbstractMarkupTokenMaker {
// store back cached position
zzMarkedPos = zzMarkedPosL;
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
case 1: {
addToken(Token.IDENTIFIER);
}
case 11:
break;
case 9: {
addToken(Token.MARKUP_TAG_DELIMITER);
}
case 12:
break;
case 2: {
addToken(Token.WHITESPACE);
}
case 13:
break;
case 10: {
addToken(Token.OPERATOR);
}
case 14:
break;
case 8: {
addToken(Token.MARKUP_TAG_NAME);
}
case 15:
break;
case 4: {
addToken(Token.MARKUP_TAG_DELIMITER);
yybegin(INTAG);
}
case 16:
break;
case 6: {
addToken(
Token.IDENTIFIER); /* Unhandled chars, not likely */
}
case 17:
break;
case 5: {
addToken(Token.MARKUP_TAG_ATTRIBUTE);
}
case 18:
break;
case 3: {
addNullToken();
return firstToken;
}
case 19:
break;
case 7: {
yybegin(YYINITIAL);
addToken(Token.MARKUP_TAG_DELIMITER);
}
case 20:
break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
switch (zzLexicalState) {
case INTAG: {
addToken(zzMarkedPos, zzMarkedPos, INTERNAL_INTAG);
return firstToken;
}
case 42:
break;
case YYINITIAL: {
addNullToken();
return firstToken;
}
case 43:
break;
default:
return null;
}
} else {
zzScanError(ZZ_NO_MATCH);
case 1: {
addToken(Token.IDENTIFIER);
}
case 11:
break;
case 9: {
addToken(Token.MARKUP_TAG_DELIMITER);
}
case 12:
break;
case 2: {
addToken(Token.WHITESPACE);
}
case 13:
break;
case 10: {
addToken(Token.OPERATOR);
}
case 14:
break;
case 8: {
addToken(Token.MARKUP_TAG_NAME);
}
case 15:
break;
case 4: {
addToken(Token.MARKUP_TAG_DELIMITER);
yybegin(INTAG);
}
case 16:
break;
case 6: {
addToken(Token.IDENTIFIER); /* Unhandled chars, not likely */
}
case 17:
break;
case 5: {
addToken(Token.MARKUP_TAG_ATTRIBUTE);
}
case 18:
break;
case 3: {
addNullToken();
return firstToken;
}
case 19:
break;
case 7: {
yybegin(YYINITIAL);
addToken(Token.MARKUP_TAG_DELIMITER);
}
case 20:
break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
switch (zzLexicalState) {
case INTAG: {
addToken(zzMarkedPos, zzMarkedPos, INTERNAL_INTAG);
return firstToken;
}
case 42:
break;
case YYINITIAL: {
addNullToken();
return firstToken;
}
case 43:
break;
default:
return null;
}
} else {
zzScanError(ZZ_NO_MATCH);
}
}
}
}
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -22,16 +22,15 @@ import org.fife.ui.rsyntaxtextarea.TokenTypes;
*
* This implementation was created using
* <a href="http://www.jflex.de/">JFlex</a> 1.4.1; however, the generated file
* was modified for performance. Memory allocation needs to be almost
* completely removed to be competitive with the handwritten lexers (subclasses
* of <code>AbstractTokenMaker</code>, so this class has been modified so that
* was modified for performance. Memory allocation needs to be almost completely
* removed to be competitive with the handwritten lexers (subclasses of
* <code>AbstractTokenMaker</code>, so this class has been modified so that
* Strings are never allocated (via yytext()), and the scanner never has to
* worry about refilling its buffer (needlessly copying chars around).
* We can achieve this because RText always scans exactly 1 line of tokens at a
* time, and hands the scanner this line as an array of characters (a Segment
* really). Since tokens contain pointers to char arrays instead of Strings
* holding their contents, there is no need for allocating new memory for
* Strings.
* worry about refilling its buffer (needlessly copying chars around). We can
* achieve this because RText always scans exactly 1 line of tokens at a time,
* and hands the scanner this line as an array of characters (a Segment really).
* Since tokens contain pointers to char arrays instead of Strings holding their
* contents, there is no need for allocating new memory for Strings.
* <p>
*
* The actual algorithm generated for scanning has, of course, not been
@@ -41,16 +40,16 @@ import org.fife.ui.rsyntaxtextarea.TokenTypes;
* If you wish to regenerate this file yourself, keep in mind the following:
* <ul>
* <li>The generated <code>DockerTokenMaker.java</code> file will contain two
* definitions of both <code>zzRefill</code> and <code>yyreset</code>.
* You should hand-delete the second of each definition (the ones
* generated by the lexer), as these generated methods modify the input
* buffer, which we'll never have to do.</li>
* <li>You should also change the declaration/definition of zzBuffer to NOT
* be initialized. This is a needless memory allocation for us since we
* will be pointing the array somewhere else anyway.</li>
* definitions of both <code>zzRefill</code> and <code>yyreset</code>. You
* should hand-delete the second of each definition (the ones generated by the
* lexer), as these generated methods modify the input buffer, which we'll never
* have to do.</li>
* <li>You should also change the declaration/definition of zzBuffer to NOT be
* initialized. This is a needless memory allocation for us since we will be
* pointing the array somewhere else anyway.</li>
* <li>You should NOT call <code>yylex()</code> on the generated scanner
* directly; rather, you should use <code>getTokenList</code> as you would
* with any other <code>TokenMaker</code> instance.</li>
* directly; rather, you should use <code>getTokenList</code> as you would with
* any other <code>TokenMaker</code> instance.</li>
* </ul>
*
* @author Robert Futrell
@@ -58,7 +57,7 @@ import org.fife.ui.rsyntaxtextarea.TokenTypes;
*
*/
public class DockerTokenMaker extends AbstractJFlexTokenMaker {
/** This character denotes the end of file */
public static final int YYEOF = -1;
/** lexical states */
@@ -81,16 +80,16 @@ public class DockerTokenMaker extends AbstractJFlexTokenMaker {
* Translates DFA states to action switch labels.
*/
private static final int[] ZZ_ACTION = zzUnpackAction();
private static final String ZZ_ACTION_PACKED_0 = "\1\1\2\0\2\1\1\2\14\1\1\3\2\4\1\5" + "\1\6\1\7\1\10\1\11\1\12\1\13\1\14\1\11"
+ "\1\15\1\16\1\17\16\1\1\14\1\17\1\1\1\20" + "\41\1";
private static final String ZZ_ACTION_PACKED_0 = "\1\1\2\0\2\1\1\2\14\1\1\3\2\4\1\5"
+ "\1\6\1\7\1\10\1\11\1\12\1\13\1\14\1\11" + "\1\15\1\16\1\17\16\1\1\14\1\17\1\1\1\20" + "\41\1";
private static int[] zzUnpackAction() {
int[] result = new int[84];
int offset = 0;
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAction(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -104,28 +103,29 @@ public class DockerTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/**
* Translates a state to a row index in the transition table
*/
private static final int[] ZZ_ROWMAP = zzUnpackRowMap();
private static final String ZZ_ROWMAP_PACKED_0 = "\0\0\0\41\0\102\0\143\0\204\0\245\0\306\0\347"
+ "\0\u0108\0\u0129\0\u014a\0\u016b\0\u018c\0\u01ad\0\u01ce\0\u01ef"
+ "\0\u0210\0\u0231\0\143\0\143\0\u0252\0\143\0\143\0\u0273" + "\0\143\0\u0294\0\143\0\143\0\u02b5\0\u02d6\0\143\0\143"
+ "\0\u0210\0\u0231\0\143\0\143\0\u0252\0\143\0\143\0\u0273"
+ "\0\143\0\u0294\0\143\0\143\0\u02b5\0\u02d6\0\143\0\143"
+ "\0\u02f7\0\u0318\0\u0339\0\u035a\0\u037b\0\u039c\0\u03bd\0\u03de"
+ "\0\u03ff\0\u0420\0\u0441\0\u0462\0\u0483\0\u04a4\0\u04c5\0\143"
+ "\0\143\0\u04e6\0\204\0\u0507\0\u0528\0\u0549\0\u056a\0\u058b"
+ "\0\u05ac\0\u05cd\0\u05ee\0\u060f\0\u0630\0\u0651\0\u0672\0\u0693"
+ "\0\u06b4\0\u06d5\0\u06f6\0\u0717\0\u0738\0\u0759\0\u077a\0\u079b"
+ "\0\u07bc\0\u07dd\0\u07fe\0\u081f\0\u0840\0\u0861\0\u0882\0\u08a3" + "\0\u08c4\0\u08e5\0\u0906\0\u0927";
private static int[] zzUnpackRowMap() {
int[] result = new int[84];
int offset = 0;
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
return result;
}
private static int zzUnpackRowMap(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -136,38 +136,46 @@ public class DockerTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/**
* The transition table of the DFA
*/
private static final int[] ZZ_TRANS = zzUnpackTrans();
private static final String ZZ_TRANS_PACKED_0 = "\1\4\1\5\1\6\1\7\1\10\3\5\1\11\1\12" + "\1\13\1\14\1\5\1\15\1\16\3\5\1\17\1\20"
+ "\1\21\1\5\1\22\2\5\1\23\1\24\1\25\1\26" + "\1\27\1\30\1\31\1\4\34\32\1\33\2\32\1\34"
+ "\1\35\35\36\1\37\1\36\1\40\1\41\42\0\1\5" + "\1\0\26\5\12\0\1\6\37\0\1\5\1\0\1\5" + "\1\42\24\5\11\0\1\5\1\0\6\5\1\43\5\5"
+ "\1\44\11\5\11\0\1\5\1\0\3\5\1\45\11\5" + "\1\46\10\5\11\0\1\5\1\0\12\5\1\47\13\5" + "\11\0\1\5\1\0\6\5\1\50\17\5\11\0\1\5"
+ "\1\0\3\5\1\51\22\5\11\0\1\5\1\0\17\5" + "\1\52\6\5\11\0\1\5\1\0\1\5\1\53\24\5" + "\11\0\1\5\1\0\4\5\1\54\21\5\11\0\1\5"
+ "\1\0\10\5\1\55\15\5\11\0\1\5\1\0\1\44" + "\7\5\1\56\15\5\11\0\1\5\1\0\10\5\1\57" + "\15\5\43\0\1\24\5\0\37\30\1\0\1\30\34\32"
+ "\1\0\2\32\2\0\37\60\1\0\1\60\35\36\1\0" + "\1\36\2\0\37\61\1\0\1\61\1\0\1\5\1\0" + "\2\5\1\62\23\5\11\0\1\5\1\0\25\5\1\63"
+ "\11\0\1\5\1\0\14\5\1\63\11\5\11\0\1\5" + "\1\0\4\5\1\64\13\5\1\63\5\5\11\0\1\5" + "\1\0\16\5\1\65\7\5\11\0\1\5\1\0\3\5"
+ "\1\63\22\5\11\0\1\5\1\0\10\5\1\66\15\5" + "\11\0\1\5\1\0\11\5\1\67\14\5\11\0\1\5" + "\1\0\5\5\1\70\20\5\11\0\1\5\1\0\11\5"
+ "\1\71\14\5\11\0\1\5\1\0\10\5\1\72\15\5" + "\11\0\1\5\1\0\13\5\1\73\12\5\11\0\1\5" + "\1\0\16\5\1\74\7\5\11\0\1\5\1\0\6\5"
+ "\1\75\17\5\11\0\1\5\1\0\3\5\1\76\22\5" + "\11\0\1\5\1\0\6\5\1\77\17\5\11\0\1\5" + "\1\0\10\5\1\100\15\5\11\0\1\5\1\0\1\63"
+ "\25\5\11\0\1\5\1\0\12\5\1\101\13\5\11\0" + "\1\5\1\0\6\5\1\63\17\5\11\0\1\5\1\0" + "\5\5\1\102\20\5\11\0\1\5\1\0\16\5\1\103"
+ "\7\5\11\0\1\5\1\0\12\5\1\104\13\5\11\0" + "\1\5\1\0\22\5\1\63\3\5\11\0\1\5\1\0" + "\24\5\1\105\1\5\11\0\1\5\1\0\4\5\1\106"
+ "\21\5\11\0\1\5\1\0\22\5\1\107\3\5\11\0" + "\1\5\1\0\17\5\1\110\6\5\11\0\1\5\1\0" + "\2\5\1\111\23\5\11\0\1\5\1\0\13\5\1\63"
+ "\12\5\11\0\1\5\1\0\17\5\1\112\6\5\11\0" + "\1\5\1\0\1\110\25\5\11\0\1\5\1\0\14\5" + "\1\113\11\5\11\0\1\5\1\0\1\5\1\114\24\5"
+ "\11\0\1\5\1\0\16\5\1\115\7\5\11\0\1\5" + "\1\0\5\5\1\63\20\5\11\0\1\5\1\0\13\5" + "\1\44\12\5\11\0\1\5\1\0\2\5\1\116\23\5"
+ "\11\0\1\5\1\0\2\5\1\70\23\5\11\0\1\5" + "\1\0\2\5\1\117\23\5\11\0\1\5\1\0\10\5" + "\1\120\15\5\11\0\1\5\1\0\25\5\1\121\11\0"
+ "\1\5\1\0\3\5\1\52\22\5\11\0\1\5\1\0" + "\2\5\1\122\23\5\11\0\1\5\1\0\3\5\1\123" + "\22\5\11\0\1\5\1\0\3\5\1\124\22\5\11\0"
+ "\1\5\1\0\1\5\1\102\24\5\11\0\1\5\1\0" + "\4\5\1\63\21\5\10\0";
private static final String ZZ_TRANS_PACKED_0 = "\1\4\1\5\1\6\1\7\1\10\3\5\1\11\1\12"
+ "\1\13\1\14\1\5\1\15\1\16\3\5\1\17\1\20" + "\1\21\1\5\1\22\2\5\1\23\1\24\1\25\1\26"
+ "\1\27\1\30\1\31\1\4\34\32\1\33\2\32\1\34" + "\1\35\35\36\1\37\1\36\1\40\1\41\42\0\1\5"
+ "\1\0\26\5\12\0\1\6\37\0\1\5\1\0\1\5" + "\1\42\24\5\11\0\1\5\1\0\6\5\1\43\5\5"
+ "\1\44\11\5\11\0\1\5\1\0\3\5\1\45\11\5" + "\1\46\10\5\11\0\1\5\1\0\12\5\1\47\13\5"
+ "\11\0\1\5\1\0\6\5\1\50\17\5\11\0\1\5" + "\1\0\3\5\1\51\22\5\11\0\1\5\1\0\17\5"
+ "\1\52\6\5\11\0\1\5\1\0\1\5\1\53\24\5" + "\11\0\1\5\1\0\4\5\1\54\21\5\11\0\1\5"
+ "\1\0\10\5\1\55\15\5\11\0\1\5\1\0\1\44" + "\7\5\1\56\15\5\11\0\1\5\1\0\10\5\1\57"
+ "\15\5\43\0\1\24\5\0\37\30\1\0\1\30\34\32" + "\1\0\2\32\2\0\37\60\1\0\1\60\35\36\1\0"
+ "\1\36\2\0\37\61\1\0\1\61\1\0\1\5\1\0" + "\2\5\1\62\23\5\11\0\1\5\1\0\25\5\1\63"
+ "\11\0\1\5\1\0\14\5\1\63\11\5\11\0\1\5" + "\1\0\4\5\1\64\13\5\1\63\5\5\11\0\1\5"
+ "\1\0\16\5\1\65\7\5\11\0\1\5\1\0\3\5" + "\1\63\22\5\11\0\1\5\1\0\10\5\1\66\15\5"
+ "\11\0\1\5\1\0\11\5\1\67\14\5\11\0\1\5" + "\1\0\5\5\1\70\20\5\11\0\1\5\1\0\11\5"
+ "\1\71\14\5\11\0\1\5\1\0\10\5\1\72\15\5" + "\11\0\1\5\1\0\13\5\1\73\12\5\11\0\1\5"
+ "\1\0\16\5\1\74\7\5\11\0\1\5\1\0\6\5" + "\1\75\17\5\11\0\1\5\1\0\3\5\1\76\22\5"
+ "\11\0\1\5\1\0\6\5\1\77\17\5\11\0\1\5" + "\1\0\10\5\1\100\15\5\11\0\1\5\1\0\1\63"
+ "\25\5\11\0\1\5\1\0\12\5\1\101\13\5\11\0" + "\1\5\1\0\6\5\1\63\17\5\11\0\1\5\1\0"
+ "\5\5\1\102\20\5\11\0\1\5\1\0\16\5\1\103" + "\7\5\11\0\1\5\1\0\12\5\1\104\13\5\11\0"
+ "\1\5\1\0\22\5\1\63\3\5\11\0\1\5\1\0" + "\24\5\1\105\1\5\11\0\1\5\1\0\4\5\1\106"
+ "\21\5\11\0\1\5\1\0\22\5\1\107\3\5\11\0" + "\1\5\1\0\17\5\1\110\6\5\11\0\1\5\1\0"
+ "\2\5\1\111\23\5\11\0\1\5\1\0\13\5\1\63" + "\12\5\11\0\1\5\1\0\17\5\1\112\6\5\11\0"
+ "\1\5\1\0\1\110\25\5\11\0\1\5\1\0\14\5" + "\1\113\11\5\11\0\1\5\1\0\1\5\1\114\24\5"
+ "\11\0\1\5\1\0\16\5\1\115\7\5\11\0\1\5" + "\1\0\5\5\1\63\20\5\11\0\1\5\1\0\13\5"
+ "\1\44\12\5\11\0\1\5\1\0\2\5\1\116\23\5" + "\11\0\1\5\1\0\2\5\1\70\23\5\11\0\1\5"
+ "\1\0\2\5\1\117\23\5\11\0\1\5\1\0\10\5" + "\1\120\15\5\11\0\1\5\1\0\25\5\1\121\11\0"
+ "\1\5\1\0\3\5\1\52\22\5\11\0\1\5\1\0" + "\2\5\1\122\23\5\11\0\1\5\1\0\3\5\1\123"
+ "\22\5\11\0\1\5\1\0\3\5\1\124\22\5\11\0" + "\1\5\1\0\1\5\1\102\24\5\11\0\1\5\1\0" + "\4\5\1\63\21\5\10\0";
private static int[] zzUnpackTrans() {
int[] result = new int[2376];
int offset = 0;
offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
return result;
}
private static int zzUnpackTrans(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -182,7 +190,7 @@ public class DockerTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/* error codes */
private static final int ZZ_UNKNOWN_ERROR = 0;
private static final int ZZ_NO_MATCH = 1;
@@ -194,15 +202,16 @@ public class DockerTokenMaker extends AbstractJFlexTokenMaker {
* ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
*/
private static final int[] ZZ_ATTRIBUTE = zzUnpackAttribute();
private static final String ZZ_ATTRIBUTE_PACKED_0 = "\1\1\2\0\1\11\16\1\2\11\1\1\2\11\1\1" + "\1\11\1\1\2\11\2\1\2\11\17\1\2\11\43\1";
private static final String ZZ_ATTRIBUTE_PACKED_0 = "\1\1\2\0\1\11\16\1\2\11\1\1\2\11\1\1"
+ "\1\11\1\1\2\11\2\1\2\11\17\1\2\11\43\1";
private static int[] zzUnpackAttribute() {
int[] result = new int[84];
int offset = 0;
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAttribute(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -216,7 +225,7 @@ public class DockerTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/** the input device */
private java.io.Reader zzReader;
/** the current state of the DFA */
@@ -224,8 +233,8 @@ public class DockerTokenMaker extends AbstractJFlexTokenMaker {
/** the current lexical state */
private int zzLexicalState = YYINITIAL;
/**
* this buffer contains the current text to be matched and is
* the source of the yytext() string
* this buffer contains the current text to be matched and is the source of the
* yytext() string
*/
private char zzBuffer[];
/** the textposition at the last accepting state */
@@ -235,62 +244,54 @@ public class DockerTokenMaker extends AbstractJFlexTokenMaker {
/** startRead marks the beginning of the yytext() string in the buffer */
private int zzStartRead;
/**
* endRead marks the last character in the buffer, that has been read
* from input
* endRead marks the last character in the buffer, that has been read from input
*/
private int zzEndRead;
/** zzAtEOF == true <=> the scanner is at the EOF */
private boolean zzAtEOF;
/* user code: */
/**
* Constructor. This must be here because JFlex does not generate a
* no-parameter constructor.
* Constructor. This must be here because JFlex does not generate a no-parameter
* constructor.
*/
public DockerTokenMaker() {}
public DockerTokenMaker() {
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType
* The token's type.
* @param tokenType The token's type.
*/
private void addToken(int tokenType) {
addToken(zzStartRead, zzMarkedPos - 1, tokenType);
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType
* The token's type.
* @param tokenType The token's type.
*/
private void addToken(int start, int end, int tokenType) {
int so = start + offsetShift;
addToken(zzBuffer, start, end, tokenType, so);
}
/**
* 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 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.
*/
@Override
public void addToken(char[] array, int start, int end, int tokenType, int startOffset) {
super.addToken(array, start, end, tokenType, startOffset);
zzStartRead = zzMarkedPos;
}
/**
* {@inheritDoc}
*/
@@ -298,35 +299,30 @@ public class DockerTokenMaker extends AbstractJFlexTokenMaker {
public String[] getLineCommentStartAndEnd(int languageIndex) {
return new String[] { "#", null };
}
/**
* Returns whether tokens of the specified type should have "mark
* occurrences" enabled for the current programming language.
* Returns whether tokens of the specified type should have "mark occurrences"
* enabled for the current programming language.
*
* @param type
* The token type.
* @return Whether tokens of this type should have "mark occurrences"
* enabled.
* @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 || type == Token.RESERVED_WORD;
}
/**
* Returns the first token in the linked list of tokens generated
* from <code>text</code>. This method must be implemented by
* subclasses so they can correctly implement syntax highlighting.
* Returns the first token in the linked list of tokens generated from
* <code>text</code>. This method must be implemented by subclasses so they can
* correctly implement syntax highlighting.
*
* @param text
* The text from which to get tokens.
* @param initialTokenType
* The token type we should start with.
* @param startOffset
* The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing
* the syntax highlighted text.
* @param text The text from which to get tokens.
* @param initialTokenType The token type we should start with.
* @param startOffset The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing the syntax
* highlighted text.
*/
@Override
public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
@@ -344,36 +340,34 @@ public class DockerTokenMaker extends AbstractJFlexTokenMaker {
return new TokenImpl();
}
}
/**
* Refills the input buffer.
*
* @return <code>true</code> if EOF was reached, otherwise
* <code>false</code>.
* @return <code>true</code> if EOF was reached, otherwise <code>false</code>.
*/
private boolean zzRefill() {
return zzCurrentPos >= s.offset + s.count;
}
/**
* Resets the scanner to read from a new input stream.
* Does not close the old reader.
* Resets the scanner to read from a new input stream. Does not close the old
* reader.
*
* All internal variables are reset, the old input stream
* <b>cannot</b> be reused (internal buffer is discarded and lost).
* Lexical state is set to <tt>YY_INITIAL</tt>.
* All internal variables are reset, the old input stream <b>cannot</b> be
* reused (internal buffer is discarded and lost). Lexical state is set to
* <tt>YY_INITIAL</tt>.
*
* @param reader
* the new input stream
* @param reader the new input stream
*/
public final void yyreset(Reader reader) {
// 's' has been updated.
zzBuffer = s.array;
/*
* We replaced the line below with the two below it because zzRefill
* no longer "refills" the buffer (since the way we do it, it's always
* "full" the first time through, since it points to the segment's
* array). So, we assign zzEndRead here.
* We replaced the line below with the two below it because zzRefill no longer
* "refills" the buffer (since the way we do it, it's always "full" the first
* time through, since it points to the segment's array). So, we assign
* zzEndRead here.
*/
// zzStartRead = zzEndRead = s.offset;
zzStartRead = s.offset;
@@ -383,34 +377,31 @@ public class DockerTokenMaker extends AbstractJFlexTokenMaker {
zzReader = reader;
zzAtEOF = false;
}
/**
* Creates a new scanner
* There is also a java.io.InputStream version of this constructor.
* Creates a new scanner There is also a java.io.InputStream version of this
* constructor.
*
* @param in
* the java.io.Reader to read input from.
* @param in the java.io.Reader to read input from.
*/
public DockerTokenMaker(java.io.Reader in) {
this.zzReader = in;
}
/**
* Creates a new scanner.
* There is also java.io.Reader version of this constructor.
* Creates a new scanner. There is also java.io.Reader version of this
* constructor.
*
* @param in
* the java.io.Inputstream to read input from.
* @param in the java.io.Inputstream to read input from.
*/
public DockerTokenMaker(java.io.InputStream in) {
this(new java.io.InputStreamReader(in));
}
/**
* Unpacks the compressed character translation table.
*
* @param packed
* the packed character translation table
* @param packed the packed character translation table
* @return the unpacked character translation table
*/
private static char[] zzUnpackCMap(String packed) {
@@ -426,7 +417,7 @@ public class DockerTokenMaker extends AbstractJFlexTokenMaker {
}
return map;
}
/**
* Closes the input stream.
*/
@@ -436,69 +427,64 @@ public class DockerTokenMaker extends AbstractJFlexTokenMaker {
if (zzReader != null)
zzReader.close();
}
/**
* Returns the current lexical state.
*/
public final int yystate() {
return zzLexicalState;
}
/**
* Enters a new lexical state
*
* @param newState
* the new lexical state
* @param newState the new lexical state
*/
@Override
public final void yybegin(int newState) {
zzLexicalState = newState;
}
/**
* Returns the text matched by the current regular expression.
*/
public final String yytext() {
return new String(zzBuffer, zzStartRead, zzMarkedPos - zzStartRead);
}
/**
* Returns the character at position <tt>pos</tt> from the
* matched text.
* Returns the character at position <tt>pos</tt> from the matched text.
*
* It is equivalent to yytext().charAt(pos), but faster
*
* @param pos
* the position of the character to fetch.
* A value from 0 to yylength()-1.
* @param pos the position of the character to fetch. A value from 0 to
* yylength()-1.
*
* @return the character at position pos
*/
public final char yycharat(int pos) {
return zzBuffer[zzStartRead + pos];
}
/**
* Returns the length of the matched text region.
*/
public final int yylength() {
return zzMarkedPos - zzStartRead;
}
/**
* Reports an error that occured while scanning.
*
* In a wellformed scanner (no or only correct usage of
* yypushback(int) and a match-all fallback rule) this method
* will only be called with things that "Can't Possibly Happen".
* If this method is called, something is seriously wrong
* (e.g. a JFlex bug producing a faulty scanner etc.).
* In a wellformed scanner (no or only correct usage of yypushback(int) and a
* match-all fallback rule) this method will only be called with things that
* "Can't Possibly Happen". If this method is called, something is seriously
* wrong (e.g. a JFlex bug producing a faulty scanner etc.).
*
* Usual syntax/scanner level error handling should be done
* in error fallback rules.
* Usual syntax/scanner level error handling should be done in error fallback
* rules.
*
* @param errorCode
* the code of the errormessage to display
* @param errorCode the code of the errormessage to display
*/
private void zzScanError(int errorCode) {
String message;
@@ -509,29 +495,27 @@ public class DockerTokenMaker extends AbstractJFlexTokenMaker {
}
throw new Error(message);
}
/**
* Pushes the specified amount of characters back into the input stream.
*
* They will be read again by then next call of the scanning method
*
* @param number
* the number of characters to be read again.
* This number must not be greater than yylength()!
* @param number the number of characters to be read again. This number must not
* be greater than yylength()!
*/
public void yypushback(int number) {
if (number > yylength())
zzScanError(ZZ_PUSHBACK_2BIG);
zzMarkedPos -= number;
}
/**
* Resumes scanning until the next regular expression is matched,
* the end of input is encountered or an I/O-Error occurs.
* Resumes scanning until the next regular expression is matched, the end of
* input is encountered or an I/O-Error occurs.
*
* @return the next token
* @exception java.io.IOException
* if any I/O-Error occurs
* @exception java.io.IOException if any I/O-Error occurs
*/
public org.fife.ui.rsyntaxtextarea.Token yylex() throws java.io.IOException {
int zzInput;
@@ -550,8 +534,7 @@ public class DockerTokenMaker extends AbstractJFlexTokenMaker {
zzAction = -1;
zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
zzState = zzLexicalState;
zzForAction:
{
zzForAction: {
while (true) {
if (zzCurrentPosL < zzEndReadL)
zzInput = zzBufferL[zzCurrentPosL++];
@@ -591,122 +574,122 @@ public class DockerTokenMaker extends AbstractJFlexTokenMaker {
// store back cached position
zzMarkedPos = zzMarkedPosL;
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
case 16: {
addToken(Token.RESERVED_WORD);
}
case 17:
break;
case 1: {
addToken(Token.IDENTIFIER);
}
case 18:
break;
case 7: {
addToken(Token.COMMENT_EOL);
addNullToken();
return firstToken;
}
case 19:
break;
case 2: {
addToken(Token.WHITESPACE);
}
case 20:
break;
case 11: {
addToken(start, zzStartRead - 1, Token.LITERAL_STRING_DOUBLE_QUOTE);
return firstToken;
}
case 21:
break;
case 14: {
addToken(start, zzStartRead - 1, Token.LITERAL_CHAR);
return firstToken;
}
case 22:
break;
case 12: { /* Skip escaped chars. */
}
case 23:
break;
case 4: {
addToken(Token.OPERATOR);
}
case 24:
break;
case 15: { /*
* Skip escaped single quotes only, but this should
* still work.
*/
}
case 25:
break;
case 5: {
start = zzMarkedPos - 1;
yybegin(STRING);
}
case 26:
break;
case 13: {
yybegin(YYINITIAL);
addToken(start, zzStartRead, Token.LITERAL_CHAR);
}
case 27:
break;
case 10: {
yybegin(YYINITIAL);
addToken(start, zzStartRead, Token.LITERAL_STRING_DOUBLE_QUOTE);
}
case 28:
break;
case 8: {
addNullToken();
return firstToken;
}
case 29:
break;
case 9: {}
case 30:
break;
case 3: {
addToken(Token.SEPARATOR);
}
case 31:
break;
case 6: {
start = zzMarkedPos - 1;
yybegin(CHAR_LITERAL);
}
case 32:
break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
switch (zzLexicalState) {
case STRING: {
addToken(start, zzStartRead - 1, Token.LITERAL_STRING_DOUBLE_QUOTE);
return firstToken;
}
case 85:
break;
case CHAR_LITERAL: {
addToken(start, zzStartRead - 1, Token.LITERAL_CHAR);
return firstToken;
}
case 86:
break;
case YYINITIAL: {
addNullToken();
return firstToken;
}
case 87:
break;
default:
return null;
}
} else {
zzScanError(ZZ_NO_MATCH);
case 16: {
addToken(Token.RESERVED_WORD);
}
case 17:
break;
case 1: {
addToken(Token.IDENTIFIER);
}
case 18:
break;
case 7: {
addToken(Token.COMMENT_EOL);
addNullToken();
return firstToken;
}
case 19:
break;
case 2: {
addToken(Token.WHITESPACE);
}
case 20:
break;
case 11: {
addToken(start, zzStartRead - 1, Token.LITERAL_STRING_DOUBLE_QUOTE);
return firstToken;
}
case 21:
break;
case 14: {
addToken(start, zzStartRead - 1, Token.LITERAL_CHAR);
return firstToken;
}
case 22:
break;
case 12: { /* Skip escaped chars. */
}
case 23:
break;
case 4: {
addToken(Token.OPERATOR);
}
case 24:
break;
case 15: { /*
* Skip escaped single quotes only, but this should still work.
*/
}
case 25:
break;
case 5: {
start = zzMarkedPos - 1;
yybegin(STRING);
}
case 26:
break;
case 13: {
yybegin(YYINITIAL);
addToken(start, zzStartRead, Token.LITERAL_CHAR);
}
case 27:
break;
case 10: {
yybegin(YYINITIAL);
addToken(start, zzStartRead, Token.LITERAL_STRING_DOUBLE_QUOTE);
}
case 28:
break;
case 8: {
addNullToken();
return firstToken;
}
case 29:
break;
case 9: {
}
case 30:
break;
case 3: {
addToken(Token.SEPARATOR);
}
case 31:
break;
case 6: {
start = zzMarkedPos - 1;
yybegin(CHAR_LITERAL);
}
case 32:
break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
switch (zzLexicalState) {
case STRING: {
addToken(start, zzStartRead - 1, Token.LITERAL_STRING_DOUBLE_QUOTE);
return firstToken;
}
case 85:
break;
case CHAR_LITERAL: {
addToken(start, zzStartRead - 1, Token.LITERAL_CHAR);
return firstToken;
}
case 86:
break;
case YYINITIAL: {
addNullToken();
return firstToken;
}
case 87:
break;
default:
return null;
}
} else {
zzScanError(ZZ_NO_MATCH);
}
}
}
}
@@ -20,16 +20,15 @@ import org.fife.ui.rsyntaxtextarea.TokenImpl;
*
* This implementation was created using
* <a href="http://www.jflex.de/">JFlex</a> 1.4.1; however, the generated file
* was modified for performance. Memory allocation needs to be almost
* completely removed to be competitive with the handwritten lexers (subclasses
* of <code>AbstractTokenMaker</code>, so this class has been modified so that
* was modified for performance. Memory allocation needs to be almost completely
* removed to be competitive with the handwritten lexers (subclasses of
* <code>AbstractTokenMaker</code>, so this class has been modified so that
* Strings are never allocated (via yytext()), and the scanner never has to
* worry about refilling its buffer (needlessly copying chars around).
* We can achieve this because RText always scans exactly 1 line of tokens at a
* time, and hands the scanner this line as an array of characters (a Segment
* really). Since tokens contain pointers to char arrays instead of Strings
* holding their contents, there is no need for allocating new memory for
* Strings.
* worry about refilling its buffer (needlessly copying chars around). We can
* achieve this because RText always scans exactly 1 line of tokens at a time,
* and hands the scanner this line as an array of characters (a Segment really).
* Since tokens contain pointers to char arrays instead of Strings holding their
* contents, there is no need for allocating new memory for Strings.
* <p>
*
* The actual algorithm generated for scanning has, of course, not been
@@ -39,23 +38,23 @@ import org.fife.ui.rsyntaxtextarea.TokenImpl;
* If you wish to regenerate this file yourself, keep in mind the following:
* <ul>
* <li>The generated <code>XMLTokenMaker.java</code> file will contain two
* definitions of both <code>zzRefill</code> and <code>yyreset</code>.
* You should hand-delete the second of each definition (the ones
* generated by the lexer), as these generated methods modify the input
* buffer, which we'll never have to do.</li>
* <li>You should also change the declaration/definition of zzBuffer to NOT
* be initialized. This is a needless memory allocation for us since we
* will be pointing the array somewhere else anyway.</li>
* definitions of both <code>zzRefill</code> and <code>yyreset</code>. You
* should hand-delete the second of each definition (the ones generated by the
* lexer), as these generated methods modify the input buffer, which we'll never
* have to do.</li>
* <li>You should also change the declaration/definition of zzBuffer to NOT be
* initialized. This is a needless memory allocation for us since we will be
* pointing the array somewhere else anyway.</li>
* <li>You should NOT call <code>yylex()</code> on the generated scanner
* directly; rather, you should use <code>getTokenList</code> as you would
* with any other <code>TokenMaker</code> instance.</li>
* directly; rather, you should use <code>getTokenList</code> as you would with
* any other <code>TokenMaker</code> instance.</li>
* </ul>
*
* @author Robert Futrell
* @version 1.0
*/
public class DtdTokenMaker extends AbstractJFlexTokenMaker {
/** This character denotes the end of file */
public static final int YYEOF = -1;
/** lexical states */
@@ -79,16 +78,17 @@ public class DtdTokenMaker extends AbstractJFlexTokenMaker {
* Translates DFA states to action switch labels.
*/
private static final int[] ZZ_ACTION = zzUnpackAction();
private static final String ZZ_ACTION_PACKED_0 = "\5\0\1\1\1\2\1\3\1\4\1\5\4\4\1\3" + "\1\6\2\3\2\7\2\10\2\7\1\11\5\0\2\3"
+ "\1\10\3\7\5\0\1\12\2\3\3\7\1\13\2\0" + "\1\14\2\3\3\7\2\0\2\3\1\15\2\7\2\3" + "\2\7\1\16\1\17\1\7";
private static final String ZZ_ACTION_PACKED_0 = "\5\0\1\1\1\2\1\3\1\4\1\5\4\4\1\3"
+ "\1\6\2\3\2\7\2\10\2\7\1\11\5\0\2\3" + "\1\10\3\7\5\0\1\12\2\3\3\7\1\13\2\0"
+ "\1\14\2\3\3\7\2\0\2\3\1\15\2\7\2\3" + "\2\7\1\16\1\17\1\7";
private static int[] zzUnpackAction() {
int[] result = new int[70];
int offset = 0;
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAction(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -102,7 +102,7 @@ public class DtdTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/**
* Translates a state to a row index in the transition table
*/
@@ -114,15 +114,16 @@ public class DtdTokenMaker extends AbstractJFlexTokenMaker {
+ "\0\u0156\0\u049a\0\u04c0\0\u04e6\0\u050c\0\u0532\0\u0558\0\u057e"
+ "\0\u05a4\0\u0156\0\u05ca\0\u05f0\0\u0616\0\u063c\0\u0662\0\u0156"
+ "\0\u0688\0\u06ae\0\u06d4\0\u06fa\0\u0720\0\u0746\0\u076c\0\u0792"
+ "\0\u07b8\0\u06d4\0\u07de\0\u0804\0\u02ac\0\u082a\0\u0850\0\u0876" + "\0\u089c\0\u08c2\0\u08e8\0\u0214\0\u0214\0\u090e";
+ "\0\u07b8\0\u06d4\0\u07de\0\u0804\0\u02ac\0\u082a\0\u0850\0\u0876"
+ "\0\u089c\0\u08c2\0\u08e8\0\u0214\0\u0214\0\u090e";
private static int[] zzUnpackRowMap() {
int[] result = new int[70];
int offset = 0;
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
return result;
}
private static int zzUnpackRowMap(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -133,41 +134,42 @@ public class DtdTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/**
* The transition table of the DFA
*/
private static final int[] ZZ_TRANS = zzUnpackTrans();
private static final String ZZ_TRANS_PACKED_0 = "\1\6\1\7\21\6\1\10\22\6\2\11\1\12\5\11" + "\1\13\3\11\1\14\4\11\1\15\3\11\1\16\20\11"
+ "\1\17\1\7\24\17\1\20\1\21\4\17\1\22\11\17" + "\1\23\1\7\24\23\1\20\17\23\1\24\1\7\1\24"
+ "\1\25\1\26\21\24\1\20\10\24\1\27\1\24\1\30" + "\4\24\1\6\1\0\21\6\1\0\22\6\1\0\1\7"
+ "\70\0\1\31\21\0\2\11\1\0\5\11\1\0\3\11" + "\1\0\4\11\1\0\3\11\1\0\20\11\57\0\1\32"
+ "\45\0\1\33\3\0\1\34\51\0\1\35\51\0\1\36" + "\20\0\1\17\1\0\24\17\1\0\20\17\1\0\24\17"
+ "\1\0\1\17\1\37\16\17\1\0\24\17\1\0\4\17" + "\1\40\12\17\1\23\1\0\24\23\1\0\17\23\1\24"
+ "\1\0\1\24\2\0\21\24\1\0\17\24\3\25\1\41" + "\42\25\4\26\1\41\41\26\1\24\1\0\1\24\2\0"
+ "\21\24\1\0\11\24\1\42\6\24\1\0\1\24\2\0" + "\21\24\1\0\6\24\1\43\5\24\1\44\2\24\25\0"
+ "\1\45\31\0\1\46\46\0\1\47\51\0\1\50\50\0" + "\1\51\52\0\1\52\17\0\1\17\1\0\24\17\1\0"
+ "\1\53\17\17\1\0\24\17\1\0\4\17\1\54\12\17" + "\1\24\1\0\1\24\2\0\21\24\1\0\5\24\1\55"
+ "\12\24\1\0\1\24\2\0\21\24\1\0\2\24\1\56" + "\15\24\1\0\1\24\2\0\21\24\1\0\1\57\16\24"
+ "\25\0\1\60\32\0\1\61\53\0\1\62\44\0\1\47" + "\50\0\1\63\23\0\1\17\1\0\24\17\1\0\2\17"
+ "\1\64\15\17\1\0\24\17\1\0\1\17\1\65\15\17" + "\1\24\1\0\1\24\2\0\21\24\1\0\4\24\1\66"
+ "\13\24\1\0\1\24\2\0\21\24\1\0\13\24\1\67" + "\4\24\1\0\1\24\2\0\21\24\1\0\15\24\1\70"
+ "\1\24\13\0\1\47\4\0\1\62\33\0\1\71\43\0" + "\2\72\12\63\1\72\1\63\1\72\1\0\2\72\1\0"
+ "\12\63\1\72\4\63\1\17\1\0\24\17\1\0\1\73" + "\17\17\1\0\24\17\1\0\6\17\1\74\10\17\1\24"
+ "\1\0\1\24\2\0\21\24\1\0\5\24\1\75\12\24" + "\1\0\1\24\2\0\21\24\1\0\1\24\1\76\16\24"
+ "\1\0\1\24\2\0\21\24\1\0\16\24\1\77\6\0" + "\1\63\37\0\1\17\1\0\24\17\1\0\3\17\1\100"
+ "\14\17\1\0\24\17\1\0\7\17\1\101\7\17\1\24" + "\1\0\1\24\2\0\21\24\1\0\6\24\1\102\11\24"
+ "\1\0\1\24\2\0\21\24\1\0\6\24\1\103\10\24" + "\1\17\1\0\24\17\1\0\4\17\1\104\13\17\1\0"
+ "\24\17\1\0\4\17\1\105\12\17\1\24\1\0\1\24" + "\2\0\21\24\1\0\1\106\17\24\1\0\1\24\2\0"
+ "\21\24\1\0\14\24\1\102\3\24\1\0\1\24\2\0" + "\21\24\1\0\11\24\1\75\5\24";
private static final String ZZ_TRANS_PACKED_0 = "\1\6\1\7\21\6\1\10\22\6\2\11\1\12\5\11"
+ "\1\13\3\11\1\14\4\11\1\15\3\11\1\16\20\11" + "\1\17\1\7\24\17\1\20\1\21\4\17\1\22\11\17"
+ "\1\23\1\7\24\23\1\20\17\23\1\24\1\7\1\24" + "\1\25\1\26\21\24\1\20\10\24\1\27\1\24\1\30"
+ "\4\24\1\6\1\0\21\6\1\0\22\6\1\0\1\7" + "\70\0\1\31\21\0\2\11\1\0\5\11\1\0\3\11"
+ "\1\0\4\11\1\0\3\11\1\0\20\11\57\0\1\32" + "\45\0\1\33\3\0\1\34\51\0\1\35\51\0\1\36"
+ "\20\0\1\17\1\0\24\17\1\0\20\17\1\0\24\17" + "\1\0\1\17\1\37\16\17\1\0\24\17\1\0\4\17"
+ "\1\40\12\17\1\23\1\0\24\23\1\0\17\23\1\24" + "\1\0\1\24\2\0\21\24\1\0\17\24\3\25\1\41"
+ "\42\25\4\26\1\41\41\26\1\24\1\0\1\24\2\0" + "\21\24\1\0\11\24\1\42\6\24\1\0\1\24\2\0"
+ "\21\24\1\0\6\24\1\43\5\24\1\44\2\24\25\0" + "\1\45\31\0\1\46\46\0\1\47\51\0\1\50\50\0"
+ "\1\51\52\0\1\52\17\0\1\17\1\0\24\17\1\0" + "\1\53\17\17\1\0\24\17\1\0\4\17\1\54\12\17"
+ "\1\24\1\0\1\24\2\0\21\24\1\0\5\24\1\55" + "\12\24\1\0\1\24\2\0\21\24\1\0\2\24\1\56"
+ "\15\24\1\0\1\24\2\0\21\24\1\0\1\57\16\24" + "\25\0\1\60\32\0\1\61\53\0\1\62\44\0\1\47"
+ "\50\0\1\63\23\0\1\17\1\0\24\17\1\0\2\17" + "\1\64\15\17\1\0\24\17\1\0\1\17\1\65\15\17"
+ "\1\24\1\0\1\24\2\0\21\24\1\0\4\24\1\66" + "\13\24\1\0\1\24\2\0\21\24\1\0\13\24\1\67"
+ "\4\24\1\0\1\24\2\0\21\24\1\0\15\24\1\70" + "\1\24\13\0\1\47\4\0\1\62\33\0\1\71\43\0"
+ "\2\72\12\63\1\72\1\63\1\72\1\0\2\72\1\0" + "\12\63\1\72\4\63\1\17\1\0\24\17\1\0\1\73"
+ "\17\17\1\0\24\17\1\0\6\17\1\74\10\17\1\24" + "\1\0\1\24\2\0\21\24\1\0\5\24\1\75\12\24"
+ "\1\0\1\24\2\0\21\24\1\0\1\24\1\76\16\24" + "\1\0\1\24\2\0\21\24\1\0\16\24\1\77\6\0"
+ "\1\63\37\0\1\17\1\0\24\17\1\0\3\17\1\100" + "\14\17\1\0\24\17\1\0\7\17\1\101\7\17\1\24"
+ "\1\0\1\24\2\0\21\24\1\0\6\24\1\102\11\24" + "\1\0\1\24\2\0\21\24\1\0\6\24\1\103\10\24"
+ "\1\17\1\0\24\17\1\0\4\17\1\104\13\17\1\0" + "\24\17\1\0\4\17\1\105\12\17\1\24\1\0\1\24"
+ "\2\0\21\24\1\0\1\106\17\24\1\0\1\24\2\0" + "\21\24\1\0\14\24\1\102\3\24\1\0\1\24\2\0"
+ "\21\24\1\0\11\24\1\75\5\24";
private static int[] zzUnpackTrans() {
int[] result = new int[2356];
int offset = 0;
offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
return result;
}
private static int zzUnpackTrans(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -182,7 +184,7 @@ public class DtdTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/* error codes */
private static final int ZZ_UNKNOWN_ERROR = 0;
private static final int ZZ_NO_MATCH = 1;
@@ -194,16 +196,16 @@ public class DtdTokenMaker extends AbstractJFlexTokenMaker {
* ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
*/
private static final int[] ZZ_ATTRIBUTE = zzUnpackAttribute();
private static final String ZZ_ATTRIBUTE_PACKED_0 = "\5\0\4\1\1\11\5\1\1\11\11\1\5\0\2\1" + "\1\11\3\1\5\0\1\11\5\1\1\11\2\0\6\1"
+ "\2\0\14\1";
private static final String ZZ_ATTRIBUTE_PACKED_0 = "\5\0\4\1\1\11\5\1\1\11\11\1\5\0\2\1"
+ "\1\11\3\1\5\0\1\11\5\1\1\11\2\0\6\1" + "\2\0\14\1";
private static int[] zzUnpackAttribute() {
int[] result = new int[70];
int offset = 0;
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAttribute(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -217,7 +219,7 @@ public class DtdTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/** the input device */
private java.io.Reader zzReader;
/** the current state of the DFA */
@@ -225,8 +227,8 @@ public class DtdTokenMaker extends AbstractJFlexTokenMaker {
/** the current lexical state */
private int zzLexicalState = YYINITIAL;
/**
* this buffer contains the current text to be matched and is
* the source of the yytext() string
* this buffer contains the current text to be matched and is the source of the
* yytext() string
*/
private char zzBuffer[];
/** the textposition at the last accepting state */
@@ -236,139 +238,124 @@ public class DtdTokenMaker extends AbstractJFlexTokenMaker {
/** startRead marks the beginning of the yytext() string in the buffer */
private int zzStartRead;
/**
* endRead marks the last character in the buffer, that has been read
* from input
* endRead marks the last character in the buffer, that has been read from input
*/
private int zzEndRead;
/** zzAtEOF == true <=> the scanner is at the EOF */
private boolean zzAtEOF;
/* user code: */
/**
* Token type specific to XMLTokenMaker denoting a line ending with an
* unclosed XML tag; thus a new line is beginning still inside of the tag.
* Token type specific to XMLTokenMaker denoting a line ending with an unclosed
* XML tag; thus a new line is beginning still inside of the tag.
*/
public static final int INTERNAL_INTAG_START = -1;
/**
* Token type specific to XMLTokenMaker denoting a line ending with an
* unclosed DOCTYPE element.
* Token type specific to XMLTokenMaker denoting a line ending with an unclosed
* DOCTYPE element.
*/
public static final int INTERNAL_INTAG_ELEMENT = -2;
/**
* Token type specific to XMLTokenMaker denoting a line ending with an
* unclosed, locally-defined DTD in a DOCTYPE element.
* Token type specific to XMLTokenMaker denoting a line ending with an unclosed,
* locally-defined DTD in a DOCTYPE element.
*/
public static final int INTERNAL_INTAG_ATTLIST = -3;
/**
* Token type specific to XMLTokenMaker denoting a line ending with an
* unclosed comment. The state to return to when this comment ends is
* embedded in the token type as well.
* Token type specific to XMLTokenMaker denoting a line ending with an unclosed
* comment. The state to return to when this comment ends is embedded in the
* token type as well.
*/
public static final int INTERNAL_IN_COMMENT = -(1 << 11);
/**
* The state we were in prior to the current one. This is used to know
* what state to resume after an MLC ends.
* The state we were in prior to the current one. This is used to know what
* state to resume after an MLC ends.
*/
private int prevState;
/**
* Constructor. This must be here because JFlex does not generate a
* no-parameter constructor.
* Constructor. This must be here because JFlex does not generate a no-parameter
* constructor.
*/
public DtdTokenMaker() {}
public DtdTokenMaker() {
}
/**
* Adds the token specified to the current linked list of tokens as an
* "end token;" that is, at <code>zzMarkedPos</code>.
* Adds the token specified to the current linked list of tokens as an "end
* token;" that is, at <code>zzMarkedPos</code>.
*
* @param tokenType
* The token's type.
* @param tokenType The token's type.
*/
private void addEndToken(int tokenType) {
addToken(zzMarkedPos, zzMarkedPos, tokenType);
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType
* The token's type.
* @param tokenType The token's type.
* @see #addToken(int, int, int)
*/
private void addHyperlinkToken(int start, int end, int tokenType) {
int so = start + offsetShift;
addToken(zzBuffer, start, end, tokenType, so, true);
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType
* The token's type.
* @param tokenType The token's type.
*/
private void addToken(int tokenType) {
addToken(zzStartRead, zzMarkedPos - 1, tokenType);
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType
* The token's type.
* @param tokenType The token's type.
*/
private void addToken(int start, int end, int tokenType) {
int so = start + offsetShift;
addToken(zzBuffer, start, end, tokenType, so);
}
/**
* 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 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.
*/
@Override
public void addToken(char[] array, int start, int end, int tokenType, int startOffset) {
super.addToken(array, start, end, tokenType, startOffset);
zzStartRead = zzMarkedPos;
}
/**
* Always returns <tt>false</tt>, as you never want "mark occurrences"
* working in XML files.
* Always returns <tt>false</tt>, as you never want "mark occurrences" working
* in XML files.
*
* @param type
* The token type.
* @return Whether tokens of this type should have "mark occurrences"
* enabled.
* @param type The token type.
* @return Whether tokens of this type should have "mark occurrences" enabled.
*/
@Override
public boolean getMarkOccurrencesOfTokenType(int type) {
return false;
}
/**
* Returns the first token in the linked list of tokens generated
* from <code>text</code>. This method must be implemented by
* subclasses so they can correctly implement syntax highlighting.
* Returns the first token in the linked list of tokens generated from
* <code>text</code>. This method must be implemented by subclasses so they can
* correctly implement syntax highlighting.
*
* @param text
* The text from which to get tokens.
* @param initialTokenType
* The token type we should start with.
* @param startOffset
* The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing
* the syntax highlighted text.
* @param text The text from which to get tokens.
* @param initialTokenType The token type we should start with.
* @param startOffset The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing the syntax
* highlighted text.
*/
@Override
public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
@@ -378,29 +365,29 @@ public class DtdTokenMaker extends AbstractJFlexTokenMaker {
// Start off in the proper state.
int state = YYINITIAL;
switch (initialTokenType) {
case INTERNAL_INTAG_START:
state = INTAG_START;
break;
case INTERNAL_INTAG_ELEMENT:
state = INTAG_ELEMENT;
break;
case INTERNAL_INTAG_ATTLIST:
state = INTAG_ATTLIST;
break;
default:
if (initialTokenType < -1024) { // INTERNAL_IN_COMMENT -
// prevState
int main = -(-initialTokenType & 0xffffff00);
switch (main) {
default: // Should never happen
case INTERNAL_IN_COMMENT:
state = COMMENT;
break;
}
prevState = -initialTokenType & 0xff;
} else { // Shouldn't happen
state = YYINITIAL;
case INTERNAL_INTAG_START:
state = INTAG_START;
break;
case INTERNAL_INTAG_ELEMENT:
state = INTAG_ELEMENT;
break;
case INTERNAL_INTAG_ATTLIST:
state = INTAG_ATTLIST;
break;
default:
if (initialTokenType < -1024) { // INTERNAL_IN_COMMENT -
// prevState
int main = -(-initialTokenType & 0xffffff00);
switch (main) {
default: // Should never happen
case INTERNAL_IN_COMMENT:
state = COMMENT;
break;
}
prevState = -initialTokenType & 0xff;
} else { // Shouldn't happen
state = YYINITIAL;
}
}
start = text.offset;
s = text;
@@ -413,36 +400,34 @@ public class DtdTokenMaker extends AbstractJFlexTokenMaker {
return new TokenImpl();
}
}
/**
* Refills the input buffer.
*
* @return <code>true</code> if EOF was reached, otherwise
* <code>false</code>.
* @return <code>true</code> if EOF was reached, otherwise <code>false</code>.
*/
private boolean zzRefill() {
return zzCurrentPos >= s.offset + s.count;
}
/**
* Resets the scanner to read from a new input stream.
* Does not close the old reader.
* Resets the scanner to read from a new input stream. Does not close the old
* reader.
*
* All internal variables are reset, the old input stream
* <b>cannot</b> be reused (internal buffer is discarded and lost).
* Lexical state is set to <tt>YY_INITIAL</tt>.
* All internal variables are reset, the old input stream <b>cannot</b> be
* reused (internal buffer is discarded and lost). Lexical state is set to
* <tt>YY_INITIAL</tt>.
*
* @param reader
* the new input stream
* @param reader the new input stream
*/
public final void yyreset(java.io.Reader reader) {
// 's' has been updated.
zzBuffer = s.array;
/*
* We replaced the line below with the two below it because zzRefill
* no longer "refills" the buffer (since the way we do it, it's always
* "full" the first time through, since it points to the segment's
* array). So, we assign zzEndRead here.
* We replaced the line below with the two below it because zzRefill no longer
* "refills" the buffer (since the way we do it, it's always "full" the first
* time through, since it points to the segment's array). So, we assign
* zzEndRead here.
*/
// zzStartRead = zzEndRead = s.offset;
zzStartRead = s.offset;
@@ -452,34 +437,31 @@ public class DtdTokenMaker extends AbstractJFlexTokenMaker {
zzReader = reader;
zzAtEOF = false;
}
/**
* Creates a new scanner
* There is also a java.io.InputStream version of this constructor.
* Creates a new scanner There is also a java.io.InputStream version of this
* constructor.
*
* @param in
* the java.io.Reader to read input from.
* @param in the java.io.Reader to read input from.
*/
public DtdTokenMaker(java.io.Reader in) {
this.zzReader = in;
}
/**
* Creates a new scanner.
* There is also java.io.Reader version of this constructor.
* Creates a new scanner. There is also java.io.Reader version of this
* constructor.
*
* @param in
* the java.io.Inputstream to read input from.
* @param in the java.io.Inputstream to read input from.
*/
public DtdTokenMaker(java.io.InputStream in) {
this(new java.io.InputStreamReader(in));
}
/**
* Unpacks the compressed character translation table.
*
* @param packed
* the packed character translation table
* @param packed the packed character translation table
* @return the unpacked character translation table
*/
private static char[] zzUnpackCMap(String packed) {
@@ -495,7 +477,7 @@ public class DtdTokenMaker extends AbstractJFlexTokenMaker {
}
return map;
}
/**
* Closes the input stream.
*/
@@ -505,69 +487,64 @@ public class DtdTokenMaker extends AbstractJFlexTokenMaker {
if (zzReader != null)
zzReader.close();
}
/**
* Returns the current lexical state.
*/
public final int yystate() {
return zzLexicalState;
}
/**
* Enters a new lexical state
*
* @param newState
* the new lexical state
* @param newState the new lexical state
*/
@Override
public final void yybegin(int newState) {
zzLexicalState = newState;
}
/**
* Returns the text matched by the current regular expression.
*/
public final String yytext() {
return new String(zzBuffer, zzStartRead, zzMarkedPos - zzStartRead);
}
/**
* Returns the character at position <tt>pos</tt> from the
* matched text.
* Returns the character at position <tt>pos</tt> from the matched text.
*
* It is equivalent to yytext().charAt(pos), but faster
*
* @param pos
* the position of the character to fetch.
* A value from 0 to yylength()-1.
* @param pos the position of the character to fetch. A value from 0 to
* yylength()-1.
*
* @return the character at position pos
*/
public final char yycharat(int pos) {
return zzBuffer[zzStartRead + pos];
}
/**
* Returns the length of the matched text region.
*/
public final int yylength() {
return zzMarkedPos - zzStartRead;
}
/**
* Reports an error that occured while scanning.
*
* In a wellformed scanner (no or only correct usage of
* yypushback(int) and a match-all fallback rule) this method
* will only be called with things that "Can't Possibly Happen".
* If this method is called, something is seriously wrong
* (e.g. a JFlex bug producing a faulty scanner etc.).
* In a wellformed scanner (no or only correct usage of yypushback(int) and a
* match-all fallback rule) this method will only be called with things that
* "Can't Possibly Happen". If this method is called, something is seriously
* wrong (e.g. a JFlex bug producing a faulty scanner etc.).
*
* Usual syntax/scanner level error handling should be done
* in error fallback rules.
* Usual syntax/scanner level error handling should be done in error fallback
* rules.
*
* @param errorCode
* the code of the errormessage to display
* @param errorCode the code of the errormessage to display
*/
private void zzScanError(int errorCode) {
String message;
@@ -578,29 +555,27 @@ public class DtdTokenMaker extends AbstractJFlexTokenMaker {
}
throw new Error(message);
}
/**
* Pushes the specified amount of characters back into the input stream.
*
* They will be read again by then next call of the scanning method
*
* @param number
* the number of characters to be read again.
* This number must not be greater than yylength()!
* @param number the number of characters to be read again. This number must not
* be greater than yylength()!
*/
public void yypushback(int number) {
if (number > yylength())
zzScanError(ZZ_PUSHBACK_2BIG);
zzMarkedPos -= number;
}
/**
* Resumes scanning until the next regular expression is matched,
* the end of input is encountered or an I/O-Error occurs.
* Resumes scanning until the next regular expression is matched, the end of
* input is encountered or an I/O-Error occurs.
*
* @return the next token
* @exception java.io.IOException
* if any I/O-Error occurs
* @exception java.io.IOException if any I/O-Error occurs
*/
public org.fife.ui.rsyntaxtextarea.Token yylex() throws java.io.IOException {
int zzInput;
@@ -619,8 +594,7 @@ public class DtdTokenMaker extends AbstractJFlexTokenMaker {
zzAction = -1;
zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
zzState = zzLexicalState;
zzForAction:
{
zzForAction: {
while (true) {
if (zzCurrentPosL < zzEndReadL)
zzInput = zzBufferL[zzCurrentPosL++];
@@ -660,134 +634,135 @@ public class DtdTokenMaker extends AbstractJFlexTokenMaker {
// store back cached position
zzMarkedPos = zzMarkedPosL;
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
case 3: {
addToken(Token.IDENTIFIER);
}
case 16:
break;
case 2: {
addToken(Token.WHITESPACE);
}
case 17:
break;
case 1: {
/* Not really valid */ addToken(Token.IDENTIFIER);
}
case 18:
break;
case 12: {
int temp = zzStartRead;
addToken(start, zzStartRead - 1, Token.MARKUP_COMMENT);
addHyperlinkToken(temp, zzMarkedPos - 1, Token.MARKUP_COMMENT);
start = zzMarkedPos;
}
case 19:
break;
case 9: {
addToken(Token.MARKUP_TAG_DELIMITER);
yybegin(INTAG_START);
}
case 20:
break;
case 6: {
addToken(Token.MARKUP_TAG_DELIMITER);
yybegin(YYINITIAL);
}
case 21:
break;
case 10: {
int temp = zzMarkedPos;
addToken(start, zzStartRead + 2, Token.MARKUP_COMMENT);
start = temp;
yybegin(prevState);
}
case 22:
break;
case 11: {
start = zzStartRead;
prevState = zzLexicalState;
yybegin(COMMENT);
}
case 23:
break;
case 7: {
addToken(Token.MARKUP_TAG_ATTRIBUTE);
}
case 24:
break;
case 15: {
addToken(Token.MARKUP_TAG_NAME);
yybegin(INTAG_ATTLIST);
}
case 25:
break;
case 14: {
addToken(Token.MARKUP_TAG_NAME);
yybegin(INTAG_ELEMENT);
}
case 26:
break;
case 13: {
addToken(Token.MARKUP_PROCESSING_INSTRUCTION);
}
case 27:
break;
case 4: {}
case 28:
break;
case 5: {
addToken(start, zzStartRead - 1, Token.MARKUP_COMMENT);
addEndToken(INTERNAL_IN_COMMENT - prevState);
return firstToken;
}
case 29:
break;
case 8: {
addToken(Token.MARKUP_TAG_ATTRIBUTE_VALUE);
}
case 30:
break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
switch (zzLexicalState) {
case INTAG_START: {
addEndToken(INTERNAL_INTAG_START);
return firstToken;
}
case 71:
break;
case INTAG_ELEMENT: {
addEndToken(INTERNAL_INTAG_ELEMENT);
return firstToken;
}
case 72:
break;
case YYINITIAL: {
addNullToken();
return firstToken;
}
case 73:
break;
case INTAG_ATTLIST: {
addEndToken(INTERNAL_INTAG_ATTLIST);
return firstToken;
}
case 74:
break;
case COMMENT: {
addToken(start, zzStartRead - 1, Token.MARKUP_COMMENT);
addEndToken(INTERNAL_IN_COMMENT - prevState);
return firstToken;
}
case 75:
break;
default:
return null;
}
} else {
zzScanError(ZZ_NO_MATCH);
case 3: {
addToken(Token.IDENTIFIER);
}
case 16:
break;
case 2: {
addToken(Token.WHITESPACE);
}
case 17:
break;
case 1: {
/* Not really valid */ addToken(Token.IDENTIFIER);
}
case 18:
break;
case 12: {
int temp = zzStartRead;
addToken(start, zzStartRead - 1, Token.MARKUP_COMMENT);
addHyperlinkToken(temp, zzMarkedPos - 1, Token.MARKUP_COMMENT);
start = zzMarkedPos;
}
case 19:
break;
case 9: {
addToken(Token.MARKUP_TAG_DELIMITER);
yybegin(INTAG_START);
}
case 20:
break;
case 6: {
addToken(Token.MARKUP_TAG_DELIMITER);
yybegin(YYINITIAL);
}
case 21:
break;
case 10: {
int temp = zzMarkedPos;
addToken(start, zzStartRead + 2, Token.MARKUP_COMMENT);
start = temp;
yybegin(prevState);
}
case 22:
break;
case 11: {
start = zzStartRead;
prevState = zzLexicalState;
yybegin(COMMENT);
}
case 23:
break;
case 7: {
addToken(Token.MARKUP_TAG_ATTRIBUTE);
}
case 24:
break;
case 15: {
addToken(Token.MARKUP_TAG_NAME);
yybegin(INTAG_ATTLIST);
}
case 25:
break;
case 14: {
addToken(Token.MARKUP_TAG_NAME);
yybegin(INTAG_ELEMENT);
}
case 26:
break;
case 13: {
addToken(Token.MARKUP_PROCESSING_INSTRUCTION);
}
case 27:
break;
case 4: {
}
case 28:
break;
case 5: {
addToken(start, zzStartRead - 1, Token.MARKUP_COMMENT);
addEndToken(INTERNAL_IN_COMMENT - prevState);
return firstToken;
}
case 29:
break;
case 8: {
addToken(Token.MARKUP_TAG_ATTRIBUTE_VALUE);
}
case 30:
break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
switch (zzLexicalState) {
case INTAG_START: {
addEndToken(INTERNAL_INTAG_START);
return firstToken;
}
case 71:
break;
case INTAG_ELEMENT: {
addEndToken(INTERNAL_INTAG_ELEMENT);
return firstToken;
}
case 72:
break;
case YYINITIAL: {
addNullToken();
return firstToken;
}
case 73:
break;
case INTAG_ATTLIST: {
addEndToken(INTERNAL_INTAG_ATTLIST);
return firstToken;
}
case 74:
break;
case COMMENT: {
addToken(start, zzStartRead - 1, Token.MARKUP_COMMENT);
addEndToken(INTERNAL_IN_COMMENT - prevState);
return firstToken;
}
case 75:
break;
default:
return null;
}
} else {
zzScanError(ZZ_NO_MATCH);
}
}
}
}
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -20,16 +20,15 @@ import org.fife.ui.rsyntaxtextarea.TokenImpl;
*
* This implementation was created using
* <a href="http://www.jflex.de/">JFlex</a> 1.4.1; however, the generated file
* was modified for performance. Memory allocation needs to be almost
* completely removed to be competitive with the handwritten lexers (subclasses
* of <code>AbstractTokenMaker</code>, so this class has been modified so that
* was modified for performance. Memory allocation needs to be almost completely
* removed to be competitive with the handwritten lexers (subclasses of
* <code>AbstractTokenMaker</code>, so this class has been modified so that
* Strings are never allocated (via yytext()), and the scanner never has to
* worry about refilling its buffer (needlessly copying chars around).
* We can achieve this because RText always scans exactly 1 line of tokens at a
* time, and hands the scanner this line as an array of characters (a Segment
* really). Since tokens contain pointers to char arrays instead of Strings
* holding their contents, there is no need for allocating new memory for
* Strings.
* worry about refilling its buffer (needlessly copying chars around). We can
* achieve this because RText always scans exactly 1 line of tokens at a time,
* and hands the scanner this line as an array of characters (a Segment really).
* Since tokens contain pointers to char arrays instead of Strings holding their
* contents, there is no need for allocating new memory for Strings.
* <p>
*
* The actual algorithm generated for scanning has, of course, not been
@@ -39,16 +38,16 @@ import org.fife.ui.rsyntaxtextarea.TokenImpl;
* If you wish to regenerate this file yourself, keep in mind the following:
* <ul>
* <li>The generated <code>HostsTokenMaker.java</code> file will contain two
* definitions of both <code>zzRefill</code> and <code>yyreset</code>.
* You should hand-delete the second of each definition (the ones
* generated by the lexer), as these generated methods modify the input
* buffer, which we'll never have to do.</li>
* <li>You should also change the declaration/definition of zzBuffer to NOT
* be initialized. This is a needless memory allocation for us since we
* will be pointing the array somewhere else anyway.</li>
* definitions of both <code>zzRefill</code> and <code>yyreset</code>. You
* should hand-delete the second of each definition (the ones generated by the
* lexer), as these generated methods modify the input buffer, which we'll never
* have to do.</li>
* <li>You should also change the declaration/definition of zzBuffer to NOT be
* initialized. This is a needless memory allocation for us since we will be
* pointing the array somewhere else anyway.</li>
* <li>You should NOT call <code>yylex()</code> on the generated scanner
* directly; rather, you should use <code>getTokenList</code> as you would
* with any other <code>TokenMaker</code> instance.</li>
* directly; rather, you should use <code>getTokenList</code> as you would with
* any other <code>TokenMaker</code> instance.</li>
* </ul>
*
* @author Robert Futrell
@@ -56,7 +55,7 @@ import org.fife.ui.rsyntaxtextarea.TokenImpl;
*
*/
public class HostsTokenMaker extends AbstractJFlexTokenMaker {
/** This character denotes the end of file */
public static final int YYEOF = -1;
/** lexical states */
@@ -77,14 +76,14 @@ public class HostsTokenMaker extends AbstractJFlexTokenMaker {
*/
private static final int[] ZZ_ACTION = zzUnpackAction();
private static final String ZZ_ACTION_PACKED_0 = "\2\0\1\1\1\2\1\3\1\4\1\5\1\6\3\5" + "\12\0\1\7\2\0";
private static int[] zzUnpackAction() {
int[] result = new int[24];
int offset = 0;
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAction(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -98,21 +97,22 @@ public class HostsTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/**
* Translates a state to a row index in the transition table
*/
private static final int[] ZZ_ROWMAP = zzUnpackRowMap();
private static final String ZZ_ROWMAP_PACKED_0 = "\0\0\0\22\0\44\0\66\0\110\0\66\0\132\0\66"
+ "\0\154\0\176\0\220\0\242\0\264\0\306\0\330\0\352" + "\0\374\0\u010e\0\u0120\0\u0132\0\u0144\0\u0156\0\u0168\0\u0156";
+ "\0\154\0\176\0\220\0\242\0\264\0\306\0\330\0\352"
+ "\0\374\0\u010e\0\u0120\0\u0132\0\u0144\0\u0156\0\u0168\0\u0156";
private static int[] zzUnpackRowMap() {
int[] result = new int[24];
int offset = 0;
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
return result;
}
private static int zzUnpackRowMap(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -123,23 +123,24 @@ public class HostsTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/**
* The transition table of the DFA
*/
private static final int[] ZZ_TRANS = zzUnpackTrans();
private static final String ZZ_TRANS_PACKED_0 = "\1\3\1\4\1\5\1\6\16\3\1\7\1\10\5\7" + "\1\11\3\7\1\12\4\7\1\13\1\7\1\3\3\0"
+ "\16\3\24\0\1\5\17\0\1\7\1\0\5\7\1\0" + "\3\7\1\0\4\7\1\0\1\7\10\0\1\14\21\0" + "\1\15\3\0\1\16\25\0\1\17\11\0\1\20\22\0"
private static final String ZZ_TRANS_PACKED_0 = "\1\3\1\4\1\5\1\6\16\3\1\7\1\10\5\7"
+ "\1\11\3\7\1\12\4\7\1\13\1\7\1\3\3\0" + "\16\3\24\0\1\5\17\0\1\7\1\0\5\7\1\0"
+ "\3\7\1\0\4\7\1\0\1\7\10\0\1\14\21\0" + "\1\15\3\0\1\16\25\0\1\17\11\0\1\20\22\0"
+ "\1\21\25\0\1\22\24\0\1\23\12\0\1\24\27\0" + "\1\25\20\0\1\21\24\0\1\26\12\0\1\21\4\0"
+ "\1\25\7\0\1\27\17\0\2\30\12\26\1\30\1\26" + "\1\30\5\0\1\26\14\0";
private static int[] zzUnpackTrans() {
int[] result = new int[378];
int offset = 0;
offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
return result;
}
private static int zzUnpackTrans(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -154,7 +155,7 @@ public class HostsTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/* error codes */
private static final int ZZ_UNKNOWN_ERROR = 0;
private static final int ZZ_NO_MATCH = 1;
@@ -167,14 +168,14 @@ public class HostsTokenMaker extends AbstractJFlexTokenMaker {
*/
private static final int[] ZZ_ATTRIBUTE = zzUnpackAttribute();
private static final String ZZ_ATTRIBUTE_PACKED_0 = "\2\0\1\1\1\11\1\1\1\11\1\1\1\11\3\1" + "\12\0\1\1\2\0";
private static int[] zzUnpackAttribute() {
int[] result = new int[24];
int offset = 0;
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAttribute(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -188,7 +189,7 @@ public class HostsTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/** the input device */
private java.io.Reader zzReader;
/** the current state of the DFA */
@@ -196,8 +197,8 @@ public class HostsTokenMaker extends AbstractJFlexTokenMaker {
/** the current lexical state */
private int zzLexicalState = YYINITIAL;
/**
* this buffer contains the current text to be matched and is
* the source of the yytext() string
* this buffer contains the current text to be matched and is the source of the
* yytext() string
*/
private char zzBuffer[];
/** the textposition at the last accepting state */
@@ -207,8 +208,7 @@ public class HostsTokenMaker extends AbstractJFlexTokenMaker {
/** startRead marks the beginning of the yytext() string in the buffer */
private int zzStartRead;
/**
* endRead marks the last character in the buffer, that has been read
* from input
* endRead marks the last character in the buffer, that has been read from input
*/
private int zzEndRead;
/** zzAtEOF == true <=> the scanner is at the EOF */
@@ -218,67 +218,59 @@ public class HostsTokenMaker extends AbstractJFlexTokenMaker {
* Whether or not this is the first token on a line.
*/
private boolean first;
/**
* Constructor. This must be here because JFlex does not generate a
* no-parameter constructor.
* Constructor. This must be here because JFlex does not generate a no-parameter
* constructor.
*/
public HostsTokenMaker() {}
public HostsTokenMaker() {
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType
* The token's type.
* @param tokenType The token's type.
* @see #addToken(int, int, int)
*/
private void addHyperlinkToken(int start, int end, int tokenType) {
int so = start + offsetShift;
addToken(zzBuffer, start, end, tokenType, so, true);
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType
* The token's type.
* @param tokenType The token's type.
*/
private void addToken(int tokenType) {
addToken(zzStartRead, zzMarkedPos - 1, tokenType);
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType
* The token's type.
* @param tokenType The token's type.
*/
private void addToken(int start, int end, int tokenType) {
int so = start + offsetShift;
addToken(zzBuffer, start, end, tokenType, so);
}
/**
* 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 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.
*/
@Override
public void addToken(char[] array, int start, int end, int tokenType, int startOffset) {
super.addToken(array, start, end, tokenType, startOffset);
zzStartRead = zzMarkedPos;
}
/**
* {@inheritDoc}
*/
@@ -286,7 +278,7 @@ public class HostsTokenMaker extends AbstractJFlexTokenMaker {
public String[] getLineCommentStartAndEnd(int languageIndex) {
return new String[] { "#", null };
}
/**
* {@inheritDoc}
*/
@@ -294,21 +286,18 @@ public class HostsTokenMaker extends AbstractJFlexTokenMaker {
public boolean getMarkOccurrencesOfTokenType(int type) {
return type == Token.RESERVED_WORD;
}
/**
* Returns the first token in the linked list of tokens generated
* from <code>text</code>. This method must be implemented by
* subclasses so they can correctly implement syntax highlighting.
* Returns the first token in the linked list of tokens generated from
* <code>text</code>. This method must be implemented by subclasses so they can
* correctly implement syntax highlighting.
*
* @param text
* The text from which to get tokens.
* @param initialTokenType
* The token type we should start with.
* @param startOffset
* The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing
* the syntax highlighted text.
* @param text The text from which to get tokens.
* @param initialTokenType The token type we should start with.
* @param startOffset The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing the syntax
* highlighted text.
*/
@Override
public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
@@ -327,36 +316,34 @@ public class HostsTokenMaker extends AbstractJFlexTokenMaker {
return new TokenImpl();
}
}
/**
* Refills the input buffer.
*
* @return <code>true</code> if EOF was reached, otherwise
* <code>false</code>.
* @return <code>true</code> if EOF was reached, otherwise <code>false</code>.
*/
private boolean zzRefill() {
return zzCurrentPos >= s.offset + s.count;
}
/**
* Resets the scanner to read from a new input stream.
* Does not close the old reader.
* Resets the scanner to read from a new input stream. Does not close the old
* reader.
*
* All internal variables are reset, the old input stream
* <b>cannot</b> be reused (internal buffer is discarded and lost).
* Lexical state is set to <tt>YY_INITIAL</tt>.
* All internal variables are reset, the old input stream <b>cannot</b> be
* reused (internal buffer is discarded and lost). Lexical state is set to
* <tt>YY_INITIAL</tt>.
*
* @param reader
* the new input stream
* @param reader the new input stream
*/
public final void yyreset(java.io.Reader reader) {
// 's' has been updated.
zzBuffer = s.array;
/*
* We replaced the line below with the two below it because zzRefill
* no longer "refills" the buffer (since the way we do it, it's always
* "full" the first time through, since it points to the segment's
* array). So, we assign zzEndRead here.
* We replaced the line below with the two below it because zzRefill no longer
* "refills" the buffer (since the way we do it, it's always "full" the first
* time through, since it points to the segment's array). So, we assign
* zzEndRead here.
*/
// zzStartRead = zzEndRead = s.offset;
zzStartRead = s.offset;
@@ -366,34 +353,31 @@ public class HostsTokenMaker extends AbstractJFlexTokenMaker {
zzReader = reader;
zzAtEOF = false;
}
/**
* Creates a new scanner
* There is also a java.io.InputStream version of this constructor.
* Creates a new scanner There is also a java.io.InputStream version of this
* constructor.
*
* @param in
* the java.io.Reader to read input from.
* @param in the java.io.Reader to read input from.
*/
public HostsTokenMaker(java.io.Reader in) {
this.zzReader = in;
}
/**
* Creates a new scanner.
* There is also java.io.Reader version of this constructor.
* Creates a new scanner. There is also java.io.Reader version of this
* constructor.
*
* @param in
* the java.io.Inputstream to read input from.
* @param in the java.io.Inputstream to read input from.
*/
public HostsTokenMaker(java.io.InputStream in) {
this(new java.io.InputStreamReader(in));
}
/**
* Unpacks the compressed character translation table.
*
* @param packed
* the packed character translation table
* @param packed the packed character translation table
* @return the unpacked character translation table
*/
private static char[] zzUnpackCMap(String packed) {
@@ -409,7 +393,7 @@ public class HostsTokenMaker extends AbstractJFlexTokenMaker {
}
return map;
}
/**
* Closes the input stream.
*/
@@ -419,69 +403,64 @@ public class HostsTokenMaker extends AbstractJFlexTokenMaker {
if (zzReader != null)
zzReader.close();
}
/**
* Returns the current lexical state.
*/
public final int yystate() {
return zzLexicalState;
}
/**
* Enters a new lexical state
*
* @param newState
* the new lexical state
* @param newState the new lexical state
*/
@Override
public final void yybegin(int newState) {
zzLexicalState = newState;
}
/**
* Returns the text matched by the current regular expression.
*/
public final String yytext() {
return new String(zzBuffer, zzStartRead, zzMarkedPos - zzStartRead);
}
/**
* Returns the character at position <tt>pos</tt> from the
* matched text.
* Returns the character at position <tt>pos</tt> from the matched text.
*
* It is equivalent to yytext().charAt(pos), but faster
*
* @param pos
* the position of the character to fetch.
* A value from 0 to yylength()-1.
* @param pos the position of the character to fetch. A value from 0 to
* yylength()-1.
*
* @return the character at position pos
*/
public final char yycharat(int pos) {
return zzBuffer[zzStartRead + pos];
}
/**
* Returns the length of the matched text region.
*/
public final int yylength() {
return zzMarkedPos - zzStartRead;
}
/**
* Reports an error that occured while scanning.
*
* In a wellformed scanner (no or only correct usage of
* yypushback(int) and a match-all fallback rule) this method
* will only be called with things that "Can't Possibly Happen".
* If this method is called, something is seriously wrong
* (e.g. a JFlex bug producing a faulty scanner etc.).
* In a wellformed scanner (no or only correct usage of yypushback(int) and a
* match-all fallback rule) this method will only be called with things that
* "Can't Possibly Happen". If this method is called, something is seriously
* wrong (e.g. a JFlex bug producing a faulty scanner etc.).
*
* Usual syntax/scanner level error handling should be done
* in error fallback rules.
* Usual syntax/scanner level error handling should be done in error fallback
* rules.
*
* @param errorCode
* the code of the errormessage to display
* @param errorCode the code of the errormessage to display
*/
private void zzScanError(int errorCode) {
String message;
@@ -492,29 +471,27 @@ public class HostsTokenMaker extends AbstractJFlexTokenMaker {
}
throw new Error(message);
}
/**
* Pushes the specified amount of characters back into the input stream.
*
* They will be read again by then next call of the scanning method
*
* @param number
* the number of characters to be read again.
* This number must not be greater than yylength()!
* @param number the number of characters to be read again. This number must not
* be greater than yylength()!
*/
public void yypushback(int number) {
if (number > yylength())
zzScanError(ZZ_PUSHBACK_2BIG);
zzMarkedPos -= number;
}
/**
* Resumes scanning until the next regular expression is matched,
* the end of input is encountered or an I/O-Error occurs.
* Resumes scanning until the next regular expression is matched, the end of
* input is encountered or an I/O-Error occurs.
*
* @return the next token
* @exception java.io.IOException
* if any I/O-Error occurs
* @exception java.io.IOException if any I/O-Error occurs
*/
public org.fife.ui.rsyntaxtextarea.Token yylex() throws java.io.IOException {
int zzInput;
@@ -533,8 +510,7 @@ public class HostsTokenMaker extends AbstractJFlexTokenMaker {
zzAction = -1;
zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
zzState = zzLexicalState;
zzForAction:
{
zzForAction: {
while (true) {
if (zzCurrentPosL < zzEndReadL)
zzInput = zzBufferL[zzCurrentPosL++];
@@ -574,70 +550,71 @@ public class HostsTokenMaker extends AbstractJFlexTokenMaker {
// store back cached position
zzMarkedPos = zzMarkedPosL;
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
case 2: {
addNullToken();
return firstToken;
}
case 8:
break;
case 7: {
int temp = zzStartRead;
addToken(start, zzStartRead - 1, Token.COMMENT_EOL);
addHyperlinkToken(temp, zzMarkedPos - 1, Token.COMMENT_EOL);
start = zzMarkedPos;
}
case 9:
break;
case 4: {
start = zzMarkedPos - 1;
yybegin(EOL_COMMENT);
}
case 10:
break;
case 3: {
addToken(Token.WHITESPACE);
}
case 11:
break;
case 6: {
addToken(start, zzStartRead - 1, Token.COMMENT_EOL);
addNullToken();
return firstToken;
}
case 12:
break;
case 1: {
addToken(first ? Token.RESERVED_WORD : Token.IDENTIFIER);
first = false;
}
case 13:
break;
case 5: {}
case 14:
break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
switch (zzLexicalState) {
case EOL_COMMENT: {
addToken(start, zzStartRead - 1, Token.COMMENT_EOL);
addNullToken();
return firstToken;
}
case 25:
break;
case YYINITIAL: {
addNullToken();
return firstToken;
}
case 26:
break;
default:
return null;
}
} else {
zzScanError(ZZ_NO_MATCH);
case 2: {
addNullToken();
return firstToken;
}
case 8:
break;
case 7: {
int temp = zzStartRead;
addToken(start, zzStartRead - 1, Token.COMMENT_EOL);
addHyperlinkToken(temp, zzMarkedPos - 1, Token.COMMENT_EOL);
start = zzMarkedPos;
}
case 9:
break;
case 4: {
start = zzMarkedPos - 1;
yybegin(EOL_COMMENT);
}
case 10:
break;
case 3: {
addToken(Token.WHITESPACE);
}
case 11:
break;
case 6: {
addToken(start, zzStartRead - 1, Token.COMMENT_EOL);
addNullToken();
return firstToken;
}
case 12:
break;
case 1: {
addToken(first ? Token.RESERVED_WORD : Token.IDENTIFIER);
first = false;
}
case 13:
break;
case 5: {
}
case 14:
break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
switch (zzLexicalState) {
case EOL_COMMENT: {
addToken(start, zzStartRead - 1, Token.COMMENT_EOL);
addNullToken();
return firstToken;
}
case 25:
break;
case YYINITIAL: {
addNullToken();
return firstToken;
}
case 26:
break;
default:
return null;
}
} else {
zzScanError(ZZ_NO_MATCH);
}
}
}
}
File diff suppressed because it is too large. Load diff
@@ -22,16 +22,15 @@ import org.fife.ui.rsyntaxtextarea.TokenImpl;
*
* This implementation was created using
* <a href="http://www.jflex.de/">JFlex</a> 1.4.1; however, the generated file
* was modified for performance. Memory allocation needs to be almost
* completely removed to be competitive with the handwritten lexers (subclasses
* of <code>AbstractTokenMaker</code>, so this class has been modified so that
* was modified for performance. Memory allocation needs to be almost completely
* removed to be competitive with the handwritten lexers (subclasses of
* <code>AbstractTokenMaker</code>, so this class has been modified so that
* Strings are never allocated (via yytext()), and the scanner never has to
* worry about refilling its buffer (needlessly copying chars around).
* We can achieve this because RText always scans exactly 1 line of tokens at a
* time, and hands the scanner this line as an array of characters (a Segment
* really). Since tokens contain pointers to char arrays instead of Strings
* holding their contents, there is no need for allocating new memory for
* Strings.
* worry about refilling its buffer (needlessly copying chars around). We can
* achieve this because RText always scans exactly 1 line of tokens at a time,
* and hands the scanner this line as an array of characters (a Segment really).
* Since tokens contain pointers to char arrays instead of Strings holding their
* contents, there is no need for allocating new memory for Strings.
* <p>
*
* The actual algorithm generated for scanning has, of course, not been
@@ -40,17 +39,17 @@ import org.fife.ui.rsyntaxtextarea.TokenImpl;
*
* If you wish to regenerate this file yourself, keep in mind the following:
* <ul>
* <li>The generated <code>IniTokenMaker.java</code> file will
* contain two definitions of both <code>zzRefill</code> and
* <code>yyreset</code>. You should hand-delete the second of each
* definition (the ones generated by the lexer), as these generated
* methods modify the input buffer, which we'll never have to do.
* <li>You should also change the declaration/definition of zzBuffer to NOT
* be initialized. This is a needless memory allocation for us since we
* will be pointing the array somewhere else anyway.
* <li>The generated <code>IniTokenMaker.java</code> file will contain two
* definitions of both <code>zzRefill</code> and <code>yyreset</code>. You
* should hand-delete the second of each definition (the ones generated by the
* lexer), as these generated methods modify the input buffer, which we'll never
* have to do.
* <li>You should also change the declaration/definition of zzBuffer to NOT be
* initialized. This is a needless memory allocation for us since we will be
* pointing the array somewhere else anyway.
* <li>You should NOT call <code>yylex()</code> on the generated scanner
* directly; rather, you should use <code>getTokenList</code> as you would
* with any other <code>TokenMaker</code> instance.
* directly; rather, you should use <code>getTokenList</code> as you would with
* any other <code>TokenMaker</code> instance.
* </ul>
*
* @author Robert Futrell
@@ -58,7 +57,7 @@ import org.fife.ui.rsyntaxtextarea.TokenImpl;
*
*/
public class IniTokenMaker extends AbstractJFlexTokenMaker {
/** This character denotes the end of file */
public static final int YYEOF = -1;
/** lexical states */
@@ -67,7 +66,8 @@ public class IniTokenMaker extends AbstractJFlexTokenMaker {
/**
* Translates characters to character classes
*/
private static final String ZZ_CMAP_PACKED = "\11\0\1\3\1\5\25\0\1\3\2\0\1\4\27\0\1\4\1\0" + "\1\1\35\0\1\2\1\0\1\6\uffa2\0";
private static final String ZZ_CMAP_PACKED = "\11\0\1\3\1\5\25\0\1\3\2\0\1\4\27\0\1\4\1\0"
+ "\1\1\35\0\1\2\1\0\1\6\uffa2\0";
/**
* Translates characters to character classes
*/
@@ -77,14 +77,14 @@ public class IniTokenMaker extends AbstractJFlexTokenMaker {
*/
private static final int[] ZZ_ACTION = zzUnpackAction();
private static final String ZZ_ACTION_PACKED_0 = "\1\1\1\2\1\1\1\3\1\4\1\5\1\6\1\2" + "\1\7\1\4";
private static int[] zzUnpackAction() {
int[] result = new int[10];
int offset = 0;
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAction(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -98,20 +98,20 @@ public class IniTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/**
* Translates a state to a row index in the transition table
*/
private static final int[] ZZ_ROWMAP = zzUnpackRowMap();
private static final String ZZ_ROWMAP_PACKED_0 = "\0\0\0\7\0\16\0\25\0\34\0\43\0\52\0\61" + "\0\25\0\25";
private static int[] zzUnpackRowMap() {
int[] result = new int[10];
int offset = 0;
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
return result;
}
private static int zzUnpackRowMap(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -122,21 +122,21 @@ public class IniTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/**
* The transition table of the DFA
*/
private static final int[] ZZ_TRANS = zzUnpackTrans();
private static final String ZZ_TRANS_PACKED_0 = "\1\3\1\4\1\5\1\6\1\7\1\0\1\3\1\10" + "\1\11\1\5\1\6\1\7\1\0\1\10\1\3\5\0"
+ "\1\3\7\0\6\5\1\12\3\0\1\6\3\0\5\7" + "\1\0\1\7\1\10\5\0\1\10";
private static final String ZZ_TRANS_PACKED_0 = "\1\3\1\4\1\5\1\6\1\7\1\0\1\3\1\10"
+ "\1\11\1\5\1\6\1\7\1\0\1\10\1\3\5\0" + "\1\3\7\0\6\5\1\12\3\0\1\6\3\0\5\7" + "\1\0\1\7\1\10\5\0\1\10";
private static int[] zzUnpackTrans() {
int[] result = new int[56];
int offset = 0;
offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
return result;
}
private static int zzUnpackTrans(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -151,7 +151,7 @@ public class IniTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/* error codes */
private static final int ZZ_UNKNOWN_ERROR = 0;
private static final int ZZ_NO_MATCH = 1;
@@ -164,14 +164,14 @@ public class IniTokenMaker extends AbstractJFlexTokenMaker {
*/
private static final int[] ZZ_ATTRIBUTE = zzUnpackAttribute();
private static final String ZZ_ATTRIBUTE_PACKED_0 = "\3\1\1\11\4\1\2\11";
private static int[] zzUnpackAttribute() {
int[] result = new int[10];
int offset = 0;
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAttribute(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -185,7 +185,7 @@ public class IniTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/** the input device */
private java.io.Reader zzReader;
/** the current state of the DFA */
@@ -193,8 +193,8 @@ public class IniTokenMaker extends AbstractJFlexTokenMaker {
/** the current lexical state */
private int zzLexicalState = YYINITIAL;
/**
* this buffer contains the current text to be matched and is
* the source of the yytext() string
* this buffer contains the current text to be matched and is the source of the
* yytext() string
*/
private char zzBuffer[];
/** the textposition at the last accepting state */
@@ -204,64 +204,55 @@ public class IniTokenMaker extends AbstractJFlexTokenMaker {
/** startRead marks the beginning of the yytext() string in the buffer */
private int zzStartRead;
/**
* endRead marks the last character in the buffer, that has been read
* from input
* endRead marks the last character in the buffer, that has been read from input
*/
private int zzEndRead;
/** zzAtEOF == true <=> the scanner is at the EOF */
private boolean zzAtEOF;
/* user code: */
/**
* Constructor. This must be here because JFlex does not generate a
* no-parameter constructor.
* Constructor. This must be here because JFlex does not generate a no-parameter
* constructor.
*/
public IniTokenMaker() {
super();
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType
* The token's type.
* @param tokenType The token's type.
*/
private void addToken(int tokenType) {
addToken(zzStartRead, zzMarkedPos - 1, tokenType);
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType
* The token's type.
* @param tokenType The token's type.
*/
private void addToken(int start, int end, int tokenType) {
int so = start + offsetShift;
addToken(zzBuffer, start, end, tokenType, so);
}
/**
* 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 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.
*/
@Override
public void addToken(char[] array, int start, int end, int tokenType, int startOffset) {
super.addToken(array, start, end, tokenType, startOffset);
zzStartRead = zzMarkedPos;
}
/**
* {@inheritDoc}
*/
@@ -269,21 +260,18 @@ public class IniTokenMaker extends AbstractJFlexTokenMaker {
public String[] getLineCommentStartAndEnd(int languageIndex) {
return new String[] { ";", null };
}
/**
* Returns the first token in the linked list of tokens generated
* from <code>text</code>. This method must be implemented by
* subclasses so they can correctly implement syntax highlighting.
* Returns the first token in the linked list of tokens generated from
* <code>text</code>. This method must be implemented by subclasses so they can
* correctly implement syntax highlighting.
*
* @param text
* The text from which to get tokens.
* @param initialTokenType
* The token type we should start with.
* @param startOffset
* The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing
* the syntax highlighted text.
* @param text The text from which to get tokens.
* @param initialTokenType The token type we should start with.
* @param startOffset The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing the syntax
* highlighted text.
*/
@Override
public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
@@ -301,36 +289,34 @@ public class IniTokenMaker extends AbstractJFlexTokenMaker {
return new TokenImpl();
}
}
/**
* Refills the input buffer.
*
* @return <code>true</code> if EOF was reached, otherwise
* <code>false</code>.
* @return <code>true</code> if EOF was reached, otherwise <code>false</code>.
*/
private boolean zzRefill() {
return zzCurrentPos >= s.offset + s.count;
}
/**
* Resets the scanner to read from a new input stream.
* Does not close the old reader.
* Resets the scanner to read from a new input stream. Does not close the old
* reader.
*
* All internal variables are reset, the old input stream
* <b>cannot</b> be reused (internal buffer is discarded and lost).
* Lexical state is set to <tt>YY_INITIAL</tt>.
* All internal variables are reset, the old input stream <b>cannot</b> be
* reused (internal buffer is discarded and lost). Lexical state is set to
* <tt>YY_INITIAL</tt>.
*
* @param reader
* the new input stream
* @param reader the new input stream
*/
public final void yyreset(Reader reader) {
// 's' has been updated.
zzBuffer = s.array;
/*
* We replaced the line below with the two below it because zzRefill
* no longer "refills" the buffer (since the way we do it, it's always
* "full" the first time through, since it points to the segment's
* array). So, we assign zzEndRead here.
* We replaced the line below with the two below it because zzRefill no longer
* "refills" the buffer (since the way we do it, it's always "full" the first
* time through, since it points to the segment's array). So, we assign
* zzEndRead here.
*/
// zzStartRead = zzEndRead = s.offset;
zzStartRead = s.offset;
@@ -340,34 +326,31 @@ public class IniTokenMaker extends AbstractJFlexTokenMaker {
zzReader = reader;
zzAtEOF = false;
}
/**
* Creates a new scanner
* There is also a java.io.InputStream version of this constructor.
* Creates a new scanner There is also a java.io.InputStream version of this
* constructor.
*
* @param in
* the java.io.Reader to read input from.
* @param in the java.io.Reader to read input from.
*/
public IniTokenMaker(java.io.Reader in) {
this.zzReader = in;
}
/**
* Creates a new scanner.
* There is also java.io.Reader version of this constructor.
* Creates a new scanner. There is also java.io.Reader version of this
* constructor.
*
* @param in
* the java.io.Inputstream to read input from.
* @param in the java.io.Inputstream to read input from.
*/
public IniTokenMaker(java.io.InputStream in) {
this(new java.io.InputStreamReader(in));
}
/**
* Unpacks the compressed character translation table.
*
* @param packed
* the packed character translation table
* @param packed the packed character translation table
* @return the unpacked character translation table
*/
private static char[] zzUnpackCMap(String packed) {
@@ -383,7 +366,7 @@ public class IniTokenMaker extends AbstractJFlexTokenMaker {
}
return map;
}
/**
* Closes the input stream.
*/
@@ -393,69 +376,64 @@ public class IniTokenMaker extends AbstractJFlexTokenMaker {
if (zzReader != null)
zzReader.close();
}
/**
* Returns the current lexical state.
*/
public final int yystate() {
return zzLexicalState;
}
/**
* Enters a new lexical state
*
* @param newState
* the new lexical state
* @param newState the new lexical state
*/
@Override
public final void yybegin(int newState) {
zzLexicalState = newState;
}
/**
* Returns the text matched by the current regular expression.
*/
public final String yytext() {
return new String(zzBuffer, zzStartRead, zzMarkedPos - zzStartRead);
}
/**
* Returns the character at position <tt>pos</tt> from the
* matched text.
* Returns the character at position <tt>pos</tt> from the matched text.
*
* It is equivalent to yytext().charAt(pos), but faster
*
* @param pos
* the position of the character to fetch.
* A value from 0 to yylength()-1.
* @param pos the position of the character to fetch. A value from 0 to
* yylength()-1.
*
* @return the character at position pos
*/
public final char yycharat(int pos) {
return zzBuffer[zzStartRead + pos];
}
/**
* Returns the length of the matched text region.
*/
public final int yylength() {
return zzMarkedPos - zzStartRead;
}
/**
* Reports an error that occured while scanning.
*
* In a wellformed scanner (no or only correct usage of
* yypushback(int) and a match-all fallback rule) this method
* will only be called with things that "Can't Possibly Happen".
* If this method is called, something is seriously wrong
* (e.g. a JFlex bug producing a faulty scanner etc.).
* In a wellformed scanner (no or only correct usage of yypushback(int) and a
* match-all fallback rule) this method will only be called with things that
* "Can't Possibly Happen". If this method is called, something is seriously
* wrong (e.g. a JFlex bug producing a faulty scanner etc.).
*
* Usual syntax/scanner level error handling should be done
* in error fallback rules.
* Usual syntax/scanner level error handling should be done in error fallback
* rules.
*
* @param errorCode
* the code of the errormessage to display
* @param errorCode the code of the errormessage to display
*/
private void zzScanError(int errorCode) {
String message;
@@ -466,29 +444,27 @@ public class IniTokenMaker extends AbstractJFlexTokenMaker {
}
throw new Error(message);
}
/**
* Pushes the specified amount of characters back into the input stream.
*
* They will be read again by then next call of the scanning method
*
* @param number
* the number of characters to be read again.
* This number must not be greater than yylength()!
* @param number the number of characters to be read again. This number must not
* be greater than yylength()!
*/
public void yypushback(int number) {
if (number > yylength())
zzScanError(ZZ_PUSHBACK_2BIG);
zzMarkedPos -= number;
}
/**
* Resumes scanning until the next regular expression is matched,
* the end of input is encountered or an I/O-Error occurs.
* Resumes scanning until the next regular expression is matched, the end of
* input is encountered or an I/O-Error occurs.
*
* @return the next token
* @exception java.io.IOException
* if any I/O-Error occurs
* @exception java.io.IOException if any I/O-Error occurs
*/
public org.fife.ui.rsyntaxtextarea.Token yylex() throws java.io.IOException {
int zzInput;
@@ -507,8 +483,7 @@ public class IniTokenMaker extends AbstractJFlexTokenMaker {
zzAction = -1;
zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
zzState = zzLexicalState;
zzForAction:
{
zzForAction: {
while (true) {
if (zzCurrentPosL < zzEndReadL)
zzInput = zzBufferL[zzCurrentPosL++];
@@ -548,66 +523,66 @@ public class IniTokenMaker extends AbstractJFlexTokenMaker {
// store back cached position
zzMarkedPos = zzMarkedPosL;
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
case 3: {
start = zzMarkedPos;
addToken(Token.OPERATOR);
yybegin(VALUE);
}
case 8:
break;
case 2: {
addToken(Token.IDENTIFIER);
}
case 9:
break;
case 5: {
addToken(Token.WHITESPACE);
}
case 10:
break;
case 7: {
start = zzMarkedPos;
addToken(Token.OPERATOR);
}
case 11:
break;
case 6: {
addToken(Token.COMMENT_EOL);
}
case 12:
break;
case 4: {
addToken(Token.PREPROCESSOR);
}
case 13:
break;
case 1: {
addToken(Token.DATA_TYPE);
}
case 14:
break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
switch (zzLexicalState) {
case YYINITIAL: {
addNullToken();
return firstToken;
}
case 11:
break;
case VALUE: {
addNullToken();
return firstToken;
}
case 12:
break;
default:
return null;
}
} else {
zzScanError(ZZ_NO_MATCH);
case 3: {
start = zzMarkedPos;
addToken(Token.OPERATOR);
yybegin(VALUE);
}
case 8:
break;
case 2: {
addToken(Token.IDENTIFIER);
}
case 9:
break;
case 5: {
addToken(Token.WHITESPACE);
}
case 10:
break;
case 7: {
start = zzMarkedPos;
addToken(Token.OPERATOR);
}
case 11:
break;
case 6: {
addToken(Token.COMMENT_EOL);
}
case 12:
break;
case 4: {
addToken(Token.PREPROCESSOR);
}
case 13:
break;
case 1: {
addToken(Token.DATA_TYPE);
}
case 14:
break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
switch (zzLexicalState) {
case YYINITIAL: {
addNullToken();
return firstToken;
}
case 11:
break;
case VALUE: {
addNullToken();
return firstToken;
}
case 12:
break;
default:
return null;
}
} else {
zzScanError(ZZ_NO_MATCH);
}
}
}
}
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -14,7 +14,7 @@ package org.fife.ui.rsyntaxtextarea.modes;
* @version 1.0
*/
public class JshintrcTokenMaker extends JsonTokenMaker {
/**
* Constructor; overridden to enable highlighting of EOL comments.
*/
@@ -22,16 +22,15 @@ import org.fife.ui.rsyntaxtextarea.TokenImpl;
*
* This implementation was created using
* <a href="http://www.jflex.de/">JFlex</a> 1.4.1; however, the generated file
* was modified for performance. Memory allocation needs to be almost
* completely removed to be competitive with the handwritten lexers (subclasses
* of <code>AbstractTokenMaker</code>, so this class has been modified so that
* was modified for performance. Memory allocation needs to be almost completely
* removed to be competitive with the handwritten lexers (subclasses of
* <code>AbstractTokenMaker</code>, so this class has been modified so that
* Strings are never allocated (via yytext()), and the scanner never has to
* worry about refilling its buffer (needlessly copying chars around).
* We can achieve this because RText always scans exactly 1 line of tokens at a
* time, and hands the scanner this line as an array of characters (a Segment
* really). Since tokens contain pointers to char arrays instead of Strings
* holding their contents, there is no need for allocating new memory for
* Strings.
* worry about refilling its buffer (needlessly copying chars around). We can
* achieve this because RText always scans exactly 1 line of tokens at a time,
* and hands the scanner this line as an array of characters (a Segment really).
* Since tokens contain pointers to char arrays instead of Strings holding their
* contents, there is no need for allocating new memory for Strings.
* <p>
*
* The actual algorithm generated for scanning has, of course, not been
@@ -41,16 +40,16 @@ import org.fife.ui.rsyntaxtextarea.TokenImpl;
* If you wish to regenerate this file yourself, keep in mind the following:
* <ul>
* <li>The generated <code>JsonTokenMaker.java</code> file will contain two
* definitions of both <code>zzRefill</code> and <code>yyreset</code>.
* You should hand-delete the second of each definition (the ones
* generated by the lexer), as these generated methods modify the input
* buffer, which we'll never have to do.</li>
* <li>You should also change the declaration/definition of zzBuffer to NOT
* be initialized. This is a needless memory allocation for us since we
* will be pointing the array somewhere else anyway.</li>
* definitions of both <code>zzRefill</code> and <code>yyreset</code>. You
* should hand-delete the second of each definition (the ones generated by the
* lexer), as these generated methods modify the input buffer, which we'll never
* have to do.</li>
* <li>You should also change the declaration/definition of zzBuffer to NOT be
* initialized. This is a needless memory allocation for us since we will be
* pointing the array somewhere else anyway.</li>
* <li>You should NOT call <code>yylex()</code> on the generated scanner
* directly; rather, you should use <code>getTokenList</code> as you would
* with any other <code>TokenMaker</code> instance.</li>
* directly; rather, you should use <code>getTokenList</code> as you would with
* any other <code>TokenMaker</code> instance.</li>
* </ul>
*
* @author Robert Futrell
@@ -58,7 +57,7 @@ import org.fife.ui.rsyntaxtextarea.TokenImpl;
*
*/
public class JsonTokenMaker extends AbstractJFlexTokenMaker {
/** This character denotes the end of file */
public static final int YYEOF = -1;
/** lexical states */
@@ -79,16 +78,17 @@ public class JsonTokenMaker extends AbstractJFlexTokenMaker {
* Translates DFA states to action switch labels.
*/
private static final int[] ZZ_ACTION = zzUnpackAction();
private static final String ZZ_ACTION_PACKED_0 = "\2\0\1\1\1\2\1\3\2\1\1\4\4\1\1\5" + "\1\6\1\7\3\6\2\0\1\4\1\10\1\4\1\1"
+ "\1\11\2\1\4\0\2\12\1\0\1\13\1\4\1\14" + "\1\4\3\1\4\0\1\4\1\15\1\16\2\0\1\17" + "\1\4\2\0\1\4";
private static final String ZZ_ACTION_PACKED_0 = "\2\0\1\1\1\2\1\3\2\1\1\4\4\1\1\5"
+ "\1\6\1\7\3\6\2\0\1\4\1\10\1\4\1\1" + "\1\11\2\1\4\0\2\12\1\0\1\13\1\4\1\14"
+ "\1\4\3\1\4\0\1\4\1\15\1\16\2\0\1\17" + "\1\4\2\0\1\4";
private static int[] zzUnpackAction() {
int[] result = new int[55];
int offset = 0;
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAction(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -102,7 +102,7 @@ public class JsonTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/**
* Translates a state to a row index in the transition table
*/
@@ -112,15 +112,16 @@ public class JsonTokenMaker extends AbstractJFlexTokenMaker {
+ "\0\u01c0\0\u01e0\0\u0200\0\u0220\0\u0240\0\u0260\0\u0280\0\u02a0"
+ "\0\240\0\u02c0\0\u02e0\0\u0300\0\u0320\0\u0340\0\u0360\0\u0380"
+ "\0\u03a0\0\u03a0\0\240\0\u03c0\0\240\0\u03e0\0\u0400\0\u0420"
+ "\0\u0440\0\u0460\0\u0480\0\u04a0\0\u04c0\0\u04e0\0\100\0\100" + "\0\u0500\0\u0520\0\u0540\0\u0560\0\u0580\0\u0540\0\u05a0";
+ "\0\u0440\0\u0460\0\u0480\0\u04a0\0\u04c0\0\u04e0\0\100\0\100"
+ "\0\u0500\0\u0520\0\u0540\0\u0560\0\u0580\0\u0540\0\u05a0";
private static int[] zzUnpackRowMap() {
int[] result = new int[55];
int offset = 0;
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
return result;
}
private static int zzUnpackRowMap(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -131,35 +132,40 @@ public class JsonTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/**
* The transition table of the DFA
*/
private static final int[] ZZ_TRANS = zzUnpackTrans();
private static final String ZZ_TRANS_PACKED_0 = "\1\3\1\4\2\3\1\5\1\3\1\6\1\7\1\3" + "\1\10\2\3\1\11\1\3\1\12\3\3\1\13\2\3"
+ "\1\14\3\3\1\15\1\6\1\15\4\3\10\16\1\17" + "\14\16\1\20\6\16\1\21\2\16\1\22\1\3\1\0" + "\4\3\1\0\2\3\1\0\4\3\1\0\12\3\3\0"
+ "\4\3\1\0\1\4\42\0\1\5\12\0\1\23\1\24" + "\3\0\1\24\57\0\1\5\33\0\10\10\1\25\1\26" + "\1\10\1\27\24\10\1\3\1\0\4\3\1\0\2\3"
+ "\1\0\1\30\3\3\1\0\12\3\3\0\4\3\16\0" + "\1\31\21\0\1\3\1\0\4\3\1\0\2\3\1\0" + "\4\3\1\0\4\3\1\32\5\3\3\0\5\3\1\0"
+ "\4\3\1\0\2\3\1\0\4\3\1\0\7\3\1\33" + "\2\3\3\0\4\3\10\16\1\0\14\16\1\0\6\16" + "\1\0\2\16\23\0\1\34\13\0\1\35\23\0\1\36"
+ "\54\0\1\37\4\0\1\40\37\0\1\41\2\0\1\42" + "\11\0\1\42\16\0\11\25\1\43\1\25\1\44\24\25"
+ "\32\0\1\45\5\0\10\25\1\0\1\10\1\46\4\10" + "\3\25\2\10\1\25\1\10\12\25\1\3\1\0\4\3" + "\1\0\2\3\1\0\4\3\1\0\10\3\1\47\1\3"
+ "\3\0\5\3\1\0\4\3\1\0\2\3\1\0\1\50" + "\3\3\1\0\12\3\3\0\5\3\1\0\4\3\1\0" + "\2\3\1\0\4\3\1\0\10\3\1\51\1\3\3\0"
+ "\4\3\35\0\1\52\31\0\1\53\32\0\1\54\54\0" + "\1\55\4\0\1\40\13\0\1\24\3\0\1\24\17\0"
+ "\1\41\33\0\10\25\1\0\33\25\2\56\3\25\1\43" + "\1\25\1\44\1\25\1\56\2\25\1\56\3\25\3\56"
+ "\11\25\1\3\1\0\4\3\1\0\2\3\1\0\4\3" + "\1\0\10\3\1\57\1\3\3\0\5\3\1\0\4\3" + "\1\0\2\3\1\0\4\3\1\0\5\3\1\60\4\3"
+ "\3\0\5\3\1\0\4\3\1\0\2\3\1\0\4\3" + "\1\0\11\3\1\50\3\0\4\3\32\0\1\61\31\0" + "\1\52\50\0\1\62\21\0\1\63\20\0\4\25\2\64"
+ "\3\25\1\43\1\25\1\44\1\25\1\64\2\25\1\64" + "\3\25\3\64\11\25\16\0\1\65\51\0\1\52\1\0"
+ "\1\61\7\0\1\63\1\66\2\63\2\66\2\0\1\63" + "\1\0\3\63\1\66\1\63\1\66\7\63\1\0\2\66"
+ "\4\63\4\25\2\67\3\25\1\43\1\25\1\44\1\25" + "\1\67\2\25\1\67\3\25\3\67\11\25\16\0\1\63"
+ "\21\0\4\25\2\10\3\25\1\43\1\25\1\44\1\25" + "\1\10\2\25\1\10\3\25\3\10\11\25";
private static final String ZZ_TRANS_PACKED_0 = "\1\3\1\4\2\3\1\5\1\3\1\6\1\7\1\3"
+ "\1\10\2\3\1\11\1\3\1\12\3\3\1\13\2\3" + "\1\14\3\3\1\15\1\6\1\15\4\3\10\16\1\17"
+ "\14\16\1\20\6\16\1\21\2\16\1\22\1\3\1\0" + "\4\3\1\0\2\3\1\0\4\3\1\0\12\3\3\0"
+ "\4\3\1\0\1\4\42\0\1\5\12\0\1\23\1\24" + "\3\0\1\24\57\0\1\5\33\0\10\10\1\25\1\26"
+ "\1\10\1\27\24\10\1\3\1\0\4\3\1\0\2\3" + "\1\0\1\30\3\3\1\0\12\3\3\0\4\3\16\0"
+ "\1\31\21\0\1\3\1\0\4\3\1\0\2\3\1\0" + "\4\3\1\0\4\3\1\32\5\3\3\0\5\3\1\0"
+ "\4\3\1\0\2\3\1\0\4\3\1\0\7\3\1\33" + "\2\3\3\0\4\3\10\16\1\0\14\16\1\0\6\16"
+ "\1\0\2\16\23\0\1\34\13\0\1\35\23\0\1\36" + "\54\0\1\37\4\0\1\40\37\0\1\41\2\0\1\42"
+ "\11\0\1\42\16\0\11\25\1\43\1\25\1\44\24\25" + "\32\0\1\45\5\0\10\25\1\0\1\10\1\46\4\10"
+ "\3\25\2\10\1\25\1\10\12\25\1\3\1\0\4\3" + "\1\0\2\3\1\0\4\3\1\0\10\3\1\47\1\3"
+ "\3\0\5\3\1\0\4\3\1\0\2\3\1\0\1\50" + "\3\3\1\0\12\3\3\0\5\3\1\0\4\3\1\0"
+ "\2\3\1\0\4\3\1\0\10\3\1\51\1\3\3\0" + "\4\3\35\0\1\52\31\0\1\53\32\0\1\54\54\0"
+ "\1\55\4\0\1\40\13\0\1\24\3\0\1\24\17\0" + "\1\41\33\0\10\25\1\0\33\25\2\56\3\25\1\43"
+ "\1\25\1\44\1\25\1\56\2\25\1\56\3\25\3\56" + "\11\25\1\3\1\0\4\3\1\0\2\3\1\0\4\3"
+ "\1\0\10\3\1\57\1\3\3\0\5\3\1\0\4\3" + "\1\0\2\3\1\0\4\3\1\0\5\3\1\60\4\3"
+ "\3\0\5\3\1\0\4\3\1\0\2\3\1\0\4\3" + "\1\0\11\3\1\50\3\0\4\3\32\0\1\61\31\0"
+ "\1\52\50\0\1\62\21\0\1\63\20\0\4\25\2\64" + "\3\25\1\43\1\25\1\44\1\25\1\64\2\25\1\64"
+ "\3\25\3\64\11\25\16\0\1\65\51\0\1\52\1\0" + "\1\61\7\0\1\63\1\66\2\63\2\66\2\0\1\63"
+ "\1\0\3\63\1\66\1\63\1\66\7\63\1\0\2\66" + "\4\63\4\25\2\67\3\25\1\43\1\25\1\44\1\25"
+ "\1\67\2\25\1\67\3\25\3\67\11\25\16\0\1\63" + "\21\0\4\25\2\10\3\25\1\43\1\25\1\44\1\25"
+ "\1\10\2\25\1\10\3\25\3\10\11\25";
private static int[] zzUnpackTrans() {
int[] result = new int[1472];
int offset = 0;
offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
return result;
}
private static int zzUnpackTrans(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -174,7 +180,7 @@ public class JsonTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/* error codes */
private static final int ZZ_UNKNOWN_ERROR = 0;
private static final int ZZ_NO_MATCH = 1;
@@ -186,16 +192,16 @@ public class JsonTokenMaker extends AbstractJFlexTokenMaker {
* ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
*/
private static final int[] ZZ_ATTRIBUTE = zzUnpackAttribute();
private static final String ZZ_ATTRIBUTE_PACKED_0 = "\2\0\3\1\1\11\6\1\1\11\1\1\1\11\3\1" + "\2\0\1\1\1\3\2\1\1\11\2\1\4\0\2\1"
+ "\1\0\1\11\1\1\1\15\4\1\4\0\3\1\2\0" + "\2\1\2\0\1\1";
private static final String ZZ_ATTRIBUTE_PACKED_0 = "\2\0\3\1\1\11\6\1\1\11\1\1\1\11\3\1"
+ "\2\0\1\1\1\3\2\1\1\11\2\1\4\0\2\1" + "\1\0\1\11\1\1\1\15\4\1\4\0\3\1\2\0" + "\2\1\2\0\1\1";
private static int[] zzUnpackAttribute() {
int[] result = new int[55];
int offset = 0;
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAttribute(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -209,7 +215,7 @@ public class JsonTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/** the input device */
private java.io.Reader zzReader;
/** the current state of the DFA */
@@ -217,8 +223,8 @@ public class JsonTokenMaker extends AbstractJFlexTokenMaker {
/** the current lexical state */
private int zzLexicalState = YYINITIAL;
/**
* this buffer contains the current text to be matched and is
* the source of the yytext() string
* this buffer contains the current text to be matched and is the source of the
* yytext() string
*/
private char zzBuffer[];
/** the textposition at the last accepting state */
@@ -230,92 +236,82 @@ public class JsonTokenMaker extends AbstractJFlexTokenMaker {
/** startRead marks the beginning of the yytext() string in the buffer */
private int zzStartRead;
/**
* endRead marks the last character in the buffer, that has been read
* from input
* endRead marks the last character in the buffer, that has been read from input
*/
private int zzEndRead;
/** zzAtEOF == true <=> the scanner is at the EOF */
private boolean zzAtEOF;
/* user code: */
private boolean highlightEolComments;
/**
* Constructor. This must be here because JFlex does not generate a
* no-parameter constructor.
* Constructor. This must be here because JFlex does not generate a no-parameter
* constructor.
*/
public JsonTokenMaker() {}
public JsonTokenMaker() {
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType
* The token's type.
* @param tokenType The token's type.
* @see #addToken(int, int, int)
*/
private void addHyperlinkToken(int start, int end, int tokenType) {
int so = start + offsetShift;
addToken(zzBuffer, start, end, tokenType, so, true);
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType
* The token's type.
* @param tokenType The token's type.
*/
private void addToken(int tokenType) {
addToken(zzStartRead, zzMarkedPos - 1, tokenType);
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType
* The token's type.
* @param tokenType The token's type.
*/
private void addToken(int start, int end, int tokenType) {
int so = start + offsetShift;
addToken(zzBuffer, start, end, tokenType, so, 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.
*/
@Override
public void addToken(char[] array, int start, int end, int tokenType, int startOffset, boolean hyperlink) {
super.addToken(array, start, end, tokenType, startOffset, hyperlink);
zzStartRead = zzMarkedPos;
}
/**
* Returns <code>true</code> always as C-style languages use curly braces
* to denote code blocks.
* Returns <code>true</code> always as C-style languages use curly braces to
* denote code blocks.
*
* @return <code>true</code> always.
*/
public boolean getCurlyBracesDenoteCodeBlocks() {
return true;
}
@Override
public boolean getMarkOccurrencesOfTokenType(int type) {
return false;
}
@Override
public boolean getShouldIndentNextLineAfter(Token t) {
if (t != null && t.length() == 1) {
@@ -324,21 +320,18 @@ public class JsonTokenMaker extends AbstractJFlexTokenMaker {
}
return false;
}
/**
* Returns the first token in the linked list of tokens generated
* from <code>text</code>. This method must be implemented by
* subclasses so they can correctly implement syntax highlighting.
* Returns the first token in the linked list of tokens generated from
* <code>text</code>. This method must be implemented by subclasses so they can
* correctly implement syntax highlighting.
*
* @param text
* The text from which to get tokens.
* @param initialTokenType
* The token type we should start with.
* @param startOffset
* The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing
* the syntax highlighted text.
* @param text The text from which to get tokens.
* @param initialTokenType The token type we should start with.
* @param startOffset The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing the syntax
* highlighted text.
*/
@Override
public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
@@ -357,40 +350,38 @@ public class JsonTokenMaker extends AbstractJFlexTokenMaker {
return new TokenImpl();
}
}
protected void setHighlightEolComments(boolean highlightEolComments) {
this.highlightEolComments = highlightEolComments;
}
/**
* Refills the input buffer.
*
* @return <code>true</code> if EOF was reached, otherwise
* <code>false</code>.
* @return <code>true</code> if EOF was reached, otherwise <code>false</code>.
*/
private boolean zzRefill() {
return zzCurrentPos >= s.offset + s.count;
}
/**
* Resets the scanner to read from a new input stream.
* Does not close the old reader.
* Resets the scanner to read from a new input stream. Does not close the old
* reader.
*
* All internal variables are reset, the old input stream
* <b>cannot</b> be reused (internal buffer is discarded and lost).
* Lexical state is set to <tt>YY_INITIAL</tt>.
* All internal variables are reset, the old input stream <b>cannot</b> be
* reused (internal buffer is discarded and lost). Lexical state is set to
* <tt>YY_INITIAL</tt>.
*
* @param reader
* the new input stream
* @param reader the new input stream
*/
public final void yyreset(Reader reader) {
// 's' has been updated.
zzBuffer = s.array;
/*
* We replaced the line below with the two below it because zzRefill
* no longer "refills" the buffer (since the way we do it, it's always
* "full" the first time through, since it points to the segment's
* array). So, we assign zzEndRead here.
* We replaced the line below with the two below it because zzRefill no longer
* "refills" the buffer (since the way we do it, it's always "full" the first
* time through, since it points to the segment's array). So, we assign
* zzEndRead here.
*/
// zzStartRead = zzEndRead = s.offset;
zzStartRead = s.offset;
@@ -400,34 +391,31 @@ public class JsonTokenMaker extends AbstractJFlexTokenMaker {
zzReader = reader;
zzAtEOF = false;
}
/**
* Creates a new scanner
* There is also a java.io.InputStream version of this constructor.
* Creates a new scanner There is also a java.io.InputStream version of this
* constructor.
*
* @param in
* the java.io.Reader to read input from.
* @param in the java.io.Reader to read input from.
*/
public JsonTokenMaker(java.io.Reader in) {
this.zzReader = in;
}
/**
* Creates a new scanner.
* There is also java.io.Reader version of this constructor.
* Creates a new scanner. There is also java.io.Reader version of this
* constructor.
*
* @param in
* the java.io.Inputstream to read input from.
* @param in the java.io.Inputstream to read input from.
*/
public JsonTokenMaker(java.io.InputStream in) {
this(new java.io.InputStreamReader(in));
}
/**
* Unpacks the compressed character translation table.
*
* @param packed
* the packed character translation table
* @param packed the packed character translation table
* @return the unpacked character translation table
*/
private static char[] zzUnpackCMap(String packed) {
@@ -443,7 +431,7 @@ public class JsonTokenMaker extends AbstractJFlexTokenMaker {
}
return map;
}
/**
* Closes the input stream.
*/
@@ -453,69 +441,64 @@ public class JsonTokenMaker extends AbstractJFlexTokenMaker {
if (zzReader != null)
zzReader.close();
}
/**
* Returns the current lexical state.
*/
public final int yystate() {
return zzLexicalState;
}
/**
* Enters a new lexical state
*
* @param newState
* the new lexical state
* @param newState the new lexical state
*/
@Override
public final void yybegin(int newState) {
zzLexicalState = newState;
}
/**
* Returns the text matched by the current regular expression.
*/
public final String yytext() {
return new String(zzBuffer, zzStartRead, zzMarkedPos - zzStartRead);
}
/**
* Returns the character at position <tt>pos</tt> from the
* matched text.
* Returns the character at position <tt>pos</tt> from the matched text.
*
* It is equivalent to yytext().charAt(pos), but faster
*
* @param pos
* the position of the character to fetch.
* A value from 0 to yylength()-1.
* @param pos the position of the character to fetch. A value from 0 to
* yylength()-1.
*
* @return the character at position pos
*/
public final char yycharat(int pos) {
return zzBuffer[zzStartRead + pos];
}
/**
* Returns the length of the matched text region.
*/
public final int yylength() {
return zzMarkedPos - zzStartRead;
}
/**
* Reports an error that occured while scanning.
*
* In a wellformed scanner (no or only correct usage of
* yypushback(int) and a match-all fallback rule) this method
* will only be called with things that "Can't Possibly Happen".
* If this method is called, something is seriously wrong
* (e.g. a JFlex bug producing a faulty scanner etc.).
* In a wellformed scanner (no or only correct usage of yypushback(int) and a
* match-all fallback rule) this method will only be called with things that
* "Can't Possibly Happen". If this method is called, something is seriously
* wrong (e.g. a JFlex bug producing a faulty scanner etc.).
*
* Usual syntax/scanner level error handling should be done
* in error fallback rules.
* Usual syntax/scanner level error handling should be done in error fallback
* rules.
*
* @param errorCode
* the code of the errormessage to display
* @param errorCode the code of the errormessage to display
*/
private void zzScanError(int errorCode) {
String message;
@@ -526,29 +509,27 @@ public class JsonTokenMaker extends AbstractJFlexTokenMaker {
}
throw new Error(message);
}
/**
* Pushes the specified amount of characters back into the input stream.
*
* They will be read again by then next call of the scanning method
*
* @param number
* the number of characters to be read again.
* This number must not be greater than yylength()!
* @param number the number of characters to be read again. This number must not
* be greater than yylength()!
*/
public void yypushback(int number) {
if (number > yylength())
zzScanError(ZZ_PUSHBACK_2BIG);
zzMarkedPos -= number;
}
/**
* Resumes scanning until the next regular expression is matched,
* the end of input is encountered or an I/O-Error occurs.
* Resumes scanning until the next regular expression is matched, the end of
* input is encountered or an I/O-Error occurs.
*
* @return the next token
* @exception java.io.IOException
* if any I/O-Error occurs
* @exception java.io.IOException if any I/O-Error occurs
*/
public org.fife.ui.rsyntaxtextarea.Token yylex() throws java.io.IOException {
int zzInput;
@@ -570,8 +551,7 @@ public class JsonTokenMaker extends AbstractJFlexTokenMaker {
zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
zzState = zzLexicalState;
zzWasPushback = false;
zzForAction:
{
zzForAction: {
while (true) {
if (zzCurrentPosL < zzEndReadL)
zzInput = zzBufferL[zzCurrentPosL++];
@@ -618,114 +598,115 @@ public class JsonTokenMaker extends AbstractJFlexTokenMaker {
if (zzWasPushback)
zzMarkedPos = zzPushbackPosL;
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
case 13: {
addToken(Token.RESERVED_WORD);
}
case 16:
break;
case 1: {
case 13: {
addToken(Token.RESERVED_WORD);
}
case 16:
break;
case 1: {
addToken(Token.IDENTIFIER);
}
case 17:
break;
case 10: {
addToken(Token.LITERAL_NUMBER_FLOAT);
}
case 18:
break;
case 8: {
addToken(Token.LITERAL_STRING_DOUBLE_QUOTE);
}
case 19:
break;
case 12: {
addToken(Token.VARIABLE);
}
case 20:
break;
case 9: {
if (highlightEolComments) {
start = zzMarkedPos - 2;
yybegin(EOL_COMMENT);
} else {
addToken(Token.IDENTIFIER);
}
case 17:
break;
case 10: {
addToken(Token.LITERAL_NUMBER_FLOAT);
}
case 18:
break;
case 8: {
addToken(Token.LITERAL_STRING_DOUBLE_QUOTE);
}
case 19:
break;
case 12: {
addToken(Token.VARIABLE);
}
case 20:
break;
case 9: {
if (highlightEolComments) {
start = zzMarkedPos - 2;
yybegin(EOL_COMMENT);
} else {
addToken(Token.IDENTIFIER);
}
case 21:
break;
case 2: {
addToken(Token.WHITESPACE);
}
case 22:
break;
case 15: {
int temp = zzStartRead;
addToken(start, zzStartRead - 1, Token.COMMENT_EOL);
addHyperlinkToken(temp, zzMarkedPos - 1, Token.COMMENT_EOL);
start = zzMarkedPos;
}
case 23:
break;
case 3: {
addToken(Token.LITERAL_NUMBER_DECIMAL_INT);
}
case 24:
break;
case 14: {
addToken(Token.LITERAL_BOOLEAN);
}
case 25:
break;
case 4: {
addToken(Token.ERROR_STRING_DOUBLE);
addNullToken();
return firstToken;
}
case 26:
break;
case 7: {
addToken(start, zzStartRead - 1, Token.COMMENT_EOL);
addNullToken();
return firstToken;
}
case 27:
break;
case 11: {
addToken(Token.ERROR_STRING_DOUBLE);
}
case 28:
break;
case 6: {
}
case 29:
break;
case 5: {
addToken(Token.SEPARATOR);
}
case 30:
break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
switch (zzLexicalState) {
case EOL_COMMENT: {
addToken(start, zzStartRead - 1, Token.COMMENT_EOL);
addNullToken();
return firstToken;
}
}
case 21:
break;
case 2: {
addToken(Token.WHITESPACE);
}
case 22:
break;
case 15: {
int temp = zzStartRead;
addToken(start, zzStartRead - 1, Token.COMMENT_EOL);
addHyperlinkToken(temp, zzMarkedPos - 1, Token.COMMENT_EOL);
start = zzMarkedPos;
}
case 23:
break;
case 3: {
addToken(Token.LITERAL_NUMBER_DECIMAL_INT);
}
case 24:
break;
case 14: {
addToken(Token.LITERAL_BOOLEAN);
}
case 25:
break;
case 4: {
addToken(Token.ERROR_STRING_DOUBLE);
addNullToken();
return firstToken;
}
case 26:
break;
case 7: {
addToken(start, zzStartRead - 1, Token.COMMENT_EOL);
addNullToken();
return firstToken;
}
case 27:
break;
case 11: {
addToken(Token.ERROR_STRING_DOUBLE);
}
case 28:
break;
case 6: {}
case 29:
break;
case 5: {
addToken(Token.SEPARATOR);
}
case 30:
break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
switch (zzLexicalState) {
case EOL_COMMENT: {
addToken(start, zzStartRead - 1, Token.COMMENT_EOL);
addNullToken();
return firstToken;
}
case 56:
break;
case YYINITIAL: {
addNullToken();
return firstToken;
}
case 57:
break;
default:
return null;
}
} else {
zzScanError(ZZ_NO_MATCH);
case 56:
break;
case YYINITIAL: {
addNullToken();
return firstToken;
}
case 57:
break;
default:
return null;
}
} else {
zzScanError(ZZ_NO_MATCH);
}
}
}
}
@@ -21,16 +21,15 @@ import org.fife.ui.rsyntaxtextarea.TokenImpl;
*
* This implementation was created using
* <a href="http://www.jflex.de/">JFlex</a> 1.4.1; however, the generated file
* was modified for performance. Memory allocation needs to be almost
* completely removed to be competitive with the handwritten lexers (subclasses
* of <code>AbstractTokenMaker</code>, so this class has been modified so that
* was modified for performance. Memory allocation needs to be almost completely
* removed to be competitive with the handwritten lexers (subclasses of
* <code>AbstractTokenMaker</code>, so this class has been modified so that
* Strings are never allocated (via yytext()), and the scanner never has to
* worry about refilling its buffer (needlessly copying chars around).
* We can achieve this because RSTA always scans exactly 1 line of tokens at a
* time, and hands the scanner this line as an array of characters (a Segment
* really). Since tokens contain pointers to char arrays instead of Strings
* holding their contents, there is no need for allocating new memory for
* Strings.
* worry about refilling its buffer (needlessly copying chars around). We can
* achieve this because RSTA always scans exactly 1 line of tokens at a time,
* and hands the scanner this line as an array of characters (a Segment really).
* Since tokens contain pointers to char arrays instead of Strings holding their
* contents, there is no need for allocating new memory for Strings.
* <p>
*
* The actual algorithm generated for scanning has, of course, not been
@@ -40,16 +39,16 @@ import org.fife.ui.rsyntaxtextarea.TokenImpl;
* If you wish to regenerate this file yourself, keep in mind the following:
* <ul>
* <li>The generated <code>LatexTokenMaker.java</code> file will contain two
* definitions of both <code>zzRefill</code> and <code>yyreset</code>.
* You should hand-delete the second of each definition (the ones
* generated by the lexer), as these generated methods modify the input
* buffer, which we'll never have to do.</li>
* <li>You should also change the declaration/definition of zzBuffer to NOT
* be initialized. This is a needless memory allocation for us since we
* will be pointing the array somewhere else anyway.</li>
* definitions of both <code>zzRefill</code> and <code>yyreset</code>. You
* should hand-delete the second of each definition (the ones generated by the
* lexer), as these generated methods modify the input buffer, which we'll never
* have to do.</li>
* <li>You should also change the declaration/definition of zzBuffer to NOT be
* initialized. This is a needless memory allocation for us since we will be
* pointing the array somewhere else anyway.</li>
* <li>You should NOT call <code>yylex()</code> on the generated scanner
* directly; rather, you should use <code>getTokenList</code> as you would
* with any other <code>TokenMaker</code> instance.</li>
* directly; rather, you should use <code>getTokenList</code> as you would with
* any other <code>TokenMaker</code> instance.</li>
* </ul>
*
* @author Robert Futrell
@@ -57,7 +56,7 @@ import org.fife.ui.rsyntaxtextarea.TokenImpl;
*
*/
public class LatexTokenMaker extends AbstractJFlexTokenMaker {
/** This character denotes the end of file */
public static final int YYEOF = -1;
/** lexical states */
@@ -78,16 +77,16 @@ public class LatexTokenMaker extends AbstractJFlexTokenMaker {
* Translates DFA states to action switch labels.
*/
private static final int[] ZZ_ACTION = zzUnpackAction();
private static final String ZZ_ACTION_PACKED_0 = "\2\0\2\1\1\2\1\3\1\1\1\4\1\5\4\6" + "\1\7\1\10\1\11\2\10\4\0\2\10\4\0\2\10"
+ "\2\0\1\12\1\0\1\10\3\0\1\10\1\13\2\0" + "\1\14";
private static final String ZZ_ACTION_PACKED_0 = "\2\0\2\1\1\2\1\3\1\1\1\4\1\5\4\6"
+ "\1\7\1\10\1\11\2\10\4\0\2\10\4\0\2\10" + "\2\0\1\12\1\0\1\10\3\0\1\10\1\13\2\0" + "\1\14";
private static int[] zzUnpackAction() {
int[] result = new int[43];
int offset = 0;
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAction(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -101,23 +100,24 @@ public class LatexTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/**
* Translates a state to a row index in the transition table
*/
private static final int[] ZZ_ROWMAP = zzUnpackRowMap();
private static final String ZZ_ROWMAP_PACKED_0 = "\0\0\0\33\0\66\0\121\0\66\0\66\0\154\0\66"
+ "\0\66\0\207\0\242\0\275\0\330\0\66\0\363\0\66" + "\0\u010e\0\u0129\0\u0144\0\u015f\0\u017a\0\u0195\0\u01b0\0\u01cb"
+ "\0\66\0\207\0\242\0\275\0\330\0\66\0\363\0\66"
+ "\0\u010e\0\u0129\0\u0144\0\u015f\0\u017a\0\u0195\0\u01b0\0\u01cb"
+ "\0\u01e6\0\u0201\0\u021c\0\u0237\0\u0252\0\u026d\0\u0288\0\u02a3"
+ "\0\u02be\0\u02d9\0\u02f4\0\u030f\0\u02be\0\u032a\0\u0345\0\66" + "\0\u0360\0\u037b\0\66";
private static int[] zzUnpackRowMap() {
int[] result = new int[43];
int offset = 0;
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
return result;
}
private static int zzUnpackRowMap(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -128,30 +128,35 @@ public class LatexTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/**
* The transition table of the DFA
*/
private static final int[] ZZ_TRANS = zzUnpackTrans();
private static final String ZZ_TRANS_PACKED_0 = "\1\3\2\4\1\5\1\6\3\3\10\4\1\3\1\4" + "\1\3\1\7\1\10\3\4\1\10\1\4\1\11\10\12"
+ "\1\13\3\12\1\14\4\12\1\15\10\12\1\16\34\0" + "\2\4\5\0\10\4\1\0\1\4\3\0\3\4\1\0" + "\1\4\2\0\2\17\1\0\1\20\3\0\7\17\1\21"
+ "\1\0\1\17\3\0\1\22\2\17\1\0\1\17\1\0" + "\10\12\1\0\3\12\1\0\4\12\1\0\10\12\12\0" + "\1\23\32\0\1\24\3\0\1\25\36\0\1\26\12\0"
+ "\2\17\5\0\10\17\1\0\1\17\3\0\3\17\1\0" + "\1\17\2\0\2\17\5\0\10\17\1\0\1\17\3\0" + "\2\17\1\27\1\0\1\17\2\0\2\17\5\0\7\17"
+ "\1\30\1\0\1\17\3\0\3\17\1\0\1\17\12\0" + "\1\31\33\0\1\32\36\0\1\33\35\0\1\34\12\0" + "\2\17\5\0\10\17\1\0\1\17\3\0\3\17\1\0"
+ "\1\35\2\0\2\17\5\0\10\17\1\0\1\17\3\0" + "\1\17\1\36\1\17\1\0\1\17\13\0\1\37\40\0"
+ "\1\40\31\0\1\32\35\0\1\41\11\0\2\17\5\0" + "\10\17\1\0\1\17\3\0\3\17\1\42\1\17\2\0" + "\2\17\5\0\5\17\1\43\2\17\1\0\1\17\3\0"
private static final String ZZ_TRANS_PACKED_0 = "\1\3\2\4\1\5\1\6\3\3\10\4\1\3\1\4"
+ "\1\3\1\7\1\10\3\4\1\10\1\4\1\11\10\12" + "\1\13\3\12\1\14\4\12\1\15\10\12\1\16\34\0"
+ "\2\4\5\0\10\4\1\0\1\4\3\0\3\4\1\0" + "\1\4\2\0\2\17\1\0\1\20\3\0\7\17\1\21"
+ "\1\0\1\17\3\0\1\22\2\17\1\0\1\17\1\0" + "\10\12\1\0\3\12\1\0\4\12\1\0\10\12\12\0"
+ "\1\23\32\0\1\24\3\0\1\25\36\0\1\26\12\0" + "\2\17\5\0\10\17\1\0\1\17\3\0\3\17\1\0"
+ "\1\17\2\0\2\17\5\0\10\17\1\0\1\17\3\0" + "\2\17\1\27\1\0\1\17\2\0\2\17\5\0\7\17"
+ "\1\30\1\0\1\17\3\0\3\17\1\0\1\17\12\0" + "\1\31\33\0\1\32\36\0\1\33\35\0\1\34\12\0"
+ "\2\17\5\0\10\17\1\0\1\17\3\0\3\17\1\0" + "\1\35\2\0\2\17\5\0\10\17\1\0\1\17\3\0"
+ "\1\17\1\36\1\17\1\0\1\17\13\0\1\37\40\0" + "\1\40\31\0\1\32\35\0\1\41\11\0\2\17\5\0"
+ "\10\17\1\0\1\17\3\0\3\17\1\42\1\17\2\0" + "\2\17\5\0\5\17\1\43\2\17\1\0\1\17\3\0"
+ "\3\17\1\0\1\17\14\0\1\32\4\0\1\40\20\0" + "\1\44\25\0\1\41\1\45\1\0\2\45\12\41\1\45"
+ "\1\41\1\45\2\0\3\41\1\0\1\41\2\0\2\46" + "\5\0\10\46\1\0\1\46\3\0\3\46\1\0\1\46" + "\2\0\2\17\5\0\10\17\1\0\1\17\3\0\2\17"
+ "\1\47\1\0\1\17\7\0\1\41\25\0\2\46\5\0" + "\10\46\1\0\1\46\2\0\1\50\3\46\1\0\1\46" + "\2\0\2\17\5\0\10\17\1\0\1\17\3\0\3\17"
+ "\1\51\1\17\2\0\2\52\5\0\10\52\1\0\1\52" + "\3\0\3\52\1\0\1\52\2\0\2\52\5\0\10\52" + "\1\0\1\52\2\0\1\53\3\52\1\0\1\52\1\0";
+ "\1\41\1\45\2\0\3\41\1\0\1\41\2\0\2\46" + "\5\0\10\46\1\0\1\46\3\0\3\46\1\0\1\46"
+ "\2\0\2\17\5\0\10\17\1\0\1\17\3\0\2\17" + "\1\47\1\0\1\17\7\0\1\41\25\0\2\46\5\0"
+ "\10\46\1\0\1\46\2\0\1\50\3\46\1\0\1\46" + "\2\0\2\17\5\0\10\17\1\0\1\17\3\0\3\17"
+ "\1\51\1\17\2\0\2\52\5\0\10\52\1\0\1\52" + "\3\0\3\52\1\0\1\52\2\0\2\52\5\0\10\52"
+ "\1\0\1\52\2\0\1\53\3\52\1\0\1\52\1\0";
private static int[] zzUnpackTrans() {
int[] result = new int[918];
int offset = 0;
offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
return result;
}
private static int zzUnpackTrans(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -166,7 +171,7 @@ public class LatexTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/* error codes */
private static final int ZZ_UNKNOWN_ERROR = 0;
private static final int ZZ_NO_MATCH = 1;
@@ -178,16 +183,16 @@ public class LatexTokenMaker extends AbstractJFlexTokenMaker {
* ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
*/
private static final int[] ZZ_ATTRIBUTE = zzUnpackAttribute();
private static final String ZZ_ATTRIBUTE_PACKED_0 = "\2\0\1\11\1\1\2\11\1\1\2\11\4\1\1\11" + "\1\1\1\11\2\1\4\0\2\1\4\0\2\1\2\0"
+ "\1\1\1\0\1\1\3\0\1\1\1\11\2\0\1\11";
private static final String ZZ_ATTRIBUTE_PACKED_0 = "\2\0\1\11\1\1\2\11\1\1\2\11\4\1\1\11"
+ "\1\1\1\11\2\1\4\0\2\1\4\0\2\1\2\0" + "\1\1\1\0\1\1\3\0\1\1\1\11\2\0\1\11";
private static int[] zzUnpackAttribute() {
int[] result = new int[43];
int offset = 0;
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAttribute(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -201,7 +206,7 @@ public class LatexTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/** the input device */
private java.io.Reader zzReader;
/** the current state of the DFA */
@@ -209,8 +214,8 @@ public class LatexTokenMaker extends AbstractJFlexTokenMaker {
/** the current lexical state */
private int zzLexicalState = YYINITIAL;
/**
* this buffer contains the current text to be matched and is
* the source of the yytext() string
* this buffer contains the current text to be matched and is the source of the
* yytext() string
*/
private char zzBuffer[];
/** the textposition at the last accepting state */
@@ -220,77 +225,67 @@ public class LatexTokenMaker extends AbstractJFlexTokenMaker {
/** startRead marks the beginning of the yytext() string in the buffer */
private int zzStartRead;
/**
* endRead marks the last character in the buffer, that has been read
* from input
* endRead marks the last character in the buffer, that has been read from input
*/
private int zzEndRead;
/** zzAtEOF == true <=> the scanner is at the EOF */
private boolean zzAtEOF;
/* user code: */
/**
* Constructor. This must be here because JFlex does not generate a
* no-parameter constructor.
* Constructor. This must be here because JFlex does not generate a no-parameter
* constructor.
*/
public LatexTokenMaker() {}
public LatexTokenMaker() {
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType
* The token's type.
* @param tokenType The token's type.
* @see #addToken(int, int, int)
*/
private void addHyperlinkToken(int start, int end, int tokenType) {
int so = start + offsetShift;
addToken(zzBuffer, start, end, tokenType, so, true);
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType
* The token's type.
* @param tokenType The token's type.
*/
private void addToken(int tokenType) {
addToken(zzStartRead, zzMarkedPos - 1, tokenType);
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType
* The token's type.
* @param tokenType The token's type.
* @see #addHyperlinkToken(int, int, int)
*/
private void addToken(int start, int end, int tokenType) {
int so = start + offsetShift;
addToken(zzBuffer, start, end, tokenType, so, 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.
*/
@Override
public void addToken(char[] array, int start, int end, int tokenType, int startOffset, boolean hyperlink) {
super.addToken(array, start, end, tokenType, startOffset, hyperlink);
zzStartRead = zzMarkedPos;
}
/**
* ${inheritDoc}
*/
@@ -298,21 +293,18 @@ public class LatexTokenMaker extends AbstractJFlexTokenMaker {
public String[] getLineCommentStartAndEnd(int languageIndex) {
return new String[] { "%", null };
}
/**
* Returns the first token in the linked list of tokens generated
* from <code>text</code>. This method must be implemented by
* subclasses so they can correctly implement syntax highlighting.
* Returns the first token in the linked list of tokens generated from
* <code>text</code>. This method must be implemented by subclasses so they can
* correctly implement syntax highlighting.
*
* @param text
* The text from which to get tokens.
* @param initialTokenType
* The token type we should start with.
* @param startOffset
* The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing
* the syntax highlighted text.
* @param text The text from which to get tokens.
* @param initialTokenType The token type we should start with.
* @param startOffset The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing the syntax
* highlighted text.
*/
@Override
public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
@@ -330,38 +322,35 @@ public class LatexTokenMaker extends AbstractJFlexTokenMaker {
return new TokenImpl();
}
}
/**
* Refills the input buffer.
*
* @return <code>true</code> if EOF was reached, otherwise
* <code>false</code>.
* @exception IOException
* if any I/O-Error occurs.
* @return <code>true</code> if EOF was reached, otherwise <code>false</code>.
* @exception IOException if any I/O-Error occurs.
*/
private boolean zzRefill() {
return zzCurrentPos >= s.offset + s.count;
}
/**
* Resets the scanner to read from a new input stream.
* Does not close the old reader.
* Resets the scanner to read from a new input stream. Does not close the old
* reader.
*
* All internal variables are reset, the old input stream
* <b>cannot</b> be reused (internal buffer is discarded and lost).
* Lexical state is set to <tt>YY_INITIAL</tt>.
* All internal variables are reset, the old input stream <b>cannot</b> be
* reused (internal buffer is discarded and lost). Lexical state is set to
* <tt>YY_INITIAL</tt>.
*
* @param reader
* the new input stream
* @param reader the new input stream
*/
public final void yyreset(java.io.Reader reader) {
// 's' has been updated.
zzBuffer = s.array;
/*
* We replaced the line below with the two below it because zzRefill
* no longer "refills" the buffer (since the way we do it, it's always
* "full" the first time through, since it points to the segment's
* array). So, we assign zzEndRead here.
* We replaced the line below with the two below it because zzRefill no longer
* "refills" the buffer (since the way we do it, it's always "full" the first
* time through, since it points to the segment's array). So, we assign
* zzEndRead here.
*/
// zzStartRead = zzEndRead = s.offset;
zzStartRead = s.offset;
@@ -371,34 +360,31 @@ public class LatexTokenMaker extends AbstractJFlexTokenMaker {
zzReader = reader;
zzAtEOF = false;
}
/**
* Creates a new scanner
* There is also a java.io.InputStream version of this constructor.
* Creates a new scanner There is also a java.io.InputStream version of this
* constructor.
*
* @param in
* the java.io.Reader to read input from.
* @param in the java.io.Reader to read input from.
*/
public LatexTokenMaker(java.io.Reader in) {
this.zzReader = in;
}
/**
* Creates a new scanner.
* There is also java.io.Reader version of this constructor.
* Creates a new scanner. There is also java.io.Reader version of this
* constructor.
*
* @param in
* the java.io.Inputstream to read input from.
* @param in the java.io.Inputstream to read input from.
*/
public LatexTokenMaker(java.io.InputStream in) {
this(new java.io.InputStreamReader(in));
}
/**
* Unpacks the compressed character translation table.
*
* @param packed
* the packed character translation table
* @param packed the packed character translation table
* @return the unpacked character translation table
*/
private static char[] zzUnpackCMap(String packed) {
@@ -414,7 +400,7 @@ public class LatexTokenMaker extends AbstractJFlexTokenMaker {
}
return map;
}
/**
* Closes the input stream.
*/
@@ -424,69 +410,64 @@ public class LatexTokenMaker extends AbstractJFlexTokenMaker {
if (zzReader != null)
zzReader.close();
}
/**
* Returns the current lexical state.
*/
public final int yystate() {
return zzLexicalState;
}
/**
* Enters a new lexical state
*
* @param newState
* the new lexical state
* @param newState the new lexical state
*/
@Override
public final void yybegin(int newState) {
zzLexicalState = newState;
}
/**
* Returns the text matched by the current regular expression.
*/
public final String yytext() {
return new String(zzBuffer, zzStartRead, zzMarkedPos - zzStartRead);
}
/**
* Returns the character at position <tt>pos</tt> from the
* matched text.
* Returns the character at position <tt>pos</tt> from the matched text.
*
* It is equivalent to yytext().charAt(pos), but faster
*
* @param pos
* the position of the character to fetch.
* A value from 0 to yylength()-1.
* @param pos the position of the character to fetch. A value from 0 to
* yylength()-1.
*
* @return the character at position pos
*/
public final char yycharat(int pos) {
return zzBuffer[zzStartRead + pos];
}
/**
* Returns the length of the matched text region.
*/
public final int yylength() {
return zzMarkedPos - zzStartRead;
}
/**
* Reports an error that occured while scanning.
*
* In a wellformed scanner (no or only correct usage of
* yypushback(int) and a match-all fallback rule) this method
* will only be called with things that "Can't Possibly Happen".
* If this method is called, something is seriously wrong
* (e.g. a JFlex bug producing a faulty scanner etc.).
* In a wellformed scanner (no or only correct usage of yypushback(int) and a
* match-all fallback rule) this method will only be called with things that
* "Can't Possibly Happen". If this method is called, something is seriously
* wrong (e.g. a JFlex bug producing a faulty scanner etc.).
*
* Usual syntax/scanner level error handling should be done
* in error fallback rules.
* Usual syntax/scanner level error handling should be done in error fallback
* rules.
*
* @param errorCode
* the code of the errormessage to display
* @param errorCode the code of the errormessage to display
*/
private void zzScanError(int errorCode) {
String message;
@@ -497,29 +478,27 @@ public class LatexTokenMaker extends AbstractJFlexTokenMaker {
}
throw new Error(message);
}
/**
* Pushes the specified amount of characters back into the input stream.
*
* They will be read again by then next call of the scanning method
*
* @param number
* the number of characters to be read again.
* This number must not be greater than yylength()!
* @param number the number of characters to be read again. This number must not
* be greater than yylength()!
*/
public void yypushback(int number) {
if (number > yylength())
zzScanError(ZZ_PUSHBACK_2BIG);
zzMarkedPos -= number;
}
/**
* Resumes scanning until the next regular expression is matched,
* the end of input is encountered or an I/O-Error occurs.
* Resumes scanning until the next regular expression is matched, the end of
* input is encountered or an I/O-Error occurs.
*
* @return the next token
* @exception java.io.IOException
* if any I/O-Error occurs
* @exception java.io.IOException if any I/O-Error occurs
*/
public org.fife.ui.rsyntaxtextarea.Token yylex() throws java.io.IOException {
int zzInput;
@@ -538,8 +517,7 @@ public class LatexTokenMaker extends AbstractJFlexTokenMaker {
zzAction = -1;
zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
zzState = zzLexicalState;
zzForAction:
{
zzForAction: {
while (true) {
if (zzCurrentPosL < zzEndReadL)
zzInput = zzBufferL[zzCurrentPosL++];
@@ -579,104 +557,105 @@ public class LatexTokenMaker extends AbstractJFlexTokenMaker {
// store back cached position
zzMarkedPos = zzMarkedPosL;
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
case 1: {
addToken(Token.IDENTIFIER);
}
case 13:
break;
case 8: {
addToken(Token.FUNCTION);
}
case 14:
break;
case 2: {
addToken(Token.WHITESPACE);
}
case 15:
break;
case 12: {
int temp = zzStartRead;
addToken(temp, temp + 5, Token.RESERVED_WORD);
addToken(temp + 6, temp + 6, Token.SEPARATOR);
addToken(temp + 7, zzMarkedPos - 2, Token.RESERVED_WORD);
addToken(zzMarkedPos - 1, zzMarkedPos - 1, Token.SEPARATOR);
}
case 16:
break;
case 10: {
int temp = zzStartRead;
addToken(start, zzStartRead - 1, Token.COMMENT_EOL);
addHyperlinkToken(temp, zzMarkedPos - 1, Token.COMMENT_EOL);
start = zzMarkedPos;
}
case 17:
break;
case 3: {
start = zzMarkedPos - 1;
yybegin(EOL_COMMENT);
}
case 18:
break;
case 11: {
int temp = zzStartRead;
addToken(temp, temp + 3, Token.RESERVED_WORD);
addToken(temp + 4, temp + 4, Token.SEPARATOR);
addToken(temp + 5, zzMarkedPos - 2, Token.RESERVED_WORD);
addToken(zzMarkedPos - 1, zzMarkedPos - 1, Token.SEPARATOR);
}
case 19:
break;
case 5: {
addNullToken();
return firstToken;
}
case 20:
break;
case 7: {
addToken(start, zzStartRead - 1, Token.COMMENT_EOL);
addNullToken();
return firstToken;
}
case 21:
break;
case 9: {
int temp = zzStartRead;
addToken(temp, temp, Token.SEPARATOR);
addToken(temp + 1, temp + 1, Token.IDENTIFIER);
}
case 22:
break;
case 6: {}
case 23:
break;
case 4: {
addToken(Token.SEPARATOR);
}
case 24:
break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
switch (zzLexicalState) {
case EOL_COMMENT: {
addToken(start, zzStartRead - 1, Token.COMMENT_EOL);
addNullToken();
return firstToken;
}
case 44:
break;
case YYINITIAL: {
addNullToken();
return firstToken;
}
case 45:
break;
default:
return null;
}
} else {
zzScanError(ZZ_NO_MATCH);
case 1: {
addToken(Token.IDENTIFIER);
}
case 13:
break;
case 8: {
addToken(Token.FUNCTION);
}
case 14:
break;
case 2: {
addToken(Token.WHITESPACE);
}
case 15:
break;
case 12: {
int temp = zzStartRead;
addToken(temp, temp + 5, Token.RESERVED_WORD);
addToken(temp + 6, temp + 6, Token.SEPARATOR);
addToken(temp + 7, zzMarkedPos - 2, Token.RESERVED_WORD);
addToken(zzMarkedPos - 1, zzMarkedPos - 1, Token.SEPARATOR);
}
case 16:
break;
case 10: {
int temp = zzStartRead;
addToken(start, zzStartRead - 1, Token.COMMENT_EOL);
addHyperlinkToken(temp, zzMarkedPos - 1, Token.COMMENT_EOL);
start = zzMarkedPos;
}
case 17:
break;
case 3: {
start = zzMarkedPos - 1;
yybegin(EOL_COMMENT);
}
case 18:
break;
case 11: {
int temp = zzStartRead;
addToken(temp, temp + 3, Token.RESERVED_WORD);
addToken(temp + 4, temp + 4, Token.SEPARATOR);
addToken(temp + 5, zzMarkedPos - 2, Token.RESERVED_WORD);
addToken(zzMarkedPos - 1, zzMarkedPos - 1, Token.SEPARATOR);
}
case 19:
break;
case 5: {
addNullToken();
return firstToken;
}
case 20:
break;
case 7: {
addToken(start, zzStartRead - 1, Token.COMMENT_EOL);
addNullToken();
return firstToken;
}
case 21:
break;
case 9: {
int temp = zzStartRead;
addToken(temp, temp, Token.SEPARATOR);
addToken(temp + 1, temp + 1, Token.IDENTIFIER);
}
case 22:
break;
case 6: {
}
case 23:
break;
case 4: {
addToken(Token.SEPARATOR);
}
case 24:
break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
switch (zzLexicalState) {
case EOL_COMMENT: {
addToken(start, zzStartRead - 1, Token.COMMENT_EOL);
addNullToken();
return firstToken;
}
case 44:
break;
case YYINITIAL: {
addNullToken();
return firstToken;
}
case 45:
break;
default:
return null;
}
} else {
zzScanError(ZZ_NO_MATCH);
}
}
}
}
@@ -17,14 +17,14 @@ import org.fife.ui.rsyntaxtextarea.TokenTypes;
* @version 1.0
*/
public class LessTokenMaker extends CSSTokenMaker {
/**
* Constructor; overridden to enable the niceties added by Less.
*/
public LessTokenMaker() {
setHighlightingLess(true);
}
/**
* {@inheritDoc}
*/
@@ -32,7 +32,7 @@ public class LessTokenMaker extends CSSTokenMaker {
public String[] getLineCommentStartAndEnd(int languageIndex) {
return new String[] { "//", null };
}
/**
* {@inheritDoc}
*/
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -23,16 +23,15 @@ import org.fife.ui.rsyntaxtextarea.TokenImpl;
*
* This implementation was created using
* <a href="http://www.jflex.de/">JFlex</a> 1.4.1; however, the generated file
* was modified for performance. Memory allocation needs to be almost
* completely removed to be competitive with the handwritten lexers (subclasses
* of <code>AbstractTokenMaker</code>, so this class has been modified so that
* was modified for performance. Memory allocation needs to be almost completely
* removed to be competitive with the handwritten lexers (subclasses of
* <code>AbstractTokenMaker</code>, so this class has been modified so that
* Strings are never allocated (via yytext()), and the scanner never has to
* worry about refilling its buffer (needlessly copying chars around).
* We can achieve this because RText always scans exactly 1 line of tokens at a
* time, and hands the scanner this line as an array of characters (a Segment
* really). Since tokens contain pointers to char arrays instead of Strings
* holding their contents, there is no need for allocating new memory for
* Strings.
* worry about refilling its buffer (needlessly copying chars around). We can
* achieve this because RText always scans exactly 1 line of tokens at a time,
* and hands the scanner this line as an array of characters (a Segment really).
* Since tokens contain pointers to char arrays instead of Strings holding their
* contents, there is no need for allocating new memory for Strings.
* <p>
*
* The actual algorithm generated for scanning has, of course, not been
@@ -42,16 +41,16 @@ import org.fife.ui.rsyntaxtextarea.TokenImpl;
* If you wish to regenerate this file yourself, keep in mind the following:
* <ul>
* <li>The generated <code>MakefileTokenMaker.java</code> file will contain two
* definitions of both <code>zzRefill</code> and <code>yyreset</code>.
* You should hand-delete the second of each definition (the ones
* generated by the lexer), as these generated methods modify the input
* buffer, which we'll never have to do.</li>
* <li>You should also change the declaration/definition of zzBuffer to NOT
* be initialized. This is a needless memory allocation for us since we
* will be pointing the array somewhere else anyway.</li>
* definitions of both <code>zzRefill</code> and <code>yyreset</code>. You
* should hand-delete the second of each definition (the ones generated by the
* lexer), as these generated methods modify the input buffer, which we'll never
* have to do.</li>
* <li>You should also change the declaration/definition of zzBuffer to NOT be
* initialized. This is a needless memory allocation for us since we will be
* pointing the array somewhere else anyway.</li>
* <li>You should NOT call <code>yylex()</code> on the generated scanner
* directly; rather, you should use <code>getTokenList</code> as you would
* with any other <code>TokenMaker</code> instance.</li>
* directly; rather, you should use <code>getTokenList</code> as you would with
* any other <code>TokenMaker</code> instance.</li>
* </ul>
*
* @author Robert Futrell
@@ -59,7 +58,7 @@ import org.fife.ui.rsyntaxtextarea.TokenImpl;
*
*/
public class MakefileTokenMaker extends AbstractJFlexTokenMaker {
/** This character denotes the end of file */
public static final int YYEOF = -1;
/** lexical states */
@@ -80,17 +79,17 @@ public class MakefileTokenMaker extends AbstractJFlexTokenMaker {
* Translates DFA states to action switch labels.
*/
private static final int[] ZZ_ACTION = zzUnpackAction();
private static final String ZZ_ACTION_PACKED_0 = "\2\0\2\1\1\2\2\1\1\3\1\4\1\5\1\6" + "\1\1\1\7\1\10\14\1\2\11\1\12\1\13\1\14"
+ "\1\15\1\16\1\17\1\20\1\5\1\6\1\21\2\0" + "\1\22\23\1\1\23\1\24\1\20\1\21\1\22\2\1" + "\1\25\43\1\1\25\14\1\1\25\5\1\1\0\2\1"
+ "\1\0\1\1\1\0\1\25";
private static final String ZZ_ACTION_PACKED_0 = "\2\0\2\1\1\2\2\1\1\3\1\4\1\5\1\6"
+ "\1\1\1\7\1\10\14\1\2\11\1\12\1\13\1\14" + "\1\15\1\16\1\17\1\20\1\5\1\6\1\21\2\0"
+ "\1\22\23\1\1\23\1\24\1\20\1\21\1\22\2\1" + "\1\25\43\1\1\25\14\1\1\25\5\1\1\0\2\1" + "\1\0\1\1\1\0\1\25";
private static int[] zzUnpackAction() {
int[] result = new int[129];
int offset = 0;
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAction(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -104,7 +103,7 @@ public class MakefileTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/**
* Translates a state to a row index in the transition table
*/
@@ -112,7 +111,8 @@ public class MakefileTokenMaker extends AbstractJFlexTokenMaker {
private static final String ZZ_ROWMAP_PACKED_0 = "\0\0\0\51\0\122\0\173\0\244\0\315\0\366\0\122"
+ "\0\u011f\0\u0148\0\u0171\0\u019a\0\u01c3\0\122\0\u01ec\0\u0215"
+ "\0\u023e\0\u0267\0\u0290\0\u02b9\0\u02e2\0\u030b\0\u0334\0\u035d"
+ "\0\u0386\0\u03af\0\u03d8\0\u0401\0\u042a\0\122\0\122\0\122" + "\0\122\0\122\0\122\0\u0453\0\u047c\0\122\0\u019a\0\u04a5"
+ "\0\u0386\0\u03af\0\u03d8\0\u0401\0\u042a\0\122\0\122\0\122"
+ "\0\122\0\122\0\122\0\u0453\0\u047c\0\122\0\u019a\0\u04a5"
+ "\0\122\0\u04ce\0\u04f7\0\u0520\0\u0549\0\u0572\0\u059b\0\u05c4"
+ "\0\u05ed\0\u0616\0\u063f\0\u0668\0\u0691\0\u06ba\0\u06e3\0\u070c"
+ "\0\u0735\0\u075e\0\u0787\0\u07b0\0\122\0\122\0\u0148\0\u0171"
@@ -124,14 +124,14 @@ public class MakefileTokenMaker extends AbstractJFlexTokenMaker {
+ "\0\u0def\0\u0e18\0\u0e41\0\u0e6a\0\u0e93\0\u0ebc\0\u0ee5\0\u0f0e"
+ "\0\u0f37\0\u0f60\0\u0f89\0\u0fb2\0\u0fdb\0\u1004\0\u102d\0\u1056"
+ "\0\u107f\0\u10a8\0\u10d1\0\u10fa\0\u1123\0\u114c\0\u1175\0\u119e" + "\0\122";
private static int[] zzUnpackRowMap() {
int[] result = new int[129];
int offset = 0;
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
return result;
}
private static int zzUnpackRowMap(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -142,60 +142,78 @@ public class MakefileTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/**
* The transition table of the DFA
*/
private static final int[] ZZ_TRANS = zzUnpackTrans();
private static final String ZZ_TRANS_PACKED_0 = "\1\3\1\4\1\5\1\6\1\7\2\3\1\10\1\11" + "\1\12\1\3\1\13\1\14\1\15\1\6\1\16\1\17"
+ "\1\20\1\21\1\4\1\22\1\23\1\24\1\4\1\25" + "\1\4\1\26\1\27\3\4\1\3\1\30\1\4\1\31" + "\2\4\1\32\1\4\2\3\4\33\1\34\10\33\1\35"
private static final String ZZ_TRANS_PACKED_0 = "\1\3\1\4\1\5\1\6\1\7\2\3\1\10\1\11"
+ "\1\12\1\3\1\13\1\14\1\15\1\6\1\16\1\17" + "\1\20\1\21\1\4\1\22\1\23\1\24\1\4\1\25"
+ "\1\4\1\26\1\27\3\4\1\3\1\30\1\4\1\31" + "\2\4\1\32\1\4\2\3\4\33\1\34\10\33\1\35"
+ "\31\33\1\36\1\37\52\0\2\4\1\40\14\0\17\4" + "\1\0\7\4\4\0\1\5\65\0\1\16\36\0\1\41"
+ "\1\42\52\0\1\11\40\0\7\12\1\0\1\12\1\43" + "\1\44\36\12\7\13\1\0\2\13\1\45\1\46\35\13"
+ "\7\47\1\0\2\47\1\50\1\47\1\51\34\47\7\15" + "\1\0\41\15\1\0\2\4\1\40\14\0\1\4\1\52" + "\15\4\1\0\7\4\3\0\2\4\1\40\14\0\4\4"
+ "\1\53\1\4\1\54\10\4\1\0\7\4\3\0\2\4" + "\1\40\14\0\1\55\16\4\1\0\7\4\3\0\2\4" + "\1\40\14\0\13\4\1\56\1\4\1\57\1\4\1\0"
+ "\7\4\3\0\2\4\1\40\14\0\6\4\1\60\10\4" + "\1\0\1\61\6\4\3\0\2\4\1\40\14\0\5\4" + "\1\62\11\4\1\0\7\4\3\0\2\4\1\40\14\0"
+ "\11\4\1\63\4\4\1\64\1\0\1\65\3\4\1\66" + "\2\4\3\0\2\4\1\40\14\0\1\67\16\4\1\0" + "\7\4\3\0\2\4\1\40\14\0\17\4\1\0\1\70"
+ "\6\4\3\0\2\4\1\40\14\0\3\4\1\71\13\4" + "\1\0\7\4\3\0\2\4\1\40\14\0\6\4\1\72" + "\10\4\1\0\1\73\6\4\3\0\2\4\1\40\14\0"
+ "\17\4\1\0\1\74\6\4\2\0\4\33\1\0\10\33" + "\1\0\31\33\7\0\1\75\1\76\42\0\7\35\1\0"
+ "\41\35\7\12\1\0\1\12\1\77\1\44\36\12\7\13" + "\1\0\2\13\1\45\1\100\35\13\7\47\1\0\2\47"
+ "\1\50\1\47\1\101\34\47\1\0\2\4\1\40\14\0" + "\1\4\1\102\15\4\1\0\7\4\3\0\2\4\1\40" + "\14\0\5\4\1\103\11\4\1\0\7\4\3\0\2\4"
+ "\1\40\14\0\3\4\1\104\13\4\1\0\7\4\3\0" + "\2\4\1\40\14\0\16\4\1\105\1\0\7\4\3\0" + "\2\4\1\40\14\0\1\4\1\106\15\4\1\0\7\4"
+ "\3\0\2\4\1\40\14\0\10\4\1\107\6\4\1\0" + "\7\4\3\0\2\4\1\40\14\0\3\4\1\110\7\4" + "\1\111\1\4\1\112\1\4\1\0\7\4\3\0\2\4"
+ "\1\40\14\0\3\4\1\113\13\4\1\0\7\4\3\0" + "\2\4\1\40\14\0\1\4\1\114\2\4\1\115\6\4" + "\1\116\3\4\1\0\7\4\3\0\2\4\1\40\14\0"
+ "\5\4\1\117\11\4\1\0\7\4\3\0\2\4\1\40" + "\14\0\3\4\1\120\13\4\1\0\7\4\3\0\2\4" + "\1\40\14\0\3\4\1\121\13\4\1\0\7\4\3\0"
+ "\2\4\1\40\14\0\4\4\1\122\12\4\1\0\7\4" + "\3\0\2\4\1\40\14\0\10\4\1\123\6\4\1\0" + "\7\4\3\0\2\4\1\40\14\0\16\4\1\124\1\0"
+ "\7\4\3\0\2\4\1\40\14\0\6\4\1\125\10\4" + "\1\0\7\4\3\0\2\4\1\40\14\0\15\4\1\126" + "\1\4\1\0\7\4\3\0\2\4\1\40\14\0\3\4"
+ "\1\127\13\4\1\0\7\4\3\0\2\4\1\40\14\0" + "\6\4\1\130\10\4\1\0\7\4\3\0\2\4\1\40" + "\14\0\2\4\1\131\5\4\1\132\6\4\1\0\7\4"
+ "\3\0\2\4\1\40\14\0\6\4\1\133\10\4\1\0" + "\7\4\3\0\2\4\1\40\14\0\17\4\1\0\4\4" + "\1\134\2\4\3\0\2\4\1\40\14\0\4\4\1\135"
+ "\1\4\1\135\10\4\1\0\7\4\3\0\2\4\1\40" + "\14\0\4\4\1\104\12\4\1\0\7\4\3\0\2\4" + "\1\40\14\0\10\4\1\136\6\4\1\0\7\4\3\0"
+ "\2\4\1\40\14\0\1\4\1\137\15\4\1\0\7\4" + "\3\0\2\4\1\40\14\0\16\4\1\140\1\0\7\4" + "\3\0\2\4\1\40\14\0\4\4\1\141\12\4\1\0"
+ "\7\4\3\0\2\4\1\40\14\0\4\4\1\135\12\4" + "\1\0\7\4\3\0\2\4\1\40\14\0\17\4\1\0" + "\6\4\1\104\3\0\2\4\1\40\14\0\1\4\1\114"
+ "\2\4\1\115\12\4\1\0\7\4\3\0\2\4\1\40" + "\14\0\5\4\1\142\11\4\1\0\7\4\3\0\2\4" + "\1\40\14\0\6\4\1\143\10\4\1\0\7\4\3\0"
+ "\2\4\1\40\14\0\16\4\1\104\1\0\7\4\3\0" + "\2\4\1\40\14\0\15\4\1\144\1\4\1\0\7\4" + "\3\0\2\4\1\40\14\0\4\4\1\145\12\4\1\0"
+ "\7\4\3\0\2\4\1\40\14\0\1\4\1\146\15\4" + "\1\0\7\4\3\0\2\4\1\40\14\0\17\4\1\0" + "\1\4\1\74\5\4\3\0\2\4\1\40\14\0\1\4"
+ "\1\147\15\4\1\0\7\4\3\0\2\4\1\40\14\0" + "\1\4\1\150\15\4\1\0\7\4\3\0\2\4\1\40" + "\14\0\13\4\1\104\3\4\1\0\7\4\3\0\2\4"
+ "\1\40\14\0\3\4\1\151\13\4\1\0\7\4\3\0" + "\2\4\1\40\14\0\11\4\1\63\5\4\1\0\7\4" + "\3\0\2\4\1\40\14\0\13\4\1\107\3\4\1\0"
+ "\7\4\3\0\2\4\1\40\14\0\10\4\1\152\6\4" + "\1\0\7\4\3\0\2\4\1\40\14\0\5\4\1\104" + "\11\4\1\0\7\4\3\0\2\4\1\40\14\0\16\4"
+ "\1\153\1\0\7\4\3\0\2\4\1\40\14\0\10\4" + "\1\154\6\4\1\0\7\4\3\0\2\4\1\40\14\0" + "\4\4\1\155\12\4\1\0\7\4\3\0\2\4\1\40"
+ "\14\0\1\156\16\4\1\0\7\4\3\0\2\4\1\40" + "\14\0\6\4\1\157\10\4\1\0\7\4\3\0\2\4" + "\1\40\14\0\2\4\1\104\14\4\1\0\7\4\3\0"
+ "\2\4\1\40\14\0\15\4\1\104\1\4\1\0\7\4" + "\3\0\2\4\1\40\14\0\13\4\1\160\3\4\1\0" + "\7\4\3\0\2\4\1\40\14\0\6\4\1\54\10\4"
+ "\1\0\7\4\3\0\2\4\1\40\14\0\17\4\1\0" + "\3\4\1\161\3\4\3\0\2\4\1\40\14\0\10\4" + "\1\104\6\4\1\0\7\4\3\0\2\4\1\40\14\0"
+ "\4\4\1\117\12\4\1\0\7\4\3\0\2\4\1\40" + "\14\0\11\4\1\162\5\4\1\0\7\4\3\0\2\4" + "\1\40\14\0\17\4\1\0\2\4\1\163\4\4\3\0"
+ "\2\4\1\40\14\0\16\4\1\164\1\0\7\4\3\0" + "\2\4\1\40\14\0\3\4\1\165\13\4\1\0\7\4" + "\3\0\2\4\1\40\14\0\17\4\1\0\3\4\1\166"
+ "\3\4\3\0\2\4\1\40\14\0\7\4\1\104\7\4" + "\1\0\7\4\3\0\2\4\1\40\14\0\1\167\16\4" + "\1\0\7\4\3\0\2\4\1\40\14\0\1\170\16\4"
+ "\1\0\7\4\3\0\2\4\1\40\14\0\12\4\1\171" + "\4\4\1\0\7\4\3\0\2\4\1\40\14\0\17\4" + "\1\0\1\170\6\4\3\0\2\4\1\40\14\0\3\4"
+ "\1\172\13\4\1\0\7\4\3\0\2\4\1\40\14\0" + "\17\4\1\173\7\4\3\0\2\4\1\40\14\0\17\4" + "\1\0\4\4\1\104\2\4\3\0\2\4\1\40\14\0"
+ "\14\4\1\107\2\4\1\0\7\4\3\0\2\4\1\40" + "\14\0\3\4\1\174\13\4\1\0\7\4\3\0\2\4" + "\1\40\14\0\10\4\1\121\6\4\1\0\7\4\3\0"
+ "\2\4\1\40\14\0\6\4\1\175\10\4\1\0\7\4" + "\42\0\1\176\11\0\2\4\1\40\14\0\1\4\1\104" + "\15\4\1\0\7\4\3\0\2\4\1\40\14\0\13\4"
+ "\7\47\1\0\2\47\1\50\1\47\1\51\34\47\7\15" + "\1\0\41\15\1\0\2\4\1\40\14\0\1\4\1\52"
+ "\15\4\1\0\7\4\3\0\2\4\1\40\14\0\4\4" + "\1\53\1\4\1\54\10\4\1\0\7\4\3\0\2\4"
+ "\1\40\14\0\1\55\16\4\1\0\7\4\3\0\2\4" + "\1\40\14\0\13\4\1\56\1\4\1\57\1\4\1\0"
+ "\7\4\3\0\2\4\1\40\14\0\6\4\1\60\10\4" + "\1\0\1\61\6\4\3\0\2\4\1\40\14\0\5\4"
+ "\1\62\11\4\1\0\7\4\3\0\2\4\1\40\14\0" + "\11\4\1\63\4\4\1\64\1\0\1\65\3\4\1\66"
+ "\2\4\3\0\2\4\1\40\14\0\1\67\16\4\1\0" + "\7\4\3\0\2\4\1\40\14\0\17\4\1\0\1\70"
+ "\6\4\3\0\2\4\1\40\14\0\3\4\1\71\13\4" + "\1\0\7\4\3\0\2\4\1\40\14\0\6\4\1\72"
+ "\10\4\1\0\1\73\6\4\3\0\2\4\1\40\14\0" + "\17\4\1\0\1\74\6\4\2\0\4\33\1\0\10\33"
+ "\1\0\31\33\7\0\1\75\1\76\42\0\7\35\1\0" + "\41\35\7\12\1\0\1\12\1\77\1\44\36\12\7\13"
+ "\1\0\2\13\1\45\1\100\35\13\7\47\1\0\2\47" + "\1\50\1\47\1\101\34\47\1\0\2\4\1\40\14\0"
+ "\1\4\1\102\15\4\1\0\7\4\3\0\2\4\1\40" + "\14\0\5\4\1\103\11\4\1\0\7\4\3\0\2\4"
+ "\1\40\14\0\3\4\1\104\13\4\1\0\7\4\3\0" + "\2\4\1\40\14\0\16\4\1\105\1\0\7\4\3\0"
+ "\2\4\1\40\14\0\1\4\1\106\15\4\1\0\7\4" + "\3\0\2\4\1\40\14\0\10\4\1\107\6\4\1\0"
+ "\7\4\3\0\2\4\1\40\14\0\3\4\1\110\7\4" + "\1\111\1\4\1\112\1\4\1\0\7\4\3\0\2\4"
+ "\1\40\14\0\3\4\1\113\13\4\1\0\7\4\3\0" + "\2\4\1\40\14\0\1\4\1\114\2\4\1\115\6\4"
+ "\1\116\3\4\1\0\7\4\3\0\2\4\1\40\14\0" + "\5\4\1\117\11\4\1\0\7\4\3\0\2\4\1\40"
+ "\14\0\3\4\1\120\13\4\1\0\7\4\3\0\2\4" + "\1\40\14\0\3\4\1\121\13\4\1\0\7\4\3\0"
+ "\2\4\1\40\14\0\4\4\1\122\12\4\1\0\7\4" + "\3\0\2\4\1\40\14\0\10\4\1\123\6\4\1\0"
+ "\7\4\3\0\2\4\1\40\14\0\16\4\1\124\1\0" + "\7\4\3\0\2\4\1\40\14\0\6\4\1\125\10\4"
+ "\1\0\7\4\3\0\2\4\1\40\14\0\15\4\1\126" + "\1\4\1\0\7\4\3\0\2\4\1\40\14\0\3\4"
+ "\1\127\13\4\1\0\7\4\3\0\2\4\1\40\14\0" + "\6\4\1\130\10\4\1\0\7\4\3\0\2\4\1\40"
+ "\14\0\2\4\1\131\5\4\1\132\6\4\1\0\7\4" + "\3\0\2\4\1\40\14\0\6\4\1\133\10\4\1\0"
+ "\7\4\3\0\2\4\1\40\14\0\17\4\1\0\4\4" + "\1\134\2\4\3\0\2\4\1\40\14\0\4\4\1\135"
+ "\1\4\1\135\10\4\1\0\7\4\3\0\2\4\1\40" + "\14\0\4\4\1\104\12\4\1\0\7\4\3\0\2\4"
+ "\1\40\14\0\10\4\1\136\6\4\1\0\7\4\3\0" + "\2\4\1\40\14\0\1\4\1\137\15\4\1\0\7\4"
+ "\3\0\2\4\1\40\14\0\16\4\1\140\1\0\7\4" + "\3\0\2\4\1\40\14\0\4\4\1\141\12\4\1\0"
+ "\7\4\3\0\2\4\1\40\14\0\4\4\1\135\12\4" + "\1\0\7\4\3\0\2\4\1\40\14\0\17\4\1\0"
+ "\6\4\1\104\3\0\2\4\1\40\14\0\1\4\1\114" + "\2\4\1\115\12\4\1\0\7\4\3\0\2\4\1\40"
+ "\14\0\5\4\1\142\11\4\1\0\7\4\3\0\2\4" + "\1\40\14\0\6\4\1\143\10\4\1\0\7\4\3\0"
+ "\2\4\1\40\14\0\16\4\1\104\1\0\7\4\3\0" + "\2\4\1\40\14\0\15\4\1\144\1\4\1\0\7\4"
+ "\3\0\2\4\1\40\14\0\4\4\1\145\12\4\1\0" + "\7\4\3\0\2\4\1\40\14\0\1\4\1\146\15\4"
+ "\1\0\7\4\3\0\2\4\1\40\14\0\17\4\1\0" + "\1\4\1\74\5\4\3\0\2\4\1\40\14\0\1\4"
+ "\1\147\15\4\1\0\7\4\3\0\2\4\1\40\14\0" + "\1\4\1\150\15\4\1\0\7\4\3\0\2\4\1\40"
+ "\14\0\13\4\1\104\3\4\1\0\7\4\3\0\2\4" + "\1\40\14\0\3\4\1\151\13\4\1\0\7\4\3\0"
+ "\2\4\1\40\14\0\11\4\1\63\5\4\1\0\7\4" + "\3\0\2\4\1\40\14\0\13\4\1\107\3\4\1\0"
+ "\7\4\3\0\2\4\1\40\14\0\10\4\1\152\6\4" + "\1\0\7\4\3\0\2\4\1\40\14\0\5\4\1\104"
+ "\11\4\1\0\7\4\3\0\2\4\1\40\14\0\16\4" + "\1\153\1\0\7\4\3\0\2\4\1\40\14\0\10\4"
+ "\1\154\6\4\1\0\7\4\3\0\2\4\1\40\14\0" + "\4\4\1\155\12\4\1\0\7\4\3\0\2\4\1\40"
+ "\14\0\1\156\16\4\1\0\7\4\3\0\2\4\1\40" + "\14\0\6\4\1\157\10\4\1\0\7\4\3\0\2\4"
+ "\1\40\14\0\2\4\1\104\14\4\1\0\7\4\3\0" + "\2\4\1\40\14\0\15\4\1\104\1\4\1\0\7\4"
+ "\3\0\2\4\1\40\14\0\13\4\1\160\3\4\1\0" + "\7\4\3\0\2\4\1\40\14\0\6\4\1\54\10\4"
+ "\1\0\7\4\3\0\2\4\1\40\14\0\17\4\1\0" + "\3\4\1\161\3\4\3\0\2\4\1\40\14\0\10\4"
+ "\1\104\6\4\1\0\7\4\3\0\2\4\1\40\14\0" + "\4\4\1\117\12\4\1\0\7\4\3\0\2\4\1\40"
+ "\14\0\11\4\1\162\5\4\1\0\7\4\3\0\2\4" + "\1\40\14\0\17\4\1\0\2\4\1\163\4\4\3\0"
+ "\2\4\1\40\14\0\16\4\1\164\1\0\7\4\3\0" + "\2\4\1\40\14\0\3\4\1\165\13\4\1\0\7\4"
+ "\3\0\2\4\1\40\14\0\17\4\1\0\3\4\1\166" + "\3\4\3\0\2\4\1\40\14\0\7\4\1\104\7\4"
+ "\1\0\7\4\3\0\2\4\1\40\14\0\1\167\16\4" + "\1\0\7\4\3\0\2\4\1\40\14\0\1\170\16\4"
+ "\1\0\7\4\3\0\2\4\1\40\14\0\12\4\1\171" + "\4\4\1\0\7\4\3\0\2\4\1\40\14\0\17\4"
+ "\1\0\1\170\6\4\3\0\2\4\1\40\14\0\3\4" + "\1\172\13\4\1\0\7\4\3\0\2\4\1\40\14\0"
+ "\17\4\1\173\7\4\3\0\2\4\1\40\14\0\17\4" + "\1\0\4\4\1\104\2\4\3\0\2\4\1\40\14\0"
+ "\14\4\1\107\2\4\1\0\7\4\3\0\2\4\1\40" + "\14\0\3\4\1\174\13\4\1\0\7\4\3\0\2\4"
+ "\1\40\14\0\10\4\1\121\6\4\1\0\7\4\3\0" + "\2\4\1\40\14\0\6\4\1\175\10\4\1\0\7\4"
+ "\42\0\1\176\11\0\2\4\1\40\14\0\1\4\1\104" + "\15\4\1\0\7\4\3\0\2\4\1\40\14\0\13\4"
+ "\1\177\3\4\1\0\7\4\33\0\1\200\20\0\2\4" + "\1\40\14\0\17\4\1\0\1\4\1\104\5\4\40\0" + "\1\201\12\0";
private static int[] zzUnpackTrans() {
int[] result = new int[4551];
int offset = 0;
offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
return result;
}
private static int zzUnpackTrans(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -210,7 +228,7 @@ public class MakefileTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/* error codes */
private static final int ZZ_UNKNOWN_ERROR = 0;
private static final int ZZ_NO_MATCH = 1;
@@ -222,16 +240,16 @@ public class MakefileTokenMaker extends AbstractJFlexTokenMaker {
* ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
*/
private static final int[] ZZ_ATTRIBUTE = zzUnpackAttribute();
private static final String ZZ_ATTRIBUTE_PACKED_0 = "\2\0\1\11\4\1\1\11\5\1\1\11\17\1\6\11" + "\2\1\1\11\2\0\1\11\23\1\2\11\74\1\1\0"
+ "\2\1\1\0\1\1\1\0\1\11";
private static final String ZZ_ATTRIBUTE_PACKED_0 = "\2\0\1\11\4\1\1\11\5\1\1\11\17\1\6\11"
+ "\2\1\1\11\2\0\1\11\23\1\2\11\74\1\1\0" + "\2\1\1\0\1\1\1\0\1\11";
private static int[] zzUnpackAttribute() {
int[] result = new int[129];
int offset = 0;
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAttribute(String packed, int offset, int[] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
@@ -245,7 +263,7 @@ public class MakefileTokenMaker extends AbstractJFlexTokenMaker {
}
return j;
}
/** the input device */
private java.io.Reader zzReader;
/** the current state of the DFA */
@@ -253,8 +271,8 @@ public class MakefileTokenMaker extends AbstractJFlexTokenMaker {
/** the current lexical state */
private int zzLexicalState = YYINITIAL;
/**
* this buffer contains the current text to be matched and is
* the source of the yytext() string
* this buffer contains the current text to be matched and is the source of the
* yytext() string
*/
private char zzBuffer[];
/** the textposition at the last accepting state */
@@ -264,63 +282,55 @@ public class MakefileTokenMaker extends AbstractJFlexTokenMaker {
/** startRead marks the beginning of the yytext() string in the buffer */
private int zzStartRead;
/**
* endRead marks the last character in the buffer, that has been read
* from input
* endRead marks the last character in the buffer, that has been read from input
*/
private int zzEndRead;
/** zzAtEOF == true <=> the scanner is at the EOF */
private boolean zzAtEOF;
/* user code: */
private Stack<Boolean> varDepths;
/**
* Constructor. This must be here because JFlex does not generate a
* no-parameter constructor.
* Constructor. This must be here because JFlex does not generate a no-parameter
* constructor.
*/
public MakefileTokenMaker() {}
public MakefileTokenMaker() {
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType
* The token's type.
* @param tokenType The token's type.
*/
private void addToken(int tokenType) {
addToken(zzStartRead, zzMarkedPos - 1, tokenType);
}
/**
* Adds the token specified to the current linked list of tokens.
*
* @param tokenType
* The token's type.
* @param tokenType The token's type.
*/
private void addToken(int start, int end, int tokenType) {
int so = start + offsetShift;
addToken(zzBuffer, start, end, tokenType, so);
}
/**
* 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 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.
*/
@Override
public void addToken(char[] array, int start, int end, int tokenType, int startOffset) {
super.addToken(array, start, end, tokenType, startOffset);
zzStartRead = zzMarkedPos;
}
/**
* {@inheritDoc}
*/
@@ -328,35 +338,30 @@ public class MakefileTokenMaker extends AbstractJFlexTokenMaker {
public String[] getLineCommentStartAndEnd(int languageIndex) {
return new String[] { "#", null };
}
/**
* Returns whether tokens of the specified type should have "mark
* occurrences" enabled for the current programming language.
* Returns whether tokens of the specified type should have "mark occurrences"
* enabled for the current programming language.
*
* @param type
* The token type.
* @return Whether tokens of this type should have "mark occurrences"
* enabled.
* @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 || type == Token.VARIABLE;
}
/**
* Returns the first token in the linked list of tokens generated
* from <code>text</code>. This method must be implemented by
* subclasses so they can correctly implement syntax highlighting.
* Returns the first token in the linked list of tokens generated from
* <code>text</code>. This method must be implemented by subclasses so they can
* correctly implement syntax highlighting.
*
* @param text
* The text from which to get tokens.
* @param initialTokenType
* The token type we should start with.
* @param startOffset
* The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing
* the syntax highlighted text.
* @param text The text from which to get tokens.
* @param initialTokenType The token type we should start with.
* @param startOffset The offset into the document at which
* <code>text</code> starts.
* @return The first <code>Token</code> in a linked list representing the syntax
* highlighted text.
*/
@Override
public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
@@ -372,36 +377,34 @@ public class MakefileTokenMaker extends AbstractJFlexTokenMaker {
return new TokenImpl();
}
}
/**
* Refills the input buffer.
*
* @return <code>true</code> if EOF was reached, otherwise
* <code>false</code>.
* @return <code>true</code> if EOF was reached, otherwise <code>false</code>.
*/
private boolean zzRefill() {
return zzCurrentPos >= s.offset + s.count;
}
/**
* Resets the scanner to read from a new input stream.
* Does not close the old reader.
* Resets the scanner to read from a new input stream. Does not close the old
* reader.
*
* All internal variables are reset, the old input stream
* <b>cannot</b> be reused (internal buffer is discarded and lost).
* Lexical state is set to <tt>YY_INITIAL</tt>.
* All internal variables are reset, the old input stream <b>cannot</b> be
* reused (internal buffer is discarded and lost). Lexical state is set to
* <tt>YY_INITIAL</tt>.
*
* @param reader
* the new input stream
* @param reader the new input stream
*/
public final void yyreset(Reader reader) {
// 's' has been updated.
zzBuffer = s.array;
/*
* We replaced the line below with the two below it because zzRefill
* no longer "refills" the buffer (since the way we do it, it's always
* "full" the first time through, since it points to the segment's
* array). So, we assign zzEndRead here.
* We replaced the line below with the two below it because zzRefill no longer
* "refills" the buffer (since the way we do it, it's always "full" the first
* time through, since it points to the segment's array). So, we assign
* zzEndRead here.
*/
// zzStartRead = zzEndRead = s.offset;
zzStartRead = s.offset;
@@ -411,34 +414,31 @@ public class MakefileTokenMaker extends AbstractJFlexTokenMaker {
zzReader = reader;
zzAtEOF = false;
}
/**
* Creates a new scanner
* There is also a java.io.InputStream version of this constructor.
* Creates a new scanner There is also a java.io.InputStream version of this
* constructor.
*
* @param in
* the java.io.Reader to read input from.
* @param in the java.io.Reader to read input from.
*/
public MakefileTokenMaker(java.io.Reader in) {
this.zzReader = in;
}
/**
* Creates a new scanner.
* There is also java.io.Reader version of this constructor.
* Creates a new scanner. There is also java.io.Reader version of this
* constructor.
*
* @param in
* the java.io.Inputstream to read input from.
* @param in the java.io.Inputstream to read input from.
*/
public MakefileTokenMaker(java.io.InputStream in) {
this(new java.io.InputStreamReader(in));
}
/**
* Unpacks the compressed character translation table.
*
* @param packed
* the packed character translation table
* @param packed the packed character translation table
* @return the unpacked character translation table
*/
private static char[] zzUnpackCMap(String packed) {
@@ -454,7 +454,7 @@ public class MakefileTokenMaker extends AbstractJFlexTokenMaker {
}
return map;
}
/**
* Closes the input stream.
*/
@@ -464,69 +464,64 @@ public class MakefileTokenMaker extends AbstractJFlexTokenMaker {
if (zzReader != null)
zzReader.close();
}
/**
* Returns the current lexical state.
*/
public final int yystate() {
return zzLexicalState;
}
/**
* Enters a new lexical state
*
* @param newState
* the new lexical state
* @param newState the new lexical state
*/
@Override
public final void yybegin(int newState) {
zzLexicalState = newState;
}
/**
* Returns the text matched by the current regular expression.
*/
public final String yytext() {
return new String(zzBuffer, zzStartRead, zzMarkedPos - zzStartRead);
}
/**
* Returns the character at position <tt>pos</tt> from the
* matched text.
* Returns the character at position <tt>pos</tt> from the matched text.
*
* It is equivalent to yytext().charAt(pos), but faster
*
* @param pos
* the position of the character to fetch.
* A value from 0 to yylength()-1.
* @param pos the position of the character to fetch. A value from 0 to
* yylength()-1.
*
* @return the character at position pos
*/
public final char yycharat(int pos) {
return zzBuffer[zzStartRead + pos];
}
/**
* Returns the length of the matched text region.
*/
public final int yylength() {
return zzMarkedPos - zzStartRead;
}
/**
* Reports an error that occured while scanning.
*
* In a wellformed scanner (no or only correct usage of
* yypushback(int) and a match-all fallback rule) this method
* will only be called with things that "Can't Possibly Happen".
* If this method is called, something is seriously wrong
* (e.g. a JFlex bug producing a faulty scanner etc.).
* In a wellformed scanner (no or only correct usage of yypushback(int) and a
* match-all fallback rule) this method will only be called with things that
* "Can't Possibly Happen". If this method is called, something is seriously
* wrong (e.g. a JFlex bug producing a faulty scanner etc.).
*
* Usual syntax/scanner level error handling should be done
* in error fallback rules.
* Usual syntax/scanner level error handling should be done in error fallback
* rules.
*
* @param errorCode
* the code of the errormessage to display
* @param errorCode the code of the errormessage to display
*/
private void zzScanError(int errorCode) {
String message;
@@ -537,29 +532,27 @@ public class MakefileTokenMaker extends AbstractJFlexTokenMaker {
}
throw new Error(message);
}
/**
* Pushes the specified amount of characters back into the input stream.
*
* They will be read again by then next call of the scanning method
*
* @param number
* the number of characters to be read again.
* This number must not be greater than yylength()!
* @param number the number of characters to be read again. This number must not
* be greater than yylength()!
*/
public void yypushback(int number) {
if (number > yylength())
zzScanError(ZZ_PUSHBACK_2BIG);
zzMarkedPos -= number;
}
/**
* Resumes scanning until the next regular expression is matched,
* the end of input is encountered or an I/O-Error occurs.
* Resumes scanning until the next regular expression is matched, the end of
* input is encountered or an I/O-Error occurs.
*
* @return the next token
* @exception java.io.IOException
* if any I/O-Error occurs
* @exception java.io.IOException if any I/O-Error occurs
*/
public org.fife.ui.rsyntaxtextarea.Token yylex() throws java.io.IOException {
int zzInput;
@@ -578,8 +571,7 @@ public class MakefileTokenMaker extends AbstractJFlexTokenMaker {
zzAction = -1;
zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
zzState = zzLexicalState;
zzForAction:
{
zzForAction: {
while (true) {
if (zzCurrentPosL < zzEndReadL)
zzInput = zzBufferL[zzCurrentPosL++];
@@ -619,170 +611,171 @@ public class MakefileTokenMaker extends AbstractJFlexTokenMaker {
// store back cached position
zzMarkedPos = zzMarkedPosL;
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
case 13: {
addToken(Token.PREPROCESSOR);
case 13: {
addToken(Token.PREPROCESSOR);
}
case 22:
break;
case 15: {
if (varDepths == null) {
varDepths = new Stack<Boolean>();
} else {
varDepths.clear();
}
case 22:
break;
case 15: {
if (varDepths == null) {
varDepths = new Stack<Boolean>();
} else {
varDepths.clear();
}
varDepths.push(Boolean.FALSE);
start = zzMarkedPos - 2;
yybegin(VAR);
}
case 23:
break;
case 3: {
addNullToken();
return firstToken;
}
case 24:
break;
case 16: {
addToken(Token.LITERAL_CHAR);
}
case 25:
break;
case 12: {
if (!varDepths.empty() && varDepths.peek() == Boolean.TRUE) {
varDepths.pop();
if (varDepths.empty()) {
addToken(start, zzStartRead, Token.VARIABLE);
yybegin(YYINITIAL);
}
varDepths.push(Boolean.FALSE);
start = zzMarkedPos - 2;
yybegin(VAR);
}
case 23:
break;
case 3: {
addNullToken();
return firstToken;
}
case 24:
break;
case 16: {
addToken(Token.LITERAL_CHAR);
}
case 25:
break;
case 12: {
if (!varDepths.empty() && varDepths.peek() == Boolean.TRUE) {
varDepths.pop();
if (varDepths.empty()) {
addToken(start, zzStartRead, Token.VARIABLE);
yybegin(YYINITIAL);
}
}
case 26:
break;
case 11: {
if (!varDepths.empty() && varDepths.peek() == Boolean.FALSE) {
varDepths.pop();
if (varDepths.empty()) {
addToken(start, zzStartRead, Token.VARIABLE);
yybegin(YYINITIAL);
}
}
case 26:
break;
case 11: {
if (!varDepths.empty() && varDepths.peek() == Boolean.FALSE) {
varDepths.pop();
if (varDepths.empty()) {
addToken(start, zzStartRead, Token.VARIABLE);
yybegin(YYINITIAL);
}
}
case 27:
break;
case 4: {
addToken(Token.WHITESPACE);
}
case 27:
break;
case 4: {
addToken(Token.WHITESPACE);
}
case 28:
break;
case 21: {
addToken(Token.RESERVED_WORD);
}
case 29:
break;
case 20: {
varDepths.push(Boolean.FALSE);
}
case 30:
break;
case 18: {
addToken(Token.LITERAL_BACKQUOTE);
}
case 31:
break;
case 19: {
varDepths.push(Boolean.TRUE);
}
case 32:
break;
case 1: {
addToken(Token.IDENTIFIER);
}
case 33:
break;
case 14: {
if (varDepths == null) {
varDepths = new Stack<Boolean>();
} else {
varDepths.clear();
}
case 28:
break;
case 21: {
addToken(Token.RESERVED_WORD);
}
case 29:
break;
case 20: {
varDepths.push(Boolean.FALSE);
}
case 30:
break;
case 18: {
addToken(Token.LITERAL_BACKQUOTE);
}
case 31:
break;
case 19: {
varDepths.push(Boolean.TRUE);
}
case 32:
break;
case 1: {
addToken(Token.IDENTIFIER);
}
case 33:
break;
case 14: {
if (varDepths == null) {
varDepths = new Stack<Boolean>();
} else {
varDepths.clear();
varDepths.push(Boolean.TRUE);
start = zzMarkedPos - 2;
yybegin(VAR);
}
case 34:
break;
case 5: {
addToken(Token.ERROR_CHAR);
addNullToken();
return firstToken;
}
case 35:
break;
case 6: {
addToken(Token.ERROR_STRING_DOUBLE);
addNullToken();
return firstToken;
}
case 36:
break;
case 10: {
int temp1 = zzStartRead;
int temp2 = zzMarkedPos;
addToken(start, zzStartRead - 1, Token.VARIABLE);
addToken(temp1, temp2 - 1, Token.COMMENT_EOL);
addNullToken();
return firstToken;
}
case 37:
break;
case 17: {
addToken(Token.LITERAL_STRING_DOUBLE_QUOTE);
}
case 38:
break;
case 7: {
addToken(Token.COMMENT_EOL);
addNullToken();
return firstToken;
}
case 39:
break;
case 2: {
addToken(Token.LITERAL_NUMBER_DECIMAL_INT);
}
case 40:
break;
case 8: {
addToken(Token.OPERATOR);
}
case 41:
break;
case 9: {
}
case 42:
break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
switch (zzLexicalState) {
case VAR: {
addToken(start, zzStartRead - 1, Token.VARIABLE);
addNullToken();
return firstToken;
}
varDepths.push(Boolean.TRUE);
start = zzMarkedPos - 2;
yybegin(VAR);
}
case 34:
break;
case 5: {
addToken(Token.ERROR_CHAR);
addNullToken();
return firstToken;
}
case 35:
break;
case 6: {
addToken(Token.ERROR_STRING_DOUBLE);
addNullToken();
return firstToken;
}
case 36:
break;
case 10: {
int temp1 = zzStartRead;
int temp2 = zzMarkedPos;
addToken(start, zzStartRead - 1, Token.VARIABLE);
addToken(temp1, temp2 - 1, Token.COMMENT_EOL);
addNullToken();
return firstToken;
}
case 37:
break;
case 17: {
addToken(Token.LITERAL_STRING_DOUBLE_QUOTE);
}
case 38:
break;
case 7: {
addToken(Token.COMMENT_EOL);
addNullToken();
return firstToken;
}
case 39:
break;
case 2: {
addToken(Token.LITERAL_NUMBER_DECIMAL_INT);
}
case 40:
break;
case 8: {
addToken(Token.OPERATOR);
}
case 41:
break;
case 9: {}
case 42:
break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
switch (zzLexicalState) {
case VAR: {
addToken(start, zzStartRead - 1, Token.VARIABLE);
addNullToken();
return firstToken;
}
case 130:
break;
case YYINITIAL: {
addNullToken();
return firstToken;
}
case 131:
break;
default:
return null;
}
} else {
zzScanError(ZZ_NO_MATCH);
case 130:
break;
case YYINITIAL: {
addNullToken();
return firstToken;
}
case 131:
break;
default:
return null;
}
} else {
zzScanError(ZZ_NO_MATCH);
}
}
}
}
File diff suppressed because it is too large. Load diff
Loaded 100 of 211 files, more files were not shown because too many files have changed in this diff. Show more