62 |
62 |
63 import java.util.ArrayList; |
63 import java.util.ArrayList; |
64 import java.util.Collections; |
64 import java.util.Collections; |
65 import java.util.Iterator; |
65 import java.util.Iterator; |
66 import java.util.List; |
66 import java.util.List; |
|
67 import java.util.Objects; |
67 import java.util.function.Predicate; |
68 import java.util.function.Predicate; |
68 |
69 |
69 import javax.lang.model.element.Element; |
70 import javax.lang.model.element.Element; |
70 import javax.lang.model.element.ElementKind; |
71 import javax.lang.model.element.ElementKind; |
71 import javax.lang.model.element.Modifier; |
72 import javax.lang.model.element.Modifier; |
278 break; |
279 break; |
279 } |
280 } |
280 String requiredPrefix = identifier; |
281 String requiredPrefix = identifier; |
281 return computeSuggestions(codeWrap, cursor, anchor).stream() |
282 return computeSuggestions(codeWrap, cursor, anchor).stream() |
282 .filter(s -> s.continuation().startsWith(requiredPrefix) && !s.continuation().equals(REPL_DOESNOTMATTER_CLASS_NAME)) |
283 .filter(s -> s.continuation().startsWith(requiredPrefix) && !s.continuation().equals(REPL_DOESNOTMATTER_CLASS_NAME)) |
283 .sorted(Comparator.comparing(s -> s.continuation())) |
284 .sorted(Comparator.comparing(Suggestion::continuation)) |
284 .collect(collectingAndThen(toList(), Collections::unmodifiableList)); |
285 .collect(collectingAndThen(toList(), Collections::unmodifiableList)); |
285 } |
286 } |
286 |
287 |
287 private List<Suggestion> computeSuggestions(OuterWrap code, int cursor, int[] anchor) { |
288 private List<Suggestion> computeSuggestions(OuterWrap code, int cursor, int[] anchor) { |
288 AnalyzeTask at = proc.taskFactory.new AnalyzeTask(code); |
289 AnalyzeTask at = proc.taskFactory.new AnalyzeTask(code); |
635 Element encl = el.getEnclosingElement(); |
636 Element encl = el.getEnclosingElement(); |
636 |
637 |
637 return IS_STATIC.or(IS_CLASS).or(IS_INTERFACE).negate().test(el) || |
638 return IS_STATIC.or(IS_CLASS).or(IS_INTERFACE).negate().test(el) || |
638 IS_PACKAGE.test(encl); |
639 IS_PACKAGE.test(encl); |
639 }; |
640 }; |
640 private final Function<Element, Iterable<? extends Element>> IDENTITY = el -> Collections.singletonList(el); |
641 private final Function<Element, Iterable<? extends Element>> IDENTITY = Collections::singletonList; |
641 private final Function<Boolean, String> DEFAULT_PAREN = hasParams -> hasParams ? "(" : "()"; |
642 private final Function<Boolean, String> DEFAULT_PAREN = hasParams -> hasParams ? "(" : "()"; |
642 private final Function<Boolean, String> NO_PAREN = hasParams -> ""; |
643 private final Function<Boolean, String> NO_PAREN = hasParams -> ""; |
643 |
644 |
644 private void addElements(Iterable<? extends Element> elements, Predicate<Element> accept, Predicate<Element> smart, List<Suggestion> result) { |
645 private void addElements(Iterable<? extends Element> elements, Predicate<Element> accept, Predicate<Element> smart, List<Suggestion> result) { |
645 addElements(elements, accept, smart, DEFAULT_PAREN, result); |
646 addElements(elements, accept, smart, DEFAULT_PAREN, result); |
829 } |
830 } |
830 } |
831 } |
831 }; |
832 }; |
832 @SuppressWarnings("unchecked") |
833 @SuppressWarnings("unchecked") |
833 List<Element> result = Util.stream(scopeIterable) |
834 List<Element> result = Util.stream(scopeIterable) |
834 .flatMap(s -> localElements(s)) |
835 .flatMap(this::localElements) |
835 .flatMap(el -> Util.stream((Iterable<Element>)elementConvertor.apply(el))) |
836 .flatMap(el -> Util.stream((Iterable<Element>)elementConvertor.apply(el))) |
836 .collect(toCollection(ArrayList :: new)); |
837 .collect(toCollection(ArrayList :: new)); |
837 result.addAll(listPackages(at, "")); |
838 result.addAll(listPackages(at, "")); |
838 return result; |
839 return result; |
839 } |
840 } |
1184 |
1185 |
1185 List<Documentation> result = Collections.emptyList(); |
1186 List<Documentation> result = Collections.emptyList(); |
1186 |
1187 |
1187 try (JavadocHelper helper = JavadocHelper.create(at.task, findSources())) { |
1188 try (JavadocHelper helper = JavadocHelper.create(at.task, findSources())) { |
1188 result = elements.map(el -> constructDocumentation(at, helper, el, computeJavadoc)) |
1189 result = elements.map(el -> constructDocumentation(at, helper, el, computeJavadoc)) |
1189 .filter(r -> r != null) |
1190 .filter(Objects::nonNull) |
1190 .collect(Collectors.toList()); |
1191 .collect(Collectors.toList()); |
1191 } catch (IOException ex) { |
1192 } catch (IOException ex) { |
1192 proc.debug(ex, "JavadocHelper.close()"); |
1193 proc.debug(ex, "JavadocHelper.close()"); |
1193 } |
1194 } |
1194 |
1195 |