Java Code Examples for com.google.javascript.rhino.jstype.JSType#hasProperty()
The following examples show how to use
com.google.javascript.rhino.jstype.JSType#hasProperty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Nopol2017_0029_t.java From coming with MIT License | 5 votes |
/** Check that we don't create new properties on structs. */ private void checkPropCreation(NodeTraversal t, Node lvalue) { if (lvalue.isGetProp()) { Node obj = lvalue.getFirstChild(); Node prop = lvalue.getLastChild(); JSType objType = getJSType(obj); String pname = prop.getString(); if (objType.isStruct() && !objType.hasProperty(pname)) { if (!(obj.isThis() && getJSType(t.getScope().getRootNode()).isConstructor())) { report(t, prop, ILLEGAL_PROPERTY_CREATION); } } } }
Example 2
Source File: Nopol2017_0029_s.java From coming with MIT License | 5 votes |
/** Check that we don't create new properties on structs. */ private void checkPropCreation(NodeTraversal t, Node lvalue) { if (lvalue.isGetProp()) { Node obj = lvalue.getFirstChild(); Node prop = lvalue.getLastChild(); JSType objType = getJSType(obj); String pname = prop.getString(); if (objType.isStruct() && !objType.hasProperty(pname)) { if (!(obj.isThis() && getJSType(t.getScope().getRootNode()).isConstructor())) { report(t, prop, ILLEGAL_PROPERTY_CREATION); } } } }
Example 3
Source File: Closure_125_TypeCheck_t.java From coming with MIT License | 5 votes |
/** * After a struct object is created, we can't add new properties to it, with * one exception. We allow creation of "static" properties like * Foo.prototype.bar = baz; * where Foo.prototype is a struct, if the assignment happens at the top level * and the constructor Foo is defined in the same file. */ private void checkPropCreation(NodeTraversal t, Node lvalue) { if (lvalue.isGetProp()) { Node obj = lvalue.getFirstChild(); Node prop = lvalue.getLastChild(); JSType objType = getJSType(obj); String pname = prop.getString(); if (!objType.isStruct() || objType.hasProperty(pname)) { return; } Scope s = t.getScope(); if (obj.isThis() && getJSType(s.getRootNode()).isConstructor()) { return; } // Prop created outside ctor, check that it's a static prop Node assgnExp = lvalue.getParent(); Node assgnStm = assgnExp.getParent(); if (objType instanceof ObjectType && s.isGlobal() && NodeUtil.isPrototypePropertyDeclaration(assgnStm)) { ObjectType instance = objType.toObjectType().getOwnerFunction().getInstanceType(); String file = lvalue.getSourceFileName(); Node ctor = instance.getConstructor().getSource(); if (ctor != null && ctor.getSourceFileName().equals(file)) { JSType rvalueType = assgnExp.getLastChild().getJSType(); instance.defineInferredProperty(pname, rvalueType, lvalue); return; } } report(t, prop, ILLEGAL_PROPERTY_CREATION); } }
Example 4
Source File: Closure_125_TypeCheck_s.java From coming with MIT License | 5 votes |
/** * After a struct object is created, we can't add new properties to it, with * one exception. We allow creation of "static" properties like * Foo.prototype.bar = baz; * where Foo.prototype is a struct, if the assignment happens at the top level * and the constructor Foo is defined in the same file. */ private void checkPropCreation(NodeTraversal t, Node lvalue) { if (lvalue.isGetProp()) { Node obj = lvalue.getFirstChild(); Node prop = lvalue.getLastChild(); JSType objType = getJSType(obj); String pname = prop.getString(); if (!objType.isStruct() || objType.hasProperty(pname)) { return; } Scope s = t.getScope(); if (obj.isThis() && getJSType(s.getRootNode()).isConstructor()) { return; } // Prop created outside ctor, check that it's a static prop Node assgnExp = lvalue.getParent(); Node assgnStm = assgnExp.getParent(); if (objType instanceof ObjectType && s.isGlobal() && NodeUtil.isPrototypePropertyDeclaration(assgnStm)) { ObjectType instance = objType.toObjectType().getOwnerFunction().getInstanceType(); String file = lvalue.getSourceFileName(); Node ctor = instance.getConstructor().getSource(); if (ctor != null && ctor.getSourceFileName().equals(file)) { JSType rvalueType = assgnExp.getLastChild().getJSType(); instance.defineInferredProperty(pname, rvalueType, lvalue); return; } } report(t, prop, ILLEGAL_PROPERTY_CREATION); } }
Example 5
Source File: Closure_2_TypeCheck_s.java From coming with MIT License | 5 votes |
/** Check that we don't create new properties on structs. */ private void checkPropCreation(NodeTraversal t, Node lvalue) { if (lvalue.isGetProp()) { Node obj = lvalue.getFirstChild(); Node prop = lvalue.getLastChild(); JSType objType = getJSType(obj); String pname = prop.getString(); if (objType.isStruct() && !objType.hasProperty(pname)) { if (!(obj.isThis() && getJSType(t.getScope().getRootNode()).isConstructor())) { report(t, prop, ILLEGAL_PROPERTY_CREATION); } } } }
Example 6
Source File: Closure_2_TypeCheck_t.java From coming with MIT License | 5 votes |
/** Check that we don't create new properties on structs. */ private void checkPropCreation(NodeTraversal t, Node lvalue) { if (lvalue.isGetProp()) { Node obj = lvalue.getFirstChild(); Node prop = lvalue.getLastChild(); JSType objType = getJSType(obj); String pname = prop.getString(); if (objType.isStruct() && !objType.hasProperty(pname)) { if (!(obj.isThis() && getJSType(t.getScope().getRootNode()).isConstructor())) { report(t, prop, ILLEGAL_PROPERTY_CREATION); } } } }
Example 7
Source File: TypeCheck.java From astor with GNU General Public License v2.0 | 5 votes |
/** Check that we don't create new properties on structs. */ private void checkPropCreation(NodeTraversal t, Node lvalue) { if (lvalue.isGetProp()) { Node obj = lvalue.getFirstChild(); Node prop = lvalue.getLastChild(); JSType objType = getJSType(obj); String pname = prop.getString(); if (objType.isStruct() && !objType.hasProperty(pname)) { if (!(obj.isThis() && getJSType(t.getScope().getRootNode()).isConstructor())) { report(t, prop, ILLEGAL_PROPERTY_CREATION); } } } }