-
-
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
feat: add a static method to getting started with one single line of code #1559
Conversation
Nice! It is true that Launcher is not intuitive and I am often fighting with initial configuration of Spoon too. |
@@ -798,4 +800,12 @@ public CtModel getModel() { | |||
return factory.getModel(); | |||
} | |||
|
|||
/** returns the AST of an inline class */ | |||
public static CtClass<?> parseClass(String code) { |
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.
I'm not sure about your method return: I think this method will be quickly used with code containing multiple types (enum + class for example or multiple classes).
Then I see two solutions:
- Either the method return a list of CtTypes (and then we may have to rename it)
- Either it checks that the model contains only one CtClass (and then we explictely do not accept interfaces or enum, and most importantly we give a comprehensive error for the user)
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.
Or even code can contain only an interface...
I would return a CtType.
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.
The idea of this PR is to have the easiest possible introduction to Spoon. Having CtClass means that users would have directly getConstructors etc. which they would naturally expect (which is not in CtType). CtType is a slight less natural, more abstract concept. Once newcomers understand this method, they would obviously move to the complete configurable Launcher and the rest of the metamodel (incl CtType)
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.
I'm ok for keeping CtClass return but we should then check the type before casting, to help the user in case he did not pass a simple class.
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.
I think I would create a new Launcher instead of adding a new method in a class that contains already to much stuff.
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.
new Launcher
may be yes! But only as a replacement/wrapper of old non intuitive Launcher. I do not think we should have many ways/launchers how to start processing. The one "well designed" launcher would be nice ... but I actually have no constructive suggestion how it should look like. I just have problems with the old Launcher.
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.
Maybe something as a LauncherBuilder:
CtModel model = new LauncherBuilder().useAutoimport()
.useNoclasspath()
.addInputSource("./myDirectory/")
.addInputSource("./anotherOne")
.setOutputDir("./target")
.build();
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 exactly! But someone should analyze all Launcher use cases and organize them into intuitive API. I am not the one who knows use cases of Launcher well enough. Let's make an issue where we can build such a concept.
Indeed, we need to improve the documentation of the Launcher. |
There is a confusion there. |
Yep, that's why we opened a new issue to discuss the design of a new launcher. |
For me the design of this PR is wrong. It will introduce more confusion in the API than solve issues. |
No description provided.