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

review: feature: Substitute string literals #1403

Merged
merged 2 commits into from
Jun 22, 2017

Conversation

pvojtechovsky
Copy link
Collaborator

implements #1337

@@ -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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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());

Copy link
Collaborator

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

@pvojtechovsky pvojtechovsky force-pushed the featSubstStrLiterals branch from 53c5ab3 to 8261429 Compare June 20, 2017 20:18
@pvojtechovsky
Copy link
Collaborator Author

OK, you are right.
I have added explicit tests of several combinations of string literal substitution and parameter value type.
There is also tested how behaves invocation replacement - it is tested in same test, to easily see the difference in behavior.
It is ready for merge. WDYT?

@monperrus
Copy link
Collaborator

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?

@pvojtechovsky
Copy link
Collaborator Author

The Template parameter is declared explicitly now. OK? ;-)

@monperrus monperrus merged commit e6e2087 into INRIA:master Jun 22, 2017
@monperrus
Copy link
Collaborator

thanks Pavel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants