use of meghanada.analyze.Range in project meghanada-server by mopemope.
the class ReferenceSearcher method searchMethodCallReferences.
private static List<Reference> searchMethodCallReferences(Source src, SearchCondition sc) throws IOException {
List<String> lines = FileUtils.readLines(src.getFile());
int size = lines.size();
List<Reference> result = new ArrayList<>(size);
Collection<MethodCall> methodCalls = src.getMethodCalls();
for (MethodCall mc : methodCalls) {
String declaringClass = mc.declaringClass;
String methodName = mc.name;
boolean compare = ClassNameUtils.compareArgumentType(mc.getArguments(), sc.arguments);
if (compare && sc.declaringClass.equals(declaringClass) && sc.name.equals(methodName)) {
Range range = mc.nameRange;
long line = range.begin.line;
long column = range.begin.column;
String code = StringEscapeUtils.escapeJava(lines.get((int) line - 1));
Reference ref = new Reference(src.filePath, line, column, code);
result.add(ref);
}
}
return result;
}
use of meghanada.analyze.Range in project meghanada-server by mopemope.
the class JavaVariableCompletionTest method createLocalVariable5.
@Test
public void createLocalVariable5() throws Exception {
JavaVariableCompletion completion = getCompilation();
Optional<LocalVariable> olv = timeIt(() -> {
final Range range = new Range(0, 0, 0, 0);
final Range nameRange = new Range(0, 0, 0, 0);
final MethodCall mcs = new MethodCall("parser", "parse", 0, nameRange, range);
return completion.createLocalVariable(mcs, "org.apache.commons.cli.CommandLine");
});
LocalVariable lv = olv.get();
System.out.println(lv);
assertEquals(4, lv.getCandidates().size());
}
use of meghanada.analyze.Range in project meghanada-server by mopemope.
the class ReferenceSearcher method searchClassReferences.
private static List<Reference> searchClassReferences(Source src, SearchCondition sc) throws IOException {
List<String> lines = FileUtils.readLines(src.getFile());
int size = lines.size();
List<Reference> result = new ArrayList<>(size);
Collection<MethodCall> methodCalls = src.getMethodCalls();
for (MethodCall mc : methodCalls) {
String declaringClass = mc.declaringClass;
if (sc.declaringClass.equals(declaringClass) && mc.scope.contains(sc.name)) {
Range range = mc.nameRange;
long line = range.begin.line;
long column = range.begin.column;
String code = StringEscapeUtils.escapeJava(lines.get((int) line - 1));
Reference ref = new Reference(src.filePath, line, column, code);
result.add(ref);
}
}
Collection<FieldAccess> fieldAccesses = src.getFieldAccesses();
for (FieldAccess fa : fieldAccesses) {
String declaringClass = fa.declaringClass;
if (sc.declaringClass.equals(declaringClass) && fa.scope.contains(sc.name)) {
Range range = fa.range;
long line = range.begin.line;
long column = range.begin.column;
String code = StringEscapeUtils.escapeJava(lines.get((int) line - 1));
Reference ref = new Reference(src.filePath, line, column, code);
result.add(ref);
}
}
return result;
}
Aggregations