
aQute.bnd.make.coverage.Coverage Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of biz.aQute.bndlib Show documentation
Show all versions of biz.aQute.bndlib Show documentation
bndlib: A Swiss Army Knife for OSGi
The newest version!
package aQute.bnd.make.coverage;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import aQute.bnd.classfile.Attribute;
import aQute.bnd.classfile.MethodInfo;
import aQute.bnd.osgi.ClassDataCollector;
import aQute.bnd.osgi.Clazz;
import aQute.bnd.osgi.Clazz.MethodDef;
import aQute.bnd.osgi.Descriptors.TypeRef;
/**
* This class can create a coverage table between two classspaces. The
* destination class space is used to create a table of methods. All source
* methods that refer to a specific dest are then filled into the table.
*/
public class Coverage {
/**
* Create a cross reference table from source to dest.
*
* @param source The methods that refer to dest
* @param dest The methods that are being referred to
* @return A mapping of source methods to destination methods.
* @throws Exception
*/
public static Map> getCrossRef(Collection source, Collection dest)
throws Exception {
final Map> catalog = buildCatalog(dest);
crossRef(source, catalog);
return catalog;
}
private static void crossRef(Collection source, final Map> catalog)
throws Exception {
for (final Clazz clazz : source) {
clazz.parseClassFileWithCollector(new ClassDataCollector() {
// MethodDef source;
@Override
public void implementsInterfaces(TypeRef names[]) {
MethodDef def = clazz.new MethodDef(new MethodInfo(0, "", "()V", new Attribute[0]));
// TODO
for (TypeRef interfaceName : names) {
for (Map.Entry> entry : catalog.entrySet()) {
String catalogClass = entry.getKey()
.getContainingClass()
.getFQN();
List references = entry.getValue();
if (catalogClass.equals(interfaceName.getFQN())) {
references.add(def);
}
}
}
}
// Method definitions
@Override
public void method(MethodDef source) {
// this.source = source;
}
// TODO need to use different reference method
// public void reference(MethodDef reference) {
// List references = catalog.get(reference);
// if (references != null) {
// references.add(source);
// }
// }
});
}
}
private static Map> buildCatalog(Collection sources) throws Exception {
final Map> catalog = new TreeMap<>((a, b) -> a.getName()
.compareTo(b.getName()));
for (final Clazz clazz : sources) {
clazz.parseClassFileWithCollector(new ClassDataCollector() {
@Override
public boolean classStart(int access, TypeRef name) {
return clazz.isPublic();
}
@Override
public void method(MethodDef source) {
if (source.isPublic() || source.isProtected())
catalog.put(source, new ArrayList<>());
}
});
}
return catalog;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy