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


Java StringLiteral类代码示例

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


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

示例1: getPropertyNames

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

示例2: getPropertyNames

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

示例3: processObjectLiteralForMap

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

示例4: possiblyAMethodTerm

import org.mozilla.javascript.ast.StringLiteral; //导入依赖的package包/类
/**
 * conservative check that returns false only for terms that obviously do not represent methods
 *
 * TODO move this code inside ITypeTerm??
 * @param t
 * @return
 */
private boolean possiblyAMethodTerm(ITypeTerm t) {
    if (ConstraintGenUtil.isNullUndefinedLitOrVoidOp(t)) {
        return false;
    }
    if (t instanceof ExpressionTerm) {
        ExpressionTerm et = (ExpressionTerm) t;
        AstNode node = et.getNode();
        if (node != null) {
            return !(node instanceof NumberLiteral
                    || node instanceof StringLiteral);
        }
    }
    return !(t instanceof ArrayLiteralTerm
            || t instanceof MapLiteralTerm
            || t instanceof ObjectLiteralTerm
            || t instanceof TypeConstantTerm);
}
 
开发者ID:Samsung,项目名称:SJS,代码行数:25,代码来源:DirectionalConstraintSolver.java

示例5: decompile

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

示例6: getDirective

import org.mozilla.javascript.ast.StringLiteral; //导入依赖的package包/类
private String getDirective(AstNode n) {
    if (n instanceof ExpressionStatement) {
        AstNode e = ((ExpressionStatement) n).getExpression();
        if (e instanceof StringLiteral) {
            return ((StringLiteral) e).getValue();
        }
    }
    return null;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:10,代码来源:Parser.java

示例7: createStringLiteral

import org.mozilla.javascript.ast.StringLiteral; //导入依赖的package包/类
private StringLiteral createStringLiteral() {
    int pos = ts.tokenBeg, end = ts.tokenEnd;
    StringLiteral s = new StringLiteral(pos, end - pos);
    s.setLineno(ts.lineno);
    s.setValue(ts.getString());
    s.setQuoteCharacter(ts.getQuoteChar());
    return s;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:9,代码来源:Parser.java

示例8: isMap

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

示例9: isSyntacticModuleRequire

import org.mozilla.javascript.ast.StringLiteral; //导入依赖的package包/类
/**
   * Syntactically identify module imports
   */
  private boolean isSyntacticModuleRequire(FunctionCall fc) {
AstNode target = fc.getTarget();
      if (target instanceof Name) {
          Name name = (Name)target;
          return name.getIdentifier().equals("require") && fc.getArguments().size() == 1 && fc.getArguments().get(0) instanceof StringLiteral;
      } else {
          return false;
      }
  }
 
开发者ID:Samsung,项目名称:SJS,代码行数:13,代码来源:ConstraintVisitor.java

示例10: processStringLiteral

import org.mozilla.javascript.ast.StringLiteral; //导入依赖的package包/类
/**
 * for string constants, returns an ITerm representing the expression. A separate
 * equality constraint is generated that equates that term to string
 */
private ITypeTerm processStringLiteral(StringLiteral n) {
	ITypeTerm expTerm = findOrCreateExpressionTerm(n);
	ITypeTerm stringConst = findOrCreateTypeTerm(StringType.make(), n.getLineno());
	addTypeEqualityConstraint(expTerm, stringConst, n.getLineno(), null);
	return expTerm;
}
 
开发者ID:Samsung,项目名称:SJS,代码行数:11,代码来源:ConstraintVisitor.java

示例11: nameOf

import org.mozilla.javascript.ast.StringLiteral; //导入依赖的package包/类
/**
 * Find the textual name of the given node.
 */
@Nullable
private String nameOf(final AstNode node) {
  if (node instanceof Name) {
    return ((Name) node).getIdentifier();
  }
  else if (node instanceof PropertyGet) {
    PropertyGet prop = (PropertyGet) node;
    return String.format("%s.%s", nameOf(prop.getTarget()), nameOf(prop.getProperty()));
  }
  else if (node instanceof StringLiteral) {
    return ((StringLiteral) node).getValue();
  }
  return null;
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:18,代码来源:ClassDefScanner.java

示例12: stringLiteral

import org.mozilla.javascript.ast.StringLiteral; //导入依赖的package包/类
/**
 * Return string literal value.
 */
private String stringLiteral(final AstNode node) {
  checkState(node instanceof StringLiteral, node, "Expected string literal only");
  //noinspection ConstantConditions
  StringLiteral string = (StringLiteral) node;
  return string.getValue();
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:10,代码来源:ClassDefScanner.java

示例13: stringLiterals

import org.mozilla.javascript.ast.StringLiteral; //导入依赖的package包/类
/**
 * Returns string literal or array of string literals.
 *
 * @see #stringLiteral(AstNode)
 * @see #arrayStringLiteral(AstNode)
 */
private List<String> stringLiterals(final AstNode node) {
  // string literal or array of string literals
  if (node instanceof StringLiteral) {
    return Collections.singletonList(stringLiteral(node));
  }
  else if (node instanceof ArrayLiteral) {
    return arrayStringLiteral(node);
  }
  else {
    throw reportError(node, "Expected string literal or array of string literal only");
  }
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:19,代码来源:ClassDefScanner.java

示例14: safeGetString

import org.mozilla.javascript.ast.StringLiteral; //导入依赖的package包/类
protected static String safeGetString(AstNode node){
	if(node.getType() == Token.STRING){
		StringLiteral sl = (StringLiteral)node;
		return sl.getValue();
	}else if(node.getType()==Token.NUMBER){
		NumberLiteral nl = (NumberLiteral)node;
		return nl.getValue();
	}else{
		return node.getString();
	}
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:12,代码来源:FormulaInfo.java

示例15: extractMethodName

import org.mozilla.javascript.ast.StringLiteral; //导入依赖的package包/类
private boolean extractMethodName(AstNode node, StringBuilder sb) {
    if (node.getType() == Token.ADD) {
        InfixExpression infix = (InfixExpression) node;
        return extractMethodName(infix.getLeft(), sb) && extractMethodName(infix.getRight(), sb);
    } else if (node.getType() == Token.STRING) {
        sb.append(((StringLiteral) node).getValue());
        return true;
    } else {
        return false;
    }
}
 
开发者ID:konsoletyper,项目名称:teavm,代码行数:12,代码来源:JavaInvocationProcessor.java


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