Search in sources :

Example 21 with ClassIndex

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

the class ProjectDatabaseTest method testStore01.

@Test
public void testStore01() throws Exception {
    String name = "java.lang.String";
    ClassIndex ci = null;
    int count = 10;
    for (int i = 0; i < count; i++) {
        ci = timeItF("store:{} count:" + i, () -> {
            ClassIndex c = new ClassIndex(name, Collections.emptyList(), Collections.emptyList());
            database.storeObject(c);
            return c;
        });
    }
    for (int i = 0; i < count; i++) {
        ClassIndex ci2 = timeItF("load:{} count:" + i, () -> database.loadObject(ClassIndex.ENTITY_TYPE, name, ClassIndex.class));
        assertEquals(ci, ci2);
    }
    long size = database.size(ClassIndex.ENTITY_TYPE);
    assertEquals(1, size);
}
Also used : ClassIndex(meghanada.reflect.ClassIndex) Test(org.junit.Test)

Example 22 with ClassIndex

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

the class ProjectDatabaseTest method testStore02.

@Test
public void testStore02() throws Exception {
    String name = "java.lang.String";
    ClassIndex ci = null;
    int count = 100;
    for (int i = 0; i < count; i++) {
        ci = timeItF("store:{} count:" + i, () -> {
            ClassIndex c = new ClassIndex(name, Collections.emptyList(), Collections.emptyList());
            database.storeObject(c, false);
            return c;
        });
    }
    for (int i = 0; i < count; i++) {
        ClassIndex ci2 = timeItF("load:{} count:" + i, () -> database.loadObject(ClassIndex.ENTITY_TYPE, name, ClassIndex.class));
        assertEquals(ci, ci2);
    }
    long size = database.size(ClassIndex.ENTITY_TYPE);
    assertEquals(1, size);
}
Also used : ClassIndex(meghanada.reflect.ClassIndex) Test(org.junit.Test)

Example 23 with ClassIndex

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

the class ProjectDatabaseTest method testStore03.

@Test
public void testStore03() throws Exception {
    String name = "java.lang.String";
    ClassIndex ci = null;
    int count = 100;
    List<ClassIndex> lst = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        ClassIndex c = new ClassIndex(name + i, Collections.emptyList(), Collections.emptyList());
        lst.add(c);
    }
    database.storeObjects(lst, true);
    lst.forEach(c -> {
        System.out.println(c.getEntityId());
    });
}
Also used : ClassIndex(meghanada.reflect.ClassIndex) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 24 with ClassIndex

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

the class ASMReflectorTest method testReflectInterface1.

@Test
public void testReflectInterface1() throws Exception {
    ASMReflector asmReflector = ASMReflector.getInstance();
    Stopwatch stopwatch = Stopwatch.createUnstarted();
    {
        String fqcn = "com.google.common.eventbus.SubscriberExceptionHandler";
        File jar = getJar("guava");
        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());
            System.out.println("Return: " + m.getRawReturnType());
        });
        assertEquals(1, 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 25 with ClassIndex

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

the class ASMReflectorTest method testReflectWithGenerics4.

@Test
public void testReflectWithGenerics4() throws Exception {
    ASMReflector asmReflector = ASMReflector.getInstance();
    Stopwatch stopwatch = Stopwatch.createUnstarted();
    {
        String fqcn = "com.google.common.cache.CacheBuilder<Object, Object>";
        File jar = getJar("guava");
        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());
        // System.out.println("Return: " + m.getRawReturnType());
        });
        assertEquals(61, 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)

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