Search in sources :

Example 1 with ChainIterable

use of com.jetbrains.python.toolbox.ChainIterable in project intellij-community by JetBrains.

the class PyStarImportElementImpl method iterateNames.

@NotNull
public Iterable<PyElement> iterateNames() {
    if (getParent() instanceof PyFromImportStatement) {
        PyFromImportStatement fromImportStatement = (PyFromImportStatement) getParent();
        final List<PsiElement> importedFiles = fromImportStatement.resolveImportSourceCandidates();
        ChainIterable<PyElement> chain = new ChainIterable<>();
        for (PsiElement importedFile : new HashSet<>(importedFiles)) {
            // resolver gives lots of duplicates
            final PsiElement source = PyUtil.turnDirIntoInit(importedFile);
            if (source instanceof PyFile) {
                final PyFile sourceFile = (PyFile) source;
                chain.add(filterStarImportableNames(sourceFile.iterateNames(), sourceFile));
            }
        }
        return chain;
    }
    return Collections.emptyList();
}
Also used : ChainIterable(com.jetbrains.python.toolbox.ChainIterable) PsiElement(com.intellij.psi.PsiElement) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ChainIterable

use of com.jetbrains.python.toolbox.ChainIterable in project intellij-community by JetBrains.

the class PythonDocumentationProvider method describeFunction.

/**
   * Creates a HTML description of function definition.
   *
   * @param fun             the function
   * @param funcNameWrapper puts a tag around the function name
   * @param escaper         sanitizes values that come directly from doc string or code
   * @return chain of strings for further chaining
   */
@NotNull
static ChainIterable<String> describeFunction(@NotNull PyFunction fun, FP.Lambda1<Iterable<String>, Iterable<String>> funcNameWrapper, @NotNull FP.Lambda1<String, String> escaper) {
    final ChainIterable<String> cat = new ChainIterable<>();
    final String name = fun.getName();
    cat.addItem("def ").addWith(funcNameWrapper, $(name));
    final TypeEvalContext context = TypeEvalContext.userInitiated(fun.getProject(), fun.getContainingFile());
    final List<PyParameter> parameters = PyUtil.getParameters(fun, context);
    final String paramStr = "(" + StringUtil.join(parameters, parameter -> PyUtil.getReadableRepr(parameter, false), ", ") + ")";
    cat.addItem(escaper.apply(paramStr));
    if (!PyNames.INIT.equals(name)) {
        cat.addItem(escaper.apply("\nInferred type: "));
        describeTypeWithLinks(fun, cat);
        cat.addItem(BR);
    }
    return cat;
}
Also used : ChainIterable(com.jetbrains.python.toolbox.ChainIterable) TypeEvalContext(com.jetbrains.python.psi.types.TypeEvalContext) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ChainIterable (com.jetbrains.python.toolbox.ChainIterable)2 NotNull (org.jetbrains.annotations.NotNull)2 PsiElement (com.intellij.psi.PsiElement)1 HashSet (com.intellij.util.containers.HashSet)1 TypeEvalContext (com.jetbrains.python.psi.types.TypeEvalContext)1