TypeInfo: a way to reach the anonymous and local classes declared in a type's bodies
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 49/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- java
- Ambito
- developer-experience, tooling
Direzione di ricerca
Start by tracing how ParseConstructorCall and ParseTypeDeclaration create TypeInfo for anonymous and local classes, then inspect TypeInfo.subTypes() and recursiveSubTypeStream(). The issue proposes storing those classes in declaration order or exposing a body-walking stream; choose an approach that preserves subTypes() as member types only. Done when callers can discover nested anonymous and local classes recursively, including the example loop, without each writing its own body walk.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What is missing
TypeInfo.subTypes() returns the member types, and recursiveSubTypeStream() is built on it. Anonymous classes (new T() { … }) and local classes (declared in a method body) are not in either: ParseConstructorCall and ParseTypeDeclaration give them a TypeInfo with an enclosing type and a stable index (getAndIncrementAnonymousTypes), but nothing adds them to the enclosing type, so the only way to find them is to visit every method body and field initializer for ConstructorCall.anonymousClass() and LocalTypeDeclaration.typeInfo(), recursively.
Every tool that wants "all the code in this compilation unit" (a search over methods, a rewrite of loop bodies, a census of calls) rediscovers this the hard way: a loop inside
return new HttpResponse() {
@Override
public void generateResponse(StaplerRequest2 req, StaplerResponse2 rsp, Object node) {
for (Map.Entry<String, String> header : headers.entrySet()) {
rsp.setHeader(header.getKey(), header.getValue());
}
}
};
is simply never seen when the tool walks primary.recursiveSubTypeStream().flatMap(TypeInfo::constructorAndMethodStream). In a large code base (Jenkins core) this hid a few percent of the sites of one rewrite.
Proposal
Either of:
TypeInfo.localTypes(): the anonymous and local classes whose enclosing type this is, in declaration order, filled by the parser at the two places that mint them; and arecursiveSubTypeStreamIncludingLocal()(or a boolean parameter) that descends into them as it does into member types; or- a documented
TypeInfo.anonymousAndLocalTypeStream()that performs the body walk once, in the API, so that callers do not each write it.
The first is cheaper for callers and keeps subTypes() as it is (member types only), which some callers surely depend on.
Workaround used
A helper that walks constructorAndMethodStream() bodies and field initializers with Element.visit, collecting ConstructorCall.anonymousClass() and LocalTypeDeclaration.typeInfo() into a queue, deduplicated by identity, until the queue is empty.
Seen on 0.9.5-alpha.13.
- Lingua principale
- Java
- Stelle
- 1
- Fork
- 1
- Merge medio
- 1h 58m
- PR unite (30g)
- 5
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di CodeLaser/maddi
-
build/ci good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
bug front-end:javac
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
C# printer: an inner class of a generic class needs the outer type's arguments (Outer<A>.Inner)Apertafront-end:csharp
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 10/100
-
Java → C# translation: an idiomatic C# printer driven by the modification and nullability analysesApertaenhancement extension front-end:csharp
Difficoltà 5/5 Più di una settimana Idoneità per principianti 8/100
Tutte le issue di CodeLaser/maddi
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
OpenIntegrationEngine/engine#496 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
SasanLabs/VulnerableApp#836 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement frontend
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
Albertinesilva/backend-engineering-journey-java-springboot#46 ·
-
Snyk: vulnerabilities in jackson-databind 2.21.5Forse già presa @harrywu23 l’ha presa oggi. Apertabug
Difficoltà 1/5 1-3 ore Idoneità per principianti 80/100
SOFTENG-310-Group-4/Project-A1-310-Group-4#115 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
carlos-emr/carlos#4833 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno