use of com.intellij.psi.PsiInvalidElementAccessException in project intellij-community by JetBrains.
the class DomInvocationHandler method getFixedChild.
@NotNull
final IndexedElementInvocationHandler getFixedChild(final Pair<FixedChildDescriptionImpl, Integer> info) {
final FixedChildDescriptionImpl description = info.first;
XmlName xmlName = description.getXmlName();
final EvaluatedXmlName evaluatedXmlName = createEvaluatedXmlName(xmlName);
if (myStub != null && description.isStubbed()) {
List<DomStub> stubs = myStub.getChildrenByName(xmlName.getLocalName(), xmlName.getNamespaceKey());
DomStub stub = stubs.isEmpty() ? null : stubs.get(0);
DomParentStrategy strategy = stub == null ? new StubParentStrategy.Empty(myStub) : new StubParentStrategy(stub);
return new IndexedElementInvocationHandler(evaluatedXmlName, description, 0, strategy, myManager, (ElementStub) stub);
}
final XmlTag tag = getXmlTag();
final int index = info.second;
if (tag != null) {
if (!tag.isValid()) {
throw new PsiInvalidElementAccessException(tag);
}
final XmlTag[] subTags = tag.getSubTags();
for (int i = 0, subTagsLength = subTags.length; i < subTagsLength; i++) {
XmlTag xmlTag = subTags[i];
if (!xmlTag.isValid()) {
throw new PsiInvalidElementAccessException(xmlTag, "invalid children of valid tag: " + tag.getText() + "; subtag=" + xmlTag + "; index=" + i);
}
}
final List<XmlTag> tags = DomImplUtil.findSubTags(subTags, evaluatedXmlName, getFile());
if (tags.size() > index) {
final XmlTag child = tags.get(index);
final IndexedElementInvocationHandler semElement = myManager.getSemService().getSemElement(DomManagerImpl.DOM_INDEXED_HANDLER_KEY, child);
if (semElement == null) {
final IndexedElementInvocationHandler take2 = myManager.getSemService().getSemElement(DomManagerImpl.DOM_INDEXED_HANDLER_KEY, child);
throw new AssertionError("No DOM at XML. Parent=" + tag + "; child=" + child + "; index=" + index + "; second attempt=" + take2);
}
return semElement;
}
}
return new IndexedElementInvocationHandler(evaluatedXmlName, description, index, new VirtualDomParentStrategy(this), myManager, null);
}
use of com.intellij.psi.PsiInvalidElementAccessException in project intellij-community by JetBrains.
the class VariantsProcessor method execute.
@Override
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState substitutor) {
// skip whatever the filter rejects
if (myNodeFilter != null && !myNodeFilter.value(element))
return true;
// TODO: refactor to look saner; much code duplication
if (element instanceof PsiNamedElement) {
final PsiNamedElement psiNamedElement = (PsiNamedElement) element;
final String name = PyUtil.getElementNameWithoutExtension(psiNamedElement);
if (name != null && nameIsAcceptable(name)) {
addElement(name, psiNamedElement);
}
} else if (element instanceof PyReferenceExpression) {
PyReferenceExpression expr = (PyReferenceExpression) element;
String referencedName = expr.getReferencedName();
if (nameIsAcceptable(referencedName)) {
addElement(referencedName, expr);
}
} else if (element instanceof PyImportedNameDefiner) {
boolean handledAsImported = false;
if (element instanceof PyImportElement) {
final PyImportElement importElement = (PyImportElement) element;
handledAsImported = handleImportElement(importElement);
}
if (!handledAsImported) {
final PyImportedNameDefiner definer = (PyImportedNameDefiner) element;
for (PyElement expr : definer.iterateNames()) {
if (expr != null && expr != myContext) {
// NOTE: maybe rather have SingleIterables skip nulls outright?
if (!expr.isValid()) {
throw new PsiInvalidElementAccessException(expr, "Definer: " + definer);
}
String referencedName = expr instanceof PyFile ? FileUtil.getNameWithoutExtension(((PyFile) expr).getName()) : expr.getName();
if (referencedName != null && nameIsAcceptable(referencedName)) {
addImportedElement(referencedName, expr);
}
}
}
}
}
return true;
}
use of com.intellij.psi.PsiInvalidElementAccessException in project intellij-community by JetBrains.
the class ResolveImportUtil method resolveNameInFromImport.
@NotNull
public static List<RatedResolveResult> resolveNameInFromImport(PyFromImportStatement importStatement, @NotNull QualifiedName qName) {
PsiFile file = importStatement.getContainingFile().getOriginalFile();
String name = qName.getComponents().get(0);
final List<PsiElement> candidates = importStatement.resolveImportSourceCandidates();
List<PsiElement> resultList = new ArrayList<>();
for (PsiElement candidate : candidates) {
if (!candidate.isValid()) {
throw new PsiInvalidElementAccessException(candidate, "Got an invalid candidate from resolveImportSourceCandidates(): " + candidate.getClass());
}
if (candidate instanceof PsiDirectory) {
candidate = PyUtil.getPackageElement((PsiDirectory) candidate, importStatement);
}
List<RatedResolveResult> results = resolveChildren(candidate, name, file, false, true, false);
if (!results.isEmpty()) {
for (RatedResolveResult result : results) {
final PsiElement element = result.getElement();
if (element != null) {
if (!element.isValid()) {
throw new PsiInvalidElementAccessException(element, "Got an invalid candidate from resolveChild(): " + element.getClass());
}
resultList.add(element);
}
}
}
}
if (!resultList.isEmpty()) {
return rateResults(resultList);
}
return Collections.emptyList();
}
use of com.intellij.psi.PsiInvalidElementAccessException in project intellij-community by JetBrains.
the class ASTDelegatePsiElement method getManager.
@Override
public PsiManagerEx getManager() {
Project project = ProjectCoreUtil.theOnlyOpenProject();
if (project != null) {
return PsiManagerEx.getInstanceEx(project);
}
PsiElement parent = this;
while (parent instanceof ASTDelegatePsiElement) {
parent = parent.getParent();
}
if (parent == null) {
throw new PsiInvalidElementAccessException(this);
}
return (PsiManagerEx) parent.getManager();
}
use of com.intellij.psi.PsiInvalidElementAccessException in project intellij-community by JetBrains.
the class StubBasedPsiElementBase method getNode.
/**
* Ensures this element is AST-based. This is an expensive operation that might take significant time and allocate lots of objects,
* so it should be to be avoided if possible.
*
* @return an AST node corresponding to this element. If the element is currently operating via stubs,
* this causes AST to be loaded for the whole file and all stub-based PSI elements in this file (including the current one)
* to be switched from stub to AST. So, after this call {@link #getStub()} will return null.
*/
@Override
@NotNull
public ASTNode getNode() {
if (mySubstrateRef instanceof SubstrateRef.StubRef) {
ApplicationManager.getApplication().assertReadAccessAllowed();
PsiFileImpl file = (PsiFileImpl) getContainingFile();
if (!file.isValid())
throw new PsiInvalidElementAccessException(this);
FileElement treeElement = file.getTreeElement();
if (treeElement != null && mySubstrateRef instanceof SubstrateRef.StubRef) {
return notBoundInExistingAst(file, treeElement);
}
treeElement = file.calcTreeElement();
if (mySubstrateRef instanceof SubstrateRef.StubRef) {
return failedToBindStubToAst(file, treeElement);
}
}
return mySubstrateRef.getNode();
}
Aggregations