resource bundle editor: ignore locales intention. post-review change (IDEA-CR-5668)
authorDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Thu, 15 Oct 2015 11:49:22 +0000 (14:49 +0300)
committerDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Thu, 15 Oct 2015 11:49:22 +0000 (14:49 +0300)
platform/analysis-impl/src/com/intellij/codeInspection/ProblemDescriptorUtil.java
platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionListStep.java
plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/editor/inspections/ResourceBundleEditorInspectionPass.java
plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/editor/inspections/ResourceBundleEditorProblemDescriptor.java
plugins/properties/src/META-INF/plugin.xml

index 93f40c41a3d90f8a0cccc8029850c684a75423cd..47eb271344ea2d5b46ca3af1cb3a131e6322c3b9 100644 (file)
@@ -140,6 +140,19 @@ public class ProblemDescriptorUtil {
                                                               @NotNull HighlightSeverity severity,
                                                               @NotNull SeverityRegistrar severityRegistrar) {
     final ProblemHighlightType highlightType = problemDescriptor.getHighlightType();
+    final HighlightInfoType highlightInfoType = getHighlightInfoType(highlightType, severity, severityRegistrar);
+    if (highlightInfoType == HighlightSeverity.INFORMATION) {
+      final TextAttributesKey attributes = ((ProblemDescriptorBase)problemDescriptor).getEnforcedTextAttributes();
+      if (attributes != null) {
+        return new HighlightInfoType.HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, attributes);
+      }
+    }
+    return highlightInfoType;
+  }
+
+  public static HighlightInfoType getHighlightInfoType(@NotNull ProblemHighlightType highlightType,
+                                                       @NotNull HighlightSeverity severity,
+                                                       @NotNull SeverityRegistrar severityRegistrar) {
     switch (highlightType) {
       case GENERIC_ERROR_OR_WARNING:
         return severityRegistrar.getHighlightInfoTypeBySeverity(severity);
@@ -164,10 +177,6 @@ public class ProblemDescriptorUtil {
       case GENERIC_ERROR:
         return HighlightInfoType.ERROR;
       case INFORMATION:
-        final TextAttributesKey attributes = ((ProblemDescriptorBase)problemDescriptor).getEnforcedTextAttributes();
-        if (attributes != null) {
-          return new HighlightInfoType.HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, attributes);
-        }
         return HighlightInfoType.INFORMATION;
     }
     throw new RuntimeException("Cannot map " + highlightType);
index 85bf449092e213d50815dfb86ff6707b6048de0e..8c9e48ace441e29ab7e4d5963736526b6f93739a 100644 (file)
@@ -114,65 +114,74 @@ public class IntentionListStep implements ListPopupStep<IntentionActionWithTextC
   private boolean wrapActionsTo(@NotNull List<HighlightInfo.IntentionActionDescriptor> newDescriptors,
                                 @NotNull Set<IntentionActionWithTextCaching> cachedActions,
                                 boolean callUpdate) {
-    final int caretOffset = myEditor == null ? 0 : myEditor.getCaretModel().getOffset();
-    final int fileOffset = caretOffset > 0 && caretOffset == myFile.getTextLength() ? caretOffset - 1 : caretOffset;
-    PsiElement element;
-    final PsiElement hostElement;
-    if (myFile instanceof PsiCompiledElement) {
-      hostElement = element = myFile;
-
-    }
-    else if (myEditor != null && PsiDocumentManager.getInstance(myProject).isUncommited(myEditor.getDocument())) {
-      //???
-      FileViewProvider viewProvider = myFile.getViewProvider();
-      hostElement = element = viewProvider.findElementAt(fileOffset, viewProvider.getBaseLanguage());
-    }
-    else {
-      hostElement = myFile.getViewProvider().findElementAt(fileOffset, myFile.getLanguage());
-      element = InjectedLanguageUtil.findElementAtNoCommit(myFile, fileOffset);
-    }
-    PsiFile injectedFile;
-    Editor injectedEditor;
-    if (element == null || element == hostElement) {
-      injectedFile = myFile;
-      injectedEditor = myEditor;
-    }
-    else {
-      injectedFile = element.getContainingFile();
-      injectedEditor = myEditor == null ? null : InjectedLanguageUtil.getInjectedEditorForInjectedFile(myEditor, injectedFile);
-    }
-
     boolean changed = false;
-    for (Iterator<IntentionActionWithTextCaching> iterator = cachedActions.iterator(); iterator.hasNext();) {
-      IntentionActionWithTextCaching cachedAction = iterator.next();
-      IntentionAction action = cachedAction.getAction();
-      if (myEditor != null && !ShowIntentionActionsHandler.availableFor(myFile, myEditor, action)
-        && (hostElement == element || element != null && !ShowIntentionActionsHandler.availableFor(injectedFile, injectedEditor, action))) {
-        iterator.remove();
-        changed = true;
+    if (myEditor == null) {
+      LOG.assertTrue(!callUpdate);
+      for (HighlightInfo.IntentionActionDescriptor descriptor : newDescriptors) {
+        changed |= cachedActions.add(wrapAction(descriptor, null, myFile, null));
+      }
+    } else {
+      final int caretOffset = myEditor.getCaretModel().getOffset();
+      final int fileOffset = caretOffset > 0 && caretOffset == myFile.getTextLength() ? caretOffset - 1 : caretOffset;
+      PsiElement element;
+      final PsiElement hostElement;
+      if (myFile instanceof PsiCompiledElement) {
+        hostElement = element = myFile;
+      }
+      else if (PsiDocumentManager.getInstance(myProject).isUncommited(myEditor.getDocument())) {
+        //???
+        FileViewProvider viewProvider = myFile.getViewProvider();
+        hostElement = element = viewProvider.findElementAt(fileOffset, viewProvider.getBaseLanguage());
+      }
+      else {
+        hostElement = myFile.getViewProvider().findElementAt(fileOffset, myFile.getLanguage());
+        element = InjectedLanguageUtil.findElementAtNoCommit(myFile, fileOffset);
+      }
+      PsiFile injectedFile;
+      Editor injectedEditor;
+      if (element == null || element == hostElement) {
+        injectedFile = myFile;
+        injectedEditor = myEditor;
+      }
+      else {
+        injectedFile = element.getContainingFile();
+        injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(myEditor, injectedFile);
       }
-    }
 
-    Set<IntentionActionWithTextCaching> wrappedNew = new THashSet<IntentionActionWithTextCaching>(newDescriptors.size(), ACTION_TEXT_AND_CLASS_EQUALS);
-    for (HighlightInfo.IntentionActionDescriptor descriptor : newDescriptors) {
-      final IntentionAction action = descriptor.getAction();
-      if (element != null && element != hostElement && (!callUpdate || myEditor == null || ShowIntentionActionsHandler.availableFor(injectedFile, injectedEditor, action))) {
-        IntentionActionWithTextCaching cachedAction = wrapAction(descriptor, element, injectedFile, injectedEditor);
-        wrappedNew.add(cachedAction);
-        changed |= cachedActions.add(cachedAction);
+      for (Iterator<IntentionActionWithTextCaching> iterator = cachedActions.iterator(); iterator.hasNext(); ) {
+        IntentionActionWithTextCaching cachedAction = iterator.next();
+        IntentionAction action = cachedAction.getAction();
+        if (!ShowIntentionActionsHandler.availableFor(myFile, myEditor, action) &&
+            (hostElement == element || element != null && !ShowIntentionActionsHandler.availableFor(injectedFile, injectedEditor, action))) {
+          iterator.remove();
+          changed = true;
+        }
       }
-      else if (hostElement != null && (!callUpdate || myEditor == null || ShowIntentionActionsHandler.availableFor(myFile, myEditor, action))) {
-        IntentionActionWithTextCaching cachedAction = wrapAction(descriptor, hostElement, myFile, myEditor);
-        wrappedNew.add(cachedAction);
-        changed |= cachedActions.add(cachedAction);
+
+      Set<IntentionActionWithTextCaching> wrappedNew =
+        new THashSet<IntentionActionWithTextCaching>(newDescriptors.size(), ACTION_TEXT_AND_CLASS_EQUALS);
+      for (HighlightInfo.IntentionActionDescriptor descriptor : newDescriptors) {
+        final IntentionAction action = descriptor.getAction();
+        if (element != null &&
+            element != hostElement &&
+            (!callUpdate || ShowIntentionActionsHandler.availableFor(injectedFile, injectedEditor, action))) {
+          IntentionActionWithTextCaching cachedAction = wrapAction(descriptor, element, injectedFile, injectedEditor);
+          wrappedNew.add(cachedAction);
+          changed |= cachedActions.add(cachedAction);
+        }
+        else if (hostElement != null && (!callUpdate || ShowIntentionActionsHandler.availableFor(myFile, myEditor, action))) {
+          IntentionActionWithTextCaching cachedAction = wrapAction(descriptor, hostElement, myFile, myEditor);
+          wrappedNew.add(cachedAction);
+          changed |= cachedActions.add(cachedAction);
+        }
       }
-    }
-    for (Iterator<IntentionActionWithTextCaching> iterator = cachedActions.iterator(); iterator.hasNext();) {
-      IntentionActionWithTextCaching cachedAction = iterator.next();
-      if (!wrappedNew.contains(cachedAction)) {
-        // action disappeared
-        iterator.remove();
-        changed = true;
+      for (Iterator<IntentionActionWithTextCaching> iterator = cachedActions.iterator(); iterator.hasNext(); ) {
+        IntentionActionWithTextCaching cachedAction = iterator.next();
+        if (!wrappedNew.contains(cachedAction)) {
+          // action disappeared
+          iterator.remove();
+          changed = true;
+        }
       }
     }
     return changed;
@@ -180,10 +189,11 @@ public class IntentionListStep implements ListPopupStep<IntentionActionWithTextC
 
   @NotNull
   IntentionActionWithTextCaching wrapAction(@NotNull HighlightInfo.IntentionActionDescriptor descriptor,
-                                            @NotNull PsiElement element,
-                                            @NotNull PsiFile containingFile,
+                                            @Nullable PsiElement element,
+                                            @Nullable PsiFile containingFile,
                                             @Nullable Editor containingEditor) {
     IntentionActionWithTextCaching cachedAction = new IntentionActionWithTextCaching(descriptor);
+    if (element == null) return cachedAction;
     final List<IntentionAction> options = descriptor.getOptions(element, containingEditor);
     if (options == null) return cachedAction;
     for (IntentionAction option : options) {
index d3590824363e3f861b3e99a35d6a37c0052c511b..88e6a90a8bfeef18ceb93d6b9e305cec7425408d 100644 (file)
@@ -92,7 +92,9 @@ public class ResourceBundleEditorInspectionPass {
             }
             HighlightSeverity severity = profileToUse.getInspectionProfile().getErrorLevel(toolKey, containingFile).getSeverity();
             final HighlightInfoType infoType =
-              ProblemDescriptorUtil.highlightTypeFromDescriptor(descriptor, severity, SeverityRegistrar.getSeverityRegistrar(project));
+              ProblemDescriptorUtil.getHighlightInfoType(descriptor.getHighlightType(),
+                                                         severity,
+                                                         SeverityRegistrar.getSeverityRegistrar(project));
             highlightTypes.add(infoType);
           }
         }
index c17bcb3c794fbb9e8e601774b2dd9e383618d550..ee9d286494d070edf7d4b7169ca781650c17bf4a 100644 (file)
  */
 package com.intellij.lang.properties.editor.inspections;
 
-import com.intellij.codeInspection.ProblemDescriptor;
+import com.intellij.codeInspection.CommonProblemDescriptor;
 import com.intellij.codeInspection.ProblemHighlightType;
 import com.intellij.codeInspection.QuickFix;
-import com.intellij.lang.annotation.ProblemGroup;
-import com.intellij.openapi.editor.colors.TextAttributesKey;
-import com.intellij.openapi.util.TextRange;
-import com.intellij.psi.PsiElement;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 /**
  * @author Dmitry Batkovich
  */
-public class ResourceBundleEditorProblemDescriptor implements ProblemDescriptor {
+public class ResourceBundleEditorProblemDescriptor implements CommonProblemDescriptor {
   private final ProblemHighlightType myHighlightType;
   private final String myDescriptionTemplate;
   private final QuickFix[] myFixes;
 
-  public ResourceBundleEditorProblemDescriptor(final ProblemHighlightType type, String template, QuickFix<ResourceBundleEditorProblemDescriptor>... fixes) {
+  public ResourceBundleEditorProblemDescriptor(final ProblemHighlightType type, String template, QuickFix... fixes) {
     myHighlightType = type;
     myDescriptionTemplate = template;
     myFixes = fixes;
@@ -55,55 +51,4 @@ public class ResourceBundleEditorProblemDescriptor implements ProblemDescriptor
   public QuickFix[] getFixes() {
     return myFixes;
   }
-
-  @Override
-  public PsiElement getPsiElement() {
-    throw new UnsupportedOperationException();
-  }
-
-  @Override
-  public PsiElement getStartElement() {
-    throw new UnsupportedOperationException();
-  }
-
-  @Override
-  public PsiElement getEndElement() {
-    throw new UnsupportedOperationException();
-  }
-
-  @Override
-  public TextRange getTextRangeInElement() {
-    throw new UnsupportedOperationException();
-  }
-
-  @Override
-  public int getLineNumber() {
-    throw new UnsupportedOperationException();
-  }
-
-  @Override
-  public boolean isAfterEndOfLine() {
-    throw new UnsupportedOperationException();
-  }
-
-  @Override
-  public void setTextAttributes(TextAttributesKey key) {
-    throw new UnsupportedOperationException();
-  }
-
-  @Nullable
-  @Override
-  public ProblemGroup getProblemGroup() {
-    throw new UnsupportedOperationException();
-  }
-
-  @Override
-  public void setProblemGroup(@Nullable ProblemGroup problemGroup) {
-    throw new UnsupportedOperationException();
-  }
-
-  @Override
-  public boolean showTooltip() {
-    throw new UnsupportedOperationException();
-  }
 }
index 3f5d08df90939be2496c70211bc6fb4d6ac525cd..de90a2dc8af92c43138372e463ad737e1e99e7db 100644 (file)
@@ -86,9 +86,9 @@
                      key="wrong.property.key.value.delimiter.inspection.display.name" groupKey="properties.files.inspection.group.display.name"
                      enabledByDefault="true" level="WEAK WARNING" cleanupTool="true"
                      implementationClass="com.intellij.codeInspection.WrongPropertyKeyValueDelimiterInspection"/>
-    <localInspection language="Properties" shortName="IncompleteProperty" bundle="messages.PropertiesBundle"
+    <localInspection language="Properties" shortName="IncompleteProperty" unfair="true" bundle="messages.PropertiesBundle"
                      key="incomplete.property.inspection.display.name" groupKey="properties.files.inspection.group.display.name"
-                     enabledByDefault="true" level="ERROR" cleanupTool="false"
+                     enabledByDefault="true" level="ERROR"
                      implementationClass="com.intellij.lang.properties.editor.inspections.incomplete.IncompletePropertyInspection"/>
 
     <idIndexer filetype="Properties" implementationClass="com.intellij.psi.impl.cache.impl.idCache.PropertiesIdIndexer"/>