void () { final VirtualFile file = createChildData(myPrjDir1, "aaa.txt"); WriteCommandAction.writeCommandAction(getProject()).run(() -> { FileTypeManagerImpl fileTypeManager = (FileTypeManagerImpl)FileTypeManager.getInstance(); try { FileManagerImpl fileManager = (FileManagerImpl)myPsiManager.getFileManager(); fileManager.findFile(file); fileTypeManager.removeAssociation(FileTypes.PLAIN_TEXT, new ExtensionFileNameMatcher("txt")); fileTypeManager.associate(JavaFileType.INSTANCE, new ExtensionFileNameMatcher("txt")); fileManager.checkConsistency(); } finally { fileTypeManager.associate(FileTypes.PLAIN_TEXT, new ExtensionFileNameMatcher("txt")); fileTypeManager.removeAssociation(JavaFileType.INSTANCE, new ExtensionFileNameMatcher("txt")); } }); }