Repository: haxefoundation/intellij-haxe
Issue: ClassCastException: TwigFile cannot be cast to HaxeFile

I think that we need to check the file type before processing inspections.  TwigFiles are PHP templates and this probably occurred in PhpStorm, rather than IDEA.

JetBrains report:
```
java.lang.ClassCastException: com.jetbrains.twig.TwigFile cannot be cast to com.intellij.plugins.haxe.lang.psi.HaxeFile
	at com.intellij.plugins.haxe.util.HaxeImportUtil.findUnusedImports(HaxeImportUtil.java:37)
	at com.intellij.plugins.haxe.ide.inspections.HaxeUnusedImportInspection.checkFile(HaxeUnusedImportInspection.java:71)
	at com.intellij.codeInspection.LocalInspectionTool$1.visitFile(LocalInspectionTool.java:141)
	at com.intellij.extapi.psi.PsiFileBase.accept(PsiFileBase.java:70)
	at com.intellij.codeInspection.InspectionEngine.acceptElements(InspectionEngine.java:75)
	at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.lambda$visitRestElementsAndCleanup$4(LocalInspectionsPass.java:299)
	at com.intellij.concurrency.ApplierCompleter.execAndForkSubTasks(ApplierCompleter.java:133)
	at com.intellij.concurrency.ApplierCompleter.tryToExecAllList(ApplierCompleter.java:223)
	at com.intellij.concurrency.ApplierCompleter.execAndForkSubTasks(ApplierCompleter.java:151)
	at com.intellij.concurrency.ApplierCompleter.tryToExecAllList(ApplierCompleter.java:223)
	at com.intellij.concurrency.ApplierCompleter.execAndForkSubTasks(ApplierCompleter.java:151)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1175)
	at com.intellij.concurrency.ApplierCompleter.lambda$wrapInReadActionAndIndicator$1(ApplierCompleter.java:105)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:583)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:533)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:87)
	at com.intellij.concurrency.ApplierCompleter.wrapInReadActionAndIndicator(ApplierCompleter.java:116)
	at com.intellij.concurrency.ApplierCompleter.lambda$compute$0(ApplierCompleter.java:96)
	at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:147)
	at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:223)
	at com.intellij.concurrency.ApplierCompleter.compute(ApplierCompleter.java:96)
	at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.pollAndExecCC(ForkJoinPool.java:1190)
	at java.util.concurrent.ForkJoinPool.helpComplete(ForkJoinPool.java:1879)
	at java.util.concurrent.ForkJoinPool.awaitJoin(ForkJoinPool.java:2045)
	at java.util.concurrent.ForkJoinTask.doJoin(ForkJoinTask.java:390)
	at java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:719)
	at java.util.concurrent.ForkJoinPool.invoke(ForkJoinPool.java:2616)
	at com.intellij.concurrency.JobLauncherImpl.invokeConcurrentlyUnderProgress(JobLauncherImpl.java:65)
	at com.intellij.concurrency.JobLauncher.invokeConcurrentlyUnderProgress(JobLauncher.java:56)
	at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.visitRestElementsAndCleanup(LocalInspectionsPass.java:310)
	at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.inspect(LocalInspectionsPass.java:221)
	at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.collectInformationWithProgress(LocalInspectionsPass.java:119)
	at com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass.doCollectInformation(ProgressableTextEditorHighlightingPass.java:84)
	at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:69)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$null$1(PassExecutorService.java:423)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1180)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$2(PassExecutorService.java:416)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:583)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:533)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:87)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:415)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$0(PassExecutorService.java:391)
	at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:147)
	at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:223)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:389)
	at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:161)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
```

Changed files:
src/common/com/intellij/plugins/haxe/ide/inspections/HaxeUnresolvedSymbolInspection.java
src/common/com/intellij/plugins/haxe/ide/inspections/HaxePreprocessorInspection.java
src/common/com/intellij/plugins/haxe/ide/inspections/HaxeUnusedImportInspection.java
src/common/com/intellij/plugins/haxe/ide/inspections/HaxeDeprecatedInspection.java

diff --git a/src/common/com/intellij/plugins/haxe/ide/inspections/HaxeDeprecatedInspection.java b/src/common/com/intellij/plugins/haxe/ide/inspections/HaxeDeprecatedInspection.java
index a416c389..41a702de 100644
--- a/src/common/com/intellij/plugins/haxe/ide/inspections/HaxeDeprecatedInspection.java
+++ b/src/common/com/intellij/plugins/haxe/ide/inspections/HaxeDeprecatedInspection.java
@@ -25,6 +25,7 @@ import com.intellij.codeInspection.ProblemHighlightType;
 import com.intellij.openapi.util.TextRange;
 import com.intellij.plugins.haxe.HaxeBundle;
 import com.intellij.plugins.haxe.ide.annotator.HaxeAnnotatingVisitor;
+import com.intellij.plugins.haxe.lang.psi.HaxeFile;
 import com.intellij.plugins.haxe.lang.psi.HaxeMethodDeclaration;
 import com.intellij.plugins.haxe.lang.psi.HaxeReferenceExpression;
 import com.intellij.plugins.haxe.lang.psi.HaxeFieldDeclaration;
@@ -68,6 +69,7 @@ public class HaxeDeprecatedInspection extends LocalInspectionTool {
   @Nullable
   @Override
   public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
+    if (!(file instanceof HaxeFile)) return null;
     final List<ProblemDescriptor> result = new ArrayList<ProblemDescriptor>();
     new HaxeAnnotatingVisitor() {
       @Override
diff --git a/src/common/com/intellij/plugins/haxe/ide/inspections/HaxePreprocessorInspection.java b/src/common/com/intellij/plugins/haxe/ide/inspections/HaxePreprocessorInspection.java
index 7276c49a..8dcd218b 100644
--- a/src/common/com/intellij/plugins/haxe/ide/inspections/HaxePreprocessorInspection.java
+++ b/src/common/com/intellij/plugins/haxe/ide/inspections/HaxePreprocessorInspection.java
@@ -22,6 +22,7 @@ import com.intellij.lang.ASTNode;
 import com.intellij.lang.FileASTNode;
 import com.intellij.plugins.haxe.HaxeBundle;
 import com.intellij.plugins.haxe.lang.lexer.HaxeTokenTypes;
+import com.intellij.plugins.haxe.lang.psi.HaxeFile;
 import com.intellij.psi.PsiFile;
 import com.intellij.psi.impl.source.tree.LeafElement;
 import com.intellij.psi.impl.source.tree.TreeUtil;
@@ -65,7 +66,7 @@ public class HaxePreprocessorInspection extends LocalInspectionTool {
   @Nullable
   @Override
   public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
-
+    if (!(file instanceof HaxeFile)) return null;
     final List<ProblemDescriptor> result = new ArrayList<ProblemDescriptor>();
     final ProblemReporter reporter = new ProblemReporter() {
       @Override
diff --git a/src/common/com/intellij/plugins/haxe/ide/inspections/HaxeUnresolvedSymbolInspection.java b/src/common/com/intellij/plugins/haxe/ide/inspections/HaxeUnresolvedSymbolInspection.java
index be08cee4..204e22a4 100644
--- a/src/common/com/intellij/plugins/haxe/ide/inspections/HaxeUnresolvedSymbolInspection.java
+++ b/src/common/com/intellij/plugins/haxe/ide/inspections/HaxeUnresolvedSymbolInspection.java
@@ -24,6 +24,7 @@ import com.intellij.codeInspection.ProblemHighlightType;
 import com.intellij.openapi.util.TextRange;
 import com.intellij.plugins.haxe.HaxeBundle;
 import com.intellij.plugins.haxe.ide.annotator.HaxeAnnotatingVisitor;
+import com.intellij.plugins.haxe.lang.psi.HaxeFile;
 import com.intellij.plugins.haxe.lang.psi.HaxeReferenceExpression;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiFile;
@@ -65,6 +66,7 @@ public class HaxeUnresolvedSymbolInspection extends LocalInspectionTool {
   @Nullable
   @Override
   public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
+    if (!(file instanceof HaxeFile)) return null;
     final List<ProblemDescriptor> result = new ArrayList<ProblemDescriptor>();
     new HaxeAnnotatingVisitor() {
       @Override
diff --git a/src/common/com/intellij/plugins/haxe/ide/inspections/HaxeUnusedImportInspection.java b/src/common/com/intellij/plugins/haxe/ide/inspections/HaxeUnusedImportInspection.java
index 84644683..78def3d6 100644
--- a/src/common/com/intellij/plugins/haxe/ide/inspections/HaxeUnusedImportInspection.java
+++ b/src/common/com/intellij/plugins/haxe/ide/inspections/HaxeUnusedImportInspection.java
@@ -26,6 +26,7 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.TextRange;
 import com.intellij.plugins.haxe.HaxeBundle;
 import com.intellij.plugins.haxe.ide.HaxeImportOptimizer;
+import com.intellij.plugins.haxe.lang.psi.HaxeFile;
 import com.intellij.plugins.haxe.lang.psi.HaxeImportStatement;
 import com.intellij.plugins.haxe.util.HaxeImportUtil;
 import com.intellij.psi.PsiElement;
@@ -68,8 +69,8 @@ public class HaxeUnusedImportInspection extends LocalInspectionTool {
   @Nullable
   @Override
   public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
+    if (!(file instanceof HaxeFile)) return null;
     List<HaxeImportStatement> unusedImports = HaxeImportUtil.findUnusedImports(file);
-
     if (unusedImports.isEmpty()) {
       return ProblemDescriptor.EMPTY_ARRAY;
     }
@@ -116,4 +117,6 @@ public class HaxeUnusedImportInspection extends LocalInspectionTool {
       });
     }
   };
+
+
 }