本文整理汇总了Java中com.google.javascript.rhino.Node.getChildAtIndex方法的典型用法代码示例。如果您正苦于以下问题:Java Node.getChildAtIndex方法的具体用法?Java Node.getChildAtIndex怎么用?Java Node.getChildAtIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.rhino.Node
的用法示例。
在下文中一共展示了Node.getChildAtIndex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateTypeOfParametersOnClosure
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* For functions with function parameters, type inference will set the type of
* a function literal argument from the function parameter type.
*/
private void updateTypeOfParametersOnClosure(Node n, FunctionType fnType) {
int i = 0;
for (Node iParameter : fnType.getParameters()) {
JSType iParameterType = iParameter.getJSType();
if (iParameterType instanceof FunctionType) {
FunctionType iParameterFnType = (FunctionType) iParameterType;
if (i + 1 >= n.getChildCount()) {
// TypeCheck#visitParametersList will warn so we bail.
return;
}
Node iArgument = n.getChildAtIndex(i + 1);
JSType iArgumentType = getJSType(iArgument);
if (iArgument.getType() == Token.FUNCTION &&
iArgumentType instanceof FunctionType &&
iArgumentType.getJSDocInfo() == null) {
iArgument.setJSType(iParameterFnType);
}
}
i++;
}
}
示例2: createCallProposals
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void createCallProposals(Node inspectedNode, Map<Integer, List<Proposal>> proposals, ArrayList<Var> internalVars, ArrayList<Var> externalVars) {
Node firstChild = inspectedNode.getFirstChild();
ArrayList<Var> visiableVars = new ArrayList<>();
internalVars.stream().filter(v->v.getNameNode().getSourceOffset() < inspectedNode.getSourceOffset())
.forEach(visiableVars::add);
visiableVars.addAll(externalVars);
if (firstChild != null && firstChild.getJSType() != null && firstChild.getJSType() instanceof FunctionType) {
FunctionType ft = (FunctionType)firstChild.getJSType();
int paramNum = 0;
for (Node paramterNode : ft.getParameters()) {
++paramNum;
ArrayList<Var> filteredVars = new ArrayList<>();
JSType parameterNodeType = fixNullType(paramterNode.getJSType());
visiableVars.stream().filter(v -> noTypeFound(v) || viableAssignment(v.getNameNode().getJSType(), parameterNodeType)).forEach(filteredVars::add);
Node argumentNode = inspectedNode.getChildCount() > paramNum?inspectedNode.getChildAtIndex(paramNum):null;
filteredVars.sort(this::compareTypeQuality);
ArrayList<Proposal> proposalList = new ArrayList<>(filteredVars.stream().map(v -> new Proposal(v.getName())).collect(Collectors.toList()));
if (parameterNodeType.isFunctionType() && (argumentNode == null || !argumentNode.getJSType().isFunctionType())) {
String newFunction = createFunctionDeclaration(parameterNodeType.toMaybeFunctionType());
proposalList.add(0,new Proposal(newFunction));
}
if (argumentNode != null) {
proposals.put(argumentNode.getSourceOffset(), proposalList);
} else {
proposals.put(inspectedNode.getSourceOffset()+inspectedNode.getLength()-1, proposalList);
break;
}
}
} else {
proposals.put(inspectedNode.getSourceOffset()+1,visiableVars.stream().map(v->new Proposal(v.getName())).collect(Collectors.toList()));
}
}
示例3: visitEs6Import
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void visitEs6Import(NodeTraversal t, Node n) {
Node namespace = n.getChildAtIndex(2);
if (!namespace.isString()) {
return;
}
checkNamespaceIsProvided(t, namespace, namespace.getString());
}
示例4: gatherFunctions
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Find all functions in this parse tree by recursively traversing it's children.
*/
private void gatherFunctions(Node parent, Set<CFGFunction> gathered) {
JavaScriptType objectLiteralType = null;
if(parent.getType() == Token.OBJECTLIT) {
String name = "";
Node parentParent = parent.getParent();
if(parentParent != null && parentParent.getType() == Token.ASSIGN) {
// Was this assigned to a property or a local?
Node assignee = parentParent.getChildAtIndex(0);
if(assignee.getType() == Token.GETPROP) {
Node property = assignee.getLastChild();
if(property != null && property.getType() == Token.STRING) {
name = property.getString();
}
}
else if(assignee.getType() == Token.NAME) {
name = assignee.getString();
}
else if(assignee.getType() == Token.GETELEM) {
}
else {
}
}
else if(parentParent.getType() == Token.NAME)
name = parentParent.getString();
objectLiteralType = new JavaScriptType(name, true);
objectLiteralTypes.put(parent, objectLiteralType);
if(!name.equals("")) namedObjectLiteralTypes.put(name, objectLiteralType);
// Feedlack.out("Found object literal named " + name + " on line " + parent.getLineno());
}
for(Node child : parent.children()) {
// Feedlack.out("On ");
if(child instanceof FunctionNode) {
CFGFunction fun = addFunction(parent, (FunctionNode)child);
gathered.add(fun);
if(objectLiteralType != null) {
objectLiteralType.addFunction(fun);
// Feedlack.out("Found function " + fun.getFunctionName() + " for type " + objectLiteralType.getName());
}
}
gatherFunctions(child, gathered);
}
}