use of org.robovm.compiler.CompilerException in project robovm by robovm.
the class ObjCBlockPlugin method parseAnnotations.
private static int parseAnnotations(SootMethod m, String originalValue, String value, TreeSet<String> values) {
Matcher matcher = BLOCK_ANNOTATION_PATTERN.matcher(value);
int pos = 0;
while (matcher.find()) {
if (matcher.start() != pos) {
break;
}
String anno = BLOCK_ANNOTATIONS.get(matcher.group().trim());
if (anno == null) {
throw new CompilerException("Unsupported annotation \"" + matcher.group().trim() + "\" in @Block annotation value \"" + originalValue + "\" on method " + m);
}
values.add(anno);
pos = matcher.end();
}
return pos;
}
use of org.robovm.compiler.CompilerException in project robovm by robovm.
the class IOSTarget method createInfoPList.
protected void createInfoPList(File dir) throws IOException {
NSDictionary dict = new NSDictionary();
if (config.getIosInfoPList() != null && config.getIosInfoPList().getDictionary() != null) {
NSDictionary infoPListDict = config.getIosInfoPList().getDictionary();
for (String key : infoPListDict.allKeys()) {
dict.put(key, infoPListDict.objectForKey(key));
}
} else {
dict.put("CFBundleVersion", "1.0");
dict.put("CFBundleExecutable", config.getExecutableName());
dict.put("CFBundleName", config.getExecutableName());
dict.put("CFBundleIdentifier", getBundleId());
dict.put("CFBundlePackageType", "APPL");
dict.put("LSRequiresIPhoneOS", true);
NSObject supportedDeviceFamilies = sdk.getDefaultProperty("SUPPORTED_DEVICE_FAMILIES");
if (supportedDeviceFamilies != null) {
// SUPPORTED_DEVICE_FAMILIES is either a NSString of comma
// separated numbers
// or an NSArray with NSStrings. UIDeviceFamily values should be
// NSNumbers.
NSArray families = null;
if (supportedDeviceFamilies instanceof NSString) {
NSString defFamilies = (NSString) supportedDeviceFamilies;
String[] parts = defFamilies.toString().split(",");
families = new NSArray(parts.length);
for (int i = 0; i < families.count(); i++) {
families.setValue(i, new NSNumber(parts[i].trim()));
}
} else {
NSArray defFamilies = (NSArray) supportedDeviceFamilies;
families = new NSArray(defFamilies.count());
for (int i = 0; i < families.count(); i++) {
families.setValue(i, new NSNumber(defFamilies.objectAtIndex(i).toString()));
}
}
dict.put("UIDeviceFamily", families);
}
dict.put("UISupportedInterfaceOrientations", new NSArray(new NSString("UIInterfaceOrientationPortrait"), new NSString("UIInterfaceOrientationLandscapeLeft"), new NSString("UIInterfaceOrientationLandscapeRight"), new NSString("UIInterfaceOrientationPortraitUpsideDown")));
dict.put("UISupportedInterfaceOrientations~ipad", new NSArray(new NSString("UIInterfaceOrientationPortrait"), new NSString("UIInterfaceOrientationLandscapeLeft"), new NSString("UIInterfaceOrientationLandscapeRight"), new NSString("UIInterfaceOrientationPortraitUpsideDown")));
dict.put("UIRequiredDeviceCapabilities", new NSArray(new NSString("armv7")));
}
dict.put("DTPlatformName", sdk.getPlatformName());
dict.put("DTSDKName", sdk.getCanonicalName());
for (File f : FileUtils.listFiles(partialPListDir, new String[] { "plist" }, false)) {
try {
NSDictionary d = (NSDictionary) PropertyListParser.parse(f);
dict.putAll(d);
} catch (Exception e) {
throw new CompilerException(e);
}
}
if (dict.objectForKey("MinimumOSVersion") == null) {
// This is required
dict.put("MinimumOSVersion", "6.0");
}
customizeInfoPList(dict);
/*
* Make sure CFBundleShortVersionString and CFBundleVersion are at the
* top of the Info.plist file to avoid the "Could not hardlink copy"
* problem when launching on the simulator. com.dd.plist maintains the
* insertion order of keys so we rebuild the dictionary here and make
* sure those two keys are inserted first. See #771.
*/
NSDictionary newDict = new NSDictionary();
if (dict.objectForKey("CFBundleShortVersionString") != null) {
newDict.put("CFBundleShortVersionString", dict.objectForKey("CFBundleShortVersionString"));
dict.remove("CFBundleShortVersionString");
}
if (dict.objectForKey("CFBundleVersion") != null) {
newDict.put("CFBundleVersion", dict.objectForKey("CFBundleVersion"));
dict.remove("CFBundleVersion");
}
for (String key : dict.allKeys()) {
newDict.put(key, dict.objectForKey(key));
}
File tmpInfoPlist = new File(config.getTmpDir(), "Info.plist");
PropertyListParser.saveAsBinary(newDict, tmpInfoPlist);
config.getLogger().info("Installing Info.plist to %s", dir);
FileUtils.copyFile(tmpInfoPlist, new File(dir, tmpInfoPlist.getName()));
}
use of org.robovm.compiler.CompilerException in project robovm by robovm.
the class LambdaClassGenerator method createForwardingMethod.
private void createForwardingMethod(SootClass caller, String lambdaClassName, ClassWriter cw, String name, List<Type> parameters, Type returnType, List<Type> invokedParameters, SootMethodType samMethodType, SootMethodHandle implMethod, SootMethodType instantiatedMethodType, boolean isBridgeMethod) {
String descriptor = Types.getDescriptor(parameters, returnType);
String implClassName = implMethod.getMethodRef().declaringClass().getName().replace('.', '/');
int accessFlags = ACC_PUBLIC | (isBridgeMethod ? ACC_BRIDGE : 0);
MethodVisitor mv = cw.visitMethod(accessFlags, name, descriptor, null, null);
mv.visitCode();
// figure out the invoke op code for the lambda implementation
// as well as if it's an instance method.
int invokeOpCode = INVOKESTATIC;
boolean isInstanceMethod = false;
switch(implMethod.getReferenceKind()) {
case SootMethodHandle.REF_invokeInterface:
invokeOpCode = INVOKEINTERFACE;
isInstanceMethod = true;
break;
case SootMethodHandle.REF_invokeSpecial:
invokeOpCode = INVOKESPECIAL;
isInstanceMethod = true;
break;
case SootMethodHandle.REF_newInvokeSpecial:
invokeOpCode = INVOKESPECIAL;
break;
case SootMethodHandle.REF_invokeStatic:
invokeOpCode = INVOKESTATIC;
break;
case SootMethodHandle.REF_invokeVirtual:
invokeOpCode = INVOKEVIRTUAL;
isInstanceMethod = true;
break;
default:
throw new CompilerException("Unknown invoke type: " + implMethod.getReferenceKind());
}
GeneratorAdapter caster = new GeneratorAdapter(mv, accessFlags, name, descriptor);
// push the arguments
pushArguments(caller, lambdaClassName, mv, caster, parameters, invokedParameters, implMethod, instantiatedMethodType, isInstanceMethod);
// generate a descriptor for the lambda implementation
// to invoke based on the parameters. If the lambda
// is an instance method, we need to remove the first
// parameter for the descriptor generation as it's
// not part of the method signature.
String implDescriptor = null;
List<Type> paramTypes = new ArrayList<Type>(implMethod.getMethodType().getParameterTypes());
if (isInstanceMethod)
paramTypes.remove(0);
implDescriptor = Types.getDescriptor(paramTypes, implMethod.getMethodType().getReturnType());
// call the lambda implementation
mv.visitMethodInsn(invokeOpCode, implClassName, implMethod.getMethodRef().name(), implDescriptor, invokeOpCode == INVOKEINTERFACE);
// emit the return instruction based on the return type
createForwardingMethodReturn(mv, caster, returnType, samMethodType, implMethod, instantiatedMethodType);
mv.visitMaxs(-1, -1);
mv.visitEnd();
}
use of org.robovm.compiler.CompilerException 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.");
}
use of org.robovm.compiler.CompilerException in project robovm by robovm.
the class IOSTarget method init.
public void init(Config config) {
super.init(config);
if (config.getArch() == null) {
arch = Arch.thumbv7;
} else {
if (!isSimulatorArch(config.getArch()) && !isDeviceArch(config.getArch())) {
throw new IllegalArgumentException("Arch '" + config.getArch() + "' is unsupported for iOS target");
}
arch = config.getArch();
}
if (isDeviceArch(arch)) {
if (!config.isSkipLinking() && !config.isIosSkipSigning()) {
signIdentity = config.getIosSignIdentity();
if (signIdentity == null) {
signIdentity = SigningIdentity.find(SigningIdentity.list(), "/(?i)iPhone Developer|iOS Development/");
}
}
}
if (config.getIosInfoPList() != null) {
config.getIosInfoPList().parse(config.getProperties());
}
if (isDeviceArch(arch)) {
if (!config.isSkipLinking() && !config.isIosSkipSigning()) {
provisioningProfile = config.getIosProvisioningProfile();
if (provisioningProfile == null) {
String bundleId = "*";
if (config.getIosInfoPList() != null && config.getIosInfoPList().getBundleIdentifier() != null) {
bundleId = config.getIosInfoPList().getBundleIdentifier();
}
provisioningProfile = ProvisioningProfile.find(ProvisioningProfile.list(), signIdentity, bundleId);
}
}
}
String sdkVersion = config.getIosSdkVersion();
List<SDK> sdks = getSDKs();
if (sdkVersion == null) {
if (sdks.isEmpty()) {
throw new IllegalArgumentException("No " + (isDeviceArch(arch) ? "device" : "simulator") + " SDKs installed");
}
Collections.sort(sdks);
this.sdk = sdks.get(sdks.size() - 1);
} else {
for (SDK sdk : sdks) {
if (sdk.getVersion().equals(sdkVersion)) {
this.sdk = sdk;
break;
}
}
if (sdk == null) {
throw new IllegalArgumentException("No SDK found matching version string " + sdkVersion);
}
}
entitlementsPList = config.getIosEntitlementsPList();
partialPListDir = new File(config.getTmpDir(), "partial-plists");
partialPListDir.mkdirs();
try {
FileUtils.cleanDirectory(partialPListDir);
} catch (IOException e) {
throw new CompilerException(e);
}
}
Aggregations