Skip to content

Commit 61a31c3

Browse files
committed
Cleanup.
1 parent 22dc956 commit 61a31c3

File tree

1 file changed

+27
-32
lines changed

1 file changed

+27
-32
lines changed

java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/RunOnceFactory.java

+27-32
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,23 @@
3434
import org.openide.util.Lookup;
3535
import org.openide.util.Pair;
3636
import org.openide.util.lookup.ServiceProvider;
37+
import org.openide.util.lookup.ServiceProviders;
3738

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+
})
4343
public class RunOnceFactory extends JavaSourceTaskFactory {
4444

4545
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<>();
5448
private FileObject currentFile;
5549
private CancellableTask<CompilationInfo> task;
56-
50+
5751
public RunOnceFactory() {
5852
super(Phase.RESOLVED, Priority.BELOW_NORMAL);
59-
INSTANCE = this;
53+
// INSTANCE = this;
6054
}
6155

6256
protected synchronized CancellableTask<CompilationInfo> createTask(FileObject file) {
@@ -75,53 +69,54 @@ public void run(CompilationInfo parameter) throws Exception {
7569
protected synchronized Collection<FileObject> getFileObjects() {
7670
if (currentFile == null)
7771
return Collections.<FileObject>emptyList();
78-
72+
7973
return Collections.<FileObject>singletonList(currentFile);
8074
}
8175

8276
private synchronized void addImpl(FileObject file, CancellableTask<CompilationInfo> task) {
8377
if (LOG.isLoggable(Level.FINE)) {
8478
LOG.log(Level.FINE, "addImpl({0}, {1})", new Object[] {FileUtil.getFileDisplayName(file), task.getClass().getName()});
8579
}
86-
80+
8781
work.add(Pair.<FileObject, CancellableTask<CompilationInfo>>of(file, task));
88-
82+
8983
if (currentFile == null)
9084
next();
9185
}
92-
86+
9387
private synchronized void next() {
9488
LOG.fine("next, phase 1");
95-
89+
9690
if (currentFile != null) {
9791
currentFile = null;
9892
task = null;
9993
fileObjectsChanged();
10094
}
101-
95+
10296
LOG.fine("next, phase 1 done");
103-
97+
10498
if (work.isEmpty())
10599
return ;
106-
100+
107101
LOG.fine("next, phase 2");
108-
102+
109103
Pair<FileObject, CancellableTask<CompilationInfo>> p = work.remove(0);
110-
104+
111105
currentFile = p.first();
112106
task = p.second();
113-
107+
114108
fileObjectsChanged();
115-
109+
116110
LOG.fine("next, phase 2 done");
117111
}
118-
112+
119113

120114
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)
123118
return ;
124-
125-
INSTANCE.addImpl(file, task);
119+
120+
factory.addImpl(file, task);
126121
}
127122
}

0 commit comments

Comments
 (0)