本文整理汇总了Java中org.mozilla.javascript.ast.ObjectLiteral类的典型用法代码示例。如果您正苦于以下问题:Java ObjectLiteral类的具体用法?Java ObjectLiteral怎么用?Java ObjectLiteral使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObjectLiteral类属于org.mozilla.javascript.ast包,在下文中一共展示了ObjectLiteral类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: decompileObjectLiteral
import org.mozilla.javascript.ast.ObjectLiteral; //导入依赖的package包/类
void decompileObjectLiteral(ObjectLiteral node) {
decompiler.addToken(Token.LC);
List<ObjectProperty> props = node.getElements();
int size = props.size();
for (int i = 0; i < size; i++) {
ObjectProperty prop = props.get(i);
boolean destructuringShorthand =
Boolean.TRUE.equals(prop.getProp(Node.DESTRUCTURING_SHORTHAND));
decompile(prop.getLeft());
if (!destructuringShorthand) {
decompiler.addToken(Token.COLON);
decompile(prop.getRight());
}
if (i < size - 1) {
decompiler.addToken(Token.COMMA);
}
}
decompiler.addToken(Token.RC);
}
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:20,代码来源:IRFactory.java
示例2: getPropertyNames
import org.mozilla.javascript.ast.ObjectLiteral; //导入依赖的package包/类
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;
}
开发者ID:Samsung,项目名称:SJS,代码行数:18,代码来源:MapLiteralTerm.java
示例3: getPropertyNames
import org.mozilla.javascript.ast.ObjectLiteral; //导入依赖的package包/类
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;
}
开发者ID:Samsung,项目名称:SJS,代码行数:17,代码来源:ConstraintGenUtil.java
示例4: processObjectLiteralForObject
import org.mozilla.javascript.ast.ObjectLiteral; //导入依赖的package包/类
/**
* 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;
}
开发者ID:Samsung,项目名称:SJS,代码行数:23,代码来源:ConstraintVisitor.java
示例5: processObjectLiteralForMap
import org.mozilla.javascript.ast.ObjectLiteral; //导入依赖的package包/类
/**
* Create constraints for a map literal.
*/
private ITypeTerm processObjectLiteralForMap(ObjectLiteral o) {
ITypeTerm expTerm = findOrCreateMapLiteralTerm(o);
for (ObjectProperty prop : o.getElements()){
AstNode left = prop.getLeft();
AstNode right = prop.getRight();
if (left instanceof StringLiteral){
// for map literal o = { name_1 : exp_1, ..., name_k : exp_k } generate
// a constraint |exp_i| <: MapElem(|o|)
ITypeTerm mapAccessTerm = findOrCreateIndexedTerm(expTerm, o.getLineno());
ITypeTerm valTerm = processExpression(right);
processCopy(right, valTerm, mapAccessTerm,
o.getLineno(), (solution) ->
genericTypeError("map does not have a homogenous value type", locationOf(prop))
.withNote("map value type is " + describeTypeOf(mapAccessTerm, solution))
.withNote("key " + left.toSource() + " has type " + describeTypeOf(valTerm, solution)));
}
}
return expTerm;
}
开发者ID:Samsung,项目名称:SJS,代码行数:25,代码来源:ConstraintVisitor.java
示例6: visitPrototypeMembers
import org.mozilla.javascript.ast.ObjectLiteral; //导入依赖的package包/类
private void visitPrototypeMembers(ObjectLiteral objLiteral,
String clazz) {
List<ObjectProperty> properties = objLiteral.getElements();
for (ObjectProperty property : properties) {
AstNode propertyKey = property.getLeft();
JavaScriptTreeNode tn = createTreeNode(propertyKey);
String memberName = RhinoUtil.getPropertyName(propertyKey);
AstNode propertyValue = property.getRight();
visitPrototypeMember(tn, clazz,
memberName, propertyValue);
}
}
开发者ID:bobbylight,项目名称:RSTALanguageSupport,代码行数:18,代码来源:JavaScriptOutlineTreeGenerator.java
示例7: decompile
import org.mozilla.javascript.ast.ObjectLiteral; //导入依赖的package包/类
void decompile(AstNode node) {
switch (node.getType()) {
case Token.ARRAYLIT:
decompileArrayLiteral((ArrayLiteral)node);
break;
case Token.OBJECTLIT:
decompileObjectLiteral((ObjectLiteral)node);
break;
case Token.STRING:
decompiler.addString(((StringLiteral)node).getValue());
break;
case Token.NAME:
decompiler.addName(((Name)node).getIdentifier());
break;
case Token.NUMBER:
decompiler.addNumber(((NumberLiteral)node).getNumber());
break;
case Token.GETPROP:
decompilePropertyGet((PropertyGet)node);
break;
case Token.EMPTY:
break;
case Token.GETELEM:
decompileElementGet((ElementGet) node);
break;
case Token.THIS:
decompiler.addToken(node.getType());
break;
default:
Kit.codeBug("unexpected token: "
+ Token.typeToName(node.getType()));
}
}
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:34,代码来源:IRFactory.java
示例8: arrowFunctionParams
import org.mozilla.javascript.ast.ObjectLiteral; //导入依赖的package包/类
private void arrowFunctionParams(FunctionNode fnNode, AstNode params, Map<String, Node> destructuring, Set<String> paramNames) {
if (params instanceof ArrayLiteral || params instanceof ObjectLiteral) {
markDestructuring(params);
fnNode.addParam(params);
String pname = currentScriptOrFn.getNextTempName();
defineSymbol(Token.LP, pname, false);
destructuring.put(pname, params);
} else if (params instanceof InfixExpression && params.getType() == Token.COMMA) {
arrowFunctionParams(fnNode, ((InfixExpression)params).getLeft(), destructuring, paramNames);
arrowFunctionParams(fnNode, ((InfixExpression)params).getRight(), destructuring, paramNames);
} else if (params instanceof Name) {
fnNode.addParam(params);
String paramName = ((Name)params).getIdentifier();
defineSymbol(Token.LP, paramName);
if (this.inUseStrictDirective) {
if ("eval".equals(paramName) ||
"arguments".equals(paramName))
{
reportError("msg.bad.id.strict", paramName);
}
if (paramNames.contains(paramName))
addError("msg.dup.param.strict", paramName);
paramNames.add(paramName);
}
} else {
reportError("msg.no.parm", params.getPosition(), params.getLength());
fnNode.addParam(makeErrorNode());
}
}
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:31,代码来源:Parser.java
示例9: ObjectLiteralTerm
import org.mozilla.javascript.ast.ObjectLiteral; //导入依赖的package包/类
public ObjectLiteralTerm(ObjectLiteral n){
super(n);
ObjectType oType = new ObjectType(this.getPropertyNames().stream()
.map((s) -> new Property(s, new AnyType(), false))
.collect(Collectors.toList()));
this.type = oType;
}
开发者ID:Samsung,项目名称:SJS,代码行数:8,代码来源:ObjectLiteralTerm.java
示例10: findOrCreateObjectLiteralTerm
import org.mozilla.javascript.ast.ObjectLiteral; //导入依赖的package包/类
/**
* Find or create a term representing the type of an object literal
*/
public ITypeTerm findOrCreateObjectLiteralTerm(ObjectLiteral n) {
if (!objectLiteralTerms.containsKey(n)){
objectLiteralTerms.put(n, new ObjectLiteralTerm(n));
}
return objectLiteralTerms.get(n);
}
开发者ID:Samsung,项目名称:SJS,代码行数:10,代码来源:ConstraintFactory.java
示例11: findOrCreateMapLiteralTerm
import org.mozilla.javascript.ast.ObjectLiteral; //导入依赖的package包/类
/**
* Find or create a term representing the type of a map literal
*/
public ITypeTerm findOrCreateMapLiteralTerm(ObjectLiteral n) {
if (!mapLiteralTerms.containsKey(n)){
mapLiteralTerms.put(n, new MapLiteralTerm(n));
}
return mapLiteralTerms.get(n);
}
开发者ID:Samsung,项目名称:SJS,代码行数:10,代码来源:ConstraintFactory.java
示例12: isObject
import org.mozilla.javascript.ast.ObjectLiteral; //导入依赖的package包/类
/**
* 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;
}
开发者ID:Samsung,项目名称:SJS,代码行数:13,代码来源:ConstraintGenUtil.java
示例13: isMap
import org.mozilla.javascript.ast.ObjectLiteral; //导入依赖的package包/类
/**
* 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;
}
开发者ID:Samsung,项目名称:SJS,代码行数:17,代码来源:ConstraintGenUtil.java
示例14: validRHSForAssignToPrototype
import org.mozilla.javascript.ast.ObjectLiteral; //导入依赖的package包/类
/**
* is right a valid expression to assign into the prototype field of a
* constructor? currently we allow object literals, constructor calls, and
* expressions of the form B.prototype
*
* @param right
* @return
*/
private boolean validRHSForAssignToPrototype(AstNode right) {
if (right instanceof ObjectLiteral || right instanceof NewExpression) {
return true;
}
if (right instanceof PropertyGet) {
PropertyGet pg = (PropertyGet) right;
if (pg.getProperty().getIdentifier().equals("prototype")) {
return true;
}
}
return false;
}
开发者ID:Samsung,项目名称:SJS,代码行数:21,代码来源:ConstraintVisitor.java
示例15: processObjectLiteral
import org.mozilla.javascript.ast.ObjectLiteral; //导入依赖的package包/类
/**
* generate constraints for object literals.
*/
private ITypeTerm processObjectLiteral(ObjectLiteral n) {
if (ConstraintGenUtil.isObject(n)){
return processObjectLiteralForObject(n);
} else if (ConstraintGenUtil.isMap(n)){
return processObjectLiteralForMap(n);
} else {
return expError("inconsistent use of quotes in object literal: " + n.toSource(), n);
}
}
开发者ID:Samsung,项目名称:SJS,代码行数:14,代码来源:ConstraintVisitor.java
示例16: visitMethodOrEnum
import org.mozilla.javascript.ast.ObjectLiteral; //导入依赖的package包/类
private void visitMethodOrEnum(final String name, final String jsDoc,
final AstNode astNode) {
if (jsDoc == null) {
//TODO sometimes values are recognized as enums even if they are not.
LOG.error("Comment in node {} for file {} is empty.", name, fileName);
return;
}
final JsElement element = parser.parse(fileName, jsDoc);
if (element == null || element.isPrivate()) {
return; // ignore private stuff...
}
if (element.isEnum()) {
final JsFile jsFile = parseClassOrInterfaceName(name, false, element);
files.put(name, jsFile);
if (astNode instanceof ObjectLiteral) {
final ObjectLiteral ol = (ObjectLiteral) astNode;
for (final ObjectProperty op : ol.getElements()) {
final Name left = (Name) op.getLeft();
jsFile.addEnumValue(left.toSource(), left.getJsDoc());
}
}
} else if (isMethod(name, element)) {
//method assigned as method variable.
final JsMethod method = addMethod(name, element, false);
if (method == null) {
LOG.warn("Should this be abstract: {} in file:{}", name, fileName);
} else {
method.setAbstract(true);
}
} else if (element.isConst() || element.isDefine()){
consts.put(name, element);
} else {
LOG.warn("We missed something: {}: {} in file:{}", name, element,
fileName);
}
}
开发者ID:gruifo,项目名称:gruifo,代码行数:38,代码来源:JavaScriptFileParser.java
示例17: print
import org.mozilla.javascript.ast.ObjectLiteral; //导入依赖的package包/类
private void print(ObjectLiteral node) throws IOException {
writer.append('{').ws();
if (node.getElements() != null && !node.getElements().isEmpty()) {
print(node.getElements().get(0));
for (int i = 1; i < node.getElements().size(); ++i) {
writer.append(',').ws();
print(node.getElements().get(i));
}
}
writer.ws().append('}');
}
开发者ID:konsoletyper,项目名称:teavm,代码行数:12,代码来源:AstWriter.java
示例18: transformObjectLiteral
import org.mozilla.javascript.ast.ObjectLiteral; //导入依赖的package包/类
private Node transformObjectLiteral(ObjectLiteral node) {
if (node.isDestructuring()) {
return node;
}
// createObjectLiteral rewrites its argument as object
// creation plus object property entries, so later compiler
// stages don't need to know about object literals.
decompiler.addToken(Token.LC);
List<ObjectProperty> elems = node.getElements();
Node object = new Node(Token.OBJECTLIT);
Object[] properties;
if (elems.isEmpty()) {
properties = ScriptRuntime.emptyArgs;
} else {
int size = elems.size(), i = 0;
properties = new Object[size];
for (ObjectProperty prop : elems) {
if (prop.isGetterMethod()) {
decompiler.addToken(Token.GET);
} else if (prop.isSetterMethod()) {
decompiler.addToken(Token.SET);
} else if (prop.isNormalMethod()) {
decompiler.addToken(Token.METHOD);
}
properties[i++] = getPropKey(prop.getLeft());
// OBJECTLIT is used as ':' in object literal for
// decompilation to solve spacing ambiguity.
if (!(prop.isMethod())) {
decompiler.addToken(Token.OBJECTLIT);
}
Node right = transform(prop.getRight());
if (prop.isGetterMethod()) {
right = createUnary(Token.GET, right);
} else if (prop.isSetterMethod()) {
right = createUnary(Token.SET, right);
} else if (prop.isNormalMethod()) {
right = createUnary(Token.METHOD, right);
}
object.addChildToBack(right);
if (i < size) {
decompiler.addToken(Token.COMMA);
}
}
}
decompiler.addToken(Token.RC);
object.putProp(Node.OBJECT_IDS_PROP, properties);
return object;
}
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:53,代码来源:IRFactory.java
示例19: memberExpr
import org.mozilla.javascript.ast.ObjectLiteral; //导入依赖的package包/类
/**
* Parse a new-expression, or if next token isn't {@link Token#NEW},
* a primary expression.
* @param allowCallSyntax passed down to {@link #memberExprTail}
*/
private AstNode memberExpr(boolean allowCallSyntax)
throws IOException
{
int tt = peekToken(), lineno = ts.lineno;
AstNode pn;
if (tt != Token.NEW) {
pn = primaryExpr();
} else {
consumeToken();
int pos = ts.tokenBeg;
NewExpression nx = new NewExpression(pos);
AstNode target = memberExpr(false);
int end = getNodeEnd(target);
nx.setTarget(target);
int lp = -1;
if (matchToken(Token.LP)) {
lp = ts.tokenBeg;
List<AstNode> args = argumentList();
if (args != null && args.size() > ARGC_LIMIT)
reportError("msg.too.many.constructor.args");
int rp = ts.tokenBeg;
end = ts.tokenEnd;
if (args != null)
nx.setArguments(args);
nx.setParens(lp - pos, rp - pos);
}
// Experimental syntax: allow an object literal to follow a new
// expression, which will mean a kind of anonymous class built with
// the JavaAdapter. the object literal will be passed as an
// additional argument to the constructor.
if (matchToken(Token.LC)) {
ObjectLiteral initializer = objectLiteral();
end = getNodeEnd(initializer);
nx.setInitializer(initializer);
}
nx.setLength(end - pos);
pn = nx;
}
pn.setLineno(lineno);
AstNode tail = memberExprTail(allowCallSyntax, pn);
return tail;
}
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:52,代码来源:Parser.java
示例20: destructuringAssignmentHelper
import org.mozilla.javascript.ast.ObjectLiteral; //导入依赖的package包/类
Node destructuringAssignmentHelper(int variableType, Node left,
Node right, String tempName)
{
Scope result = createScopeNode(Token.LETEXPR, left.getLineno());
result.addChildToFront(new Node(Token.LET,
createName(Token.NAME, tempName, right)));
try {
pushScope(result);
defineSymbol(Token.LET, tempName, true);
} finally {
popScope();
}
Node comma = new Node(Token.COMMA);
result.addChildToBack(comma);
List<String> destructuringNames = new ArrayList<String>();
boolean empty = true;
switch (left.getType()) {
case Token.ARRAYLIT:
empty = destructuringArray((ArrayLiteral)left,
variableType, tempName, comma,
destructuringNames);
break;
case Token.OBJECTLIT:
empty = destructuringObject((ObjectLiteral)left,
variableType, tempName, comma,
destructuringNames);
break;
case Token.GETPROP:
case Token.GETELEM:
switch (variableType) {
case Token.CONST:
case Token.LET:
case Token.VAR:
reportError("msg.bad.assign.left");
}
comma.addChildToBack(simpleAssignment(left, createName(tempName)));
break;
default:
reportError("msg.bad.assign.left");
}
if (empty) {
// Don't want a COMMA node with no children. Just add a zero.
comma.addChildToBack(createNumber(0));
}
result.putProp(Node.DESTRUCTURING_NAMES, destructuringNames);
return result;
}
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:48,代码来源:Parser.java
注:本文中的org.mozilla.javascript.ast.ObjectLiteral类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论