本文整理汇总了Java中org.netbeans.api.lexer.Token.id方法的典型用法代码示例。如果您正苦于以下问题:Java Token.id方法的具体用法?Java Token.id怎么用?Java Token.id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.api.lexer.Token
的用法示例。
在下文中一共展示了Token.id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scanForSemicolon
import org.netbeans.api.lexer.Token; //导入方法依赖的package包/类
private static int scanForSemicolon(Document doc, int[] offset, int start, int end) throws BadLocationException {
TokenHierarchy<Document> th = doc != null ? TokenHierarchy.get(doc) : null;
List<TokenSequence<?>> embeddedSequences = th != null ? th.embeddedTokenSequences(offset[0], false) : null;
TokenSequence<?> seq = embeddedSequences != null ? embeddedSequences.get(embeddedSequences.size() - 1) : null;
if (seq == null) {
return offset[0];
}
seq.move(start);
int semicolon = -1;
while(seq.moveNext()) {
int tokenOffset = seq.offset();
if(tokenOffset > end) {
break;
}
Token<?> t = seq.token();
if(t != null && t.id() == JavaTokenId.SEMICOLON ) {
semicolon = tokenOffset;
break;
}
}
return semicolon;
}
示例2: testScriptType_empty
import org.netbeans.api.lexer.Token; //导入方法依赖的package包/类
public void testScriptType_empty() {
TokenHierarchy th = TokenHierarchy.create("<script type=\"\">plain</script>", HTMLTokenId.language());
TokenSequence ts = th.tokenSequence();
ts.moveStart();
while(ts.moveNext()) {
Token t = ts.token();
if(t.id() == HTMLTokenId.SCRIPT) {
String scriptType = (String)t.getProperty(HTMLTokenId.SCRIPT_TYPE_TOKEN_PROPERTY);
assertNotNull(scriptType);
assertEquals("", scriptType);
return ;
}
}
assertTrue("Couldn't find any SCRIPT token!", false);
}
示例3: defineEmbeddings
import org.netbeans.api.lexer.Token; //导入方法依赖的package包/类
private void defineEmbeddings(TokenSequence seq, ConsoleModel model, ConsoleSection s) {
F: for (Rng r : s.getPartRanges()) {
seq.move(r.start);
Token<JShellToken> tukac;
W: while (seq.moveNext() && seq.offset() < r.end) {
tukac = seq.token();
switch (tukac.id()) {
case JAVA:
seq.createEmbedding(JavaTokenId.language(), 0, 0);
// fall through
case WHITESPACE:
break;
default:
break W;
}
}
}
}
示例4: getFirstChildLocked
import org.netbeans.api.lexer.Token; //导入方法依赖的package包/类
private Node getFirstChildLocked(TokenSequence ts) {
while (ts.moveNext()) {
Token<XMLTokenId> t = ts.token();
if (t.id() == XMLTokenId.VALUE) {
// fuzziness to relax minor tokenization changes
CharSequence image = t.text();
if (image.length() == 1) {
char test = image.charAt(0);
if (test == '"' || test == '\'') {
if (ts.moveNext()) {
t = ts.token();
} else {
return null;
}
}
}
if (t.id() == XMLTokenId.VALUE) {
return new TextImpl(syntax, t, ts.offset(), ts.offset() + t.length(), this);
} else {
return null;
}
}
}
return null;
}
示例5: isTag
import org.netbeans.api.lexer.Token; //导入方法依赖的package包/类
private static boolean isTag(Token<? extends TokenId> tag) {
CharSequence s = tag.text();
int l = s.length();
boolean b = tag.id() == JavadocTokenId.HTML_TAG &&
l >= 3 &&
s.charAt(0) == '<' && //NOI18N
s.charAt(l - 1) == '>'; //NOI18N
if (b) {
if (s.charAt(1) == '/') { //NOI18N
b = l >= 4 && Character.isLetterOrDigit(s.charAt(2));
} else {
b = Character.isLetterOrDigit(s.charAt(1));
}
}
return b;
}
示例6: findIdentifierSpanImpl
import org.netbeans.api.lexer.Token; //导入方法依赖的package包/类
private static Token<JavaTokenId> findIdentifierSpanImpl(CompilationInfo info, MemberSelectTree 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.getIdentifier().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;
}
示例7: isWhiteSpace
import org.netbeans.api.lexer.Token; //导入方法依赖的package包/类
private static boolean isWhiteSpace(Token<? extends TokenId> token) {
if (token == null || token.id() != JavadocTokenId.OTHER_TEXT) {
return false;
}
String ws = " \t\n";
return ws.indexOf(token.text().charAt(0)) >= 0;
}
示例8: isWhiteSpaceFirst
import org.netbeans.api.lexer.Token; //导入方法依赖的package包/类
public static boolean isWhiteSpaceFirst(Token<JavadocTokenId> token) {
if (token == null || token.id() != JavadocTokenId.OTHER_TEXT || token.length() < 1) {
return false;
}
CharSequence text = token.text();
char c = text.charAt(0);
return c == ' ' || c == '\t';
}
示例9: assertSameOutput
import org.netbeans.api.lexer.Token; //导入方法依赖的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: getAttributeValue
import org.netbeans.api.lexer.Token; //导入方法依赖的package包/类
private String getAttributeValue(TokenSequence<XMLTokenId> ts, String name) {
boolean readValue = false;
while (ts.moveNext()) {
Token<XMLTokenId> next = ts.token();
switch (next.id()) {
case ARGUMENT:
if (name.equals(next.text().toString())) {
readValue = true;
}
continue;
case VALUE:
if (readValue) {
CharSequence val = next.text().subSequence(1, next.text().length() - 1);
return val.toString();
}
continue;
case OPERATOR:
case EOL:
case ERROR:
case WS:
continue;
default:
return null;
}
}
return null;
}
示例11: noCompletion
import org.netbeans.api.lexer.Token; //导入方法依赖的package包/类
/**
* No completion inside PI, CDATA, comment section.
* True only inside PI or CDATA section, false otherwise.
* @param target
*/
public boolean noCompletion(JTextComponent target) {
if(target == null || target.getCaret() == null)
return false;
int offset = target.getCaret().getDot();
if(offset < 0)
return false;
//no completion inside CDATA or comment section
BaseDocument document = (BaseDocument)target.getDocument();
((AbstractDocument)document).readLock();
try {
TokenHierarchy th = TokenHierarchy.get(document);
TokenSequence ts = th.tokenSequence();
if(ts == null)
return false;
ts.move(offset);
Token token = ts.token();
if(token == null) {
ts.moveNext();
token = ts.token();
if(token == null)
return false;
}
if( token.id() == XMLTokenId.CDATA_SECTION ||
token.id() == XMLTokenId.BLOCK_COMMENT ||
token.id() == XMLTokenId.PI_START ||
token.id() == XMLTokenId.PI_END ||
token.id() == XMLTokenId.PI_CONTENT ||
token.id() == XMLTokenId.PI_TARGET ) {
return true;
}
} finally {
((AbstractDocument)document).readUnlock();
}
return false;
}
示例12: atOffset
import org.netbeans.api.lexer.Token; //导入方法依赖的package包/类
/**
* Finds the starting tag token for the specified offset. It respects the
* search direction in the search context. May return {@code null} in the
* case of an error or when tag could not be found.
*
* @return starting tag Token
*/
private Token atOffset(TokenSequence ts, int offset) {
int diff = ts.move(offset);
if (diff == 0 && (context == null || context.isSearchingBackward())) {
if (!ts.movePrevious()) {
return null;
}
} else {
if (!ts.moveNext()) {
return null;
}
}
if (diff == ts.token().text().length() - 1 && (context != null && !context.isSearchingBackward())) {
if (!ts.moveNext()) {
return null;
}
}
do {
Token t = ts.token();
XMLTokenId id = (XMLTokenId)t.id();
switch (id) {
case ARGUMENT:
case OPERATOR:
case VALUE:
case WS:
// continue the cycle
break;
default:
return t;
}
} while (ts.movePrevious());
return ts.token();
}
示例13: initCompletedMemberContext
import org.netbeans.api.lexer.Token; //导入方法依赖的package包/类
private void initCompletedMemberContext() {
//parse the text behind the cursor and try to find identifiers.
//it seems to be impossible to use JMI model for this since it havily
//relies on the state of the source (whether it contains errors, which types etc.)
String type = null;
String genericType = null;
String propertyName = null;
CCParser nnp = new CCParser(getController()); //helper parser
TokenSequence<JavaTokenId> ts = getController().getTokenHierarchy().tokenSequence(JavaTokenId.language());
ts.move(getCompletionOffset() + 1);
nextNonWhitespaceToken(ts);
Token<JavaTokenId> ti = ts.token();
while (ti != null && propertyName == null) {
javax.lang.model.element.Element el = null;
try {
el = getController().getTrees().getElement(getCompletionTreePath(getController(), ts.offset() + 1, CompletionProvider.COMPLETION_QUERY_TYPE));
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
//skip all annotations between the CC offset and the completed member
if (el!=null && el.getKind() == ElementKind.ANNOTATION_TYPE) {
//parse to find NN end
CCParser.CC parsed = nnp.parseAnnotation(ts.offset() + 1);
if (parsed != null) {
//parse after the NN end (skip)
ts.move(parsed.getEndOffset());
ti = ts.token();
continue;
}
}
//test whether we have just found a type and '<' character after
if (genericType != null && ti.id() == JavaTokenId.LT) {
//maybe a start of generic
ts.moveNext();
Token<JavaTokenId> ti2 = ts.token();
if (ti2.id() == JavaTokenId.IDENTIFIER) {
//found generic
//genericType = ti2.getImage();
//ti = ti.getNext(); //skip the next IDENTIFIER token so it is not considered as property name
} else {
//false alarm
genericType = null;
}
} else if (ti.id() == JavaTokenId.IDENTIFIER) {
if (type == null) {
//type = ti.getImage();
genericType = type;
} else {
//propertyName = ti.getImage();
}
}
ts.moveNext();
ti = ts.token();
}
completedMemberName = propertyName;
completedMemberJavaClassName = genericType == null ? type : genericType;
}
示例14: isReferenceTag
import org.netbeans.api.lexer.Token; //导入方法依赖的package包/类
private static boolean isReferenceTag(Token<JavadocTokenId> tag) {
String tagName = tag.text().toString().intern();
return tag.id() == JavadocTokenId.TAG && ALL_REF_TAG_NAMES.contains(tagName);
}
示例15: isWhiteSpaceToken
import org.netbeans.api.lexer.Token; //导入方法依赖的package包/类
@Override
protected boolean isWhiteSpaceToken(Token<HTMLTokenId> token) {
return token.id() == HTMLTokenId.WS ||
(token.id() == HTMLTokenId.TEXT && token.text().toString().trim().length() == 0);
}