Search in sources :

Example 1 with ClassIndex

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

the class ASMReflectorTest method testReflectAll6.

@Test
public void testReflectAll6() throws Exception {
    ASMReflector asmReflector = ASMReflector.getInstance();
    Stopwatch stopwatch = Stopwatch.createUnstarted();
    {
        File jar = getRTJar();
        Map<String, ClassIndex> index = asmReflector.getClassIndexes(jar);
        String fqcn = "java.util.jar.JarFile";
        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 2 with ClassIndex

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

the class ASMReflectorTest method testReflectWithGenerics3.

@Test
public void testReflectWithGenerics3() throws Exception {
    ASMReflector asmReflector = ASMReflector.getInstance();
    Stopwatch stopwatch = Stopwatch.createUnstarted();
    {
        String fqcn = "java.util.Map<? extends String, ? extends Long>";
        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(34, memberDescriptors.size());
        } else {
            assertEquals(47, 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 3 with ClassIndex

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

the class ASMReflectorTest method testGetClasses1.

@Test
public void testGetClasses1() throws Exception {
    File jar = getJar("junit:junit");
    ASMReflector asmReflector = ASMReflector.getInstance();
    Map<ClassIndex, File> classIndex = timeIt(() -> asmReflector.getClasses(jar));
    assertEquals(189, classIndex.size());
// classIndex.forEach((classIndex1, file) -> System.out.println(classIndex1));
}
Also used : ClassIndex(meghanada.reflect.ClassIndex) File(java.io.File) Test(org.junit.Test)

Example 4 with ClassIndex

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

the class ASMReflectorTest method testReflectWithGenerics1.

@Test
public void testReflectWithGenerics1() throws Exception {
    ASMReflector asmReflector = ASMReflector.getInstance();
    Stopwatch stopwatch = Stopwatch.createUnstarted();
    {
        String fqcn = "java.util.Map";
        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.getDeclaration()));
        Config config = Config.load();
        if (config.isJava8()) {
            assertEquals(34, memberDescriptors.size());
        } else {
            assertEquals(47, memberDescriptors.size());
        }
        stopwatch.reset();
        memberDescriptors.stream().filter(memberDescriptor -> memberDescriptor.getName().equals("entrySet")).forEach(memberDescriptor -> {
            if (memberDescriptor instanceof MethodDescriptor) {
                MethodDescriptor methodDescriptor = (MethodDescriptor) memberDescriptor;
                methodDescriptor.getTypeParameterMap().put("K", "String");
                methodDescriptor.getTypeParameterMap().put("V", "Long");
                System.out.println(memberDescriptor.getReturnType());
                assertEquals("java.util.Set<java.util.Map$Entry<String, Long>>", memberDescriptor.getReturnType());
            }
        });
    }
}
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) MethodDescriptor(meghanada.reflect.MethodDescriptor) Test(org.junit.Test)

Example 5 with ClassIndex

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

the class ASMReflectorTest method testReflectAll1.

@Test
public void testReflectAll1() throws Exception {
    ASMReflector asmReflector = ASMReflector.getInstance();
    Stopwatch stopwatch = Stopwatch.createUnstarted();
    {
        File jar = getRTJar();
        String fqcn = "java.util.stream.Stream<java.util.List<java.lang.String>>";
        Map<String, ClassIndex> index = asmReflector.getClassIndexes(jar);
        final InheritanceInfo info = asmReflector.getReflectInfo(index, fqcn);
        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());
        });
        stopwatch.reset();
        stopwatch.start();
        List<MemberDescriptor> memberDescriptors2 = asmReflector.reflectAll(info);
        System.out.println(stopwatch.stop());
        System.out.println(memberDescriptors2.size());
    }
}
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)

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