truncate extremely long inspection descriptions
authorAlexey Kudravtsev <cdr@intellij.com>
Thu, 3 Jun 2010 11:29:01 +0000 (15:29 +0400)
committerAlexey Kudravtsev <cdr@intellij.com>
Fri, 4 Jun 2010 08:19:51 +0000 (12:19 +0400)
platform/lang-impl/src/com/intellij/codeInspection/ui/ProblemDescriptionNode.java

index 24ee0577a4d964d16364cadaf3c573907c3f781e..81286c4b328451d74b8370a6d50d46b69ece2bfc 100644 (file)
@@ -44,8 +44,7 @@ public class ProblemDescriptionNode extends InspectionTreeNode {
   private CommonProblemDescriptor myDescriptor;
   protected DescriptorProviderInspection myTool;
 
-  public ProblemDescriptionNode(final Object userObject,
-                                final DescriptorProviderInspection tool) {
+  public ProblemDescriptionNode(final Object userObject, final DescriptorProviderInspection tool) {
     super(userObject);
     myTool = tool;
   }
@@ -60,9 +59,14 @@ public class ProblemDescriptionNode extends InspectionTreeNode {
   }
 
   @Nullable
-  public RefEntity getElement() { return myElement; }
+  public RefEntity getElement() {
+    return myElement;
+  }
+
   @Nullable
-  public CommonProblemDescriptor getDescriptor() { return myDescriptor; }
+  public CommonProblemDescriptor getDescriptor() {
+    return myDescriptor;
+  }
 
   public Icon getIcon(boolean expanded) {
     if (myDescriptor instanceof ProblemDescriptorImpl) {
@@ -78,7 +82,7 @@ public class ProblemDescriptionNode extends InspectionTreeNode {
   }
 
   public boolean isValid() {
-    if (myElement instanceof RefElement && !((RefElement)myElement).isValid()) return false;
+    if (myElement instanceof RefElement && !myElement.isValid()) return false;
     final CommonProblemDescriptor descriptor = getDescriptor();
     if (descriptor instanceof ProblemDescriptor) {
       final PsiElement psiElement = ((ProblemDescriptor)descriptor).getPsiElement();
@@ -127,15 +131,17 @@ public class ProblemDescriptionNode extends InspectionTreeNode {
   public static String extractHighlightedText(CommonProblemDescriptor descriptor, PsiElement psiElement) {
     if (psiElement == null || !psiElement.isValid()) return "";
     String ref = psiElement.getText();
-    if(descriptor instanceof ProblemDescriptorImpl) {
+    if (descriptor instanceof ProblemDescriptorImpl) {
       TextRange textRange = ((ProblemDescriptorImpl)descriptor).getTextRange();
       final TextRange elementRange = psiElement.getTextRange();
-      if (textRange!=null && elementRange!=null) {
+      if (textRange != null && elementRange != null) {
         textRange = textRange.shiftRight(-elementRange.getStartOffset());
-        if(textRange.getStartOffset() >= 0 && textRange.getEndOffset() <= ref.length())
+        if (textRange.getStartOffset() >= 0 && textRange.getEndOffset() <= ref.length()) {
           ref = textRange.substring(ref);
+        }
       }
     }
+    ref = StringUtil.first(ref.replaceAll("\n"," ").trim(), 100, true);
     return ref;
   }
 }