Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: substitution of return expression.S() #1755

Merged
merged 1 commit into from
Nov 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/test/java/spoon/test/template/TemplateReplaceReturnTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import spoon.Launcher;
import spoon.OutputType;
import spoon.reflect.code.CtBlock;
import spoon.reflect.code.CtExpression;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.factory.Factory;
import spoon.support.compiler.FileSystemFile;
Expand Down Expand Up @@ -36,4 +37,23 @@ public void testReturnReplaceTemplate() throws Exception {
ModelUtils.canBeBuilt(new File("./target/spooned/spoon/test/template/ReturnReplaceResult.java"), 8);
}

@Test
public void testNoReturnReplaceTemplate() throws Exception {
//contract: the template engine supports replace of return expression by `<CtExpression>`
Launcher launcher = new Launcher();
launcher.addTemplateResource(new FileSystemFile("./src/test/java/spoon/test/template/testclasses/ReturnReplaceTemplate.java"));

launcher.buildModel();
Factory factory = launcher.getFactory();

CtExpression<String> model = factory.createLiteral("AStringLiteral");

CtClass<?> resultKlass = factory.Class().create(factory.Package().getOrCreate("spoon.test.template"), "ReturnReplaceResult");
new ReturnReplaceTemplate(model).apply(resultKlass);
assertEquals("{ return \"AStringLiteral\";}", resultKlass.getMethod("method").getBody().toString().replaceAll("[\\r\\n\\t]+", "").replaceAll("\\s{2,}", " "));
launcher.setSourceOutputDirectory(new File("./target/spooned/"));
launcher.getModelBuilder().generateProcessedSourceFiles(OutputType.CLASSES);
ModelUtils.canBeBuilt(new File("./target/spooned/spoon/test/template/ReturnReplaceResult.java"), 8);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package spoon.test.template.testclasses;

import spoon.reflect.code.CtBlock;
import spoon.template.ExtensionTemplate;
import spoon.template.Local;
import spoon.template.TemplateParameter;
Expand All @@ -14,7 +13,7 @@ public String method() throws Throwable {
TemplateParameter<String> _statement_;

@Local
public ReturnReplaceTemplate(CtBlock<String> statement) {
public ReturnReplaceTemplate(TemplateParameter<String> statement) {
this._statement_ = statement;
}

Expand Down