diff --git a/platform/core-api/src/com/intellij/usageView/UsageInfo.java b/platform/core-api/src/com/intellij/usageView/UsageInfo.java index f5b177196ff6..371ed8c4dbf7 100644 --- a/platform/core-api/src/com/intellij/usageView/UsageInfo.java +++ b/platform/core-api/src/com/intellij/usageView/UsageInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -79,7 +79,7 @@ public class UsageInfo { } public UsageInfo(@NotNull SmartPsiElementPointer smartPointer, - SmartPsiFileRange psiFileRange, + @Nullable SmartPsiFileRange psiFileRange, boolean dynamicUsage, boolean nonCodeUsage) { myDynamicUsage = dynamicUsage; @@ -88,21 +88,13 @@ public class UsageInfo { mySmartPointer = smartPointer; } - @NotNull - public SmartPsiElementPointer getSmartPointer() { - return mySmartPointer; - } - - public SmartPsiFileRange getPsiFileRange() { - return myPsiFileRange; - } - - public boolean isNonCodeUsage() { - return isNonCodeUsage; - } - - public void setDynamicUsage(boolean dynamicUsage) { - myDynamicUsage = dynamicUsage; + // in case of find file by name, not by text inside. Since it can be a binary file, do not query for text offsets. + public UsageInfo(@NotNull PsiFile psiFile) { + Project project = psiFile.getProject(); + SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(project); + mySmartPointer = smartPointerManager.createSmartPsiElementPointer(psiFile); + myPsiFileRange = null; + isNonCodeUsage = true; } public UsageInfo(@NotNull PsiElement element, boolean isNonCodeUsage) { @@ -126,6 +118,23 @@ public class UsageInfo { this(element, false); } + @NotNull + public SmartPsiElementPointer getSmartPointer() { + return mySmartPointer; + } + + public SmartPsiFileRange getPsiFileRange() { + return myPsiFileRange; + } + + public boolean isNonCodeUsage() { + return isNonCodeUsage; + } + + public void setDynamicUsage(boolean dynamicUsage) { + myDynamicUsage = dynamicUsage; + } + @Nullable public PsiElement getElement() { // SmartPointer is used to fix SCR #4572, hotya eto krivo i nado vse perepisat' return mySmartPointer.getElement(); @@ -209,13 +218,18 @@ public class UsageInfo { } public boolean isValid() { + if (myPsiFileRange == null && getElement() instanceof PsiFile) { + return true; // in case of binary file + } return getSegment() != null; } @Nullable public Segment getSegment() { PsiElement element = getElement(); - if (element == null) return null; + if (element == null + // in case of binary file + || myPsiFileRange == null && element instanceof PsiFile) return null; TextRange range = element.getTextRange(); TextRange.assertProperRange(range, element); if (element instanceof PsiFile) { diff --git a/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java b/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java index 210a906e4026..7369956b960d 100644 --- a/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java +++ b/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java @@ -247,7 +247,7 @@ public class FindInProjectUtil { if (!ApplicationManager.getApplication().runReadAction(new Computable() { @Override public Boolean compute() { - return consumer.process(new UsageInfo(psiFile,0,0,true)); + return consumer.process(new UsageInfo(psiFile)); } })) { throw new ProcessCanceledException(); diff --git a/platform/usageView/src/com/intellij/usages/ChunkExtractor.java b/platform/usageView/src/com/intellij/usages/ChunkExtractor.java index 929f0486299d..fa6f6d785052 100644 --- a/platform/usageView/src/com/intellij/usages/ChunkExtractor.java +++ b/platform/usageView/src/com/intellij/usages/ChunkExtractor.java @@ -116,7 +116,6 @@ public class ChunkExtractor { Project project = file.getProject(); myDocument = PsiDocumentManager.getInstance(project).getDocument(file); - LOG.assertTrue(myDocument != null); final FileType fileType = file.getFileType(); SyntaxHighlighter highlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(fileType, project, file.getVirtualFile()); highlighter = highlighter == null ? new PlainSyntaxHighlighter() : highlighter;