@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; } }
/** * 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>. * @return Whether this tag can be a foldable region. */ private static boolean isFoldableTag(Token tagNameToken) { return tagNameToken!=null && FOLDABLE_TAGS.contains(tagNameToken.getLexeme().toLowerCase()); }
private static boolean isSpaces(Token t) { String lexeme = t.getLexeme(); return lexeme.trim().isEmpty(); }
/** * Returns whether a closing tag ("<code></...></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. * @return Whether it's the end of the current fold region. */ private static boolean isEndOfLastFold(Stack<String> tagNameStack, Token tagNameToken) { if (tagNameToken!=null && !tagNameStack.isEmpty()) { return tagNameToken.getLexeme().equalsIgnoreCase(tagNameStack.peek()); } return false; }
@Override public boolean equals(Object obj) { if (obj==this) { return true; } if (!(obj instanceof Token)) { return false; } Token t2 = (Token)obj; return offset==t2.getOffset() && type==t2.getType() && languageIndex==t2.getLanguageIndex() && hyperlink==t2.isHyperlink() && ((getLexeme()==null && t2.getLexeme()==null) || (getLexeme()!=null && getLexeme().equals(t2.getLexeme()))); }
@Test public void testEolComments_URL() { String[] eolCommentLiterals = { "// Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testEolComments_URL() { String[] eolCommentLiterals = { "// Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testEolComments_URL() { String[] eolCommentLiterals = { "; Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testEolComments_URL() { String[] eolCommentLiterals = { "// Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testEolComments_URL() { String[] eolCommentLiterals = { "# Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testEolComments_URL() { String[] eolCommentLiterals = { "// Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testJS_EolComments_URL() { String[] eolCommentLiterals = { "// Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, JS_PREV_TOKEN_TYPE, 0); Assert.assertEquals("Unexpected token: " + token, TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testEolComments_URL() { String[] eolCommentLiterals = { "; Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testLess_EolComments_URL() { String[] eolCommentLiterals = { "// Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testEolComments_URL() { String[] eolCommentLiterals = { "// Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testEolComments_URL() { String[] eolCommentLiterals = { "// Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testEolComments_URL() { String[] eolCommentLiterals = { "# Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testEolComments_URL() { String[] eolCommentLiterals = { "// Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }
@Test public void testEolComments_URL() { String[] eolCommentLiterals = { "// Hello world http://www.sas.com", }; for (String code : eolCommentLiterals) { Segment segment = createSegment(code); TokenMaker tm = createTokenMaker(); Token token = tm.getTokenList(segment, TokenTypes.NULL, 0); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); token = token.getNextToken(); Assert.assertTrue(token.isHyperlink()); Assert.assertEquals(TokenTypes.COMMENT_EOL, token.getType()); Assert.assertEquals("http://www.sas.com", token.getLexeme()); } }