com.intellij.psi.PsiFile#equals ( )源码实例Demo

下面列出了com.intellij.psi.PsiFile#equals ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: intellij   文件: LabelReference.java
@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);
}
 
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;
}
 
源代码3 项目: consulo   文件: FileIncludeManagerImpl.java
@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;
          }
        }
      }
    }
  }
}
 
@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;
}
 
源代码5 项目: BashSupport   文件: FileInclusionManager.java
/**
 * 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;
}
 
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;
}
 
@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()]);
}
 
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());
            }
        }
    }
}
 
源代码9 项目: consulo   文件: QuickFixWrapper.java
@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);
  }
}
 
源代码10 项目: consulo   文件: MethodUpDownUtil.java
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);
  }
}
 
源代码11 项目: consulo   文件: MoveFilesOrDirectoriesProcessor.java
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()]);
}