-
-
Notifications
You must be signed in to change notification settings - Fork 353
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
review: test SubstitionVisitor enum replace #1389
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d1ec9a8
test SubstitutionVisitor enum value replace
pvojtechovsky cb94255
fix SubstitutionVisitor enum value replace
pvojtechovsky e30c3fc
check generated code
pvojtechovsky 4d73fe6
fix variable name and create enum class reference in tmpl constructor
pvojtechovsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/test/java/spoon/test/template/TemplateEnumAccessTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package spoon.test.template; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.io.File; | ||
import java.lang.annotation.ElementType; | ||
|
||
import org.junit.Test; | ||
|
||
import spoon.Launcher; | ||
import spoon.OutputType; | ||
import spoon.reflect.declaration.CtClass; | ||
import spoon.reflect.factory.Factory; | ||
import spoon.support.compiler.FileSystemFile; | ||
import spoon.test.template.testclasses.EnumAccessTemplate; | ||
import spoon.testing.utils.ModelUtils; | ||
|
||
public class TemplateEnumAccessTest { | ||
|
||
@Test | ||
public void testEnumAccessTest() throws Exception { | ||
//contract: the template engine supports enum value access substitution | ||
Launcher launcher = new Launcher(); | ||
launcher.addTemplateResource(new FileSystemFile("./src/test/java/spoon/test/template/testclasses/EnumAccessTemplate.java")); | ||
|
||
launcher.buildModel(); | ||
Factory factory = launcher.getFactory(); | ||
|
||
CtClass<?> resultKlass = factory.Class().create(factory.Package().getOrCreate("spoon.test.template"), "EnumAccessResult"); | ||
new EnumAccessTemplate(ElementType.FIELD, launcher.getFactory().Type().createReference(ElementType.class)).apply(resultKlass); | ||
assertEquals("java.lang.annotation.ElementType.FIELD.name()", resultKlass.getMethod("method").getBody().getStatement(0).toString()); | ||
launcher.setSourceOutputDirectory(new File("./target/spooned/")); | ||
launcher.getModelBuilder().generateProcessedSourceFiles(OutputType.CLASSES); | ||
ModelUtils.canBeBuilt(new File("./target/spooned/spoon/test/template/EnumAccessResult.java"), 8); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/test/java/spoon/test/template/testclasses/EnumAccessTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package spoon.test.template.testclasses; | ||
|
||
import spoon.reflect.reference.CtTypeReference; | ||
import spoon.template.ExtensionTemplate; | ||
import spoon.template.Local; | ||
import spoon.template.Parameter; | ||
|
||
public class EnumAccessTemplate extends ExtensionTemplate { | ||
|
||
public void method() throws Throwable { | ||
_AnEnum_._value_.name(); | ||
} | ||
|
||
@Parameter("_AnEnum_") | ||
CtTypeReference<?> anEnum; | ||
|
||
@Parameter | ||
Enum _value_; | ||
|
||
@Local | ||
public EnumAccessTemplate(Enum anEmum, CtTypeReference<?> anEnum) { | ||
this._value_ = anEmum; | ||
this.anEnum = anEnum; | ||
} | ||
|
||
@Local | ||
enum _AnEnum_ { | ||
@Parameter | ||
_value_ | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename anEmum to enumValue?
could this be created from "anEmum" directly (Reference().create(anEmum.getClass())?