com.jetbrains.python.psi.stubs.PyClassAttributesIndex Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of python-community Show documentation
Show all versions of python-community Show documentation
A packaging of the IntelliJ Community Edition python-community library.
This is release number 1 of trunk branch 142.
The newest version!
package com.jetbrains.python.psi.stubs;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiNamedElement;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.stubs.StringStubIndexExtension;
import com.intellij.psi.stubs.StubIndex;
import com.intellij.psi.stubs.StubIndexKey;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import com.jetbrains.python.psi.PyClass;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
/**
* @author Mikhail Golubev
*/
public class PyClassAttributesIndex extends StringStubIndexExtension {
public static final StubIndexKey KEY = StubIndexKey.createIndexKey("Py.class.attributes");
@NotNull
@Override
public StubIndexKey getKey() {
return KEY;
}
public static Collection find(@NotNull String name, @NotNull Project project) {
return StubIndex.getElements(KEY, name, project, GlobalSearchScope.allScope(project), PyClass.class);
}
/**
* Returns all attributes: methods, class and instance fields that are declared directly in the specified class
* (not taking inheritance into account).
*
* This method must not access the AST because it is being called during stub indexing.
*/
@NotNull
public static List getAllDeclaredAttributeNames(@NotNull PyClass pyClass) {
final List members = ContainerUtil.concat(pyClass.getInstanceAttributes(),
pyClass.getClassAttributes(),
Arrays.asList(pyClass.getMethods(false)));
return ContainerUtil.mapNotNull(members, new Function() {
@Override
public String fun(PsiNamedElement expression) {
final String attrName = expression.getName();
return attrName != null ? attrName : null;
}
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy