use of meghanada.reflect.MethodDescriptor in project meghanada-server by mopemope.
the class ASMReflectorTest method testReflectWithGenerics1.
@Test
public void testReflectWithGenerics1() throws Exception {
ASMReflector asmReflector = ASMReflector.getInstance();
Stopwatch stopwatch = Stopwatch.createUnstarted();
{
String fqcn = "java.util.Map";
File jar = getRTJar();
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()));
Config config = Config.load();
if (config.isJava8()) {
assertEquals(34, memberDescriptors.size());
} else {
assertEquals(47, memberDescriptors.size());
}
stopwatch.reset();
memberDescriptors.stream().filter(memberDescriptor -> memberDescriptor.getName().equals("entrySet")).forEach(memberDescriptor -> {
if (memberDescriptor instanceof MethodDescriptor) {
MethodDescriptor methodDescriptor = (MethodDescriptor) memberDescriptor;
methodDescriptor.getTypeParameterMap().put("K", "String");
methodDescriptor.getTypeParameterMap().put("V", "Long");
System.out.println(memberDescriptor.getReturnType());
assertEquals("java.util.Set<java.util.Map$Entry<String, Long>>", memberDescriptor.getReturnType());
}
});
}
}
use of meghanada.reflect.MethodDescriptor in project meghanada-server by mopemope.
the class MethodAnalyzeVisitor method toMemberDescriptor.
private void toMemberDescriptor() {
String modifier = ASMReflector.toModifier(this.access, this.hasDefault);
if (this.interfaceMethod) {
modifier = ClassNameUtils.replace(modifier, "abstract", "").trim();
}
final CandidateUnit.MemberType memberType = name.equals("<init>") ? CandidateUnit.MemberType.CONSTRUCTOR : CandidateUnit.MemberType.METHOD;
final String methodName = memberType == CandidateUnit.MemberType.CONSTRUCTOR ? this.classAnalyzeVisitor.className : this.name;
final EntryMessage message = log.traceEntry("className={} memberType={} methodName={} returnType={}", this.classAnalyzeVisitor.className, methodName, memberType, this.returnType);
if (methodName.startsWith("lambda$")) {
// skip
log.traceExit(message);
return;
}
if (memberType == CandidateUnit.MemberType.CONSTRUCTOR && methodName.equals(ClassNameUtils.OBJECT_CLASS)) {
// skip
log.traceExit(message);
return;
}
final String returnFQCN = memberType == CandidateUnit.MemberType.CONSTRUCTOR ? methodName : this.returnType.getFQCN();
final List<MethodParameter> methodParameters = this.parameterTypes.stream().map(typeInfo -> new MethodParameter(typeInfo.getFQCN(), typeInfo.paramName)).collect(Collectors.toList());
final MethodDescriptor descriptor = new MethodDescriptor(this.classAnalyzeVisitor.className, methodName, modifier, methodParameters, this.exceptions, returnFQCN, this.hasDefault, memberType);
descriptor.setTypeParameters(this.typeParameters);
log.trace("formalType={}", this.formalType);
if (this.formalType != null) {
descriptor.formalType = this.formalType.toString();
}
this.classAnalyzeVisitor.members.add(descriptor);
log.traceExit(message);
}
use of meghanada.reflect.MethodDescriptor in project meghanada-server by mopemope.
the class ReferenceSearcher method searchMethodCallCondition.
private static Optional<SearchCondition> searchMethodCallCondition(Source source, int line, int col, String symbol) {
EntryMessage msg = log.traceEntry("line={} col={} symbol={}", line, col, symbol);
Optional<MethodCall> mcResult = source.getMethodCall(line, col, true);
Optional<SearchCondition> result = mcResult.map(mc -> {
String methodName = mc.name;
List<String> arguments = mc.getArguments();
String declaringClass = mc.declaringClass;
if (isNull(declaringClass)) {
return null;
}
MemberDescriptor method = searchMatchMethod(declaringClass, methodName, arguments).orElseGet(() -> searchMatchConstructor(declaringClass, arguments).orElse(null));
if (isNull(method)) {
// not match
return null;
}
MethodDescriptor md = (MethodDescriptor) method;
if (md.getMemberType().equals(CandidateUnit.MemberType.CONSTRUCTOR)) {
return new SearchCondition(mc.declaringClass, mc.name, SearchCondition.Type.CONSTRUCTOR, mc.getArguments());
}
return new SearchCondition(mc.declaringClass, mc.name, SearchCondition.Type.METHOD, mc.getArguments());
});
log.traceExit(msg);
return result;
}
Aggregations