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

Unable to insert constructor return type #144

Closed
topnessman opened this issue Nov 15, 2017 · 5 comments
Closed

Unable to insert constructor return type #144

topnessman opened this issue Nov 15, 2017 · 5 comments
Assignees

Comments

@topnessman
Copy link

topnessman commented Nov 15, 2017

Please read the sections below.

@mernst
Copy link
Member

mernst commented Nov 15, 2017

It's difficult to understand the exact problem. Can you give example input and output files, and a command line that you think should create the output files from the input files? Thanks!

@topnessman
Copy link
Author

Testcase:

public class FieldAssignCase2_1 {
    FieldAssignCase2_1() {
    }

    Object foo(){return null;}
}

Jailf file:

package qual:
  annotation @A:

package :
class FieldAssignCase2_1:
method <init>()V:
insert-annotation Method.type: @qual.A

method foo()Ljava/lang/Object;:
insert-annotation Method.type: @qual.A

I run this command to insert annotations from jaif file to source code:

../annotation-tools/annotation-file-utilities/scripts/insert-annotations-to-source default.jaif testinput/inference/limited-inferrable-afu/FieldAssignCase2_1.java -v

The console output is:

Read 3 annotations from default.jaif
Processing testinput/inference/limited-inferrable-afu/FieldAssignCase2_1.java
Parsed testinput/inference/limited-inferrable-afu/FieldAssignCase2_1.java
getPositions returned 1 positions in tree for testinput/inference/limited-inferrable-afu/FieldAssignCase2_1.java
.Writing ./anno/FieldAssignCase2_1.java

And the insertion result is:

import qual.A;
public class FieldAssignCase2_1 {
    FieldAssignCase2_1() {
    }

    @A
    Object foo(){return null;}
}

The expected result is: both constructor return and method return have annotation @A.
Actual result is: only method return gets inserted annotation @A but constructor return gets nothing inserted.

But if I use this syntax in jaif file:

package qual:
  annotation @A:

package :
class FieldAssignCase2_1:
method <init>()V:
return: @qual.A

method foo()Ljava/lang/Object;:
return: @qual.A

And run the same command:

../annotation-tools/annotation-file-utilities/scripts/insert-annotations-to-source default.jaif testinput/inference/limited-inferrable-afu/FieldAssignCase2_1.java -v

I got console output:

Processing testinput/inference/limited-inferrable-afu/FieldAssignCase2_1.java
Parsed testinput/inference/limited-inferrable-afu/FieldAssignCase2_1.java
getPositions returned 2 positions in tree for testinput/inference/limited-inferrable-afu/FieldAssignCase2_1.java
..Writing ./anno/FieldAssignCase2_1.java

and expected insertion result:

import qual.A;
public class FieldAssignCase2_1 {
    @A
    FieldAssignCase2_1() {
    }

    @A
    Object foo(){return null;}
}

So the new syntax using insert-annotation Method.type doesn't work as expected for constructors.

@wmdietl wmdietl mentioned this issue Nov 19, 2017
@wmdietl
Copy link
Member

wmdietl commented Nov 19, 2017

The existing test for constructor return types works:

https://github.com/typetools/annotation-tools/blob/master/annotation-file-utilities/tests/converted/ConstructorReturn.jaif

The difference to your test is that @A is a declaration annotation, not a type use annotation.
If you change the beginning of your .jaif file to

package qual:
  annotation @A: @java.lang.annotation.Target(value={TYPE_USE})

you should see the expected outcome.

If annotation @A is indeed a declaration annotation, you should use:

method <init>()V: @A

However, the latter isn't working for me.

@topnessman can you verify that changing the annotation to a type use annotation allows you to insert it on the constructor return type?
Can you also verify that inserting a declaration annotation on a constructor does not work as expected?
Thanks!

@topnessman
Copy link
Author

Hi @wmdietl ,

can you verify that changing the annotation to a type use annotation allows you to insert it on the constructor return type?

Yes, by changing annotation to type use annotation and inserting again, the constructor return type is inserted back correctly. The jaif file is:

package qual:
  annotation @A: @java.lang.annotation.Target(value={TYPE_USE})

package :
class FieldAssignCase2_1:
method <init>()V:
insert-annotation Method.type: @qual.A

method foo()Ljava/lang/Object;:
insert-annotation Method.type: @qual.A

And the file is:

import qual.A;
public class FieldAssignCase2_1 {
    @A
    FieldAssignCase2_1() {
    }

    @A
    Object foo(){return null;}
}

Can you also verify that inserting a declaration annotation on a constructor does not work as expected?

I confirmed that inserting declaration annotation to constructor return doesn't work.
But when I tried this jaif file:

package qual:
  annotation @A:

package :
class FieldAssignCase2_1:
method <init>()V:// instead of having @A directly, add "return: @qual.A" in the next line
return: @qual.A

method foo()Ljava/lang/Object;:
insert-annotation Method.type: @qual.A

Insertion result is the same as the one above.

@mernst
Copy link
Member

mernst commented Nov 29, 2017

Fixed by 2cc54cb.
However, #146 shows additional work that this report inspired.

@mernst mernst closed this as completed Nov 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants