当前位置: 首页>>代码示例>>Java>>正文


Java Name.getIdentifier方法代码示例

本文整理汇总了Java中org.mozilla.javascript.ast.Name.getIdentifier方法的典型用法代码示例。如果您正苦于以下问题:Java Name.getIdentifier方法的具体用法?Java Name.getIdentifier怎么用?Java Name.getIdentifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.mozilla.javascript.ast.Name的用法示例。


在下文中一共展示了Name.getIdentifier方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: transformXmlRef

import org.mozilla.javascript.ast.Name; //导入方法依赖的package包/类
private Node transformXmlRef(Node pn, XmlRef node, int memberTypeFlags) {
    if ((memberTypeFlags & Node.ATTRIBUTE_FLAG) != 0)
        decompiler.addToken(Token.XMLATTR);
    Name namespace = node.getNamespace();
    String ns = namespace != null ? namespace.getIdentifier() : null;
    if (ns != null) {
        decompiler.addName(ns);
        decompiler.addToken(Token.COLONCOLON);
    }
    if (node instanceof XmlPropRef) {
        String name = ((XmlPropRef)node).getPropName().getIdentifier();
        decompiler.addName(name);
        return createPropertyGet(pn, ns, name, memberTypeFlags);
    } else {
        decompiler.addToken(Token.LB);
        Node expr = transform(((XmlElemRef)node).getExpression());
        decompiler.addToken(Token.RB);
        return createElementGet(pn, ns, expr, memberTypeFlags);
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:21,代码来源:IRFactory.java

示例2: cleanName

import org.mozilla.javascript.ast.Name; //导入方法依赖的package包/类
/**
 * Gets a Java-compatible "informative" name for the the ScriptOrFnNode
 */
String cleanName(final ScriptNode n)
{
  String result = "";
  if (n instanceof FunctionNode) {
    Name name = ((FunctionNode) n).getFunctionName();
    if (name == null) {
      result = "anonymous";
    } else {
      result = name.getIdentifier();
    }
  } else {
    result = "script";
  }
  return result;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:19,代码来源:Codegen.java

示例3: processVariableReference

import org.mozilla.javascript.ast.Name; //导入方法依赖的package包/类
/**
 * for an expression that consists of a simple reference to a variable, we create an ITerm
 * for that expression, find the unique representative for the referenced variable, and
 * generate a constraint that equates these.
 */
private ITypeTerm processVariableReference(Name name) {
	ITypeTerm expTerm = findOrCreateExpressionTerm(name);
	if (!ConstraintGenUtil.isGlobal(name)){ // no need for NameDeclarationTerm for global variables
		Name declaration = ConstraintGenUtil.findDecl(name);
		ITypeTerm nameTerm = findOrCreateNameDeclarationTerm(declaration);
		addTypeEqualityConstraint(expTerm, nameTerm, name.getLineno(), null);
	} else {
		String identifier = name.getIdentifier();
		if (identifier.equals("undefined")){
			addTypeEqualityConstraint(new TypeParamTerm(name), findOrCreateExpressionTerm(name), name.getLineno(), null);
		} else {
			ITypeTerm globalTerm = findOrCreateGlobalDeclarationTerm(name, jsEnv);
			addTypeEqualityConstraint(globalTerm, expTerm, name.getLineno(), null);
			createConstraintsForGlobalFunction(name);
		}
	}
	return expTerm;
}
 
开发者ID:Samsung,项目名称:SJS,代码行数:24,代码来源:ConstraintVisitor.java

示例4: findOrCreateNameDeclarationTerm

import org.mozilla.javascript.ast.Name; //导入方法依赖的package包/类
/**
 * Find or create a term representing an expression consisting of a variable name
 */
public NameDeclarationTerm findOrCreateNameDeclarationTerm(final Name name){
    Name name2 = ConstraintGenUtil.findDecl(name);
    if (name2 == null) {
        throw new Error("no declaration found for " + name.getIdentifier());
    }
    if (!nameTerms.containsKey(name2)){
        nameTerms.put(name2, new NameDeclarationTerm(name2));
    }
    return nameTerms.get(name2);
}
 
开发者ID:Samsung,项目名称:SJS,代码行数:14,代码来源:ConstraintFactory.java

示例5: createConstraintsForGlobalFunction

import org.mozilla.javascript.ast.Name; //导入方法依赖的package包/类
/**
 * Create constraints for parameterized external functions such as Array<T>
 */
private void createConstraintsForGlobalFunction(Name name) {
	ITypeTerm term = findOrCreateExpressionTerm(name);
	String functionName = name.getIdentifier();
	Type type = jsEnv.get(functionName);
	if (type == null){
		error("reference to unknown global: " + name.getIdentifier(), name);
		return;
	}
	ITypeTerm typeParamTerm = new TypeParamTerm(name);
	if (ConstraintGenUtil.isParameterized(type)){
		generateConstraintsForType(name, typeParamTerm, term, type);
	}
}
 
开发者ID:Samsung,项目名称:SJS,代码行数:17,代码来源:ConstraintVisitor.java

示例6: visit

import org.mozilla.javascript.ast.Name; //导入方法依赖的package包/类
@Override
public boolean visit(AstNode node) {
    if (node instanceof Name) {
        Name name = (Name) node;
        if (!name.isLocalName()) {
            String id = name.getIdentifier();
            usages.put(id, getUsage(id) + 1);
        }
    }
    return true;
}
 
开发者ID:konsoletyper,项目名称:teavm,代码行数:12,代码来源:JSBodyInlineUtil.java

示例7: extractVariableFromNode

import org.mozilla.javascript.ast.Name; //导入方法依赖的package包/类
/**
 * Extract the variable from the Rhino node and add to the CodeBlock
 * 
 * @param node AstNode node from which to extract the variable
 * @param block code block to add the variable too
 * @param offset position of the variable in code
 * @param initializer node associated with variable
 */
private JavaScriptVariableDeclaration extractVariableFromNode(AstNode node,
		CodeBlock block, int offset, AstNode initializer) {
	JavaScriptVariableDeclaration dec = null;
	// check that the caret position is below the dot before looking for
	// the variable
	if (node != null) {

		switch (node.getType()) {
			case Token.NAME:
				Name name = (Name) node;
				dec = new JavaScriptVariableDeclaration(name
						.getIdentifier(), offset, provider, block);
				dec.setStartOffset(name.getAbsolutePosition());
				dec.setEndOffset(name.getAbsolutePosition() + name.getLength());
				if (initializer != null
						&& initializer.getType() == Token.CALL) {
					// set the type node later for functions as these
					// sometimes cannot be resolved until
					// after the entire document is parsed
					ProcessFunctionType func = new ProcessFunctionType();
					func.dec = dec;
					func.typeNode = initializer;
					functions.add(func);
				}
				if (initializer == null
						|| JavaScriptHelper.canResolveVariable(name,
								initializer)) {
					block.addVariable(dec);
				}
				break;
			default:
				Logger.log("... Unknown var target type: "
						+ node.getClass());
				break;
		}
	}

	return dec;
}
 
开发者ID:bobbylight,项目名称:RSTALanguageSupport,代码行数:48,代码来源:JavaScriptAstParser.java

示例8: NameDeclarationTerm

import org.mozilla.javascript.ast.Name; //导入方法依赖的package包/类
public NameDeclarationTerm(Name name) {
super(name);
this.identifier = name.getIdentifier();
this.type = new AnyType();
}
 
开发者ID:Samsung,项目名称:SJS,代码行数:6,代码来源:NameDeclarationTerm.java

示例9: processAssignToPrototype

import org.mozilla.javascript.ast.Name; //导入方法依赖的package包/类
/**
 * assignment to the "prototype" property
 */
private void processAssignToPrototype(Assignment a, AstNode left, AstNode right, ITypeTerm expTerm) throws Error {
	PropertyGet pg = (PropertyGet)left;
	AstNode base = pg.getTarget();
	ITypeTerm pgTerm = findOrCreateExpressionTerm(pg);
	if (base instanceof Name){
		Name name = (Name)base;
		if (!validRHSForAssignToPrototype(right)) {
			error(
					"expression "
							+ right.toSource()
							+ " cannot be assigned to a constructor prototype (line "
							+ right.getLineno() + ")", a);
		}
		// can only write to prototype immediately after declaration of
		// constructor of the same name
		AstNode parent = a.getParent();
		if (!(parent instanceof ExpressionStatement)) {
			error(
					"assignment to prototype property not allowed here (line "
							+ a.getLineno() + ")", a);
			return;
		}
		Node prev = getPredecessorNode(parent);
		if (!(prev instanceof FunctionNode)) {
			error(
					"assignment to prototype property only allowed after constructor declaration (line "
							+ a.getLineno() + ")", a);
			return;
		}
		FunctionNode fn = (FunctionNode) prev;
		String functionName = fn.getName();
		String identifier = name.getIdentifier();
		if (!functionName.equals(identifier)) {
			error(
					"can only assign to prototype of function "
							+ functionName + " here (line " + a.getLineno()
							+ ")", a);
			return;
		}
		ITypeTerm baseTerm = findOrCreateExpressionTerm(base); // make term for expression
		ITypeTerm nameTerm = findOrCreateNameDeclarationTerm(name); // find unique representative for referenced Name
		addTypeEqualityConstraint(baseTerm, nameTerm, a.getLineno(), null); // equate them
		ITypeTerm protoTerm = findOrCreateProtoTerm(baseTerm, pg.getLineno());
		ITypeTerm rightTerm = processExpression(right);
		addTypeEqualityConstraint(pgTerm, protoTerm, a.getLineno(), null);
		addTypeEqualityConstraint(rightTerm, protoTerm, a.getLineno(), null);
		addTypeEqualityConstraint(expTerm, protoTerm, a.getLineno(), null);
	} else {
		error("processAssignToPrototype: unsupported case for receiver expression: " + base.getClass().getName(), base);
	}
}
 
开发者ID:Samsung,项目名称:SJS,代码行数:55,代码来源:ConstraintVisitor.java

示例10: checkForValidProtoPropAssign

import org.mozilla.javascript.ast.Name; //导入方法依赖的package包/类
private void checkForValidProtoPropAssign(Assignment a, PropertyGet pg,
		int assignLineNo, PropertyGet basePG) {
	AstNode baseTarget = basePG.getTarget();
	if (!(baseTarget instanceof Name)) {
		error("assignment to property of prototype not valid (line " + assignLineNo + ")", a);
		return;
	}
	Name baseName = (Name) baseTarget;
	AstNode parent = a.getParent();
	if (!(parent instanceof ExpressionStatement)) {
		error("assignment to property of prototype not valid (line " + assignLineNo + ")", a);
		return;
	}
	Node prev = getPredecessorNode(parent);
	if (prev instanceof FunctionNode) {
		FunctionNode fn = (FunctionNode) prev;
		String functionName = fn.getName();
		String identifier = baseName.getIdentifier();
		if (!functionName.equals(identifier)) {
			error("can only assign to prototype of function " + functionName + " here (line " + assignLineNo + ")", a);
			return;
		}

	} else if (prev instanceof ExpressionStatement) {
		// it needs to be an assignment either to C.prototype or C.prototype.foo
		// TODO clean up this gross code
		AstNode expression = ((ExpressionStatement)prev).getExpression();
		if (!(expression instanceof Assignment)) {
			error("assignment to property of prototype not valid (line " + assignLineNo + ")", a);
			return;
		}
		Assignment prevAssign = (Assignment) expression;
		AstNode prevLeft = prevAssign.getLeft();
		if (!(prevLeft instanceof PropertyGet)) {
			error("assignment to property of prototype not valid (line " + assignLineNo + ")", a);
			return;
		}
		PropertyGet prevPG = (PropertyGet) prevLeft;
		AstNode prevPGTarget = prevPG.getTarget();
		if (prevPG.getProperty().getIdentifier().equals("prototype")) {
			checkForSameName(assignLineNo, baseName, prevPGTarget);
		} else if (prevPGTarget instanceof PropertyGet) {
			PropertyGet prevPGBasePG = (PropertyGet) prevPGTarget;
			if (!prevPGBasePG.getProperty().getIdentifier().equals("prototype")) {
				error("assignment to property of prototype not valid (line " + assignLineNo + ")", a);
				return;
			}
			checkForSameName(assignLineNo, baseName, prevPGBasePG.getTarget());
		} else {
			error("assignment to property of prototype not valid (line " + assignLineNo + ")", a);
			return;
		}
	} else {
		error("assignment to property of prototype not valid (line " + assignLineNo + ")", a);
		return;
	}
}
 
开发者ID:Samsung,项目名称:SJS,代码行数:58,代码来源:ConstraintVisitor.java


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