IDEADEV-42042: method separators in Groovy classes don't render properly
authorMaxim Medvedev <maxim.medvedev@jetbrains.com>
Sat, 26 Dec 2009 15:26:23 +0000 (18:26 +0300)
committerMaxim Medvedev <maxim.medvedev@jetbrains.com>
Sat, 26 Dec 2009 15:26:23 +0000 (18:26 +0300)
java/java-impl/src/com/intellij/codeInsight/daemon/impl/JavaLineMarkerProvider.java
plugins/groovy/src/org/jetbrains/plugins/groovy/codeInsight/GroovyLineMarkerProvider.java

index e69f64fc07bc070c35c6d4795759fe6ecaefbdf3..1b1a39e657962a066e7875bcd349a1ac292d6d69 100644 (file)
@@ -57,8 +57,8 @@ public class JavaLineMarkerProvider implements LineMarkerProvider, DumbAware {
   private static final Icon IMPLEMENTED_INTERFACE_MARKER_RENDERER = IMPLEMENTED_METHOD_MARKER_RENDERER;
   private static final Icon SUBCLASSED_CLASS_MARKER_RENDERER = OVERRIDEN_METHOD_MARKER_RENDERER;
 
-  private final DaemonCodeAnalyzerSettings myDaemonSettings;
-  private final EditorColorsManager myColorsManager;
+  protected final DaemonCodeAnalyzerSettings myDaemonSettings;
+  protected final EditorColorsManager myColorsManager;
 
   public JavaLineMarkerProvider(DaemonCodeAnalyzerSettings daemonSettings, EditorColorsManager colorsManager) {
     myDaemonSettings = daemonSettings;
@@ -119,7 +119,7 @@ public class JavaLineMarkerProvider implements LineMarkerProvider, DumbAware {
     return null;
   }
 
-  private static int getCategory(PsiElement element) {
+  protected static int getCategory(PsiElement element) {
     if (element instanceof PsiField) return 1;
     if (element instanceof PsiClass || element instanceof PsiClassInitializer) return 2;
     if (element instanceof PsiMethod) {
index 844a2791785e622a21083c356ed49538c77ccc63..155056efd2af5fb796211e3ce9bcc3274f13757a 100644 (file)
  */
 package org.jetbrains.plugins.groovy.codeInsight;
 
+import com.intellij.codeHighlighting.Pass;
 import com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings;
 import com.intellij.codeInsight.daemon.LineMarkerInfo;
 import com.intellij.codeInsight.daemon.impl.JavaLineMarkerProvider;
 import com.intellij.lang.ASTNode;
+import com.intellij.openapi.editor.colors.CodeInsightColors;
 import com.intellij.openapi.editor.colors.EditorColorsManager;
-import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiNameIdentifierOwner;
+import com.intellij.openapi.editor.colors.EditorColorsScheme;
+import com.intellij.openapi.editor.markup.GutterIconRenderer;
+import com.intellij.openapi.editor.markup.SeparatorPlacement;
+import com.intellij.psi.*;
+import com.intellij.util.NullableFunction;
+import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment;
+import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner;
 import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
 
 import java.util.Collection;
@@ -31,7 +38,8 @@ import java.util.List;
  * @author ilyas
  * Same logic as for Java LMP
  */
-public class GroovyLineMarkerProvider extends JavaLineMarkerProvider{
+public class GroovyLineMarkerProvider extends JavaLineMarkerProvider {
+
   public GroovyLineMarkerProvider(DaemonCodeAnalyzerSettings daemonSettings, EditorColorsManager colorsManager) {
     super(daemonSettings, colorsManager);
   }
@@ -45,6 +53,44 @@ public class GroovyLineMarkerProvider extends JavaLineMarkerProvider{
         return super.getLineMarkerInfo(((PsiNameIdentifierOwner)parent).getNameIdentifier());
       }
     }
+    //need to draw method separator above docComment
+    if (myDaemonSettings.SHOW_METHOD_SEPARATORS && element.getFirstChild() == null) {
+      PsiElement element1 = element;
+      boolean isMember = false;
+      while (element1 != null && !(element1 instanceof PsiFile) && element1.getPrevSibling() == null) {
+        element1 = element1.getParent();
+        if (element1 instanceof PsiMember) {
+          isMember = true;
+          break;
+        }
+      }
+      if (isMember && !(element1 instanceof PsiAnonymousClass || element1.getParent() instanceof PsiAnonymousClass)) {
+        boolean drawSeparator = false;
+        int category = getCategory(element1);
+        for (PsiElement child = element1.getPrevSibling(); child != null; child = child.getPrevSibling()) {
+          int category1 = getCategory(child);
+          if (category1 == 0) continue;
+          drawSeparator = category != 1 || category1 != 1;
+          break;
+        }
+
+        if (drawSeparator) {
+          GrDocComment comment = null;
+          if (element1 instanceof GrDocCommentOwner) {
+            comment = ((GrDocCommentOwner)element1).getGrDocComment();
+          }
+          LineMarkerInfo info =
+            new LineMarkerInfo<PsiElement>(element, comment != null ? comment.getTextRange() : element.getTextRange(), null,
+                                           Pass.UPDATE_ALL, NullableFunction.NULL, null,
+                                           GutterIconRenderer.Alignment.RIGHT);
+          EditorColorsScheme scheme = myColorsManager.getGlobalScheme();
+          info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR);
+          info.separatorPlacement = SeparatorPlacement.TOP;
+          return info;
+        }
+      }
+    }
+
     return super.getLineMarkerInfo(element);
   }