use of com.jetbrains.python.psi.stubs.PyFromImportStatementStub in project intellij-community by JetBrains.
the class PyFromImportStatementImpl method getImportSourceQName.
public QualifiedName getImportSourceQName() {
final PyFromImportStatementStub stub = getStub();
if (stub != null) {
final QualifiedName qName = stub.getImportSourceQName();
if (qName != null && qName.getComponentCount() == 0) {
// relative import only: from .. import the_name
return null;
}
return qName;
}
final PyReferenceExpression importSource = getImportSource();
if (importSource == null) {
return null;
}
return importSource.asQualifiedName();
}
use of com.jetbrains.python.psi.stubs.PyFromImportStatementStub in project intellij-community by JetBrains.
the class PyFromImportStatementImpl method getImportElements.
@NotNull
public PyImportElement[] getImportElements() {
final PyFromImportStatementStub stub = getStub();
if (stub != null) {
return stub.getChildrenByType(PyElementTypes.IMPORT_ELEMENT, count -> new PyImportElement[count]);
}
List<PyImportElement> result = new ArrayList<>();
final ASTNode importKeyword = getNode().findChildByType(PyTokenTypes.IMPORT_KEYWORD);
if (importKeyword != null) {
for (ASTNode node = importKeyword.getTreeNext(); node != null; node = node.getTreeNext()) {
if (node.getElementType() == PyElementTypes.IMPORT_ELEMENT) {
result.add((PyImportElement) node.getPsi());
}
}
}
return result.toArray(new PyImportElement[result.size()]);
}
use of com.jetbrains.python.psi.stubs.PyFromImportStatementStub in project intellij-community by JetBrains.
the class PyFromImportStatementImpl method getRelativeLevel.
public int getRelativeLevel() {
final PyFromImportStatementStub stub = getStub();
if (stub != null) {
return stub.getRelativeLevel();
}
int result = 0;
ASTNode seeker = getNode().getFirstChildNode();
while (seeker != null && (seeker.getElementType() == PyTokenTypes.FROM_KEYWORD || seeker.getElementType() == TokenType.WHITE_SPACE)) {
seeker = seeker.getTreeNext();
}
while (seeker != null && seeker.getElementType() == PyTokenTypes.DOT) {
result++;
seeker = seeker.getTreeNext();
}
return result;
}
Aggregations