This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 240512 - "use" statements for custom annotations are not recognized
Summary: "use" statements for custom annotations are not recognized
Status: RESOLVED FIXED
Alias: None
Product: php
Classification: Unclassified
Component: Editor (show other bugs)
Version: 7.4
Hardware: All All
: P3 normal with 1 vote (vote)
Assignee: Ondrej Brejla
URL:
Keywords:
Depends on: 241060
Blocks:
  Show dependency tree
 
Reported: 2014-01-15 18:11 UTC by ianfp
Modified: 2016-10-14 10:15 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
screenshot (87.19 KB, image/png)
2014-01-15 18:11 UTC, ianfp
Details
Custom type annotation parser (3.59 KB, text/x-java)
2014-01-27 14:36 UTC, Ondrej Brejla
Details

Note You need to log in before you can comment on or make changes to this bug.
Description ianfp 2014-01-15 18:11:28 UTC
Created attachment 144001 [details]
screenshot

Symfony2 allows the user to create custom validator classes and apply them as annotations:

http://symfony.com/doc/current/cookbook/validation/custom_constraint.html

Such custom annotations need to be imported into the current namespace via the "use" statement. However, the editor does not recognize these "use" statements as being used in the code. (See the attached screenshot.)

I would have marked this as an enhancement, except for this problem: if I then use the "Fix use statements" keyboard shortcut, the "use" statements for my custom annotations are removed. If I don't notice and then try to validate the object, I get a fatal error because the annotation classes cannot be found!
Comment 1 Ondrej Brejla 2014-01-27 14:20:10 UTC
And that custom validator classes physically exists? Do you have such classes in your project?
Comment 2 Ondrej Brejla 2014-01-27 14:36:15 UTC
Created attachment 144417 [details]
Custom type annotation parser

Proposed fix, but not sure how is this change save...
Comment 3 ianfp 2014-01-27 17:05:07 UTC
(In reply to Ondrej Brejla from comment #1)
> And that custom validator classes physically exists? Do you have such
> classes in your project?

Yes, I wrote those custom validator classes and they are part of the same project.
Comment 4 Ondrej Brejla 2014-01-28 14:04:22 UTC
Ok, so I improved it a bit in the dev build. If you go to Options -> PHP -> Annotations, you can check "Treat Unknown Annotations as Type Annotations (e.g. Symfony2 Custom Validators)" and then *all* unknown (any other annotation parser knows 'em) annotations are resolved as Type annotations. So it will match use statements properly ;)

Fixed in web-main #b8bf50621882
Comment 5 ianfp 2014-01-28 17:06:17 UTC
(In reply to Ondrej Brejla from comment #4)
> Ok, so I improved it a bit in the dev build. If you go to Options -> PHP ->
> Annotations, you can check "Treat Unknown Annotations as Type Annotations
> (e.g. Symfony2 Custom Validators)" and then *all* unknown (any other
> annotation parser knows 'em) annotations are resolved as Type annotations.
> So it will match use statements properly ;)
> 
> Fixed in web-main #b8bf50621882

Wow! Thanks for the fast turnaround on this. I presume that it will go live with the 8.0 release (based on the Target Milestone)?
Comment 6 Ondrej Brejla 2014-01-28 18:50:23 UTC
You are welcome :) Exactly! You can of course try it in the dev build when QA posts here a comment that it was integrated.
Comment 7 Quality Engineering 2014-01-29 02:52:46 UTC
Integrated into 'main-silver', will be available in build *201401290001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/b8bf50621882
User: Ondrej Brejla <obrejla@netbeans.org>
Log: #240512 - "use" statements for custom annotations are not recognized
Comment 8 pmaselkowski 2016-10-14 10:15:10 UTC
As a side note I'll add that to keep use statements for whatever reasons, use @see docblock with type, ie:

/**
 * @Validator(MyType)
 * @see MyType
 */
public $myProperty;

This will keep use statement even after applying "Fix use statements"