Search in sources :

Example 11 with CompilerException

use of org.robovm.compiler.CompilerException 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 12 with CompilerException

use of org.robovm.compiler.CompilerException in project robovm by robovm.

the class IOSTarget method doBuild.

@Override
protected void doBuild(File outFile, List<String> ccArgs, List<File> objectFiles, List<String> libArgs) throws IOException {
    // (#195)
    if (!config.getFrameworks().contains("UIKit")) {
        libArgs.add("-framework");
        libArgs.add("UIKit");
    }
    String minVersion = getMinimumOSVersion();
    int majorVersionNumber = -1;
    try {
        majorVersionNumber = Integer.parseInt(minVersion.substring(0, minVersion.indexOf('.')));
    } catch (NumberFormatException e) {
        throw new CompilerException("Failed to get major version number from " + "MinimumOSVersion string '" + minVersion + "'");
    }
    if (isDeviceArch(arch)) {
        ccArgs.add("-miphoneos-version-min=" + minVersion);
        if (config.isDebug()) {
            ccArgs.add("-Wl,-no_pie");
        }
    } else {
        ccArgs.add("-mios-simulator-version-min=" + minVersion);
        if (config.getArch() == Arch.x86 || config.isDebug()) {
            ccArgs.add("-Wl,-no_pie");
        }
    }
    if (majorVersionNumber >= 7) {
        // On iOS 7 and higher the linker will default to link against
        // libc++ which is needed for C++11 support. We need the older
        // libstdc++ as our native libs are compiled against it and need to
        // work on iOS 6. If an app needs C++11 support the user will need
        // to link against /usr/lib/libc++.dylib explicitly.
        ccArgs.add("-stdlib=libstdc++");
    }
    ccArgs.add("-isysroot");
    ccArgs.add(sdk.getRoot().getAbsolutePath());
    // specify dynamic library loading path
    libArgs.add("-Xlinker");
    libArgs.add("-rpath");
    libArgs.add("-Xlinker");
    libArgs.add("@executable_path/Frameworks");
    libArgs.add("-Xlinker");
    libArgs.add("-rpath");
    libArgs.add("-Xlinker");
    libArgs.add("@loader_path/Frameworks");
    super.doBuild(outFile, ccArgs, objectFiles, libArgs);
}
Also used : CompilerException(org.robovm.compiler.CompilerException) NSString(com.dd.plist.NSString)

Aggregations

CompilerException (org.robovm.compiler.CompilerException)12 RefType (soot.RefType)8 SootMethod (soot.SootMethod)6 DoubleType (soot.DoubleType)5 FloatType (soot.FloatType)5 LongType (soot.LongType)5 PrimType (soot.PrimType)5 Type (soot.Type)5 VoidType (soot.VoidType)5 SootMethodType (org.robovm.compiler.util.generic.SootMethodType)4 BooleanType (soot.BooleanType)4 NSString (com.dd.plist.NSString)3 File (java.io.File)3 SootClass (soot.SootClass)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 Body (soot.Body)2 Local (soot.Local)2 RefLikeType (soot.RefLikeType)2