use of org.robovm.compiler.clazz.Clazzes in project robovm by robovm.
the class AppCompilerTest method testMultilineFile.
@Test
public void testMultilineFile() throws Exception {
final Path impl1 = new MockPath("META-INF/services/java.lang.Number", "# first register Integer\n" + "java.lang.Integer\n" + "# then add Long\n" + "java.lang.Long\n" + "\n\n\n\n");
Clazzes clazzes = createClazzes(impl1);
Clazz interfaceClazz = clazzes.load("java/lang/Number");
Set<Clazz> compiled = new HashSet<>();
Set<Clazz> queue = new LinkedHashSet<>();
AppCompiler.addMetaInfImplementations(clazzes, interfaceClazz, compiled, queue);
assertEquals("Two items added to queue: " + queue, 2, queue.size());
assertTrue("Integer in queue" + queue, queue.contains(clazzes.load("java/lang/Integer")));
assertTrue("Long in queue" + queue, queue.contains(clazzes.load("java/lang/Long")));
}
use of org.robovm.compiler.clazz.Clazzes in project robovm by robovm.
the class AppCompilerTest method allStreamsAreClosedInCaseOfFailure.
@Test
public void allStreamsAreClosedInCaseOfFailure() throws Exception {
final MockPath impl1 = new MockPath("META-INF/services/java.lang.Number", "java.lang.Integer");
impl1.toThrow = new IOException();
final MockPath impl2 = new MockPath("META-INF/services/java.lang.Number", "nobody.knows.such.Class");
Clazzes clazzes = createClazzes(impl1, impl2);
Clazz interfaceClazz = clazzes.load("java/lang/Number");
Set<Clazz> compiled = new HashSet<>();
Set<Clazz> queue = new LinkedHashSet<>();
try {
AppCompiler.addMetaInfImplementations(clazzes, interfaceClazz, compiled, queue);
fail("Should throw an exception");
} catch (IOException ex) {
assertSame("Our exception is thrown", impl1.toThrow, ex);
}
assertTrue("First stream is closed", impl1.closed);
assertTrue("Second stream is closed", impl2.closed);
}
use of org.robovm.compiler.clazz.Clazzes in project robovm by robovm.
the class AppCompilerTest method testMetainfServiceImplIsAdded.
@Test
public void testMetainfServiceImplIsAdded() throws Exception {
final Path impl1 = new MockPath("META-INF/services/java.lang.Number", "java.lang.Integer");
Clazzes clazzes = createClazzes(impl1);
Clazz interfaceClazz = clazzes.load("java/lang/Number");
Set<Clazz> compiled = new HashSet<>();
Set<Clazz> queue = new LinkedHashSet<>();
AppCompiler.addMetaInfImplementations(clazzes, interfaceClazz, compiled, queue);
assertEquals("One item added to queue: " + queue, 1, queue.size());
assertTrue("Integer in queue" + queue, queue.contains(clazzes.load("java/lang/Integer")));
}
use of org.robovm.compiler.clazz.Clazzes in project robovm by robovm.
the class AppCompilerTest method createClazzes.
private static Clazzes createClazzes(final Path... paths) throws Exception {
File home = new File(System.getProperty("java.home"));
Config cfg = new Config() {
};
Clazzes clazzes = new Clazzes(cfg, Collections.nCopies(1, new File(new File(home, "lib"), "rt.jar")), Collections.<File>emptyList()) {
@Override
public List<Path> getPaths() {
return Arrays.asList(paths);
}
};
return clazzes;
}
use of org.robovm.compiler.clazz.Clazzes in project robovm by robovm.
the class ObjCProtocolProxyPlugin method generateProxyMethods.
private void generateProxyMethods(Config config, List<String> interfazes, ClassWriter cw) throws IOException {
Clazzes clazzes = config.getClazzes();
final Set<String> addedMethods = new HashSet<>();
for (String interfaze : interfazes) {
Clazz clazz = clazzes.load(interfaze);
if (clazz == null) {
continue;
}
// Copy all abstract method (we skip default methods) to the proxy
// and make them native instead of abstract.
ClassReader classReader = new ClassReader(clazz.getBytes());
classReader.accept(new ClassVisitor(ASM4, cw) {
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
String key = name + desc;
if ((access & ACC_ABSTRACT) > 0 && !addedMethods.contains(key)) {
access &= ~ACC_ABSTRACT;
access |= ACC_NATIVE;
addedMethods.add(key);
return super.visitMethod(access, name, desc, signature, exceptions);
}
return null;
}
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
// Ignored
}
@Override
public void visitEnd() {
// Ignored
}
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
// Ignored
return null;
}
@Override
public void visitAttribute(Attribute attr) {
// Ignored
}
@Override
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
// Ignored
return null;
}
@Override
public void visitInnerClass(String name, String outerName, String innerName, int access) {
// Ignored
}
@Override
public void visitOuterClass(String owner, String name, String desc) {
// Ignored
}
@Override
public void visitSource(String source, String debug) {
// Ignored
}
}, 0);
}
}
Aggregations