@java.lang.Override public void set(spoon.reflect.code.CtExpression replace) { this.element.setReturnedExpression(replace); } }
@Override public <R> void visitCtReturn(CtReturn<R> returnStatement) { if (child instanceof CtExpression) { returnStatement.setReturnedExpression((CtExpression<R>) child); return; } super.visitCtReturn(returnStatement); }
@Override public <T, U> void setValue(T element, U value) { castTarget(element).setReturnedExpression(castValue(value)); } }
@Override public <R> void visitCtReturn(CtReturn<R> returnStatement) { CtReturn<R> r = returnStatement.getFactory().Core().createReturn(); r.setReturnedExpression(evaluate(returnStatement.getReturnedExpression())); setResult(r); flowEnded = true; }
private static String createWrapperContent(final CtElement element, final Factory f, final CtTypeReference returnType) { CtClass<?> w = f.Class().create(WRAPPER_CLASS_NAME); CtBlock body = f.Core().createBlock(); if (element instanceof CtStatement) { body.addStatement((CtStatement) element); } else if (element instanceof CtExpression) { CtReturn ret = f.Core().createReturn(); ret.setReturnedExpression((CtExpression) element); body.addStatement(ret); } Set<ModifierKind> modifiers = EnumSet.of(ModifierKind.STATIC); Set<CtTypeReference<? extends Throwable>> thrownTypes = new HashSet<>(); thrownTypes.add(f.Class().<Throwable>get(Throwable.class).getReference()); f.Method().create( w, modifiers, returnType, WRAPPER_METHOD_NAME, CtElementImpl.<CtParameter<?>>emptyList(), thrownTypes, body); String contents = w.toString(); // Clean up (delete wrapper from factory) after it is printed. The DefaultJavaPrettyPrinter needs w in model to be able to print it correctly w.getPackage().removeType(w); return contents; }
public <R> void visitCtReturn(final spoon.reflect.code.CtReturn<R> returnStatement) { spoon.reflect.code.CtReturn<R> aCtReturn = returnStatement.getFactory().Core().createReturn(); this.builder.copy(returnStatement, aCtReturn); aCtReturn.setAnnotations(this.cloneHelper.clone(returnStatement.getAnnotations())); aCtReturn.setReturnedExpression(this.cloneHelper.clone(returnStatement.getReturnedExpression())); aCtReturn.setComments(this.cloneHelper.clone(returnStatement.getComments())); this.cloneHelper.tailor(returnStatement, aCtReturn); this.other = aCtReturn; }
@Override public <R> void visitCtReturn(CtReturn<R> returnStatement) { if (child instanceof CtExpression) { returnStatement.setReturnedExpression((CtExpression<R>) child); return; } super.visitCtReturn(returnStatement); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public <R> void visitCtReturn(CtReturn<R> returnStatement) { super.visitCtReturn(returnStatement); CtExpression exper=returnStatement.getReturnedExpression(); if (candidates.containsKey(exper)) { returnStatement.setReturnedExpression(candidates.get(exper)); saveSketchAndSynthesize(); returnStatement.setReturnedExpression(exper); resoreDiskFile(); } }
public <R> void visitCtReturn(CtReturn<R> returnStatement) { CtReturn<R> r = returnStatement.getFactory().Core().createReturn(); r.setReturnedExpression(evaluate(r, returnStatement.getReturnedExpression())); setResult(r); flowEnded = true; }
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()); }
returnstmt.setReturnedExpression(returnexp);
.createCodeSnippetExpression(codeExpression); returnStatement = MutationSupporter.getFactory().Core().createReturn(); returnStatement.setReturnedExpression(returnExpression);
private static <R, B extends R> CtClass<?> createWrapper( CtExpression<B> st, Factory f) { CtClass<?> w = f.Class().create("Wrapper"); CtBlock<B> body = f.Core().createBlock(); CtReturn<B> ret = f.Core().createReturn(); ret.setReturnedExpression(st); body.addStatement(ret); Set<ModifierKind> x = EnumSet.noneOf(ModifierKind.class); f.Method().create( w, x, f.Type().createReference(Object.class), "wrap", CtElementImpl.<CtParameter<?>>emptyList(), CtElementImpl .<CtTypeReference<? extends Throwable>>emptySet(), body); return w; }
private void generateFinalAccessors() { List<CtField<?>> finalFields = root.getMergedClass() .getElements((CtField<?> field) -> field.hasModifier(FINAL)); finalFields.forEach(f -> { CtType<?> declaringType = f.getDeclaringType(); if (declaringType.getMethodsByName(f.getSimpleName()).isEmpty()) { Factory factory = f.getFactory(); CtMethod access = factory.Method().create( declaringType, EnumSet.of(PUBLIC), f.getType(), f.getSimpleName(), emptyList(), emptySet()); access.setParent(declaringType); access.setBody((CtBlock) factory.Core().createBlock()); CtReturn fReturn = factory.Core().createReturn(); fReturn.setReturnedExpression( factory.Code().createVariableRead(f.getReference(), false)); access.getBody().addStatement(fReturn); access.setPosition(new LinedSourcePosition( ((LinedSourcePosition) f.getPosition()).delegate, ((LinedSourcePosition) f.getPosition()).line)); } }); }
casereturn.setReturnedExpression(expressionCandidate); particularIfBlock.addStatement(casereturn); MutationSupporter.clearPosition(expCloned); defaultReturnLast.setReturnedExpression(expCloned); methodBodyBlock.addStatement(defaultReturnLast);
_return.setReturnedExpression(expressionCandidate); particularIfBlock.addStatement(_return); clearPosition(expCloned); _returnLast.setReturnedExpression(expCloned); methodBodyBlock.addStatement(_returnLast);
casereturn.setReturnedExpression(expressionCandidate); particularIfBlock.addStatement(casereturn); MutationSupporter.clearPosition(expCloned); defaultReturnLast.setReturnedExpression(expCloned); methodBodyBlock.addStatement(defaultReturnLast);
casereturn.setReturnedExpression(expressionCandidate); particularIfBlock.addStatement(casereturn); MutationSupporter.clearPosition(expCloned); defaultReturnLast.setReturnedExpression(expCloned); methodBodyBlock.addStatement(defaultReturnLast);
initFieldType == f().Type().LONG_PRIMITIVE)) { CtReturn<Object> ret = f().Core().createReturn(); ret.setReturnedExpression(f().Code().createBinaryOperator( f().Code().createVariableRead(initField.getReference(), false), f().Code().createLiteral(0), ret.setReturnedExpression(f().Code().createBinaryOperator( f().Code().createVariableRead(initField.getReference(), false), f().Core().clone(unInitExpression),
private <T> CtMethod<T> fieldAccess(CtField<T> field) { @SuppressWarnings("unchecked") Map<CtField<T>, CtMethod<T>> fields = (Map<CtField<T>, CtMethod<T>>) (Map) this.fields; return fields.compute(field, (f, proxy) -> { if (proxy == null) { proxy = createSimpleMethod(f.getType(), f.getSimpleName()); } else if (proxy.hasModifier(ABSTRACT)) { proxy.setBody(f().Core().createBlock()); proxy.removeModifier(ABSTRACT); } else { return proxy; } addGuardingPrologue(proxy); CtReturn<T> ret = f().Core().createReturn(); ret.setReturnedExpression(f().Code().createVariableRead(f.getReference(), false)); proxy.getBody().addStatement(ret); cxt.bindAccessMethod(proxy, StageModel.this); return proxy; }); }