use of meghanada.reflect.MemberDescriptor in project meghanada-server by mopemope.
the class ASMReflectorTest method testReflectAnnotation1.
@Test
public void testReflectAnnotation1() throws Exception {
ASMReflector asmReflector = ASMReflector.getInstance();
Stopwatch stopwatch = Stopwatch.createUnstarted();
{
String fqcn = "org.junit.Test";
File jar = getJar("junit:junit");
stopwatch.start();
List<MemberDescriptor> memberDescriptors = timeIt(() -> {
Map<String, ClassIndex> index = asmReflector.getClassIndexes(jar);
// Map<ClassIndex, File> index = asmReflector.getClasses(jar);
// index
// .keySet()
// .forEach(
// classIndex -> {
// if (classIndex.isAnnotation) {
// System.out.println("anno: " + classIndex);
// }
// });
final InheritanceInfo info = asmReflector.getReflectInfo(index, fqcn);
return asmReflector.reflectAll(info);
});
System.out.println(stopwatch.stop());
memberDescriptors.forEach(m -> {
System.out.println(m.getDeclaration());
});
assertEquals(2, memberDescriptors.size());
stopwatch.reset();
}
}
use of meghanada.reflect.MemberDescriptor in project meghanada-server by mopemope.
the class ASMReflectorTest method testReflectAll8.
@Test
public void testReflectAll8() throws Exception {
final ASMReflector asmReflector = ASMReflector.getInstance();
final File file = getTestOutput();
Map<String, ClassIndex> index = asmReflector.getClassIndexes(file);
final String fqcn = "meghanada.Gen4";
final List<MemberDescriptor> memberDescriptors = debugIt(() -> {
final InheritanceInfo info = asmReflector.getReflectInfo(index, fqcn);
return asmReflector.reflectAll(info);
});
memberDescriptors.forEach(md -> {
System.out.println(md.getDeclaringClass() + " # " + md.getDeclaration());
});
}
use of meghanada.reflect.MemberDescriptor in project meghanada-server by mopemope.
the class ASMReflectorTest method testReflectWithGenerics2.
@Test
public void testReflectWithGenerics2() throws Exception {
ASMReflector asmReflector = ASMReflector.getInstance();
Stopwatch stopwatch = Stopwatch.createUnstarted();
{
String fqcn = "java.util.Enumeration<? extends ZipEntry>";
File jar = getRTJar();
Map<String, ClassIndex> index = asmReflector.getClassIndexes(jar);
final InheritanceInfo info = asmReflector.getReflectInfo(index, fqcn);
stopwatch.start();
List<MemberDescriptor> memberDescriptors = asmReflector.reflectAll(info);
System.out.println(stopwatch.stop());
memberDescriptors.forEach(m -> System.out.println(m.getDisplayDeclaration()));
Config config = Config.load();
if (config.isJava8()) {
assertEquals(13, memberDescriptors.size());
} else {
assertEquals(14, memberDescriptors.size());
}
stopwatch.reset();
}
}
use of meghanada.reflect.MemberDescriptor in project meghanada-server by mopemope.
the class ProjectDatabaseHelper method getMemberDescriptors.
public static Optional<List<MemberDescriptor>> getMemberDescriptors(String fqcn) {
ProjectDatabase database = ProjectDatabase.getInstance();
return database.computeInReadonly(txn -> {
EntityIterable it = txn.find(ClassIndex.ENTITY_TYPE, ProjectDatabase.ID, fqcn).intersect(txn.findWithBlob(ClassIndex.ENTITY_TYPE, BLOB_PROP_MEMBERS));
Entity entity = it.getFirst();
if (isNull(entity)) {
return Optional.empty();
}
try (InputStream in = entity.getBlob(BLOB_PROP_MEMBERS)) {
@SuppressWarnings("unchecked") List<MemberDescriptor> res = Serializer.readObject(in, ArrayList.class);
return Optional.ofNullable(res);
} catch (Exception e) {
log.catching(e);
return Optional.empty();
}
});
}
use of meghanada.reflect.MemberDescriptor in project meghanada-server by mopemope.
the class TypeInfoSearcher method getMembers.
private static List<MemberDescriptor> getMembers(String fqcn, String clsName) {
List<MemberDescriptor> results = new ArrayList<>();
CachedASMReflector reflector = CachedASMReflector.getInstance();
for (MemberDescriptor md : reflector.reflect(fqcn)) {
CandidateUnit.MemberType type = md.getMemberType();
String nm = ClassNameUtils.getSimpleName(md.getDeclaringClass());
boolean own = clsName.equals(nm);
if (type == CandidateUnit.MemberType.CONSTRUCTOR) {
if (own) {
results.add(md);
}
} else {
if (md.isPrivate()) {
if (own) {
results.add(md);
}
} else {
results.add(md);
}
}
}
return results;
}
Aggregations