本文整理汇总了Java中org.netbeans.api.lexer.InputAttributes.setValue方法的典型用法代码示例。如果您正苦于以下问题:Java InputAttributes.setValue方法的具体用法?Java InputAttributes.setValue怎么用?Java InputAttributes.setValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.api.lexer.InputAttributes
的用法示例。
在下文中一共展示了InputAttributes.setValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testInterferenceBraceIdent
import org.netbeans.api.lexer.InputAttributes; //导入方法依赖的package包/类
public void testInterferenceBraceIdent() {
String text = "() -> {A::a();}";
InputAttributes attr = new InputAttributes();
attr.setValue(JavaTokenId.language(), "version", Integer.valueOf(7), true);
TokenHierarchy<?> hi = TokenHierarchy.create(text, false, JavaTokenId.language(), EnumSet.of(JavaTokenId.WHITESPACE), attr);
TokenSequence<?> ts = hi.tokenSequence();
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.LPAREN, "(");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.RPAREN, ")");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.ARROW, "->");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.LBRACE, "{");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.IDENTIFIER, "A");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.COLONCOLON, "::");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.IDENTIFIER, "a");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.LPAREN, "(");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.RPAREN, ")");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.SEMICOLON, ";");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.RBRACE, "}");
assertFalse(ts.moveNext());
}
示例2: testNoBinaryLiterals
import org.netbeans.api.lexer.InputAttributes; //导入方法依赖的package包/类
public void testNoBinaryLiterals() {
String text = "0b101 0B101 0b101l 0b101L";
InputAttributes attr = new InputAttributes();
attr.setValue(JavaTokenId.language(), "version", Integer.valueOf(5), true);
TokenHierarchy<?> hi = TokenHierarchy.create(text, false, JavaTokenId.language(), EnumSet.of(JavaTokenId.WHITESPACE), attr);
TokenSequence<?> ts = hi.tokenSequence();
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.INT_LITERAL, "0");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.IDENTIFIER, "b101");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.INT_LITERAL, "0");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.IDENTIFIER, "B101");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.INT_LITERAL, "0");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.IDENTIFIER, "b101l");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.INT_LITERAL, "0");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.IDENTIFIER, "b101L");
}
示例3: getTokenHierarchy
import org.netbeans.api.lexer.InputAttributes; //导入方法依赖的package包/类
@NonNull
public final TokenHierarchy<?> getTokenHierarchy() throws IOException {
if (this.tokens == null) {
final CharBuffer charBuffer = getCharContent(true);
InputAttributes attrs = new InputAttributes();
attrs.setValue(JavaTokenId.language(), "fileName", (Supplier<String>) () -> getName(), true); //NOI18N
this.tokens = TokenHierarchy.create(charBuffer, false, JavaTokenId.language(), null, attrs); //TODO: .createSnapshot();
}
return this.tokens;
}
示例4: createStyledDocument
import org.netbeans.api.lexer.InputAttributes; //导入方法依赖的package包/类
@Override
protected StyledDocument createStyledDocument (EditorKit kit) {
StyledDocument doc = super.createStyledDocument(kit);
// Enter the file object in to InputAtrributes. It can be used by lexer.
InputAttributes attributes = new InputAttributes();
FileObject fileObject = NbEditorUtilities.getFileObject(doc);
final GsfLanguage lng = language.getGsfLanguage();
if (lng != null) {
attributes.setValue(lng.getLexerLanguage(), FileObject.class, fileObject, false);
}
doc.putProperty(InputAttributes.class, attributes);
return doc;
}
示例5: xtestExoticIdentifiers
import org.netbeans.api.lexer.InputAttributes; //导入方法依赖的package包/类
public void xtestExoticIdentifiers() {//Support for exotic identifiers has been removed 6999438
String text = "a #\" \" #\"\\\"\"";
InputAttributes attr = new InputAttributes();
attr.setValue(JavaTokenId.language(), "version", Integer.valueOf(7), true);
TokenHierarchy<?> hi = TokenHierarchy.create(text, false, JavaTokenId.language(), EnumSet.of(JavaTokenId.WHITESPACE), attr);
TokenSequence<?> ts = hi.tokenSequence();
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.IDENTIFIER, "a");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.IDENTIFIER, "#\" \"");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.IDENTIFIER, "#\"\\\"\"");
}
示例6: testNoExoticIdentifiers
import org.netbeans.api.lexer.InputAttributes; //导入方法依赖的package包/类
public void testNoExoticIdentifiers() {
String text = "a #\" \"";
InputAttributes attr = new InputAttributes();
attr.setValue(JavaTokenId.language(), "version", Integer.valueOf(5), true);
TokenHierarchy<?> hi = TokenHierarchy.create(text, false, JavaTokenId.language(), EnumSet.of(JavaTokenId.WHITESPACE), attr);
TokenSequence<?> ts = hi.tokenSequence();
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.IDENTIFIER, "a");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.ERROR, "#");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.STRING_LITERAL, "\" \"");
}
示例7: testBinaryLiterals
import org.netbeans.api.lexer.InputAttributes; //导入方法依赖的package包/类
public void testBinaryLiterals() {
String text = "0b101 0B101 0b101l 0b101L";
InputAttributes attr = new InputAttributes();
attr.setValue(JavaTokenId.language(), "version", Integer.valueOf(7), true);
TokenHierarchy<?> hi = TokenHierarchy.create(text, false, JavaTokenId.language(), EnumSet.of(JavaTokenId.WHITESPACE), attr);
TokenSequence<?> ts = hi.tokenSequence();
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.INT_LITERAL, "0b101");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.INT_LITERAL, "0B101");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.LONG_LITERAL, "0b101l");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.LONG_LITERAL, "0b101L");
}
示例8: testUnderscoresInLiterals
import org.netbeans.api.lexer.InputAttributes; //导入方法依赖的package包/类
public void testUnderscoresInLiterals() {
String text = "_12 1_2 12_ 0_12 01_2 0x1_2";
InputAttributes attr = new InputAttributes();
attr.setValue(JavaTokenId.language(), "version", Integer.valueOf(7), true);
TokenHierarchy<?> hi = TokenHierarchy.create(text, false, JavaTokenId.language(), EnumSet.of(JavaTokenId.WHITESPACE), attr);
TokenSequence<?> ts = hi.tokenSequence();
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.IDENTIFIER, "_12");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.INT_LITERAL, "1_2");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.INT_LITERAL, "12");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.IDENTIFIER, "_");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.INT_LITERAL, "0_12");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.INT_LITERAL, "01_2");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.INT_LITERAL, "0x1_2");
}
示例9: testUnicode
import org.netbeans.api.lexer.InputAttributes; //导入方法依赖的package包/类
public void testUnicode() {
String text = "//\\u000Aint\\u0020\\u002E\\uuuuuu002E\\u000A";
InputAttributes attr = new InputAttributes();
attr.setValue(JavaTokenId.language(), "version", Integer.valueOf(7), true);
TokenHierarchy<?> hi = TokenHierarchy.create(text, false, JavaTokenId.language(), EnumSet.noneOf(JavaTokenId.class), attr);
TokenSequence<?> ts = hi.tokenSequence();
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.LINE_COMMENT, "//\\u000A");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.INT, "int");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.WHITESPACE, "\\u0020");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.DOT, "\\u002E");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.DOT, "\\uuuuuu002E");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.WHITESPACE, "\\u000A");
}
示例10: testBrokenUnicode
import org.netbeans.api.lexer.InputAttributes; //导入方法依赖的package包/类
public void testBrokenUnicode() {
String text = "\\u000X\\u00";
InputAttributes attr = new InputAttributes();
attr.setValue(JavaTokenId.language(), "version", Integer.valueOf(7), true);
TokenHierarchy<?> hi = TokenHierarchy.create(text, false, JavaTokenId.language(), EnumSet.noneOf(JavaTokenId.class), attr);
TokenSequence<?> ts = hi.tokenSequence();
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.ERROR, "\\");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.IDENTIFIER, "u000X");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.ERROR, "\\");
LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.IDENTIFIER, "u00");
}
示例11: testGenericCssClassEmbedding
import org.netbeans.api.lexer.InputAttributes; //导入方法依赖的package包/类
public void testGenericCssClassEmbedding() {
Map<String, Collection<String>> map = new HashMap<>();
map.put("c:button", Collections.singletonList("styleClass"));
InputAttributes inputAttributes = new InputAttributes();
inputAttributes.setValue(HTMLTokenId.language(), "cssClassTagAttrMap", map, false); //NOI18N
String text = "<c:button styleClass=\"myclass\"/>";
TokenHierarchy th = TokenHierarchy.create(text, true, HTMLTokenId.language(), Collections.<HTMLTokenId>emptySet(), inputAttributes);
TokenSequence ts = th.tokenSequence();
checkTokens(ts, "<|TAG_OPEN_SYMBOL", "c:button|TAG_OPEN", " |WS", "styleClass|ARGUMENT",
"=|OPERATOR", "\"myclass\"|VALUE_CSS", "/>|TAG_CLOSE_SYMBOL");
}
示例12: initDocument
import org.netbeans.api.lexer.InputAttributes; //导入方法依赖的package包/类
protected void initDocument(BaseDocument doc) {
// doc.addLayer(new JavaDrawLayerFactory.JavaLayer(),
// JavaDrawLayerFactory.JAVA_LAYER_VISIBILITY);
doc.putProperty(SyntaxUpdateTokens.class,
new SyntaxUpdateTokens() {
private List tokenList = new ArrayList();
public void syntaxUpdateStart() {
tokenList.clear();
}
public List syntaxUpdateEnd() {
return tokenList;
}
public void syntaxUpdateToken(TokenID id, TokenContextPath contextPath, int offset, int length) {
if (JavaTokenContext.LINE_COMMENT == id) {
tokenList.add(new TokenInfo(id, contextPath, offset, length));
}
}
}
);
InputAttributes attrs = new InputAttributes();
attrs.setValue(JavaTokenId.language(), "fileName", (Supplier<String>) () -> { //NOI18N
FileObject fo = NbEditorUtilities.getFileObject(doc);
return fo != null ? fo.getNameExt() : null;
}, true);
doc.putProperty(InputAttributes.class, attrs);
}
示例13: testEarlyNullToken
import org.netbeans.api.lexer.InputAttributes; //导入方法依赖的package包/类
public void testEarlyNullToken() throws Exception {
Document doc = new ModificationTextDocument();
// Assign a language to the document
InputAttributes attrs = new InputAttributes();
doc.putProperty(InputAttributes.class, attrs);
// Insert text into document
String text = "abc";
doc.insertString(0, text, null);
// Put the language now into the document so that lexing starts from scratch
doc.putProperty(Language.class, StateTokenId.language());
TokenHierarchy<?> hi = TokenHierarchy.get(doc);
((AbstractDocument)doc).readLock();
try {
TokenSequence<?> ts = hi.tokenSequence();
assertTrue(ts.moveNext());
LexerTestUtilities.assertTokenEquals(ts, StateTokenId.A, "a", 0);
assertEquals(LexerTestUtilities.lookahead(ts), 0);
assertEquals(LexerTestUtilities.state(ts), StateLexer.AFTER_A);
attrs.setValue(StateTokenId.language(), "returnNullToken", Boolean.TRUE, true);
try {
// Lexer will return null token too early
assertTrue(ts.moveNext());
fail("IllegalStateException not thrown when null token returned before input end.");
} catch (IllegalStateException e) {
// Expected fail of lexer
}
} finally {
((AbstractDocument)doc).readUnlock();
}
}
示例14: testIncLexerRelease
import org.netbeans.api.lexer.InputAttributes; //导入方法依赖的package包/类
public void testIncLexerRelease() throws Exception {
Document doc = new ModificationTextDocument();
// Assign a language to the document
InputAttributes attrs = new InputAttributes();
doc.putProperty(InputAttributes.class, attrs);
// Insert initial text into document
String text = "ab";
doc.insertString(0, text, null);
// Put the language now into the document so that lexing starts from scratch
doc.putProperty(Language.class, StateTokenId.language());
TokenHierarchy<?> hi = TokenHierarchy.get(doc);
TokenSequence<?> ts;
LanguagePath lp;
((AbstractDocument)doc).readLock();
try {
ts = hi.tokenSequence();
assertTrue(ts.moveNext());
LexerTestUtilities.assertTokenEquals(ts, StateTokenId.A, "a", 0);
lp = LanguagePath.get(StateTokenId.language());
assertFalse(Boolean.TRUE.equals(attrs.getValue(lp, "lexerRelease")));
assertTrue(ts.moveNext());
LexerTestUtilities.assertTokenEquals(ts, StateTokenId.BMULTI, "b", 1);
assertTrue(ts.moveNext());
LexerTestUtilities.assertTokenEquals(ts, StateTokenId.ERROR, "\n", 2);
assertFalse(ts.moveNext());
assertTrue(Boolean.TRUE.equals(attrs.getValue(lp, "lexerRelease")));
attrs.setValue(lp, "lexerRelease", Boolean.FALSE, false);
} finally {
((AbstractDocument)doc).readUnlock();
}
// Do modification and check lexer release after it
doc.insertString(1, "b", null);
assertTrue(Boolean.TRUE.equals(attrs.getValue(lp, "lexerRelease")));
}
示例15: test
import org.netbeans.api.lexer.InputAttributes; //导入方法依赖的package包/类
public void test() throws Exception {
Document doc = new ModificationTextDocument();
// Assign a language to the document
InputAttributes attrs = new InputAttributes();
doc.putProperty(InputAttributes.class, attrs);
doc.putProperty(Language.class, StateTokenId.language());
TokenHierarchy<?> hi = TokenHierarchy.get(doc);
TokenSequence<?> ts;
((AbstractDocument)doc).readLock();
try {
ts = hi.tokenSequence();
// Extra newline at the end of document returned in DocumentUtilities.getText(doc) is lexed too
assertTrue(ts.moveNext());
LexerTestUtilities.assertTokenEquals(ts, StateTokenId.ERROR, "\n", 0);
assertFalse(ts.moveNext());
} finally {
((AbstractDocument)doc).readUnlock();
}
// Insert text into document
String text = "abc";
doc.insertString(0, text, null);
((AbstractDocument)doc).readLock();
try {
ts = hi.tokenSequence();
assertTrue(ts.moveNext());
LexerTestUtilities.assertTokenEquals(ts, StateTokenId.A, "a", 0);
assertEquals(LexerTestUtilities.lookahead(ts), 0);
assertEquals(LexerTestUtilities.state(ts), StateLexer.AFTER_A);
assertTrue(ts.moveNext());
LexerTestUtilities.assertTokenEquals(ts, StateTokenId.BMULTI, "b", 1);
assertEquals(LexerTestUtilities.state(ts), StateLexer.AFTER_B);
assertEquals(LexerTestUtilities.lookahead(ts), 1);
assertTrue(ts.moveNext());
LexerTestUtilities.assertTokenEquals(ts, StateTokenId.ERROR, "c", 2);
assertTrue(ts.moveNext());
LexerTestUtilities.assertTokenEquals(ts, StateTokenId.ERROR, "\n", 3);
assertEquals(LexerTestUtilities.state(ts), null);
assertFalse(ts.moveNext());
LexerTestUtilities.incCheck(doc, false);
} finally {
((AbstractDocument)doc).readUnlock();
}
// Should relex "b" so restart state should be AFTER_A
attrs.setValue(StateTokenId.language(), "restartState", StateLexer.AFTER_A, true);
doc.insertString(2, "b", null);
}