use of soot.tagkit.AnnotationTag in project robovm by robovm.
the class ObjCMemberPlugin method transformMethod.
private void transformMethod(Config config, Clazz clazz, SootClass sootClass, SootMethod method, Set<String> selectors, Set<String> overridables, boolean extensions) {
AnnotationTag annotation = getAnnotation(method, METHOD);
if (annotation != null) {
if (extensions && !(method.isStatic() && method.isNative())) {
throw new CompilerException("Objective-C @Method method " + method + " in extension class must be static and native.");
}
transformObjCMethod(annotation, sootClass, method, selectors, overridables, extensions);
return;
}
annotation = getAnnotation(method, IBACTION);
if (annotation != null) {
if (method.isStatic() || method.isNative()) {
throw new CompilerException("Objective-C @IBAction method " + method + " must not be static or native.");
}
int paramCount = method.getParameterCount();
Type param1 = paramCount > 0 ? method.getParameterType(0) : null;
Type param2 = paramCount > 1 ? method.getParameterType(1) : null;
if (method.getReturnType() != VoidType.v() || paramCount > 2 || (param1 != null && (!isNSObject(param1) && !isNSObject(param1))) || (param2 != null && (!isUIEvent(param2) || isNSObject(param1)))) {
throw new CompilerException("Objective-C @IBAction method " + method + " does not have a supported signature. @IBAction methods" + " must return void and either take no arguments, 1 argument of type NSObject" + ", or 2 arguments of types NSObject and UIEvent.");
}
transformObjCMethod(annotation, sootClass, method, selectors, overridables, extensions);
return;
}
annotation = getAnnotation(method, PROPERTY);
if (annotation != null) {
if (extensions && !(method.isStatic() && method.isNative())) {
throw new CompilerException("Objective-C @Property method " + method + " in extension class must be static and native.");
}
transformObjCProperty(annotation, "@Property", sootClass, method, selectors, overridables, extensions);
return;
}
annotation = getAnnotation(method, IBOUTLET);
if (annotation != null) {
if (method.isStatic()) {
throw new CompilerException("Objective-C @IBOutlet method " + method + " must not be static.");
}
transformObjCProperty(annotation, "@IBOutlet", sootClass, method, selectors, overridables, extensions);
return;
}
annotation = getAnnotation(method, IBOUTLETCOLLECTION);
if (annotation != null) {
if (method.isStatic()) {
throw new CompilerException("Objective-C @IBOutletCollection method " + method + " must not be static.");
}
if (method.getReturnType() != VoidType.v() && !isNSArray(method.getReturnType()) || method.getReturnType() == VoidType.v() && method.getParameterCount() == 1 && !isNSArray(method.getParameterType(0))) {
throw new CompilerException("Objective-C @IBOutletCollection method " + method + " does not have a supported signature. " + "@IBOutletCollection getter methods must return NSArray. " + "@IBOutletCollection setter methods must have 1 parameter of type NSArray.");
}
transformObjCProperty(annotation, "@IBOutletCollection", sootClass, method, selectors, overridables, extensions);
return;
}
if (!method.isStatic() && !method.isNative() && !method.isAbstract() && !method.isPrivate() && isCustomClass(sootClass) && !hasAnnotation(method, NOT_IMPLEMENTED)) {
/*
* Create a @Callback for this method if it overrides a
* @Method/@Property method in a superclass/interface.
*/
List<SootMethod> superMethods = findOverriddenMethods(sootClass, method);
for (SootMethod superMethod : superMethods) {
if (createCustomClassCallbackIfNeeded(sootClass, method, superMethod)) {
break;
}
}
}
}
use of soot.tagkit.AnnotationTag in project robovm by robovm.
the class AnnotationsTest method join.
private String join(List<AnnotationTag> annotations) {
StringBuilder sb = new StringBuilder();
List<String> l = new ArrayList<>();
for (AnnotationTag tag : annotations) {
String type = tag.getType();
type = type.substring(type.lastIndexOf('$') + 1, type.length() - 1);
l.add(type);
}
Collections.sort(l);
for (String type : l) {
if (sb.length() > 0) {
sb.append(" ");
}
sb.append("@" + type);
}
return sb.toString();
}
use of soot.tagkit.AnnotationTag in project robovm by robovm.
the class Annotations method addRuntimeVisibleParameterAnnotation.
public static void addRuntimeVisibleParameterAnnotation(SootMethod method, int paramIndex, String annotationType) {
if (!hasParameterAnnotation(method, paramIndex, annotationType)) {
VisibilityAnnotationTag tag = getOrCreateRuntimeVisibilityAnnotationTag(method, paramIndex);
tag.addAnnotation(new AnnotationTag(annotationType, 0));
}
}
use of soot.tagkit.AnnotationTag in project robovm by robovm.
the class Annotations method getParameterAnnotations.
public static List<AnnotationTag>[] getParameterAnnotations(SootMethod method, Visibility visibility) {
@SuppressWarnings("unchecked") ArrayList<AnnotationTag>[] result = new ArrayList[method.getParameterCount()];
for (int i = 0; i < result.length; i++) {
result[i] = new ArrayList<>();
}
for (Tag tag : method.getTags()) {
if (tag instanceof VisibilityParameterAnnotationTag) {
if (visibility == Visibility.Any || ((VisibilityParameterAnnotationTag) tag).getKind() == visibility.ordinal()) {
ArrayList<VisibilityAnnotationTag> l = ((VisibilityParameterAnnotationTag) tag).getVisibilityAnnotations();
if (l != null) {
int i = 0;
for (VisibilityAnnotationTag t : l) {
ArrayList<AnnotationTag> annotations = t.getAnnotations();
if (annotations != null) {
result[i].addAll(annotations);
}
i++;
}
}
}
}
}
return result;
}
use of soot.tagkit.AnnotationTag in project robovm by robovm.
the class Annotations method addRuntimeVisibleAnnotation.
public static void addRuntimeVisibleAnnotation(Host host, String annotationType) {
if (!hasAnnotation(host, annotationType)) {
VisibilityAnnotationTag tag = getOrCreateRuntimeVisibilityAnnotationTag(host);
tag.addAnnotation(new AnnotationTag(annotationType, 0));
}
}
Aggregations