本文整理汇总了Java中org.codehaus.groovy.ast.expr.MethodCallExpression.setSafe方法的典型用法代码示例。如果您正苦于以下问题:Java MethodCallExpression.setSafe方法的具体用法?Java MethodCallExpression.setSafe怎么用?Java MethodCallExpression.setSafe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.ast.expr.MethodCallExpression
的用法示例。
在下文中一共展示了MethodCallExpression.setSafe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tryMacroMethod
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
/**
* Attempts to call given macroMethod
* @param call MethodCallExpression before the transformation
* @param macroMethod a macro method candidate
* @param macroArguments arguments to pass to
* @return true if call succeeded and current call was transformed
*/
private boolean tryMacroMethod(MethodCallExpression call, ExtensionMethodNode macroMethod, Object[] macroArguments) {
Expression result = (Expression) InvokerHelper.invokeStaticMethod(
macroMethod.getExtensionMethodNode().getDeclaringClass().getTypeClass(),
macroMethod.getName(),
macroArguments
);
if (result == null) {
// Allow macro methods to return null as an indicator that they didn't match a method call
return false;
}
call.setObjectExpression(MACRO_STUB_INSTANCE);
call.setMethod(new ConstantExpression(MACRO_STUB_METHOD_NAME));
// TODO check that we reset everything here
call.setSpreadSafe(false);
call.setSafe(false);
call.setImplicitThis(false);
call.setArguments(result);
call.setGenericsTypes(new GenericsType[0]);
return true;
}
示例2: transformMethodCallExpression
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
protected Expression transformMethodCallExpression(MethodCallExpression mce) {
Expression args = transform(mce.getArguments());
Expression method = transform(mce.getMethod());
Expression object = transform(mce.getObjectExpression());
resolveGenericsTypes(mce.getGenericsTypes());
MethodCallExpression result = new MethodCallExpression(object, method, args);
result.setSafe(mce.isSafe());
result.setImplicitThis(mce.isImplicitThis());
result.setSpreadSafe(mce.isSpreadSafe());
result.setSourcePosition(mce);
result.setGenericsTypes(mce.getGenericsTypes());
result.setMethodTarget(mce.getMethodTarget());
return result;
}
示例3: transformToMopSuperCall
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private static MethodCallExpression transformToMopSuperCall(final ClassNode superCallReceiver, final MethodCallExpression expr) {
MethodNode mn = expr.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET);
String mopName = MopWriter.getMopMethodName(mn, false);
MethodNode direct = new MethodNode(
mopName,
ACC_PUBLIC | ACC_SYNTHETIC,
mn.getReturnType(),
mn.getParameters(),
mn.getExceptions(),
EmptyStatement.INSTANCE
);
direct.setDeclaringClass(superCallReceiver);
MethodCallExpression result = new MethodCallExpression(
new VariableExpression("this"),
mopName,
expr.getArguments()
);
result.setImplicitThis(true);
result.setSpreadSafe(false);
result.setSafe(false);
result.setSourcePosition(expr);
result.setMethodTarget(direct);
return result;
}
示例4: handleTargetMethodCallExpression
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
@Override
protected boolean handleTargetMethodCallExpression(MethodCallExpression call) {
ClosureExpression closureExpression = getClosureArgument(call);
List<Expression> otherArgs = getNonClosureArguments(call);
String source = convertClosureToSource(closureExpression);
// parameter order is build(CompilePhase, boolean, String)
otherArgs.add(new ConstantExpression(source));
call.setArguments(new ArgumentListExpression(otherArgs));
call.setMethod(new ConstantExpression("buildFromBlock"));
call.setSpreadSafe(false);
call.setSafe(false);
call.setImplicitThis(false);
return false;
}
示例5: writeInvokeMethod
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
public void writeInvokeMethod(MethodCallExpression call) {
if (isClosureCall(call)) {
// let's invoke the closure method
invokeClosure(call.getArguments(), call.getMethodAsString());
} else {
boolean isSuperMethodCall = usesSuper(call);
MethodCallerMultiAdapter adapter = invokeMethod;
if (isSuperMethodCall && call.isSafe()) {
// safe is not necessary here because "super" is always not null
// but keeping the flag would trigger a VerifyError (see GROOVY-6045)
call.setSafe(false);
}
if (AsmClassGenerator.isThisExpression(call.getObjectExpression())) adapter = invokeMethodOnCurrent;
if (isSuperMethodCall) adapter = invokeMethodOnSuper;
if (isStaticInvocation(call)) adapter = invokeStaticMethod;
makeInvokeMethodCall(call, isSuperMethodCall, adapter);
}
}
示例6: tryTransformInclude
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Expression tryTransformInclude(final MethodCallExpression exp) {
Expression arguments = exp.getArguments();
if (arguments instanceof TupleExpression) {
List<Expression> expressions = ((TupleExpression) arguments).getExpressions();
if (expressions.size() == 1 && expressions.get(0) instanceof MapExpression) {
MapExpression map = (MapExpression) expressions.get(0);
List<MapEntryExpression> entries = map.getMapEntryExpressions();
if (entries.size() == 1) {
MapEntryExpression mapEntry = entries.get(0);
Expression keyExpression = mapEntry.getKeyExpression();
try {
IncludeType includeType = IncludeType.valueOf(keyExpression.getText().toLowerCase());
MethodCallExpression call = new MethodCallExpression(
exp.getObjectExpression(),
includeType.getMethodName(),
new ArgumentListExpression(
mapEntry.getValueExpression()
)
);
call.setImplicitThis(true);
call.setSafe(exp.isSafe());
call.setSpreadSafe(exp.isSpreadSafe());
call.setSourcePosition(exp);
return call;
} catch (IllegalArgumentException e) {
// not a valid import type, do not modify the code
}
}
}
}
return super.transform(exp);
}
示例7: visitConstructorCallExpression
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
@Override
public void visitConstructorCallExpression(final ConstructorCallExpression call) {
ClassNode type = call.getType();
if (type instanceof InnerClassNode) {
if (((InnerClassNode) type).isAnonymous() &&
MACROCLASS_TYPE.getNameWithoutPackage().equals(type.getSuperClass().getNameWithoutPackage())) {
try {
String source = convertInnerClassToSource(type);
MethodCallExpression macroCall = callX(
propX(classX(ClassHelper.makeWithoutCaching(MacroBuilder.class, false)), "INSTANCE"),
MACRO_METHOD,
args(
constX(source),
MacroGroovyMethods.buildSubstitutions(sourceUnit, type),
classX(ClassHelper.make(ClassNode.class))
)
);
macroCall.setSpreadSafe(false);
macroCall.setSafe(false);
macroCall.setImplicitThis(false);
call.putNodeMetaData(MacroTransformation.class, macroCall);
List<ClassNode> classes = sourceUnit.getAST().getClasses();
for (Iterator<ClassNode> iterator = classes.iterator(); iterator.hasNext(); ) {
final ClassNode aClass = iterator.next();
if (aClass == type || type == aClass.getOuterClass()) {
iterator.remove();
}
}
} catch (Exception e) {
// FIXME
e.printStackTrace();
}
return;
}
}
super.visitConstructorCallExpression(call);
}
示例8: createCloseResourceStatement
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private ExpressionStatement createCloseResourceStatement(String firstResourceIdentifierName) {
MethodCallExpression closeMethodCallExpression =
new MethodCallExpression(new VariableExpression(firstResourceIdentifierName), "close", new ArgumentListExpression());
closeMethodCallExpression.setImplicitThis(false);
closeMethodCallExpression.setSafe(true);
return new ExpressionStatement(closeMethodCallExpression);
}
示例9: createAddSuppressedStatement
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private ExpressionStatement createAddSuppressedStatement(String primaryExcName, String suppressedExcName) {
MethodCallExpression addSuppressedMethodCallExpression =
new MethodCallExpression(
new VariableExpression(primaryExcName),
"addSuppressed",
new ArgumentListExpression(Collections.singletonList(new VariableExpression(suppressedExcName))));
addSuppressedMethodCallExpression.setImplicitThis(false);
addSuppressedMethodCallExpression.setSafe(true);
return new ExpressionStatement(addSuppressedMethodCallExpression);
}
示例10: createSoftGetter
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private static void createSoftGetter(FieldNode fieldNode, Expression initExpr, ClassNode type) {
final BlockStatement body = new BlockStatement();
final Expression fieldExpr = varX(fieldNode);
final Expression resExpr = varX("res", type);
final MethodCallExpression callExpression = callX(fieldExpr, "get");
callExpression.setSafe(true);
body.addStatement(declS(resExpr, callExpression));
final Statement mainIf = ifElseS(notNullX(resExpr), stmt(resExpr), block(
assignS(resExpr, initExpr),
assignS(fieldExpr, ctorX(SOFT_REF, resExpr)),
stmt(resExpr)));
if (fieldNode.isVolatile()) {
body.addStatement(ifElseS(
notNullX(resExpr),
stmt(resExpr),
new SynchronizedStatement(syncTarget(fieldNode), block(
assignS(resExpr, callExpression),
mainIf)
)
));
} else {
body.addStatement(mainIf);
}
addMethod(fieldNode, body, type);
}
示例11: transformMethodCallExpression
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Expression transformMethodCallExpression(final MethodCallExpression exp) {
if (isTraitSuperPropertyExpression(exp.getObjectExpression())) {
Expression objectExpression = exp.getObjectExpression();
ClassNode traitReceiver = ((PropertyExpression) objectExpression).getObjectExpression().getType();
if (traitReceiver != null) {
// (SomeTrait.super).foo() --> SomeTrait$Helper.foo(this)
ClassExpression receiver = new ClassExpression(
getHelper(traitReceiver)
);
ArgumentListExpression newArgs = new ArgumentListExpression();
Expression arguments = exp.getArguments();
newArgs.addExpression(new VariableExpression("this"));
if (arguments instanceof TupleExpression) {
List<Expression> expressions = ((TupleExpression) arguments).getExpressions();
for (Expression expression : expressions) {
newArgs.addExpression(transform(expression));
}
} else {
newArgs.addExpression(transform(arguments));
}
MethodCallExpression result = new MethodCallExpression(
receiver,
transform(exp.getMethod()),
newArgs
);
result.setImplicitThis(false);
result.setSpreadSafe(exp.isSpreadSafe());
result.setSafe(exp.isSafe());
result.setSourcePosition(exp);
return result;
}
}
return super.transform(exp);
}
示例12: transformSuperMethodCall
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Expression transformSuperMethodCall(final MethodCallExpression call) {
String method = call.getMethodAsString();
if (method == null) {
throwSuperError(call);
}
Expression arguments = transform(call.getArguments());
ArgumentListExpression superCallArgs = new ArgumentListExpression();
if (arguments instanceof ArgumentListExpression) {
ArgumentListExpression list = (ArgumentListExpression) arguments;
for (Expression expression : list) {
superCallArgs.addExpression(expression);
}
} else {
superCallArgs.addExpression(arguments);
}
MethodCallExpression transformed = new MethodCallExpression(
weaved,
Traits.getSuperTraitMethodName(traitClass, method),
superCallArgs
);
transformed.setSourcePosition(call);
transformed.setSafe(call.isSafe());
transformed.setSpreadSafe(call.isSpreadSafe());
transformed.setImplicitThis(false);
return transformed;
}
示例13: transformMethodCallOnThisFallBack
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Expression transformMethodCallOnThisFallBack(final MethodCallExpression call,
final Expression method, final Expression arguments) {
MethodCallExpression transformed = new MethodCallExpression(
weaved,
method,
transform(arguments)
);
transformed.setSourcePosition(call);
transformed.setSafe(call.isSafe());
transformed.setSpreadSafe(call.isSpreadSafe());
transformed.setImplicitThis(false);
return transformed;
}
示例14: transformMethodCallOnThisInClosure
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Expression transformMethodCallOnThisInClosure(final MethodCallExpression call) {
MethodCallExpression transformed = new MethodCallExpression(
(Expression) call.getReceiver(),
call.getMethod(),
transform(call.getArguments())
);
transformed.setSourcePosition(call);
transformed.setSafe(call.isSafe());
transformed.setSpreadSafe(call.isSpreadSafe());
transformed.setImplicitThis(call.isImplicitThis());
return transformed;
}
示例15: transformPrivateMethodCallOnThis
import org.codehaus.groovy.ast.expr.MethodCallExpression; //导入方法依赖的package包/类
private Expression transformPrivateMethodCallOnThis(final MethodCallExpression call,
final Expression arguments, final String methodName) {
ArgumentListExpression newArgs = createArgumentList(arguments);
MethodCallExpression transformed = new MethodCallExpression(
new VariableExpression("this"),
methodName,
newArgs
);
transformed.setSourcePosition(call);
transformed.setSafe(call.isSafe());
transformed.setSpreadSafe(call.isSpreadSafe());
transformed.setImplicitThis(true);
return transformed;
}