redhat-developer / redhat-developer/vscode-java
Inline Method leaves unqualified instance method call inside local class when inlining into static context
Nessuno ha ancora preso questa issue.
- Lingua principale
- TypeScript
- Stelle
- 2.3k
- Fork
- 546
- Merge medio
- 20h 1m
- PR unite (30g)
- 11
Descrizione
Description
Inline Method produces uncompilable code when inlining an instance method that contains a local class into the static method main.
Before refactoring, the local class H is declared inside the instance method f(). The call helper() inside H.g() is valid because it is implicitly bound to the enclosing I01 instance.
After applying Inline Method to the invocation obj.f(), the local class H is moved into the static method main. However, the call inside H.g() remains:
return helper();
At this point, there is no implicit I01.this available in the static context. The call should be qualified with the original receiver, for example:
return obj.helper();
The refactored code no longer compiles.
Code before refactoring
public class I01 {
public static void main(String[] args) {
I01 obj = new I01();
// Refactoring operation: Inline Method
// Target invocation: obj.f()
int result = obj.f();
System.out.println(result);
}
int helper() {
return 7;
}
int f() {
class H {
int g() {
return helper();
}
}
return H.class.getSimpleName().length();
}
}
Code after refactoring
public class I01 {
public static void main(String[] args) {
I01 obj = new I01();
class H {
int g() {
return helper();
}
}
// Refactoring operation: Inline Method
// Target invocation: obj.f()
int result = H.class.getSimpleName().length();
System.out.println(result);
}
int helper() {
return 7;
}
int f() {
class H {
int g() {
return helper();
}
}
return H.class.getSimpleName().length();
}
}
Guida per i contributori
Apri 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.
Direzione di ricerca
Inizia con l’implementazione di Inline Method e riproduci il problema usando l’esempio I01, concentrandoti sulle classi locali spostate in contesti statici di main. Traccia come viene gestito il ricevitore dell’obj.f() originale all’interno di H.g(); il lavoro è completato quando la chiamata generata a helper() è qualificata con il ricevitore e il codice Java sottoposto a refactoring viene compilato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 48/100