use of jadx.core.dex.visitors.typeinference.TypeCompareEnum in project jadx by skylot.
the class OverrideMethodVisitor method updateArgType.
private ArgType updateArgType(MethodNode mth, IMethodDetails baseMth, SuperTypesData superData, int argNum) {
ArgType arg = mth.getArgTypes().get(argNum);
ArgType baseArg = baseMth.getArgTypes().get(argNum);
if (arg.equals(baseArg)) {
return null;
}
if (!baseArg.containsTypeVariable()) {
return null;
}
TypeCompare typeCompare = mth.root().getTypeUpdate().getTypeCompare();
ArgType baseCls = baseMth.getMethodInfo().getDeclClass().getType();
for (ArgType superType : superData.getSuperTypes()) {
TypeCompareEnum compareResult = typeCompare.compareTypes(superType, baseCls);
if (compareResult == TypeCompareEnum.NARROW_BY_GENERIC) {
ArgType targetArgType = mth.root().getTypeUtils().replaceClassGenerics(superType, baseArg);
if (targetArgType != null && !targetArgType.containsTypeVariable() && !targetArgType.equals(arg)) {
return targetArgType;
}
}
}
return null;
}
use of jadx.core.dex.visitors.typeinference.TypeCompareEnum in project jadx by skylot.
the class AttachTryCatchVisitor method checkAndFilterHandlers.
private static void checkAndFilterHandlers(MethodNode mth, List<ExceptionHandler> list) {
if (list.size() <= 1) {
return;
}
// Remove shadowed handlers (with same or narrow type compared to previous)
TypeCompare typeCompare = mth.root().getTypeCompare();
Iterator<ExceptionHandler> it = list.iterator();
ArgType maxType = null;
while (it.hasNext()) {
ExceptionHandler handler = it.next();
ArgType maxCatch = maxCatchFromHandler(handler, typeCompare);
if (maxType == null) {
maxType = maxCatch;
} else {
TypeCompareEnum result = typeCompare.compareObjects(maxType, maxCatch);
if (result.isWiderOrEqual()) {
if (Consts.DEBUG_EXC_HANDLERS) {
LOG.debug("Removed shadowed catch handler: {}, from list: {}", handler, list);
}
it.remove();
}
}
}
}
use of jadx.core.dex.visitors.typeinference.TypeCompareEnum in project jadx by skylot.
the class ProcessVariables method checkCodeVars.
private void checkCodeVars(MethodNode mth, List<CodeVar> codeVars) {
int unknownTypesCount = 0;
for (CodeVar codeVar : codeVars) {
ArgType codeVarType = codeVar.getType();
if (codeVarType == null) {
codeVar.setType(ArgType.UNKNOWN);
unknownTypesCount++;
} else {
codeVar.getSsaVars().forEach(ssaVar -> {
ArgType ssaType = ssaVar.getImmutableType();
if (ssaType != null && ssaType.isTypeKnown()) {
TypeCompare comparator = mth.root().getTypeUpdate().getTypeCompare();
TypeCompareEnum result = comparator.compareTypes(ssaType, codeVarType);
if (result == TypeCompareEnum.CONFLICT || result.isNarrow()) {
mth.addWarn("Incorrect type for immutable var: ssa=" + ssaType + ", code=" + codeVarType + ", for " + ssaVar.getDetailedVarInfo(mth));
}
}
});
}
}
if (unknownTypesCount != 0) {
mth.addWarn("Unknown variable types count: " + unknownTypesCount);
}
}
Aggregations