use of meghanada.analyze.MethodScope in project meghanada-server by mopemope.
the class LocationSearcher method getMethodLocationFromProject.
private Optional<Location> getMethodLocationFromProject(final String methodName, final List<String> arguments, final File file) {
try {
final Source declaringClassSrc = getSource(project, file);
final String path = declaringClassSrc.getFile().getPath();
return declaringClassSrc.getClassScopes().stream().flatMap(ts -> ts.getScopes().stream()).filter(bs -> {
if (!methodName.equals(bs.getName())) {
return false;
}
if (!(bs instanceof MethodScope)) {
return false;
}
final MethodScope methodScope = (MethodScope) bs;
final List<String> parameters = methodScope.getParameters();
return ClassNameUtils.compareArgumentType(arguments, parameters);
}).map(MethodScope.class::cast).map(ms -> new Location(path, ms.getBeginLine(), ms.getNameRange().begin.column)).findFirst();
} catch (ExecutionException e) {
throw new UncheckedExecutionException(e);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of meghanada.analyze.MethodScope in project meghanada-server by mopemope.
the class ReferenceSearcher method searchMemberCondition.
private static Optional<SearchCondition> searchMemberCondition(Source source, int line, int col, String symbol) {
EntryMessage msg = log.traceEntry("line={} col={} symbol={}", line, col, symbol);
for (ClassScope classScope : source.getClassScopes()) {
for (Variable variable : classScope.getVariables()) {
if (variable.isField) {
Position pos = variable.range.begin;
String name = variable.name;
if (pos.line == line && name.equals(symbol)) {
String clazz = classScope.getFQCN();
SearchCondition condition = new SearchCondition(clazz, name, SearchCondition.Type.FIELD);
return Optional.of(condition);
}
}
}
for (BlockScope blockScope : classScope.getScopes()) {
if (blockScope instanceof MethodScope) {
MethodScope methodScope = ((MethodScope) blockScope);
Position pos = methodScope.getNameRange().begin;
String name = methodScope.getName();
if (pos.line == line && name.equals(symbol)) {
String clazz = classScope.getFQCN();
SearchCondition condition = new SearchCondition(clazz, name, SearchCondition.Type.METHOD, methodScope.getParameters());
return Optional.of(condition);
}
}
}
}
log.traceExit(msg);
return Optional.empty();
}
Aggregations