Convert ReflectionClassMetadata to Kotlin

bzip2
Graham 5 years ago
parent 3ee6d57ba9
commit 862d4a3504
  1. 73
      asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.java
  2. 37
      asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.kt

@ -1,73 +0,0 @@
package dev.openrs2.asm.classpath;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import com.google.common.collect.ImmutableList;
import dev.openrs2.asm.MemberDesc;
import org.objectweb.asm.Type;
public final class ReflectionClassMetadata extends ClassMetadata {
private final ClassPath classPath;
private final Class<?> clazz;
public ReflectionClassMetadata(ClassPath classPath, Class<?> clazz) {
this.classPath = classPath;
this.clazz = clazz;
}
@Override
public String getName() {
return clazz.getName().replace('.', '/');
}
@Override
public boolean getDependency() {
return true;
}
@Override
public boolean getInterface() {
return clazz.isInterface();
}
@Override
public ClassMetadata getSuperClass() {
var superClass = clazz.getSuperclass();
if (superClass != null) {
return classPath.get(superClass.getName().replace('.', '/'));
}
return null;
}
@Override
public ImmutableList<ClassMetadata> getSuperInterfaces() {
return Arrays.stream(clazz.getInterfaces())
.map(i -> classPath.get(i.getName().replace('.', '/')))
.collect(ImmutableList.toImmutableList());
}
@Override
public ImmutableList<MemberDesc> getFields() {
return Arrays.stream(clazz.getDeclaredFields())
.map(f -> new MemberDesc(f.getName(), Type.getDescriptor(f.getType())))
.collect(ImmutableList.toImmutableList());
}
@Override
public ImmutableList<MemberDesc> getMethods() {
return Arrays.stream(clazz.getDeclaredMethods())
.map(m -> new MemberDesc(m.getName(), Type.getMethodDescriptor(m)))
.collect(ImmutableList.toImmutableList());
}
@Override
public boolean isNative(MemberDesc method) {
for (var m : clazz.getDeclaredMethods()) {
if (m.getName().equals(method.getName()) && Type.getMethodDescriptor(m).equals(method.getDesc())) {
return Modifier.isNative(m.getModifiers());
}
}
return false;
}
}

@ -0,0 +1,37 @@
package dev.openrs2.asm.classpath
import dev.openrs2.asm.MemberDesc
import org.objectweb.asm.Type
import java.lang.reflect.Modifier
private val Class<*>.asmName: String
get() = name.replace('.', '/')
class ReflectionClassMetadata(private val classPath: ClassPath, private val clazz: Class<*>) : ClassMetadata() {
override val name: String
get() = clazz.asmName
override val dependency: Boolean
get() = true
override val `interface`: Boolean
get() = clazz.isInterface
override val superClass: ClassMetadata?
get() = if (clazz.superclass != null) classPath[clazz.superclass.asmName] else null
override val superInterfaces
get() = clazz.interfaces.map { classPath[it.asmName] }.toList()
override val fields
get() = clazz.declaredFields.map { MemberDesc(it.name, Type.getDescriptor(it.type)) }.toList()
override val methods
get() = clazz.declaredMethods.map { MemberDesc(it.name, Type.getMethodDescriptor(it)) }.toList()
override fun isNative(method: MemberDesc): Boolean {
val m = clazz.declaredMethods.find { it.name == method.name && Type.getMethodDescriptor(it) == method.desc }
?: return false
return Modifier.isNative(m.modifiers)
}
}
Loading…
Cancel
Save