-
-
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
review: feature: Substitute string literals #1403
Conversation
@@ -667,7 +665,12 @@ public void createTypeFromTemplate() throws Exception { | |||
assertNull(genClass.getMethod("someMethod")); | |||
assertTrue(generatedIfaceMethod!=generatedClassMethod); | |||
assertTrue(generatedClassMethod.isOverriding(generatedIfaceMethod)); | |||
|
|||
//contract: check replace in literals |
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 is the parameter (in parameters
) driving this replacement?
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.
It is the parameter implicitly added by this code
class Substitution {
...
public static <T> CtType<T> createTypeFromTemplate(String qualifiedTypeName, CtType<T> templateOfType, Map<String, Object> templateParameters) {
final Factory f = templateOfType.getFactory();
CtTypeReference<T> typeRef = f.Type().createReference(qualifiedTypeName);
CtPackage targetPackage = f.Package().getOrCreate(typeRef.getPackage().getSimpleName());
final Map<String, Object> extendedParams = new HashMap<String, Object>(templateParameters);
//--------Here is the implicit parameter added----------------
extendedParams.put(templateOfType.getSimpleName(), typeRef);
List<CtType<T>> generated = new SubstitutionVisitor(f, extendedParams).substitute(templateOfType.clone());
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.
Implicit is worse than explicit. What if we move this code in the test? ie this responsibility to the caller?
I guess that string substitution should work outside createTypeFromTemplate, consequently, could you add a test with a template dedicated to string substitution?
thanks
53c5ab3
to
8261429
Compare
OK, you are right. |
That's good thanks. What I miss in SubstituteLiteralTemplate is that the template parameter are implicit, we don't explicitly define a template parameter related to String and annotated with @parameter. What do you think? |
The Template parameter is declared explicitly now. OK? ;-) |
thanks Pavel |
implements #1337