mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-18 17:38:17 +00:00
option(const) to disable get/set decompilation and use __get__ and __set__
This commit is contained in:
@@ -548,19 +548,21 @@ public class ActionScript2ClassDetector {
|
||||
FunctionActionItem func = (FunctionActionItem) trait.getValue();
|
||||
func.isSetter = true;
|
||||
|
||||
//There is return getter added at the end of every setter, gotta remove it, since it won't compile
|
||||
//as setter must not return a value
|
||||
if (!func.actions.isEmpty()) {
|
||||
int pos = func.actions.size() - 1;
|
||||
if (func.actions.get(pos) instanceof ScriptEndItem) {
|
||||
pos--;
|
||||
}
|
||||
if (pos >= 0 && func.actions.get(pos) instanceof ReturnActionItem) {
|
||||
GraphTargetItem val = func.actions.get(pos);
|
||||
if (val.value instanceof CallMethodActionItem) {
|
||||
if (((CallMethodActionItem) val.value).methodName instanceof DirectValueActionItem) {
|
||||
if (((CallMethodActionItem) val.value).methodName.toString().startsWith("__get__")) {
|
||||
func.actions.remove(pos);
|
||||
if (FunctionActionItem.DECOMPILE_GET_SET) {
|
||||
//There is return getter added at the end of every setter, gotta remove it, since it won't compile
|
||||
//as setter must not return a value
|
||||
if (!func.actions.isEmpty()) {
|
||||
int pos = func.actions.size() - 1;
|
||||
if (func.actions.get(pos) instanceof ScriptEndItem) {
|
||||
pos--;
|
||||
}
|
||||
if (pos >= 0 && func.actions.get(pos) instanceof ReturnActionItem) {
|
||||
GraphTargetItem val = func.actions.get(pos);
|
||||
if (val.value instanceof CallMethodActionItem) {
|
||||
if (((CallMethodActionItem) val.value).methodName instanceof DirectValueActionItem) {
|
||||
if (((CallMethodActionItem) val.value).methodName.toString().startsWith("__get__")) {
|
||||
func.actions.remove(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,8 @@ import java.util.Set;
|
||||
*/
|
||||
public class FunctionActionItem extends ActionItem implements BranchStackResistant {
|
||||
|
||||
public static final boolean DECOMPILE_GET_SET = true;
|
||||
|
||||
public boolean isGetter = false;
|
||||
|
||||
public boolean isSetter = false;
|
||||
@@ -100,7 +102,6 @@ public class FunctionActionItem extends ActionItem implements BranchStackResista
|
||||
variables.add(variable);
|
||||
}
|
||||
|
||||
|
||||
public FunctionActionItem() {
|
||||
super(null, null, PRECEDENCE_PRIMARY);
|
||||
}
|
||||
@@ -129,20 +130,24 @@ public class FunctionActionItem extends ActionItem implements BranchStackResista
|
||||
}
|
||||
|
||||
writer.append("function");
|
||||
if (isGetter) {
|
||||
writer.append(" get");
|
||||
}
|
||||
if (isSetter) {
|
||||
writer.append(" set");
|
||||
if (DECOMPILE_GET_SET) {
|
||||
if (isGetter) {
|
||||
writer.append(" get");
|
||||
}
|
||||
if (isSetter) {
|
||||
writer.append(" set");
|
||||
}
|
||||
}
|
||||
if (calculatedFunctionName != null) {
|
||||
writer.append(" ");
|
||||
String fname = calculatedFunctionName.toStringNoQuotes(localData);
|
||||
if (isGetter && fname.startsWith("__get__")) {
|
||||
fname = fname.substring(7);
|
||||
}
|
||||
if (isSetter && fname.startsWith("__set__")) {
|
||||
fname = fname.substring(7);
|
||||
if (DECOMPILE_GET_SET) {
|
||||
if (isGetter && fname.startsWith("__get__")) {
|
||||
fname = fname.substring(7);
|
||||
}
|
||||
if (isSetter && fname.startsWith("__set__")) {
|
||||
fname = fname.substring(7);
|
||||
}
|
||||
}
|
||||
|
||||
if (!IdentifiersDeobfuscation.isValidName(false, fname)) {
|
||||
@@ -153,11 +158,13 @@ public class FunctionActionItem extends ActionItem implements BranchStackResista
|
||||
}
|
||||
} else if (!functionName.isEmpty()) {
|
||||
String fname = functionName;
|
||||
if (isGetter && fname.startsWith("__get__")) {
|
||||
fname = fname.substring(7);
|
||||
}
|
||||
if (isSetter && fname.startsWith("__set__")) {
|
||||
fname = fname.substring(7);
|
||||
if (DECOMPILE_GET_SET) {
|
||||
if (isGetter && fname.startsWith("__get__")) {
|
||||
fname = fname.substring(7);
|
||||
}
|
||||
if (isSetter && fname.startsWith("__set__")) {
|
||||
fname = fname.substring(7);
|
||||
}
|
||||
}
|
||||
writer.append(" ");
|
||||
if (!IdentifiersDeobfuscation.isValidName(false, fname)) {
|
||||
|
||||
@@ -724,7 +724,6 @@ public class ActionSourceGenerator implements SourceGenerator {
|
||||
Set<String> staticSetters = new HashSet<>();
|
||||
Set<String> staticGetters = new HashSet<>();
|
||||
|
||||
|
||||
if (!isInterface) {
|
||||
for (int pass = 1; pass <= 2; pass++) { //two passes, methods first, then variables
|
||||
for (int t = 0; t < traits.size(); t++) {
|
||||
@@ -738,12 +737,25 @@ public class ActionSourceGenerator implements SourceGenerator {
|
||||
if (fi.isGetter || fi.isSetter) {
|
||||
(traitsStatic.get(t) ? staticProperties : properties).add(fi.calculatedFunctionName.toString());
|
||||
}
|
||||
|
||||
if (!FunctionActionItem.DECOMPILE_GET_SET) {
|
||||
if (fi.calculatedFunctionName.toString().startsWith("__get__") || fi.calculatedFunctionName.toString().startsWith("__set__")) {
|
||||
(traitsStatic.get(t) ? staticProperties : properties).add(fi.calculatedFunctionName.toString().substring(7));
|
||||
}
|
||||
if (fi.calculatedFunctionName.toString().startsWith("__get__")) {
|
||||
(traitsStatic.get(t) ? staticGetters : getters).add(fi.calculatedFunctionName.toString().substring(7));
|
||||
}
|
||||
if (fi.calculatedFunctionName.toString().startsWith("__set__")) {
|
||||
(traitsStatic.get(t) ? staticSetters : setters).add(fi.calculatedFunctionName.toString().substring(7));
|
||||
}
|
||||
}
|
||||
|
||||
String prefix = "";
|
||||
if (fi.isGetter) {
|
||||
if (fi.isGetter) { //really has "get" keyword
|
||||
(traitsStatic.get(t) ? staticGetters : getters).add(fi.calculatedFunctionName.toString());
|
||||
prefix = "__get__";
|
||||
}
|
||||
if (fi.isSetter) {
|
||||
if (fi.isSetter) { //really has "set" keyword
|
||||
(traitsStatic.get(t) ? staticSetters : setters).add(fi.calculatedFunctionName.toString());
|
||||
prefix = "__set__";
|
||||
}
|
||||
@@ -795,7 +807,6 @@ public class ActionSourceGenerator implements SourceGenerator {
|
||||
ifbody.add(new ActionCallMethod());
|
||||
}
|
||||
|
||||
|
||||
if (!isInterface) {
|
||||
ifbody.add(new ActionPush((Long) 1L));
|
||||
ifbody.add(new ActionPush(Null.INSTANCE));
|
||||
|
||||
Reference in New Issue
Block a user