redhat-developer / redhat-developer/vscode-java
Inline Method leaves unqualified instance method call inside local class when inlining into static context
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 2.3k
- Forks
- 546
- Ø Merge
- 20 Std. 1 Min.
- Gemergte PRs (30 T.)
- 11
Beschreibung
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();
}
}
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der Implementierung von Inline Method und reproduziere das Problem anhand des Beispiels I01. Konzentriere dich dabei auf lokale Klassen, die in statische main-Kontexte verschoben wurden. Verfolge, wie der Empfänger des ursprünglichen obj.f() innerhalb von H.g() behandelt wird; abgeschlossen ist die Aufgabe, wenn der generierte Aufruf helper() mit dem Empfänger qualifiziert ist und der refaktorisierte Java-Code kompiliert.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 48/100