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());
}
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;
}
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());
}
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();
}
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());
}
Aggregations