use of soot.tagkit.AnnotationClassElem in project robovm by robovm.
the class MarshalerLookup method getBaseType.
private soot.Type getBaseType(SootMethod m, AnnotationTag anno) {
AnnotationClassElem el = (AnnotationClassElem) getElemByName(anno, "baseType");
if (el != null) {
switch(el.getDesc().charAt(0)) {
case 'Z':
return BooleanType.v();
case 'B':
return ByteType.v();
case 'S':
return ShortType.v();
case 'C':
return CharType.v();
case 'I':
return IntType.v();
case 'J':
return LongType.v();
case 'F':
return FloatType.v();
case 'D':
return DoubleType.v();
}
return null;
}
soot.Type t = m.getReturnType();
if (t == VoidType.v()) {
t = m.getParameterType(0);
}
if (t instanceof RefType) {
SootClass c = ((RefType) t).getSootClass();
if (isInstanceOfClass(c, "java.nio.ByteBuffer")) {
return ByteType.v();
} else if (isInstanceOfClass(c, "java.nio.ShortBuffer")) {
return ShortType.v();
} else if (isInstanceOfClass(c, "java.nio.CharBuffer")) {
return CharType.v();
} else if (isInstanceOfClass(c, "java.nio.IntBuffer")) {
return IntType.v();
} else if (isInstanceOfClass(c, "java.nio.LongBuffer")) {
return LongType.v();
} else if (isInstanceOfClass(c, "java.nio.FloatBuffer")) {
return FloatType.v();
} else if (isInstanceOfClass(c, "java.nio.DoubleBuffer")) {
return DoubleType.v();
} else if (isInstanceOfClass(c, "org.robovm.rt.bro.Struct")) {
return config.getClazzes().load("org/robovm/rt/bro/Struct").getSootClass().getType();
}
} else if (t instanceof ArrayType) {
ArrayType arrayType = (ArrayType) t;
if (arrayType.baseType instanceof PrimType || isInstanceOfClass(arrayType.baseType, "org.robovm.rt.bro.Struct")) {
return arrayType.baseType;
}
}
return null;
}
use of soot.tagkit.AnnotationClassElem in project robovm by robovm.
the class MarshalerLookup method findMarshalerMethod.
public MarshalerMethod findMarshalerMethod(MarshalSite marshalSite) {
int pidx = marshalSite.paramIdx;
if (pidx != MarshalSite.RECEIVER) {
// Use @Marshaler annotation on method or parameter at paramIndex if there is one
AnnotationTag anno = pidx == MarshalSite.RETURN_TYPE ? getMarshalerAnnotation(marshalSite.method) : getMarshalerAnnotation(marshalSite.method, pidx);
if (anno != null) {
AnnotationClassElem elem = (AnnotationClassElem) getElemByName(anno, "value");
String name = getInternalNameFromDescriptor(elem.getDesc());
Clazz marshalerClazz = config.getClazzes().load(name);
if (marshalerClazz != null) {
Marshaler marshaler = new Marshaler(marshalerClazz);
if (marshaler.canMarshal(marshalSite)) {
return marshaler.getMarshalerMethod(marshalSite);
}
}
throw new IllegalArgumentException(String.format("@Marshaler %s specified for %s of %s method %s can " + "not be used to marshal %s", name.replace('/', '.'), (pidx == MarshalSite.RETURN_TYPE ? "return type" : "parameter " + (pidx + 1)), marshalSite.callTypeName, marshalSite.method, marshalSite.type));
}
}
Marshaler marshaler = findMarshalers(marshalSite);
if (marshaler != null) {
return marshaler.getMarshalerMethod(marshalSite);
}
throw new IllegalArgumentException(String.format("No @Marshaler found for %s of %s method %s", (pidx == MarshalSite.RECEIVER ? "receiver" : (pidx == MarshalSite.RETURN_TYPE ? "return type" : "parameter " + (pidx + 1))), marshalSite.callTypeName, marshalSite.method));
}
use of soot.tagkit.AnnotationClassElem in project robovm by robovm.
the class AttributesEncoder method encodeAnnotationElementValue.
private PackedStructureConstant encodeAnnotationElementValue(AnnotationElem ae) {
PackedStructureType type = getAnnotationElementType(ae);
Value kind = new IntegerConstant((byte) ae.getKind());
if (ae instanceof AnnotationIntElem) {
AnnotationIntElem aie = (AnnotationIntElem) ae;
return new PackedStructureConstant(type, kind, new IntegerConstant(aie.getValue()));
} else if (ae instanceof AnnotationLongElem) {
AnnotationLongElem ale = (AnnotationLongElem) ae;
return new PackedStructureConstant(type, kind, new IntegerConstant(ale.getValue()));
} else if (ae instanceof AnnotationFloatElem) {
AnnotationFloatElem afe = (AnnotationFloatElem) ae;
return new PackedStructureConstant(type, kind, new FloatingPointConstant(afe.getValue()));
} else if (ae instanceof AnnotationDoubleElem) {
AnnotationDoubleElem ade = (AnnotationDoubleElem) ae;
return new PackedStructureConstant(type, kind, new FloatingPointConstant(ade.getValue()));
} else if (ae instanceof AnnotationStringElem) {
AnnotationStringElem ase = (AnnotationStringElem) ae;
return new PackedStructureConstant(type, kind, getStringOrNull(ase.getValue()));
} else if (ae instanceof AnnotationClassElem) {
AnnotationClassElem ace = (AnnotationClassElem) ae;
addDependencyIfNeeded(ace.getDesc());
return new PackedStructureConstant(type, kind, getStringOrNull(ace.getDesc()));
} else if (ae instanceof AnnotationEnumElem) {
AnnotationEnumElem aee = (AnnotationEnumElem) ae;
addDependencyIfNeeded(aee.getTypeName());
return new PackedStructureConstant(type, kind, getStringOrNull(aee.getTypeName()), getStringOrNull(aee.getConstantName()));
} else if (ae instanceof AnnotationArrayElem) {
AnnotationArrayElem aae = (AnnotationArrayElem) ae;
Value[] values = new Value[aae.getNumValues() + 2];
values[0] = kind;
values[1] = new IntegerConstant((char) aae.getNumValues());
for (int i = 0; i < aae.getNumValues(); i++) {
values[i + 2] = encodeAnnotationElementValue(aae.getValueAt(i));
}
return new PackedStructureConstant(type, values);
} else if (ae instanceof AnnotationAnnotationElem) {
AnnotationAnnotationElem aae = (AnnotationAnnotationElem) ae;
return new PackedStructureConstant(type, kind, encodeAnnotationTagValue(aae.getValue()));
}
throw new IllegalArgumentException("Unknown AnnotationElem type: " + ae.getClass());
}
use of soot.tagkit.AnnotationClassElem in project robovm by robovm.
the class ObjCBlockPlugin method addMarshalerAnnotation.
static void addMarshalerAnnotation(SootMethod method, String marshalerName) {
AnnotationTag annotationTag = new AnnotationTag(MARSHALER, 1);
annotationTag.addElem(new AnnotationClassElem("L" + marshalerName + ";", 'c', "value"));
addRuntimeVisibleAnnotation(method, annotationTag);
}
use of soot.tagkit.AnnotationClassElem in project robovm by robovm.
the class ObjCBlockPlugin method addMarshalerAnnotation.
static void addMarshalerAnnotation(SootMethod method, int paramIndex, String marshalerName) {
AnnotationTag annotationTag = new AnnotationTag(MARSHALER, 1);
annotationTag.addElem(new AnnotationClassElem("L" + marshalerName + ";", 'c', "value"));
addRuntimeVisibleParameterAnnotation(method, paramIndex, annotationTag);
}
Aggregations