use of soot.tagkit.AnnotationArrayElem in project robovm by robovm.
the class MarshalerLookup method getSupportedCallTypes.
private Set<Long> getSupportedCallTypes(AnnotationTag anno) {
AnnotationArrayElem el = (AnnotationArrayElem) getElemByName(anno, "supportedCallTypes");
if (el == null) {
return new HashSet<Long>(Arrays.asList(Bro.MarshalerFlags.CALL_TYPE_BRIDGE, Bro.MarshalerFlags.CALL_TYPE_CALLBACK, Bro.MarshalerFlags.CALL_TYPE_STRUCT_MEMBER, Bro.MarshalerFlags.CALL_TYPE_GLOBAL_VALUE, Bro.MarshalerFlags.CALL_TYPE_PTR));
}
ArrayList<AnnotationElem> values = ((AnnotationArrayElem) el).getValues();
Set<Long> callTypes = new HashSet<>();
for (AnnotationElem value : values) {
callTypes.add(((AnnotationLongElem) value).getValue());
}
return callTypes;
}
use of soot.tagkit.AnnotationArrayElem 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.AnnotationArrayElem in project soot by Sable.
the class AnnotationElemBuilder method visitArray.
@Override
public AnnotationVisitor visitArray(final String name) {
return new AnnotationElemBuilder() {
@Override
public void visitEnd() {
String ename = name;
if (ename == null)
ename = "default";
AnnotationElemBuilder.this.elems.add(new AnnotationArrayElem(this.elems, '[', ename));
}
};
}
use of soot.tagkit.AnnotationArrayElem in project soot by Sable.
the class AnnotationElemBuilder method getAnnotationElement.
public AnnotationElem getAnnotationElement(String name, Object value) {
AnnotationElem elem;
if (value instanceof Byte) {
elem = new AnnotationIntElem((Byte) value, 'B', name);
} else if (value instanceof Boolean) {
elem = new AnnotationIntElem(((Boolean) value) ? 1 : 0, 'Z', name);
} else if (value instanceof Character) {
elem = new AnnotationIntElem((Character) value, 'C', name);
} else if (value instanceof Short) {
elem = new AnnotationIntElem((Short) value, 'S', name);
} else if (value instanceof Integer) {
elem = new AnnotationIntElem((Integer) value, 'I', name);
} else if (value instanceof Long) {
elem = new AnnotationLongElem((Long) value, 'J', name);
} else if (value instanceof Float) {
elem = new AnnotationFloatElem((Float) value, 'F', name);
} else if (value instanceof Double) {
elem = new AnnotationDoubleElem((Double) value, 'D', name);
} else if (value instanceof String) {
elem = new AnnotationStringElem(value.toString(), 's', name);
} else if (value instanceof Type) {
Type t = (Type) value;
elem = new AnnotationClassElem(t.getDescriptor(), 'c', name);
} else if (value.getClass().isArray()) {
ArrayList<AnnotationElem> annotationArray = new ArrayList<AnnotationElem>();
if (value instanceof byte[]) {
for (Object element : (byte[]) value) annotationArray.add(getAnnotationElement(name, element));
} else if (value instanceof boolean[]) {
for (Object element : (boolean[]) value) annotationArray.add(getAnnotationElement(name, element));
} else if (value instanceof char[]) {
for (Object element : (char[]) value) annotationArray.add(getAnnotationElement(name, element));
} else if (value instanceof short[]) {
for (Object element : (short[]) value) annotationArray.add(getAnnotationElement(name, element));
} else if (value instanceof int[]) {
for (Object element : (int[]) value) annotationArray.add(getAnnotationElement(name, element));
} else if (value instanceof long[]) {
for (Object element : (long[]) value) annotationArray.add(getAnnotationElement(name, element));
} else if (value instanceof float[]) {
for (Object element : (float[]) value) annotationArray.add(getAnnotationElement(name, element));
} else if (value instanceof double[]) {
for (Object element : (double[]) value) annotationArray.add(getAnnotationElement(name, element));
} else if (value instanceof String[]) {
for (Object element : (String[]) value) annotationArray.add(getAnnotationElement(name, element));
} else if (value instanceof Type[]) {
for (Object element : (Type[]) value) annotationArray.add(getAnnotationElement(name, element));
} else
throw new UnsupportedOperationException("Unsupported array value type: " + value.getClass());
elem = new AnnotationArrayElem(annotationArray, '[', name);
} else
throw new UnsupportedOperationException("Unsupported value type: " + value.getClass());
return (elem);
}
use of soot.tagkit.AnnotationArrayElem in project soot by Sable.
the class DexAnnotation method handleAnnotationElement.
private ArrayList<AnnotationElem> handleAnnotationElement(AnnotationElement ae, List<? extends EncodedValue> evList) {
ArrayList<AnnotationElem> aelemList = new ArrayList<AnnotationElem>();
for (EncodedValue ev : evList) {
int type = ev.getValueType();
AnnotationElem elem = null;
switch(type) {
case // BYTE
0x00:
{
ByteEncodedValue v = (ByteEncodedValue) ev;
elem = new AnnotationIntElem(v.getValue(), 'B', ae.getName());
break;
}
case // SHORT
0x02:
{
ShortEncodedValue v = (ShortEncodedValue) ev;
elem = new AnnotationIntElem(v.getValue(), 'S', ae.getName());
break;
}
case // CHAR
0x03:
{
CharEncodedValue v = (CharEncodedValue) ev;
elem = new AnnotationIntElem(v.getValue(), 'C', ae.getName());
break;
}
case // INT
0x04:
{
IntEncodedValue v = (IntEncodedValue) ev;
elem = new AnnotationIntElem(v.getValue(), 'I', ae.getName());
break;
}
case // LONG
0x06:
{
LongEncodedValue v = (LongEncodedValue) ev;
elem = new AnnotationLongElem(v.getValue(), 'J', ae.getName());
break;
}
case // FLOAT
0x10:
{
FloatEncodedValue v = (FloatEncodedValue) ev;
elem = new AnnotationFloatElem(v.getValue(), 'F', ae.getName());
break;
}
case // DOUBLE
0x11:
{
DoubleEncodedValue v = (DoubleEncodedValue) ev;
elem = new AnnotationDoubleElem(v.getValue(), 'D', ae.getName());
break;
}
case // STRING
0x17:
{
StringEncodedValue v = (StringEncodedValue) ev;
elem = new AnnotationStringElem(v.getValue(), 's', ae.getName());
break;
}
case // TYPE
0x18:
{
TypeEncodedValue v = (TypeEncodedValue) ev;
elem = new AnnotationClassElem(v.getValue(), 'c', ae.getName());
break;
}
case // FIELD (Dalvik specific?)
0x19:
{
FieldEncodedValue v = (FieldEncodedValue) ev;
FieldReference fr = v.getValue();
String fieldSig = "";
fieldSig += DexType.toSootAT(fr.getDefiningClass()) + ": ";
fieldSig += DexType.toSootAT(fr.getType()) + " ";
fieldSig += fr.getName();
elem = new AnnotationStringElem(fieldSig, 'f', ae.getName());
break;
}
case // METHOD (Dalvik specific?)
0x1a:
{
MethodEncodedValue v = (MethodEncodedValue) ev;
MethodReference mr = v.getValue();
String className = DexType.toSootICAT(mr.getDefiningClass());
String returnType = DexType.toSootAT(mr.getReturnType());
String methodName = mr.getName();
String parameters = "";
for (CharSequence p : mr.getParameterTypes()) {
parameters += DexType.toSootAT(p.toString());
}
String mSig = className + " |" + methodName + " |" + parameters + " |" + returnType;
elem = new AnnotationStringElem(mSig, 'M', ae.getName());
break;
}
case // ENUM : Warning -> encoding Dalvik specific!
0x1b:
{
EnumEncodedValue v = (EnumEncodedValue) ev;
FieldReference fr = v.getValue();
elem = new AnnotationEnumElem(DexType.toSootAT(fr.getType()).toString(), fr.getName(), 'e', ae.getName());
break;
}
case // ARRAY
0x1c:
{
ArrayEncodedValue v = (ArrayEncodedValue) ev;
ArrayList<AnnotationElem> l = handleAnnotationElement(ae, v.getValue());
if (l != null)
elem = new AnnotationArrayElem(l, '[', ae.getName());
break;
}
case // ANNOTATION
0x1d:
{
AnnotationEncodedValue v = (AnnotationEncodedValue) ev;
AnnotationTag t = new AnnotationTag(DexType.toSootAT(v.getType()).toString());
for (AnnotationElement newElem : v.getElements()) {
List<EncodedValue> l = new ArrayList<EncodedValue>();
l.add(newElem.getValue());
List<AnnotationElem> aList = handleAnnotationElement(newElem, l);
if (aList != null)
for (AnnotationElem e : aList) t.addElem(e);
}
elem = new AnnotationAnnotationElem(t, '@', ae.getName());
break;
}
case // NULL (Dalvik specific?)
0x1e:
{
elem = new AnnotationStringElem(null, 'N', ae.getName());
break;
}
case // BOOLEAN
0x1f:
{
BooleanEncodedValue v = (BooleanEncodedValue) ev;
elem = new AnnotationBooleanElem(v.getValue(), 'Z', ae.getName());
break;
}
default:
{
throw new RuntimeException("Unknown annotation element 0x" + Integer.toHexString(type));
}
}
if (elem != null)
aelemList.add(elem);
}
return aelemList;
}
Aggregations