summaryrefslogtreecommitdiff
path: root/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsEx.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsEx.java')
-rw-r--r--java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsEx.java23
1 files changed, 16 insertions, 7 deletions
diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsEx.java b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsEx.java
index 026b7111d18f..ae6bb5dd7b27 100644
--- a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsEx.java
+++ b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsEx.java
@@ -37,6 +37,7 @@ import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.*;
@@ -403,17 +404,25 @@ public abstract class DebuggerUtilsEx extends DebuggerUtils {
public abstract CompletionEditor createEditor(Project project, PsiElement context, @NonNls String recentsId);
- @Nullable
- public static CodeFragmentFactory getEffectiveCodeFragmentFactory(final PsiElement psiContext) {
- final CodeFragmentFactory factory = ApplicationManager.getApplication().runReadAction(new Computable<CodeFragmentFactory>() {
+ @NotNull
+ public static CodeFragmentFactory findAppropriateCodeFragmentFactory(final TextWithImports text, final PsiElement context) {
+ CodeFragmentFactory factory = ApplicationManager.getApplication().runReadAction(new Computable<CodeFragmentFactory>() {
@Override
public CodeFragmentFactory compute() {
- final List<CodeFragmentFactory> codeFragmentFactories = getCodeFragmentFactories(psiContext);
- // the list always contains at least DefaultCodeFragmentFactory
- return codeFragmentFactories.get(0);
+ final FileType fileType = text.getFileType();
+ final List<CodeFragmentFactory> factories = getCodeFragmentFactories(context);
+ if (fileType == null) {
+ return factories.get(0);
+ }
+ for (CodeFragmentFactory factory : factories) {
+ if (factory.getFileType().equals(fileType)) {
+ return factory;
+ }
+ }
+ return DefaultCodeFragmentFactory.getInstance();
}
});
- return factory != null? new CodeFragmentFactoryContextWrapper(factory) : null;
+ return new CodeFragmentFactoryContextWrapper(factory);
}
private static class SigReader {