Skip to content

Commit 86c0ee8

Browse files
committed
Some cleanup and comment adjustments in AsyncJavaSymbolDescriptor, after Eirik reviewed Claude's patch.
1 parent 4161040 commit 86c0ee8

1 file changed

Lines changed: 31 additions & 54 deletions

File tree

java/java.sourceui/src/org/netbeans/modules/java/source/ui/AsyncJavaSymbolDescriptor.java

Lines changed: 31 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,20 @@ public String getSimpleName() {
104104
@Override
105105
public void open() {
106106
final Collection<? extends SymbolDescriptor> symbols = resolve();
107-
/* resolve() falls back to Collections.singleton(this) if it could
108-
not enrich the descriptor (e.g. javac threw CompletionFailure
109-
for some transient reason). Detect that case explicitly to
110-
avoid recursing into our own open(); fall back to opening the
111-
type by its ElementHandle via ElementOpen, which goes through
112-
ClassIndex/SourceUtils. */
113-
if (symbols.size() == 1 && symbols.iterator().next() == this) {
107+
if (symbols.isEmpty()) {
108+
return;
109+
}
110+
SymbolDescriptor sd = symbols.iterator().next();
111+
if (sd != this) {
112+
sd.open();
113+
} else {
114+
/* The case where resolve() returns an un-enriched Collections.singleton(this) because
115+
of some error (e.g. javac threw CompletionFailure). Fall back to opening the type by
116+
its ElementHandle via ElementOpen, which goes through ClassIndex/SourceUtils. */
114117
final FileObject file = getFileObject();
115118
if (file != null) {
116119
ElementOpen.open(ClasspathInfo.create(file), getOwner());
117120
}
118-
return;
119-
}
120-
if (!symbols.isEmpty()) {
121-
symbols.iterator().next().open();
122121
}
123122
}
124123

@@ -186,33 +185,17 @@ private Collection<? extends SymbolDescriptor> resolve() {
186185
final List<SymbolDescriptor> symbols = new ArrayList<>();
187186
try {
188187
final String binName = ElementHandleAccessor.getInstance().getJVMSignature(getOwner())[0];
189-
/* Build the JavacTask via JavacParser.createJavacTask
190-
(which pre-registers NetBeans' javac context enhancers --
191-
most importantly NBClassReader, plus NBAttr, NBEnter,
192-
NBMemberEnter, NBResolve, NBClassFinder, NBJavaCompiler,
193-
NBClassWriter, etc.) instead of calling
194-
JavacTool.create().getTask(...) directly. NetBeans .sig
195-
files (the per-root cached form of indexed Java classes)
196-
are written by NBClassWriter and use a relaxed/extended
197-
class-file format that only NBClassReader knows how to
198-
read; stock javac's ClassReader rejects them with
199-
BadClassFile, which propagates as CompletionFailure.
200-
ElementUtils.getTypeElementByBinaryName silently catches
201-
the CompletionFailure and returns null, and resolve()
202-
therefore returned an empty collection for every Java
203-
type whose .sig had any NB-specific encoding -- the
204-
actual cause of the long-standing Go to Symbol
205-
disappearance bug. */
188+
/* Build the JavacTask via JavacParser.createJavacTask, which pre-registers NetBeans'
189+
javac context enhancers, e.g. NBClassReader plus NBAttr, NBEnter, NBMemberEnter,
190+
NBResolve, NBClassFinder, NBJavaCompiler, NBClassWriter, instead of calling
191+
JavacTool.create().getTask(...) directly.
192+
193+
NetBeans .sig files (the per-root cached form of indexed Java classes) are written by
194+
NBClassWriter and use a relaxed/extended class-file format that only NBClassReader knows
195+
how to read. Stock javac's ClassReader would rejects them with BadClassFile. */
206196
final ClasspathInfo cpInfo = ClasspathInfo.create(getRoot());
207197
final JavacTaskImpl jt = JavacParser.createJavacTask(
208-
cpInfo,
209-
null,
210-
null,
211-
null,
212-
null,
213-
null,
214-
null,
215-
null,
198+
cpInfo, null, null, null, null, null, null, null,
216199
Collections.<JavaFileObject>emptyList());
217200
//Force JTImpl.prepareCompiler to get JTImpl into Context
218201
jt.enter();
@@ -253,26 +236,20 @@ the CompletionFailure and returns null, and resolve()
253236
}
254237
}
255238
} catch (RuntimeException e) {
256-
/* Swallow so that unexpected javac failures (e.g.
257-
CompletionFailure, which is a RuntimeException) fall through
258-
to the "no enriched symbols" path below rather than
259-
propagating into the WORKER thread and leaving the descriptor
260-
in a half-initialized state. Previously this was a catch for
261-
IOException, thrown by the old hand-rolled JavaFileManager
262-
wiring that has now been deleted. */
239+
/* Swallow so that unexpected javac failures (e.g. CompletionFailure, which is a
240+
RuntimeException) fall through to the "no enriched symbols" path below rather than
241+
propagating into the WORKER thread and leaving the descriptor in a half-initialized
242+
state. */
263243
Exceptions.printStackTrace(e);
264244
}
265-
/* The async path is meant to *enrich* a descriptor that the
266-
(Lucene-backed) JavaSymbolProvider already produced -- not to
267-
delete it. If javac couldn't load the TypeElement (te==null),
268-
no enclosed element matched ident, or the lookup threw, the
269-
entry is still a valid match from the index and must remain
270-
in the list. Returning an empty collection here would cause
271-
Models.MutableListModelImpl#descriptorChanged to remove the
272-
source from the live model, producing the long-standing
273-
"search results appear briefly then disappear" Go to Symbol
274-
symptom. Fall back to keeping the AsyncJavaSymbolDescriptor
275-
itself. */
245+
/* The async path is meant to *enrich* a descriptor that the (Lucene-backed)
246+
JavaSymbolProvider already produced, not to delete it. If javac couldn't load the
247+
TypeElement (te==null), no enclosed element matched ident, or the lookup threw, the entry is
248+
still a valid match from the index and must remain in the list. Returning an empty
249+
collection here would cause Models.MutableListModelImpl#descriptorChanged to remove the
250+
source from the live model, causing Lucene-based search results to appear briefly then
251+
disappear in the Go to Symbol dialog. Fall back to keeping the AsyncJavaSymbolDescriptor
252+
itself. */
276253
if (symbols.isEmpty()) {
277254
return Collections.<SymbolDescriptor>singleton(this);
278255
}

0 commit comments

Comments
 (0)