use of org.robovm.compiler.util.generic.SootMethodType in project robovm by robovm.
the class ObjCBlockPlugin method resolveTargetMethodSignature.
protected static Type[] resolveTargetMethodSignature(SootMethod blockMethod, SootMethod targetMethod, Type blockParamType) {
if (targetMethod.getTag("SignatureTag") == null) {
// Not a generic method.
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;
}
use of org.robovm.compiler.util.generic.SootMethodType in project robovm by robovm.
the class ObjCBlockPlugin method transformMethod.
private void transformMethod(Config config, Clazz clazz, SootMethod blockMethod, int[] blockParamIndexes, Map<String, Integer> blockTypeIds) throws IOException {
SootMethodType blockMethodType = new SootMethodType(blockMethod);
if (blockParamIndexes != null) {
Type[] genericParameterTypes = blockMethodType.getGenericParameterTypes();
for (int i = 0; i < blockParamIndexes.length; i++) {
int idx = blockParamIndexes[i];
if (idx == -1) {
break;
}
SootMethod targetMethod = getBlockTargetMethod(blockMethod, idx);
Type[] actualGenericTypes = resolveTargetMethodSignature(blockMethod, targetMethod, genericParameterTypes[idx]);
soot.Type[] actualRawTypes = toRawTypes(actualGenericTypes);
soot.Type[] unboxedTypes = unboxTypes(actualRawTypes);
String[][] targetMethodAnnotations = parseTargetMethodAnnotations(targetMethod, readStringElem(getParameterAnnotation(blockMethod, idx, BLOCK), "value", ""));
// Create the marshaler class associated with this block type
String marshaler = createBlockMarshaler(config, clazz, targetMethod, actualGenericTypes, actualRawTypes, unboxedTypes, blockTypeIds, targetMethodAnnotations);
addMarshalerAnnotation(blockMethod, idx, marshaler);
}
}
if (hasAnnotation(blockMethod, BLOCK)) {
SootMethod targetMethod = getBlockTargetMethod(blockMethod);
Type[] actualGenericTypes = resolveTargetMethodSignature(blockMethod, targetMethod, blockMethodType.getGenericReturnType());
soot.Type[] actualRawTypes = toRawTypes(actualGenericTypes);
soot.Type[] unboxedTypes = unboxTypes(actualRawTypes);
String[][] targetMethodAnnotations = parseTargetMethodAnnotations(targetMethod, readStringElem(getAnnotation(blockMethod, BLOCK), "value", ""));
String marshaler = createBlockMarshaler(config, clazz, targetMethod, actualGenericTypes, actualRawTypes, unboxedTypes, blockTypeIds, targetMethodAnnotations);
addMarshalerAnnotation(blockMethod, marshaler);
}
}
use of org.robovm.compiler.util.generic.SootMethodType in project robovm by robovm.
the class ObjCBlockPluginTest method testResolveTargetMethodSignatureGenericWithUnresolvedDirectTypeVariable.
@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]);
}
use of org.robovm.compiler.util.generic.SootMethodType in project robovm by robovm.
the class ObjCMemberPlugin method createGenericSignatureForMsgSend.
private void createGenericSignatureForMsgSend(SootMethod annotatedMethod, SootMethod m, List<Type> paramTypes, boolean extensions) {
SignatureTag tag = (SignatureTag) annotatedMethod.getTag(SignatureTag.class.getSimpleName());
if (tag != null) {
SootMethodType type = new SootMethodType(annotatedMethod);
List<String> genericParameterTypes = new ArrayList<>();
for (org.robovm.compiler.util.generic.Type t : type.getGenericParameterTypes()) {
genericParameterTypes.add(t.toGenericSignature());
}
if (!extensions) {
/*
* For non extensions the generic signature is missing the
* receiver as parameter 1.
*/
genericParameterTypes.add(0, Types.getDescriptor(paramTypes.get(0)));
}
/*
* Always insert the selector as parameter 2 of the generic
* signature.
*/
genericParameterTypes.add(1, Types.getDescriptor(paramTypes.get(1)));
StringBuilder sb = new StringBuilder("(");
sb.append(StringUtils.join(genericParameterTypes, ""));
sb.append(")");
sb.append(type.getGenericReturnType().toGenericSignature());
m.addTag(new SignatureTag(sb.toString()));
}
}
use of org.robovm.compiler.util.generic.SootMethodType in project robovm by robovm.
the class ObjCBlockPluginTest method signatureToType.
private Type signatureToType(String desc) {
String rawDesc = desc.replaceAll("<.*>", "");
String internalName = rawDesc.replaceAll("^\\[*", "");
int dims = rawDesc.length() - internalName.length();
internalName = Types.getInternalNameFromDescriptor(internalName);
soot.Type sootType = SootResolver.v().makeClassRef(internalName.replace('/', '.')).getType();
for (int i = 0; i < dims; i++) {
sootType = sootType.makeArrayType();
}
SootMethod m = new SootMethod("foo", Arrays.asList(sootType), VoidType.v());
m.addTag(new SignatureTag("(" + desc + ")V"));
SootMethodType mType = new SootMethodType(m);
return mType.getGenericParameterTypes()[0];
}
Aggregations