Search in sources :

Example 6 with PyCustomMember

use of com.jetbrains.python.codeInsight.PyCustomMember in project intellij-community by JetBrains.

the class PyStdlibModuleMembersProvider method getMembersByQName.

@Override
protected Collection<PyCustomMember> getMembersByQName(PyFile module, String qName) {
    if (qName.equals("os")) {
        final List<PyCustomMember> results = new ArrayList<>();
        PsiElement path = null;
        if (module != null) {
            final String pathModuleName = SystemInfo.isWindows ? "ntpath" : "posixpath";
            path = ResolveImportUtil.resolveModuleInRoots(QualifiedName.fromDottedString(pathModuleName), module);
        }
        results.add(new PyCustomMember("path", path));
        return results;
    }
    return Collections.emptyList();
}
Also used : PyCustomMember(com.jetbrains.python.codeInsight.PyCustomMember) ArrayList(java.util.ArrayList) PsiElement(com.intellij.psi.PsiElement)

Example 7 with PyCustomMember

use of com.jetbrains.python.codeInsight.PyCustomMember in project intellij-community by JetBrains.

the class NumpyClassMembersProvider method getMembers.

@NotNull
@Override
public Collection<PyCustomMember> getMembers(PyClassType clazz, PsiElement location, TypeEvalContext typeEvalContext) {
    if (location != null && clazz.getPyClass().isSubclass(PyNames.TYPES_FUNCTION_TYPE, typeEvalContext)) {
        final PsiElement element = location.getOriginalElement();
        final PsiReference reference = element.getReference();
        if (reference != null) {
            final PsiElement resolved = reference.resolve();
            if (resolved instanceof PyFunction) {
                final List<PyCustomMember> result = new ArrayList<>();
                if (NumpyUfuncs.isUFunc(((PyFunction) resolved).getName()) && NumpyDocStringTypeProvider.isInsideNumPy(resolved)) {
                    for (String method : NumpyUfuncs.UFUNC_METHODS) {
                        result.add(new PyCustomMember(method, resolved));
                    }
                    return result;
                }
            }
        }
    }
    return Collections.emptyList();
}
Also used : PyFunction(com.jetbrains.python.psi.PyFunction) PyCustomMember(com.jetbrains.python.codeInsight.PyCustomMember) ArrayList(java.util.ArrayList) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with PyCustomMember

use of com.jetbrains.python.codeInsight.PyCustomMember in project intellij-community by JetBrains.

the class NumpyModuleMembersProvider method getMembersByQName.

@Override
protected Collection<PyCustomMember> getMembersByQName(PyFile module, String qName) {
    if ("numpy".equals(qName)) {
        final List<PyCustomMember> members = new ArrayList<>();
        for (String type : NUMERIC_TYPES) {
            members.add(new PyCustomMember(type, DTYPE, false));
        }
        for (String type : PYTHON_TYPES) {
            members.add(new PyCustomMember(type, DTYPE, false));
        }
        addTestingModule(module, members);
        return members;
    }
    return Collections.emptyList();
}
Also used : PyCustomMember(com.jetbrains.python.codeInsight.PyCustomMember) ArrayList(java.util.ArrayList)

Example 9 with PyCustomMember

use of com.jetbrains.python.codeInsight.PyCustomMember in project intellij-community by JetBrains.

the class PyClassTypeImpl method getMemberNames.

@NotNull
@Override
public Set<String> getMemberNames(boolean inherited, @NotNull TypeEvalContext context) {
    final Set<String> result = new LinkedHashSet<>();
    for (PyFunction function : myClass.getMethods()) {
        result.add(function.getName());
    }
    for (PyTargetExpression expression : myClass.getClassAttributes()) {
        result.add(expression.getName());
    }
    for (PyTargetExpression expression : myClass.getInstanceAttributes()) {
        result.add(expression.getName());
    }
    result.addAll(ObjectUtils.notNull(myClass.getSlots(context), Collections.emptyList()));
    for (PyClassMembersProvider provider : Extensions.getExtensions(PyClassMembersProvider.EP_NAME)) {
        for (PyCustomMember member : provider.getMembers(this, null, context)) {
            result.add(member.getName());
        }
    }
    if (inherited) {
        for (PyClassLikeType type : getAncestorTypes(context)) {
            if (type != null) {
                final PyClassLikeType ancestorType = isDefinition() ? type : type.toInstance();
                result.addAll(ancestorType.getMemberNames(false, context));
            }
        }
    }
    return result;
}
Also used : PyCustomMember(com.jetbrains.python.codeInsight.PyCustomMember) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with PyCustomMember

use of com.jetbrains.python.codeInsight.PyCustomMember in project intellij-community by JetBrains.

the class PyStdlibClassMembersProvider method calcMockPatchMembers.

@NotNull
private static List<PyCustomMember> calcMockPatchMembers() {
    final String[] members = new String[] { "object", "dict", "multiple", "stopall", "TEST_PREFIX" };
    final String moduleQName = "unittest.mock";
    return ContainerUtil.map(members, member -> new PyCustomMember(member).resolvesTo(moduleQName).toAssignment("patch." + member));
}
Also used : PyCustomMember(com.jetbrains.python.codeInsight.PyCustomMember) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PyCustomMember (com.jetbrains.python.codeInsight.PyCustomMember)10 ArrayList (java.util.ArrayList)5 PsiElement (com.intellij.psi.PsiElement)4 NotNull (org.jetbrains.annotations.NotNull)3 PyFunction (com.jetbrains.python.psi.PyFunction)2 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 PsiFile (com.intellij.psi.PsiFile)1 PsiReference (com.intellij.psi.PsiReference)1 PyTargetExpression (com.jetbrains.python.psi.PyTargetExpression)1 PyUtil (com.jetbrains.python.psi.PyUtil)1 PyQualifiedNameResolveContext (com.jetbrains.python.psi.resolve.PyQualifiedNameResolveContext)1