Skip to content

Commit

Permalink
Exclude class fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xpenatan committed Nov 9, 2023
1 parent d319ae8 commit 665f574
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[1.0.0-SNAPSHOT]
- add TeaClassFilter printAllowedClasses() and printExcludedClasses()
- add TeaReflectionSupplier.printReflectionClasses()
- Change exclude class comparison to regex

[1.0.0-b8]
- Fix MMB code
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.xpenatan.gdx.backends.teavm.config.plugins;

import com.github.xpenatan.gdx.backends.teavm.config.TeaBuilder;
import java.util.ArrayList;
import org.teavm.model.FieldReference;
import org.teavm.model.MethodReference;
Expand All @@ -10,6 +11,10 @@ public class TeaClassFilter implements ElementFilter {
private static final ArrayList<Pair> methodsToExclude = new ArrayList<>();
private static final ArrayList<Pair> fieldsToExclude = new ArrayList<>();

private static final ArrayList<String> ALLOWED_CLASSES = new ArrayList<>();
private static final ArrayList<String> EXCLUDED_CLASSES = new ArrayList<>();


/**
* my.package.ClassName or my.package
*/
Expand All @@ -31,10 +36,32 @@ public static void addFieldsToExclude(String className, String fieldName) {
fieldsToExclude.add(new Pair(className, fieldName));
}

/**
* Must be called after TeaBuilder.build
*/
public static void printAllowedClasses() {
TeaBuilder.logHeader("EXCLUDED CLASSES: " + ALLOWED_CLASSES.size());
for(String allowedClass : ALLOWED_CLASSES) {
TeaBuilder.log(allowedClass);
}
TeaBuilder.logEnd();
}

/**
* Must be called after TeaBuilder.build
*/
public static void printExcludedClasses() {
TeaBuilder.logHeader("ALLOWED CLASES: " + EXCLUDED_CLASSES.size());
for(String excludedClass : EXCLUDED_CLASSES) {
TeaBuilder.log(excludedClass);
}
TeaBuilder.logEnd();
}

private static boolean containsClass(ArrayList<String> list, String className) {
for(int i = 0; i < list.size(); i++) {
String excludedClass = list.get(i);
if(className.contains(excludedClass))
if(className.matches(excludedClass) || className.contains(excludedClass + "$") )
return true;
}
return false;
Expand All @@ -58,6 +85,12 @@ public boolean acceptClass(String fullClassName) {
if(containsClass(classesToExclude, fullClassName)) {
accceptClass = false;
}
if(accceptClass) {
ALLOWED_CLASSES.add(fullClassName);
}
else {
EXCLUDED_CLASSES.add(fullClassName);
}
return accceptClass;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.xpenatan.gdx.backends.teavm.config.plugins;

import com.github.xpenatan.gdx.backends.teavm.config.TeaBuilder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -17,6 +18,8 @@ public class TeaReflectionSupplier implements ReflectionSupplier {

private static ArrayList<String> clazzList = new ArrayList();

private static HashSet<String> REFLECTION_CLASSES = new HashSet<>();

public static void addReflectionClass(Class<?> type) {
addReflectionClass(type.getName());
}
Expand All @@ -41,6 +44,17 @@ public static void addReflectionClass(String className) {
clazzList.add(className);
}

/**
* Must be called after TeaBuilder.build
*/
public static void printReflectionClasses() {
TeaBuilder.logHeader("REFLECTION CLASSES: " + REFLECTION_CLASSES.size());
for(String reflectionClass : REFLECTION_CLASSES) {
TeaBuilder.log(reflectionClass);
}
TeaBuilder.logEnd();
}

public TeaReflectionSupplier() {
}

Expand All @@ -54,6 +68,7 @@ public Collection<String> getAccessibleFields(ReflectionContext context, String

if(cls != null) {
if(canHaveReflection(className)) {
REFLECTION_CLASSES.add(className);
for(FieldReader field : cls.getFields()) {
String name = field.getName();
fields.add(name);
Expand All @@ -71,6 +86,7 @@ public Collection<MethodDescriptor> getAccessibleMethods(ReflectionContext conte
}
Set<MethodDescriptor> methods = new HashSet<>();
if(canHaveReflection(className)) {
REFLECTION_CLASSES.add(className);
Collection<? extends MethodReader> methods2 = cls.getMethods();
for(MethodReader method : methods2) {
MethodDescriptor descriptor = method.getDescriptor();
Expand Down

0 comments on commit 665f574

Please sign in to comment.