34
34
import org .openide .util .Lookup ;
35
35
import org .openide .util .Pair ;
36
36
import org .openide .util .lookup .ServiceProvider ;
37
+ import org .openide .util .lookup .ServiceProviders ;
37
38
38
- /**
39
- *
40
- * @author Jan Lahoda
41
- */
42
- @ ServiceProvider (service =JavaSourceTaskFactory .class )
39
+ @ ServiceProviders ({
40
+ @ ServiceProvider (service =JavaSourceTaskFactory .class ),
41
+ @ ServiceProvider (service =RunOnceFactory .class )
42
+ })
43
43
public class RunOnceFactory extends JavaSourceTaskFactory {
44
44
45
45
private static final Logger LOG = Logger .getLogger (RunOnceFactory .class .getName ());
46
-
47
- // static {
48
- // LOG.setLevel(Level.ALL);
49
- // }
50
-
51
- private static RunOnceFactory INSTANCE ;
52
-
53
- private List <Pair <FileObject , CancellableTask <CompilationInfo >>> work = new LinkedList <Pair <FileObject , CancellableTask <CompilationInfo >>>();
46
+
47
+ private List <Pair <FileObject , CancellableTask <CompilationInfo >>> work = new LinkedList <>();
54
48
private FileObject currentFile ;
55
49
private CancellableTask <CompilationInfo > task ;
56
-
50
+
57
51
public RunOnceFactory () {
58
52
super (Phase .RESOLVED , Priority .BELOW_NORMAL );
59
- INSTANCE = this ;
53
+ // INSTANCE = this;
60
54
}
61
55
62
56
protected synchronized CancellableTask <CompilationInfo > createTask (FileObject file ) {
@@ -75,53 +69,54 @@ public void run(CompilationInfo parameter) throws Exception {
75
69
protected synchronized Collection <FileObject > getFileObjects () {
76
70
if (currentFile == null )
77
71
return Collections .<FileObject >emptyList ();
78
-
72
+
79
73
return Collections .<FileObject >singletonList (currentFile );
80
74
}
81
75
82
76
private synchronized void addImpl (FileObject file , CancellableTask <CompilationInfo > task ) {
83
77
if (LOG .isLoggable (Level .FINE )) {
84
78
LOG .log (Level .FINE , "addImpl({0}, {1})" , new Object [] {FileUtil .getFileDisplayName (file ), task .getClass ().getName ()});
85
79
}
86
-
80
+
87
81
work .add (Pair .<FileObject , CancellableTask <CompilationInfo >>of (file , task ));
88
-
82
+
89
83
if (currentFile == null )
90
84
next ();
91
85
}
92
-
86
+
93
87
private synchronized void next () {
94
88
LOG .fine ("next, phase 1" );
95
-
89
+
96
90
if (currentFile != null ) {
97
91
currentFile = null ;
98
92
task = null ;
99
93
fileObjectsChanged ();
100
94
}
101
-
95
+
102
96
LOG .fine ("next, phase 1 done" );
103
-
97
+
104
98
if (work .isEmpty ())
105
99
return ;
106
-
100
+
107
101
LOG .fine ("next, phase 2" );
108
-
102
+
109
103
Pair <FileObject , CancellableTask <CompilationInfo >> p = work .remove (0 );
110
-
104
+
111
105
currentFile = p .first ();
112
106
task = p .second ();
113
-
107
+
114
108
fileObjectsChanged ();
115
-
109
+
116
110
LOG .fine ("next, phase 2 done" );
117
111
}
118
-
112
+
119
113
120
114
public static void add (FileObject file , CancellableTask <CompilationInfo > task ) {
121
- Lookup .getDefault ().lookupAll (JavaSourceTaskFactory .class ).forEach (x -> {});
122
- if (INSTANCE == null )
115
+ RunOnceFactory factory = Lookup .getDefault ().lookup (RunOnceFactory .class );
116
+
117
+ if (factory == null )
123
118
return ;
124
-
125
- INSTANCE .addImpl (file , task );
119
+
120
+ factory .addImpl (file , task );
126
121
}
127
122
}
0 commit comments