@NotNull private Token mergeLongClassNames(Token prev, Token current, boolean annotation) { int offset = current.getOffset(); if (annotation) { offset++; } JavaNode javaNode = codeArea.getJavaNodeAtOffset(jCls, 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) && javaNode.getFullName().startsWith(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; }
@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; } }
/** * 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) { firstToken = currentToken = null; } else { currentToken = previousToken; currentToken.setNextToken(null); } }
/** * {@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) { augmentTokenList(); } return token; }
/** * {@inheritDoc} */ @Override public void addNullToken() { if (firstToken==null) { firstToken = tokenFactory.createToken(); currentToken = firstToken; } else { TokenImpl next = tokenFactory.createToken(); currentToken.setNextToken(next); previousToken = currentToken; currentToken = next; } currentToken.setLanguageIndex(languageIndex); }
/** * Clones a token list. This is necessary as tokens are reused in * {@link RSyntaxDocument}, so we can't simply use the ones we * are handed from it. * * @param t The token list to clone. * @return The clone of the token list. */ private TokenImpl cloneTokenList(Token t) { if (t==null) { return null; } TokenImpl clone = new TokenImpl(t); TokenImpl cloneEnd = clone; while ((t=t.getNextToken())!=null) { TokenImpl temp = new TokenImpl(t); cloneEnd.setNextToken(temp); cloneEnd = temp; } return clone; }
/** * 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. */ public void addToken(char[] array, int start, int end, int tokenType, int startOffset, boolean hyperlink) { if (firstToken==null) { firstToken = tokenFactory.createToken(array, start, end, startOffset, tokenType); currentToken = firstToken; // previous token is still null. } else { TokenImpl next = tokenFactory.createToken(array, start,end, startOffset, tokenType); currentToken.setNextToken(next); previousToken = currentToken; currentToken = next; } currentToken.setLanguageIndex(languageIndex); currentToken.setHyperlink(hyperlink); }
/** * 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) { firstToken = currentToken = null; } else { currentToken = previousToken; currentToken.setNextToken(null); } }
lastToken.setNextToken(t); t = new TokenImpl(new char[] { '\n' }, 0,0, docOffs, Token.WHITESPACE, 0); lastToken.setNextToken(t); lastToken = t; temp.setNextToken(null);
/** * {@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) { augmentTokenList(); } return token; }
/** * {@inheritDoc} */ @Override public void addNullToken() { if (firstToken==null) { firstToken = tokenFactory.createToken(); currentToken = firstToken; } else { TokenImpl next = tokenFactory.createToken(); currentToken.setNextToken(next); previousToken = currentToken; currentToken = next; } currentToken.setLanguageIndex(languageIndex); }
/** * Clones a token list. This is necessary as tokens are reused in * {@link RSyntaxDocument}, so we can't simply use the ones we * are handed from it. * * @param t The token list to clone. * @return The clone of the token list. */ private TokenImpl cloneTokenList(Token t) { if (t==null) { return null; } TokenImpl clone = new TokenImpl(t); TokenImpl cloneEnd = clone; while ((t=t.getNextToken())!=null) { TokenImpl temp = new TokenImpl(t); cloneEnd.setNextToken(temp); cloneEnd = temp; } return clone; }
/** * 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. */ public void addToken(char[] array, int start, int end, int tokenType, int startOffset, boolean hyperlink) { if (firstToken==null) { firstToken = tokenFactory.createToken(array, start, end, startOffset, tokenType); currentToken = firstToken; // previous token is still null. } else { TokenImpl next = tokenFactory.createToken(array, start,end, startOffset, tokenType); currentToken.setNextToken(next); previousToken = currentToken; currentToken = next; } currentToken.setLanguageIndex(languageIndex); currentToken.setHyperlink(hyperlink); }
lastToken.setNextToken(t); t = new TokenImpl(new char[] { '\n' }, 0,0, docOffs, Token.WHITESPACE, 0); lastToken.setNextToken(t); lastToken = t; temp.setNextToken(null);