-
-
Notifications
You must be signed in to change notification settings - Fork 352
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
WiP: refactor SubstitutionVisitor. Unify conversion of template parameters #1350
Conversation
14900c1
to
7a5d624
Compare
7a5d624
to
8eb0bea
Compare
|
||
@Test | ||
public void testStatementTemplateRootSubstitution() throws Exception { | ||
//contract: the template engine supports substitution of root element |
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.
what do you mean by "root element"?
in new SubstituteRootTemplate(param).apply(resultKlass);
do you mean param
or resultKlass
or something else?
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.
Root element is in this case the body of the statement
method.
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.
does that mean that the body of the statement method is never substituted?
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.
yes, if I remember well (90%) it was not substituted. Or it failed with exception (10%)
Factory factory = spoon.getFactory(); | ||
|
||
CtClass<?> templateClass = factory.Class().get(SubstituteRootTemplate.class); | ||
CtBlock<Void> param = (CtBlock) templateClass.getMethod("sampleBlock").getBody(); |
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 to templateParam
? (param
suggests method parameter)
|
||
@Override | ||
public void statement() throws Throwable { | ||
block.S(); |
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.
what do you mean by "root element"?
This is root element of testStatementTemplateRootSubstitution()
@monperrus The solution of C) will simplify SubstitutionVisitor (forEach and CtExecutable#parameters replacing, ...), but it causes deep refactoring too ... so I am actually checking how it will look like and then we can have a look how to split it into smaller PRs... |
this PR is contained in #1359. Closing this one. |
Motivation: clean and simplify code of
SubstitutionVisitor
, before next refactoring, which will support decoupledtemplate model
and 'template parameters', which allows even more powerful templates.Following changes were done on
SubstitutionVisitor
in this PR:Parameters#getParameterValueAsXXX
methods - it is now cleaner what it does, corner cases are handled consistently, errors are reported. duplicate code was removed.TODO: refactor array access (the places which still use
Parameters#getValue(...)
)