本文整理汇总了Java中org.codehaus.groovy.ast.expr.Expression.transformExpression方法的典型用法代码示例。如果您正苦于以下问题:Java Expression.transformExpression方法的具体用法?Java Expression.transformExpression怎么用?Java Expression.transformExpression使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.ast.expr.Expression
的用法示例。
在下文中一共展示了Expression.transformExpression方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transformMapEntryExpression
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
private Expression transformMapEntryExpression(MapEntryExpression me, ClassNode constructorCallType) {
Expression key = me.getKeyExpression();
Expression value = me.getValueExpression();
ModuleNode module = currentClass.getModule();
if (module != null && key instanceof ConstantExpression) {
Map<String, ImportNode> importNodes = module.getStaticImports();
if (importNodes.containsKey(key.getText())) {
ImportNode importNode = importNodes.get(key.getText());
if (importNode.getType().equals(constructorCallType)) {
String newKey = importNode.getFieldName();
return new MapEntryExpression(new ConstantExpression(newKey), value.transformExpression(this));
}
}
}
return me;
}
示例2: transform
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
public Expression transform(Expression exp) {
if (exp == null) return null;
Expression ret = null;
if (exp instanceof VariableExpression) {
ret = transformVariableExpression((VariableExpression) exp);
} else if (exp.getClass() == PropertyExpression.class) {
ret = transformPropertyExpression((PropertyExpression) exp);
} else if (exp instanceof DeclarationExpression) {
ret = transformDeclarationExpression((DeclarationExpression) exp);
} else if (exp instanceof BinaryExpression) {
ret = transformBinaryExpression((BinaryExpression) exp);
} else if (exp instanceof MethodCallExpression) {
ret = transformMethodCallExpression((MethodCallExpression) exp);
} else if (exp instanceof ClosureExpression) {
ret = transformClosureExpression((ClosureExpression) exp);
} else if (exp instanceof ConstructorCallExpression) {
ret = transformConstructorCallExpression((ConstructorCallExpression) exp);
} else if (exp instanceof AnnotationConstantExpression) {
ret = transformAnnotationConstantExpression((AnnotationConstantExpression) exp);
} else {
resolveOrFail(exp.getType(), exp);
ret = exp.transformExpression(this);
}
if (ret!=null && ret!=exp) ret.setSourcePosition(exp);
return ret;
}
示例3: makeMapTypedArgsTransformer
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
private static ClassCodeExpressionTransformer makeMapTypedArgsTransformer() {
return new ClassCodeExpressionTransformer() {
@Override
public Expression transform(Expression exp) {
if (exp instanceof ClosureExpression) {
ClosureExpression ce = (ClosureExpression) exp;
ce.getCode().visit(this);
} else if (exp instanceof VariableExpression) {
VariableExpression ve = (VariableExpression) exp;
if (ve.getName().equals("args") && ve.getAccessedVariable() instanceof DynamicVariable) {
VariableExpression newVe = new VariableExpression(new Parameter(MAP_TYPE, "args"));
newVe.setSourcePosition(ve);
return newVe;
}
}
return exp.transformExpression(this);
}
@Override
protected SourceUnit getSourceUnit() {
return null;
}
};
}
示例4: transform
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
@Override
public Expression transform(Expression expr) {
if (expr == null) return null;
if (expr instanceof DeclarationExpression) {
DeclarationExpression de = (DeclarationExpression) expr;
if (de.getLeftExpression() == candidate.getLeftExpression()) {
if (insideScriptBody) {
// TODO make EmptyExpression work
// partially works but not if only thing in script
// return EmptyExpression.INSTANCE;
return new ConstantExpression(null);
}
addError("Annotation " + MY_TYPE_NAME + " can only be used within a Script body.", expr);
return expr;
}
} else if (insideScriptBody && expr instanceof VariableExpression && currentClosure != null) {
VariableExpression ve = (VariableExpression) expr;
if (ve.getName().equals(variableName)) {
// we may only check the variable name because the Groovy compiler
// already fails if a variable with the same name already exists in the scope.
// this means that a closure cannot shadow a class variable
ve.setAccessedVariable(fieldNode);
final VariableScope variableScope = currentClosure.getVariableScope();
final Iterator<Variable> iterator = variableScope.getReferencedLocalVariablesIterator();
while (iterator.hasNext()) {
Variable next = iterator.next();
if (next.getName().equals(variableName)) iterator.remove();
}
variableScope.putReferencedClassVariable(fieldNode);
return ve;
}
}
return expr.transformExpression(this);
}
示例5: transform
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
public Expression transform(Expression exp) {
if (exp == null) return null;
if (!currentClass.isInterface() && exp.getClass() == ConstantExpression.class) {
setConstField((ConstantExpression) exp);
}
return exp.transformExpression(this);
}
示例6: transform
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
@Override
public Expression transform(Expression expr) {
if (expr == null) return null;
if (expr instanceof DeclarationExpression) {
DeclarationExpression de = (DeclarationExpression) expr;
if (de.getLeftExpression() == candidate.getLeftExpression()) {
if (insideScriptBody) {
// TODO make EmptyExpression work
// partially works but not if only thing in script
// return EmptyExpression.INSTANCE;
return new ConstantExpression(null);
}
addError("Annotation " + MY_TYPE_NAME + " can only be used within a Script body.", expr);
return expr;
}
} else if (insideScriptBody && expr instanceof VariableExpression && currentClosure != null) {
VariableExpression ve = (VariableExpression) expr;
if (ve.getName().equals(variableName)) {
adjustToClassVar(ve);
return ve;
}
} else if (currentAIC != null && expr instanceof ArgumentListExpression) {
// if a match is found, the compiler will have already set up aic constructor to hav
// an argument which isn't needed since we'll be accessing the field; we must undo it
Expression skip = null;
List<Expression> origArgList = ((ArgumentListExpression) expr).getExpressions();
for (int i = 0; i < origArgList.size(); i++) {
Expression arg = origArgList.get(i);
if (matchesCandidate(arg)) {
skip = arg;
adjustConstructorAndFields(i, currentAIC.getType());
break;
}
}
if (skip != null) {
return adjustedArgList(skip, origArgList);
}
}
return expr.transformExpression(this);
}
示例7: transform
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Expression transform(final Expression expression) {
if (expression == null) {
return null;
}
final boolean matches = isOfTypeAndMatchesCriteria(expression, clazz, criteria);
if (matches) {
return this.transformExpression((T) expression);
}
return expression.transformExpression(this);
}
示例8: transform
import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
public Expression transform(Expression exp) {
if (exp == null) return null;
return exp.transformExpression(this);
}