use of com.intellij.codeInsight.intention.EmptyIntentionAction in project intellij-community by JetBrains.
the class LocalInspectionsPass method registerQuickFixes.
private static void registerQuickFixes(@NotNull LocalInspectionToolWrapper tool, @NotNull ProblemDescriptor descriptor, @NotNull HighlightInfo highlightInfo, @NotNull Set<Pair<TextRange, String>> emptyActionRegistered) {
final HighlightDisplayKey key = HighlightDisplayKey.find(tool.getShortName());
boolean needEmptyAction = true;
final QuickFix[] fixes = descriptor.getFixes();
if (fixes != null && fixes.length > 0) {
for (int k = 0; k < fixes.length; k++) {
if (fixes[k] != null) {
// prevent null fixes from var args
QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixWrapper.wrap(descriptor, k), key);
needEmptyAction = false;
}
}
}
HintAction hintAction = descriptor instanceof ProblemDescriptorImpl ? ((ProblemDescriptorImpl) descriptor).getHintAction() : null;
if (hintAction != null) {
QuickFixAction.registerQuickFixAction(highlightInfo, hintAction, key);
needEmptyAction = false;
}
if (((ProblemDescriptorBase) descriptor).getEnforcedTextAttributes() != null) {
needEmptyAction = false;
}
if (needEmptyAction && emptyActionRegistered.add(Pair.create(highlightInfo.getFixTextRange(), tool.getShortName()))) {
IntentionAction emptyIntentionAction = new EmptyIntentionAction(tool.getDisplayName());
QuickFixAction.registerQuickFixAction(highlightInfo, emptyIntentionAction, key);
}
}
use of com.intellij.codeInsight.intention.EmptyIntentionAction in project intellij-community by JetBrains.
the class PostHighlightingVisitor method processLocalVariable.
@Nullable
private HighlightInfo processLocalVariable(@NotNull PsiLocalVariable variable, @NotNull PsiIdentifier identifier, @NotNull ProgressIndicator progress) {
if (variable instanceof PsiResourceVariable && PsiUtil.isIgnoredName(variable.getName()))
return null;
if (UnusedSymbolUtil.isImplicitUsage(myProject, variable, progress))
return null;
if (!myRefCountHolder.isReferenced(variable)) {
String message = JavaErrorMessages.message("local.variable.is.never.used", identifier.getText());
HighlightInfo highlightInfo = UnusedSymbolUtil.createUnusedSymbolInfo(identifier, message, myDeadCodeInfoType);
IntentionAction fix = variable instanceof PsiResourceVariable ? QuickFixFactory.getInstance().createRenameToIgnoredFix(variable) : QuickFixFactory.getInstance().createRemoveUnusedVariableFix(variable);
QuickFixAction.registerQuickFixAction(highlightInfo, fix, myDeadCodeKey);
return highlightInfo;
}
boolean referenced = myRefCountHolder.isReferencedForRead(variable);
if (!referenced && !UnusedSymbolUtil.isImplicitRead(myProject, variable, progress)) {
String message = JavaErrorMessages.message("local.variable.is.not.used.for.reading", identifier.getText());
HighlightInfo highlightInfo = UnusedSymbolUtil.createUnusedSymbolInfo(identifier, message, myDeadCodeInfoType);
QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixFactory.getInstance().createRemoveUnusedVariableFix(variable), myDeadCodeKey);
return highlightInfo;
}
if (!variable.hasInitializer()) {
referenced = myRefCountHolder.isReferencedForWrite(variable);
if (!referenced && !UnusedSymbolUtil.isImplicitWrite(myProject, variable, progress)) {
String message = JavaErrorMessages.message("local.variable.is.not.assigned", identifier.getText());
final HighlightInfo unusedSymbolInfo = UnusedSymbolUtil.createUnusedSymbolInfo(identifier, message, myDeadCodeInfoType);
QuickFixAction.registerQuickFixAction(unusedSymbolInfo, new EmptyIntentionAction(UnusedSymbolLocalInspectionBase.DISPLAY_NAME), myDeadCodeKey);
return unusedSymbolInfo;
}
}
return null;
}
use of com.intellij.codeInsight.intention.EmptyIntentionAction in project intellij-community by JetBrains.
the class EmptyIntentionInspectionQuickFixTest method testX.
public void testX() throws Exception {
configureByFile(getBasePath() + "/X.java");
List<IntentionAction> emptyActions = getAvailableActions();
for (int i = emptyActions.size() - 1; i >= 0; i--) {
IntentionAction action = emptyActions.get(i);
if (!(action instanceof EmptyIntentionAction))
emptyActions.remove(i);
}
assertEquals(emptyActions.toString(), 1, emptyActions.size());
}
use of com.intellij.codeInsight.intention.EmptyIntentionAction in project intellij-community by JetBrains.
the class EmptyIntentionInspectionQuickFixTest method testLowPriority.
public void testLowPriority() throws Exception {
configureByFile(getBasePath() + "/LowPriority.java");
List<IntentionAction> emptyActions = getAvailableActions();
int i = 0;
for (; i < emptyActions.size(); i++) {
final IntentionAction intentionAction = emptyActions.get(i);
if ("Make 'i' not final".equals(intentionAction.getText())) {
break;
}
if (intentionAction instanceof EmptyIntentionAction) {
fail("Low priority action prior to quick fix");
}
}
assertTrue(i < emptyActions.size());
for (; i < emptyActions.size(); i++) {
if (emptyActions.get(i) instanceof EditInspectionToolsSettingsAction) {
return;
}
}
fail("Missed inspection setting action");
}
use of com.intellij.codeInsight.intention.EmptyIntentionAction in project intellij-community by JetBrains.
the class GrUnresolvedAccessChecker method addEmptyIntentionIfNeeded.
private void addEmptyIntentionIfNeeded(@Nullable HighlightInfo info) {
if (info != null) {
int s1 = info.quickFixActionMarkers != null ? info.quickFixActionMarkers.size() : 0;
int s2 = info.quickFixActionRanges != null ? info.quickFixActionRanges.size() : 0;
if (s1 + s2 == 0) {
EmptyIntentionAction emptyIntentionAction = new EmptyIntentionAction(GrUnresolvedAccessInspection.getDisplayText());
QuickFixAction.registerQuickFixAction(info, emptyIntentionAction, myDisplayKey);
}
}
}
Aggregations