如何将匿名 类 重新集成到 ECD 反编译器生成的 Java 代码中?
How to reintegrate anonymous classes into Java code produced by the ECD decompiler?
我有一个学校用的 jar,应该被反编译、修改和重新评估。我使用 Eclipse 的 ECD 插件反编译了所有 class 文件,但我想我有一些匿名的 class 被提取出来,需要合并回另一个 class。我有一个 class P,然后还有五个 classes 名为 P$1、P$2、...、P$5。
这是 P 的问题部分:
public class P {
private ArrayList<Family> group;
private int marker;
private Integer primaryElement;
Comparator<Family> c;
public P(ArrayList<Family> g, Integer i, Comparator<Family> c) {
this.marker = -1;
this.group = new ArrayList(g);
this.primaryElement = i;
this.c = c;
}
/* Some unrelated methods */
public String printHeader() {
return this.print(new 1(this));
}
public String printRow(Integer i) {
return this.print(new 2(this, i));
}
public String printPad() {
return this.print(new 3(this));
}
public Object printCost() {
return this.print(new 4(this));
}
public String printLine() {
return this.print(new 5(this));
}
这里是 P$1。其他的都差不多。
final class P implements PrintCommand {
P(P arg0) {
this.this[=13=] = arg0;
}
public String print(Family f) {
return String.format("%3d", new Object[]{Integer.valueOf(f.getId())});
}
}
如果您想知道,PrintCommand 是一个超级简单的界面:
public interface PrintCommand {
String print(Family arg0);
}
如何将 P$1 合并回 P?另外,this.this$0 在 P$1 中是什么意思?
在匿名 class 中,您可以使用 P.this
从封闭的 class 引用 this
。为此,java 编译器将创建一个构造函数,它将一个名为 this[=13=]
的字段设置为传递给构造函数的引用。
原始代码大概是这样的:
public String printHeader() {
return this.print(new PrintCommand() {
public String print(Family f) {
return String.format(%3d", f.getId());
}
);
}
编译器还会做其他事情,例如从封闭的 class 中为私有 methods/fields 添加访问器方法,这些访问器方法可以在内部 class 中访问。或将内部 class 中使用的(有效)最终变量的值传递给构造函数。
从Java Runtime的角度来看,没有匿名内部class,只有命名为classes.
我有一个学校用的 jar,应该被反编译、修改和重新评估。我使用 Eclipse 的 ECD 插件反编译了所有 class 文件,但我想我有一些匿名的 class 被提取出来,需要合并回另一个 class。我有一个 class P,然后还有五个 classes 名为 P$1、P$2、...、P$5。
这是 P 的问题部分:
public class P {
private ArrayList<Family> group;
private int marker;
private Integer primaryElement;
Comparator<Family> c;
public P(ArrayList<Family> g, Integer i, Comparator<Family> c) {
this.marker = -1;
this.group = new ArrayList(g);
this.primaryElement = i;
this.c = c;
}
/* Some unrelated methods */
public String printHeader() {
return this.print(new 1(this));
}
public String printRow(Integer i) {
return this.print(new 2(this, i));
}
public String printPad() {
return this.print(new 3(this));
}
public Object printCost() {
return this.print(new 4(this));
}
public String printLine() {
return this.print(new 5(this));
}
这里是 P$1。其他的都差不多。
final class P implements PrintCommand {
P(P arg0) {
this.this[=13=] = arg0;
}
public String print(Family f) {
return String.format("%3d", new Object[]{Integer.valueOf(f.getId())});
}
}
如果您想知道,PrintCommand 是一个超级简单的界面:
public interface PrintCommand {
String print(Family arg0);
}
如何将 P$1 合并回 P?另外,this.this$0 在 P$1 中是什么意思?
在匿名 class 中,您可以使用 P.this
从封闭的 class 引用 this
。为此,java 编译器将创建一个构造函数,它将一个名为 this[=13=]
的字段设置为传递给构造函数的引用。
原始代码大概是这样的:
public String printHeader() {
return this.print(new PrintCommand() {
public String print(Family f) {
return String.format(%3d", f.getId());
}
);
}
编译器还会做其他事情,例如从封闭的 class 中为私有 methods/fields 添加访问器方法,这些访问器方法可以在内部 class 中访问。或将内部 class 中使用的(有效)最终变量的值传递给构造函数。
从Java Runtime的角度来看,没有匿名内部class,只有命名为classes.