本文整理汇总了Java中com.google.javascript.rhino.Node.getCharno方法的典型用法代码示例。如果您正苦于以下问题:Java Node.getCharno方法的具体用法?Java Node.getCharno怎么用?Java Node.getCharno使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.rhino.Node
的用法示例。
在下文中一共展示了Node.getCharno方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitNew
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Visits a NEW node.
*/
private void visitNew(NodeTraversal t, Node n) {
Node constructor = n.getFirstChild();
FunctionType type = getFunctionType(constructor);
if (type != null && type.isConstructor()) {
visitParameterList(t, n, type);
ensureTyped(t, n, type.getInstanceType());
} else {
// TODO(user): add support for namespaced objects.
if (constructor.getType() != Token.GETPROP) {
// TODO(user): make the constructor node have lineno/charno
// and use constructor for a more precise error indication.
// It seems that GETPROP nodes are missing this information.
Node line;
if (constructor.getLineno() < 0 || constructor.getCharno() < 0) {
line = n;
} else {
line = constructor;
}
t.report(line, NOT_A_CONSTRUCTOR);
}
ensureTyped(t, n);
}
}
示例2: splitVarDeclarations
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Split a var node such as:
* var a, b;
* into individual statements:
* var a;
* var b;
* @param n The whose children we should inspect.
*/
private void splitVarDeclarations(Node n) {
for (Node next, c = n.getFirstChild(); c != null; c = next) {
next = c.getNext();
if (c.getType() == Token.VAR) {
if (assertOnChange && !c.hasChildren()) {
throw new IllegalStateException("Empty VAR node.");
}
while (c.getFirstChild() != c.getLastChild()) {
Node name = c.getFirstChild();
c.removeChild(name);
Node newVar = new Node(
Token.VAR, name, n.getLineno(), n.getCharno());
n.addChildBefore(newVar, c);
reportCodeChange("VAR with multiple children");
}
}
}
}
示例3: formatNodePosition
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private String formatNodePosition(Node n) {
if (n == null) {
return MISSING_SOURCE + "\n";
}
int lineNumber = n.getLineno();
int columnNumber = n.getCharno();
String src = compiler.getSourceLine(sourceName, lineNumber);
if (src == null) {
src = MISSING_SOURCE;
}
return sourceName + ":" + lineNumber + ":" + columnNumber + "\n"
+ src + "\n";
}
示例4: JSError
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Creates a JSError for a source file location. Package private to avoid
* any entanglement with code outside of the compiler.
*
* This is a preferred internal constructor.
*/
private JSError(String sourceName, Node node,
DiagnosticType type, String... arguments) {
this(sourceName,
(node != null) ? node.getLineno() : -1,
(node != null) ? node.getCharno() : -1,
type, null, arguments);
}
示例5: rewriteCallExpression
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Rewrite the call so "this" is preserved.
* a.b(c);
* becomes:
* var temp1 = a;
* var temp0 = temp1.b;
* temp0.call(temp1,c);
*
* @return The replacement node.
*/
private Node rewriteCallExpression(Node call, DecompositionState state) {
Preconditions.checkArgument(call.getType() == Token.CALL);
Node first = call.getFirstChild();
Preconditions.checkArgument(NodeUtil.isGet(first));
// Extracts the expression representing the function to call. For example:
// "a['b'].c" from "a['b'].c()"
Node getVarNode = extractExpression(
first, state.extractBeforeStatement);
state.extractBeforeStatement = getVarNode;
// Extracts the object reference to be used as "this". For example:
// "a['b']" from "a['b'].c"
Node getExprNode = getVarNode.getFirstChild().getFirstChild();
Preconditions.checkArgument(NodeUtil.isGet(getExprNode));
Node thisVarNode = extractExpression(
getExprNode.getFirstChild(), state.extractBeforeStatement);
state.extractBeforeStatement = thisVarNode;
// Rewrite the CALL expression.
Node thisNameNode = thisVarNode.getFirstChild();
Node functionNameNode = getVarNode.getFirstChild();
// CALL
// GETPROP
// functionName
// "call"
// thisName
// original-parameter1
// original-parameter2
// ...
Node newCall = new Node(Token.CALL,
new Node(Token.GETPROP,
functionNameNode.cloneNode(),
Node.newString("call")),
thisNameNode.cloneNode(), call.getLineno(), call.getCharno());
// Throw away the call name
call.removeFirstChild();
if (call.hasChildren()) {
// Add the call parameters to the new call.
newCall.addChildrenToBack(call.removeChildren());
}
// Replace the call.
Node callParent = call.getParent();
callParent.replaceChild(call, newCall);
return newCall;
}
示例6: addMapping
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Adds a mapping for the given node.
*
* @param node The node that the new mapping represents.
* @param startPosition The position on the starting line
* @param endPosition The position on the ending line.
*/
void addMapping(Node node, Position startPosition, Position endPosition) {
Object sourceFile = node.getProp(Node.SOURCEFILE_PROP);
// If the node does not have an associated source file or
// its line number is -1, then the node does not have sufficient
// information for a mapping to be useful.
if (sourceFile == null || node.getLineno() < 0) {
return;
}
// Create the new mapping.
Mapping mapping = new Mapping();
mapping.id = mappings.size();
mapping.sourceFile = sourceFile.toString();
mapping.originalPosition = new Position(node.getLineno(), node.getCharno());
Object originalName = node.getProp(Node.ORIGINALNAME_PROP);
if (originalName != null) {
mapping.originalName = originalName.toString();
}
// If the mapping is found on the first line, we need to offset
// its character position by the number of characters found on
// the *last* line of the source file to which the code is
// being generated.
int offsetLine = offsetPosition.getLineNumber();
int startOffsetPosition = offsetPosition.getCharacterIndex();
int endOffsetPosition = offsetPosition.getCharacterIndex();
if (startPosition.getLineNumber() > 0) {
startOffsetPosition = 0;
}
if (endPosition.getLineNumber() > 0) {
endOffsetPosition = 0;
}
mapping.startPosition =
new Position(startPosition.getLineNumber() + offsetLine,
startPosition.getCharacterIndex() + startOffsetPosition);
mapping.endPosition =
new Position(endPosition.getLineNumber() + offsetLine,
endPosition.getCharacterIndex() + endOffsetPosition);
mappings.add(mapping);
}
示例7: make
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Creates a JSError from a file and Node position.
*
* @param sourceName The source file name
* @param n Determines the line and char position within the source file name
* @param type The DiagnosticType
* @param arguments Arguments to be incorporated into the message
*/
public static JSError make(String sourceName, Node n, CheckLevel level,
DiagnosticType type, String... arguments) {
return new JSError(sourceName, n.getLineno(), n.getCharno(), type, level,
arguments);
}