refactor: use same instance for empty type vars annotation

This commit is contained in:
Skylot
2020-08-09 15:02:11 +01:00
parent 7fed5534eb
commit 593a32a689
2 changed files with 15 additions and 3 deletions
@@ -1,19 +1,30 @@
package jadx.core.dex.attributes.nodes;
import java.util.Collections;
import java.util.Set;
import jadx.core.dex.attributes.AType;
import jadx.core.dex.attributes.IAttribute;
import jadx.core.dex.instructions.args.ArgType;
import static jadx.core.utils.Utils.isEmpty;
/**
* Set of known type variables at current method
*/
public class MethodTypeVarsAttr implements IAttribute {
private static final MethodTypeVarsAttr EMPTY = new MethodTypeVarsAttr(Collections.emptySet());
public static MethodTypeVarsAttr build(Set<ArgType> typeVars) {
if (isEmpty(typeVars)) {
return EMPTY;
}
return new MethodTypeVarsAttr(typeVars);
}
private final Set<ArgType> typeVars;
public MethodTypeVarsAttr(Set<ArgType> typeVars) {
private MethodTypeVarsAttr(Set<ArgType> typeVars) {
this.typeVars = typeVars;
}
@@ -92,8 +92,9 @@ public class TypeUtils {
return typeVarsAttr.getTypeVars();
}
Set<ArgType> typeVars = collectKnownTypeVarsAtMethod(mth);
mth.addAttr(new MethodTypeVarsAttr(typeVars));
return typeVars;
MethodTypeVarsAttr varsAttr = MethodTypeVarsAttr.build(typeVars);
mth.addAttr(varsAttr);
return varsAttr.getTypeVars();
}
private static Set<ArgType> collectKnownTypeVarsAtMethod(MethodNode mth) {