本文整理汇总了Java中org.mozilla.javascript.ast.AstNode.toSource方法的典型用法代码示例。如果您正苦于以下问题:Java AstNode.toSource方法的具体用法?Java AstNode.toSource怎么用?Java AstNode.toSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mozilla.javascript.ast.AstNode
的用法示例。
在下文中一共展示了AstNode.toSource方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitOtherNode
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
private void visitOtherNode(final AstNode node) {
if (node instanceof PropertyGet
&& node.getParent() instanceof ExpressionStatement) {
if (node.getJsDoc() == null) {
LOG.error("Node {} has empty comment in file:{}",
node.toSource(), fileName);
return;
}
final JsElement element = parser.parse(fileName, node.getJsDoc());
final String typedef = node.toSource();
if (isMethod(typedef, element)) {
addMethodOrField(typedef, element, false);
} else if (element.getType() == null) {
final JsFile jFile = parseClassOrInterfaceName(typedef,
element.isInterface(), element);
files.put(typedef, jFile);
} else {
LOG.error("Type '{}' ignored in file:{}", typedef, fileName);
}
}
}
示例2: findJavaStaticType
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
/**
* Try to resolve the Token.NAME AstNode and return a TypeDeclaration
* @param node node to resolve
* @return TypeDeclaration if the name can be resolved as a Java Class else null
*/
protected TypeDeclaration findJavaStaticType(AstNode node) {
// check parent is of type property get
String testName = node.toSource();
if (testName != null) {
TypeDeclaration dec = JavaScriptHelper.getTypeDeclaration(testName, provider);
if(dec != null)
{
ClassFile cf = provider.getJavaScriptTypesFactory().getClassFile(
provider.getJarManager(), dec);
if (cf != null) {
TypeDeclaration returnDec = provider.getJavaScriptTypesFactory()
.createNewTypeDeclaration(cf, true, false);
return returnDec;
}
}
}
return null;
}
示例3: lookupFromName
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的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;
}
示例4: canResolveVariable
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
/**
* Test whether the start of the variable is the same name as the variable
* being initialised. This is not possible.
*
* @param target Name of variable being created
* @param initialiser name of initialiser
* @return true if name is different
*/
public static boolean canResolveVariable(AstNode target, AstNode initialiser) {
String varName = target.toSource();
try {
String init = initialiser.toSource();
String[] splitInit = init.split("\\.");
if (splitInit.length > 0) {
return !varName.equals(splitInit[0]);
}
}
catch(Exception e) {
//AstNode can throw exceptions if toSource() is invalid e.g new Date(""..toString());
}
return false;
}
示例5: convertNodeToSource
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
public static String convertNodeToSource(AstNode node)
{
try
{
return node.toSource();
}
catch(Exception e)
{
Logger.log(e.getMessage());
}
return null;
}
示例6: findNewExpressionString
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
/**
* Returns the node name from 'Token.NEW' AstNode e.g new Object --> Object
* new Date --> Date etc..
*
* @param node NewExpression node
* @return Extracts the Name identifier from NewExpression
*/
private static String findNewExpressionString(AstNode node) {
NewExpression newEx = (NewExpression) node;
AstNode target = newEx.getTarget();
String source = target.toSource();
int index = source.indexOf('(');
if (index != -1) {
source = source.substring(0, index);
}
return source;
}
示例7: resolveTypeFromFunctionNode
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
/**
* Get the source of the node and try to resolve function node:
*
* @param functionNode
* @return a.toString().getCharAt(1); returns String TypeDeclaration
*/
public TypeDeclaration resolveTypeFromFunctionNode(AstNode functionNode) {
String functionText = functionNode.toSource();
// resolve the TypeDeclaration and set on the variable
return resolveTypeDeclation(functionText);
}
示例8: evaluate
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
@Override
public byte evaluate(TypeInfSolverVariable lhsVar, TypeInfSolverVariable rhsVar) {
TypeConstraintSolverVariable lhs = (TypeConstraintSolverVariable) lhsVar;
TypeConstraintSolverVariable rhs = (TypeConstraintSolverVariable) rhsVar;
if (lhs == null) {
throw new IllegalArgumentException("lhs == null");
}
Type old = lhs.getType();
boolean changed = false;
logger.debug("called on {} and {}", lhs, rhs);
Type rhsType = rhs.getType();
if (rhsType instanceof TopReferenceType) {
System.err.println("doh");
}
if (Types.isEqual(old, rhsType)) {
// do nothing
} else if (old instanceof BottomType) {
// initialize to the RHS type
ITypeTerm termForType = rhs.getTermForType();
if (termForType instanceof TypeConstantTerm) {
// the type constant term is not useful for diagnosis. Use the
// expression
// term representing the constant value
termForType = lhs.getOrigTerm();
}
if (rhsType instanceof UnattachedMethodType && targetTerm instanceof PropertyAccessTerm) {
PropertyAccessTerm targetAccess = (PropertyAccessTerm) targetTerm;
if (isValidMethodUpdateTarget(targetAccess)) {
// since we're writing into a property, make the type an
// attached method
UnattachedMethodType umt = (UnattachedMethodType) rhsType;
rhsType = new AttachedMethodType(umt.paramTypes(),
umt.paramNames(), umt.returnType());
} else {
// TODO source location!!!
AstNode node = targetTerm.getNode();
if (node != null) {
throw new CoreException("cannot update " + node.toSource() + " with a method (line " + node.getLineno() + ")",
Cause.derived(lhs.reasonForCurrentValue, rhs.reasonForCurrentValue, reason));
} else {
throw new CoreException("cannot update " + targetTerm + " with a method",
Cause.derived(lhs.reasonForCurrentValue, rhs.reasonForCurrentValue, reason));
}
}
}
lhs.setTypeAndTerm(rhsType, termForType,
Cause.derived(lhs.reasonForCurrentValue, rhs.reasonForCurrentValue, reason));
changed = true;
} else if (rhsType instanceof BottomType) {
// do nothing
} else {
changed = joinType(lhs, rhs);
}
logger.debug("Changed = {}, result: lhs is now {}", (changed?"Y":"N"), lhs);
return changed ? FixedPointConstants.CHANGED : FixedPointConstants.NOT_CHANGED;
}
示例9: findJavaStaticType
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
/**
* Try to resolve the Token.NAME AstNode and return a TypeDeclaration
* @param node node to resolve
* @return TypeDeclaration if the name can be resolved as a Java Class else null
*/
@Override
protected TypeDeclaration findJavaStaticType(AstNode node) {
// check parent is of type property get
String testName = null;
if (node.getParent() != null
&& node.getParent().getType() == Token.GETPROP) { // ast
// parser
String name = node.toSource();
try
{
String longName = node.getParent().toSource();
if(longName.indexOf('[') == -1 && longName.indexOf(']') == -1 &&
longName.indexOf('(') == -1 && longName.indexOf(')') == -1) {
// trim the text to the short name
int index = longName.lastIndexOf(name);
if (index > -1) {
testName = longName.substring(0, index + name.length());
}
}
}
catch(Exception e)
{
Logger.log(e.getMessage());
}
}
else {
testName = node.toSource();
}
if (testName != null) {
TypeDeclaration dec = JavaScriptHelper.getTypeDeclaration(testName, provider);
if(dec == null)
dec = JavaScriptHelper.createNewTypeDeclaration(testName);
ClassFile cf = provider.getJavaScriptTypesFactory().getClassFile(
provider.getJarManager(), dec);
if (cf != null) {
TypeDeclaration returnDec = provider.getJavaScriptTypesFactory()
.createNewTypeDeclaration(cf, true, false);
return returnDec;
}
}
return null;
}