Java Code Examples for org.mozilla.javascript.ast.ObjectProperty#getLeft()
The following examples show how to use
org.mozilla.javascript.ast.ObjectProperty#getLeft() .
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: MapLiteralTerm.java From SJS with Apache License 2.0 | 6 votes |
public List<String> getPropertyNames(){ List<String> propNames = new ArrayList<String>(); ObjectLiteral ol = (ObjectLiteral)this.getNode(); for (ObjectProperty op : ol.getElements()){ AstNode left = op.getLeft(); if (left instanceof Name){ propNames.add(((Name)left).getIdentifier()); } else if (left instanceof StringLiteral){ String identifier = ConstraintGenUtil.removeQuotes(((StringLiteral)left).toSource()); propNames.add(identifier); } else { System.err.println(left.getClass().getName() + " " + left.toSource()); throw new Error("unsupported case in getPropertyNames()"); } } return propNames; }
Example 2
Source File: ObjectLiteralTerm.java From SJS with Apache License 2.0 | 6 votes |
public List<String> getPropertyNames(){ List<String> propNames = new ArrayList<String>(); ObjectLiteral ol = (ObjectLiteral)this.getNode(); for (ObjectProperty op : ol.getElements()){ AstNode left = op.getLeft(); if (left instanceof Name){ propNames.add(((Name)left).getIdentifier()); } else if (left instanceof StringLiteral){ String identifier = ConstraintGenUtil.removeQuotes(((StringLiteral)left).toSource()); propNames.add(identifier); } else { System.err.println(left.getClass().getName() + " " + left.toSource()); throw new Error("unsupported case in getPropertyNames()"); } } return propNames; }
Example 3
Source File: ConstraintGenUtil.java From SJS with Apache License 2.0 | 6 votes |
public static List<String> getPropertyNames(ObjectLiteral ol){ List<String> propNames = new ArrayList<String>(); for (ObjectProperty op : ol.getElements()){ AstNode left = op.getLeft(); if (left instanceof Name){ propNames.add(((Name)left).getIdentifier()); } else if (left instanceof StringLiteral){ String identifier = ConstraintGenUtil.removeQuotes(((StringLiteral)left).toSource()); propNames.add(identifier); } else { System.err.println(left.getClass().getName() + " " + left.toSource()); throw new Error("unsupported case in getPropertyNames()"); } } return propNames; }
Example 4
Source File: ConstraintVisitor.java From SJS with Apache License 2.0 | 6 votes |
/** * Create constraints for an object literal. */ private ITypeTerm processObjectLiteralForObject(ObjectLiteral n) { ITypeTerm expTerm = findOrCreateObjectLiteralTerm(n); ObjectLiteral o = (ObjectLiteral)n; for (ObjectProperty prop : o.getElements()){ AstNode left = prop.getLeft(); AstNode right = prop.getRight(); if (left instanceof Name){ String identifier = ((Name)left).getIdentifier(); // for object literal o = { name_1 : exp_1, ..., name_k : exp_k } generate // a constraint |exp_i| <: prop(|o|, name_i) ITypeTerm propTerm = findOrCreatePropertyAccessTerm(expTerm, identifier, null); ITypeTerm valTerm = processExpression(right); processCopy(right, valTerm, propTerm, n.getLineno(), null); } } return expTerm; }
Example 5
Source File: ConstraintGenUtil.java From SJS with Apache License 2.0 | 5 votes |
/** * Tests if an object literal is an object by checking that all * properties are unquoted. */ static boolean isObject(ObjectLiteral o){ boolean result = (o.getElements().size() > 0); for (ObjectProperty prop : o.getElements()){ AstNode left = prop.getLeft(); result = result && (left instanceof Name); } return result; }
Example 6
Source File: ConstraintGenUtil.java From SJS with Apache License 2.0 | 5 votes |
/** * Tests if an object literal is a map by checking that * all properties are quoted. * In JavaScript, both double quotes and single quotes are * supported but for now we assume double quotes are used. * * Empty object literals are assumed to be maps. */ static boolean isMap(ObjectLiteral o){ boolean result = true; for (ObjectProperty prop : o.getElements()){ AstNode left = prop.getLeft(); result = result && (left instanceof StringLiteral); } return result; }