1
1
package org .moreunit .elements ;
2
2
3
- import java .util .ArrayList ;
3
+ import java .util .Comparator ;
4
+ import java .util .HashSet ;
4
5
import java .util .List ;
6
+ import java .util .Set ;
5
7
6
8
import org .eclipse .jdt .core .ICompilationUnit ;
7
9
import org .eclipse .jdt .core .IJavaElement ;
17
19
public class MissingClassTreeContentProvider implements ITreeContentProvider
18
20
{
19
21
20
- public MissingClassTreeContentProvider ()
21
- {
22
-
23
- }
24
-
25
- public Object [] getChildren (Object arg0 )
22
+ public Object [] getChildren (Object parent )
26
23
{
24
+ if (parent instanceof IPackageFragment packageFragment )
25
+ {
26
+ try
27
+ {
28
+ Set <ICompilationUnit > compilationUnits = new HashSet <>();
29
+ for (ICompilationUnit compilationUnit : packageFragment .getCompilationUnits ())
30
+ {
31
+ if (compilationUnit .findPrimaryType () != null )
32
+ {
33
+ ClassTypeFacade classTypeFacade = new ClassTypeFacade (compilationUnit );
34
+ if (! TypeFacade .isTestCase (compilationUnit ) && ! classTypeFacade .hasTestCase ())
35
+ {
36
+ compilationUnits .add (compilationUnit );
37
+ }
38
+ }
39
+ }
40
+ return compilationUnits .stream ().sorted (Comparator .comparing (Object ::toString , String .CASE_INSENSITIVE_ORDER )).toArray (ICompilationUnit []::new );
41
+ }
42
+ catch (JavaModelException e )
43
+ {
44
+ e .printStackTrace ();
45
+ }
46
+ }
27
47
return null ;
28
48
}
29
49
30
- public Object getParent (Object arg0 )
50
+ public Object getParent (Object child )
31
51
{
52
+ if (child instanceof ICompilationUnit unit )
53
+ {
54
+ return unit .getParent ();
55
+ }
32
56
return null ;
33
57
}
34
58
35
- public boolean hasChildren (Object arg0 )
59
+ public boolean hasChildren (Object parent )
36
60
{
37
- return false ;
61
+ return ! ( parent instanceof ICompilationUnit ) ;
38
62
}
39
63
40
64
public Object [] getElements (Object inputElement )
41
65
{
42
- List <Object > elements = new ArrayList <Object >();
43
-
44
- if (inputElement instanceof MissingTestsViewPart )
66
+ Set <IPackageFragment > packages = new HashSet <>();
67
+ if (inputElement instanceof MissingTestsViewPart missingTestsViewPart )
45
68
{
46
- IJavaProject javaProject = (( MissingTestsViewPart ) inputElement ) .getSelectedJavaProject ();
69
+ IJavaProject javaProject = missingTestsViewPart .getSelectedJavaProject ();
47
70
if (javaProject != null )
48
71
{
49
72
List <IPackageFragmentRoot > allSourceFolderFromProject = PluginTools .getAllSourceFolderFromProject (javaProject );
@@ -62,7 +85,8 @@ public Object[] getElements(Object inputElement)
62
85
ClassTypeFacade classTypeFacade = new ClassTypeFacade (compilationUnit );
63
86
if (! TypeFacade .isTestCase (compilationUnit ) && ! classTypeFacade .hasTestCase ())
64
87
{
65
- elements .add (compilationUnit );
88
+ packages .add ((IPackageFragment ) javaPackage );
89
+ break ;
66
90
}
67
91
}
68
92
}
@@ -75,8 +99,7 @@ public Object[] getElements(Object inputElement)
75
99
}
76
100
}
77
101
}
78
-
79
- return elements .toArray ();
102
+ return packages .stream ().sorted (Comparator .comparing (Object ::toString , String .CASE_INSENSITIVE_ORDER )).toArray (IJavaElement []::new );
80
103
}
81
104
82
105
public void inputChanged (Viewer arg0 , Object arg1 , Object arg2 )
0 commit comments