Search in sources :

Example 1 with TokenImpl

use of org.fife.ui.rsyntaxtextarea.TokenImpl in project jadx by skylot.

the class JadxTokenMaker method concatTokensUntil.

@Nullable
private Token concatTokensUntil(Token start, String endText) {
    StringBuilder sb = new StringBuilder();
    Token current = start;
    while (current != null && current.getType() != TokenTypes.NULL) {
        String text = current.getLexeme();
        if (text != null) {
            sb.append(text);
            if (text.equals(endText)) {
                char[] line = sb.toString().toCharArray();
                TokenImpl token = new TokenImpl(line, 0, line.length - 1, start.getOffset(), start.getType(), start.getLanguageIndex());
                token.setNextToken(current.getNextToken());
                return token;
            }
        }
        current = current.getNextToken();
    }
    return null;
}
Also used : TokenImpl(org.fife.ui.rsyntaxtextarea.TokenImpl) Token(org.fife.ui.rsyntaxtextarea.Token) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with TokenImpl

use of org.fife.ui.rsyntaxtextarea.TokenImpl in project Brino by BrinoOficial.

the class BrinoSyntax method getTokenList.

/**
 * 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.
 */
public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
    resetTokenList();
    this.offsetShift = -text.offset + startOffset;
    // Start off in the proper state.
    int state = Token.NULL;
    switch(initialTokenType) {
        case Token.COMMENT_MULTILINE:
            state = MLC;
            start = text.offset;
            break;
        /* No documentation comments */
        default:
            state = Token.NULL;
    }
    s = text;
    try {
        yyreset(zzReader);
        yybegin(state);
        return yylex();
    } catch (IOException ioe) {
        ioe.printStackTrace();
        return new TokenImpl();
    }
}
Also used : TokenImpl(org.fife.ui.rsyntaxtextarea.TokenImpl) IOException(java.io.IOException)

Example 3 with TokenImpl

use of org.fife.ui.rsyntaxtextarea.TokenImpl in project jadx by skylot.

the class JadxTokenMaker method mergeLongClassNames.

@NotNull
private Token mergeLongClassNames(Token prev, Token current, boolean annotation) {
    int offset = current.getTextOffset();
    if (annotation) {
        offset++;
    }
    JavaNode javaNode = codeArea.getJavaNodeAtOffset(offset);
    if (javaNode instanceof JavaClass) {
        String name = javaNode.getName();
        String lexeme = current.getLexeme();
        if (annotation && lexeme.length() > 1) {
            lexeme = lexeme.substring(1);
        }
        if (!lexeme.equals(name) && isClassNameStart(javaNode, lexeme)) {
            // try to replace long class name with one token
            Token replace = concatTokensUntil(current, name);
            if (replace != null && prev instanceof TokenImpl) {
                TokenImpl impl = ((TokenImpl) prev);
                impl.setNextToken(replace);
                current = replace;
            }
        }
    }
    return current;
}
Also used : JavaClass(jadx.api.JavaClass) TokenImpl(org.fife.ui.rsyntaxtextarea.TokenImpl) Token(org.fife.ui.rsyntaxtextarea.Token) JavaNode(jadx.api.JavaNode) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

TokenImpl (org.fife.ui.rsyntaxtextarea.TokenImpl)3 Token (org.fife.ui.rsyntaxtextarea.Token)2 JavaClass (jadx.api.JavaClass)1 JavaNode (jadx.api.JavaNode)1 IOException (java.io.IOException)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1