本文整理汇总了Java中org.mozilla.javascript.ast.Name类的典型用法代码示例。如果您正苦于以下问题:Java Name类的具体用法?Java Name怎么用?Java Name使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Name类属于org.mozilla.javascript.ast包,在下文中一共展示了Name类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例2: xmlElemRef
import org.mozilla.javascript.ast.Name; //导入依赖的package包/类
/**
* Parse the [expr] portion of an xml element reference, e.g.
* @[expr], @*::[expr], or ns::[expr].
*/
private XmlElemRef xmlElemRef(int atPos, Name namespace, int colonPos)
throws IOException
{
int lb = ts.tokenBeg, rb = -1, pos = atPos != -1 ? atPos : lb;
AstNode expr = expr();
int end = getNodeEnd(expr);
if (mustMatchToken(Token.RB, "msg.no.bracket.index")) {
rb = ts.tokenBeg;
end = ts.tokenEnd;
}
XmlElemRef ref = new XmlElemRef(pos, end - pos);
ref.setNamespace(namespace);
ref.setColonPos(colonPos);
ref.setAtPos(atPos);
ref.setExpression(expr);
ref.setBrackets(lb, rb);
return ref;
}
示例3: 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;
}
示例4: getPropertyNames
import org.mozilla.javascript.ast.Name; //导入依赖的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;
}
示例5: findOrCreateFunctionTerm
import org.mozilla.javascript.ast.Name; //导入依赖的package包/类
/**
* Find or create a term representing a FunctionNode (function definition). The
* created FunctionTerm provides methods for accessing the terms corresponding to the
* function's parameters and return type. The boolean flag isMethod indicates whether
* the function is a method.
*/
public FunctionTerm findOrCreateFunctionTerm(FunctionNode fun, FunctionTerm.FunctionKind funType) {
if (!functionTerms.containsKey(fun)){
FunctionTerm var = new FunctionTerm(fun, funType);
var.setReturnVariable(this.findOrCreateFunctionReturnTerm(var, fun.getParamCount()));
List<AstNode> params = fun.getParams();
List<NameDeclarationTerm> paramVars = new ArrayList<NameDeclarationTerm>();
for (int i=0; i < params.size(); i++){
AstNode param = params.get(i);
if (param instanceof Name){
NameDeclarationTerm paramCV = this.findOrCreateNameDeclarationTerm((Name)param);
paramVars.add(paramCV);
} else {
throw new Error("unimplemented case in findOrCreateFunctionVariable");
}
}
var.setParamVariables(paramVars);
functionTerms.put(fun, var);
}
return functionTerms.get(fun);
}
示例6: getPropertyNames
import org.mozilla.javascript.ast.Name; //导入依赖的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;
}
示例7: createFunctionNodeConstraints
import org.mozilla.javascript.ast.Name; //导入依赖的package包/类
/**
* For a function definition (FunctionNode), create constraints equating its
* parameters to param(.) variables, and equate the type of the function name
* to the type of the entire function definition.
*/
private void createFunctionNodeConstraints(FunctionNode node, ITypeTerm funTerm){
// if the function has a name, equate the types of the function node and the function name
Name funName = node.getFunctionName();
if (funName != null){
ITypeTerm nameTerm = findOrCreateNameDeclarationTerm(funName);
addSubTypeConstraint(funTerm, nameTerm, node.getLineno(), null);
}
// for a function f with params v1, v2, ... generate param(|f|,i) = |v_i|
for (int i=0; i < node.getParamCount(); i++){
AstNode param = node.getParams().get(i);
if (param instanceof Name){
Name name = (Name)param;
ITypeTerm nameVar = findOrCreateNameDeclarationTerm(name);
ITypeTerm paramVar = findOrCreateFunctionParamTerm(funTerm, i, node.getParamCount(), node.getLineno());
addTypeEqualityConstraint(paramVar, nameVar, param.getLineno(), null);
} else {
error("createFunctionNodeConstraints: unexpected parameter type", node);
}
}
}
示例8: processAssignment
import org.mozilla.javascript.ast.Name; //导入依赖的package包/类
/**
* generate constraints for assignments
*/
private void processAssignment(Assignment a) throws Error {
AstNode left = a.getLeft();
AstNode right = a.getRight();
ITypeTerm expTerm = findOrCreateExpressionTerm(a);
if (left instanceof Name){
processAssignToVariable(a, left, right, expTerm);
} else if (left instanceof PropertyGet) {
PropertyGet pg = (PropertyGet)left;
if (pg.getProperty().getIdentifier().equals("prototype")){
processAssignToPrototype(a, left, right, expTerm);
} else {
processAssignToProperty(a, left, right, expTerm);
}
processExpression(pg.getTarget()); // TEST
} else if (left instanceof ElementGet){
processIndexedAssignment(a, left, right, expTerm);
} else {
error("unsupported LHS type in Assignment: " + left.getClass().getName(), left);
}
}
示例9: processObjectLiteralForObject
import org.mozilla.javascript.ast.Name; //导入依赖的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;
}
示例10: 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;
}
示例11: createLookupString
import org.mozilla.javascript.ast.Name; //导入依赖的package包/类
private String createLookupString(FunctionCall fn)
{
StringBuilder sb = new StringBuilder();
String name = "";
switch(fn.getTarget().getType())
{
case Token.NAME : name = ((Name) fn.getTarget()).getIdentifier();
break;
}
sb.append(name);
sb.append("(");
Iterator<AstNode> i = fn.getArguments().iterator();
while (i.hasNext())
{
i.next();
sb.append("p");
if(i.hasNext())
sb.append(",");
}
sb.append(")");
return sb.toString();
}
示例12: lookupFromName
import org.mozilla.javascript.ast.Name; //导入依赖的package包/类
/**
* Lookup the name of the node within the last JavaScript type. e.g var a =
* 1; var b = a.MAX_VALUE; looks up MAX_VALUE within NumberLiteral a where a
* is resolve before as a JavaScript Number;
*
* @param node
* @param lastJavaScriptType
* @return
*/
protected JavaScriptType lookupFromName(AstNode node,
JavaScriptType lastJavaScriptType) {
JavaScriptType javaScriptType = null;
if (lastJavaScriptType != null) {
String lookupText = null;
switch (node.getType()) {
case Token.NAME:
lookupText = ((Name) node).getIdentifier();
break;
}
if (lookupText == null) {
// just try the source
lookupText = node.toSource();
}
javaScriptType = lookupJavaScriptType(lastJavaScriptType,
lookupText);
}
return javaScriptType;
}
示例13: decompile
import org.mozilla.javascript.ast.Name; //导入依赖的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()));
}
}
示例14: arrowFunctionParams
import org.mozilla.javascript.ast.Name; //导入依赖的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());
}
}
示例15: breakStatement
import org.mozilla.javascript.ast.Name; //导入依赖的package包/类
private BreakStatement breakStatement()
throws IOException
{
if (currentToken != Token.BREAK) codeBug();
consumeToken();
int lineno = ts.lineno, pos = ts.tokenBeg, end = ts.tokenEnd;
Name breakLabel = null;
if (peekTokenOrEOL() == Token.NAME) {
breakLabel = createNameNode();
end = getNodeEnd(breakLabel);
}
// matchJumpLabelName only matches if there is one
LabeledStatement labels = matchJumpLabelName();
// always use first label as target
Jump breakTarget = labels == null ? null : labels.getFirstLabel();
if (breakTarget == null && breakLabel == null) {
if (loopAndSwitchSet == null || loopAndSwitchSet.size() == 0) {
if (breakLabel == null) {
reportError("msg.bad.break", pos, end - pos);
}
} else {
breakTarget = loopAndSwitchSet.get(loopAndSwitchSet.size() - 1);
}
}
BreakStatement pn = new BreakStatement(pos, end - pos);
pn.setBreakLabel(breakLabel);
// can be null if it's a bad break in error-recovery mode
if (breakTarget != null)
pn.setBreakTarget(breakTarget);
pn.setLineno(lineno);
return pn;
}