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;
}
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")));
}
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);
}
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")));
}
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;
}
Aggregations