Search in sources :

Example 6 with ClassIndex

use of meghanada.reflect.ClassIndex in project meghanada-server by mopemope.

the class ASMReflectorTest method testReflectAll7.

@Test
public void testReflectAll7() throws Exception {
    ASMReflector asmReflector = ASMReflector.getInstance();
    Stopwatch stopwatch = Stopwatch.createUnstarted();
    {
        File jar = getJar("guava");
        Map<String, ClassIndex> index = asmReflector.getClassIndexes(jar);
        String fqcn = "com.google.common.base.Joiner";
        final InheritanceInfo info = asmReflector.getReflectInfo(index, fqcn);
        System.out.println(info);
        stopwatch.start();
        List<MemberDescriptor> memberDescriptors1 = asmReflector.reflectAll(info);
        System.out.println(stopwatch.stop());
        System.out.println(memberDescriptors1.size());
        memberDescriptors1.forEach(md -> {
            System.out.println(md.getDeclaration());
        // System.out.println(md.declaration);
        });
    }
}
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 ClassIndex

use of meghanada.reflect.ClassIndex 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 8 with ClassIndex

use of meghanada.reflect.ClassIndex 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 9 with ClassIndex

use of meghanada.reflect.ClassIndex 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 10 with ClassIndex

use of meghanada.reflect.ClassIndex in project meghanada-server by mopemope.

the class ASMReflectorTest method testGetClasses2.

@Test
public void testGetClasses2() throws Exception {
    File jar = getRTJar();
    ASMReflector asmReflector = ASMReflector.getInstance();
    Map<ClassIndex, File> classIndex = timeIt(() -> asmReflector.getClasses(jar));
    Config config = Config.load();
    if (config.isJava8()) {
        assertEquals(4105, classIndex.size());
    } else {
        assertEquals(6940, classIndex.size());
    }
// classIndex.forEach((i, file) -> System.out.println(i));
}
Also used : ClassIndex(meghanada.reflect.ClassIndex) Config(meghanada.config.Config) File(java.io.File) Test(org.junit.Test)

Aggregations

ClassIndex (meghanada.reflect.ClassIndex)42 File (java.io.File)25 Test (org.junit.Test)22 Config (meghanada.config.Config)16 List (java.util.List)15 Map (java.util.Map)15 MemberDescriptor (meghanada.reflect.MemberDescriptor)15 Stopwatch (com.google.common.base.Stopwatch)13 GradleTestBase (meghanada.GradleTestBase)12 Config.debugIt (meghanada.config.Config.debugIt)12 Config.timeIt (meghanada.config.Config.timeIt)12 MethodDescriptor (meghanada.reflect.MethodDescriptor)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 ArrayList (java.util.ArrayList)10 CachedASMReflector (meghanada.reflect.asm.CachedASMReflector)8 JarFile (java.util.jar.JarFile)7 IOException (java.io.IOException)4