• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ObjectProperty类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.mozilla.javascript.ast.ObjectProperty的典型用法代码示例。如果您正苦于以下问题:Java ObjectProperty类的具体用法?Java ObjectProperty怎么用?Java ObjectProperty使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ObjectProperty类属于org.mozilla.javascript.ast包,在下文中一共展示了ObjectProperty类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: decompileObjectLiteral

import org.mozilla.javascript.ast.ObjectProperty; //导入依赖的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.ObjectProperty; //导入依赖的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.ObjectProperty; //导入依赖的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.ObjectProperty; //导入依赖的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.ObjectProperty; //导入依赖的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.ObjectProperty; //导入依赖的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: methodDefinition

import org.mozilla.javascript.ast.ObjectProperty; //导入依赖的package包/类
private ObjectProperty methodDefinition(int pos, AstNode propName, int entryKind)
    throws IOException
{
    FunctionNode fn = function(FunctionNode.FUNCTION_EXPRESSION);
    // We've already parsed the function name, so fn should be anonymous.
    Name name = fn.getFunctionName();
    if (name != null && name.length() != 0) {
        reportError("msg.bad.prop");
    }
    ObjectProperty pn = new ObjectProperty(pos);
    switch (entryKind) {
    case GET_ENTRY:
        pn.setIsGetterMethod();
        fn.setFunctionIsGetterMethod();
        break;
    case SET_ENTRY:
        pn.setIsSetterMethod();
        fn.setFunctionIsSetterMethod();
        break;
    case METHOD_ENTRY:
        pn.setIsNormalMethod();
        fn.setFunctionIsNormalMethod();
        break;
    }
    int end = getNodeEnd(fn);
    pn.setLeft(propName);
    pn.setRight(fn);
    pn.setLength(end - pos);
    return pn;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:31,代码来源:Parser.java


示例8: isObject

import org.mozilla.javascript.ast.ObjectProperty; //导入依赖的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


示例9: isMap

import org.mozilla.javascript.ast.ObjectProperty; //导入依赖的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


示例10: visitMethodOrEnum

import org.mozilla.javascript.ast.ObjectProperty; //导入依赖的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


示例11: print

import org.mozilla.javascript.ast.ObjectProperty; //导入依赖的package包/类
private void print(ObjectProperty node) throws IOException {
    if (node.isGetterMethod()) {
        writer.append("get ");
    } else if (node.isSetterMethod()) {
        writer.append("set ");
    }
    Map<String, NameEmitter> oldNameMap = nameMap;
    nameMap = Collections.emptyMap();
    print(node.getLeft());
    nameMap = oldNameMap;
    if (!node.isMethod()) {
        writer.ws().append(':').ws();
    }
    print(node.getRight());
}
 
开发者ID:konsoletyper,项目名称:teavm,代码行数:16,代码来源:AstWriter.java


示例12: transformObjectLiteral

import org.mozilla.javascript.ast.ObjectProperty; //导入依赖的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


示例13: isMethodAssignedInObjectLiteral

import org.mozilla.javascript.ast.ObjectProperty; //导入依赖的package包/类
public static boolean isMethodAssignedInObjectLiteral(FunctionNode n){
	return (n.getParent() instanceof ObjectProperty && n.getParent().getParent() instanceof ObjectLiteral);
}
 
开发者ID:Samsung,项目名称:SJS,代码行数:4,代码来源:ConstraintGenUtil.java


示例14: visit

import org.mozilla.javascript.ast.ObjectProperty; //导入依赖的package包/类
@Override
public boolean visit(AstNode node) {
    boolean continueProcessing = true;
    // We only need to check Object Literals
    if (node instanceof ObjectLiteral) {
        List<ObjectProperty> kvProps = null;
        List<ObjectProperty> props = ((ObjectLiteral) node).getElements();
        if (props != null) {
            // Walk through nodes to check if this is a root bundle with
            // key/value pairs embedded.
            for (int i = 0; i < props.size(); i++) {
                Node left = props.get(i).getLeft();
                String name = null;
                if (left instanceof StringLiteral) {
                    name = ((StringLiteral) left).getValue();
                } else if (left instanceof Name) {
                    name = ((Name) left).getIdentifier();
                } else {
                    continue;
                }
                Node right = props.get(i).getRight();
                if (name.equalsIgnoreCase("root")) {
                    // This AMD i18n bundle with "root" object
                    // (key/value pairs) embedded.
                    // For example,
                    //
                    // define({
                    // "root": {
                    // "msg.hello": "Hello",
                    // "msg.byte": "Bye"
                    // },
                    // "fr": true,
                    // "de": true
                    // });
                    //
                    right = removeParenthes(right);
                    if (right instanceof ObjectLiteral) {
                        kvProps = ((ObjectLiteral) right).getElements();
                        break;
                    }
                }
            }
        }

        if (kvProps == null) {
            // This bundle contains key/value pairs in the root Object
            // directly.
            // For example,
            //
            // define({
            // "msg.hello": "Hello",
            // "msg.byte": "Bye"
            // });
            //
            kvProps = props;
        }

        // Put key/value pairs to elements
        for (ObjectProperty kv : kvProps) {
            Node propKey = kv.getLeft();
            String key = null;
            if (propKey instanceof Name) {
                key = ((Name) propKey).getIdentifier();
            } else if (propKey instanceof StringLiteral) {
                key = ((StringLiteral) propKey).getValue();
            }
            if (key == null) {
                continue;
            }

            Node propVal = kv.getRight();
            String val = concatStringNodes(propVal);
            if (val == null) {
                continue;
            }
            elements.put(key, val);
        }
        continueProcessing = false;
    }
    return continueProcessing;
}
 
开发者ID:IBM-Cloud,项目名称:gp-java-tools,代码行数:82,代码来源:AmdJsResource.java


示例15: visitPropertyDescriptors

import org.mozilla.javascript.ast.ObjectProperty; //导入依赖的package包/类
/**
 * It is assumed that <code>descriptorObjectLit</code> has been
 * identified as an object literal containing property descriptors.  Any
 * property descriptors found as properties of that literal are parsed
 * and tree nodes are created for them.
 *
 * @param descriptorObjLit The object literal containing property
 *        descriptors (for example, the object parameter to
 *        <code>Object.create()</code>).
 * @param clazz The class that the properties belong to.
 */
private void visitPropertyDescriptors(ObjectLiteral descriptorObjLit,
		String clazz) {

	List<ObjectProperty> descriptors = descriptorObjLit.getElements();
	for (ObjectProperty prop : descriptors) {

		AstNode propertyKey = prop.getLeft();
		AstNode propertyValue = prop.getRight();

		// Should always be true, as this should be a property descriptor
		if (propertyValue instanceof ObjectLiteral) {

			JavaScriptTreeNode tn = createTreeNode(propertyKey);

			String memberName = RhinoUtil.getPropertyName(propertyKey);
			visitPropertyDescriptor(tn, clazz,
				memberName, (ObjectLiteral)propertyValue);

		}

	}

}
 
开发者ID:bobbylight,项目名称:RSTALanguageSupport,代码行数:35,代码来源:JavaScriptOutlineTreeGenerator.java



注:本文中的org.mozilla.javascript.ast.ObjectProperty类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ActionDomainEvent类代码示例发布时间:2022-05-23
下一篇:
Java XmlTagNameProvider类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap