Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

TypeInfo: a way to reach the anonymous and local classes declared in a type's bodies

Chiusa
#126 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

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

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

enhancement
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 a recursiveSubTypeStreamIncludingLocal() (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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di CodeLaser/maddi

Tutte le issue di CodeLaser/maddi

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.