PropDefinitionKind kind = typeRegistry.canPropertyBeDefined(objectType, propName); if (kind.equals(PropDefinitionKind.KNOWN)) { return;
private void checkPropertyAccessHelper(JSType objectType, String propName, NodeTraversal t, Node n) { if (!objectType.isEmptyType() && reportMissingProperties && (!NodeUtil.isPropertyTest(compiler, n) || objectType.isStruct()) && !typeRegistry.canPropertyBeDefined(objectType, propName)) { boolean lowConfidence = objectType.isUnknownType() || objectType.isEquivalentTo(getNativeType(OBJECT_TYPE)); SuggestionPair pair = null; if (!lowConfidence) { pair = getClosestPropertySuggestion(objectType, propName); } if (pair != null && pair.distance * 4 < propName.length()) { report(t, n.getLastChild(), INEXISTENT_PROPERTY_WITH_SUGGESTION, propName, typeRegistry.getReadableTypeName(n.getFirstChild()), pair.suggestion); } else { DiagnosticType reportType = lowConfidence ? POSSIBLE_INEXISTENT_PROPERTY : INEXISTENT_PROPERTY; report(t, n.getLastChild(), reportType, propName, typeRegistry.getReadableTypeName(n.getFirstChild())); } } }
private void checkPropCreation(NodeTraversal t, Node lvalue) { if (lvalue.isGetProp()) { JSType objType = getJSType(lvalue.getFirstChild()); if (!objType.isEmptyType() && !objType.isUnknownType()) { Node prop = lvalue.getLastChild(); String propName = prop.getString(); PropDefinitionKind kind = typeRegistry.canPropertyBeDefined(objType, propName); if (!kind.equals(PropDefinitionKind.KNOWN)) { if (objType.isStruct()) { report(t, prop, ILLEGAL_PROPERTY_CREATION); } else { // null checks are reported elsewhere if (!objType.isNoType() && !objType.isUnknownType() && objType.isSubtypeOf(getNativeType(NULL_VOID))) { return; } reportMissingProperty( lvalue.getFirstChild(), objType, lvalue.getSecondChild(), kind, t, true); } } } } }