Skip to content
New issue

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

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

Already on GitHub? # to your account

review: feature: add "Generated by ..." comments automatically #1465

Merged
merged 2 commits into from
Jul 24, 2017

Conversation

pvojtechovsky
Copy link
Collaborator

SubstitutionVisitor adds "Generated by ..." java doc comment automatically now.

For example:

    /**
     * Generated by a.b.c..RequestBuilderTemplate(RequestBuilderTemplate.java:25)
     */
    public CreateAnswerWithTargetBuilder(ServiceAPI serviceWrapper) {
        this.serviceWrapper = serviceWrapper;
        request = new CreateAnswerWithTargetReq();
    }

TODO: make it configurable whether it is added or not

@pvojtechovsky pvojtechovsky force-pushed the feaGeneratedBy branch 2 times, most recently from a8c8209 to 6033764 Compare July 15, 2017 19:15
@spoon-bot
Copy link
Collaborator

Revapi Analysis results

Old API: fr.inria.gforge.spoon:spoon-core:jar:5.9.0-20170714.224607-7

New API: fr.inria.gforge.spoon:spoon-core:jar:5.9.0-SNAPSHOT

Detected changes: 2.

Change 1

Name Element
Old none
New method boolean spoon.compiler.Environment::isAddGeneratedBy()
Code java.method.addedToInterface
Description Method was added to an interface.
Breaking binary: non_breaking,

Change 2

Name Element
Old none
New method void spoon.compiler.Environment::setAddGeneratedBy(boolean)
Code java.method.addedToInterface
Description Method was added to an interface.
Breaking binary: non_breaking,

@pvojtechovsky pvojtechovsky changed the title WiP: feature: add "Generated by ..." comments automatically review: feature: add "Generated by ..." comments automatically Jul 15, 2017
@INRIA INRIA deleted a comment from spoon-bot Jul 16, 2017
@monperrus
Copy link
Collaborator

I like the idea of this PR.

But I don't think that having a lot a boolean, somewhat cryptic, options in Environment is good. IMHO, this is already a problem we have and we should not worsen the situation.

Coming back to this PR here are possible solutions:

  • not having an option
  • having the option as a (public?) field in SubstitutionVisitor

WDYT?

@pvojtechovsky
Copy link
Collaborator Author

criptic configuration of spoon

I agree. I personally cannot configure spoon launcher easily. I always copy the code from somewhere...

public field in SubstitutionVisitor

I agree. This is good step. But it is not enough, because clients of Templates has no easy way how to set this field. So we need some support here too.

In future I would like to use TemplateBuilder, with appropriate related setter

@pvojtechovsky
Copy link
Collaborator Author

I removed Environment setter. I added SubstitutionVisitor#addGeneratedBy(boolean) and AbstractTemplate#addGeneratedBy(boolen)

OK now?

@monperrus
Copy link
Collaborator

Thanks a lot, that's much better and clearer.

One more problem is the duplication of the boolean setting in SubstitutionVisitor and AbstractTemplate: one does not really know who is responsible for this.

Here is a tentative solution: instead of

new SuperTemplate().addGeneratedBy(true).apply(superc);

I'd propose something like this:

// only SubstitutionVisitor is responsible of its configuration
template = new SuperTemplate();
template.getSubstitutionVisitor().addGeneratedBy(true)
template.apply(superc);

it's more verbose (but it's a special advanced case), but it follows the Single Responsibility Principle.

WDYT?

@pvojtechovsky
Copy link
Collaborator Author

Your suggestion is not compatible with all spoon.template.Substitution static methods. All of them expects that Template exists first and that SubstitutionVisitor is created many times internally in Substitution#substitute(...)

There is also problem that Template must be configured before SubstitutionVisitor is created for the template, because the template parameters are collected at SubstitutionVisitor creation time.

So I suggest to keep it as it is. It is may be not nice, but better solution would need more refactoring and would cause changes in API

@monperrus monperrus merged commit e6f0492 into INRIA:master Jul 24, 2017
@monperrus
Copy link
Collaborator

better solution would need more refactoring and would cause changes in API

I agree.

thanks Pavel for this nice feature.

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

Successfully merging this pull request may close these issues.

3 participants