Search in sources :

Example 16 with Clazz

use of org.robovm.compiler.clazz.Clazz 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 17 with Clazz

use of org.robovm.compiler.clazz.Clazz 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);
    }
}
Also used : Attribute(org.objectweb.asm.Attribute) ClassVisitor(org.objectweb.asm.ClassVisitor) FieldVisitor(org.objectweb.asm.FieldVisitor) MethodVisitor(org.objectweb.asm.MethodVisitor) AnnotationVisitor(org.objectweb.asm.AnnotationVisitor) ClassReader(org.objectweb.asm.ClassReader) Clazz(org.robovm.compiler.clazz.Clazz) Clazzes(org.robovm.compiler.clazz.Clazzes) HashSet(java.util.HashSet)

Example 18 with Clazz

use of org.robovm.compiler.clazz.Clazz in project robovm by robovm.

the class AppCompilerTest method testMultipleMetainfServiceImplsAdded.

@Test
public void testMultipleMetainfServiceImplsAdded() throws Exception {
    final Path impl1 = new MockPath("META-INF/services/java.lang.Number", "java.lang.Integer");
    final Path impl2 = new MockPath("META-INF/services/java.lang.Number", "java.lang.Long");
    Clazzes clazzes = createClazzes(impl1, impl2);
    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")));
}
Also used : Path(org.robovm.compiler.clazz.Path) LinkedHashSet(java.util.LinkedHashSet) Clazz(org.robovm.compiler.clazz.Clazz) Clazzes(org.robovm.compiler.clazz.Clazzes) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 19 with Clazz

use of org.robovm.compiler.clazz.Clazz in project robovm by robovm.

the class AppCompilerTest method testMissingImplIsIgnore.

@Test
public void testMissingImplIsIgnore() throws Exception {
    final Path impl1 = new MockPath("META-INF/services/java.lang.Number", "java.lang.Integer");
    final Path 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<>();
    AppCompiler.addMetaInfImplementations(clazzes, interfaceClazz, compiled, queue);
    assertEquals("Just one item added to queue: " + queue, 1, queue.size());
    assertTrue("Integer in queue" + queue, queue.contains(clazzes.load("java/lang/Integer")));
}
Also used : Path(org.robovm.compiler.clazz.Path) LinkedHashSet(java.util.LinkedHashSet) Clazz(org.robovm.compiler.clazz.Clazz) Clazzes(org.robovm.compiler.clazz.Clazzes) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 20 with Clazz

use of org.robovm.compiler.clazz.Clazz in project robovm by robovm.

the class AppCompiler method getMatchingClasses.

/**
     * Returns all {@link Clazz}es in all {@link Path}s matching the specified
     * ANT-style pattern.
     */
private Collection<Clazz> getMatchingClasses(String pattern) {
    AntPathMatcher matcher = new AntPathMatcher(pattern, ".");
    Map<String, Clazz> matches = new HashMap<String, Clazz>();
    for (Path path : config.getClazzes().getPaths()) {
        for (Clazz clazz : path.listClasses()) {
            if (!matches.containsKey(clazz.getClassName()) && matcher.matches(clazz.getClassName())) {
                matches.put(clazz.getClassName(), clazz);
            }
        }
    }
    return matches.values();
}
Also used : Path(org.robovm.compiler.clazz.Path) HashMap(java.util.HashMap) Clazz(org.robovm.compiler.clazz.Clazz) AntPathMatcher(org.robovm.compiler.util.AntPathMatcher)

Aggregations

Clazz (org.robovm.compiler.clazz.Clazz)23 HashSet (java.util.HashSet)9 Test (org.junit.Test)6 Clazzes (org.robovm.compiler.clazz.Clazzes)6 Path (org.robovm.compiler.clazz.Path)6 LinkedHashSet (java.util.LinkedHashSet)5 Unreachable (org.robovm.compiler.llvm.Unreachable)5 File (java.io.File)4 IOException (java.io.IOException)3 TreeSet (java.util.TreeSet)3 Function (org.robovm.compiler.llvm.Function)3 FunctionRef (org.robovm.compiler.llvm.FunctionRef)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ClassReader (org.objectweb.asm.ClassReader)2 ClassVisitor (org.objectweb.asm.ClassVisitor)2 MethodVisitor (org.objectweb.asm.MethodVisitor)2 ModuleBuilder (org.robovm.compiler.ModuleBuilder)2 ClazzInfo (org.robovm.compiler.clazz.ClazzInfo)2 Dependency (org.robovm.compiler.clazz.Dependency)2