use of jadx.core.dex.attributes.nodes.GenericInfoAttr in project jadx by skylot.
the class GenericTypesVisitor method attachGenericTypesInfo.
private void attachGenericTypesInfo(MethodNode mth, ConstructorInsn insn) {
try {
RegisterArg resultArg = insn.getResult();
if (resultArg == null) {
return;
}
ArgType argType = resultArg.getSVar().getCodeVar().getType();
if (argType == null || argType.getGenericTypes() == null) {
return;
}
ClassNode cls = mth.root().resolveClass(insn.getClassType());
if (cls != null && cls.getGenericTypeParameters().isEmpty()) {
return;
}
insn.addAttr(new GenericInfoAttr(argType.getGenericTypes()));
} catch (Exception e) {
LOG.error("Failed to attach constructor generic info", e);
}
}
use of jadx.core.dex.attributes.nodes.GenericInfoAttr in project jadx by skylot.
the class InsnGen method makeConstructor.
private void makeConstructor(ConstructorInsn insn, ICodeWriter code) throws CodegenException {
ClassNode cls = mth.root().resolveClass(insn.getClassType());
if (cls != null && cls.isAnonymous() && !fallback) {
cls.ensureProcessed();
inlineAnonymousConstructor(code, cls, insn);
mth.getParentClass().addInlinedClass(cls);
return;
}
if (insn.isSelf()) {
throw new JadxRuntimeException("Constructor 'self' invoke must be removed!");
}
MethodNode callMth = mth.root().resolveMethod(insn.getCallMth());
if (insn.isSuper()) {
code.attachAnnotation(callMth);
code.add("super");
} else if (insn.isThis()) {
code.attachAnnotation(callMth);
code.add("this");
} else {
code.add("new ");
if (callMth == null || callMth.contains(AFlag.DONT_GENERATE)) {
// use class reference if constructor method is missing (default constructor)
code.attachAnnotation(mth.root().resolveClass(insn.getCallMth().getDeclClass()));
} else {
code.attachAnnotation(callMth);
}
mgen.getClassGen().addClsName(code, insn.getClassType());
GenericInfoAttr genericInfoAttr = insn.get(AType.GENERIC_INFO);
if (genericInfoAttr != null) {
code.add('<');
if (genericInfoAttr.isExplicit()) {
boolean first = true;
for (ArgType type : genericInfoAttr.getGenericTypes()) {
if (!first) {
code.add(',');
} else {
first = false;
}
mgen.getClassGen().useType(code, type);
}
}
code.add('>');
}
}
generateMethodArguments(code, insn, 0, callMth);
}
Aggregations