Search in sources :

Example 11 with AnnotationTag

use of soot.tagkit.AnnotationTag in project robovm by robovm.

the class ObjCMemberPlugin method createCustomClassCallbackIfNeeded.

private boolean createCustomClassCallbackIfNeeded(SootClass sootClass, SootMethod method, SootMethod superMethod) {
    AnnotationTag annotation = getAnnotation(superMethod, METHOD);
    if (annotation != null) {
        createCallback(sootClass, method, superMethod, getObjCMethodSelectorName(annotation, superMethod, false), getReceiverType(sootClass));
        return true;
    } else {
        annotation = getAnnotation(superMethod, PROPERTY);
        if (annotation != null) {
            boolean isGetter = method.getReturnType() != VoidType.v();
            createCallback(sootClass, method, superMethod, getObjCPropertySelectorName(annotation, superMethod, isGetter), getReceiverType(sootClass));
            return true;
        }
    }
    return false;
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag)

Example 12 with AnnotationTag

use of soot.tagkit.AnnotationTag in project robovm by robovm.

the class ObjCMemberPlugin method findStrongRefGetter.

private SootMethod findStrongRefGetter(SootClass sootClass, final SootMethod method, boolean extensions) {
    AnnotationTag annotation = getAnnotation(method, PROPERTY);
    if (annotation == null) {
        annotation = getAnnotation(method, IBOUTLET);
    }
    if (annotation == null) {
        annotation = getAnnotation(method, IBOUTLETCOLLECTION);
    }
    String setterPropName = readStringElem(annotation, "name", "").trim();
    if (setterPropName.length() == 0) {
        String methodName = method.getName();
        if (!methodName.startsWith("set") || methodName.length() == 3) {
            throw new CompilerException("Failed to determine the property " + "name from the @Property method " + method + ". Either specify the name explicitly in the @Property " + "annotation or rename the method according to the Java " + "beans property setter method naming convention.");
        }
        setterPropName = methodName.substring(3);
        setterPropName = setterPropName.substring(0, 1).toLowerCase() + setterPropName.substring(1);
    }
    int paramCount = extensions ? 1 : 0;
    Type propType = method.getParameterType(extensions ? 1 : 0);
    for (SootMethod m : sootClass.getMethods()) {
        if (m != method && method.isStatic() == m.isStatic() && m.getParameterCount() == paramCount && m.getReturnType().equals(propType)) {
            AnnotationTag propertyAnno = getAnnotation(m, PROPERTY);
            if (propertyAnno != null) {
                String getterPropName = readStringElem(propertyAnno, "name", "").trim();
                if (getterPropName.length() == 0) {
                    String methodName = m.getName();
                    if (!methodName.startsWith("get") || methodName.length() == 3) {
                        // style getter
                        continue;
                    }
                    getterPropName = methodName.substring(3);
                    getterPropName = getterPropName.substring(0, 1).toLowerCase() + getterPropName.substring(1);
                }
                if (setterPropName.equals(getterPropName)) {
                    return m;
                }
            }
        }
    }
    throw new CompilerException("Failed to determine the getter method " + "corresponding to the strong ref @Property setter method " + method + ". The getter must either specify the name explicitly in the @Property " + "annotation or be named according to the Java " + "beans property getter method naming convention.");
}
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 13 with AnnotationTag

use of soot.tagkit.AnnotationTag in project robovm by robovm.

the class MarshalerLookup method findMarshalersOn.

private List<Marshaler> findMarshalersOn(SootClass sc, Set<String> visited, Set<String> seen) {
    String internalName = getInternalName(sc);
    if (visited.contains(internalName)) {
        return Collections.emptyList();
    }
    visited.contains(internalName);
    List<Marshaler> all = cache.get(sc.getName());
    if (all == null) {
        all = new ArrayList<>();
        for (AnnotationTag tag : getMarshalerAnnotations(sc)) {
            AnnotationClassElem elem = (AnnotationClassElem) getElemByName(tag, "value");
            String name = getInternalNameFromDescriptor(elem.getDesc());
            Clazz marshalerClazz = config.getClazzes().load(name);
            if (marshalerClazz != null) {
                all.add(new Marshaler(marshalerClazz));
            }
        }
        cache.put(sc.getName(), all);
    }
    List<Marshaler> result = new ArrayList<>();
    for (Marshaler m : all) {
        String name = m.clazz.getInternalName();
        if (!seen.contains(name)) {
            seen.add(name);
            result.add(m);
        }
    }
    return result;
}
Also used : AnnotationTag(soot.tagkit.AnnotationTag) AnnotationClassElem(soot.tagkit.AnnotationClassElem) ArrayList(java.util.ArrayList) Clazz(org.robovm.compiler.clazz.Clazz)

Example 14 with AnnotationTag

use of soot.tagkit.AnnotationTag in project robovm by robovm.

the class ObjCMemberPlugin method addNotImplementedAnnotation.

static void addNotImplementedAnnotation(SootMethod method, String selectorName) {
    AnnotationTag annotationTag = new AnnotationTag(NOT_IMPLEMENTED, 1);
    annotationTag.addElem(new AnnotationStringElem(selectorName, 's', "value"));
    addRuntimeVisibleAnnotation(method, annotationTag);
}
Also used : AnnotationStringElem(soot.tagkit.AnnotationStringElem) AnnotationTag(soot.tagkit.AnnotationTag)

Example 15 with AnnotationTag

use of soot.tagkit.AnnotationTag in project robovm by robovm.

the class ObjCMemberPlugin method addBindSelectorAnnotation.

static void addBindSelectorAnnotation(SootMethod method, String selectorName) {
    AnnotationTag annotationTag = new AnnotationTag(BIND_SELECTOR, 1);
    annotationTag.addElem(new AnnotationStringElem(selectorName, 's', "value"));
    addRuntimeVisibleAnnotation(method, annotationTag);
}
Also used : AnnotationStringElem(soot.tagkit.AnnotationStringElem) AnnotationTag(soot.tagkit.AnnotationTag)

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