Search in sources :

Example 16 with AnnotationTag

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;
            }
        }
    }
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) RefType(soot.RefType) BooleanType(soot.BooleanType) SootMethodType(org.robovm.compiler.util.generic.SootMethodType) Type(soot.Type) DoubleType(soot.DoubleType) FloatType(soot.FloatType) LongType(soot.LongType) RefLikeType(soot.RefLikeType) PrimType(soot.PrimType) VoidType(soot.VoidType) CompilerException(org.robovm.compiler.CompilerException) SootMethod(soot.SootMethod)

Example 17 with AnnotationTag

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();
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) ArrayList(java.util.ArrayList)

Example 18 with AnnotationTag

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));
    }
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag)

Example 19 with AnnotationTag

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;
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) ArrayList(java.util.ArrayList) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) Tag(soot.tagkit.Tag) AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag)

Example 20 with AnnotationTag

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));
    }
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) VisibilityParameterAnnotationTag(soot.tagkit.VisibilityParameterAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag) VisibilityAnnotationTag(soot.tagkit.VisibilityAnnotationTag)

Aggregations

AnnotationTag (soot.tagkit.AnnotationTag)21 ArrayList (java.util.ArrayList)7 VisibilityAnnotationTag (soot.tagkit.VisibilityAnnotationTag)7 VisibilityParameterAnnotationTag (soot.tagkit.VisibilityParameterAnnotationTag)7 Tag (soot.tagkit.Tag)4 Type (org.robovm.compiler.llvm.Type)3 Value (org.robovm.compiler.llvm.Value)3 VoidType (soot.VoidType)3 AnnotationClassElem (soot.tagkit.AnnotationClassElem)3 CompilerException (org.robovm.compiler.CompilerException)2 Clazz (org.robovm.compiler.clazz.Clazz)2 Br (org.robovm.compiler.llvm.Br)2 Function (org.robovm.compiler.llvm.Function)2 Global (org.robovm.compiler.llvm.Global)2 Icmp (org.robovm.compiler.llvm.Icmp)2 IntegerConstant (org.robovm.compiler.llvm.IntegerConstant)2 Label (org.robovm.compiler.llvm.Label)2 Load (org.robovm.compiler.llvm.Load)2 NullConstant (org.robovm.compiler.llvm.NullConstant)2 PointerType (org.robovm.compiler.llvm.PointerType)2