本文整理汇总了Java中jdk.nashorn.internal.parser.Token.descPosition方法的典型用法代码示例。如果您正苦于以下问题:Java Token.descPosition方法的具体用法?Java Token.descPosition怎么用?Java Token.descPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.parser.Token
的用法示例。
在下文中一共展示了Token.descPosition方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeComments
import jdk.nashorn.internal.parser.Token; //导入方法依赖的package包/类
/**
* Removes all commentaries from some JavaScript code.
*
* @param text a source
* @return comments-free JavaScript code
*/
public static String removeComments(String text) {
StringBuilder sb = new StringBuilder();
int i = 0;
for (Long t : getCommentsTokens(text)) {
int offset = Token.descPosition(t);
int lenght = Token.descLength(t);
sb.append(text.substring(i, offset));
for (int j = 0; j < lenght; j++) {
sb.append(" ");//NOI18N
}
i = offset + lenght;
}
sb.append(text.substring(i));
return sb.toString();
}
示例2: format
import jdk.nashorn.internal.parser.Token; //导入方法依赖的package包/类
/**
* Format an error message to include source and line information.
* @param message Error message string.
* @param source Source file information.
* @param line Source line number.
* @param column Source column number.
* @param token Offending token descriptor.
* @return formatted string
*/
public static String format(final String message, final Source source, final int line, final int column, final long token) {
final String eoln = System.lineSeparator();
final int position = Token.descPosition(token);
final StringBuilder sb = new StringBuilder();
// Source description and message.
sb.append(source.getName()).
append(':').
append(line).
append(':').
append(column).
append(' ').
append(message).
append(eoln);
// Source content.
final String sourceLine = source.getSourceLine(position);
sb.append(sourceLine).append(eoln);
// Pointer to column.
for (int i = 0; i < column; i++) {
if (sourceLine.charAt(i) == '\t') {
sb.append('\t');
} else {
sb.append(' ');
}
}
sb.append('^');
// Use will append eoln.
// buffer.append(eoln);
return sb.toString();
}
示例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: reparse
import jdk.nashorn.internal.parser.Token; //导入方法依赖的package包/类
FunctionNode reparse() {
if (isSerialized()) {
return deserialize();
}
final int descPosition = Token.descPosition(token);
final Context context = Context.getContextTrusted();
final Parser parser = new Parser(
context.getEnv(),
source,
new Context.ThrowErrorManager(),
isStrict(),
// source starts at line 0, so even though lineNumber is the correct declaration line, back off
// one to make it exclusive
lineNumber - 1,
context.getLogger(Parser.class));
if (getFunctionFlag(FunctionNode.IS_ANONYMOUS)) {
parser.setFunctionName(functionName);
}
parser.setReparsedFunction(this);
final FunctionNode program = parser.parse(CompilerConstants.PROGRAM.symbolName(), descPosition,
Token.descLength(token), true);
// Parser generates a program AST even if we're recompiling a single function, so when we are only
// recompiling a single function, extract it from the program.
return (isProgram() ? program : extractFunctionFromScript(program)).setName(null, functionName);
}
示例5: format
import jdk.nashorn.internal.parser.Token; //导入方法依赖的package包/类
/**
* Format an error message to include source and line information.
* @param message Error message string.
* @param source Source file information.
* @param line Source line number.
* @param column Source column number.
* @param token Offending token descriptor.
* @return formatted string
*/
public static String format(final String message, final Source source, final int line, final int column, final long token) {
final String eoln = System.lineSeparator();
final int position = Token.descPosition(token);
final StringBuilder sb = new StringBuilder();
// Source description and message.
sb.append(source.getName()).
append(':').
append(line).
append(':').
append(column).
append(' ').
append(message).
append(eoln);
// Source content.
final String sourceLine = source.getSourceLine(position);
sb.append(sourceLine).append(eoln);
// Pointer to column.
for (int i = 0; i < column; i++) {
if (i < sourceLine.length() && sourceLine.charAt(i) == '\t') {
sb.append('\t');
} else {
sb.append(' ');
}
}
sb.append('^');
// Use will append eoln.
// buffer.append(eoln);
return sb.toString();
}
示例6: getString
import jdk.nashorn.internal.parser.Token; //导入方法依赖的package包/类
/**
* Fetch a portion of source content associated with a token.
* @param token Token descriptor.
* @return Source content portion.
*/
public String getString(final long token) {
final int start = Token.descPosition(token);
final int len = Token.descLength(token);
return new String(data(), start, len);
}
示例7: getString
import jdk.nashorn.internal.parser.Token; //导入方法依赖的package包/类
/**
* Fetch a portion of source content associated with a token.
* @param token Token descriptor.
* @return Source content portion.
*/
public String getString(final long token) {
final int start = Token.descPosition(token);
final int len = Token.descLength(token);
return new String(content, start, len);
}
示例8: tokenFor
import jdk.nashorn.internal.parser.Token; //导入方法依赖的package包/类
private static long tokenFor(final FunctionNode fn) {
final int position = Token.descPosition(fn.getFirstToken());
final int length = Token.descPosition(fn.getLastToken()) - position + Token.descLength(fn.getLastToken());
return Token.toDesc(TokenType.FUNCTION, position, length);
}
示例9: getPosition
import jdk.nashorn.internal.parser.Token; //导入方法依赖的package包/类
/**
* Get token position within source where the error originated.
* @return token position if available, else -1
*/
public int getPosition() {
return Token.descPosition(token);
}
示例10: Node
import jdk.nashorn.internal.parser.Token; //导入方法依赖的package包/类
/**
* Constructor
*
* @param token token
* @param finish finish
*/
public Node(final long token, final int finish) {
this.token = token;
this.start = Token.descPosition(token);
this.finish = finish;
}
示例11: position
import jdk.nashorn.internal.parser.Token; //导入方法依赖的package包/类
/**
* Return token position from a token descriptor.
*
* @return Start position of the token in the source.
*/
public int position() {
return Token.descPosition(token);
}
示例12: getId
import jdk.nashorn.internal.parser.Token; //导入方法依赖的package包/类
/**
* Get the unique ID for this function within the script file.
* @return the id
*/
public int getId() {
return isProgram() ? -1: Token.descPosition(firstToken);
}