Java Code Examples for org.netbeans.api.lexer.TokenSequence#subSequence()
The following examples show how to use
org.netbeans.api.lexer.TokenSequence#subSequence() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LexerBasedHighlightLayer.java From netbeans with Apache License 2.0 | 6 votes |
public synchronized HighlightsSequence getHighlights(int startOffset, int endOffset) { if (colorings.isEmpty()) { return HighlightsSequence.EMPTY; } TokenHierarchy th = TokenHierarchy.get(doc); TokenSequence<? extends TokenId> seq = th.tokenSequence(); if (seq == null) { // Null when token hierarchy is inactive return HighlightsSequence.EMPTY; } if (seq.language() == JavaTokenId.language()) { return new LexerBasedHighlightSequence(this, seq.subSequence(startOffset, endOffset), colorings); } else { return new EmbeddedLexerBasedHighlightSequence(this, seq.subSequence(startOffset, endOffset), colorings); } }
Example 2
Source File: PHPCompletionItem.java From netbeans with Apache License 2.0 | 5 votes |
public static boolean insertOnlyMethodsName(CompletionRequest request) { if (request.insertOnlyMethodsName != null) { return request.insertOnlyMethodsName; } boolean result = false; TokenHierarchy<?> tokenHierarchy = request.result.getSnapshot().getTokenHierarchy(); TokenSequence<PHPTokenId> tokenSequence = (TokenSequence<PHPTokenId>) tokenHierarchy.tokenSequence(); if (tokenSequence != null) { VariableScope variableScope = request.result.getModel().getVariableScope(request.anchor); if (variableScope != null) { tokenSequence = tokenSequence.subSequence(request.anchor, variableScope.getBlockRange().getEnd()); } boolean wasWhitespace = false; while (tokenSequence.moveNext()) { Token<PHPTokenId> token = tokenSequence.token(); PHPTokenId id = token.id(); if (PHPTokenId.PHP_STRING.equals(id)) { if (wasWhitespace) { // this needs brackets: curl_set^ curl_setopt($ch, $option, $ch); break; } else { // this doesn't need brackets: curl_setopt^ ($ch, $option, $ch); continue; } } else if (PHPTokenId.WHITESPACE.equals(id)) { wasWhitespace = true; continue; } else if (PHPTokenId.PHP_TOKEN.equals(id) && TokenUtilities.textEquals(token.text(), "(")) { //NOI18N result = true; break; } else { break; } } } return result; }