use of jadx.core.dex.nodes.utils.TypeUtils in project jadx by skylot.
the class MethodInvokeVisitor method getTypeVarsMapping.
private Map<ArgType, ArgType> getTypeVarsMapping(BaseInvokeNode invokeInsn) {
MethodInfo callMthInfo = invokeInsn.getCallMth();
ArgType declClsType = callMthInfo.getDeclClass().getType();
ArgType callClsType = getClsCallType(invokeInsn, declClsType);
TypeUtils typeUtils = root.getTypeUtils();
Map<ArgType, ArgType> clsTypeVars = typeUtils.getTypeVariablesMapping(callClsType);
Map<ArgType, ArgType> mthTypeVars = typeUtils.getTypeVarMappingForInvoke(invokeInsn);
return Utils.mergeMaps(clsTypeVars, mthTypeVars);
}
use of jadx.core.dex.nodes.utils.TypeUtils in project jadx by skylot.
the class TypeUpdate method invokeListener.
private TypeUpdateResult invokeListener(TypeUpdateInfo updateInfo, InsnNode insn, InsnArg arg, ArgType candidateType) {
BaseInvokeNode invoke = (BaseInvokeNode) insn;
if (isAssign(invoke, arg)) {
// TODO: implement backward type propagation (from result to instance)
return SAME;
}
if (invoke.getInstanceArg() == arg) {
IMethodDetails methodDetails = root.getMethodUtils().getMethodDetails(invoke);
if (methodDetails == null) {
return SAME;
}
TypeUtils typeUtils = root.getTypeUtils();
Set<ArgType> knownTypeVars = typeUtils.getKnownTypeVarsAtMethod(updateInfo.getMth());
Map<ArgType, ArgType> typeVarsMap = typeUtils.getTypeVariablesMapping(candidateType);
ArgType returnType = methodDetails.getReturnType();
List<ArgType> argTypes = methodDetails.getArgTypes();
int argsCount = argTypes.size();
if (typeVarsMap.isEmpty()) {
// generics can't be resolved => use as is
return applyInvokeTypes(updateInfo, invoke, argsCount, knownTypeVars, () -> returnType, argTypes::get);
}
// resolve types before apply
return applyInvokeTypes(updateInfo, invoke, argsCount, knownTypeVars, () -> typeUtils.replaceTypeVariablesUsingMap(returnType, typeVarsMap), argNum -> typeUtils.replaceClassGenerics(candidateType, argTypes.get(argNum)));
}
return SAME;
}
use of jadx.core.dex.nodes.utils.TypeUtils in project jadx by skylot.
the class MethodNode method initArguments.
private void initArguments(List<ArgType> args) {
int pos = getArgsStartPos(args);
TypeUtils typeUtils = root().getTypeUtils();
if (accFlags.isStatic()) {
thisArg = null;
} else {
ArgType thisClsType = typeUtils.expandTypeVariables(this, parentClass.getType());
RegisterArg arg = InsnArg.reg(pos++, thisClsType);
arg.add(AFlag.THIS);
arg.add(AFlag.IMMUTABLE_TYPE);
thisArg = arg;
}
if (args.isEmpty()) {
argsList = Collections.emptyList();
return;
}
argsList = new ArrayList<>(args.size());
for (ArgType argType : args) {
ArgType expandedType = typeUtils.expandTypeVariables(this, argType);
RegisterArg regArg = InsnArg.reg(pos, expandedType);
regArg.add(AFlag.METHOD_ARGUMENT);
regArg.add(AFlag.IMMUTABLE_TYPE);
argsList.add(regArg);
pos += argType.getRegCount();
}
}
use of jadx.core.dex.nodes.utils.TypeUtils in project jadx by skylot.
the class SignatureProcessor method parseMethodSignature.
private void parseMethodSignature(MethodNode mth) {
SignatureParser sp = SignatureParser.fromNode(mth);
if (sp == null) {
return;
}
try {
List<ArgType> typeParameters = sp.consumeGenericTypeParameters();
List<ArgType> parsedArgTypes = sp.consumeMethodArgs(mth.getMethodInfo().getArgsCount());
ArgType parsedRetType = sp.consumeType();
if (!validateInnerType(parsedRetType) || !validateInnerType(parsedArgTypes)) {
mth.addWarnComment("Incorrect inner types in method signature: " + sp.getSignature());
return;
}
// apply before expand args
mth.updateTypeParameters(typeParameters);
TypeUtils typeUtils = root.getTypeUtils();
ArgType retType = typeUtils.expandTypeVariables(mth, parsedRetType);
List<ArgType> argTypes = Utils.collectionMap(parsedArgTypes, t -> typeUtils.expandTypeVariables(mth, t));
if (!validateAndApplyTypes(mth, sp, retType, argTypes)) {
// bad types -> reset typed parameters
mth.updateTypeParameters(Collections.emptyList());
}
} catch (Exception e) {
mth.addWarnComment("Failed to parse method signature: " + sp.getSignature(), e);
}
}
use of jadx.core.dex.nodes.utils.TypeUtils in project jadx by skylot.
the class ClassNode method visitSuperTypes.
public void visitSuperTypes(BiConsumer<ArgType, ArgType> consumer) {
TypeUtils typeUtils = root.getTypeUtils();
ArgType thisType = this.getType();
if (!superClass.equals(ArgType.OBJECT)) {
consumer.accept(thisType, superClass);
typeUtils.visitSuperTypes(superClass, consumer);
}
for (ArgType iface : interfaces) {
consumer.accept(thisType, iface);
typeUtils.visitSuperTypes(iface, consumer);
}
}
Aggregations