本文整理汇总了Java中org.netbeans.api.lexer.TokenSequence.movePrevious方法的典型用法代码示例。如果您正苦于以下问题:Java TokenSequence.movePrevious方法的具体用法?Java TokenSequence.movePrevious怎么用?Java TokenSequence.movePrevious使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.api.lexer.TokenSequence
的用法示例。
在下文中一共展示了TokenSequence.movePrevious方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getToken
import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private Token getToken(TokenSequence ts, int offset, boolean next, int[] startOffset) {
int diff = ts.move(offset);
boolean ok;
if(next) {
ok = ts.moveNext();
} else if (diff > 0) {
ok = ts.moveNext();
} else {
ok = ts.movePrevious();
}
if (!ok) {
return null;
}
if (startOffset != null) {
startOffset[0] = ts.offset();
if (startOffset.length > 1) {
startOffset[1] = ts.offset() + ts.token().length();
}
}
return ts.token();
}
示例2: getInstantRenamerVisitor
import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
@Override
public <T extends Set<OffsetRange>> NodeVisitor<T> getInstantRenamerVisitor(EditorFeatureContext context, T result) {
TokenSequence<CssTokenId> tokenSequence = context.getTokenSequence();
int diff = tokenSequence.move(context.getCaretOffset());
if (diff > 0 && tokenSequence.moveNext() || diff == 0 && tokenSequence.movePrevious()) {
Token<CssTokenId> token = tokenSequence.token();
final CharSequence elementName = token.text();
return new NodeVisitor<T>(result) {
@Override
public boolean visit(Node node) {
switch (node.type()) {
case cp_mixin_name:
case cp_variable:
if (LexerUtils.equals(elementName, node.image(), false, false)) {
OffsetRange range = new OffsetRange(node.from(), node.to());
getResult().add(range);
break;
}
}
return false;
}
};
}
return null;
}
示例3: findLastNonWhitespaceToken
import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private static TokenSequence<JavaTokenId> findLastNonWhitespaceToken(TokenSequence<JavaTokenId> ts, int startPos, int endPos) {
ts.move(endPos);
while(ts.movePrevious()) {
int offset = ts.offset();
if (offset < startPos) {
return null;
}
switch (ts.token().id()) {
case WHITESPACE:
case LINE_COMMENT:
case BLOCK_COMMENT:
case JAVADOC_COMMENT:
break;
default:
return ts;
}
}
return null;
}
示例4: isJavadocContext
import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
public static boolean isJavadocContext(TokenHierarchy hierarchy, int offset) {
TokenSequence<JavaTokenId> ts = SourceUtils.getJavaTokenSequence(hierarchy, offset);
if (!movedToJavadocToken(ts, offset)) {
return false;
}
TokenSequence<JavadocTokenId> jdts = ts.embedded(JavadocTokenId.language());
if (jdts == null) {
return false;
} else if (jdts.isEmpty()) {
return isEmptyJavadoc(ts.token(), offset - ts.offset());
}
jdts.move(offset);
if (!jdts.moveNext() && !jdts.movePrevious()) {
return false;
}
// this checks /** and */ headers
return isInsideToken(jdts, offset) && !isInsideIndent(jdts.token(), offset - jdts.offset());
}
示例5: caretInsidePreviousToken
import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private static boolean caretInsidePreviousToken(HintContext ctx, long startAt, JavaTokenId lookFor) {
if (startAt < 0) {
return false;
}
TokenSequence<JavaTokenId> ts = ctx.getInfo().getTokenHierarchy().tokenSequence(JavaTokenId.language());
ts.move((int) startAt);
while (ts.movePrevious()) {
if (ts.token().id() == lookFor) {
int start = ts.offset();
int end = ts.offset() + ts.token().length();
return ctx.getCaretLocation() >= start && ctx.getCaretLocation() <= end;
}
}
return false;
}
示例6: getPositionedSequence
import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
public static <T extends TokenId> TokenSequence<T> getPositionedSequence(BaseDocument doc, int offset, boolean lookBack, Language<T> language) {
TokenSequence<T> ts = getTokenSequence(doc, offset, language);
if (ts != null) {
try {
ts.move(offset);
} catch (AssertionError e) {
DataObject dobj = (DataObject)doc.getProperty(Document.StreamDescriptionProperty);
if (dobj != null) {
Exceptions.attachMessage(e, FileUtil.getFileDisplayName(dobj.getPrimaryFile()));
}
throw e;
}
if (!lookBack && !ts.moveNext()) {
return null;
} else if (lookBack && !ts.moveNext() && !ts.movePrevious()) {
return null;
}
return ts;
}
return null;
}
示例7: previousNonWhitespaceToken
import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
TokenSequence<JavaTokenId> previousNonWhitespaceToken(TokenSequence<JavaTokenId> ts) {
while (ts.movePrevious()) {
switch (ts.token().id()) {
case WHITESPACE:
case LINE_COMMENT:
case BLOCK_COMMENT:
case JAVADOC_COMMENT:
break;
default:
return ts;
}
}
return null;
}
示例8: isCaretInsideTag
import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
public static boolean isCaretInsideTag(int caretPos, TokenSequence tokenSequence) {
if (! isTokenSequenceUsable(tokenSequence)) return false;
boolean tagFirstCharFound = false, tagLastCharFound = false;
Token token = null;
boolean checkComment = tokenSequence.move(caretPos) != 0;
tokenSequence.moveNext();
do {
token = tokenSequence.token();
if (isTagFirstChar(token)) {
tagFirstCharFound = true;
break;
} else if (checkComment && token.id() == XMLTokenId.BLOCK_COMMENT) {
return true;
}
checkComment = false;
} while (tokenSequence.movePrevious());
if (! tagFirstCharFound) return false;
while (tokenSequence.moveNext()) {
token = tokenSequence.token();
int tokenOffset = tokenSequence.offset();
boolean isEndTagSuffix = isEndTagSuffix(token);
if (isTagLastChar(token) || isEndTagSuffix) {
if ((tokenOffset >= caretPos) ||
(isEndTagSuffix && (tokenOffset == caretPos - 1))) {
tagLastCharFound = true;
}
break;
}
if (token.id() == XMLTokenId.TAG || token.id() == XMLTokenId.TEXT) {
if (token.text().charAt(0) == '<') {
break;
}
}
}
return (tagFirstCharFound && tagLastCharFound);
}
示例9: assertSameOutput
import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
/**
* Compares the result with the golden string but ignores *all* whitespaces. In order to keep the nice IDE tools
* to work, if a inconsistency is found, the prefix of the golden file will be forged from the actual result, so the
* first reported inconsistency will occur at the right place.
* The lax comparison can be switched off by -Dorg.netbeans.test.hints.strictOutputCompare=true
* @param result
* @param golden
*/
private void assertSameOutput(String result, String golden) throws Exception {
Language lng = Language.find("text/x-java");
if (lng == null || Boolean.getBoolean("org.netbeans.test.hints.strictOutputCompare")) {
assertEquals("The output code does not match the expected code.", reduceWhitespaces(golden),
reduceWhitespaces(result));
return;
}
TokenHierarchy h1 = TokenHierarchy.create(result, lng);
TokenHierarchy h2 = TokenHierarchy.create(golden, lng);
TokenSequence s1 = h1.tokenSequence();
TokenSequence s2 = h2.tokenSequence();
while (s2.moveNext()) {
Token gt = s2.token();
boolean wh = gt.id() == JavaTokenId.WHITESPACE;
if (s1.moveNext()) {
Token rt;
do {
rt = s1.token();
if (!wh) {
if (!rt.text().toString().equals(gt.text().toString())) {
failNotSame(result, golden, s1.offset());
}
} else if (!isWH(rt)) {
s1.movePrevious();
break;
}
} while (isWH(rt) && s1.moveNext());
} else if (!wh) {
failNotSame(result, golden, s2.offset());
}
}
s1.movePrevious();
s2.movePrevious();
if (s1.moveNext() != s2.moveNext()) {
failNotSame(result, golden, s2.offset());
}
}
示例10: findIdentifierSpanImpl
import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private static Token<JavaTokenId> findIdentifierSpanImpl(CompilationInfo info, MemberReferenceTree tree, CompilationUnitTree cu, SourcePositions positions) {
int start = (int)positions.getStartPosition(cu, tree);
int endPosition = (int)positions.getEndPosition(cu, tree);
if (start == (-1) || endPosition == (-1))
return null;
String member = tree.getName().toString();
TokenHierarchy<?> th = info.getTokenHierarchy();
TokenSequence<JavaTokenId> ts = th.tokenSequence(JavaTokenId.language());
if (ts.move(endPosition) == Integer.MAX_VALUE) {
return null;
}
if (ts.moveNext()) {
while (ts.offset() >= start) {
Token<JavaTokenId> t = ts.token();
if (t.id() == JavaTokenId.IDENTIFIER && member.equals(info.getTreeUtilities().decodeIdentifier(t.text()).toString())) {
return t;
}
if (!ts.movePrevious())
break;
}
}
return null;
}
示例11: isAddRightBrace
import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
/**
* Resolve whether pairing right curly should be added automatically
* at the caret position or not.
* <br>
* There must be only whitespace or line comment or block comment
* between the caret position
* and the left brace and the left brace must be on the same line
* where the caret is located.
* <br>
* The caret must not be "contained" in the opened block comment token.
*
* @param doc document in which to operate.
* @param caretOffset offset of the caret.
* @return true if a right brace '}' should be added
* or false if not.
*/
static boolean isAddRightBrace(BaseDocument doc, int caretOffset) throws BadLocationException {
if (tokenBalance(doc, JavaTokenId.LBRACE) <= 0) {
return false;
}
int caretRowStartOffset = org.netbeans.editor.Utilities.getRowStart(doc, caretOffset);
TokenSequence<JavaTokenId> ts = javaTokenSequence(doc, caretOffset, true);
if (ts == null) {
return false;
}
boolean first = true;
do {
if (ts.offset() < caretRowStartOffset) {
return false;
}
switch (ts.token().id()) {
case WHITESPACE:
case LINE_COMMENT:
break;
case BLOCK_COMMENT:
case JAVADOC_COMMENT:
if (first && caretOffset > ts.offset() && caretOffset < ts.offset() + ts.token().length()) {
// Caret contained within block comment -> do not add anything
return false;
}
break; // Skip
case LBRACE:
return true;
}
first = false;
} while (ts.movePrevious());
return false;
}
示例12: findPrefix
import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
/** Returns part of token before cursor or entire token if at the end of it.
* Returns null prefix if token is comma, rparen or whitespace. Returned offset is
* caret offset if prefix is null, otherwise it is token offset. */
private Symbol findPrefix() {
TokenSequence<SQLTokenId> seq = env.getTokenSequence();
int caretOffset = env.getCaretOffset();
String prefix = null;
if (seq.move(caretOffset) > 0) {
// Not on token boundary.
if (!seq.moveNext() && !seq.movePrevious()) {
return new Symbol(null, caretOffset, caretOffset);
}
} else {
if (!seq.movePrevious()) {
return new Symbol(null, caretOffset, caretOffset);
}
}
switch (seq.token().id()) {
case WHITESPACE:
case COMMA:
case RPAREN:
return new Symbol(null, caretOffset, caretOffset);
default:
int offset = caretOffset - seq.offset();
if (offset > 0 && offset < seq.token().length()) {
prefix = seq.token().text().subSequence(0, offset).toString();
} else {
prefix = seq.token().text().toString();
}
return new Symbol(prefix, seq.offset(), seq.offset());
}
}
示例13: embeddedTokenSequences
import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
public List<TokenSequence<?>> embeddedTokenSequences(
int offset, boolean backwardBias
) {
synchronized (rootTokenList) {
TokenSequence<?> seq = tokenSequence();
List<TokenSequence<?>> sequences = new ArrayList<TokenSequence<?>>();
while (seq != null) {
seq.move(offset);
if (seq.moveNext()) {
if (seq.offset() == offset && backwardBias) {
if (seq.movePrevious()) {
sequences.add(seq);
seq = seq.embedded();
} else {
seq = null;
}
} else {
sequences.add(seq);
seq = seq.embedded();
}
} else if (backwardBias && seq.movePrevious()) {
sequences.add(seq);
seq = seq.embedded();
} else {
seq = null;
}
}
return sequences;
}
}
示例14: moveTo
import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
/**
* Moves <code>seq</code> to first occurence of specified <code>toToken</code> if specified direction.
* @param seq sequence of tokens
* @param toToken token to stop on.
* @param forward move forward if true, backward otherwise
* @return true if token has been reached.
*/
private boolean moveTo(TokenSequence<JavaTokenId> seq, JavaTokenId toToken, boolean forward) {
if (seq.token() == null) return false;//seq.move(<end-of-stream>) might have been called - see test224577.
do {
if (toToken == seq.token().id()) {
return true;
}
} while (forward ? seq.moveNext() : seq.movePrevious());
return false;
}
示例15: isForLoopTryWithResourcesOrLambdaSemicolon
import org.netbeans.api.lexer.TokenSequence; //导入方法依赖的package包/类
private static boolean isForLoopTryWithResourcesOrLambdaSemicolon(TokenSequence<JavaTokenId> ts) {
int parenDepth = 0; // parenthesis depth
int braceDepth = 0; // brace depth
boolean semicolonFound = false; // next semicolon
int tsOrigIndex = ts.index();
try {
while (ts.movePrevious()) {
switch (ts.token().id()) {
case LPAREN:
if (parenDepth == 0) { // could be a 'for (' or 'try ('
while (ts.movePrevious()) {
switch (ts.token().id()) {
case WHITESPACE:
case BLOCK_COMMENT:
case JAVADOC_COMMENT:
case LINE_COMMENT:
break; // skip
case FOR:
case TRY:
return true;
default:
return false;
}
}
return false;
} else { // non-zero depth
parenDepth--;
}
break;
case RPAREN:
parenDepth++;
break;
case LBRACE:
if (braceDepth == 0) { // unclosed left brace
if (!semicolonFound) {
while (ts.movePrevious()) {
switch (ts.token().id()) {
case WHITESPACE:
case BLOCK_COMMENT:
case JAVADOC_COMMENT:
case LINE_COMMENT:
break; // skip
case ARROW:
return true;
default:
return false;
}
}
}
return false;
}
braceDepth--;
break;
case RBRACE:
braceDepth++;
break;
case SEMICOLON:
if (semicolonFound) { // one semicolon already found
return false;
}
semicolonFound = true;
break;
}
}
} finally {
// Restore orig TS's location
ts.moveIndex(tsOrigIndex);
ts.moveNext();
}
return false;
}