Search in sources :

Example 6 with Clazz

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

the class TrampolineCompiler method checkClassAccessible.

private boolean checkClassAccessible(Function f, Trampoline t) {
    Clazz caller = config.getClazzes().load(t.getCallingClass());
    String targetClassName = t.getTarget();
    if (isArray(targetClassName)) {
        if (isPrimitiveBaseType(targetClassName)) {
            return true;
        }
        targetClassName = getBaseType(targetClassName);
    }
    Clazz target = config.getClazzes().load(targetClassName);
    if (Access.checkClassAccessible(target, caller)) {
        return true;
    }
    throwIllegalAccessError(f, ILLEGAL_ACCESS_ERROR_CLASS, target, caller);
    f.add(new Unreachable());
    return false;
}
Also used : Unreachable(org.robovm.compiler.llvm.Unreachable) Clazz(org.robovm.compiler.clazz.Clazz)

Example 7 with Clazz

use of org.robovm.compiler.clazz.Clazz 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")));
}
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 8 with Clazz

use of org.robovm.compiler.clazz.Clazz 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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Clazz(org.robovm.compiler.clazz.Clazz) IOException(java.io.IOException) Clazzes(org.robovm.compiler.clazz.Clazzes) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 9 with Clazz

use of org.robovm.compiler.clazz.Clazz 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")));
}
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 10 with Clazz

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

the class AppCompiler method getRootClasses.

/**
     * Returns all root classes. These are the minimum set of classes that needs
     * to be compiled and linked. The compiler will use this set to determine
     * which classes need to be recompiled and linked in through the root
     * classes' dependencies.
     * 
     * The classes matching {@link #ROOT_CLASS_PATTERNS} and
     * {@link #ROOT_CLASSES} will always be included. If a main class has been
     * specified it will also become a root. Any root class pattern specified on
     * the command line (as returned by {@link Config#getRoots()} will also be
     * used to find root classes. If no main class has been specified and
     * {@link Config#getRoots()} returns an empty set all classes available on
     * the bootclasspath and the classpath will become roots.
     */
private TreeSet<Clazz> getRootClasses() {
    TreeSet<Clazz> classes = new TreeSet<Clazz>();
    for (String rootClassName : ROOT_CLASSES) {
        Clazz clazz = config.getClazzes().load(rootClassName);
        if (clazz == null) {
            throw new CompilerException("Root class " + rootClassName + " not found");
        }
        classes.add(clazz);
    }
    if (config.getMainClass() != null) {
        Clazz clazz = config.getClazzes().load(config.getMainClass().replace('.', '/'));
        if (clazz == null) {
            throw new CompilerException("Main class " + config.getMainClass() + " not found");
        }
        classes.add(clazz);
    }
    if (config.getForceLinkClasses().isEmpty()) {
        if (config.getMainClass() == null) {
            classes.addAll(config.getClazzes().listClasses());
        }
    } else {
        for (String pattern : config.getForceLinkClasses()) {
            if (pattern == null || pattern.trim().isEmpty()) {
                continue;
            }
            pattern = pattern.trim();
            if (pattern.indexOf('*') == -1) {
                Clazz clazz = config.getClazzes().load(pattern.replace('.', '/'));
                if (clazz == null) {
                    throw new CompilerException("Root class " + pattern + " not found");
                }
                classes.add(clazz);
            } else {
                Collection<Clazz> matches = getMatchingClasses(pattern);
                if (matches.isEmpty()) {
                    config.getLogger().warn("Root pattern %s matches no classes", pattern);
                } else {
                    classes.addAll(matches);
                }
            }
        }
    }
    return classes;
}
Also used : TreeSet(java.util.TreeSet) Clazz(org.robovm.compiler.clazz.Clazz)

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