Repository navigation
Conversation
81f3bdd to
6dd9e36
Compare
6dd9e36 to
55ab14c
Compare
7e47c30 to
9bff8b5
Compare
9bff8b5 to
d0c465a
Compare
d0c465a to
e1dc9b0
Compare
4adcb80 to
8580d86
Compare
8580d86 to
9cb055c
Compare
|
Caching candidates to investigate in this PR. Found by reading the code only, nothing was profiled. Line numbers are at High
Medium
Low (cheap each time, called often)
Already cached
To settle for each
|
There was a problem hiding this comment.
LibraryMembers builds the symbols of members the file does not declare (java.util.List#get, a jar method, a method of another source file) from the server data.
flowchart LR
TI["types answer: members JSON per type"] -->|"memberFromTypeInfo"| LM["LibraryMembers"]
TI -->|"registerProjectMembers"| LM
DOC["document: dump symbols and facts"] -->|"createDumpSymbol, then linkDumpSymbol"| LM
LM --> S["JMethodSymbol / JVariableSymbol, cached in sema.symbols"]
LM --> D["sema.declaredMembers: annotations, throws, varargs"]
A member fact of the types answer, like this one for List.get:
{"k":"m","name":"get","desc":"(I)Ljava/lang/Object;","vis":"public","abstract":true,"retType":{"id":"E","kind":"typevar"}}becomes a JMethodSymbol with id java.util.List#get(I)Ljava/lang/Object;: parameter and return types from the descriptor, modifiers from vis / abstract / static, plus throws, varargs and annotations.
The document side works in two passes: createDumpSymbol creates every symbol, then linkDumpSymbol sets owners and types, so an owner never has to exist before its members. applyLibraryMember then copies flags, annotations and throws from the matching member fact.
registerProjectMembers records the annotations, throws and varargs of other source files' members in sema.declaredMembers.
There was a problem hiding this comment.
MemberFactory creates the symbol JSema.resolve(id) cannot find, and fills symbols in from facts and type info.
flowchart TD
R["sema.resolve(id)"] --> A{"in sema.symbols?"}
A -->|yes| X["return it"]
A -->|no| B{"in dumpSymbols?"}
B -->|yes| LM["LibraryMembers: createDumpSymbol, linkDumpSymbol"]
B -->|no| C{"id contains #?"}
C -->|yes| CM["MemberFactory.createMember"]
C -->|no| D{"id contains <?"}
D -->|yes| TP["MemberFactory.typeParameter"]
D -->|no| TS["sema.typeSymbol"]
createMember parses an id like com.acme.Owner#foo(int,String) into owner, name and params, then:
- a member fact of the owner or its parents is found (matched typed, then by arity, then as varargs):
LibraryMembers.memberFromTypeInfobuilds it - otherwise a method is built from the facts and the parsed params
- otherwise it is field-like: a lambda (
$lambda$), a local or anonymous class (Owner#create()$Local$1), or a plain field
The rest fills symbols in: applyFact and fillMethod (from this file's graph facts), applyTypeInfo (from a types answer), plus the cached array, primitive and type variable symbols.
There was a problem hiding this comment.
MemberLookup finds the member a name refers to, by walking a type and its supertypes in the member facts.
flowchart TD
Q["findMember(owner, id, match)"] --> O["owner's member facts"]
O --> M{"matches name and params?"}
M -->|yes| R["return that fact"]
M -->|no| P["each parent: superclass, then interfaces"]
P --> O
Match sets how strict the match is:
TYPED: same name and erased parameter typesARITY: same name and parameter countVARARGS: same name, last parameter is an array, arity fits
MemberFactory tries them in that order, and LibraryMembers uses TYPED.
declaredMethod, declaredField, functionalMethod, receiverSymbol, takesNoFunction and arityMatches pick overloads and fields. They have no caller in this PR, so they belong with the PR that first uses them.
There was a problem hiding this comment.
Finds the methods a method overrides, by walking the supertypes of its class.
flowchart LR
C["Child.run()"] -->|overrides| P["Parent.run()"]
C -->|overrides| R["Runnable.run()"]
There was a problem hiding this comment.
This file contains static helpers to read SemSitter ids, JSON and facts.
… and extract shared constants
dab1c91 to
a67367e
Compare
a67367e to
39a2cdd
Compare
Code Review ✅ Approved 🟡 Medium risk 7 closed / 7 findingsThe substantial new JSema type and member resolution is not yet used by production parsing; only localized Spring name fallbacks alter current behavior. Adds the SemSitter semantic model ( ✅ 7 closed✅ Bug: Type loader's nullable result is handled in one call site only
✅ Bug: Inherited library members get the receiver type as their owner
✅ Bug: Unresolved type symbols still report isTypeSymbol() == true
✅ Edge Case: Long and char annotation literals come back as source text, not Long/Character
✅ Edge Case: Subtype cache keeps stale results for types nested around type variables
...and 2 more closed from earlier reviews Verification Rules 3/3 met Knowledge 🔎 2 PRs 3 inspectedFunctional validation No results Rules 3 passed 2 not applicable
Knowledge 🔎 2 informed a finding
Broader impact PRs 3 inspectedCross-PR 3 PRs inspected 0 open impacts
Auto-approval Not enabledFor more verification details, comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
|
david-schroeter
left a comment
There was a problem hiding this comment.
I did a first round of review on this PR, there is a few things that I think are worth addressing.
| String id = element.getId(); | ||
| if (!id.isEmpty()) { | ||
| dumpSymbols.put(id, element); | ||
| if ("type".equals(element.getKind()) && id.indexOf('<') < 0) { |
There was a problem hiding this comment.
SemSitter emits a class declared inside a constructor as kind: "type" with an ID like p.C#()$Local. The < is part of the enclosing constructor’s name, not a type-parameter suffix. Checking for < anywhere in the ID makes JSema skip binary-name registration and makes LibraryMembers treat the class as a type variable. Could both checks distinguish <init> from a trailing type-parameter suffix like <T>?
Here’s a failing regression test for JSemaEdgesTest:
@Test
@EnabledIfSystemProperty(named = "semsitter.executable", matches = ".+")
void serializable_local_class_is_recognized_inside_a_constructor(@TempDir Path project) throws IOException {
Path pkg = Files.createDirectories(project.resolve("p"));
Files.writeString(pkg.resolve("C.java"), """
package p;
import java.io.Serializable;
class C {
C() {
class Local implements Serializable {
transient int cachedValue;
}
}
void method() {
class Local implements Serializable {
transient int cachedValue;
}
}
}
""");
try (SemSitterClient client = SemSitterClient.start(Path.of(System.getProperty("semsitter.executable")), project)) {
client.setSettings(Map.of("jvm.java_version", List.of("17")));
client.fullGen(List.of());
Document document = client.getFile("p/C.java", 0);
assertThat(document.getSemantic()).isTrue();
assertThat(document.getHasError()).isFalse();
sema.ingestDocument(document);
assertThat(sema.resolve("p.C#method()$Local").type().isSubtypeOf("java.io.Serializable"))
.as("method-local class (control)").isTrue();
assertThat(sema.resolve("p.C#<init>()$Local").type().isSubtypeOf("java.io.Serializable"))
.as("constructor-local class").isTrue();
}
}With the real server, the method-local class passes and the constructor-local class fails, even though both declare implements Serializable. The test checks the semantic predicate, not the rule output: S2057 uses that predicate to decide whether to check for a missing serialVersionUID, so it can skip the constructor-local class.
| for (String id : dumpSymbols.keySet()) { | ||
| libraryMembers().createDumpSymbol(id); | ||
| } | ||
| for (String id : new ArrayList<>(dumpSymbols.keySet())) { |
There was a problem hiding this comment.
Nit: Could we get rid of the new ArrayList<>(...) here or is there a reason to specially create an new list?
| for (String id : dumpSymbols.keySet()) { | ||
| libraryMembers().createDumpSymbol(id); | ||
| } |
There was a problem hiding this comment.
Could we create each symbols in the first loop to avoid a second traversal of the symbols list?
| * Loads the declarations of every type the document references, then keeps {@code loader} to | ||
| * fetch the types reached later, like the return type of a library method. | ||
| */ | ||
| void loadTypes(Function<Set<String>, JsonObject> loader) { |
There was a problem hiding this comment.
Could we create JSema from the document and loader in one step? getClassType() can return an apparently known symbol before loadTypes(), and loadTypes() only collects references already ingested. A single entry point would make that order explicit.
| symbols.putIfAbsent(fqn, created); | ||
| if (typesLoaded && caches.requestedTypes.add(fqn)) { | ||
| JsonObject loaded = typeLoader.apply(Set.of(fqn)); | ||
| if (loaded == null) { |
There was a problem hiding this comment.
Could we make typeLoader private and remove this null branch? The default loader and the wrapper in loadTypes() never return null. JSemaEdgesTest only reaches it by replacing the field; MemberLookupTest already covers a missing answer through loadTypes().
| Optional<String> name = attrs.stream() | ||
| .filter(v -> VALUE_ATTRIBUTE.equals(v.name()) || "name".equals(v.name())) | ||
| .map(v -> (String) v.value()) | ||
| .map(SymbolMetadata.AnnotationValue::value) |
There was a problem hiding this comment.
Could we move this fix and its regression tests into a small separate PR? Unresolved annotation values can already fail bean-name and qualifier lookup under ECJ, and this PR doesn't wire SemSitter into production yet. The fix looks useful on its own.
| modifiers.addAll(other.modifiers); | ||
| } | ||
|
|
||
| void addModifiers(Collection<String> values) { |
There was a problem hiding this comment.
Could addModifiers() take one modifier per entry and just call modifiers.addAll(values)? MemberFactory already uses SemaFacts.flat() to split comma-separated wire values, and the other callers already pass individual modifiers.
| } | ||
| } | ||
|
|
||
| Set<String> referencedTypeNames() { |
There was a problem hiding this comment.
Nit: Could referencedTypeNames() be private? loadTypes() is the only production caller. The test can capture the names passed to the loader instead of calling the helper directly.
| markUndeclared(); | ||
| } | ||
|
|
||
| void ingestTypes(JsonObject types) { |
There was a problem hiding this comment.
Nit: Could ingestTypes() be private? The tests can provide type answers through loadTypes() rather than call the internal merge directly. That keeps the model's loading API easier to understand.
| this.typeParameter = typeParameter; | ||
| } | ||
|
|
||
| private List<TypeTree> boundTrees = List.of(); |
There was a problem hiding this comment.
Nit: Could we move boundTrees up with the other fields?




Part 4 of 17 of JAVA-7392. Ticket: JAVA-7396.
Intent
JSemais the SemSitter semantic model: theTypeandSymbolAPI the checks already use, built from what the server sends instead of from ECJ bindings. Nothing translates documents yet, so nothing uses it outside tests.An unresolved name in an annotation has no value, as with ECJ. A separate commit makes
SpringUtilsread bean and qualifier names only fromStringvalues: an unresolved constant (@Component(TASK_TYPE_DECISION)in netflix-conductor) used to throw aNullPointerExceptionwith ECJ too, and failed the whole analysis.Inference, overload ranking and annotation metadata are stubs here (declared types, first candidate,
Symbols.EMPTY_METADATA). Later PRs replace each stub, so each one can be reviewed against its own tests.State on master
Nothing creates a
JSema. ECJ parses exactly as today.Test plan
replay/types.json.gzSpringUtilsTest: unresolved bean and qualifier names fall back to the default name, failing with aNullPointerExceptionbefore the fix