GithubHelp home page GithubHelp logo

Comments (27)

looztra avatar looztra commented on August 19, 2024

I'd be glad to give a hand on this one, but I work better with examples and there is no lombok extension so far that creates an inner class (correct me if I'm wrong) so I'm a little bit lost for the moment and not sure where to start from with all these Psi* class.
Would somebody have any hint on how to proceed?

from lombok-intellij-plugin.

SpOOnman avatar SpOOnman commented on August 19, 2024

I didn't look at that yet, but I've created a branch https://github.com/mplushnikov/lombok-intellij-plugin/tree/feature/builder and I've added tests there. Please create your pull requests there. For now I've only played with creating constructors.

from lombok-intellij-plugin.

SpOOnman avatar SpOOnman commented on August 19, 2024

I've implemented Initial @builder annotation. It works on basic example from lombok's homepage. Now I need to work on customisations and it can be reviewed.

from lombok-intellij-plugin.

looztra avatar looztra commented on August 19, 2024

Nice! I will check it out asap.
Le 15 oct. 2013 15:58, "Tomasz Kalkosiński" [email protected] a
écrit :

I've implemented Initial @builder https://github.com/Builder annotation.
It works on basic example from lombok's homepage. Now I need to work on
customisations and it can be reviewed.


Reply to this email directly or view it on
GitHubhttps://github.com//issues/5#issuecomment-26336129
.

from lombok-intellij-plugin.

SpOOnman avatar SpOOnman commented on August 19, 2024

I've just finished Builder implementation on static methods, too. Now I need to cleanup codebase and unify shared parts.

from lombok-intellij-plugin.

twillouer avatar twillouer commented on August 19, 2024

for what it's worth, I use your Builder implements with success on my intellij on my project.

from lombok-intellij-plugin.

SpOOnman avatar SpOOnman commented on August 19, 2024

Thank you @twillouer ! I'm glad.

I've finished Builder implementation. Two tests fail for now and I think I won't support these cases, as these are very complicated cases with lots of inner classes Psi magic. I display a problem with that information.

Branch is already up-to-date with master branch and it's ready to merge. Please review and merge.

from lombok-intellij-plugin.

mlueders avatar mlueders commented on August 19, 2024

I've run into a couple issues with the feature/builder branch.

First, exceptions are thrown from LombokLightClass since the accessor for mySupers is declared @NotNull but mySupers is never initialized. This is easily fixed but makes me wonder if I've got something mis-configured or am not building correctly.

Second, the IntelliJ does not recognize the methods on the generated builder class. It recognizes the 'builder' method on the target class and the generated builder class itself but none of the methods on the builder. The odd part is, I can break in LombokAugmentProvider and can see that a Psi is created for the generated builder class, complete with the appropriate methods plus build and toString, it's just not being recognized by IntelliJ for some reason.

I'm using the most recent version of feature/builder (commit 01e5704). I've tried debugging the plugin project as well as exporting the plugin and loading it into IntelliJ and get the same results.

I'm using IntelliJ 12.1.6 CE.
If there's any additional information I can provide, please let me know - I would love to use this feature!

from lombok-intellij-plugin.

SpOOnman avatar SpOOnman commented on August 19, 2024

Thank you @mlueders for your support and review. This is the first time that inner class is generated by lombok plugin so it may be rough on the edges. I'll into that and comment here.

from lombok-intellij-plugin.

mlueders avatar mlueders commented on August 19, 2024

@SpOOnman Here's some additional information about what I did to reproduce the problem.

Check out feature/builder branch and import into IntelliJ
Create a Run/Debug configuration of type plugin
Debug the plugin
Create a project in the spawned instance with the following classes in com.example package...

@Builder
public class SomeClass {
    private String name;
}
public class OtherClass {
    public static void main(String[] args) {
        SomeClass.builder().name("a name").build();
    }
}

With this configuration, auto-complete of the builder method works on SomeClass but the name method is not recognized on the SomeClassBuilder.

I put added the following conditional checkpoints on LombokAugmentProvider...

line 63, condition: processor.getClass().getName().endsWith("BuilderInnerClassProcessor")
line 66, condition: result.size() > 0

I can see the inner class with the appropriate methods being created and added to the result for SomeClass when the input type is PsiClass, just not sure why it's not showing up in the editor.

Hope this helps.

from lombok-intellij-plugin.

SpOOnman avatar SpOOnman commented on August 19, 2024

Thank you @mlueders . I see the same thing - correct PsiClass is build and it can seen by IDEA, but code completion doesn't work. I am looking into this.

from lombok-intellij-plugin.

twillouer avatar twillouer commented on August 19, 2024

hi,

2013-10-19 00:38:43,680 [ 220149]  ERROR - currency.PrioritizedFutureTask - IntelliJ IDEA 12.1.6  Build #IU-129.1359 
2013-10-19 00:38:43,680 [ 220149]  ERROR - currency.PrioritizedFutureTask - JDK: 1.7.0_45 
2013-10-19 00:38:43,680 [ 220149]  ERROR - currency.PrioritizedFutureTask - VM: Java HotSpot(TM) 64-Bit Server VM 
2013-10-19 00:38:43,680 [ 220149]  ERROR - currency.PrioritizedFutureTask - Vendor: Oracle Corporation 
2013-10-19 00:38:43,680 [ 220149]  ERROR - currency.PrioritizedFutureTask - OS: Linux 
2013-10-19 00:38:43,680 [ 220149]  ERROR - currency.PrioritizedFutureTask - Last Action: SaveAll 
2013-10-19 00:38:43,680 [ 220149]  ERROR - currency.PrioritizedFutureTask - Original exception:  
java.lang.IllegalStateException: @NotNull method de/plushnikov/intellij/plugin/psi/LombokLightClass.getSupers must not return null
        at de.plushnikov.intellij.plugin.psi.LombokLightClass.getSupers(LombokLightClass.java:136)
        at com.intellij.codeInsight.AnnotationUtil.isAnnotated(AnnotationUtil.java:286)
        at com.intellij.codeInsight.AnnotationUtil.isAnnotated(AnnotationUtil.java:254)
        at com.intellij.spring.data.util.SpringDataUtil.isRepository(SpringDataUtil.java:34)
        at com.intellij.spring.data.inspections.SpringDataJpaMethodInconsistencyInspection.checkClass(SpringDataJpaMethodInconsistencyInspection.java:39)
        at com.intellij.spring.model.highlighting.jam.AbstractSpringJavaConfigInspection.checkClassInternal(AbstractSpringJavaConfigInspection.java:50)
        at com.intellij.spring.model.highlighting.jam.AbstractSpringJavaConfigInspection.checkJavaFile(AbstractSpringJavaConfigInspection.java:43)
        at com.intellij.spring.model.highlighting.jam.AbstractSpringJavaConfigInspection.checkFile(AbstractSpringJavaConfigInspection.java:29)
        at com.intellij.codeInspection.BaseJavaLocalInspectionTool$1.visitFile(BaseJavaLocalInspectionTool.java:104)
        at com.intellij.psi.JavaElementVisitor.visitJavaFile(JavaElementVisitor.java:328)
        at com.intellij.psi.impl.source.PsiJavaFileBaseImpl.accept(PsiJavaFileBaseImpl.java:409)
        at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.a(LocalInspectionsPass.java:412)
        at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.a(LocalInspectionsPass.java:370)
        at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.a(LocalInspectionsPass.java:341)
        at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.access$000(LocalInspectionsPass.java:78)
        at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass$2.process(LocalInspectionsPass.java:309)
        at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass$2.process(LocalInspectionsPass.java:306)
        at com.intellij.concurrency.JobLauncherImpl$2$1.run(JobLauncherImpl.java:115)
        at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:226)
        at com.intellij.concurrency.JobLauncherImpl$2.process(JobLauncherImpl.java:113)
        at com.intellij.concurrency.JobLauncherImpl$1.run(JobLauncherImpl.java:54)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at com.intellij.concurrency.PrioritizedFutureTask.access$101(PrioritizedFutureTask.java:31)
        at com.intellij.concurrency.PrioritizedFutureTask$1.run(PrioritizedFutureTask.java:70)
        at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1182)
        at com.intellij.concurrency.PrioritizedFutureTask.run(PrioritizedFutureTask.java:97)
        at com.intellij.concurrency.JobImpl.scheduleAndWaitForResults(JobImpl.java:136)
        at com.intellij.concurrency.JobLauncherImpl.a(JobLauncherImpl.java:68)
        at com.intellij.concurrency.JobLauncherImpl.invokeConcurrentlyUnderProgress(JobLauncherImpl.java:110)
        at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.a(LocalInspectionsPass.java:312)
        at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.a(LocalInspectionsPass.java:218)
        at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.collectInformationWithProgress(LocalInspectionsPass.java:136)
        at com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass.doCollectInformation(ProgressableTextEditorHighlightingPass.java:58)
        at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:62)
        at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass$1$1.run(PassExecutorService.java:357)
        at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1182)
        at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass$1.run(PassExecutorService.java:348)
        at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:226)
        at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.a(PassExecutorService.java:345)
        at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:321)
        at com.intellij.concurrency.JobLauncherImpl$3.call(JobLauncherImpl.java:145)
        at com.intellij.concurrency.JobLauncherImpl$3.call(JobLauncherImpl.java:142)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at com.intellij.concurrency.PrioritizedFutureTask.access$101(PrioritizedFutureTask.java:31)
        at com.intellij.concurrency.PrioritizedFutureTask$1.run(PrioritizedFutureTask.java:70)
        at com.intellij.concurrency.PrioritizedFutureTask.run(PrioritizedFutureTask.java:113)

with java :

@Builder
public class SessionBean {

    private String sessionKey;
    private String url
    private String errorMessage;
}

and the very latest version of your branch

from lombok-intellij-plugin.

mlueders avatar mlueders commented on August 19, 2024

@SpOOnman I was poking into this a bit more and realized the inner class is being built but it's being built as part of the no-arg constructor (specifically, line 38 of BuilderProcessor).

Using the same example as above, LombokAugmentProvider:getAugments is invoked with element PsiClass:SomeClass and type com.intellij.psi.PsiMethod. When the BuilderProcessor is invoked, it eventually causes LombokAugmentProvider:getAugments to be invoked with element PsiClass:SomeClass and type com.intellij.psi.PsiClass. However, it's not clear that this is ever passed back to IDEA to be used for code completion. It doesn't look like LombokAugmentProvider:getAugments is ever invoked at the top level with type com.intellij.psi.PsiClass.

Unfortunately, I have no idea why it's not getting invoked with PsiClass. Also, I have no experience with the PsiAugmentProvider so this may not be relevant but I thought I'd pass it along in case it was useful.

from lombok-intellij-plugin.

mlueders avatar mlueders commented on August 19, 2024

@SpOOnman disregard last comment, I see now that it's being returned as the return type of the builder method

from lombok-intellij-plugin.

mlueders avatar mlueders commented on August 19, 2024

It doesn't fix the core problem but I believe BuilderInnerClassProcessor:createFieldMethods has a bug. When it creates the field method, it's setting the containingClass to parentClass when it should be setting it to innerClass (line 146)

from lombok-intellij-plugin.

SpOOnman avatar SpOOnman commented on August 19, 2024

Thank you @mlueders for your input. I've commited a bug you've noticed.

Well, I've had 3 sessions to find out why these generated methods are not "seen" by PSI and autocompletion. I still haven't figured that out. My only finding is that in Structure view, when you check "Show inherited", generated class shows up.

My track is now to check PsiClassImpl and implement all interfaces it implements in LombokLightClass. One good candidate is PsiQualifiedNamedElement, but it's too late tonight for me to play with that. I'll have another session tommorrow.

Michail, I didn't notice that anything has changes after your commit. What did you fix? Can you have a look on lack of autocompletion of this issue? We need to figure that out before release.

from lombok-intellij-plugin.

SpOOnman avatar SpOOnman commented on August 19, 2024

@mplushnikov I can see now that your commit has fixed issue that @twillouer has submitted here. Thanks!

Having another look on this, I've implemented PsiQualifiedNamedElement interface, icon and inheritance methods. I didn't fix an issue. LombokLightClass is still not properly displayed, autocompletion doesn't work and it cannot be found via Find Class dialog.

I will continue looking at this tomorrow. Feel free to poke around, maybe you can find a fix! 😵

from lombok-intellij-plugin.

SpOOnman avatar SpOOnman commented on August 19, 2024

Ok, I've taken clean, second approach to this with a little success.

It follows previous work of @mplushnikov with methods - there is a dummy class created in a Psi tree in a "proper way". LombokNewLightClass (temporary name) just overrides some of its properties. Important part is that Psi has generated this class for me so it has all it needs.

I have a success of creating a class that supports code completion. It is visible on Structure view, although you still need to check "Show inherited" for that. That should be fixed. There is still an issue with a package (default) but I think I know how to fix this.

If you want to try it out, just pull a branch and you should notice two classes created - in an old way and a SureBet class in a new way to compare. This is still work in progress. Next session tomorrow hopefully! 👍

from lombok-intellij-plugin.

mlueders avatar mlueders commented on August 19, 2024

Success!

I hacked up BuilderInnerClassProcessor to create the class with the proper name and save the created internal class in a static variable; then used that in BuilderProcessor to pass to PsiClassUtil.getTypeWithGenerics in order to initialize the methodReturnType of the builder() method and everything's working perfectly!

Code completion is working for setters, toString and build. Also, I'm not able to reproduce the default package issue - I added a builder to a class in the default package and everything works. I did some minimal testing and modified @builder vars - builderClassName, buildMethodName, builderMethodName, fluent and chain - was not able to find a problem.

If there's anything I can do to help with testing, let me know. Thanks for all the effort, can't wait for the next version to be released!

from lombok-intellij-plugin.

SpOOnman avatar SpOOnman commented on August 19, 2024

Hey @mlueders thanks for your support and input. If you have a code you want to share feel free to proceed a pull request. I will continue to work on it tonight.

from lombok-intellij-plugin.

SpOOnman avatar SpOOnman commented on August 19, 2024

Great news. I've pushed a working code that has @builder implemented fine! Autocompletion works fine, IDEA recognizes classes perfectly!

Updating tests, polishing and cleaning is left for me to do. Also, I need to display warnings on some situations. Feel free to test and send suggestions.

from lombok-intellij-plugin.

mplushnikov avatar mplushnikov commented on August 19, 2024

Great work! I'll watch it for me really next days!

from lombok-intellij-plugin.

mlueders avatar mlueders commented on August 19, 2024

I was finally able to test out the latest code and everything's working great! The only thing I noticed was that the changelog was not updated with builder support - pull request has been submitted.

I'll be distributing the plugin to my co-workers and will let you know if anyone finds anything.

Thanks again, this great plugin just got better!

from lombok-intellij-plugin.

 avatar commented on August 19, 2024

Hi!

if (PsiClassUtil.hasSuperClass(psiClass)) {
  builder.addError(ErrorMessages.canBeUsedOnConcreteClassOnly(Singleton.class));
  result = false;
}

I think, this should be removed from the validate method in class BuilderInnerClassProcessor. With this validation the @builder annotation can only be used on a concrete class only, however the @builder supports classes with superclass :)

Anyway, thanks for the implementation, it works like charm! :)

from lombok-intellij-plugin.

SpOOnman avatar SpOOnman commented on August 19, 2024

I've done cleanups and it's ready to be released!

@m-attila thank you! I've removed that check.

I've also tracked down Structure View and I've created bug report on Jetbrains YouTrack: http://youtrack.jetbrains.com/issue/IDEA-115349 LightElement should decide itself if it is visible in Structure View. Just a note here, I'll keep an eye on this.

I've droped one scenario, which is a rare case in my opinion - when builder class is already defined inner class. This would be hard to do with IntelliJ Psi internals. So I've just dropped it. Plugin refuses to process such case and reports an error for a user.

Thank you all for your support, testing and suggestions on this one. It was really great to work with you, knowing that you test it and poke around this code. 👍

@mplushnikov please review my code and merge it to master if it is satisfactionary.

from lombok-intellij-plugin.

mplushnikov avatar mplushnikov commented on August 19, 2024

Everything looks good. I have merged your branch to master and will build a new release soon!

from lombok-intellij-plugin.

SpOOnman avatar SpOOnman commented on August 19, 2024

Great job!

from lombok-intellij-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.