IDEA-60932 Support Groovy expressions in debugger expression evaluation pycharm/144.3233
authorEgor.Ushakov <egor.ushakov@jetbrains.com>
Thu, 21 Jan 2016 17:22:13 +0000 (20:22 +0300)
committerEgor.Ushakov <egor.ushakov@jetbrains.com>
Thu, 21 Jan 2016 17:26:29 +0000 (20:26 +0300)
plugins/groovy/src/org/jetbrains/plugins/groovy/debugger/GroovyCodeFragmentFactory.java

index c1f27061eca62a6dcad1d7d898f3b91060a57481..0fb1d33088035fd2d2fe132915938546ad4e3371 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2015 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ import com.intellij.openapi.util.Pair;
 import com.intellij.openapi.util.TextRange;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.psi.*;
+import com.intellij.psi.search.GlobalSearchScope;
 import com.intellij.psi.util.ClassUtil;
 import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.util.Function;
@@ -331,9 +332,20 @@ public class GroovyCodeFragmentFactory extends CodeFragmentFactory {
 
   @Override
   public boolean isContextAccepted(PsiElement context) {
-    return context != null && context.getLanguage().equals(GroovyLanguage.INSTANCE);
+    if (context != null) {
+      if (context.getLanguage().equals(GroovyLanguage.INSTANCE)) {
+        return true;
+      }
+      Project project = context.getProject();
+      if (JavaPsiFacade.getInstance(project)
+            .findClass("org.codehaus.groovy.control.CompilationUnit", GlobalSearchScope.allScope(project)) != null) {
+        return true;
+      }
+    }
+    return false;
   }
 
+  @NotNull
   @Override
   public LanguageFileType getFileType() {
     return GroovyFileType.GROOVY_FILE_TYPE;