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

Avoid duplicating annotations for multiple variables declared on the same line #79

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

Comments

@GoogleCodeExporter
Copy link

Given the following foo.jaif (attached):

---------------------------------------
package java.lang:

annotation @SuppressWarnings:
    String[] value

package pkg:

class foo:
    field a: @SuppressWarnings({"bar"})
    field b: @SuppressWarnings({"bar"})
---------------------------------------

and the following pkg/foo.java (attached):

---------------------------------------
package pkg;

public class foo
{
volatile int a, b;
}
---------------------------------------

I would expect the call to

insert-annotations-to-source -i foo.jaif pkg/foo.java

(synced on April 2, 2014 and run on Fedora 19 64-bit)

to produce

----------------------------------
package pkg;
import java.lang.SuppressWarnings;

public class foo
{
@SuppressWarnings({"bar"})
volatile int a, b;
}
----------------------------------

Instead, the following output is produced, which results in the following 
compilation error:
"foo.java:6: error: duplicate annotation"

------------------------------------------------------------------------
package pkg;
import java.lang.SuppressWarnings;

public class foo
{
volatile @SuppressWarnings({"bar"}) @SuppressWarnings({"bar"}) int a, b;
}
------------------------------------------------------------------------

Original issue reported on code.google.com by [email protected] on 10 Apr 2014 at 5:21

Attachments:

@GoogleCodeExporter
Copy link
Author

Naturally we should also check that non-duplicate annotations, such as

    field a: @SuppressWarnings({"a"})
    field b: @SuppressWarnings({"b"})

are not all concatenated at the beginning of the line as follows

volatile @SuppressWarnings({"a"}) @SuppressWarnings({"b"}) int a, b;

Original comment by [email protected] on 10 Apr 2014 at 5:46

@GoogleCodeExporter
Copy link
Author

Original comment by [email protected] on 10 Apr 2014 at 7:03

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

Note that even if only a single annotation is added, the multiple declarations 
must be split up.
If we have:

Object a, b;

Adding an annotation to a should give:

@TA Object a;
Object b;

Otherwise, the type of variable b would be changed by the change to a.

Original comment by [email protected] on 11 Apr 2014 at 8:00

@dbrosoft
Copy link
Contributor

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

@mernst mernst added this to the Medium milestone Jan 10, 2016
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

3 participants