@Override protected JSType caseTopType(JSType topType) { return getNativeType(NO_OBJECT_TYPE); }
@Override public JSType apply(TypeRestriction p) { return getRestrictedByTypeOfResult(p.type, "boolean", p.outcome); } })
@Override public FlowScope getPreciserScopeKnowingConditionOutcome(Node condition, FlowScope blindScope, boolean outcome) { if (condition.isCall() && condition.hasTwoChildren()) { Node callee = condition.getFirstChild(); Node param = condition.getLastChild(); if (callee.isGetProp() && param.isQualifiedName()) { JSType paramType = getTypeIfRefinable(param, blindScope); Node left = callee.getFirstChild(); Node right = callee.getLastChild(); if (left.isName() && "goog".equals(left.getString()) && right.isString()) { Function<TypeRestriction, JSType> restricter = restricters.get(right.getString()); if (restricter != null) { return restrictParameter(param, paramType, blindScope, restricter, outcome); } } } } return nextPreciserScopeKnowingConditionOutcome( condition, blindScope, outcome); }
p -> { if (p.outcome) { return getRestrictedWithoutUndefined(p.type); } else { return p.type != null ? getNativeType(VOID_TYPE).getGreatestSubtype(p.type) : null; if (p.outcome) { return p.type != null ? getNativeType(NULL_TYPE).getGreatestSubtype(p.type) : null; } else { return getRestrictedWithoutNull(p.type); p -> { if (p.outcome) { return getRestrictedWithoutUndefined(getRestrictedWithoutNull(p.type)); } else { return p.type != null ? getNativeType(NULL_VOID).getGreatestSubtype(p.type) : null; .put("isString", p -> getRestrictedByTypeOfResult(p.type, "string", p.outcome)) .put("isBoolean", p -> getRestrictedByTypeOfResult(p.type, "boolean", p.outcome)) .put("isNumber", p -> getRestrictedByTypeOfResult(p.type, "number", p.outcome)) .put("isFunction", p -> getRestrictedByTypeOfResult(p.type, "function", p.outcome)) .put( "isArray",
@Override public ReverseAbstractInterpreter getReverseAbstractInterpreter() { if (abstractInterpreter == null) { ChainableReverseAbstractInterpreter interpreter = new SemanticReverseAbstractInterpreter(getTypeRegistry()); if (options.closurePass) { interpreter = new ClosureReverseAbstractInterpreter(getTypeRegistry()) .append(interpreter).getFirst(); } abstractInterpreter = interpreter; } return abstractInterpreter; }
} else { return p.type != null ? getNativeType(VOID_TYPE).getGreatestSubtype(p.type) : null; if (p.outcome) { return p.type != null ? getNativeType(NULL_TYPE).getGreatestSubtype(p.type) : null; } else { return getRestrictedWithoutNull(p.type); @Override public JSType apply(TypeRestriction p) { return getRestrictedByTypeOfResult(p.type, "string", p.outcome); @Override public JSType apply(TypeRestriction p) { return getRestrictedByTypeOfResult(p.type, "number", p.outcome); public JSType apply(TypeRestriction p) { if (p.type == null) { return p.outcome ? getNativeType(ARRAY_TYPE) : null; public JSType apply(TypeRestriction p) { if (p.type == null) { return p.outcome ? getNativeType(OBJECT_TYPE) : null;
@CheckReturnValue private FlowScope restrictParameter( Node parameter, JSType type, FlowScope blindScope, Function<TypeRestriction, JSType> restriction, boolean outcome) { // restricting type = restriction.apply(new TypeRestriction(type, outcome)); // changing the scope if (type != null) { return declareNameInScope(blindScope, parameter, type); } else { return blindScope; } }
@Override public FlowScope getPreciserScopeKnowingConditionOutcome(Node condition, FlowScope blindScope, boolean outcome) { if (condition.isCall() && condition.getChildCount() == 2) { Node callee = condition.getFirstChild(); Node param = condition.getLastChild(); if (callee.isGetProp() && param.isQualifiedName()) { JSType paramType = getTypeIfRefinable(param, blindScope); Node left = callee.getFirstChild(); Node right = callee.getLastChild(); if (left.isName() && "goog".equals(left.getString()) && right.isString()) { Function<TypeRestriction, JSType> restricter = restricters.get(right.getString()); if (restricter != null) { return restrictParameter(param, paramType, blindScope, restricter, outcome); } } } } return nextPreciserScopeKnowingConditionOutcome( condition, blindScope, outcome); }
@Override public ReverseAbstractInterpreter getReverseAbstractInterpreter() { if (abstractInterpreter == null) { ChainableReverseAbstractInterpreter interpreter = new SemanticReverseAbstractInterpreter(getTypeRegistry()); if (options.closurePass) { interpreter = new ClosureReverseAbstractInterpreter(getTypeRegistry()) .append(interpreter).getFirst(); } abstractInterpreter = interpreter; } return abstractInterpreter; }
private FlowScope restrictParameter(Node parameter, JSType type, FlowScope blindScope, Function<TypeRestriction, JSType> restriction, boolean outcome) { // restricting type = restriction.apply(new TypeRestriction(type, outcome)); // changing the scope if (type != null) { FlowScope informed = blindScope.createChildFlowScope(); declareNameInScope(informed, parameter, type); return informed; } else { return blindScope; } }
@Override protected JSType caseTopType(JSType topType) { return getNativeType(NO_OBJECT_TYPE); }
@Override public JSType caseAllType() { return typeRegistry.createUnionType( getNativeType(NUMBER_STRING_BOOLEAN_SYMBOL), getNativeType(NULL_VOID)); }
@Override public JSType caseAllType() { return typeRegistry.createUnionType( getNativeType(NUMBER_STRING_BOOLEAN), getNativeType(NULL_VOID)); }