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

insert-annotation-to-source: issues with simultaneous declarations #36

Open
GoogleCodeExporter opened this issue Jul 3, 2015 · 5 comments

Comments

@GoogleCodeExporter
Copy link

Test.java contains a simultaneous declaration of fields a and b:

Object a,b;

Test1.jaif annotates a and b with SuppressWarnings(...)
Test2.jaif annotates a with @NonNull, b with @Nullable


What steps will reproduce the problem?
1. javac Test.java
2. insert-annotations-to-source Test1.jaif Test.java
3. javacheck annotated/Test.java
4. insert-annotations-to-source Test2.jaif Test.java

What is the expected output? What do you see instead?
Output from step 3:
annotated/Test.java:5: error: duplicate annotation, the declaration of 
SuppressWarnings does not have a valid Repeatable annotation
  @SuppressWarnings({"nonnull","rawness","nullness"})
  ^
1 error

Output from step 4:
Found class Test, but unable to insert @checkers.nullness.quals.Nullable:
  @checkers.nullness.quals.Nullable (nl=true) @ [GenericArrayLocationCriterion at outermost type, FieldCriterion: b, In class 'Test' (exactly), In class 'Test' (exactly)]


Ideally, the simultaneous declaration should be expanded to one declaration per 
field.

What version of the product are you using? On what operating system?
hg head on linux.

Please provide any additional information below.

Original issue reported on code.google.com by mattsbr...@g.ucla.edu on 7 May 2013 at 8:44

Attachments:

@dbrosoft
Copy link
Contributor

Test FieldMultiple has been corrected and disabled until there is a fix.

@CharlesZ-Chen
Copy link
Contributor

CharlesZ-Chen commented Dec 16, 2016

Just write this as a note for others who also meet the "multiple declarations" problem:

I've searched a bit on existing refactor tools that could refactor multiple declarations in one statement. However I didn't find anyone works.

I've filed an issue on google-java-format here:

google/google-java-format#104

But at the moment nobody gives a response on this issue.

Thus, as a workaround, I write a simple and ugly refactor that specifically refactor multiple declarations:

https://github.com/CharlesZ-Chen/multiDeclRefactor

This refactor could work as a pre-processor before doing annotation insertion on a project. However, since I developed it in a catch-the-DDL way, the code is a bit unordered and not good for maintenance. It should be just a temporary workaround, and hopefully later on some mature & professional refactor tools could solve this problem wonderfully.

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

No branches or pull requests

4 participants