method.setSimpleName(name); if (parameters != null) { method.setParameters(parameters);
public <T> void visitCtMethod(final spoon.reflect.declaration.CtMethod<T> m) { spoon.reflect.declaration.CtMethod<T> aCtMethod = m.getFactory().Core().createMethod(); this.builder.copy(m, aCtMethod); aCtMethod.setAnnotations(this.cloneHelper.clone(m.getAnnotations())); aCtMethod.setFormalCtTypeParameters(this.cloneHelper.clone(m.getFormalCtTypeParameters())); aCtMethod.setType(this.cloneHelper.clone(m.getType())); aCtMethod.setParameters(this.cloneHelper.clone(m.getParameters())); aCtMethod.setThrownTypes(this.cloneHelper.clone(m.getThrownTypes())); aCtMethod.setBody(this.cloneHelper.clone(m.getBody())); aCtMethod.setComments(this.cloneHelper.clone(m.getComments())); this.cloneHelper.tailor(m, aCtMethod); this.other = aCtMethod; }
parameter.getSimpleName())); adaptedMethod.setParameters(adaptedParams); method = adaptedMethod;
public <T> CtTargetedExpression<T, CtExpression<?>> guardedStageMethodCall( CtInvocation<T> invocation, CtMethod<T> stageMethod) { if (!stageMethods.containsKey(stageMethod)) throw new StageGraphCompilationException(stageMethod + " doesn't belong to " + this); @SuppressWarnings("unchecked") Map<CtMethod<T>, CtMethod<T>> stageMethods = (Map<CtMethod<T>, CtMethod<T>>) (Map) this.stageMethods; return f().Code().createInvocation(null, stageMethods.computeIfAbsent(stageMethod, m -> { CtMethod<T> guarded = createSimpleMethod(m.getType(), m.getSimpleName() + "Guarded"); addGuardingPrologue(guarded); guarded.setParameters(new ArrayList<>(m.getParameters())); List<CtExpression<?>> arguments = m.getParameters().stream() .map(p -> p.getReference()) .map(pr -> f().Code().createVariableRead(pr, false)) .collect(toList()); CtInvocation<T> innerInvocation = f().Code().createInvocation(null, m.getReference(), arguments); if (m.getType().equals(f().Type().VOID_PRIMITIVE)) { guarded.getBody().addStatement(innerInvocation); } else { CtReturn<T> ctReturn = f().Core().createReturn(); ctReturn.setReturnedExpression(innerInvocation); guarded.getBody().addStatement(ctReturn); } return guarded; }).getReference(), invocation.getArguments()); }
method.setSimpleName(name); if (parameters != null) { method.setParameters(parameters);