use of meghanada.reflect.FieldDescriptor in project meghanada-server by mopemope.
the class JavaCompletion method completionFieldsOrMethods.
private static Collection<? extends CandidateUnit> completionFieldsOrMethods(final Source source, final int line, final String var, final String target) {
// completionAt methods or fields
if (var.equals("this")) {
return JavaCompletion.completionThis(source, line, target);
}
if (var.equals("super")) {
return JavaCompletion.completionSuper(source, line, target);
}
log.debug("search '{}' field or method", var);
String ownPackage = source.getPackageName();
final Set<CandidateUnit> res = new HashSet<>(32);
{
// completion static method
String fqcn = source.getImportedClassFQCN(var, null);
if (nonNull(fqcn)) {
if (!fqcn.contains(".") && !ownPackage.isEmpty()) {
fqcn = ownPackage + '.' + fqcn;
}
final Collection<? extends CandidateUnit> result = JavaCompletion.reflect(ownPackage, fqcn, true, false, target);
res.addAll(result);
// add inner class
final Collection<? extends CandidateUnit> inners = CachedASMReflector.getInstance().searchInnerClasses(fqcn);
res.addAll(inners);
if (!res.isEmpty()) {
return res;
}
}
}
{
final Map<String, Variable> symbols = source.getDeclaratorMap(line);
final Variable variable = symbols.get(var);
if (nonNull(variable)) {
// get data from reflector
String fqcn = variable.fqcn;
if (!fqcn.contains(".")) {
fqcn = ownPackage + '.' + fqcn;
}
final Collection<? extends CandidateUnit> reflect = JavaCompletion.reflect(ownPackage, fqcn, target);
res.addAll(reflect);
}
}
{
for (final ClassScope cs : source.getClassScopes()) {
final String fqcn = cs.getFQCN();
final Optional<MemberDescriptor> fieldResult = JavaCompletion.reflectSelf(fqcn, true, target).stream().filter(c -> c instanceof FieldDescriptor && c.getName().equals(var)).findFirst();
if (fieldResult.isPresent()) {
final MemberDescriptor memberDescriptor = fieldResult.orElse(null);
final String returnType = memberDescriptor.getRawReturnType();
final Collection<? extends CandidateUnit> reflect = reflect(ownPackage, returnType, target);
res.addAll(reflect);
}
}
}
{
// java.lang
final String fqcn = "java.lang." + var;
final Collection<? extends CandidateUnit> result = JavaCompletion.reflect(ownPackage, fqcn, true, false, target);
res.addAll(result);
}
{
String fqcn = var;
if (!ownPackage.isEmpty()) {
fqcn = ownPackage + '.' + var;
}
final Collection<? extends CandidateUnit> reflectResults = JavaCompletion.reflect(ownPackage, fqcn, true, false, target);
res.addAll(reflectResults);
final CachedASMReflector reflector = CachedASMReflector.getInstance();
if (reflector.containsFQCN(fqcn)) {
final Collection<? extends CandidateUnit> inners = reflector.searchInnerClasses(fqcn);
res.addAll(inners);
}
}
if (line > 0 && res.isEmpty()) {
List<MethodCall> calls = source.getMethodCall(line - 1);
long lastCol = 0;
String lastFQCN = null;
for (MethodCall call : calls) {
long col = call.nameRange.begin.column;
String name = ClassNameUtils.getSimpleName(call.name);
if (name.equals(var) && col > lastCol) {
lastFQCN = call.returnType;
lastCol = col;
}
}
if (nonNull(lastFQCN)) {
res.addAll(reflectWithFQCN(lastFQCN, ""));
}
}
return res;
}
use of meghanada.reflect.FieldDescriptor in project meghanada-server by mopemope.
the class FieldAnalyzeVisitor method visitEnd.
@Override
public void visitEnd() {
final EntryMessage m = log.traceEntry("fieldSignature={}", fieldSignature);
final String modifier = ASMReflector.toModifier(access, false);
final String fqcn = fieldSignatureVisitor.getResult();
final FieldDescriptor fd = new FieldDescriptor(this.classAnalyzeVisitor.className, this.name, modifier, fqcn);
fd.setTypeParameters(fieldSignatureVisitor.getTypeParameters());
this.classAnalyzeVisitor.getMembers().add(fd);
log.traceExit(m);
}
Aggregations