@Test(expected = CompilerException.class) public void testResolveTargetMethodSignatureGenericWithUnresolvedDirectTypeVariable() throws Exception { SootMethod target = toSootClass(F.class).getMethodByName("run"); SootMethod m = toSootClass(Runners.class).getMethodByName("runner8"); SootMethodType mType = new SootMethodType(m); ObjCBlockPlugin.resolveTargetMethodSignature(m, target, mType.getGenericParameterTypes()[0]); }
protected static Type[] resolveTargetMethodSignature(SootMethod blockMethod, SootMethod targetMethod, Type blockParamType) { if (targetMethod.getTag("SignatureTag") == null) { Type[] result = new Type[targetMethod.getParameterCount() + 1]; result[0] = new SootTypeType(targetMethod.getReturnType()); for (int i = 1; i < result.length; i++) { result[i] = new SootTypeType(targetMethod.getParameterType(i - 1)); } return result; } SootClassType base = new SootClassType(targetMethod.getDeclaringClass()); TypeVariable<?>[] typeParameters = base.getTypeParameters(); SootClassType offspring = null; Type[] actualArgs = null; if (blockParamType instanceof SootClassType) { offspring = (SootClassType) blockParamType; actualArgs = new Type[0]; } else if (blockParamType instanceof ParameterizedType) { offspring = (SootClassType) ((ParameterizedType) blockParamType).getRawType(); actualArgs = ((ParameterizedType) blockParamType).getActualTypeArguments(); } Type[] resolvedArgs = resolveActualTypeArgs(offspring, base, actualArgs); Type[] result = new Type[targetMethod.getParameterCount() + 1]; SootMethodType targetMethodType = new SootMethodType(targetMethod); result[0] = resolveMethodType(blockMethod, -1, targetMethodType.getGenericReturnType(), resolvedArgs, typeParameters); Type[] genericParameterTypes = targetMethodType.getGenericParameterTypes(); for (int i = 1; i < result.length; i++) { result[i] = resolveMethodType(blockMethod, i - 1, genericParameterTypes[i - 1], resolvedArgs, typeParameters); } return result; }
ObjCBlockPlugin extends AbstractCompilerPlugin { protected static Type[] resolveTargetMethodSignature(SootMethod blockMethod, SootMethod targetMethod, Type blockParamType) { if (targetMethod.getTag("SignatureTag") == null) { Type[] result = new Type[targetMethod.getParameterCount() + 1]; result[0] = new SootTypeType(targetMethod.getReturnType()); for (int i = 1; i < result.length; i++) { result[i] = new SootTypeType(targetMethod.getParameterType(i - 1)); } return result; } SootClassType base = new SootClassType(targetMethod.getDeclaringClass()); TypeVariable<?>[] typeParameters = base.getTypeParameters(); SootClassType offspring = null; Type[] actualArgs = null; if (blockParamType instanceof SootClassType) { offspring = (SootClassType) blockParamType; actualArgs = new Type[0]; } else if (blockParamType instanceof ParameterizedType) { offspring = (SootClassType) ((ParameterizedType) blockParamType).getRawType(); actualArgs = ((ParameterizedType) blockParamType).getActualTypeArguments(); } Type[] resolvedArgs = resolveActualTypeArgs(offspring, base, actualArgs); Type[] result = new Type[targetMethod.getParameterCount() + 1]; SootMethodType targetMethodType = new SootMethodType(targetMethod); result[0] = resolveMethodType(blockMethod, -1, targetMethodType.getGenericReturnType(), resolvedArgs, typeParameters); Type[] genericParameterTypes = targetMethodType.getGenericParameterTypes(); for (int i = 1; i < result.length; i++) { result[i] = resolveMethodType(blockMethod, i - 1, genericParameterTypes[i - 1], resolvedArgs, typeParameters); } return result; } }
ObjCBlockPlugin extends AbstractCompilerPlugin { protected static Type[] resolveTargetMethodSignature(SootMethod blockMethod, SootMethod targetMethod, Type blockParamType) { if (targetMethod.getTag("SignatureTag") == null) { Type[] result = new Type[targetMethod.getParameterCount() + 1]; result[0] = new SootTypeType(targetMethod.getReturnType()); for (int i = 1; i < result.length; i++) { result[i] = new SootTypeType(targetMethod.getParameterType(i - 1)); } return result; } SootClassType base = new SootClassType(targetMethod.getDeclaringClass()); TypeVariable<?>[] typeParameters = base.getTypeParameters(); SootClassType offspring = null; Type[] actualArgs = null; if (blockParamType instanceof SootClassType) { offspring = (SootClassType) blockParamType; actualArgs = new Type[0]; } else if (blockParamType instanceof ParameterizedType) { offspring = (SootClassType) ((ParameterizedType) blockParamType).getRawType(); actualArgs = ((ParameterizedType) blockParamType).getActualTypeArguments(); } Type[] resolvedArgs = resolveActualTypeArgs(offspring, base, actualArgs); Type[] result = new Type[targetMethod.getParameterCount() + 1]; SootMethodType targetMethodType = new SootMethodType(targetMethod); result[0] = resolveMethodType(blockMethod, -1, targetMethodType.getGenericReturnType(), resolvedArgs, typeParameters); Type[] genericParameterTypes = targetMethodType.getGenericParameterTypes(); for (int i = 1; i < result.length; i++) { result[i] = resolveMethodType(blockMethod, i - 1, genericParameterTypes[i - 1], resolvedArgs, typeParameters); } return result; }  }
ObjCBlockPlugin extends AbstractCompilerPlugin { protected static Type[] resolveTargetMethodSignature(SootMethod blockMethod, SootMethod targetMethod, Type blockParamType) { if (targetMethod.getTag("SignatureTag") == null) { Type[] result = new Type[targetMethod.getParameterCount() + 1]; result[0] = new SootTypeType(targetMethod.getReturnType()); for (int i = 1; i < result.length; i++) { result[i] = new SootTypeType(targetMethod.getParameterType(i - 1)); } return result; } SootClassType base = new SootClassType(targetMethod.getDeclaringClass()); TypeVariable<?>[] typeParameters = base.getTypeParameters(); SootClassType offspring = null; Type[] actualArgs = null; if (blockParamType instanceof SootClassType) { offspring = (SootClassType) blockParamType; actualArgs = new Type[0]; } else if (blockParamType instanceof ParameterizedType) { offspring = (SootClassType) ((ParameterizedType) blockParamType).getRawType(); actualArgs = ((ParameterizedType) blockParamType).getActualTypeArguments(); } Type[] resolvedArgs = resolveActualTypeArgs(offspring, base, actualArgs); Type[] result = new Type[targetMethod.getParameterCount() + 1]; SootMethodType targetMethodType = new SootMethodType(targetMethod); result[0] = resolveMethodType(blockMethod, -1, targetMethodType.getGenericReturnType(), resolvedArgs, typeParameters); Type[] genericParameterTypes = targetMethodType.getGenericParameterTypes(); for (int i = 1; i < result.length; i++) { result[i] = resolveMethodType(blockMethod, i - 1, genericParameterTypes[i - 1], resolvedArgs, typeParameters); } return result; }  @Override void beforeClass(Config config, Clazz clazz, ModuleBuilder moduleBuilder); }
ObjCBlockPlugin extends AbstractCompilerPlugin { protected static Type[] resolveTargetMethodSignature(SootMethod blockMethod, SootMethod targetMethod, Type blockParamType) { if (targetMethod.getTag("SignatureTag") == null) { Type[] result = new Type[targetMethod.getParameterCount() + 1]; result[0] = new SootTypeType(targetMethod.getReturnType()); for (int i = 1; i < result.length; i++) { result[i] = new SootTypeType(targetMethod.getParameterType(i - 1)); } return result; } SootClassType base = new SootClassType(targetMethod.getDeclaringClass()); TypeVariable<?>[] typeParameters = base.getTypeParameters(); SootClassType offspring = null; Type[] actualArgs = null; if (blockParamType instanceof SootClassType) { offspring = (SootClassType) blockParamType; actualArgs = new Type[0]; } else if (blockParamType instanceof ParameterizedType) { offspring = (SootClassType) ((ParameterizedType) blockParamType).getRawType(); actualArgs = ((ParameterizedType) blockParamType).getActualTypeArguments(); } Type[] resolvedArgs = resolveActualTypeArgs(offspring, base, actualArgs); Type[] result = new Type[targetMethod.getParameterCount() + 1]; SootMethodType targetMethodType = new SootMethodType(targetMethod); result[0] = resolveMethodType(blockMethod, -1, targetMethodType.getGenericReturnType(), resolvedArgs, typeParameters); Type[] genericParameterTypes = targetMethodType.getGenericParameterTypes(); for (int i = 1; i < result.length; i++) { result[i] = resolveMethodType(blockMethod, i - 1, genericParameterTypes[i - 1], resolvedArgs, typeParameters); } return result; }  @Override void beforeClass(Config config, Clazz clazz, ModuleBuilder moduleBuilder); static final String OBJC_PACKAGE; static final String OBJC_ANNOTATIONS_PACKAGE; static final String BLOCK; static final String RUNNABLE_AS_OBJC_BLOCK_MARSHALER; }