public static boolean processChildrenFromTop(@NotNull PsiElement element, @NotNull PsiScopeProcessor processor, @NotNull ResolveState substitutor, @Nullable PsiElement lastParent, @NotNull PsiElement place) { PsiElement run = element.getFirstChild(); while (run != null) { if (run instanceof GoCompositeElement) { if (run.isEquivalentTo(lastParent)) return true; if (!run.processDeclarations(processor, substitutor, null, place)) return false; } run = run.getNextSibling(); } return true; } }
@NotNull public static PsiElement[] getTopLevelElementsInRange(@NotNull GoFile file, int startOffset, int endOffset, @NotNull Class<? extends PsiElement> clazz) { Couple<PsiElement> elementRange = getElementRange(file, startOffset, endOffset); if (elementRange == null) return PsiElement.EMPTY_ARRAY; Couple<PsiElement> topmostElementRange = getTopmostElementRange(elementRange); if (topmostElementRange == null) return PsiElement.EMPTY_ARRAY; if (!clazz.isInstance(topmostElementRange.first) || !clazz.isInstance(topmostElementRange.second)) { return PsiElement.EMPTY_ARRAY; } List<PsiElement> result = ContainerUtil.newSmartList(); PsiElement start = topmostElementRange.first; while (start != null && !start.isEquivalentTo(topmostElementRange.second)) { if (clazz.isInstance(start)) result.add(start); start = start.getNextSibling(); } result.add(topmostElementRange.second); return PsiUtilCore.toPsiElementArray(result); }
@Override protected boolean add(@NotNull GoNamedElement o) { PsiElement commonParent = PsiTreeUtil.findCommonParent(o, myOrigin); if (commonParent instanceof GoRangeClause || commonParent instanceof GoTypeSwitchGuard) return true; PsiElement p = o.getParent(); boolean inVarOrRange = PsiTreeUtil.getParentOfType(o, GoVarDeclaration.class) != null || p instanceof GoRangeClause; boolean differentBlocks = differentBlocks(o); boolean inShortVar = PsiTreeUtil.getParentOfType(o, GoShortVarDeclaration.class, GoRecvStatement.class) != null; if (inShortVar && differentBlocks && myImShortVarDeclaration) return true; if (differentBlocks && inShortVar && !inVarOrRange && getResult() != null && !myIsCompletion) return true; if (inShortVar && fromNotAncestorBlock(o)) return true; if (myParentGuard != null && o instanceof GoVarDefinition && p.isEquivalentTo(myParentGuard)) return true; return super.add(o); }
/** * Return element range which contains TextRange(start, end) of top level elements * common parent of elements is straight parent for each element */ @Nullable private static Couple<PsiElement> getTopmostElementRange(@NotNull Couple<PsiElement> elementRange, @NotNull PsiElement commonParent) { if (elementRange.first == null || elementRange.second == null) return null; int start = elementRange.first.getTextOffset(); int end = elementRange.second.getTextRange().getEndOffset(); TextRange range = commonParent.getTextRange(); PsiElement[] children = commonParent.getChildren(); if (commonParent.isEquivalentTo(elementRange.first) || commonParent.isEquivalentTo(elementRange.second) || range.getStartOffset() == start && (children.length == 0 || children[0].getTextRange().getStartOffset() > start) || range.getEndOffset() == end && (children.length == 0 || children[children.length - 1].getTextRange().getEndOffset() < end)) { return Couple.of(commonParent, commonParent); } PsiElement startElement = elementRange.first; PsiElement endElement = elementRange.second; for (PsiElement element : children) { range = element.getTextRange(); if (range.contains(start) && !range.contains(end)) { startElement = element; } if (range.contains(end - 1) && !range.contains(start - 1)) { endElement = element; } } return startElement.getParent().isEquivalentTo(endElement.getParent()) ? Couple.of(startElement, endElement) : null; }
@Override public boolean checkAvailable(@NotNull Editor editor, @NotNull PsiFile file, @NotNull MoveInfo info, boolean down) { if (!(file instanceof GoFile && super.checkAvailable(editor, file, info, down))) return false; Couple<PsiElement> primeElementRange = getElementRange(editor, file); if (primeElementRange == null) return false; PsiElement commonParent = primeElementRange.first.isEquivalentTo(primeElementRange.second) ? primeElementRange.first.getParent() : PsiTreeUtil.findCommonParent(primeElementRange.first, primeElementRange.second); if (commonParent == null) return false; Couple<PsiElement> elementRange = getTopmostElementRange(primeElementRange, commonParent); if (elementRange == null) return false; if (commonParent == elementRange.first) commonParent = commonParent.getParent(); info.toMove = new LineRange(elementRange.first, elementRange.second); if (elementRange.first instanceof GoTopLevelDeclaration && commonParent instanceof GoFile) { PsiElement toMove2 = getNeighborOfType(elementRange, GoTopLevelDeclaration.class, down); info.toMove2 = toMove2 != null ? new LineRange(toMove2) : null; return true; } if (commonParent instanceof GoImportList) { PsiElement toMove2 = getNeighborOfType(elementRange, GoImportDeclaration.class, down); info.toMove2 = toMove2 != null ? new LineRange(toMove2) : null; return true; } return setUpInfo(info, elementRange, commonParent, down); }
PsiElement commonParent = PsiTreeUtil.findCommonParent(elementRange.first, elementRange.second); if (commonParent == null) return null; if (commonParent.isEquivalentTo(elementRange.first) || commonParent.isEquivalentTo(elementRange.second)) { commonParent = commonParent.getParent(); if (!startElement.getParent().isEquivalentTo(endElement.getParent())) return null; endElement = commonParent; if (startElement.isEquivalentTo(endElement)) { while (startElement.getTextRange().equals(startElement.getParent().getTextRange())) { startElement = startElement.getParent();
if (lastBinding == null || !element.isEquivalentTo(lastBinding)) { Match matchAncestor = PsiTreeUtil.getContextOfType(element, Match.class);
return resolve != null && resolve.isEquivalentTo(((GoReferenceExpression)r).resolve());
public void testUnresolvedAtTopOfFile() { myFixture.configureByFiles("unresolved_at_top_of_file.ex"); PsiElement elementAtCaret = myFixture .getFile() .findElementAt(myFixture.getCaretOffset()); assertNotNull(elementAtCaret); assertInstanceOf(elementAtCaret, LeafPsiElement.class); PsiElement parent = elementAtCaret.getParent(); assertNotNull(parent); assertInstanceOf(parent, ElixirIdentifier.class); PsiElement grandParent = parent.getParent(); assertNotNull(grandParent); assertInstanceOf(grandParent, Call.class); Call grandParentCall = (Call) grandParent; PsiReference reference = grandParentCall.getReference(); assertNotNull(reference); PsiElement resolved = reference.resolve(); assertNotNull(resolved); assertTrue(resolved.isEquivalentTo(grandParent)); }
@Override public boolean isEquivalentTo(PsiElement another) { return getDelegate().isEquivalentTo(another); }
@Override public void visitSubDeclarationElement(@NotNull PerlSubDeclarationElement child) { if (psiElement.isEquivalentTo(PerlPackageUtil.getNamespaceContainerForElement(child))) { result.add(new PerlSubStructureViewElement(child)); } super.visitSubDeclarationElement(child); }
@Override public void visitPerlSubDefinitionElement(@NotNull PerlSubDefinitionElement child) { if (psiElement.isEquivalentTo(PerlPackageUtil.getNamespaceContainerForElement(child))) { implementedMethods.add(child.getName()); result.add(new PerlSubStructureViewElement(child)); } super.visitPerlSubDefinitionElement(child); }
@Override public void visitGlobVariable(@NotNull PsiPerlGlobVariable child) { if (child.isLeftSideOfAssignment() && psiElement.isEquivalentTo(PerlPackageUtil.getNamespaceContainerForElement(child))) { implementedMethods.add(child.getName()); result.add(new PerlGlobStructureViewElement(child)); } super.visitGlobVariable(child); } });
public static void walkVariableDefinitions(@NotNull BashVar reference, @NotNull Function<BashVarDef, Boolean> varDefProcessor) { String varName = reference.getName(); if (StringUtils.isBlank(varName)) { return; } Project project = reference.getProject(); GlobalSearchScope filesScope = varDefSearchScope(reference, true); PsiElement referenceDefinition = reference.getReference().resolve(); if (referenceDefinition == null) { return; } for (BashVarDef candidate : StubIndex.getElements(BashVarDefIndex.KEY, varName, project, filesScope, BashVarDef.class)) { //only variables which have the same original definition should be processed //e.g. local variables won't be processed this way if a global variable is given to this method if (referenceDefinition.isEquivalentTo(candidate) || referenceDefinition.isEquivalentTo(candidate.getReference().resolve())) { Boolean walkOn = varDefProcessor.apply(candidate); if (walkOn == null || !walkOn) { return; } } } }
if (lastParent != null && lastParent.getParent().isEquivalentTo(thisElement) && BashPsiUtils.findNextVarDefFunctionDefScope(place) != null) { for (PsiElement sibling = lastParent.getNextSibling(); sibling != null; sibling = sibling.getNextSibling()) { if (!sibling.processDeclarations(processor, state, null, place)) {
if (child.isGlobalDeclaration() && psiElement.isEquivalentTo(PerlPackageUtil.getNamespaceContainerForElement(child))) { result.add(new PerlVariableDeclarationStructureViewElement(child));