use of soot.tagkit.AnnotationArrayElem in project soot by Sable.
the class DexAnnotation method handleMethodAnnotation.
/**
* Converts method and method parameters annotations from Dexlib to Jimple
*
* @param h
* @param method
*/
public void handleMethodAnnotation(Host h, Method method) {
Set<? extends Annotation> aSet = method.getAnnotations();
if (!(aSet == null || aSet.isEmpty())) {
List<Tag> tags = handleAnnotation(aSet, null);
if (tags != null)
for (Tag t : tags) if (t != null) {
h.addTag(t);
}
}
String[] parameterNames = null;
int i = 0;
for (MethodParameter p : method.getParameters()) {
String name = p.getName();
if (name != null) {
parameterNames = new String[method.getParameters().size()];
parameterNames[i] = name;
}
i++;
}
if (parameterNames != null) {
h.addTag(new ParamNamesTag(parameterNames));
}
// Is there any parameter annotation?
boolean doParam = false;
List<? extends MethodParameter> parameters = method.getParameters();
for (MethodParameter p : parameters) {
if (p.getAnnotations().size() > 0) {
doParam = true;
break;
}
}
if (doParam) {
VisibilityParameterAnnotationTag tag = new VisibilityParameterAnnotationTag(parameters.size(), AnnotationConstants.RUNTIME_VISIBLE);
for (MethodParameter p : parameters) {
List<Tag> tags = handleAnnotation(p.getAnnotations(), null);
// so that we keep the order intact.
if (tags == null) {
tag.addVisibilityAnnotation(null);
continue;
}
VisibilityAnnotationTag paramVat = new VisibilityAnnotationTag(AnnotationConstants.RUNTIME_VISIBLE);
tag.addVisibilityAnnotation(paramVat);
for (Tag t : tags) {
if (t == null)
continue;
AnnotationTag vat = null;
if (!(t instanceof VisibilityAnnotationTag)) {
if (t instanceof DeprecatedTag) {
vat = new AnnotationTag("Ljava/lang/Deprecated;");
} else if (t instanceof SignatureTag) {
SignatureTag sig = (SignatureTag) t;
ArrayList<AnnotationElem> sigElements = new ArrayList<AnnotationElem>();
for (String s : SootToDexUtils.splitSignature(sig.getSignature())) sigElements.add(new AnnotationStringElem(s, 's', "value"));
AnnotationElem elem = new AnnotationArrayElem(sigElements, '[', "value");
vat = new AnnotationTag("Ldalvik/annotation/Signature;", Collections.singleton(elem));
} else {
throw new RuntimeException("error: unhandled tag for parameter annotation in method " + h + " (" + t + ").");
}
} else {
vat = ((VisibilityAnnotationTag) t).getAnnotations().get(0);
}
paramVat.addAnnotation(vat);
}
}
if (tag.getVisibilityAnnotations().size() > 0)
h.addTag(tag);
}
}
use of soot.tagkit.AnnotationArrayElem in project soot by Sable.
the class DexAnnotation method getSootType.
private Type getSootType(AnnotationElem e) {
Type annotationType;
switch(e.getKind()) {
case // array
'[':
// Until now we only know it's some kind of array.
annotationType = ARRAY_TYPE;
AnnotationArrayElem array = (AnnotationArrayElem) e;
if (array.getNumValues() > 0) {
// Try to determine type of the array
AnnotationElem firstElement = array.getValueAt(0);
Type type = getSootType(firstElement);
if (type == null)
return null;
if (type.equals(ARRAY_TYPE))
return ARRAY_TYPE;
return ArrayType.v(type, 1);
}
break;
case // string
's':
annotationType = RefType.v("java.lang.String");
break;
case // class
'c':
annotationType = RefType.v("java.lang.Class");
break;
case // enum
'e':
AnnotationEnumElem enumElem = (AnnotationEnumElem) e;
annotationType = Util.getType(enumElem.getTypeName());
;
break;
case 'L':
case 'J':
case 'S':
case 'D':
case 'I':
case 'F':
case 'B':
case 'C':
case 'V':
case 'Z':
annotationType = Util.getType(String.valueOf(e.getKind()));
break;
default:
annotationType = null;
break;
}
return annotationType;
}
Aggregations