Merge branch 'master' into vplyashkun/clang_tidy_multifile_fixes
authorVladimir Plyashkun <vladimir.plyashkun@jetbrains.com>
Tue, 11 Sep 2018 13:03:22 +0000 (16:03 +0300)
committerVladimir Plyashkun <vladimir.plyashkun@jetbrains.com>
Tue, 11 Sep 2018 13:03:22 +0000 (16:03 +0300)
# Conflicts:
# platform/analysis-impl/src/com/intellij/codeInspection/ExternalAnnotatorInspectionVisitor.java

platform/analysis-impl/src/com/intellij/codeInspection/ExternalAnnotatorInspectionVisitor.java
platform/analysis-impl/src/com/intellij/codeInspection/ProblemDescriptorUtil.java

index 87662ca6e4c28ac0a3751fc5bca310119c6f4adc..ddd1a2142e4286d5517450620fd1620b6618bd0a 100644 (file)
 package com.intellij.codeInspection;
 
 import com.intellij.codeInsight.daemon.impl.AnnotationHolderImpl;
-import com.intellij.codeInsight.daemon.impl.HighlightInfo;
 import com.intellij.codeInsight.intention.IntentionAction;
-import com.intellij.lang.annotation.Annotation;
 import com.intellij.lang.annotation.AnnotationSession;
 import com.intellij.lang.annotation.ExternalAnnotator;
-import com.intellij.lang.annotation.HighlightSeverity;
 import com.intellij.openapi.application.ReadAction;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.project.Project;
@@ -29,7 +26,6 @@ import com.intellij.openapi.util.Iconable;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiElementVisitor;
 import com.intellij.psi.PsiFile;
-import com.intellij.util.containers.ContainerUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -76,80 +72,12 @@ public class ExternalAnnotatorInspectionVisitor extends PsiElementVisitor {
       return ReadAction.compute(() -> {
         AnnotationHolderImpl annotationHolder = new AnnotationHolderImpl(new AnnotationSession(file), true);
         annotator.apply(file, annotationResult, annotationHolder);
-        return convertToProblemDescriptors(annotationHolder, file);
+        return ProblemDescriptorUtil.convertToProblemDescriptors(annotationHolder, file);
       });
     }
     return ProblemDescriptor.EMPTY_ARRAY;
   }
 
-  @NotNull
-  private static ProblemDescriptor[] convertToProblemDescriptors(@NotNull final List<Annotation> annotations, @NotNull final PsiFile file) {
-    if (annotations.isEmpty()) {
-      return ProblemDescriptor.EMPTY_ARRAY;
-    }
-
-    List<ProblemDescriptor> problems = ContainerUtil.newArrayListWithCapacity(annotations.size());
-    IdentityHashMap<IntentionAction, LocalQuickFix> quickFixMappingCache = ContainerUtil.newIdentityHashMap();
-    for (Annotation annotation : annotations) {
-      if (annotation.getSeverity() == HighlightSeverity.INFORMATION ||
-          annotation.getStartOffset() == annotation.getEndOffset() && !annotation.isAfterEndOfLine()) {
-        continue;
-      }
-
-      final PsiElement startElement;
-      final PsiElement endElement;
-      if (annotation.getStartOffset() == annotation.getEndOffset() && annotation.isAfterEndOfLine()) {
-        startElement = endElement = file.findElementAt(annotation.getEndOffset() - 1);
-      } else {
-        startElement = file.findElementAt(annotation.getStartOffset());
-        endElement = file.findElementAt(annotation.getEndOffset() - 1);
-      }
-      if (startElement == null || endElement == null) {
-        continue;
-      }
-
-      LocalQuickFix[] quickFixes = toLocalQuickFixes(annotation.getQuickFixes(), quickFixMappingCache);
-      ProblemHighlightType highlightType = HighlightInfo.convertSeverityToProblemHighlight(annotation.getSeverity());
-      ProblemDescriptor descriptor = new ProblemDescriptorBase(startElement,
-                                                                     endElement,
-                                                                     annotation.getMessage(),
-                                                                     quickFixes,
-                                                                     highlightType,
-                                                                     annotation.isAfterEndOfLine(),
-                                                                     null,
-                                                                     true,
-                                                                     false);
-      problems.add(descriptor);
-    }
-    return problems.toArray(ProblemDescriptor.EMPTY_ARRAY);
-  }
-
-  @NotNull
-  private static LocalQuickFix[] toLocalQuickFixes(@Nullable List<? extends Annotation.QuickFixInfo> fixInfos,
-                                                   @NotNull Map<IntentionAction, LocalQuickFix> quickFixMappingCache) {
-    if (fixInfos == null || fixInfos.isEmpty()) {
-      return LocalQuickFix.EMPTY_ARRAY;
-    }
-    LocalQuickFix[] result = new LocalQuickFix[fixInfos.size()];
-    int i = 0;
-    for (Annotation.QuickFixInfo fixInfo : fixInfos) {
-      IntentionAction intentionAction = fixInfo.quickFix;
-      final LocalQuickFix fix;
-      if (intentionAction instanceof LocalQuickFix) {
-        fix = (LocalQuickFix) intentionAction;
-      }
-      else {
-        LocalQuickFix lqf = quickFixMappingCache.get(intentionAction);
-        if (lqf == null) {
-          lqf = new LocalQuickFixBackedByIntentionAction(intentionAction);
-          quickFixMappingCache.put(intentionAction, lqf);
-        }
-        fix = lqf;
-      }
-      result[i++] = fix;
-    }
-    return result;
-  }
 
   private void addDescriptors(@NotNull ProblemDescriptor[] descriptors) {
     for (ProblemDescriptor descriptor : descriptors) {
index 6ec16507ba5a4094134a0ea0b45828be4668ea54..b70ea06eb9fdf1fd85640a631ea5b489a54682d5 100644 (file)
@@ -1,19 +1,25 @@
 // Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
 package com.intellij.codeInspection;
 
+import com.intellij.codeInsight.daemon.impl.HighlightInfo;
 import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
 import com.intellij.codeInsight.daemon.impl.SeverityRegistrar;
+import com.intellij.codeInsight.intention.IntentionAction;
+import com.intellij.lang.annotation.Annotation;
 import com.intellij.lang.annotation.HighlightSeverity;
 import com.intellij.openapi.editor.colors.CodeInsightColors;
 import com.intellij.openapi.util.Couple;
 import com.intellij.openapi.util.TextRange;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
+import com.intellij.util.containers.ContainerUtil;
 import org.intellij.lang.annotations.MagicConstant;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import java.util.ArrayList;
+import java.util.IdentityHashMap;
 import java.util.List;
 
 public class ProblemDescriptorUtil {
@@ -165,4 +171,73 @@ public class ProblemDescriptorUtil {
     }
     throw new RuntimeException("Cannot map " + highlightType);
   }
+  @NotNull
+  public static ProblemDescriptor[] convertToProblemDescriptors(@NotNull final List<Annotation> annotations, @NotNull final PsiFile file) {
+    if (annotations.isEmpty()) {
+      return ProblemDescriptor.EMPTY_ARRAY;
+    }
+
+    List<ProblemDescriptor> problems = ContainerUtil.newArrayListWithCapacity(annotations.size());
+    IdentityHashMap<IntentionAction, LocalQuickFix> quickFixMappingCache = ContainerUtil.newIdentityHashMap();
+    for (Annotation annotation : annotations) {
+      if (annotation.getSeverity() == HighlightSeverity.INFORMATION ||
+          annotation.getStartOffset() == annotation.getEndOffset() && !annotation.isAfterEndOfLine()) {
+        continue;
+      }
+
+      final PsiElement startElement;
+      final PsiElement endElement;
+      if (annotation.getStartOffset() == annotation.getEndOffset() && annotation.isAfterEndOfLine()) {
+        startElement = endElement = file.findElementAt(annotation.getEndOffset() - 1);
+      }
+      else {
+        startElement = file.findElementAt(annotation.getStartOffset());
+        endElement = file.findElementAt(annotation.getEndOffset() - 1);
+      }
+      if (startElement == null || endElement == null) {
+        continue;
+      }
+
+      LocalQuickFix[] quickFixes = toLocalQuickFixes(annotation.getQuickFixes(), quickFixMappingCache);
+      ProblemHighlightType highlightType = HighlightInfo.convertSeverityToProblemHighlight(annotation.getSeverity());
+      ProblemDescriptor descriptor = new ProblemDescriptorBase(startElement,
+                                                               endElement,
+                                                               annotation.getMessage(),
+                                                               quickFixes,
+                                                               highlightType,
+                                                               annotation.isAfterEndOfLine(),
+                                                               null,
+                                                               true,
+                                                               false);
+      problems.add(descriptor);
+    }
+    return problems.toArray(ProblemDescriptor.EMPTY_ARRAY);
+  }
+
+  @NotNull
+  private static LocalQuickFix[] toLocalQuickFixes(@Nullable List<Annotation.QuickFixInfo> fixInfos,
+                                                   @NotNull IdentityHashMap<IntentionAction, LocalQuickFix> quickFixMappingCache) {
+    if (fixInfos == null || fixInfos.isEmpty()) {
+      return LocalQuickFix.EMPTY_ARRAY;
+    }
+    LocalQuickFix[] result = new LocalQuickFix[fixInfos.size()];
+    int i = 0;
+    for (Annotation.QuickFixInfo fixInfo : fixInfos) {
+      IntentionAction intentionAction = fixInfo.quickFix;
+      final LocalQuickFix fix;
+      if (intentionAction instanceof LocalQuickFix) {
+        fix = (LocalQuickFix)intentionAction;
+      }
+      else {
+        LocalQuickFix lqf = quickFixMappingCache.get(intentionAction);
+        if (lqf == null) {
+          lqf = new ExternalAnnotatorInspectionVisitor.LocalQuickFixBackedByIntentionAction(intentionAction);
+          quickFixMappingCache.put(intentionAction, lqf);
+        }
+        fix = lqf;
+      }
+      result[i++] = fix;
+    }
+    return result;
+  }
 }