void () { @Language("JAVA") String text = "class Foo { void m() {" + " String x = 'qwerty';" + "}}"; PsiFile file = myFixture.addFileToProject("Foo.groovy", text); VirtualFile virtualFile = file.getVirtualFile(); Map<IdIndexEntry, Integer> idIndexData = getIdIndexData(virtualFile); assertTrue(idIndexData.containsKey(new IdIndexEntry("Foo", false))); assertTrue(idIndexData.containsKey(new IdIndexEntry("qwerty", false))); assertEquals(UsageSearchContext.IN_STRINGS | UsageSearchContext.IN_CODE, idIndexData.get(new IdIndexEntry("qwerty", false)).intValue()); assertEquals(GroovyFileType.GROOVY_FILE_TYPE, FileTypeIndex.getIndexedFileType(virtualFile, getProject())); ObjectStubTree<?> stub = StubTreeLoader.getInstance().readFromVFile(getProject(), virtualFile); assertStubLanguage(GroovyLanguage.INSTANCE, stub); assertEquals(GroovyLanguage.INSTANCE, file.getLanguage()); assert findClass("Foo") != null; final ExactFileNameMatcher matcher = new ExactFileNameMatcher("Foo.groovy"); try { WriteCommandAction.runWriteCommandAction(getProject(), () -> FileTypeManager.getInstance().associate(JavaFileType.INSTANCE, matcher)); assertEquals(JavaFileType.INSTANCE, FileTypeIndex.getIndexedFileType(virtualFile, getProject())); stub = StubTreeLoader.getInstance().readFromVFile(getProject(), virtualFile); assertStubLanguage(JavaLanguage.INSTANCE, stub); idIndexData = getIdIndexData(virtualFile); assertTrue(idIndexData.containsKey(new IdIndexEntry("Foo", false))); assertFalse(idIndexData.containsKey(new IdIndexEntry("qwerty", false))); PsiClass javaFooClass = findClass("Foo"); assertEquals(JavaLanguage.INSTANCE, javaFooClass.getLanguage()); } finally { WriteCommandAction.runWriteCommandAction(getProject(), () -> FileTypeManager.getInstance().removeAssociation(JavaFileType.INSTANCE, matcher)); } }