本文整理汇总了Java中com.google.javascript.rhino.Node.getJSType方法的典型用法代码示例。如果您正苦于以下问题:Java Node.getJSType方法的具体用法?Java Node.getJSType怎么用?Java Node.getJSType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.rhino.Node
的用法示例。
在下文中一共展示了Node.getJSType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: maybeAddAutoboxes
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Add concrete types for autoboxing types if necessary. The concrete type
* system does not track native types, like string, so add them if they are
* present in the JSType for the node.
*/
private ConcreteType maybeAddAutoboxes(
ConcreteType cType, Node node, String prop) {
JSType jsType = node.getJSType();
if (jsType == null) {
return cType;
} else if (jsType.isUnknownType()) {
for (JSTypeNative nativeType : nativeTypes) {
ConcreteType concrete = tt.getConcreteInstance(
tt.getTypeRegistry().getNativeObjectType(nativeType));
if (concrete != null && !concrete.getPropertyType(prop).isNone()) {
cType = cType.unionWith(concrete);
}
}
return cType;
}
return maybeAddAutoboxes(cType, jsType, prop);
}
示例2: declareArguments
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Declares all of a function's arguments.
*/
private void declareArguments(Node functionNode) {
Node astParameters = functionNode.getFirstChild().getNext();
Node body = astParameters.getNext();
FunctionType functionType = (FunctionType) functionNode.getJSType();
if (functionType != null) {
Node jsDocParameters = functionType.getParametersNode();
if (jsDocParameters != null) {
Node jsDocParameter = jsDocParameters.getFirstChild();
for (Node astParameter : astParameters.children()) {
if (jsDocParameter != null) {
defineSlot(astParameter, functionNode,
jsDocParameter.getJSType(), true);
jsDocParameter = jsDocParameter.getNext();
} else {
defineSlot(astParameter, functionNode, null, true);
}
}
}
}
}
示例3: checkConstructorDeprecation
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Checks the given NEW node to ensure that access restrictions are obeyed.
*/
private void checkConstructorDeprecation(NodeTraversal t, Node n,
Node parent) {
JSType type = n.getJSType();
if (type != null) {
String deprecationInfo = getTypeDeprecationInfo(type);
if (deprecationInfo != null &&
shouldEmitDeprecationWarning(t, n, parent)) {
if (!deprecationInfo.isEmpty()) {
compiler.report(
JSError.make(t, n, DEPRECATED_CLASS_REASON,
type.toString(), deprecationInfo));
} else {
compiler.report(
JSError.make(t, n, DEPRECATED_CLASS, type.toString()));
}
}
}
}
示例4: declareNameInScope
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Declares a refined type in {@code scope} for the name represented by
* {@code node}. It must be possible to refine the type of the given node in
* the given scope, as determined by {@link #getTypeIfRefinable}.
*/
protected void declareNameInScope(FlowScope scope, Node node, JSType type) {
switch (node.getType()) {
case Token.NAME:
scope.inferSlotType(node.getString(), type);
break;
case Token.GETPROP:
String qualifiedName = node.getQualifiedName();
Preconditions.checkNotNull(qualifiedName);
JSType origType = node.getJSType();
origType = origType == null ? getNativeType(UNKNOWN_TYPE) : origType;
scope.inferQualifiedSlot(qualifiedName, origType, type);
break;
default:
throw new IllegalArgumentException("Node cannot be refined. \n" +
node.toStringTree());
}
}
示例5: 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++;
}
}
示例6: ensureTyped
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Enforces type casts, and ensures the node is typed.
*
* A cast in the way that we use it in JSDoc annotations never
* alters the generated code and therefore never can induce any runtime
* operation. What this means is that a 'cast' is really just a compile
* time constraint on the underlying value. In the future, we may add
* support for run-time casts for compiled tests.
*
* To ensure some shred of sanity, we enforce the notion that the
* type you are casting to may only meaningfully be a narrower type
* than the underlying declared type. We also invalidate optimizations
* on bad type casts.
*
* @param t The traversal object needed to report errors.
* @param n The node getting a type assigned to it.
* @param type The type to be assigned.
*/
private void ensureTyped(NodeTraversal t, Node n, JSType type) {
// Make sure FUNCTION nodes always get function type.
Preconditions.checkState(n.getType() != Token.FUNCTION ||
type instanceof FunctionType ||
type.isUnknownType());
JSDocInfo info = n.getJSDocInfo();
if (info != null) {
if (info.hasType()) {
JSType infoType = info.getType().evaluate(t.getScope());
validator.expectCanCast(t, n, infoType, type);
type = infoType;
}
if (info.isImplicitCast() && !inExterns) {
String propName = n.getType() == Token.GETPROP ?
n.getLastChild().getString() : "(missing)";
compiler.report(
JSError.make(t, n, ILLEGAL_IMPLICIT_CAST, propName));
}
}
if (n.getJSType() == null) {
n.setJSType(type);
}
}
示例7: testEnum21
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void testEnum21() throws Exception {
Node n = parseAndTypeCheck(
"/** @enum {string} */ var E = {A : 'a', B : 'b'};\n" +
"/** @param {!E} x\[email protected] {!E} */ function f(x) { return x; }");
Node nodeX = n.getLastChild().getLastChild().getLastChild().getLastChild();
JSType typeE = nodeX.getJSType();
assertFalse(typeE.isObject());
assertFalse(typeE.isNullable());
}
示例8: createAssignProposals
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void createAssignProposals(String code, Node inspectedNode, Map<Integer, List<Proposal>> proposals, ArrayList<Var> internalVars, ArrayList<Var> externalVars) {
JSType returnType = inspectedNode.getJSType();
Node currentNode = inspectedNode.getFirstChild();
if (currentNode != null)
currentNode = currentNode.getNext();
if (currentNode != null && isIntern(currentNode)) {
addArithmeticAndAssignProposals(code, inspectedNode, proposals, internalVars, externalVars, returnType, currentNode);
}
}
示例9: getJSType
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* This method gets the JSType from the Node argument and verifies that it is
* present.
*/
private JSType getJSType(Node n) {
JSType jsType = n.getJSType();
if (jsType == null) {
// TODO(user): This branch indicates a compiler bug, not worthy of
// halting the compilation but we should log this and analyze to track
// down why it happens. This is not critical and will be resolved over
// time as the type checker is extended.
return compiler.getTypeRegistry().getNativeType(
JSTypeNative.UNKNOWN_TYPE);
} else {
return jsType;
}
}
示例10: traverseHook
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private FlowScope traverseHook(Node n, FlowScope scope) {
Node condition = n.getFirstChild();
Node trueNode = condition.getNext();
Node falseNode = n.getLastChild();
// verify the condition
scope = traverse(condition, scope);
// reverse abstract interpret the condition to produce two new scopes
FlowScope trueScope = reverseInterpreter.
getPreciserScopeKnowingConditionOutcome(
condition, scope, true);
FlowScope falseScope = reverseInterpreter.
getPreciserScopeKnowingConditionOutcome(
condition, scope, false);
// traverse the true node with the trueScope
traverse(trueNode, trueScope.createChildFlowScope());
// traverse the false node with the falseScope
traverse(falseNode, falseScope.createChildFlowScope());
// meet true and false nodes' types and assign
JSType trueType = trueNode.getJSType();
JSType falseType = falseNode.getJSType();
if (trueType != null && falseType != null) {
n.setJSType(trueType.getLeastSupertype(falseType));
} else {
n.setJSType(null);
}
return scope.createChildFlowScope();
}
示例11: getTypeAnnotation
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private String getTypeAnnotation(Node node) {
JSType type = node.getJSType();
if (type instanceof FunctionType) {
return getFunctionAnnotation(node);
} else if (type != null && !type.isUnknownType()
&& !type.isEmptyType() && !type.isVoidType()) {
return "/** @type {" + node.getJSType() + "} */\n";
} else {
return "";
}
}
示例12: traverseObjectLiteral
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private FlowScope traverseObjectLiteral(Node n, FlowScope scope) {
if (n.getJSType() != null) {
// The node has already been traversed by the data-flow analysis
// framework. Don't re-generate the anonymous object as it might lead to
// pernicious bugs.
return scope;
}
ObjectType objectType = registry.createAnonymousObjectType();
for (Node name = n.getFirstChild(); name != null;
name = name.getNext().getNext()) {
Node value = name.getNext();
scope = traverse(name, scope);
scope = traverse(value, scope);
String memberName = NodeUtil.getStringValue(name);
if (memberName != null) {
// TODO(nicksantos): We need to fix the parser so that we can
// attach JSDoc to the individual elements of object literals.
// Right now, this is not possible.
objectType.defineInferredProperty(memberName, getJSType(value), false);
} else {
n.setJSType(getNativeType(UNKNOWN_TYPE));
return scope;
}
}
n.setJSType(objectType);
return scope;
}
示例13: createArithmeticProposals
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void createArithmeticProposals(String code, Node inspectedNode, Map<Integer, List<Proposal>> proposals, ArrayList<Var> internalVars, ArrayList<Var> externalVars) {
JSType returnType = inspectedNode.getJSType();
Node currentNode = inspectedNode.getFirstChild();
while (currentNode != null) {
if (isIntern(currentNode)) {
addArithmeticAndAssignProposals(code, inspectedNode, proposals, internalVars, externalVars, returnType, currentNode);
}
currentNode = currentNode.getNext();
}
}
示例14: getJSType
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private JSType getJSType(Node n) {
if (n.getJSType() != null) {
return n.getJSType();
} else {
return getTypeRegistry().getNativeType(UNKNOWN_TYPE);
}
}
示例15: traverseAssign
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private FlowScope traverseAssign(Node n, FlowScope scope) {
Node left = n.getFirstChild();
Node right = n.getLastChild();
scope = traverseChildren(n, scope);
JSType leftType = left.getJSType();
JSType rightType = getJSType(right);
n.setJSType(rightType);
updateScopeForTypeChange(scope, left, leftType, rightType);
return scope;
}