Java Code Examples for com.intellij.psi.PsiFile#equals()
The following examples show how to use
com.intellij.psi.PsiFile#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: LabelReference.java From intellij with Apache License 2.0 | 6 votes |
@Override public PsiElement bindToElement(PsiElement element) throws IncorrectOperationException { PsiFile file = ResolveUtil.asFileSearch(element); if (file == null) { return super.bindToElement(element); } if (file.equals(resolve())) { return myElement; } BlazePackage currentPackageDir = myElement.getBlazePackage(); if (currentPackageDir == null) { return myElement; } BlazePackage newPackageDir = BlazePackage.getContainingPackage(file); if (!currentPackageDir.equals(newPackageDir)) { return myElement; } String newRuleName = newPackageDir.getPackageRelativePath(file.getViewProvider().getVirtualFile().getPath()); return handleRename(newRuleName); }
Example 2
Source File: JSGraphQLEndpointCompletionContributor.java From js-graphql-intellij-plugin with MIT License | 6 votes |
private boolean completeImportFile(@NotNull CompletionResultSet result, PsiFile file, PsiElement parent) { if ((parent instanceof JSGraphQLEndpointQuotedString || parent instanceof JSGraphQLEndpointString) && PsiTreeUtil.getParentOfType(parent, JSGraphQLEndpointImportFileReference.class) != null) { final Project project = file.getProject(); final VirtualFile entryFile = JSGraphQLConfigurationProvider.getService(project).getEndpointEntryFile(file); final GlobalSearchScope scope = JSGraphQLEndpointPsiUtil.getImportScopeFromEntryFile(project, entryFile, file); final Collection<VirtualFile> files = FileTypeIndex.getFiles(JSGraphQLEndpointFileType.INSTANCE, scope); for (VirtualFile virtualFile : files) { if(virtualFile.equals(entryFile)) { // entry file should never be imported continue; } final PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile); if (psiFile != null) { if(psiFile.equals(file)) { // don't suggest the current file continue; } String name = JSGraphQLEndpointImportUtil.getImportName(project, psiFile); result.addElement(LookupElementBuilder.create(name).withIcon(psiFile.getIcon(0))); } } return true; } return false; }
Example 3
Source File: FileIncludeManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public void processIncludingFiles(PsiFile context, Processor<? super Pair<VirtualFile, FileIncludeInfo>> processor) { context = context.getOriginalFile(); VirtualFile contextFile = context.getVirtualFile(); if (contextFile == null) return; String originalName = context.getName(); Collection<String> names = getPossibleIncludeNames(context, originalName); GlobalSearchScope scope = GlobalSearchScope.allScope(myProject); for (String name : names) { MultiMap<VirtualFile, FileIncludeInfoImpl> infoList = FileIncludeIndex.getIncludingFileCandidates(name, scope); for (VirtualFile candidate : infoList.keySet()) { PsiFile psiFile = myPsiManager.findFile(candidate); if (psiFile == null || context.equals(psiFile)) continue; for (FileIncludeInfo info : infoList.get(candidate)) { PsiFileSystemItem item = resolveFileInclude(info, psiFile); if (item != null && contextFile.equals(item.getVirtualFile())) { if (!processor.process(Pair.create(candidate, info))) { return; } } } } } }
Example 4
Source File: GraphQLConfigPackageSet.java From js-graphql-intellij-plugin with MIT License | 5 votes |
@Override public boolean contains(@NotNull PsiFile file, NamedScopesHolder holder) { if(file.equals(configEntryFile)) { return true; } VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile == null) { virtualFile = file.getOriginalFile().getVirtualFile(); } if (virtualFile != null) { return includesVirtualFile(virtualFile); } return false; }
Example 5
Source File: FileInclusionManager.java From BashSupport with Apache License 2.0 | 5 votes |
/** * Finds all files which include the given file. * The bash files of the module are checked if they include the file. * * @param project The project * @param file The file for which the includers should be found. * @return */ @NotNull public static Set<BashFile> findIncluders(@NotNull Project project, @NotNull PsiFile file) { if (DumbService.isDumb(project)) { return Collections.emptySet(); } GlobalSearchScope searchScope = BashSearchScopes.moduleScope(file); String filename = file.getName(); if (StringUtils.isEmpty(filename)) { return Collections.emptySet(); } Collection<BashIncludeCommand> includeCommands = StubIndex.getElements(BashIncludedFilenamesIndex.KEY, filename, project, BashSearchScopes.bashOnly(searchScope), BashIncludeCommand.class); if (includeCommands == null || includeCommands.isEmpty()) { return Collections.emptySet(); } Set<BashFile> includers = Sets.newLinkedHashSet(); for (BashIncludeCommand command : includeCommands) { BashFile includer = (BashFile) BashPsiUtils.findFileContext(command); if (!file.equals(includer)) { includers.add(includer); } } return includers; }
Example 6
Source File: CSharpAbstractElementTreeNode.java From consulo-csharp with Apache License 2.0 | 5 votes |
private boolean canRepresent(final PsiElement psiElement, final Object element) { if(psiElement == null || !psiElement.isValid()) { return false; } final PsiFile parentFile = psiElement.getContainingFile(); if(parentFile != null && (parentFile == element || parentFile.getVirtualFile() == element)) { return true; } if(!getSettings().isShowMembers()) { if(element instanceof PsiElement && ((PsiElement) element).isValid()) { PsiFile elementFile = ((PsiElement) element).getContainingFile(); if(elementFile != null && parentFile != null) { return elementFile.equals(parentFile); } } } return false; }
Example 7
Source File: CSharpClassesMoveProcessor.java From consulo-csharp with Apache License 2.0 | 5 votes |
@RequiredWriteAction public static NonCodeUsageInfo[] retargetUsages(UsageInfo[] usages) { final List<NonCodeUsageInfo> nonCodeUsages = new ArrayList<>(); for(UsageInfo usageInfo : usages) { if(usageInfo instanceof MyUsageInfo) { MyUsageInfo info = (MyUsageInfo) usageInfo; DotNetNamedElement declaration = info.myDeclarationAndResolveTargetCouple.getFirst(); if(info.getReference() instanceof FileReference || info.getReference() instanceof PsiDynaReference) { final PsiElement usageElement = info.getElement(); if(usageElement != null) { final PsiFile usageFile = usageElement.getContainingFile(); final PsiFile psiFile = usageFile.getViewProvider().getPsi(usageFile.getViewProvider().getBaseLanguage()); if(psiFile != null && psiFile.equals(declaration.getContainingFile())) { continue; // already processed in MoveFilesOrDirectoriesUtil.doMoveFile } } } final PsiElement refElement = info.myReference.getElement(); if(refElement != null && refElement.isValid()) { info.myReference.bindToElement(info.myDeclarationAndResolveTargetCouple.getFirst()); } } else if(usageInfo instanceof NonCodeUsageInfo) { nonCodeUsages.add((NonCodeUsageInfo) usageInfo); } } return nonCodeUsages.toArray(new NonCodeUsageInfo[nonCodeUsages.size()]); }
Example 8
Source File: IncludeVariableCollector.java From idea-php-symfony2-plugin with MIT License | 5 votes |
private void collectContextVars(IElementType iElementType, @NotNull PsiElement element, @NotNull PsiElement includeTag) { String templateName = includeTag.getText(); if(StringUtils.isNotBlank(templateName)) { for(PsiFile templateFile: TwigUtil.getTemplatePsiElements(element.getProject(), templateName)) { if(templateFile.equals(psiFile)) { collectIncludeContextVars(iElementType, element, includeTag, variables, parameter.getVisitedFiles()); } } } }
Example 9
Source File: QuickFixWrapper.java From consulo with Apache License 2.0 | 5 votes |
@Override public void invoke(@Nonnull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { //if (!CodeInsightUtil.prepareFileForWrite(file)) return; // consider all local quick fixes do it themselves final PsiElement element = myDescriptor.getPsiElement(); final PsiFile fileForUndo = element == null ? null : element.getContainingFile(); LocalQuickFix fix = getFix(); fix.applyFix(project, myDescriptor); DaemonCodeAnalyzer.getInstance(project).restart(); if (fileForUndo != null && !fileForUndo.equals(file)) { UndoUtil.markPsiFileForUndo(fileForUndo); } }
Example 10
Source File: MethodUpDownUtil.java From consulo with Apache License 2.0 | 5 votes |
private static void addStructureViewElements(final TreeElement parent, final Collection<PsiElement> array, @Nonnull PsiFile file) { for(TreeElement treeElement: parent.getChildren()) { Object value = ((StructureViewTreeElement)treeElement).getValue(); if (value instanceof PsiElement) { PsiElement element = (PsiElement)value; if (array.contains(element) || !file.equals(element.getContainingFile())) continue; array.add(element); } addStructureViewElements(treeElement, array, file); } }
Example 11
Source File: MoveFilesOrDirectoriesProcessor.java From consulo with Apache License 2.0 | 5 votes |
protected void retargetUsages(UsageInfo[] usages, Map<PsiElement, PsiElement> oldToNewMap) { final List<NonCodeUsageInfo> nonCodeUsages = new ArrayList<>(); for (UsageInfo usageInfo : usages) { if (usageInfo instanceof MyUsageInfo) { final MyUsageInfo info = (MyUsageInfo)usageInfo; final PsiElement element = myElementsToMove[info.myIndex]; if (info.getReference() instanceof FileReference || info.getReference() instanceof PsiDynaReference) { final PsiElement usageElement = info.getElement(); if (usageElement != null) { final PsiFile usageFile = usageElement.getContainingFile(); final PsiFile psiFile = usageFile.getViewProvider().getPsi(usageFile.getViewProvider().getBaseLanguage()); if (psiFile != null && psiFile.equals(element)) { continue; // already processed in MoveFilesOrDirectoriesUtil.doMoveFile } } } final PsiElement refElement = info.myReference.getElement(); if (refElement != null && refElement.isValid()) { info.myReference.bindToElement(element); } } else if (usageInfo instanceof NonCodeUsageInfo) { nonCodeUsages.add((NonCodeUsageInfo)usageInfo); } } for (PsiFile movedFile : myFoundUsages.keySet()) { MoveFileHandler.forElement(movedFile).retargetUsages(myFoundUsages.get(movedFile), oldToNewMap); } myNonCodeUsages = nonCodeUsages.toArray(new NonCodeUsageInfo[nonCodeUsages.size()]); }