com.intellij.psi.PsiFile

Here are the examples of the java api class com.intellij.psi.PsiFile taken from open source projects.

1. ReformatOnlyVcsChangedTextTest#testReformatInAllSubtree()

View license
public void testReformatInAllSubtree() throws IOException {
    ChangedFilesStructure fs = new ChangedFilesStructure(myWorkingDirectory);
    PsiFile modified11 = fs.createFile("Test4.java", COMMITTED, MODIFIED);
    PsiFile modified12 = fs.createFile("Test5.java", COMMITTED, MODIFIED);
    fs.createDirectoryAndMakeItCurrent();
    PsiDirectory dirToReformat = fs.getCurrentDirectory();
    PsiFile modified21 = fs.createFile("Test6.java", COMMITTED, MODIFIED);
    PsiFile modified22 = fs.createFile("Test7.java", COMMITTED, MODIFIED);
    fs.createDirectoryAndMakeItCurrent();
    PsiFile modified31 = fs.createFile("Test8.java", COMMITTED, MODIFIED);
    PsiFile modified32 = fs.createFile("Test9.java", COMMITTED, MODIFIED);
    reformatDirectory(dirToReformat);
    assertFormattedLines(CHANGED_LINES, modified21, modified22, modified31, modified32);
    assertFormattedLines(NO_CHANGED_LINES, modified11, modified12);
}

2. ReformatFilesWithFiltersTest#testIDEA126830()

View license
public void testIDEA126830() throws IOException {
    TestFileStructure fileTree = new TestFileStructure(getModule(), myWorkingDirectory);
    fileTree.createDirectoryAndMakeItCurrent("src");
    PsiFile java2 = fileTree.addTestFile("Test2.tj", "empty content");
    PsiFile php2 = fileTree.addTestFile("Pair2.php", "empty content");
    PsiFile js2 = fileTree.addTestFile("Pair2.js", "empty content");
    PsiDirectory test = fileTree.createDirectoryAndMakeItCurrent("test");
    PsiFile testJava1 = fileTree.addTestFile("testJava1.tj", "empty content");
    PsiFile testPhp1 = fileTree.addTestFile("testPhp1.php", "empty content");
    PsiFile testJs1 = fileTree.addTestFile("testJs1.js", "empty content");
    GlobalSearchScope testScope = directoryScope(test, true);
    reformatAndOptimize(myWorkingDirectory, testScope);
    assertWasFormatted(testJava1, testPhp1, testJs1);
    assertWasNotFormatted(java2, php2, js2);
}

3. ReformatFilesWithFiltersTest#testReformatWithoutMask()

View license
public void testReformatWithoutMask() throws IOException {
    TestFileStructure fileTree = new TestFileStructure(getModule(), myWorkingDirectory);
    PsiFile java1 = fileTree.addTestFile("Test.java", "empty content");
    PsiFile java2 = fileTree.addTestFile("Pair.java", "empty content");
    PsiFile java3 = fileTree.addTestFile("Pair2.java", "empty content");
    PsiFile php = fileTree.addTestFile("Test.php", "empty content");
    PsiFile js = fileTree.addTestFile("Test.js", "empty content");
    reformatDirectoryWithFileMask(myWorkingDirectory, null);
    assertWasFormatted(java1, java2, java3, php, js);
}

4. ReformatFilesWithFiltersTest#testFormatByOnlyOneMask()

View license
public void testFormatByOnlyOneMask() throws IOException {
    TestFileStructure fileTree = new TestFileStructure(getModule(), myWorkingDirectory);
    PsiFile java1 = fileTree.addTestFile("Test.java", "empty content");
    PsiFile java2 = fileTree.addTestFile("Pair.java", "empty content");
    PsiFile java3 = fileTree.addTestFile("Pair2.java", "empty content");
    PsiFile php = fileTree.addTestFile("Test.php", "empty content");
    PsiFile js = fileTree.addTestFile("Test.js", "empty content");
    reformatDirectoryWithFileMask(myWorkingDirectory, "*.java");
    assertWasFormatted(java1, java2, java3);
    assertWasNotFormatted(php, js);
    reformatDirectoryWithFileMask(myWorkingDirectory, "*.js");
    assertWasFormatted(js);
    assertWasNotFormatted(java1, java2, java3, php);
}

5. ReformatOnlyVcsChangedTextTest#testReformatOnlyChanged()

View license
public void testReformatOnlyChanged() throws IOException {
    ChangedFilesStructure fs = new ChangedFilesStructure(myWorkingDirectory);
    PsiFile untouched1 = fs.createFile("Test1.java", COMMITTED, COMMITTED);
    PsiFile untouched2 = fs.createFile("Test2.java", COMMITTED, COMMITTED);
    PsiFile modified1 = fs.createFile("Test4.java", COMMITTED, MODIFIED);
    PsiFile modified2 = fs.createFile("Test5.java", COMMITTED, MODIFIED);
    PsiFile modified3 = fs.createFile("Test6.java", COMMITTED, MODIFIED);
    reformatDirectory(fs.getCurrentDirectory());
    assertFormattedLines(CHANGED_LINES, modified1, modified2, modified3);
    assertFormattedLines(NO_CHANGED_LINES, untouched1, untouched2);
}

6. ReformatOnlyVcsChangedTextTest#testReformatFiles()

View license
public void testReformatFiles() throws IOException {
    ChangedFilesStructure fs = new ChangedFilesStructure(myWorkingDirectory);
    PsiFile m1 = fs.createFile("Test1.java", COMMITTED, MODIFIED);
    PsiFile u1 = fs.createFile("Test2.java", COMMITTED, COMMITTED);
    fs.createDirectoryAndMakeItCurrent();
    PsiFile m2 = fs.createFile("Test3.java", COMMITTED, MODIFIED);
    PsiFile u2 = fs.createFile("Test4.java", COMMITTED, COMMITTED);
    new ReformatCodeProcessor(getProject(), new PsiFile[] { m1, m2, u1, u2 }, null, true).run();
    assertFormattedLines(CHANGED_LINES, m1, m2);
    assertFormattedLines(NO_CHANGED_LINES, u1, u2);
}

7. HaskellGoToSymbolTest#testGoToSymbolFunction_QualifiedImport()

View license
public void testGoToSymbolFunction_QualifiedImport() {
    PsiFile[] psiFiles = myFixture.configureByFiles("QualifiedImport/Usage.hs", "QualifiedImport/Definition.hs");
    PsiFile usage = psiFiles[0];
    PsiFile definition = psiFiles[1];
    String textOfFile = definition.getText();
    int expectedStartOffset = textOfFile.indexOf("seven ::");
    PsiElement psiElement = usage.findElementAt(myFixture.getCaretOffset()).getParent();
    HaskellVarid varId = (HaskellVarid) psiElement;
    PsiReference reference = varId.getReference();
    HaskellVarid referencedElement = (HaskellVarid) reference.resolve();
    assertNotSame(psiElement, referencedElement);
    assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset());
}

8. HaskellGoToSymbolTest#testGoToSymbolFunction_QualifiedImportNoAs()

View license
public void testGoToSymbolFunction_QualifiedImportNoAs() {
    PsiFile[] psiFiles = myFixture.configureByFiles("QualifiedImportNoAs/Usage.hs", "QualifiedImportNoAs/Definition.hs");
    PsiFile usage = psiFiles[0];
    PsiFile definition = psiFiles[1];
    String textOfFile = definition.getText();
    int expectedStartOffset = textOfFile.indexOf("seven ::");
    PsiElement psiElement = usage.findElementAt(myFixture.getCaretOffset()).getParent();
    HaskellVarid varId = (HaskellVarid) psiElement;
    PsiReference reference = varId.getReference();
    HaskellVarid referencedElement = (HaskellVarid) reference.resolve();
    assertNotSame(psiElement, referencedElement);
    assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset());
}

9. HaskellGoToSymbolTest#testGoToSymbolFunction_QualifiedImportMultipleLevels()

View license
public void testGoToSymbolFunction_QualifiedImportMultipleLevels() {
    PsiFile[] psiFiles = myFixture.configureByFiles("QualifiedImportMultipleLevels/Usage/Usage.hs", "QualifiedImportMultipleLevels/Definition/Definition.hs");
    PsiFile usage = psiFiles[0];
    PsiFile definition = psiFiles[1];
    String textOfFile = definition.getText();
    int expectedStartOffset = textOfFile.indexOf("seven ::");
    PsiElement psiElement = usage.findElementAt(myFixture.getCaretOffset()).getParent();
    HaskellVarid varId = (HaskellVarid) psiElement;
    PsiReference reference = varId.getReference();
    HaskellVarid referencedElement = (HaskellVarid) reference.resolve();
    assertNotSame(psiElement, referencedElement);
    assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset());
}

10. HaskellGoToSymbolTest#testGoToSymbolFunction_QualifiedImportMultipleLevels_LocalFunctionWithSameName()

View license
public void testGoToSymbolFunction_QualifiedImportMultipleLevels_LocalFunctionWithSameName() {
    PsiFile[] psiFiles = myFixture.configureByFiles("QualifiedImportMultipleLevels_LocalFunctionWithSameName/Usage/Usage.hs", "QualifiedImportMultipleLevels_LocalFunctionWithSameName/Definition/Definition.hs");
    PsiFile usage = psiFiles[0];
    PsiFile definition = psiFiles[1];
    String textOfFile = definition.getText();
    int expectedStartOffset = textOfFile.indexOf("seven ::");
    PsiElement psiElement = usage.findElementAt(myFixture.getCaretOffset()).getParent();
    HaskellVarid varId = (HaskellVarid) psiElement;
    PsiReference reference = varId.getReference();
    HaskellVarid referencedElement = (HaskellVarid) reference.resolve();
    assertNotSame(psiElement, referencedElement);
    assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset());
}

11. HaskellGoToSymbolTest#testGoToSymbolFunction_QualifiedImportMultipleLevels_AsPartConsistsOfMultipleCons()

View license
public void testGoToSymbolFunction_QualifiedImportMultipleLevels_AsPartConsistsOfMultipleCons() {
    PsiFile[] psiFiles = myFixture.configureByFiles("QualifiedImportMultipleLevels_AsPartConsistsOfMultipleCons/Usage/Usage.hs", "QualifiedImportMultipleLevels_AsPartConsistsOfMultipleCons/Definition/Definition.hs");
    PsiFile usage = psiFiles[0];
    PsiFile definition = psiFiles[1];
    String textOfFile = definition.getText();
    int expectedStartOffset = textOfFile.indexOf("seven ::");
    PsiElement psiElement = usage.findElementAt(myFixture.getCaretOffset()).getParent();
    HaskellVarid varId = (HaskellVarid) psiElement;
    PsiReference reference = varId.getReference();
    HaskellVarid referencedElement = (HaskellVarid) reference.resolve();
    assertNotSame(psiElement, referencedElement);
    assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset());
}

12. HaskellGoToSymbolTest#testGoToSymbolFunction_ImportResolvesToModule()

View license
public void testGoToSymbolFunction_ImportResolvesToModule() {
    PsiFile[] psiFiles = myFixture.configureByFiles("ImportResolvesToModule/Usage.hs", "ImportResolvesToModule/Definition.hs");
    PsiFile usage = psiFiles[0];
    PsiFile definition = psiFiles[1];
    String textOfFile = definition.getText();
    int expectedStartOffset = textOfFile.indexOf("module Definition") + 7;
    PsiElement psiElement = usage.findElementAt(myFixture.getCaretOffset()).getParent();
    HaskellConid conId = (HaskellConid) psiElement;
    PsiReference reference = conId.getReference();
    HaskellConid referencedElement = (HaskellConid) reference.resolve();
    assertNotSame(psiElement, referencedElement);
    assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset());
}

13. HaskellGoToSymbolTest#testGoToSymbolFunction_ImportResolvesToModule_MultipleCons_OnModule()

View license
public void testGoToSymbolFunction_ImportResolvesToModule_MultipleCons_OnModule() {
    PsiFile[] psiFiles = myFixture.configureByFiles("ImportResolvesToModule_MultipleCons_OnModule/Usage.hs", "ImportResolvesToModule_MultipleCons_OnModule/Definition.hs");
    PsiFile usage = psiFiles[0];
    PsiFile definition = psiFiles[1];
    String textOfFile = definition.getText();
    int expectedStartOffset = textOfFile.indexOf("module Definition.Definition") + 18;
    PsiElement psiElement = usage.findElementAt(myFixture.getCaretOffset()).getParent();
    HaskellConid conId = (HaskellConid) psiElement;
    PsiReference reference = conId.getReference();
    HaskellConid referencedElement = (HaskellConid) reference.resolve();
    assertNotSame(psiElement, referencedElement);
    assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset());
}

14. HaskellGoToSymbolTest#testGoToSymbolFunction_ImportResolvesToModule_MultipleCons_OnPrefix()

View license
public void testGoToSymbolFunction_ImportResolvesToModule_MultipleCons_OnPrefix() {
    PsiFile[] psiFiles = myFixture.configureByFiles("ImportResolvesToModule_MultipleCons_OnPrefix/Usage.hs", "ImportResolvesToModule_MultipleCons_OnPrefix/Definition.hs");
    PsiFile usage = psiFiles[0];
    PsiFile definition = psiFiles[1];
    String textOfFile = definition.getText();
    int expectedStartOffset = textOfFile.indexOf("module Definition.Definition") + 7;
    PsiElement psiElement = usage.findElementAt(myFixture.getCaretOffset()).getParent();
    HaskellConid conId = (HaskellConid) psiElement;
    PsiReference reference = conId.getReference();
    HaskellConid referencedElement = (HaskellConid) reference.resolve();
    assertNotSame(psiElement, referencedElement);
    assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset());
}

15. LookupImpl#getPsiElement()

Project: consulo
Source File: LookupImpl.java
View license
@Override
public PsiElement getPsiElement() {
    PsiFile file = getPsiFile();
    if (file == null)
        return null;
    int offset = getLookupStart();
    Editor editor = getEditor();
    if (editor instanceof EditorWindow) {
        offset = editor.logicalPositionToOffset(((EditorWindow) editor).hostToInjected(myEditor.offsetToLogicalPosition(offset)));
    }
    if (offset > 0)
        return file.findElementAt(offset - 1);
    return file.findElementAt(0);
}

16. ShowIntentionActionsHandler#chooseBetweenHostAndInjected()

View license
@Nullable
public static Pair<PsiFile, Editor> chooseBetweenHostAndInjected(@NotNull PsiFile hostFile, @NotNull Editor hostEditor, @NotNull PairProcessor<PsiFile, Editor> predicate) {
    Editor editorToApply = null;
    PsiFile fileToApply = null;
    int offset = hostEditor.getCaretModel().getOffset();
    PsiFile injectedFile = InjectedLanguageUtil.findInjectedPsiNoCommit(hostFile, offset);
    if (injectedFile != null) {
        Editor injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(hostEditor, injectedFile);
        if (predicate.process(injectedFile, injectedEditor)) {
            editorToApply = injectedEditor;
            fileToApply = injectedFile;
        }
    }
    if (editorToApply == null && predicate.process(hostFile, hostEditor)) {
        editorToApply = hostEditor;
        fileToApply = hostFile;
    }
    if (editorToApply == null)
        return null;
    return Pair.create(fileToApply, editorToApply);
}

17. PrintManager#addToPsiFileList()

Project: consulo
Source File: PrintManager.java
View license
private static void addToPsiFileList(PsiDirectory psiDirectory, List<Pair<PsiFile, Editor>> filesList, boolean isRecursive) {
    PsiFile[] files = psiDirectory.getFiles();
    for (PsiFile file : files) {
        filesList.add(Pair.create(file, PsiUtilBase.findEditor(file)));
    }
    if (isRecursive) {
        for (PsiDirectory directory : psiDirectory.getSubdirectories()) {
            if (!Project.DIRECTORY_STORE_FOLDER.equals(directory.getName())) {
                addToPsiFileList(directory, filesList, isRecursive);
            }
        }
    }
}

18. LanguageVersionUtil#findLanguageVersion()

Project: consulo
Source File: LanguageVersionUtil.java
View license
public static LanguageVersion<?> findLanguageVersion(@NotNull Language language, @NotNull PsiFile psiFile) {
    if (psiFile.getLanguage() == language) {
        return psiFile.getLanguageVersion();
    }
    FileViewProvider viewProvider = psiFile.getViewProvider();
    PsiFile psi = viewProvider.getPsi(language);
    if (psi == null) {
        return LanguageVersionResolvers.INSTANCE.forLanguage(language).getLanguageVersion(language, psiFile);
    }
    return psi.getLanguageVersion();
}

19. AnnotationHolderImpl#assertMyFile()

Project: consulo
Source File: AnnotationHolderImpl.java
View license
private void assertMyFile(PsiElement node) {
    if (node == null)
        return;
    PsiFile myFile = myAnnotationSession.getFile();
    PsiFile containingFile = node.getContainingFile();
    LOG.assertTrue(containingFile != null, node);
    VirtualFile containingVFile = containingFile.getVirtualFile();
    VirtualFile myVFile = myFile.getVirtualFile();
    if (!Comparing.equal(containingVFile, myVFile)) {
        LOG.error("Annotation must be registered for an element inside '" + myFile + "' which is in '" + myVFile + "'.\n" + "Element passed: '" + node + "' is inside the '" + containingFile + "' which is in '" + containingVFile + "'");
    }
}

20. ModulesUtil#isModule()

Project: svgtoandroid
Source File: ModulesUtil.java
View license
private boolean isModule(PsiDirectory directory) {
    boolean hasGradle = false;
    boolean hasSrc = false;
    PsiFile[] files = directory.getFiles();
    PsiDirectory[] dirs = directory.getSubdirectories();
    for (PsiFile file : files) {
        if (file.getName().equals("build.gradle")) {
            hasGradle = true;
            break;
        }
    }
    for (PsiDirectory dir : dirs) {
        if (dir.getName().equals("src")) {
            hasSrc = true;
            break;
        }
    }
    return hasGradle && hasSrc;
}

21. AbstractLombokParsingTestCase#doTest()

View license
protected void doTest(final String beforeFileName, final String afterFileName) throws IOException {
    final PsiFile psiDelombokFile = loadToPsiFile(afterFileName);
    final PsiFile psiLombokFile = loadToPsiFile(beforeFileName);
    if (!(psiLombokFile instanceof PsiJavaFile) || !(psiDelombokFile instanceof PsiJavaFile)) {
        fail("The test file type is not supported");
    }
    final PsiJavaFile beforeFile = (PsiJavaFile) psiLombokFile;
    final PsiJavaFile afterFile = (PsiJavaFile) psiDelombokFile;
    PsiClass[] beforeClasses = beforeFile.getClasses();
    PsiClass[] afterClasses = afterFile.getClasses();
    compareClasses(beforeClasses, afterClasses);
}

22. HaskellGoToSymbolTest#testGoToSymbolFunction_QualifiedImport_MultipleImportSameQualifiedName2()

View license
public void testGoToSymbolFunction_QualifiedImport_MultipleImportSameQualifiedName2() {
    PsiFile[] psiFiles = myFixture.configureByFiles("QualifiedImport_MultipleImportSameQualifiedName2/Usage/Usage.hs", "QualifiedImport_MultipleImportSameQualifiedName2/Definition/Definition.hs", "QualifiedImport_MultipleImportSameQualifiedName2/Other/Definition.hs");
    PsiFile usage = psiFiles[0];
    String textOfFile = usage.getText();
    int expectedStartOffset = textOfFile.indexOf("qualified Other.Definition as Definition") + 30;
    PsiElement psiElement = usage.findElementAt(myFixture.getCaretOffset()).getParent();
    HaskellConid conId = (HaskellConid) psiElement;
    PsiReference reference = conId.getReference();
    HaskellConid referencedElement = (HaskellConid) reference.resolve();
    assertNotSame(psiElement, referencedElement);
    assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset());
}

23. HaskellGoToSymbolTest#testGoToSymbolFunction_QualifiedImport_MultipleImportSameQualifiedName1()

View license
public void testGoToSymbolFunction_QualifiedImport_MultipleImportSameQualifiedName1() {
    PsiFile[] psiFiles = myFixture.configureByFiles("QualifiedImport_MultipleImportSameQualifiedName1/Usage/Usage.hs", "QualifiedImport_MultipleImportSameQualifiedName1/Definition/Definition.hs", "QualifiedImport_MultipleImportSameQualifiedName1/Other/Definition.hs");
    PsiFile usage = psiFiles[0];
    String textOfFile = usage.getText();
    int expectedStartOffset = textOfFile.indexOf("qualified Definition.Definition as Definition") + 35;
    PsiElement psiElement = usage.findElementAt(myFixture.getCaretOffset()).getParent();
    HaskellConid conId = (HaskellConid) psiElement;
    PsiReference reference = conId.getReference();
    HaskellConid referencedElement = (HaskellConid) reference.resolve();
    assertNotSame(psiElement, referencedElement);
    assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset());
}

24. HaskellGoToSymbolTest#testGoToSymbolFunction_QualifiedImportQualifierresolvesMultipleCons_Cons2_NoAs()

View license
public void testGoToSymbolFunction_QualifiedImportQualifierresolvesMultipleCons_Cons2_NoAs() {
    PsiFile[] psiFiles = myFixture.configureByFiles("QualifiedImport_QualifierResolvesMultipleCons_Cons2_NoAs/Usage.hs", "QualifiedImport_QualifierResolvesMultipleCons_Cons2_NoAs/Definition.hs");
    PsiFile usage = psiFiles[0];
    String textOfFile = usage.getText();
    int expectedStartOffset = textOfFile.indexOf("qualified Definition.Definition") + 21;
    PsiElement psiElement = usage.findElementAt(myFixture.getCaretOffset()).getParent();
    HaskellConid conId = (HaskellConid) psiElement;
    PsiReference reference = conId.getReference();
    HaskellConid referencedElement = (HaskellConid) reference.resolve();
    assertNotSame(psiElement, referencedElement);
    assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset());
}

25. HaskellGoToSymbolTest#testGoToSymbolFunction_QualifiedImportQualifierresolvesMultipleCons_Cons1_NoAs()

View license
public void testGoToSymbolFunction_QualifiedImportQualifierresolvesMultipleCons_Cons1_NoAs() {
    PsiFile[] psiFiles = myFixture.configureByFiles("QualifiedImport_QualifierResolvesMultipleCons_Cons1_NoAs/Usage.hs", "QualifiedImport_QualifierResolvesMultipleCons_Cons1_NoAs/Definition.hs");
    PsiFile usage = psiFiles[0];
    String textOfFile = usage.getText();
    int expectedStartOffset = textOfFile.indexOf("qualified Definition.Definition") + 10;
    PsiElement psiElement = usage.findElementAt(myFixture.getCaretOffset()).getParent();
    HaskellConid conId = (HaskellConid) psiElement;
    PsiReference reference = conId.getReference();
    HaskellConid referencedElement = (HaskellConid) reference.resolve();
    assertNotSame(psiElement, referencedElement);
    assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset());
}

26. HaskellGoToSymbolTest#testGoToSymbolFunction_QualifiedImportQualifierresolvesMultipleCons_Cons2()

View license
public void testGoToSymbolFunction_QualifiedImportQualifierresolvesMultipleCons_Cons2() {
    PsiFile[] psiFiles = myFixture.configureByFiles("QualifiedImport_QualifierResolvesMultipleCons_Cons2/Usage.hs", "QualifiedImport_QualifierResolvesMultipleCons_Cons2/Definition.hs");
    PsiFile usage = psiFiles[0];
    String textOfFile = usage.getText();
    int expectedStartOffset = textOfFile.indexOf("as Def.Lef") + 7;
    PsiElement psiElement = usage.findElementAt(myFixture.getCaretOffset()).getParent();
    HaskellConid conId = (HaskellConid) psiElement;
    PsiReference reference = conId.getReference();
    HaskellConid referencedElement = (HaskellConid) reference.resolve();
    assertNotSame(psiElement, referencedElement);
    assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset());
}

27. HaskellGoToSymbolTest#testGoToSymbolFunction_QualifiedImportQualifierresolvesMultipleCons_Cons1()

View license
public void testGoToSymbolFunction_QualifiedImportQualifierresolvesMultipleCons_Cons1() {
    PsiFile[] psiFiles = myFixture.configureByFiles("QualifiedImport_QualifierResolvesMultipleCons_Cons1/Usage.hs", "QualifiedImport_QualifierResolvesMultipleCons_Cons1/Definition.hs");
    PsiFile usage = psiFiles[0];
    String textOfFile = usage.getText();
    int expectedStartOffset = textOfFile.indexOf("as Def.Lef") + 3;
    PsiElement psiElement = usage.findElementAt(myFixture.getCaretOffset()).getParent();
    HaskellConid conId = (HaskellConid) psiElement;
    PsiReference reference = conId.getReference();
    HaskellConid referencedElement = (HaskellConid) reference.resolve();
    assertNotSame(psiElement, referencedElement);
    assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset());
}

28. HaskellGoToSymbolTest#testGoToSymbolFunction_QualifiedImportQualifierresolves()

View license
public void testGoToSymbolFunction_QualifiedImportQualifierresolves() {
    PsiFile[] psiFiles = myFixture.configureByFiles("QualifiedImport_QualifierResolves/Usage.hs", "QualifiedImport_QualifierResolves/Definition.hs");
    PsiFile usage = psiFiles[0];
    String textOfFile = usage.getText();
    int expectedStartOffset = textOfFile.indexOf("as Def") + 3;
    PsiElement psiElement = usage.findElementAt(myFixture.getCaretOffset()).getParent();
    HaskellConid conId = (HaskellConid) psiElement;
    PsiReference reference = conId.getReference();
    HaskellConid referencedElement = (HaskellConid) reference.resolve();
    assertNotSame(psiElement, referencedElement);
    assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset());
}

29. HaskellGoToSymbolTest#testGoToSymbolFunction_QualifiedImportMultipleLevels_LocalFunctionWithSameName_CaretOnLocal()

View license
public void testGoToSymbolFunction_QualifiedImportMultipleLevels_LocalFunctionWithSameName_CaretOnLocal() {
    PsiFile[] psiFiles = myFixture.configureByFiles("QualifiedImportMultipleLevels_LocalFunctionWithSameName_CaretOnLocal/Usage/Usage.hs", "QualifiedImportMultipleLevels_LocalFunctionWithSameName_CaretOnLocal/Definition/Definition.hs");
    PsiFile usage = psiFiles[0];
    String textOfFile = usage.getText();
    int expectedStartOffset = textOfFile.indexOf("seven ::");
    PsiElement psiElement = usage.findElementAt(myFixture.getCaretOffset()).getParent();
    HaskellVarid varId = (HaskellVarid) psiElement;
    PsiReference reference = varId.getReference();
    HaskellVarid referencedElement = (HaskellVarid) reference.resolve();
    assertNotSame(psiElement, referencedElement);
    assertEquals(expectedStartOffset, referencedElement.getTextRange().getStartOffset());
}

30. RelaxIncludeIndex#processRelatedFiles()

View license
private static boolean processRelatedFiles(PsiFile file, VirtualFile[] files, PsiElementProcessor<XmlFile> processor) {
    Project project = file.getProject();
    final PsiManager psiManager = PsiManager.getInstance(project);
    final PsiFile[] psiFiles = ContainerUtil.map2Array(files, PsiFile.class, (NullableFunction<VirtualFile, PsiFile>)  file1 -> psiManager.findFile(file1));
    for (final PsiFile psiFile : psiFiles) {
        if (!processFile(psiFile, processor)) {
            return false;
        }
    }
    return true;
}

31. LookupImpl#getPsiElement()

Project: intellij-community
Source File: LookupImpl.java
View license
@Override
public PsiElement getPsiElement() {
    PsiFile file = getPsiFile();
    if (file == null)
        return null;
    int offset = getLookupStart();
    Editor editor = getEditor();
    if (editor instanceof EditorWindow) {
        offset = editor.logicalPositionToOffset(((EditorWindow) editor).hostToInjected(myEditor.offsetToLogicalPosition(offset)));
    }
    if (offset > 0)
        return file.findElementAt(offset - 1);
    return file.findElementAt(0);
}

32. ShowIntentionActionsHandler#chooseBetweenHostAndInjected()

View license
@Nullable
public static Pair<PsiFile, Editor> chooseBetweenHostAndInjected(@NotNull PsiFile hostFile, @NotNull Editor hostEditor, @NotNull PairProcessor<PsiFile, Editor> predicate) {
    Editor editorToApply = null;
    PsiFile fileToApply = null;
    int offset = hostEditor.getCaretModel().getOffset();
    PsiFile injectedFile = InjectedLanguageUtil.findInjectedPsiNoCommit(hostFile, offset);
    if (injectedFile != null) {
        Editor injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(hostEditor, injectedFile);
        if (predicate.process(injectedFile, injectedEditor)) {
            editorToApply = injectedEditor;
            fileToApply = injectedFile;
        }
    }
    if (editorToApply == null && predicate.process(hostFile, hostEditor)) {
        editorToApply = hostEditor;
        fileToApply = hostFile;
    }
    if (editorToApply == null)
        return null;
    return Pair.create(fileToApply, editorToApply);
}

33. PrintManager#addToPsiFileList()

View license
private static void addToPsiFileList(PsiDirectory psiDirectory, List<Pair<PsiFile, Editor>> filesList, boolean isRecursive) {
    PsiFile[] files = psiDirectory.getFiles();
    for (PsiFile file : files) {
        filesList.add(Pair.create(file, PsiUtilBase.findEditor(file)));
    }
    if (isRecursive) {
        for (PsiDirectory directory : psiDirectory.getSubdirectories()) {
            if (!Project.DIRECTORY_STORE_FOLDER.equals(directory.getName())) {
                addToPsiFileList(directory, filesList, true);
            }
        }
    }
}

34. BackwardDependenciesBuilder#subtractScope()

View license
private static void subtractScope(final DependenciesBuilder builders, final AnalysisScope scope) {
    final Map<PsiFile, Set<PsiFile>> dependencies = builders.getDependencies();
    Set<PsiFile> excluded = new HashSet<PsiFile>();
    for (final PsiFile psiFile : dependencies.keySet()) {
        if (scope.contains(psiFile)) {
            excluded.add(psiFile);
        }
    }
    for (final PsiFile psiFile : excluded) {
        dependencies.remove(psiFile);
    }
}

35. AnnotationHolderImpl#assertMyFile()

View license
private void assertMyFile(PsiElement node) {
    if (node == null)
        return;
    PsiFile myFile = myAnnotationSession.getFile();
    PsiFile containingFile = node.getContainingFile();
    LOG.assertTrue(containingFile != null, node);
    VirtualFile containingVFile = containingFile.getVirtualFile();
    VirtualFile myVFile = myFile.getVirtualFile();
    if (!Comparing.equal(containingVFile, myVFile)) {
        LOG.error("Annotation must be registered for an element inside '" + myFile + "' which is in '" + myVFile + "'.\n" + "Element passed: '" + node + "' is inside the '" + containingFile + "' which is in '" + containingVFile + "'");
    }
}

36. PyStudyImportResolver#resolveImportReference()

View license
@Nullable
public PsiElement resolveImportReference(QualifiedName name, QualifiedNameResolveContext context, boolean withRoots) {
    if (StudyTaskManager.getInstance(context.getProject()).getCourse() == null) {
        return null;
    }
    final String nameString = name.toString();
    PsiFile containingFile = context.getFootholdFile();
    if (containingFile == null)
        return null;
    final PsiDirectory directory = containingFile.getContainingDirectory();
    if (directory == null)
        return null;
    final PsiFile file = directory.findFile(nameString + ".py");
    if (file != null) {
        return file;
    }
    return null;
}

37. XsltIncludeIndex#_process()

View license
private static boolean _process(VirtualFile[] files, Project project, Processor<XmlFile> processor) {
    final PsiManager psiManager = PsiManager.getInstance(project);
    final PsiFile[] psiFiles = ContainerUtil.map2Array(files, PsiFile.class, (NullableFunction<VirtualFile, PsiFile>)  file -> psiManager.findFile(file));
    for (final PsiFile psiFile : psiFiles) {
        if (XsltSupport.isXsltFile(psiFile)) {
            if (!processor.process((XmlFile) psiFile)) {
                return false;
            }
        }
    }
    return true;
}

38. Form#containsFile()

Project: intellij-community
Source File: Form.java
View license
public boolean containsFile(final VirtualFile vFile) {
    final PsiFile classFile = myClassToBind.getContainingFile();
    final VirtualFile classVFile = classFile == null ? null : classFile.getVirtualFile();
    if (classVFile != null && classVFile.equals(vFile)) {
        return true;
    }
    for (PsiFile psiFile : myFormFiles) {
        final VirtualFile virtualFile = psiFile.getVirtualFile();
        if (virtualFile != null && virtualFile.equals(vFile)) {
            return true;
        }
    }
    return false;
}

39. Form2SourceCompiler#findSourceFile()

View license
private static VirtualFile findSourceFile(final CompileContext context, final VirtualFile formFile, final String className) {
    final Module module = context.getModuleByFile(formFile);
    if (module == null) {
        return null;
    }
    final PsiClass aClass = FormEditingUtil.findClassToBind(module, className);
    if (aClass == null) {
        return null;
    }
    final PsiFile containingFile = aClass.getContainingFile();
    if (containingFile == null) {
        return null;
    }
    return containingFile.getVirtualFile();
}

40. ResourceBundleTest#doTestRenameResourceBundleEntryFile()

View license
private void doTestRenameResourceBundleEntryFile(String fileNameToRenameBefore, String fileNameToCheckBefore, String fileNameToRenameAfter, String fileNameToCheckAfter) {
    final PsiFile toRenameFile = myFixture.addFileToProject(fileNameToRenameBefore, "");
    final PsiFile toCheck = myFixture.addFileToProject(fileNameToCheckBefore, "");
    final RenameProcessor processor = new RenameProcessor(getProject(), toRenameFile, fileNameToRenameAfter, true, true);
    for (AutomaticRenamerFactory factory : Extensions.getExtensions(AutomaticRenamerFactory.EP_NAME)) {
        if (factory instanceof ResourceBundleRenamerFactory) {
            processor.addRenamerFactory(factory);
        }
    }
    processor.run();
    assertEquals(fileNameToCheckAfter, toCheck.getName());
}

41. ResourceBundleEditorInsertManagerTest#doTest()

View license
private void doTest(final TestAction testAction) {
    final PsiFile baseFile = myFixture.configureByFile(getTestName(true) + "/p.properties");
    final PsiFile translationFile = myFixture.configureByFile(getTestName(true) + "/p_en.properties");
    final PropertiesFile basePropertiesFile = PropertiesImplUtil.getPropertiesFile(baseFile);
    assertNotNull(basePropertiesFile);
    final ResourceBundle bundle = basePropertiesFile.getResourceBundle();
    final ResourceBundlePropertiesUpdateManager manager = new ResourceBundlePropertiesUpdateManager(bundle);
    assertInstanceOf(manager, ResourceBundlePropertiesUpdateManager.class);
    WriteCommandAction.runWriteCommandAction(getProject(), () -> testAction.doTestAction(basePropertiesFile, PropertiesImplUtil.getPropertiesFile(translationFile), manager));
    myFixture.checkResultByFile(getTestName(true) + "/p.properties", getTestName(true) + "/p-after.properties", true);
    myFixture.checkResultByFile(getTestName(true) + "/p_en.properties", getTestName(true) + "/p-after_en.properties", true);
}

42. CustomResourceBundleTest#testLanguageCodeNotRecognized()

View license
public void testLanguageCodeNotRecognized() {
    final PsiFile file = myFixture.addFileToProject("p.properties", "");
    final PsiFile file2 = myFixture.addFileToProject("p_asd.properties", "");
    final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file);
    final PropertiesFile propertiesFile2 = PropertiesImplUtil.getPropertiesFile(file2);
    assertNotNull(propertiesFile);
    assertNotNull(propertiesFile2);
    final ResourceBundle bundle = propertiesFile.getResourceBundle();
    final ResourceBundle bundle2 = propertiesFile2.getResourceBundle();
    assertSize(1, bundle.getPropertiesFiles());
    assertSize(1, bundle2.getPropertiesFiles());
    assertEquals("p", bundle.getBaseName());
    assertEquals("p_asd", bundle2.getBaseName());
    final ResourceBundleManager manager = ResourceBundleManager.getInstance(getProject());
    final ArrayList<PropertiesFile> rawBundle = ContainerUtil.newArrayList(propertiesFile, propertiesFile2);
    final String suggestedBaseName = PropertiesUtil.getDefaultBaseName(rawBundle);
    assertEquals("p", suggestedBaseName);
    manager.combineToResourceBundle(rawBundle, suggestedBaseName);
    assertEquals("asd", propertiesFile2.getLocale().getLanguage());
}

43. CustomResourceBundleTest#testPropertiesFileNotAssociatedWhileLanguageCodeNotRecognized()

View license
public void testPropertiesFileNotAssociatedWhileLanguageCodeNotRecognized() {
    final PsiFile file = myFixture.addFileToProject("some_property_file.properties", "");
    final PsiFile file2 = myFixture.addFileToProject("some_property_fil.properties", "");
    final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file);
    assertNotNull(propertiesFile);
    final ResourceBundle resourceBundle = propertiesFile.getResourceBundle();
    assertSize(1, resourceBundle.getPropertiesFiles());
    final PropertiesFile propertiesFile2 = PropertiesImplUtil.getPropertiesFile(file2);
    assertNotNull(propertiesFile2);
    final ResourceBundle resourceBundle2 = propertiesFile.getResourceBundle();
    assertSize(1, resourceBundle2.getPropertiesFiles());
    assertEquals(PropertiesUtil.DEFAULT_LOCALE, propertiesFile.getLocale());
}

44. CustomResourceBundleTest#testPropertiesFilesDefaultCombiningToResourceBundle()

View license
public void testPropertiesFilesDefaultCombiningToResourceBundle() {
    final PsiFile file = myFixture.addFileToProject("prop_core_en.properties", "");
    final PsiFile file2 = myFixture.addFileToProject("prop_core_fi.properties", "");
    final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file);
    final PropertiesFile propertiesFile2 = PropertiesImplUtil.getPropertiesFile(file2);
    assertNotNull(propertiesFile);
    assertNotNull(propertiesFile2);
    final ResourceBundle bundle = propertiesFile.getResourceBundle();
    final ResourceBundle bundle2 = propertiesFile2.getResourceBundle();
    assertTrue(bundle.equals(bundle2));
    assertSize(2, bundle.getPropertiesFiles());
    assertTrue(bundle.getDefaultPropertiesFile().equals(bundle2.getDefaultPropertiesFile()));
    assertEquals("prop_core", bundle.getBaseName());
    assertNotSame(propertiesFile.getLocale().getLanguage(), propertiesFile.getLocale().getDisplayLanguage());
    assertNotSame(propertiesFile2.getLocale().getLanguage(), propertiesFile2.getLocale().getDisplayLanguage());
}

45. YamlPsiElementFactory#createYamlPsiFromText()

View license
@NotNull
public static PsiElement createYamlPsiFromText(Project p, final IElementType type, @NotNull String text) {
    final Ref<PsiElement> ret = new Ref<PsiElement>();
    PsiFile dummyFile = createDummyFile(p, text);
    dummyFile.accept(new PsiRecursiveElementWalkingVisitor() {

        @Override
        public void visitElement(PsiElement element) {
            if (element.getNode() == type) {
                ret.set(element);
            }
            super.visitElement(element);
        }
    });
    assert !ret.isNull() : "cannot create element from text:\n" + dummyFile.getText();
    return ret.get();
}

46. PhpRouteInspection#buildVisitor()

View license
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    PsiFile psiFile = holder.getFile();
    if (!Symfony2ProjectComponent.isEnabled(psiFile.getProject()) || !Settings.getInstance(psiFile.getProject()).phpAnnotateRoute) {
        return super.buildVisitor(holder, isOnTheFly);
    }
    psiFile.acceptChildren(new PsiRecursiveElementWalkingVisitor() {

        @Override
        public void visitElement(PsiElement element) {
            if (element instanceof StringLiteralExpression) {
                annotate((StringLiteralExpression) element, holder);
            }
            super.visitElement(element);
        }
    });
    return super.buildVisitor(holder, isOnTheFly);
}

47. IgnoreTemplatesFactory#createFromTemplate()

View license
/**
     * Creates new Gitignore file or uses an existing one.
     *
     * @param directory working directory
     * @return file
     * @throws IncorrectOperationException
     */
@Nullable
public PsiFile createFromTemplate(final PsiDirectory directory) throws IncorrectOperationException {
    final String filename = fileType.getIgnoreLanguage().getFilename();
    final PsiFile currentFile = directory.findFile(filename);
    if (currentFile != null) {
        return currentFile;
    }
    final PsiFileFactory factory = PsiFileFactory.getInstance(directory.getProject());
    final IgnoreLanguage language = fileType.getIgnoreLanguage();
    String content = StringUtil.join(TEMPLATE_NOTE, Constants.NEWLINE);
    if (language.isSyntaxSupported() && !IgnoreBundle.Syntax.GLOB.equals(language.getDefaultSyntax())) {
        content = StringUtil.join(content, IgnoreBundle.Syntax.GLOB.getPresentation(), Constants.NEWLINE, Constants.NEWLINE);
    }
    final PsiFile file = factory.createFileFromText(filename, fileType, content);
    return (PsiFile) directory.add(file);
}

48. BackgroundTaskPsiFileTreeNode#getChildrenImpl()

View license
@Override
public Collection<AbstractTreeNode> getChildrenImpl() {
    VirtualFile ourVirtualFile = getVirtualFile();
    if (ourVirtualFile == null) {
        return super.getChildrenImpl();
    }
    BackgroundTaskByVfsChangeManager vfsChangeManager = BackgroundTaskByVfsChangeManager.getInstance(getProject());
    List<BackgroundTaskByVfsChangeTask> tasks = vfsChangeManager.findTasks(ourVirtualFile);
    if (tasks.isEmpty()) {
        return super.getChildrenImpl();
    }
    List<VirtualFile> generatedFiles = new ArrayList<VirtualFile>();
    for (BackgroundTaskByVfsChangeTask task : tasks) {
        Collections.addAll(generatedFiles, task.getGeneratedFiles());
    }
    if (generatedFiles.isEmpty()) {
        return super.getChildrenImpl();
    }
    PsiFile[] psiFiles = PsiUtilBase.virtualToPsiFiles(generatedFiles, myProject);
    List<AbstractTreeNode> newChildren = new ArrayList<AbstractTreeNode>(psiFiles.length);
    for (PsiFile psiFile : psiFiles) {
        newChildren.add(new PsiFileNode(getProject(), psiFile, getSettings()));
    }
    return newChildren;
}

49. AbstractFileProcessor#findFiles()

Project: consulo
Source File: AbstractFileProcessor.java
View license
private static void findFiles(List<PsiFile> files, PsiDirectory directory, boolean subdirs) {
    final Project project = directory.getProject();
    PsiFile[] locals = directory.getFiles();
    for (PsiFile local : locals) {
        CopyrightProfile opts = CopyrightManager.getInstance(project).getCopyrightOptions(local);
        if (opts != null && CopyrightUpdaters.hasExtension(local)) {
            files.add(local);
        }
    }
    if (subdirs) {
        PsiDirectory[] dirs = directory.getSubdirectories();
        for (PsiDirectory dir : dirs) {
            findFiles(files, dir, subdirs);
        }
    }
}

50. TextFieldCompletionProvider#createDocument()

View license
private Document createDocument(final Project project, @NotNull String text) {
    final FileType fileType = PlainTextLanguage.INSTANCE.getAssociatedFileType();
    assert fileType != null;
    final long stamp = LocalTimeCounter.currentTime();
    final PsiFile psiFile = PsiFileFactory.getInstance(project).createFileFromText("Dummy." + fileType.getDefaultExtension(), fileType, text, stamp, true, false);
    psiFile.putUserData(COMPLETING_TEXT_FIELD_KEY, this);
    final Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
    assert document != null;
    return document;
}

51. BackwardDependenciesBuilder#subtractScope()

View license
private static void subtractScope(final DependenciesBuilder builders, final AnalysisScope scope) {
    final Map<PsiFile, Set<PsiFile>> dependencies = builders.getDependencies();
    Set<PsiFile> excluded = new HashSet<PsiFile>();
    for (final PsiFile psiFile : dependencies.keySet()) {
        if (scope.contains(psiFile)) {
            excluded.add(psiFile);
        }
    }
    for (final PsiFile psiFile : excluded) {
        dependencies.remove(psiFile);
    }
}

52. GroovyUnresolvedReferenceFilterByFile#isReject()

View license
@Override
public boolean isReject(@NotNull GrReferenceExpression expression) {
    PsiFile file = expression.getContainingFile();
    Boolean cachedValue = file.getUserData(KEY);
    if (cachedValue != null)
        return cachedValue;
    boolean res = false;
    for (GroovyUnresolvedHighlightFileFilter filter : GroovyUnresolvedHighlightFileFilter.EP_NAME.getExtensions()) {
        if (filter.isReject(file)) {
            res = true;
            break;
        }
    }
    file.putUserData(KEY, res);
    return res;
}

53. AbstractFileProcessor#findFiles()

View license
private static void findFiles(List<PsiFile> files, PsiDirectory directory, boolean subdirs) {
    final Project project = directory.getProject();
    PsiFile[] locals = directory.getFiles();
    for (PsiFile local : locals) {
        CopyrightProfile opts = CopyrightManager.getInstance(project).getCopyrightOptions(local);
        if (opts != null && FileTypeUtil.isSupportedFile(local)) {
            files.add(local);
        }
    }
    if (subdirs) {
        PsiDirectory[] dirs = directory.getSubdirectories();
        for (PsiDirectory dir : dirs) {
            findFiles(files, dir, subdirs);
        }
    }
}

54. AntResolveTest#testAntFilePropertyWithContexts()

View license
public void testAntFilePropertyWithContexts() throws Exception {
    final PsiReference refImporting = configureByFile("PropertyAntFileImporting.ant");
    final PsiFile importing = refImporting.getElement().getContainingFile();
    assertTrue(importing instanceof XmlFile);
    final VirtualFile vFile = importing.getVirtualFile();
    assertTrue(vFile != null);
    final PsiReference refImported = configureByFile("PropertyAntFileImported.ant", vFile.getParent());
    final PsiFile imported = refImported.getElement().getContainingFile();
    assertTrue(imported instanceof XmlFile);
    final VirtualFile importedVFile = imported.getVirtualFile();
    assertTrue(importedVFile != null);
    AntConfigurationBase.getInstance(getProject()).setContextFile((XmlFile) imported, (XmlFile) importing);
    assertTrue(refImported.resolve() != null);
    assertTrue(refImporting.resolve() != null);
}

55. PyToxTestLocator#getLocation()

View license
@NotNull
@Override
public List<Location> getLocation(@NotNull final String protocol, @NotNull final String path, @NotNull final Project project, @NotNull final GlobalSearchScope scope) {
    final PsiFile file = PyElementGenerator.getInstance(project).createDummyFile(LanguageLevel.PYTHON24, DUMMY_FILE_PADDING);
    file.putUserData(ENV_NAME_KEY, path);
    @SuppressWarnings("unchecked") final List<Location> locations = Collections.<Location>singletonList(new PsiLocation(file));
    return locations;
}

56. FileTypesTest#testAutoDetectEmptyFile()

View license
public void testAutoDetectEmptyFile() throws IOException {
    File dir = createTempDirectory();
    File file = FileUtil.createTempFile(dir, "x", "xxx_xx_xx", true);
    VirtualFile virtualFile = getVirtualFile(file);
    assertNotNull(virtualFile);
    assertEquals(FileTypes.UNKNOWN, virtualFile.getFileType());
    PsiFile psi = getPsiManager().findFile(virtualFile);
    assertTrue(psi instanceof PsiBinaryFile);
    assertEquals(FileTypes.UNKNOWN, virtualFile.getFileType());
    setBinaryContent(virtualFile, "xxxxxxx".getBytes(CharsetToolkit.UTF8_CHARSET));
    assertEquals(FileTypes.PLAIN_TEXT, virtualFile.getFileType());
    PsiFile after = getPsiManager().findFile(virtualFile);
    assertNotSame(psi, after);
    assertFalse(psi.isValid());
    assertTrue(after.isValid());
    assertTrue(after instanceof PsiPlainTextFile);
}

57. EditorHelper#openInEditor()

View license
@Nullable
public static FileEditor openInEditor(@NotNull PsiElement element, boolean switchToText) {
    PsiFile file;
    int offset;
    if (element instanceof PsiFile) {
        file = (PsiFile) element;
        offset = -1;
    } else {
        file = element.getContainingFile();
        offset = element.getTextOffset();
    }
    //SCR44414
    if (file == null)
        return null;
    VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile == null)
        return null;
    OpenFileDescriptor descriptor = new OpenFileDescriptor(element.getProject(), virtualFile, offset);
    Project project = element.getProject();
    if (offset == -1 && !switchToText) {
        FileEditorManager.getInstance(project).openEditor(descriptor, false);
    } else {
        FileEditorManager.getInstance(project).openTextEditor(descriptor, false);
    }
    return FileEditorManager.getInstance(project).getSelectedEditor(virtualFile);
}

58. CurrentFileTodosTreeBuilder#rebuildCache()

View license
@Override
void rebuildCache() {
    myFileTree.clear();
    myDirtyFileSet.clear();
    myFile2Highlighter.clear();
    CurrentFileTodosTreeStructure treeStructure = (CurrentFileTodosTreeStructure) getTreeStructure();
    PsiFile psiFile = treeStructure.getFile();
    if (treeStructure.accept(psiFile)) {
        myFileTree.add(psiFile.getVirtualFile());
    }
    treeStructure.validateCache();
}

59. PsiFileNode#updateImpl()

Project: intellij-community
Source File: PsiFileNode.java
View license
@Override
protected void updateImpl(PresentationData data) {
    PsiFile value = getValue();
    data.setPresentableText(value.getName());
    data.setIcon(value.getIcon(Iconable.ICON_FLAG_READ_STATUS));
    VirtualFile file = getVirtualFile();
    if (file != null && file.is(VFileProperty.SYMLINK)) {
        String target = file.getCanonicalPath();
        if (target == null) {
            data.setAttributesKey(CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);
            data.setTooltip(CommonBundle.message("vfs.broken.link"));
        } else {
            data.setTooltip(FileUtil.toSystemDependentName(target));
        }
    }
}

60. AbstractPsiBasedNode#contains()

View license
@Override
public boolean contains(@NotNull final VirtualFile file) {
    final PsiElement psiElement = extractPsiFromValue();
    if (psiElement == null || !psiElement.isValid()) {
        return false;
    }
    final PsiFile containingFile = psiElement.getContainingFile();
    if (containingFile == null) {
        return false;
    }
    final VirtualFile valueFile = containingFile.getVirtualFile();
    return valueFile != null && file.equals(valueFile);
}

61. DefaultCreateFromTemplateHandler#createFromTemplate()

View license
@NotNull
@Override
public PsiElement createFromTemplate(final Project project, final PsiDirectory directory, String fileName, final FileTemplate template, final String templateText, @NotNull final Map<String, Object> props) throws IncorrectOperationException {
    fileName = checkAppendExtension(fileName, template);
    if (FileTypeManager.getInstance().isFileIgnored(fileName)) {
        throw new IncorrectOperationException("This filename is ignored (Settings | Editor | File Types | Ignore files and folders)");
    }
    directory.checkCreateFile(fileName);
    FileType type = FileTypeRegistry.getInstance().getFileTypeByFileName(fileName);
    PsiFile file = PsiFileFactory.getInstance(project).createFileFromText(fileName, type, templateText);
    if (template.isReformatCode()) {
        CodeStyleManager.getInstance(project).reformat(file);
    }
    file = (PsiFile) directory.add(file);
    return file;
}

62. AddAllOpenFilesToFavorites#actionPerformed()

View license
@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null) {
        return;
    }
    final FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
    final ArrayList<PsiFile> filesToAdd = getFilesToAdd(project);
    for (PsiFile file : filesToAdd) {
        favoritesManager.addRoots(myFavoritesName, null, file);
    }
}

63. TogglePopupHintsAction#getTargetFile()

View license
private static PsiFile getTargetFile(DataContext dataContext) {
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        return null;
    }
    VirtualFile[] files = FileEditorManager.getInstance(project).getSelectedFiles();
    if (files.length == 0) {
        return null;
    }
    PsiFile psiFile = PsiManager.getInstance(project).findFile(files[0]);
    LOG.assertTrue(psiFile != null);
    return psiFile;
}

64. SelectInContextImpl#createPsiContext()

View license
@Nullable
private static SelectInContext createPsiContext(AnActionEvent event) {
    final DataContext dataContext = event.getDataContext();
    PsiElement psiElement = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
    if (psiElement == null || !psiElement.isValid()) {
        return null;
    }
    PsiFile psiFile = psiElement.getContainingFile();
    if (psiFile == null) {
        return null;
    }
    return new SimpleSelectInContext(psiFile, psiElement);
}

65. GotoImplementationHandlerTest#testMultipleImplsFromStaticCall()

View license
public void testMultipleImplsFromStaticCall() {
    PsiFile file = myFixture.addFileToProject("Foo.java", "public abstract class Hello {\n" + "    static void bar (){}\n" + "    class Hello1 extends Hello {\n" + "    }\n" + "    class Hello2 extends Hello {\n" + "    }\n" + "class D {\n" + "    {\n" + "        He<caret>llo.bar();\n" + "    }\n" + "}");
    myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
    final PsiElement[] impls = getTargets(file);
    assertEquals(2, impls.length);
}

66. GotoImplementationHandlerTest#testShowSelfNonAbstract()

View license
public void testShowSelfNonAbstract() {
    //fails if groovy plugin is enabled: org.jetbrains.plugins.groovy.codeInsight.JavaClsMethodElementEvaluator
    PsiFile file = myFixture.addFileToProject("Foo.java", "public class Hello {\n" + "    void foo(){}\n" + "\n" + "    class A {\n" + "        {\n" + "            fo<caret>o();\n" + "        }\n" + "    }\n" + "    class Hello1 extends Hello {\n" + "        void foo() {}\n" + "    }\n" + "    class Hello2 extends Hello {\n" + "        void foo() {}\n" + "    }\n" + "}");
    myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
    final PsiElement[] impls = getTargets(file);
    assertEquals(3, impls.length);
}

67. GotoImplementationHandlerTest#testToStringOnUnqualified()

View license
public void testToStringOnUnqualified() {
    final PsiFile file = myFixture.addFileToProject("Foo.java", "public class Fix {\n" + "    {\n" + "        <caret>toString();\n" + "    }\n" + "}\n" + "class FixImpl1 extends Fix {\n" + "    @Override\n" + "    public String toString() {\n" + "        return \"Impl1\";\n" + "    }\n" + "}\n" + "class FixImpl2 extends Fix {\n" + "    @Override\n" + "    public String toString() {\n" + "        return \"Impl2\";\n" + "    }\n" + "}");
    myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
    PlatformTestUtil.startPerformanceTest(getTestName(false), 150, () -> {
        PsiElement[] impls = getTargets(file);
        assertEquals(3, impls.length);
    }).cpuBound().usesAllCPUCores().assertTiming();
}

68. GotoImplementationHandlerTest#testMultipleImplsFromAbstractCall()

View license
public void testMultipleImplsFromAbstractCall() {
    PsiFile file = myFixture.addFileToProject("Foo.java", "public abstract class Hello {\n" + "    abstract void foo();\n" + "\n" + "    class A {\n" + "        {\n" + "            fo<caret>o();\n" + "        }\n" + "    }\n" + "    class Hello1 extends Hello {\n" + "        void foo() {}\n" + "    }\n" + "    class Hello2 extends Hello {\n" + "        void foo() {}\n" + "    }\n" + "}");
    myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
    final PsiElement[] impls = getTargets(file);
    assertEquals(2, impls.length);
}

69. GlobalInspectionContextTest#testRunInspectionContext()

View license
public void testRunInspectionContext() throws Exception {
    InspectionProfile profile = new InspectionProfileImpl("foo");
    InspectionToolWrapper[] tools = profile.getInspectionTools(null);
    PsiFile file = createDummyFile("xx.txt", "xxx");
    for (InspectionToolWrapper toolWrapper : tools) {
        if (!toolWrapper.isEnabledByDefault()) {
            InspectionManagerEx instance = (InspectionManagerEx) InspectionManager.getInstance(myProject);
            GlobalInspectionContextImpl context = RunInspectionIntention.createContext(toolWrapper, instance, file);
            context.initializeTools(new ArrayList<Tools>(), new ArrayList<Tools>(), new ArrayList<Tools>());
            assertEquals(1, context.getTools().size());
            return;
        }
    }
    fail("No disabled tools found: " + Arrays.asList(tools));
}

70. JavaCheckRegexpWithFlagsTest#defaultTest()

View license
private void defaultTest(@NotNull String regExp, int flags, @NotNull String[] matching, @NotNull String[] nonMatching) throws Exception {
    LanguageParserDefinitions.INSTANCE.addExplicitExtension(RegExpLanguage.INSTANCE, new RegExpParserDefinition());
    // the 1.8 mock jdk has the needed Pattern class
    PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk18());
    configureByText(JavaFileType.INSTANCE, getJavaText(regExp, flags));
    final PsiFile regexpFile = setUpRegexpInjectionAndGetRegexpFile();
    for (String text : matching) {
        assertTrue("Text '" + text + "' should match", CheckRegExpForm.isMatchingTextTest(regexpFile, text));
    }
    for (String text : nonMatching) {
        assertFalse("Text '" + text + "' should not match", CheckRegExpForm.isMatchingTextTest(regexpFile, text));
    }
}

71. UnusedImportsTest#testWithHighlightingOff()

View license
public void testWithHighlightingOff() throws Exception {
    configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
    final PsiFile file = getFile();
    final HighlightingSettingsPerFile settingsPerFile = HighlightingSettingsPerFile.getInstance(myProject);
    final FileHighlightingSetting oldSetting = settingsPerFile.getHighlightingSettingForRoot(file);
    try {
        settingsPerFile.setHighlightingSettingForRoot(file, FileHighlightingSetting.NONE);
        doDoTest(true, false, false);
    } finally {
        settingsPerFile.setHighlightingSettingForRoot(file, oldSetting);
    }
}

72. SdkSetupNotificationTestBase#configureBySdkAndText()

View license
protected EditorNotificationPanel configureBySdkAndText(@Nullable Sdk sdk, boolean moduleSdk, @NotNull String name, @NotNull String text) {
    final PsiFile psiFile = myFixture.configureByText(name, text);
    final FileEditor[] editors = FileEditorManagerEx.getInstanceEx(getProject()).openFile(psiFile.getVirtualFile(), true);
    assertSize(1, editors);
    if (moduleSdk) {
        ModuleRootModificationUtil.setModuleSdk(myModule, sdk);
    } else {
        setProjectSdk(sdk);
        ModuleRootModificationUtil.setSdkInherited(myModule);
    }
    return editors[0].getUserData(SdkSetupNotificationProvider.KEY);
}

73. ClsGenerics18HighlightingTest#testCaptureContext()

View license
public void testCaptureContext() {
    String name = getTestName(false);
    addLibrary(name + ".jar", name + "-sources.jar");
    Project project = myFixture.getProject();
    PsiClass aClass = JavaPsiFacade.getInstance(project).findClass("a.Pair", GlobalSearchScope.allScope(project));
    assertNotNull(aClass);
    PsiFile containingFile = aClass.getContainingFile();
    PsiElement navigationElement = containingFile.getNavigationElement();
    assertInstanceOf(navigationElement, PsiFileImpl.class);
    myFixture.openFileInEditor(((PsiFile) navigationElement).getVirtualFile());
    myFixture.checkHighlighting();
}

74. CompositeShortNamesCache#getFilesByName()

View license
@Override
@NotNull
public PsiFile[] getFilesByName(@NotNull String name) {
    Merger<PsiFile> merger = null;
    for (PsiShortNamesCache cache : myCaches) {
        PsiFile[] classes = cache.getFilesByName(name);
        if (classes.length != 0) {
            if (merger == null)
                merger = new Merger<PsiFile>();
            merger.add(classes);
        }
    }
    PsiFile[] result = merger == null ? null : merger.getResult();
    return result != null ? result : PsiFile.EMPTY_ARRAY;
}

75. SliceLeafValueRootNode#appendElementText()

View license
private static void appendElementText(@NotNull UsageInfo2UsageAdapter usage, @NotNull final PsiElement element, @NotNull final SliceUsageCellRendererBase renderer) {
    PsiFile file = element.getContainingFile();
    List<TextChunk> result = new ArrayList<>();
    ChunkExtractor.getExtractor(element.getContainingFile()).createTextChunks(usage, file.getText(), element.getTextRange().getStartOffset(), element.getTextRange().getEndOffset(), false, result);
    for (TextChunk chunk : result) {
        renderer.append(chunk.getText(), chunk.getSimpleAttributesIgnoreBackground());
    }
}

76. RenameFileAction#update()

View license
public void update(AnActionEvent e) {
    PsiFile file = e.getData(CommonDataKeys.PSI_FILE);
    Presentation presentation = e.getPresentation();
    String place = e.getPlace();
    boolean enabled = file != null && (file instanceof PsiClassOwner || ActionPlaces.EDITOR_TAB_POPUP.equals(place)) && place != ActionPlaces.EDITOR_POPUP && e.getData(CommonDataKeys.PROJECT) != null;
    presentation.setEnabled(enabled);
    presentation.setVisible(enabled);
    if (enabled) {
        presentation.setText(RENAME_FILE);
        presentation.setDescription("Rename selected file");
    }
}

77. TabPostFormatProcessor#doProcess()

View license
@NotNull
private static TextRange doProcess(@NotNull PsiElement source, @NotNull TextRange range, @NotNull CodeStyleSettings settings) {
    ASTNode node = source.getNode();
    if (node == null) {
        return range;
    }
    Language language = source.getLanguage();
    if (language != JavaLanguage.INSTANCE) {
        // this logic to other languages as well.
        return range;
    }
    if (!source.isValid())
        return range;
    PsiFile file = source.getContainingFile();
    CommonCodeStyleSettings.IndentOptions indentOptions = settings.getIndentOptionsByFile(file, range);
    boolean useTabs = indentOptions.USE_TAB_CHARACTER;
    boolean smartTabs = indentOptions.SMART_TABS;
    int tabWidth = indentOptions.TAB_SIZE;
    return processViaPsi(node, range, new TreeHelperImpl(), useTabs, smartTabs, tabWidth);
}

78. JavadocNavigationDelegate#navigateToLineEnd()

View license
/**
   * Improves navigation in case of incomplete javadoc parameter descriptions.
   * <p/>
   * Example:
   * <pre>
   *   /**
   *    * @param i[caret]
   *    * @param secondArgument
   *    */
   *    abstract void test(int i, int secondArgument);
   * </pre>
   * <p/>
   * We expect the caret to be placed in position of parameter description start then (code style is condifured to
   * <b>align</b> parameter descriptions):
   * <pre>
   *   /**
   *    * @param i                 [caret]
   *    * @param secondArgument
   *    */
   *    abstract void test(int i, int secondArgument);
   * </pre>
   * <p/>
   * or this one for non-aligned descriptions:
   * <pre>
   *   /**
   *    * @param i    [caret]
   *    * @param secondArgument
   *    */
   *    abstract void test(int i, int secondArgument);
   * </pre>
   * 
   * @param editor      current editor
   * @return            processing result
   */
@NotNull
@Override
public Result navigateToLineEnd(@NotNull Editor editor, @NotNull DataContext dataContext) {
    if (!CodeInsightSettings.getInstance().SMART_END_ACTION) {
        return Result.CONTINUE;
    }
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        return Result.CONTINUE;
    }
    final Document document = editor.getDocument();
    PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(dataContext);
    if (psiFile == null) {
        psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
    }
    if (psiFile == null) {
        return Result.CONTINUE;
    }
    return navigateToLineEnd(editor, psiFile);
}

79. PackageLookupItem#handleInsert()

View license
@Override
public void handleInsert(InsertionContext context) {
    PsiFile file = context.getFile();
    boolean addDot = !(file instanceof PsiJavaCodeReferenceCodeFragment) || ((PsiJavaCodeReferenceCodeFragment) file).isClassesAccepted();
    if (addDot) {
        context.setAddCompletionChar(false);
        TailType.DOT.processTail(context.getEditor(), context.getTailOffset());
    }
    if (addDot || context.getCompletionChar() == '.') {
        AutoPopupController.getInstance(context.getProject()).scheduleAutoPopup(context.getEditor());
    }
}

80. GenerifyFileFix#applyFix()

View license
@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
    final PsiElement element = descriptor.getPsiElement();
    if (element == null)
        return;
    final PsiFile file = element.getContainingFile();
    if (isAvailable(project, null, file)) {
        myFileName = file.getName();
        new WriteCommandAction(project) {

            @Override
            protected void run(@NotNull Result result) throws Throwable {
                invoke(project, FileEditorManager.getInstance(project).getSelectedTextEditor(), file);
            }
        }.execute();
    }
}

81. ConfigFileImpl#isValid()

View license
@Override
public boolean isValid() {
    final PsiFile psiFile = getPsiFile();
    if (psiFile == null || !psiFile.isValid()) {
        return false;
    }
    if (psiFile instanceof XmlFile) {
        final XmlDocument document = ((XmlFile) psiFile).getDocument();
        return document != null && document.getRootTag() != null;
    }
    return true;
}

82. ConfigFileImpl#getPsiFile()

View license
@Override
@Nullable
public PsiFile getPsiFile() {
    PsiFile psiFile = com.intellij.reference.SoftReference.dereference(myPsiFile);
    if (psiFile != null && psiFile.isValid()) {
        return psiFile;
    }
    VirtualFile virtualFile = getVirtualFile();
    if (virtualFile == null || !virtualFile.isValid())
        return null;
    psiFile = PsiManager.getInstance(myProject).findFile(virtualFile);
    myPsiFile = new SoftReference<PsiFile>(psiFile);
    return psiFile;
}

83. JavaParametersUtil#isClassInProductionSources()

View license
@Nullable("null if class not found")
public static Boolean isClassInProductionSources(@NotNull String mainClassName, @NotNull Module module) {
    final PsiClass psiClass = JavaExecutionUtil.findMainClass(module, mainClassName);
    if (psiClass == null) {
        return null;
    }
    final PsiFile psiFile = psiClass.getContainingFile();
    if (psiFile == null)
        return null;
    final VirtualFile virtualFile = psiFile.getVirtualFile();
    if (virtualFile == null)
        return null;
    Module classModule = psiClass.isValid() ? ModuleUtilCore.findModuleForPsiElement(psiClass) : null;
    if (classModule == null)
        classModule = module;
    ModuleFileIndex fileIndex = ModuleRootManager.getInstance(classModule).getFileIndex();
    if (fileIndex.isInSourceContent(virtualFile)) {
        return !fileIndex.isInTestSourceContent(virtualFile);
    }
    final List<OrderEntry> entriesForFile = fileIndex.getOrderEntriesForFile(virtualFile);
    for (OrderEntry entry : entriesForFile) {
        if (entry instanceof ExportableOrderEntry && ((ExportableOrderEntry) entry).getScope() == DependencyScope.TEST) {
            return false;
        }
    }
    return true;
}

84. IncludeVariableCollector#collectVars()

View license
@Override
public void collectVars(final TwigFileVariableCollectorParameter parameter, final Map<String, PsiVariable> variables) {
    final PsiFile psiFile = parameter.getElement().getContainingFile();
    if (!(psiFile instanceof TwigFile) || PsiTreeUtil.getChildOfType(psiFile, TwigExtendsTag.class) != null) {
        return;
    }
    Collection<VirtualFile> files = getImplements((TwigFile) psiFile);
    if (files.size() == 0) {
        return;
    }
    for (VirtualFile virtualFile : files) {
        PsiFile twigFile = PsiManager.getInstance(parameter.getProject()).findFile(virtualFile);
        if (!(twigFile instanceof TwigFile)) {
            continue;
        }
        twigFile.acceptChildren(new MyPsiRecursiveElementWalkingVisitor(psiFile, variables, parameter));
    }
}

85. Utils#getIgnoreFile()

Project: idea-gitignore
Source File: Utils.java
View license
/**
     * Gets Ignore file for given {@link Project} and root {@link PsiDirectory}.
     * If file is missing - creates new one.
     *
     * @param project         current project
     * @param fileType        current ignore file type
     * @param directory       root directory
     * @param createIfMissing create new file if missing
     * @return Ignore file
     */
@Nullable
public static PsiFile getIgnoreFile(@NotNull Project project, @NotNull IgnoreFileType fileType, @Nullable PsiDirectory directory, boolean createIfMissing) {
    if (directory == null) {
        directory = PsiManager.getInstance(project).findDirectory(project.getBaseDir());
    }
    assert directory != null;
    String filename = fileType.getIgnoreLanguage().getFilename();
    PsiFile file = directory.findFile(filename);
    VirtualFile virtualFile = file == null ? directory.getVirtualFile().findChild(filename) : file.getVirtualFile();
    if (file == null && virtualFile == null && createIfMissing) {
        file = new CreateFileCommandAction(project, directory, fileType).execute().getResultObject();
    }
    return file;
}

86. GradleClosureAsAnonymousParameterEnhancer#getClosureParameterType()

View license
@Nullable
@Override
protected PsiType getClosureParameterType(GrClosableBlock closure, int index) {
    PsiFile file = closure.getContainingFile();
    if (file == null || !FileUtilRt.extensionEquals(file.getName(), GradleConstants.EXTENSION))
        return null;
    PsiType psiType = super.getClosureParameterType(closure, index);
    if (psiType instanceof PsiWildcardType) {
        PsiWildcardType wildcardType = (PsiWildcardType) psiType;
        if (wildcardType.isSuper() && wildcardType.getBound() != null && wildcardType.getBound().equalsToText(GradleCommonClassNames.GRADLE_API_SOURCE_SET)) {
            return wildcardType.getBound();
        }
        if (wildcardType.isSuper() && wildcardType.getBound() != null && wildcardType.getBound().equalsToText(GradleCommonClassNames.GRADLE_API_DISTRIBUTION)) {
            return wildcardType.getBound();
        }
    }
    return null;
}

87. Utils#getPsiFile()

Project: idea-gitignore
Source File: Utils.java
View license
/**
     * Finds {@link PsiFile} for the given {@link VirtualFile} instance. If file is outside current project,
     * it's required to create new {@link PsiFile} manually.
     *
     * @param project     current project
     * @param virtualFile to handle
     * @return {@link PsiFile} instance
     */
@Nullable
public static PsiFile getPsiFile(@NotNull Project project, @NotNull VirtualFile virtualFile) {
    PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
    if (psiFile == null) {
        FileViewProvider viewProvider = PsiManager.getInstance(project).findViewProvider(virtualFile);
        if (viewProvider != null) {
            IgnoreLanguage language = IgnoreBundle.obtainLanguage(virtualFile);
            if (language != null) {
                psiFile = language.createFile(viewProvider);
            }
        }
    }
    return psiFile;
}

88. BundleClassGeneratorUtil#getBundleClassInDirectory()

View license
@Nullable
public static PhpClass getBundleClassInDirectory(@NotNull PsiDirectory bundleDirContext) {
    for (PsiFile psiFile : bundleDirContext.getFiles()) {
        if (!(psiFile instanceof PhpFile)) {
            continue;
        }
        PhpClass aClass = PhpPsiUtil.findClass((PhpFile) psiFile, new Condition<PhpClass>() {

            @Override
            public boolean value(PhpClass phpClass) {
                return PhpElementsUtil.isInstanceOf(phpClass, "\\Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface");
            }
        });
        if (aClass != null) {
            return aClass;
        }
    }
    return null;
}

89. YamlDuplicateParameterKeyInspection#buildVisitor()

View license
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    PsiFile psiFile = holder.getFile();
    if (!Symfony2ProjectComponent.isEnabled(psiFile.getProject())) {
        return super.buildVisitor(holder, isOnTheFly);
    }
    return new PsiElementVisitor() {

        @Override
        public void visitFile(PsiFile file) {
            visitRoot(file, "parameters", holder);
        }
    };
}

90. YamlDuplicateServiceKeyInspection#buildVisitor()

View license
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    PsiFile psiFile = holder.getFile();
    if (!Symfony2ProjectComponent.isEnabled(psiFile.getProject())) {
        return super.buildVisitor(holder, isOnTheFly);
    }
    return new PsiElementVisitor() {

        @Override
        public void visitFile(PsiFile file) {
            visitRoot(file, "services", holder);
        }
    };
}

91. YamlGoToKnownDeclarationHandler#attachResourceOnPathGoto()

View license
private void attachResourceOnPathGoto(PsiElement psiElement, List<PsiElement> results) {
    String text = PsiElementUtils.trimQuote(psiElement.getText());
    if (StringUtils.isBlank(text) || text.startsWith("@")) {
        return;
    }
    PsiFile containingFile = psiElement.getContainingFile();
    if (containingFile == null) {
        return;
    }
    results.addAll(FileResourceUtil.getFileResourceTargetsInDirectoryScope(containingFile, text));
}

92. DoctrineYamlMappingDriver#getMetadata()

View license
@Nullable
public DoctrineMetadataModel getMetadata(@NotNull DoctrineMappingDriverArguments args) {
    PsiFile psiFile = args.getPsiFile();
    if (!(psiFile instanceof YAMLFile)) {
        return null;
    }
    Collection<DoctrineModelField> fields = new ArrayList<DoctrineModelField>();
    DoctrineMetadataModel model = new DoctrineMetadataModel(fields);
    for (YAMLKeyValue yamlKeyValue : YamlHelper.getTopLevelKeyValues((YAMLFile) psiFile)) {
        // first line is class name; check of we are right
        if (args.isEqualClass(YamlHelper.getYamlKeyName(yamlKeyValue))) {
            model.setTable(YamlHelper.getYamlKeyValueAsString(yamlKeyValue, "table"));
            fields.addAll(EntityHelper.getModelFieldsSet(yamlKeyValue));
        }
    }
    if (model.isEmpty()) {
        return null;
    }
    return model;
}

93. TranslationDomainGotoCompletionProvider#getPsiTargets()

View license
@NotNull
@Override
public Collection<PsiElement> getPsiTargets(PsiElement element) {
    String stringLiteralValue = GotoCompletionUtil.getStringLiteralValue(element);
    if (stringLiteralValue == null) {
        return Collections.emptyList();
    }
    Collection<PsiElement> targets = new ArrayList<PsiElement>();
    for (PsiFile psiFile : TranslationUtil.getDomainPsiFiles(getElement().getProject(), stringLiteralValue)) {
        targets.add(psiFile);
    }
    return targets;
}

94. TemplateFileContributor#getItemsByName()

View license
@NotNull
@Override
public NavigationItem[] getItemsByName(String templateName, String s2, Project project, boolean b) {
    PsiFile psiFile = TwigHelper.getTemplateFileByName(project, templateName);
    if (psiFile == null) {
        return new NavigationItem[0];
    }
    return new NavigationItemEx[] { new NavigationItemEx(psiFile, templateName, TwigIcons.TwigFileIcon, "Template", false) };
}

95. JsonFileIndexTwigNamespaces#getNamespacesInner()

View license
@NotNull
private Collection<TwigPath> getNamespacesInner(@NotNull TwigNamespaceExtensionParameter parameter) {
    Collection<TwigPath> twigPaths = new ArrayList<TwigPath>();
    for (final PsiFile psiFile : FilenameIndex.getFilesByName(parameter.getProject(), "ide-twig.json", GlobalSearchScope.allScope(parameter.getProject()))) {
        Collection<TwigPath> cachedValue = CachedValuesManager.getCachedValue(psiFile, new MyJsonCachedValueProvider(psiFile));
        if (cachedValue != null) {
            twigPaths.addAll(cachedValue);
        }
    }
    return twigPaths;
}

96. TwigUtil#collectControllerTemplateVariables()

View license
public static Map<String, PsiVariable> collectControllerTemplateVariables(PsiElement psiElement) {
    Map<String, PsiVariable> vars = new HashMap<String, PsiVariable>();
    PsiFile psiFile = psiElement.getContainingFile();
    if (!(psiFile instanceof TwigFile)) {
        return vars;
    }
    Method method = findTwigFileController((TwigFile) psiFile);
    if (method != null) {
        return PhpMethodVariableResolveUtil.collectMethodVariables(method);
    }
    final Set<Method> methods = getTwigFileMethodUsageOnIndex((TwigFile) psiFile);
    Map<String, PsiVariable> stringPsiVariableHashMap = new HashMap<String, PsiVariable>();
    for (Method methodIndex : methods) {
        stringPsiVariableHashMap.putAll(PhpMethodVariableResolveUtil.collectMethodVariables(methodIndex));
    }
    return stringPsiVariableHashMap;
}

97. ControllerDocVariableCollector#collectVars()

View license
@Override
public void collectVars(TwigFileVariableCollectorParameter parameter, Map<String, PsiVariable> variables) {
    PsiFile psiFile = parameter.getElement().getContainingFile();
    if (!(psiFile instanceof TwigFile)) {
        return;
    }
    ArrayList<String> controllerNames = findFileControllerDocBlocks((TwigFile) psiFile);
    if (controllerNames.size() == 0) {
        return;
    }
    ControllerIndex controllerIndex = new ControllerIndex(parameter.getProject());
    for (String controllerName : controllerNames) {
        Method method = controllerIndex.resolveShortcutName(controllerName);
        if (method != null) {
            variables.putAll(PhpMethodVariableResolveUtil.collectMethodVariables(method));
        }
    }
}

98. XmlLineMarkerProviderTest#testThatResourceProvidesLineMarkerLineMarker()

View license
public void testThatResourceProvidesLineMarkerLineMarker() {
    PsiFile psiFile = myFixture.configureByText("foo.xml", "<foo/>");
    assertLineMarker(psiFile, new LineMarker.ToolTipEqualsAssert("Navigate to resource"));
    assertLineMarker(psiFile, new LineMarker.TargetAcceptsPattern("Navigate to resource", XmlPatterns.xmlTag().withName("import").withAttributeValue("resource", "@FooBundle/foo.xml")));
}

99. YamlLineMarkerProviderTest#testThatResourceProvidesLineMarkerLineMarker()

View license
public void testThatResourceProvidesLineMarkerLineMarker() {
    PsiFile psiFile = myFixture.configureByText("foo.yml", "");
    assertLineMarker(psiFile, new LineMarker.ToolTipEqualsAssert("Navigate to resource"));
    assertLineMarker(psiFile, new LineMarker.TargetAcceptsPattern("Navigate to resource", XmlPatterns.xmlTag().withName("import").withAttributeValue("resource", "@FooBundle/foo.yml")));
}

100. CompileActionBase#actionPerformed()

View license
public void actionPerformed(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final Project project = e.getData(CommonDataKeys.PROJECT);
    if (project == null) {
        return;
    }
    Editor editor = e.getData(CommonDataKeys.EDITOR);
    PsiFile file = e.getData(CommonDataKeys.PSI_FILE);
    if (file != null && editor != null && !DumbService.getInstance(project).isDumb()) {
        //let autoimport complete
        DaemonCodeAnalyzer.getInstance(project).autoImportReferenceAtCursor(editor, file);
    }
    doAction(dataContext, project);
}