本文整理汇总了Java中jdk.nashorn.internal.parser.Token.descType方法的典型用法代码示例。如果您正苦于以下问题:Java Token.descType方法的具体用法?Java Token.descType怎么用?Java Token.descType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.parser.Token
的用法示例。
在下文中一共展示了Token.descType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dumpTokens
import jdk.nashorn.internal.parser.Token; //导入方法依赖的package包/类
/**
* Dump a token stream to stdout
*
* TODO: most other bugging goes to stderr, change?
*
* @param source the source
* @param lexer the lexer
* @param stream the stream to dump
*/
public static void dumpTokens(final Source source, final Lexer lexer, final TokenStream stream) {
TokenType type;
int k = 0;
do {
while (k > stream.last()) {
// Get more tokens.
lexer.lexify();
}
final long token = stream.get(k);
type = Token.descType(token);
System.out.println("" + k + ": " + Token.toString(source, token, true));
k++;
} while(type != EOF);
}
示例2: getCommentsTokens
import jdk.nashorn.internal.parser.Token; //导入方法依赖的package包/类
/**
* Extracts the comments tokens from a JavaScript source.
*
* @param aSource a source
* @return a list of comment tokens
*/
public static List<Long> getCommentsTokens(String aSource) {
TokenStream tokens = new TokenStream();
Lexer lexer = new Lexer(Source.sourceFor("", aSource), tokens);//NOI18N
long t;
TokenType tt = TokenType.EOL;
int i = 0;
List<Long> commentsTokens = new ArrayList<>();
while (tt != TokenType.EOF) {
// Get next token in nashorn's parser way
while (i > tokens.last()) {
if (tokens.isFull()) {
tokens.grow();
}
lexer.lexify();
}
t = tokens.get(i++);
tt = Token.descType(t);
if (tt == TokenType.COMMENT) {
commentsTokens.add(t);
}
}
return commentsTokens;
}
示例3: tokenFor
import jdk.nashorn.internal.parser.Token; //导入方法依赖的package包/类
private static long tokenFor(final FunctionNode fn) {
final int position = Token.descPosition(fn.getFirstToken());
final long lastToken = Token.withDelimiter(fn.getLastToken());
// EOL uses length field to store the line number
final int length = Token.descPosition(lastToken) - position + (Token.descType(lastToken) == TokenType.EOL ? 0 : Token.descLength(lastToken));
return Token.toDesc(TokenType.FUNCTION, position, length);
}
示例4: parseJs
import jdk.nashorn.internal.parser.Token; //导入方法依赖的package包/类
public static ParsedJs parseJs(String aJsContent) {
Source source = Source.sourceFor("", aJsContent);//NOI18N
Options options = new Options(null);
ScriptEnvironment env = new ScriptEnvironment(options, null, null);
ErrorManager errors = new ErrorManager();
//
Map<Long, Long> prevComments = new HashMap<>();
Parser p = new Parser(env, source, errors) {
@Override
public FunctionNode parse(String scriptName, int startPos, int len, boolean allowPropertyFunction) {
prevComments.clear();
stream = new TokenStream() {
protected long prevToken;
@Override
public void put(long token) {
if (Token.descType(token) != TokenType.EOL) {
if (Token.descType(prevToken) == TokenType.COMMENT) {
prevComments.put(token, prevToken);
}
prevToken = token;
}
super.put(token);
}
};
lexer = new Lexer(source, stream, false);
// Set up first token (skips opening EOL.)
k = -1;
next();
// Begin parse.
try {
Method program = Parser.class.getDeclaredMethod("program", new Class[]{String.class, boolean.class});
program.setAccessible(true);
return (FunctionNode) program.invoke(this, new Object[]{scriptName, true});
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
Logger.getLogger(Scripts.class.getName()).log(Level.WARNING, null, ex);
return null;
}
}
};
FunctionNode jsAst = p.parse();
return jsAst != null ? new ParsedJs(jsAst, prevComments) : null;
}
示例5: isIndex
import jdk.nashorn.internal.parser.Token; //导入方法依赖的package包/类
/**
* Return true if this node represents an index operation normally represented as {@link IndexNode}.
* @return true if an index access.
*/
public boolean isIndex() {
return Token.descType(getToken()) == TokenType.LBRACKET;
}
示例6: tokenType
import jdk.nashorn.internal.parser.Token; //导入方法依赖的package包/类
/**
* Return token tokenType from a token descriptor.
*
* @return Type of token.
*/
public TokenType tokenType() {
return Token.descType(token);
}
示例7: isTokenType
import jdk.nashorn.internal.parser.Token; //导入方法依赖的package包/类
/**
* Test token tokenType.
*
* @param type a type to check this token against
* @return true if token types match.
*/
public boolean isTokenType(final TokenType type) {
return Token.descType(token) == type;
}
示例8: tokenType
import jdk.nashorn.internal.parser.Token; //导入方法依赖的package包/类
/**
* Returns this node's token's type. If you want to check for the node having a specific token type,
* consider using {@link #isTokenType(TokenType)} instead.
*
* @return type of token.
*/
public TokenType tokenType() {
return Token.descType(token);
}