Search in sources :

Example 41 with ClassIndex

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

the class ReferenceSearcher method searchClassCondition.

private static Optional<SearchCondition> searchClassCondition(Source source, int line, int col, String symbol) {
    final CachedASMReflector reflector = CachedASMReflector.getInstance();
    final EntryMessage entryMessage = log.traceEntry("line={} col={} symbol={}", line, col, symbol);
    Optional<SearchCondition> result;
    String fqcn = source.getImportedClassFQCN(symbol, null);
    if (isNull(fqcn)) {
        if (!source.getPackageName().isEmpty()) {
            fqcn = source.getPackageName() + '.' + symbol;
            result = reflector.containsClassIndex(fqcn).map(index -> {
                SearchCondition sc = new SearchCondition(index.getRawDeclaration(), index.getName(), SearchCondition.Type.CLASS);
                return Optional.of(sc);
            }).orElseGet(() -> {
                final Set<String> parents = new HashSet<>(8);
                for (final ClassScope classScope : source.getClassScopes()) {
                    final String className = classScope.getFQCN();
                    parents.add(className);
                }
                parents.addAll(source.importClasses);
                for (final ClassIndex index : reflector.searchInnerClasses(parents)) {
                    final String returnType = index.getReturnType();
                    if (returnType.endsWith(symbol)) {
                        SearchCondition sc = new SearchCondition(index.getRawDeclaration(), index.getName(), SearchCondition.Type.CLASS);
                        return Optional.of(sc);
                    }
                }
                return Optional.empty();
            });
        } else {
            result = Optional.empty();
        }
    } else {
        SearchCondition sc = new SearchCondition(fqcn, ClassNameUtils.getSimpleName(fqcn), SearchCondition.Type.CLASS);
        result = Optional.of(sc);
    }
    log.traceExit(entryMessage);
    return result;
}
Also used : ClassIndex(meghanada.reflect.ClassIndex) CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) HashSet(java.util.HashSet) Set(java.util.Set) EntryMessage(org.apache.logging.log4j.message.EntryMessage) ClassScope(meghanada.analyze.ClassScope)

Example 42 with ClassIndex

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

the class MemberCacheLoader method getClassFile.

private static File getClassFile(String fqcn) {
    Map<String, ClassIndex> globalClassIndex = CachedASMReflector.getInstance().getGlobalClassIndex();
    ClassIndex classIndex = globalClassIndex.get(fqcn);
    if (nonNull(classIndex)) {
        String filePath = classIndex.getFilePath();
        if (nonNull(filePath)) {
            return new File(filePath);
        }
    }
    return null;
}
Also used : ClassIndex(meghanada.reflect.ClassIndex) File(java.io.File)

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