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 191648 - More light-weight variant of SourceUtils.isMainClass()
Summary: More light-weight variant of SourceUtils.isMainClass()
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 7.0
Hardware: All All
: P2 normal (vote)
Assignee: Tomas Zezula
URL:
Keywords: API, PERFORMANCE
Depends on: 193101
Blocks: 183972
  Show dependency tree
 
Reported: 2010-11-04 16:49 UTC by Antonin Nebuzelsky
Modified: 2010-12-11 06:32 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Antonin Nebuzelsky 2010-11-04 16:49:32 UTC
SourceUtils.isMainClass() has two parts. First it looks for the class in the list of main classes in the index (from sources) and if not found it triggers an expensive task to look for the class in all classpath elements. The task can eventually be waiting on a parser lock in org.netbeans.modules.parsing.impl.TaskProcessor.runUserTask().

For the purpose of fixing issue 183972, a new method is needed which will search only in the index and then return false without doing the thorough parsing if not found in the index.
Comment 1 Tomas Zezula 2010-11-05 07:32:31 UTC
As discussed off line this will work only for sources not for binaries, eg. when you select the main class from platform or compile cp. But maven seems to use the isMC only for sources, so it should work.
Comment 2 Tomas Zezula 2010-11-12 12:20:31 UTC
The light way  version will not be able to detect inherited main method, like:

class A {
 psv main(String...) {}
}

class B extends A {}

as the inheritance check requires parsing and should be done outside AWT.
Is such a method with such a restriction useful for you?
Comment 3 Antonin Nebuzelsky 2010-12-07 13:10:37 UTC
I don't have a strong opinion. My guess is that inherited main() methods are not an important usecase which would have to be supported by Run File action on a project. Looking for Jesse's view as well...
Comment 4 Jesse Glick 2010-12-07 14:07:28 UTC
(In reply to comment #3)
> inherited main() methods are not an important usecase

Agreed. You can't meaningfully inherit static methods anyway, and some bug checkers will flag attempts to use static methods via inheritance as bad code style. I would not expect B in your example to be marked as having a main method, i.e. it is OK for DefaultReplaceTokenProvider to enable Run File only on source files literally containing main.
Comment 5 Antonin Nebuzelsky 2010-12-07 14:24:44 UTC
Sounds good.

Tomasi, please prepare the extra method.
Comment 6 Tomas Zezula 2010-12-07 15:08:03 UTC
OK, thanks Tondo and Jesse.
Comment 7 Tomas Zezula 2010-12-10 15:25:40 UTC
Fixed jet-main 2f07ff0e0bb7
Comment 8 Quality Engineering 2010-12-11 06:32:57 UTC
Integrated into 'main-golden', will be available in build *201012110001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/2f07ff0e0bb7
User: Tomas Zezula <tzezula@netbeans.org>
Log: #191648:More light-weight variant of SourceUtils.isMainClass()
#193101:API review of SourceUtils.isMain