Search in sources :

Example 6 with MemberDescriptor

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();
    }
}
Also used : AfterClass(org.junit.AfterClass) MethodDescriptor(meghanada.reflect.MethodDescriptor) BeforeClass(org.junit.BeforeClass) Assert.assertNotNull(org.junit.Assert.assertNotNull) Stopwatch(com.google.common.base.Stopwatch) ClassIndex(meghanada.reflect.ClassIndex) Config.timeIt(meghanada.config.Config.timeIt) Test(org.junit.Test) Config.debugIt(meghanada.config.Config.debugIt) File(java.io.File) MemberDescriptor(meghanada.reflect.MemberDescriptor) List(java.util.List) Map(java.util.Map) GradleTestBase(meghanada.GradleTestBase) Config(meghanada.config.Config) Assert.assertEquals(org.junit.Assert.assertEquals) Stopwatch(com.google.common.base.Stopwatch) List(java.util.List) File(java.io.File) Map(java.util.Map) Test(org.junit.Test)

Example 7 with MemberDescriptor

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());
    });
}
Also used : ClassIndex(meghanada.reflect.ClassIndex) MemberDescriptor(meghanada.reflect.MemberDescriptor) File(java.io.File) Test(org.junit.Test)

Example 8 with MemberDescriptor

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();
    }
}
Also used : AfterClass(org.junit.AfterClass) MethodDescriptor(meghanada.reflect.MethodDescriptor) BeforeClass(org.junit.BeforeClass) Assert.assertNotNull(org.junit.Assert.assertNotNull) Stopwatch(com.google.common.base.Stopwatch) ClassIndex(meghanada.reflect.ClassIndex) Config.timeIt(meghanada.config.Config.timeIt) Test(org.junit.Test) Config.debugIt(meghanada.config.Config.debugIt) File(java.io.File) MemberDescriptor(meghanada.reflect.MemberDescriptor) List(java.util.List) Map(java.util.Map) GradleTestBase(meghanada.GradleTestBase) Config(meghanada.config.Config) Assert.assertEquals(org.junit.Assert.assertEquals) Config(meghanada.config.Config) Stopwatch(com.google.common.base.Stopwatch) List(java.util.List) File(java.io.File) Map(java.util.Map) Test(org.junit.Test)

Example 9 with MemberDescriptor

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();
        }
    });
}
Also used : Entity(jetbrains.exodus.entitystore.Entity) EntityIterable(jetbrains.exodus.entitystore.EntityIterable) MemberDescriptor(meghanada.reflect.MemberDescriptor) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 10 with MemberDescriptor

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;
}
Also used : CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) MemberDescriptor(meghanada.reflect.MemberDescriptor) ArrayList(java.util.ArrayList) CandidateUnit(meghanada.reflect.CandidateUnit)

Aggregations

MemberDescriptor (meghanada.reflect.MemberDescriptor)26 File (java.io.File)17 Map (java.util.Map)17 ClassIndex (meghanada.reflect.ClassIndex)16 Stopwatch (com.google.common.base.Stopwatch)15 List (java.util.List)15 Config (meghanada.config.Config)15 MethodDescriptor (meghanada.reflect.MethodDescriptor)13 Test (org.junit.Test)13 GradleTestBase (meghanada.GradleTestBase)12 Config.debugIt (meghanada.config.Config.debugIt)12 Config.timeIt (meghanada.config.Config.timeIt)12 AfterClass (org.junit.AfterClass)12 Assert.assertEquals (org.junit.Assert.assertEquals)12 Assert.assertNotNull (org.junit.Assert.assertNotNull)12 BeforeClass (org.junit.BeforeClass)12 CandidateUnit (meghanada.reflect.CandidateUnit)6 CachedASMReflector (meghanada.reflect.asm.CachedASMReflector)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4