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 216856 - Static code analysis API is class path oriented (can not inspect content of Folder).
Summary: Static code analysis API is class path oriented (can not inspect content of F...
Status: RESOLVED FIXED
Alias: None
Product: editor
Classification: Unclassified
Component: Hints & Annotations (show other bugs)
Version: 7.3
Hardware: PC Solaris
: P2 normal (vote)
Assignee: Milutin Kristofic
URL:
Keywords:
Depends on: 217347
Blocks:
  Show dependency tree
 
Reported: 2012-08-14 11:15 UTC by Alexander Simon
Modified: 2014-02-05 02:46 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
add folder scope (2.42 KB, patch)
2014-02-03 09:36 UTC, Alexander Simon
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Simon 2012-08-14 11:15:54 UTC
CND is implementing C/C++ static code analyzer (private module) by reusing the Static Analysis Core API.
There is a problem when the inspector is invoked:
- the class Analyzer.Context contains empty scope if the project scope is selected.
List of source roots is empty because the list is filled by project's class paths. 
C/C++ project does not provide class paths (due to performance problem with parsing API).
Please provide class path (java) independent way to select the project scope.

Please reassign bug to right product/component if I selected wrong one.
Comment 1 Jan Lahoda 2012-08-14 11:44:33 UTC
(In reply to comment #0)
> CND is implementing C/C++ static code analyzer (private module) by reusing the
> Static Analysis Core API.

Good!

> There is a problem when the inspector is invoked:
> - the class Analyzer.Context contains empty scope if the project scope is
> selected.
> List of source roots is empty because the list is filled by project's class
> paths. 
> C/C++ project does not provide class paths (due to performance problem with
> parsing API).
> Please provide class path (java) independent way to select the project scope.

Strictly speaking, the API is not CP oriented (there is no mention of CP in the API/SPI, to my knowledge). Not even the implementation is not CP oriented - it uses the CP as a fallback, as most projects are use CP to bind to the rest of the IDE (otherwise we would need to add support for static analysis to *all* existing projects, which feels insane to me).

In fact, there is a way to specify the project's Scope: include the Scope in the project's lookup. This Scope takes precedence over everything else (and I do use it for a non-Java project). The downside is that maintaining the Scope is project's lookup is not particularly trivial. I am thinking about a ScopeProvider to support other features, and it might be usable even for code.analysis, eliminating the need to maintain the Scope itself in the Lookup. But I suggest to use the Scope for the time being, until the ScopeProvider is (or is not) sorted out.

For the record, there was another approach that used the generic source group as the final fallback when nothing else was available, but I had to drop it, due to very serious performance problems.

> 
> Please reassign bug to right product/component if I selected wrong one.
Comment 2 Alexander Simon 2012-08-14 12:55:15 UTC
(In reply to comment #1)
> (In reply to comment #0)
> In fact, there is a way to specify the project's Scope: include the Scope in
> the project's lookup. This Scope takes precedence over everything else (and I
> do use it for a non-Java project). The downside is that maintaining the Scope
> is project's lookup is not particularly trivial.

Yes, it is not trivial.
By the way C/C++ project has Sources in the lookup.
Probably it is enough? (If project does not register class paths, ask project lookup for Sources).

> I am thinking about a
> ScopeProvider to support other features, and it might be usable even for
> code.analysis, eliminating the need to maintain the Scope itself in the Lookup.

It will resolve the problem.

> But I suggest to use the Scope for the time being, until the ScopeProvider is
> (or is not) sorted out.

I'd prefer to wait ScopeProvider.
Comment 3 Jan Lahoda 2012-08-15 08:31:02 UTC
(In reply to comment #2)
> (In reply to comment #1)
> > (In reply to comment #0)
> > In fact, there is a way to specify the project's Scope: include the Scope in
> > the project's lookup. This Scope takes precedence over everything else (and I
> > do use it for a non-Java project). The downside is that maintaining the Scope
> > is project's lookup is not particularly trivial.
> 
> Yes, it is not trivial.
> By the way C/C++ project has Sources in the lookup.
> Probably it is enough? (If project does not register class paths, ask project
> lookup for Sources).

Thats what I was referring to with the generic source group. The Sources can be used in two ways: to get the generic source group, which was done originally, but as a consequence the whole subfolder of module suite projects was scanned, leading to terrible performance when any module suite was among the selected projects. Or the C/C++ source group(s) keys would need to be hardcoded in code.analysis, but the API could hardly be considered to be language agnostic after that.
Comment 4 Jan Lahoda 2012-09-05 07:15:03 UTC
Could you please check if this is sufficient:
http://hg.netbeans.org/jet-main/rev/c35e26c7a72a

Thanks.
Comment 5 Quality Engineering 2012-09-06 02:09:59 UTC
Integrated into 'main-golden', will be available in build *201209060001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/c35e26c7a72a
User: Jan Lahoda <jlahoda@netbeans.org>
Log: #216856: introducing AnalysisScopeProvider to get a Scope from a Project.
Comment 6 Alexander Simon 2012-09-11 08:29:59 UTC
What about using DataFolder in a node lookup.
C/C++ projects do not know "package" (NonRecursiveFolder in a node lookup for java). Instead  C/C++ projects know "folder" (DataFolder in a node lookup).
Comment 7 Jan Lahoda 2012-09-11 09:01:02 UTC
(In reply to comment #6)
> What about using DataFolder in a node lookup.

I would rather no do that - other project type may have the DF in the Lookup for other purposes, and it may lead to unexpected results.

Moreover, not sure if that would solve the C/C++ project situation: I always though individual files (regardless of their enclosing directories) can be added to the project? What DF would be sent to the Scope in such a case? How would be the DFs in the Lookup maintained? 

> C/C++ projects do not know "package" (NonRecursiveFolder in a node lookup for
> java). Instead  C/C++ projects know "folder" (DataFolder in a node lookup).

So don't use the NRF bucket. I assumed C/C++ project would use the "files" bucket on Scope (isn't the C/C++ project a bunch of files?), but I think you can use the source roots if you wish (which is intended to be recursive).
Comment 8 Vladimir Voskresensky 2012-09-11 13:20:38 UTC
Jan, can we remove dependency from Refactoring API? Otherwise make project now has this dependency and other applications based on cnd source base now are broken, because refactoring is excluded from platform.
Comment 9 Vladimir Voskresensky 2012-09-11 13:42:30 UTC
(In reply to comment #7)
> (In reply to comment #6)
> > What about using DataFolder in a node lookup.
> 
> I would rather no do that - other project type may have the DF in the Lookup
> for other purposes, and it may lead to unexpected results.
> 
> Moreover, not sure if that would solve the C/C++ project situation: I always
> though individual files (regardless of their enclosing directories) can be
> added to the project? What DF would be sent to the Scope in such a case? How
> would be the DFs in the Lookup maintained? 
> 
> > C/C++ projects do not know "package" (NonRecursiveFolder in a node lookup for
> > java). Instead  C/C++ projects know "folder" (DataFolder in a node lookup).
> 
> So don't use the NRF bucket. I assumed C/C++ project would use the "files"
> bucket on Scope (isn't the C/C++ project a bunch of files?), but I think you
> can use the source roots if you wish (which is intended to be recursive).
C++ project has different views over source tree. One of this views (for projects from existing sources) reflects physical structure. It might be expected by user to reduce inspect analysis to "folder" subtree (so recursively).
Any advice how to achieve it? Looks like RunAnalysisPanel should be ready for such requests as well or we should be able to create Scope over folder (recursively)
Comment 10 Jan Lahoda 2012-09-11 13:43:44 UTC
(In reply to comment #8)
> Jan, can we remove dependency from Refactoring API? Otherwise make project now
> has this dependency and other applications based on cnd source base now are
> broken, because refactoring is excluded from platform.

Not quite clear to me: are these applications going to use the static code analysis? If no, than the easiest way out I see is to create a bridge module between cnd.make.project and code.analysis instead of making cnd.make.project directly dependent on code.analysis. If yes, the situation would be more complex - not only we would have to duplicate Scope (or a similar facility), but also would be more difficult not to break existing clients. Also, would make it more difficult for code.analysis to use the standard Scope selector (not using it now, but I hope it will be possible eventually).
Comment 11 Jan Lahoda 2012-09-11 13:48:06 UTC
(In reply to comment #9)
> (In reply to comment #7)
> > (In reply to comment #6)
> > > What about using DataFolder in a node lookup.
> > 
> > I would rather no do that - other project type may have the DF in the Lookup
> > for other purposes, and it may lead to unexpected results.
> > 
> > Moreover, not sure if that would solve the C/C++ project situation: I always
> > though individual files (regardless of their enclosing directories) can be
> > added to the project? What DF would be sent to the Scope in such a case? How
> > would be the DFs in the Lookup maintained? 
> > 
> > > C/C++ projects do not know "package" (NonRecursiveFolder in a node lookup for
> > > java). Instead  C/C++ projects know "folder" (DataFolder in a node lookup).
> > 
> > So don't use the NRF bucket. I assumed C/C++ project would use the "files"
> > bucket on Scope (isn't the C/C++ project a bunch of files?), but I think you
> > can use the source roots if you wish (which is intended to be recursive).
> C++ project has different views over source tree. One of this views (for
> projects from existing sources) reflects physical structure. It might be
> expected by user to reduce inspect analysis to "folder" subtree (so
> recursively).
> Any advice how to achieve it? Looks like RunAnalysisPanel should be ready for
> such requests as well or we should be able to create Scope over folder
> (recursively)

Thats a situation for which (I think) using the standard Scope selector is most appropriate - that one is pluggable, allowing Java projects to plug in packages, and anybody else plug their own views.
Comment 12 Leonid Lenyashin 2012-09-11 14:06:37 UTC
(In reply to comment #10)
> (In reply to comment #8)
> > Jan, can we remove dependency from Refactoring API? Otherwise make project now
> > has this dependency and other applications based on cnd source base now are
> > broken, because refactoring is excluded from platform.
> 
> Not quite clear to me: are these applications going to use the static code
> analysis? If no, than the easiest way out I see is to create a bridge module
> between cnd.make.project and code.analysis instead of making cnd.make.project
> directly dependent on code.analysis. If yes, the situation would be more
> complex - not only we would have to duplicate Scope (or a similar facility),
> but also would be more difficult not to break existing clients. Also, would
> make it more difficult for code.analysis to use the standard Scope selector
> (not using it now, but I hope it will be possible eventually).

I'm not that deep into the subject, but Jan's idea towards avoiding direct dependencies sounds attractive to me.
Comment 13 Quality Engineering 2012-09-12 02:09:22 UTC
Integrated into 'main-golden', will be available in build *201209120001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/18fa272d3b56
User: Alexander Simon <alexvsimon@netbeans.org>
Log: provide scope provider of C/C++ project according to Bug #216856 Static code analysis API is class path oriented
Comment 14 Vladimir Voskresensky 2012-09-12 10:05:59 UTC
(In reply to comment #10)
> (In reply to comment #8)
> > Jan, can we remove dependency from Refactoring API? Otherwise make project now
> > has this dependency and other applications based on cnd source base now are
> > broken, because refactoring is excluded from platform.
> 
> Not quite clear to me: are these applications going to use the static code
> analysis? If no, than the easiest way out I see is to create a bridge module
> between cnd.make.project and code.analysis instead of making cnd.make.project
> directly dependent on code.analysis. If yes, the situation would be more
> complex - not only we would have to duplicate Scope (or a similar facility),
> but also would be more difficult not to break existing clients. Also, would
> make it more difficult for code.analysis to use the standard Scope selector
> (not using it now, but I hope it will be possible eventually).
Alexander, please, move scope provider from makeproject into oss and register it under
Projects/org-netbeans-modules-cnd-makeproject/Lookup in layer.xml (probably there is a corresponding annotation for that)
Comment 15 Vladimir Voskresensky 2012-09-12 10:24:51 UTC
@ProjectServiceProvider(projectType="org-netbeans-modules-cnd-makeproject", service=AnalysisScopeProvider.class)
Comment 16 Jan Lahoda 2012-11-14 13:07:50 UTC
Alexandr, Vladimir, are you OK with the current state of the API, or do you need some changes? Thanks.
Comment 17 Alexander Simon 2012-11-14 15:19:27 UTC
(In reply to comment #16)
> Alexandr, Vladimir, are you OK with the current state of the API, or do you
> need some changes? Thanks.
The project and file scope works perfect.
But I do not understand how to provide folder scope.
Comment 18 Alexander Simon 2012-11-14 15:41:32 UTC
Also selection of several files does not work as "scope".
Comment 19 Alexander Simon 2014-01-29 09:23:59 UTC
Please provide way to select several source files and folders.
It is a stopper for C/C++ static analyzer.
Please fix it in NB 8.0.
Comment 20 Alexander Simon 2014-02-03 09:36:39 UTC
Created attachment 144708 [details]
add folder scope
Comment 21 Milutin Kristofic 2014-02-04 13:50:00 UTC
Thank you for the patch. I check it with java projects, if there is nothing broken. 

http://hg.netbeans.org/jet-main/rev/c2cf661ee781
Comment 22 Quality Engineering 2014-02-05 02:46:03 UTC
Integrated into 'main-silver', will be available in build *201402050001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/c2cf661ee781
User: Milutin Kristofic <mkristofic@netbeans.org>
Log: #216856 - Static code analysis API is class path oriented (can not inspect content of Folder)