use of org.mapleir.asm.ClassNode in project maple-ir by LLVM-but-worse.
the class ClassTree method addVertex.
@Override
public boolean addVertex(ClassNode cn) {
if (cn == null) {
LOGGER.error("Received null to ClassTree.addVertex");
return false;
}
if (!super.addVertex(cn))
return false;
if (cn != rootNode) {
Set<InheritanceEdge> edges = new HashSet<>();
ClassNode sup = cn.node.superName != null ? requestClass0(cn.node.superName, cn.getName()) : rootNode;
if (sup == null) {
LOGGER.error(String.format("No superclass %s for %s", cn.node.superName, cn.getName()));
removeVertex(cn);
return false;
}
edges.add(new ExtendsEdge(cn, sup));
for (String s : cn.node.interfaces) {
ClassNode iface = requestClass0(s, cn.getName());
if (iface == null) {
LOGGER.error(String.format("No superinterface %s for %s", s, cn.getName()));
removeVertex(cn);
return false;
}
edges.add(new ImplementsEdge(cn, iface));
}
for (InheritanceEdge e : edges) {
super.addEdge(e);
}
}
return true;
}
use of org.mapleir.asm.ClassNode in project maple-ir by LLVM-but-worse.
the class ClassTree method getAllBranches.
/**
* @param cn classnode to search out from
* @return every class connected to the class in any way.
*/
public Collection<ClassNode> getAllBranches(ClassNode cn) {
Collection<ClassNode> results = new HashSet<>();
Queue<ClassNode> queue = new LinkedList<>();
queue.add(cn);
while (!queue.isEmpty()) {
ClassNode next = queue.remove();
if (results.add(next) && next != rootNode) {
queue.addAll(getAllChildren(next));
}
}
queue.add(cn);
while (!queue.isEmpty()) {
ClassNode next = queue.remove();
if (results.add(next) && next != rootNode) {
queue.addAll(getAllParents(next));
}
}
return results;
}
use of org.mapleir.asm.ClassNode in project maple-ir by LLVM-but-worse.
the class ClassTree method getCommonSuperType.
public ClassNode getCommonSuperType(String type1, String type2) {
ClassNode ccn = source.findClassNode(type1);
ClassNode dcn = source.findClassNode(type2);
if (ccn == null) {
ClassNode c;
try {
c = ClassHelper.create(type1);
} catch (IOException e) {
e.printStackTrace();
return null;
}
this.addVertex(ccn = c);
}
if (dcn == null) {
ClassNode c;
try {
c = ClassHelper.create(type2);
} catch (IOException e) {
e.printStackTrace();
return null;
}
this.addVertex(dcn = c);
}
Collection<ClassNode> c = this.getAllParents(ccn);
Collection<ClassNode> d = this.getAllParents(dcn);
if (c.contains(dcn))
return dcn;
if (d.contains(ccn))
return ccn;
Stack<ClassNode> stack = new Stack<>();
List<ClassNode> cached = new ArrayList<>(c);
Collections.reverse(cached);
stack.addAll(cached);
while (!stack.isEmpty()) {
final ClassNode peek = stack.pop();
if (d.contains(peek))
return peek;
}
return null;
}
use of org.mapleir.asm.ClassNode in project maple-ir by LLVM-but-worse.
the class ClassSource method rebuildTable.
protected void rebuildTable() {
Set<ClassNode> cset = new HashSet<>();
cset.addAll(nodeMap.values());
nodeMap.clear();
for (ClassNode cn : cset) {
nodeMap.put(cn.getName(), cn);
}
}
use of org.mapleir.asm.ClassNode in project maple-ir by LLVM-but-worse.
the class CompleteResolvingJarDumper method buildClassWriter.
public ClassWriter buildClassWriter(ClassTree tree, int flags) {
return new ClassWriter(flags) {
// this method in ClassWriter uses the systemclassloader as
// a stream location to load the super class, however, most of
// the time the class is loaded/read and parsed by us so it
// isn't defined in the system classloader. in certain cases
// we may not even want it to be loaded/resolved and we can
// bypass this by implementing the hierarchy scanning algorithm
// with ClassNodes rather than Classes.
@Override
protected String getCommonSuperClass(String type1, String type2) {
ClassNode ccn = source.findClassNode(type1);
ClassNode dcn = source.findClassNode(type2);
if (ccn == null) {
// return "java/lang/Object";
ClassNode c;
try {
c = ClassHelper.create(type1);
} catch (IOException e) {
e.printStackTrace();
return "java/lang/Object";
}
if (c == null) {
return "java/lang/Object";
}
tree.addVertex(ccn = c);
// classTree.build(c);
// return getCommonSuperClass(type1, type2);
}
if (dcn == null) {
// return "java/lang/Object";
ClassNode c;
try {
c = ClassHelper.create(type2);
} catch (IOException e) {
e.printStackTrace();
return "java/lang/Object";
}
if (c == null) {
return "java/lang/Object";
}
tree.addVertex(dcn = c);
// classTree.build(c)
// return getCommonSuperClass(type1, type2);
}
Collection<ClassNode> c = tree.getAllParents(ccn);
Collection<ClassNode> d = tree.getAllParents(dcn);
if (c.contains(dcn))
return type1;
if (d.contains(ccn))
return type2;
if (Modifier.isInterface(ccn.node.access) || Modifier.isInterface(dcn.node.access)) {
// enums as well?
return "java/lang/Object";
} else {
do {
ClassNode nccn = source.findClassNode(ccn.node.superName);
if (nccn == null)
break;
ccn = nccn;
c = tree.getAllParents(ccn);
} while (!c.contains(dcn));
return ccn.getName();
}
}
};
}
Aggregations