Java Code Examples for com.intellij.psi.PsiElement#equals()
The following examples show how to use
com.intellij.psi.PsiElement#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PackageReferenceFragment.java From intellij with Apache License 2.0 | 6 votes |
@Override public PsiElement bindToElement(PsiElement element) throws IncorrectOperationException { if (!(element instanceof BuildFile)) { return super.bindToElement(element); } if (element.equals(resolve())) { return myElement; } Label newPackageLabel = ((BuildFile) element).getPackageLabel(); if (newPackageLabel == null) { return myElement; } String newPath = newPackageLabel.blazePackage().toString(); String labelString = myElement.getStringContents(); int colonIndex = labelString.indexOf(':'); if (colonIndex != -1) { return handleRename("//" + newPath + labelString.substring(colonIndex)); } // need to assume there's an implicit rule name return handleRename("//" + newPath + ":" + PathUtil.getFileName(labelString)); }
Example 2
Source File: XQueryPsiImplUtil.java From intellij-xquery with Apache License 2.0 | 6 votes |
private static <T extends XQueryPsiElement, U extends XQueryPsiElement>boolean processChildrenIfPlaceIsNotPartOfSameBinding(T module, @NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place, Class<T> bindingClass, Class<U>... childClassesToSkip) { PsiElement commonParent = PsiTreeUtil.findCommonParent(place, module); T parentBinding = PsiTreeUtil.getParentOfType(place, bindingClass, true); XQueryExprSingle expressionInModule = PsiTreeUtil.getChildOfType(module, XQueryExprSingle.class); boolean inSameBinding = commonParent != null && commonParent.equals(module) && parentBinding != null && parentBinding.equals(module); Collection<T> childBindings = PsiTreeUtil.findChildrenOfType(expressionInModule, bindingClass); boolean partOfExpressionInBinding = childBindings.contains(parentBinding); if (inSameBinding || partOfExpressionInBinding) { return processor.execute(module, state); } else { if (!processor.execute(module, state)) { return false; } else { return ResolveUtil.processChildren(module, processor, state, lastParent, place, childClassesToSkip); } } }
Example 3
Source File: SendToEndAction.java From needsmoredojo with Apache License 2.0 | 6 votes |
private void moveElementToEnd(PsiElement define, PsiElement parameter, PsiElement lastDefine, PsiElement lastParameter, DefineStatement defineStatement) { if(lastDefine.equals(define)) { return; } PsiElement ignoreComment = AMDPsiUtil.getIgnoreCommentAfterLiteral(define); PsiElement newElement = moveImportToEnd(defineStatement.getArguments(), defineStatement.getFunction().getParameterList(), define.getText(), parameter.getText(), lastDefine, lastParameter); if(ignoreComment != null) { defineStatement.getArguments().addAfter(ignoreComment, newElement); } AMDPsiUtil.removeSingleImport(new AMDImport((JSElement) define, (JSElement)parameter)); }
Example 4
Source File: ANTLRv4FoldingBuilder.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 6 votes |
@SuppressWarnings("ConstantConditions") @Nullable private static TextRange getFileHeader(PsiElement file) { PsiElement first = file.getFirstChild(); if (first instanceof PsiWhiteSpace) first = first.getNextSibling(); PsiElement element = first; while (isComment(element)) { element = element.getNextSibling(); if (element instanceof PsiWhiteSpace) { element = element.getNextSibling(); } else { break; } } if (element == null) return null; if (element.getPrevSibling() instanceof PsiWhiteSpace) element = element.getPrevSibling(); if (element == null || element.equals(first)) return null; return new UnfairTextRange(first.getTextOffset(), element.getTextOffset()); }
Example 5
Source File: ParameterInfoController.java From consulo with Apache License 2.0 | 6 votes |
private void executeUpdateParameterInfo(PsiElement elementForUpdating, MyUpdateParameterInfoContext context, Runnable continuation) { PsiElement parameterOwner = context.getParameterOwner(); if (parameterOwner != null && !parameterOwner.equals(elementForUpdating)) { context.removeHint(); return; } runTask(myProject, ReadAction.nonBlocking(() -> { try { myHandler.updateParameterInfo(elementForUpdating, context); return elementForUpdating; } catch (IndexNotReadyException e) { DumbService.getInstance(myProject).showDumbModeNotification(CodeInsightBundle.message("parameter.info.indexing.mode.not.supported")); } return null; }).withDocumentsCommitted(myProject).expireWhen(() -> !myKeepOnHintHidden && !myHint.isVisible() && !ApplicationManager.getApplication().isHeadlessEnvironment() || getCurrentOffset() != context.getOffset() || !elementForUpdating.isValid()).expireWith(this), element -> { if (element != null && continuation != null) { context.applyUIChanges(); continuation.run(); } }, null, myEditor); }
Example 6
Source File: DependenciesModelImpl.java From ok-gradle with Apache License 2.0 | 5 votes |
/** * Returns {@code true} if {@code child} is a descendant of the {@code parent}, {@code false} otherwise. */ private static boolean isChildOfParent(@NotNull PsiElement child, @NotNull PsiElement parent) { List<PsiElement> childElements = Lists.newArrayList(parent); while (!childElements.isEmpty()) { PsiElement element = childElements.remove(0); if (element.equals(child)) { return true; } childElements.addAll(Arrays.asList(element.getChildren())); } return false; }
Example 7
Source File: FileReferenceCompletionImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean equals(final PsiElement o1, final PsiElement o2) { if (o1 instanceof PsiNamedElement && o2 instanceof PsiNamedElement) { return Comparing.equal(((PsiNamedElement)o1).getName(), ((PsiNamedElement)o2).getName()); } return o1.equals(o2); }
Example 8
Source File: VariableReferenceScopeProcessor.java From intellij-xquery with Apache License 2.0 | 5 votes |
@Override public boolean execute(@NotNull PsiElement element, ResolveState state) { boolean elementIsGoodCandidate = !element.equals(myElement) && element instanceof XQueryVarName && !(element.getParent() instanceof XQueryVarRef); if (elementIsGoodCandidate) { XQueryQName<XQueryVarName> source = aXQueryQName(myElement.getVarName()).build(); XQueryQName<XQueryVarName> checkedQName = aXQueryQName((XQueryVarName) element).build(); if (source.equals(checkedQName)) { result = checkedQName.getNamedObject(); return false; } } return true; }
Example 9
Source File: ANTLRv4FoldingBuilder.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 5 votes |
@SuppressWarnings("SimplifiableIfStatement") @Override protected boolean isRegionCollapsedByDefault(@NotNull ASTNode node) { final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(node); if (element == null) return false; ANTLRv4FoldingSettings settings = ANTLRv4FoldingSettings.getInstance(); if (RULE_BLOCKS.contains(node.getElementType())) return settings.isCollapseRuleBlocks(); if (node.getElementType() == TOKENSSPEC) return settings.isCollapseTokens(); if (element instanceof AtAction) return settings.isCollapseActions(); if (element instanceof ANTLRv4FileRoot) { return settings.isCollapseFileHeader(); } if (node.getElementType() == DOC_COMMENT_TOKEN) { PsiElement parent = element.getParent(); if (parent instanceof ANTLRv4FileRoot) { PsiElement firstChild = parent.getFirstChild(); if (firstChild instanceof PsiWhiteSpace) { firstChild = firstChild.getNextSibling(); } if (element.equals(firstChild)) { return settings.isCollapseFileHeader(); } } return settings.isCollapseDocComments(); } if (isComment(element)) { return settings.isCollapseComments(); } return false; }
Example 10
Source File: BuckGotoProvider.java From buck with Apache License 2.0 | 5 votes |
@Nullable private PsiElement resolveAsIdentifier(Project project, BuckIdentifier buckIdentifier) { String text = buckIdentifier.getIdentifierToken().getText(); BuckFunctionDefinition functionDefinition = PsiTreeUtil.getParentOfType(buckIdentifier, BuckFunctionDefinition.class); PsiElement resolved = null; while (functionDefinition != null) { resolved = BuckPsiUtils.findSymbolInPsiTree(functionDefinition.getParameterList(), text); if (resolved == null) { resolved = BuckPsiUtils.findSymbolInPsiTree(functionDefinition.getSuite(), text); } // back out one level of scoping and try again functionDefinition = PsiTreeUtil.getParentOfType(functionDefinition, BuckFunctionDefinition.class); } if (resolved == null) { resolved = BuckPsiUtils.findSymbolInPsiTree(buckIdentifier.getContainingFile(), text); } resolved = Optional.ofNullable(resolved) .map(e -> PsiTreeUtil.getParentOfType(e, BuckLoadArgument.class)) .flatMap( buckLoadArgument -> Optional.ofNullable(buckIdentifier.getContainingFile().getVirtualFile()) .map( sourceFile -> resolveAsLoadArgument(project, sourceFile, buckLoadArgument))) .orElse(resolved); if (resolved != null && !resolved.equals(buckIdentifier)) { return resolved; } else { return null; } }
Example 11
Source File: ProjectViewTestUtil.java From consulo with Apache License 2.0 | 5 votes |
private static DefaultMutableTreeNode getNodeForElement(Object root, TreeModel model, PsiElement element) { if (root instanceof DefaultMutableTreeNode) { Object userObject = ((DefaultMutableTreeNode)root).getUserObject(); if (userObject instanceof AbstractTreeNode) { AbstractTreeNode treeNode = (AbstractTreeNode)userObject; if (element.equals(treeNode.getValue())) return (DefaultMutableTreeNode)root; for (int i = 0; i < model.getChildCount(root); i++) { DefaultMutableTreeNode nodeForChild = getNodeForElement(model.getChild(root, i), model, element); if (nodeForChild != null) return nodeForChild; } } } return null; }
Example 12
Source File: ControlFlowBuilder.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public Instruction findInstructionByElement(final PsiElement element) { for (int i = instructions.size() - 1; i >= 0; i--) { final Instruction instruction = instructions.get(i); if (element.equals(instruction.getElement())) { return instruction; } } return null; }
Example 13
Source File: FileStructurePopup.java From consulo with Apache License 2.0 | 4 votes |
private static boolean isElement(@Nonnull PsiElement element, @Nullable TreePath path) { return element.equals(StructureViewComponent.unwrapValue(TreeUtil.getLastUserObject(FilteringTreeStructure.FilteringNode.class, path))); }
Example 14
Source File: IdempotenceChecker.java From consulo with Apache License 2.0 | 4 votes |
private static String checkPsiEquivalence(@Nonnull PsiElement existing, @Nonnull PsiElement fresh) { if (!existing.equals(fresh) && !existing.isEquivalentTo(fresh) && !fresh.isEquivalentTo(existing) && (seemsToBeResolveTarget(existing) || seemsToBeResolveTarget(fresh))) { return reportProblem(existing, fresh); } return null; }
Example 15
Source File: RuntimeConfigurationProducer.java From consulo with Apache License 2.0 | 4 votes |
private static boolean doesContain(final PsiElement container, PsiElement element) { while ((element = element.getParent()) != null) { if (container.equals(element)) return true; } return false; }
Example 16
Source File: XQueryContextType.java From intellij-xquery with Apache License 2.0 | 4 votes |
private boolean isBeforeQueryBody(PsiElement topmostElement) { PsiElement previousQueryBody = PsiTreeUtil.getPrevSiblingOfType(topmostElement, XQueryQueryBody.class); return previousQueryBody == null && (!(topmostElement instanceof PsiErrorElement) || !topmostElement.equals(getLastChild(topmostElement))); }
Example 17
Source File: BxReference.java From bxfs with MIT License | 4 votes |
@Override public boolean isReferenceTo(PsiElement element) { PsiElement resolvedElement = resolve(); return resolvedElement != null && resolvedElement.equals(element); }