alxsty / idea-generate-fluent-interface

Automatically exported from code.google.com/p/idea-generate-fluent-interface

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support optional javax.annotation.Generated annotation on all of the generated methods

GoogleCodeExporter opened this issue · comments

I've been taking to annotating all of my generated code like toString, fluent, 
equals, hashCode, etc with the @Generated annotation. This serves as a hint to 
future developers that they should consider regenerating the code as opposed to 
hand modifying it.

I haven't modified the GUI to capture this as a checkbox but here's what I've 
done in the worker that generates the code:

    private void createMethodFromText(String methodText) {
        PsiMethod psiMethod = elementFactory.createMethodFromText(methodText, null);
        PsiAnnotation annotation = elementFactory.createAnnotationFromText("@javax.annotation.Generated(value=\"intellij\")", psiMethod);
        psiMethod.getModifierList().addAfter(annotation, null);
        JavaCodeStyleManager.getInstance(project).shortenClassReferences(psiMethod);
        codeStyleManager.reformat(psiMethod);
        psiClass.add(psiMethod);
    }

The value attribute for the annotation is required. I've simply hard coded it 
to "intellij". I could see having this as a text field on the UI as well.

Original issue reported on code.google.com by m...@massfords.com on 10 Aug 2012 at 11:48