Search in sources :

Example 11 with ClassIndex

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

the class ClassSignatureVisitorTest method testFunctionType1.

@org.junit.Test
public void testFunctionType1() throws Exception {
    String fqcn = "java.util.function.Predicate";
    File jar = getRTJar();
    ClassSignatureVisitor visitor = doAnalyze(jar, fqcn);
    assertEquals("java.util.function.Predicate", visitor.getName());
    List<String> expected = new ArrayList<>();
    expected.add("T");
    assertEquals(expected, visitor.getTypeParameters());
    final ClassIndex index = visitor.getClassIndex();
    assertEquals(true, index.isInterface());
    assertEquals(0, index.getSupers().size());
}
Also used : ClassIndex(meghanada.reflect.ClassIndex) ArrayList(java.util.ArrayList) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.Test)

Example 12 with ClassIndex

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

the class TestRunner method getTestClass.

private List<Class<?>> getTestClass(String testName) throws ClassNotFoundException {
    List<Class<?>> classes = new ArrayList<>();
    CachedASMReflector cachedASMReflector = CachedASMReflector.getInstance();
    for (ClassIndex classIndex : cachedASMReflector.getGlobalClassIndex().values()) {
        String fqcn = classIndex.getReturnType();
        String className = classIndex.getName();
        if (fqcn.equals(testName) || className.equals(testName) || fqcn.matches(testName)) {
            classes.add(Class.forName(fqcn));
        }
    }
    return classes;
}
Also used : ClassIndex(meghanada.reflect.ClassIndex) CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) ArrayList(java.util.ArrayList)

Example 13 with ClassIndex

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

the class MemberCacheLoader method loadFromReflector.

private List<MemberDescriptor> loadFromReflector(String fqcn) {
    final String initName = ClassNameUtils.getSimpleName(fqcn);
    final ASMReflector asmReflector = ASMReflector.getInstance();
    Map<String, ClassIndex> index = CachedASMReflector.getInstance().getGlobalClassIndex();
    final InheritanceInfo info = asmReflector.getReflectInfo(index, fqcn);
    final List<MemberDescriptor> result = asmReflector.reflectAll(info);
    return result.stream().filter(md -> {
        if (md.matchType(CandidateUnit.MemberType.CONSTRUCTOR)) {
            final String name = ClassNameUtils.getSimpleName(md.getName());
            return name.equals(initName);
        }
        return true;
    }).collect(Collectors.toList());
}
Also used : ClassName(meghanada.utils.ClassName) Stopwatch(com.google.common.base.Stopwatch) FunctionUtils.wrapIOConsumer(meghanada.utils.FunctionUtils.wrapIOConsumer) InheritanceInfo(meghanada.reflect.asm.InheritanceInfo) Map(java.util.Map) CandidateUnit(meghanada.reflect.CandidateUnit) Objects.isNull(java.util.Objects.isNull) FunctionUtils.wrapIO(meghanada.utils.FunctionUtils.wrapIO) RemovalNotification(com.google.common.cache.RemovalNotification) ClassIndex(meghanada.reflect.ClassIndex) IOException(java.io.IOException) ProjectDatabaseHelper(meghanada.store.ProjectDatabaseHelper) CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) Collectors(java.util.stream.Collectors) File(java.io.File) CacheLoader(com.google.common.cache.CacheLoader) MemberDescriptor(meghanada.reflect.MemberDescriptor) List(java.util.List) Logger(org.apache.logging.log4j.Logger) RemovalCause(com.google.common.cache.RemovalCause) ClassNameUtils(meghanada.utils.ClassNameUtils) Optional(java.util.Optional) RemovalListener(com.google.common.cache.RemovalListener) ASMReflector(meghanada.reflect.asm.ASMReflector) Objects.nonNull(java.util.Objects.nonNull) Collections(java.util.Collections) Config(meghanada.config.Config) LogManager(org.apache.logging.log4j.LogManager) ClassIndex(meghanada.reflect.ClassIndex) InheritanceInfo(meghanada.reflect.asm.InheritanceInfo) MemberDescriptor(meghanada.reflect.MemberDescriptor) CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) ASMReflector(meghanada.reflect.asm.ASMReflector)

Example 14 with ClassIndex

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

the class JavaCompletion method completionImport.

private static List<ClassIndex> completionImport(final String searchWord) {
    final Config config = Config.load();
    final boolean useFuzzySearch = config.useClassFuzzySearch();
    final int idx = searchWord.lastIndexOf(':');
    final Stream<ClassIndex> stream;
    final CachedASMReflector reflector = CachedASMReflector.getInstance();
    if (idx > 0) {
        final String classPrefix = searchWord.substring(idx + 1, searchWord.length());
        if (useFuzzySearch) {
            stream = reflector.fuzzySearchClassesStream(classPrefix.toLowerCase(), false);
        } else {
            stream = reflector.searchClassesStream(classPrefix.toLowerCase(), true, false);
        }
        return stream.map(cl -> {
            cl.setMemberType(CandidateUnit.MemberType.IMPORT);
            return cl;
        }).sorted(comparing(classPrefix)).collect(Collectors.toList());
    }
    return Collections.emptyList();
}
Also used : ClassIndex(meghanada.reflect.ClassIndex) CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) Config(meghanada.config.Config)

Example 15 with ClassIndex

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

the class JavaCompletion method completionNewKeyword.

private Collection<? extends CandidateUnit> completionNewKeyword(Source source, String searchWord) {
    final boolean useFuzzySearch = Config.load().useClassFuzzySearch();
    // list all classes
    final int idx = searchWord.lastIndexOf(':');
    if (idx > 0) {
        final List<ClassIndex> result;
        final String classPrefix = searchWord.substring(idx + 1, searchWord.length());
        CachedASMReflector reflector = CachedASMReflector.getInstance();
        if (useFuzzySearch) {
            result = reflector.fuzzySearchClasses(classPrefix.toLowerCase());
        } else {
            result = reflector.searchClasses(classPrefix.toLowerCase());
        }
        result.sort(comparing(source, classPrefix));
        return result;
    }
    return JavaCompletion.completionNewKeyword(source).stream().sorted(comparing(source, "")).collect(Collectors.toList());
}
Also used : ClassIndex(meghanada.reflect.ClassIndex) CachedASMReflector(meghanada.reflect.asm.CachedASMReflector)

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