JS: don't remove class name from metadata when it's referenced indirectly from array class

This commit is contained in:
Alexey Andreev 2019-08-26 16:44:10 +03:00
parent 7a03ad6c5e
commit f028f8db37

View File

@ -19,7 +19,6 @@ import com.carrotsearch.hppc.ObjectIntHashMap;
import com.carrotsearch.hppc.ObjectIntMap;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@ -632,17 +631,33 @@ public class Renderer implements RenderingManager {
MethodDependencyInfo getNameMethod = context.getDependencyInfo().getMethod(
new MethodReference(Class.class, "getName", String.class));
if (getNameMethod != null) {
classesRequiringName.addAll(Arrays.asList(getNameMethod.getVariable(0).getClassValueNode().getTypes()));
addClassesRequiringName(classesRequiringName, getNameMethod.getVariable(0).getClassValueNode().getTypes());
}
MethodDependencyInfo getSimpleNameMethod = context.getDependencyInfo().getMethod(
new MethodReference(Class.class, "getSimpleName", String.class));
if (getSimpleNameMethod != null) {
classesRequiringName.addAll(Arrays.asList(
getSimpleNameMethod.getVariable(0).getClassValueNode().getTypes()));
addClassesRequiringName(classesRequiringName,
getSimpleNameMethod.getVariable(0).getClassValueNode().getTypes());
}
return classesRequiringName;
}
private void addClassesRequiringName(Set<String> target, String[] source) {
for (String typeName : source) {
if (typeName.startsWith("[")) {
if (!typeName.endsWith(";")) {
continue;
}
int index = 0;
while (typeName.charAt(index) == '[') {
++index;
}
typeName = typeName.substring(index, typeName.length() - 1).replace('/', '.');
}
target.add(typeName);
}
}
private void collectMethodsToCopyFromInterfaces(ClassReader cls, List<MethodReference> targetList) {
Set<MethodDescriptor> implementedMethods = new HashSet<>();
implementedMethods.addAll(targetList.stream().map(method -> method.getDescriptor())