mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 00:04:10 -08:00
Dependency checker now cuts off unused methods
This commit is contained in:
parent
6efbb75783
commit
f88b868c39
|
@ -41,12 +41,16 @@ public class ClasslibTestGenerator {
|
|||
renderer = new Renderer(writer, classSource);
|
||||
DependencyChecker dependencyChecker = new DependencyChecker(classSource);
|
||||
for (String testClass : testClasses) {
|
||||
findTests(classSource.getClassHolder(testClass));
|
||||
ClassHolder classHolder = classSource.getClassHolder(testClass);
|
||||
findTests(classHolder);
|
||||
MethodReference cons = new MethodReference(testClass, new MethodDescriptor("<init>", ValueType.VOID));
|
||||
dependencyChecker.addEntryPoint(cons);
|
||||
}
|
||||
for (MethodReference methodRef : testMethods) {
|
||||
dependencyChecker.addEntryPoint(methodRef);
|
||||
}
|
||||
dependencyChecker.checkDependencies();
|
||||
dependencyChecker.cutUnachievableClasses();
|
||||
for (String className : dependencyChecker.getAchievableClasses()) {
|
||||
decompileClass(className);
|
||||
}
|
||||
|
|
|
@ -235,4 +235,24 @@ public class DependencyChecker {
|
|||
}
|
||||
plugin.methodAchieved(this, methodRef);
|
||||
}
|
||||
|
||||
public ListableClassHolderSource cutUnachievableClasses() {
|
||||
MutableClassHolderSource cutClasses = new MutableClassHolderSource();
|
||||
for (String className : achievableClasses.keySet()) {
|
||||
ClassHolder classHolder = classSource.getClassHolder(className);
|
||||
for (MethodHolder method : classHolder.getMethods().toArray(new MethodHolder[0])) {
|
||||
MethodReference methodRef = new MethodReference(className, method.getDescriptor());
|
||||
if (!methodCache.getCachedPreimages().contains(methodRef)) {
|
||||
classHolder.removeMethod(method);
|
||||
}
|
||||
}
|
||||
for (FieldHolder field : classHolder.getFields().toArray(new FieldHolder[0])) {
|
||||
FieldReference fieldRef = new FieldReference(className, field.getName());
|
||||
if (!fieldCache.getCachedPreimages().contains(fieldRef)) {
|
||||
classHolder.removeField(field);
|
||||
}
|
||||
}
|
||||
}
|
||||
return cutClasses;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,10 +64,6 @@ public class ClassHolder extends ElementHolder {
|
|||
}
|
||||
|
||||
public void removeMethod(MethodHolder method) {
|
||||
if (method.getOwner() != null) {
|
||||
throw new IllegalArgumentException("Method " + method.getDescriptor() +
|
||||
" is not a member of " + getName());
|
||||
}
|
||||
if (method.getOwner() != this) {
|
||||
throw new IllegalArgumentException("Method " + method.getOwner().getName() +
|
||||
"." + method.getDescriptor() + " is not a member of " + getName());
|
||||
|
@ -97,10 +93,6 @@ public class ClassHolder extends ElementHolder {
|
|||
}
|
||||
|
||||
public void removeField(FieldHolder field) {
|
||||
if (field.getOwner() != null) {
|
||||
throw new IllegalArgumentException("Field " + field.getName() +
|
||||
" is not a member of " + getName());
|
||||
}
|
||||
if (field.getOwner() != this) {
|
||||
throw new IllegalArgumentException("Field " + field.getOwner().getName() + "." +
|
||||
field.getName() + " is not a member of " + getName());
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package org.teavm.model;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public interface ListableClassHolderSource extends ClassHolderSource {
|
||||
Set<String> getClassNames();
|
||||
}
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package org.teavm.model;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
|
@ -22,9 +23,14 @@ import java.util.concurrent.ConcurrentMap;
|
|||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public class MutableClassHolderSource implements ClassHolderSource {
|
||||
public class MutableClassHolderSource implements ListableClassHolderSource {
|
||||
private ConcurrentMap<String, ClassHolder> classes = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public Set<String> getClassNames() {
|
||||
return classes.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassHolder getClassHolder(String name) {
|
||||
return classes.get(name);
|
||||
|
|
Loading…
Reference in New Issue
Block a user