It would be useful to:
1) Display a hint next to the class definition if (a) Junit is enabled for the project and (b) there is no unit test for the class
\_ Clicking the hint next to the class should give the option to generate a unit test for the class
2) Display a hint next to each method in the class if (a) there is a unit test for the class and (b) there no corresponding unit test method
\_ Clicking the hint next to the method should give the option to generate a unit test for the method
These hints should have a setting next to the rest of the hints, to allow them to be toggled on and off.
Created attachment 131055 [details]
The patch contains two things.
First the part of the hints. It includes three classes in java.testrunner module that provide the two hints and also using the new api from the second part.
Second the part that includes two classes in the gsf.testrunner module. This is needed in order to be able to use the same dialog to create tests from the hints popup.
The new api is needed as hints api related stuff are in java cluster while gsf.testrunner is in ide cluster. So I choose to put the new hints in java.testrunner module which is part of the java cluster.
Please review. It is my first try with hints. I do not know if I am following hints standards, so any comments are more than welcome. Thank you
A few comments:
1. seems that that you want is a lightbulb that only appears when the cursor is at the class/method declaration. I would suggest to use: @Hint(..., category = "suggestions", hintKind = Kind.ACTION, severity = Severity.HINT). No strong need to use JavaFix when this is done, can use "normal" Fix. In general, I don't really like introducing the hintKind = Kind.INSPECTION, severity = Severity.HINT. Also, if you would like to keep hintKind = Kind.INSPECTION for any reason, please use either options=Options.QUERY (if the hint should work in Source/Inspect, but not in Refactor/Inspect and Transform) or options=Options.NO_BATCH (if the hint should worker in neither the Source/Inspect nor Refactor/Inspect and Transform) - the hint apparently cannot work properly in Refactor/Inspect and Transform (there must not be any side-effects of the JavaFix.performRewrite to make it work in I&T).
private static HashMap<Object, ArrayList<String>> validCombinations;
seems very suspicious to me. When is the map cleared? Fields like this typically lead to a memory leak, and it seems the field is re-initialized before each use, so I would suggest to drop it completely, use CompilationInfo.putCachedValue, or at least make sure the values won't be kept in the memory for the whole eternity.
3. Don't use CaretAwareJavaSourceTaskFactory.getLastPosition, use HintContext.getCaretLocation.
4. don't use tabulators.
5. in some cases
could be replaced (with easier and more readable):
6. I would suggest using Map/List instead of HashMap/ArrayList, unless HashMap/ArrayList is the only implementation that will ensure correct behaviour.
(In reply to comment #3)
> A few comments:
> 1. seems that that you want is a lightbulb ...
wasn't sure which combination to use. I will use the @Hint(..., category =
"suggestions", hintKind = Kind.ACTION, severity = Severity.HINT)
> 2. This:
> private static HashMap<Object, ArrayList<String>> validCombinations;
> seems very suspicious to me...
made it method private and also clearing it when no more useful
> 3. Don't use CaretAwareJavaSourceTaskFactory.getLastPosition, use
> Stylistic comments:
> 4. don't use tabulators.
> 5. in some cases
> could be replaced (with easier and more readable):
> 6. I would suggest using Map/List instead of HashMap/ArrayList, unless
> HashMap/ArrayList is the only implementation that will ensure correct
Created attachment 131085 [details]
updated the patch based on remarks from comment 3.
If there are no objections, I plan to integrate the change on Wednesday. Thank you
Author: Theofanis Oikonomou <email@example.com>
Date: 2013-02-13 12:25
Issue #162593 - [67cat] Add hints to Junit test generation
Integrated into 'main-golden', will be available in build *201302132300* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
User: Theofanis Oikonomou <firstname.lastname@example.org>
Log: Issue #162593 - [67cat] Add hints to Junit test generation