Search in sources :

Example 36 with ClassIndex

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

the class ASMReflector method searchReflectInfo.

private InheritanceInfo searchReflectInfo(final Map<String, ClassIndex> index, final String name, final InheritanceInfo info) {
    for (Map.Entry<String, ClassIndex> entry : index.entrySet()) {
        final ClassIndex classIndex = entry.getValue();
        final File file = new File(classIndex.getFilePath());
        final String searchName = ClassNameUtils.removeTypeParameter(name);
        final String target = classIndex.toString();
        if (target.equals(searchName)) {
            this.addInheritance(index, name, info, classIndex, file);
            break;
        }
        // 
        final Optional<String> opt = ClassNameUtils.toInnerClassName(name);
        if (opt.isPresent()) {
            final String inner = opt.get();
            if (target.equals(inner)) {
                if (!info.classFileMap.containsKey(file)) {
                    info.classFileMap.put(file, new ArrayList<>(8));
                }
                info.inherit.add(name);
                info.classFileMap.get(file).add(name);
                final List<String> supers = ASMReflector.replaceSuperClassTypeParameters(name, classIndex);
                Collections.reverse(supers);
                supers.forEach(superClass -> {
                    InheritanceInfo ignored = this.searchReflectInfo(index, superClass, info);
                });
                break;
            }
        }
    }
    return info;
}
Also used : ClassIndex(meghanada.reflect.ClassIndex) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 37 with ClassIndex

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

the class CachedASMReflector method cloneClassIndex.

private ClassIndex cloneClassIndex(ClassIndex c) {
    ClassIndex ci = c.clone();
    if (ci.isInnerClass()) {
        String p = ci.getPackage();
        if (!p.isEmpty()) {
            String declaration = ci.getDisplayDeclaration();
            String clazzName = declaration.substring(p.length() + 1);
            ci.setName(clazzName);
        }
    }
    return ci;
}
Also used : ClassIndex(meghanada.reflect.ClassIndex)

Example 38 with ClassIndex

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

the class CachedASMReflector method fuzzySearchClasses.

private List<ClassIndex> fuzzySearchClasses(final String keyword, final boolean anno) {
    final int length = keyword.length() + 1;
    final List<ClassIndex> result = new ArrayList<>(64);
    for (final ClassIndex c : this.globalClassIndex.values()) {
        if (anno && !c.isAnnotation()) {
            continue;
        }
        final String name = c.getName();
        final int score = StringUtils.getFuzzyDistance(name, keyword, Locale.ENGLISH);
        if (score >= length) {
            result.add(cloneClassIndex(c));
        }
    }
    return result;
}
Also used : ClassIndex(meghanada.reflect.ClassIndex) ArrayList(java.util.ArrayList)

Example 39 with ClassIndex

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

the class ClassAnalyzeVisitor method visit.

@Override
public void visit(int api, int access, String name, String signature, String superClass, String[] interfaces) {
    // log.debug("Name:{}", name);
    // call class
    this.access = access;
    final boolean isInterface = (Opcodes.ACC_INTERFACE & access) == Opcodes.ACC_INTERFACE;
    if (signature != null) {
        // generics
        // log.debug("name {} sig {}", name, signature);
        final SignatureReader signatureReader = new SignatureReader(signature);
        ClassSignatureVisitor classSignatureVisitor = new ClassSignatureVisitor(this.className, isInterface);
        signatureReader.accept(classSignatureVisitor);
        this.classTypeParameters = classSignatureVisitor.getTypeParameters();
        this.classIndex = classSignatureVisitor.getClassIndex();
        if (!this.classIndex.getSupers().contains(ClassNameUtils.OBJECT_CLASS)) {
            this.classIndex.addSuper(ClassNameUtils.OBJECT_CLASS);
        }
    } else {
        this.classTypeParameters = new ArrayList<>(4);
        final List<String> supers = new ArrayList<>(4);
        if (superClass != null) {
            final String superClassFQCN = ClassNameUtils.replaceSlash(superClass);
            supers.add(superClassFQCN);
        }
        Arrays.stream(interfaces).forEach(interfaceName -> supers.add(ClassNameUtils.replaceSlash(interfaceName)));
        this.classIndex = new ClassIndex(this.className, new ArrayList<>(4), supers);
        this.classIndex.setInterface(isInterface);
    }
}
Also used : ClassIndex(meghanada.reflect.ClassIndex) SignatureReader(org.objectweb.asm.signature.SignatureReader) ArrayList(java.util.ArrayList)

Example 40 with ClassIndex

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

the class ClassSignatureVisitor method getClassIndex.

ClassIndex getClassIndex() {
    final ClassIndex classIndex = new ClassIndex(this.getName(), this.getTypeParameters(), this.superClasses.stream().map(ClassInfo::toString).collect(Collectors.toList()));
    classIndex.setInterface(this.isInterface);
    return classIndex;
}
Also used : ClassIndex(meghanada.reflect.ClassIndex)

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