@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);
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);
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;
@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) {
*/
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;
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();
- }
}