use of org.robovm.compiler.clazz.Dependency in project robovm by robovm.
the class DependencyGraph method add.
/**
* Adds the specified {@link Clazz} to the graph after it has been compiled.
* If {@code root == true} the class will be added to the root set and it as
* well as its methods will always be reachable.
*/
public void add(Clazz clazz, boolean root) {
reachableNodes.clear();
ClassNode classNode = getClassNode(clazz.getInternalName());
if (root) {
roots.add(classNode);
}
ClazzInfo ci = clazz.getClazzInfo();
for (Dependency dep : ci.getDependencies()) {
if (dep instanceof InvokeMethodDependency) {
InvokeMethodDependency mdep = (InvokeMethodDependency) dep;
classNode.addEgde(getMethodNode(mdep), mdep.isWeak());
} else if (dep instanceof SuperMethodDependency) {
SuperMethodDependency mdep = (SuperMethodDependency) dep;
classNode.addEgde(getMethodNode(mdep), mdep.isWeak());
} else {
classNode.addEgde(getClassNode(dep.getClassName()), dep.isWeak());
}
}
for (MethodInfo mi : ci.getMethods()) {
boolean strong = root || // Keep callback methods
mi.isCallback() || // Keep class initializers
(mi.isStatic() && "<clinit>".equals(mi.getName()) && "()V".equals(mi.getDesc())) || // in enum classes
(ci.isEnum() && mi.isStatic() && "values".equals(mi.getName()) && mi.getDesc().equals("()[L" + clazz.getInternalName() + ";")) || // in Struct classes
(ci.isStruct() && mi.isStatic() && "sizeOf".equals(mi.getName()) && "()I".equals(mi.getDesc()));
MethodNode methodNode = getMethodNode(clazz, mi);
classNode.addEgde(methodNode, !strong);
methodNode.addEgde(classNode, false);
for (Dependency dep : mi.getDependencies()) {
if (dep instanceof InvokeMethodDependency) {
InvokeMethodDependency mdep = (InvokeMethodDependency) dep;
methodNode.addEgde(getMethodNode(mdep), mdep.isWeak());
} else if (dep instanceof SuperMethodDependency) {
// Reverse the dependency so that the method is strongly
// linked if the super method is invoked.
SuperMethodDependency mdep = (SuperMethodDependency) dep;
getMethodNode(mdep).addEgde(methodNode, false);
} else {
methodNode.addEgde(getClassNode(dep.getClassName()), dep.isWeak());
}
}
}
}
use of org.robovm.compiler.clazz.Dependency in project robovm by robovm.
the class AnnotationImplPluginTest method createAnnoImpl.
private File createAnnoImpl(Class<? extends Annotation> annoClass) {
AnnotationImplPlugin plugin = new AnnotationImplPlugin();
Clazz clazz = toClazz(annoClass);
clazz.resetClazzInfo();
plugin.beforeClass(config, clazz, new ModuleBuilder());
assertFalse(clazz.getClazzInfo().getAllDependencies().isEmpty());
Dependency dep = clazz.getClazzInfo().getAllDependencies().iterator().next();
assertEquals(clazz.getInternalName() + "$Impl", dep.getClassName());
final File implFile = new File(config.getGeneratedClassDir(clazz.getPath()), clazz.getInternalName() + "$Impl.class");
assertTrue(implFile.exists());
return implFile;
}
use of org.robovm.compiler.clazz.Dependency in project robovm by robovm.
the class ClassCompiler method mustCompile.
public boolean mustCompile(Clazz clazz) {
File oFile = config.getOFile(clazz);
if (!oFile.exists() || oFile.lastModified() < clazz.lastModified() || oFile.length() == 0) {
return true;
}
ClazzInfo ci = clazz.getClazzInfo();
if (ci == null) {
return true;
}
Set<Dependency> dependencies = ci.getAllDependencies();
for (Dependency dep : dependencies) {
Clazz depClazz = config.getClazzes().load(dep.getClassName());
if (depClazz == null) {
if (dep.getPath() != null) {
// depClazz was available the last time clazz was compiled but is now gone
return true;
}
} else {
if (dep.getPath() == null) {
// depClazz was not available the last time clazz was compiled but is now available
return true;
}
if (!dep.getPath().equals(depClazz.getPath().getFile().getAbsolutePath())) {
// depClazz was located in another place the last time clazz was built
return true;
}
if (depClazz.isInBootClasspath() != dep.isInBootClasspath()) {
// depClazz has moved to/from the bootclasspath since the last time clazz was built
return true;
}
if (depClazz.lastModified() > oFile.lastModified()) {
// depClazz has been changed since the last time clazz was built
return true;
}
}
}
// and the dependencies regenerated.
return dependencies.isEmpty();
}
Aggregations