use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.
the class QuickFixFactoryImpl method registerFixesForUnusedParameter.
@Override
public void registerFixesForUnusedParameter(@NotNull PsiParameter parameter, @NotNull Object highlightInfo) {
Project myProject = parameter.getProject();
InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getCurrentProfile();
UnusedDeclarationInspectionBase unusedParametersInspection = (UnusedDeclarationInspectionBase) profile.getUnwrappedTool(UnusedSymbolLocalInspectionBase.SHORT_NAME, parameter);
LOG.assertTrue(ApplicationManager.getApplication().isUnitTestMode() || unusedParametersInspection != null);
List<IntentionAction> options = new ArrayList<>();
HighlightDisplayKey myUnusedSymbolKey = HighlightDisplayKey.find(UnusedSymbolLocalInspectionBase.SHORT_NAME);
options.addAll(IntentionManager.getInstance().getStandardIntentionOptions(myUnusedSymbolKey, parameter));
if (unusedParametersInspection != null) {
SuppressQuickFix[] batchSuppressActions = unusedParametersInspection.getBatchSuppressActions(parameter);
Collections.addAll(options, SuppressIntentionActionFromFix.convertBatchToSuppressIntentionActions(batchSuppressActions));
}
//need suppress from Unused Parameters but settings from Unused Symbol
QuickFixAction.registerQuickFixAction((HighlightInfo) highlightInfo, new SafeDeleteFix(parameter), options, HighlightDisplayKey.getDisplayNameByKey(myUnusedSymbolKey));
}
use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.
the class QuickFixWrapper method isAvailable.
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
PsiElement psiElement = myDescriptor.getPsiElement();
if (psiElement == null || !psiElement.isValid())
return false;
final LocalQuickFix fix = getFix();
return !(fix instanceof IntentionAction) || ((IntentionAction) fix).isAvailable(project, editor, file);
}
use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.
the class WebReferencesAnnotatorBase method apply.
@Override
public void apply(@NotNull PsiFile file, MyInfo[] infos, @NotNull AnnotationHolder holder) {
if (infos == null || infos.length == 0) {
return;
}
final HighlightDisplayLevel displayLevel = getHighlightDisplayLevel(file);
for (MyInfo info : infos) {
if (!info.myResult) {
final PsiElement element = info.myAnchor.retrieve();
if (element != null) {
final int start = element.getTextRange().getStartOffset();
final TextRange range = new TextRange(start + info.myRangeInElement.getStartOffset(), start + info.myRangeInElement.getEndOffset());
final String message = getErrorMessage(info.myUrl);
final Annotation annotation;
if (displayLevel == HighlightDisplayLevel.ERROR) {
annotation = holder.createErrorAnnotation(range, message);
} else if (displayLevel == HighlightDisplayLevel.WARNING) {
annotation = holder.createWarningAnnotation(range, message);
} else if (displayLevel == HighlightDisplayLevel.WEAK_WARNING) {
annotation = holder.createInfoAnnotation(range, message);
} else {
annotation = holder.createWarningAnnotation(range, message);
}
for (IntentionAction action : getQuickFixes()) {
annotation.registerFix(action);
}
}
}
}
}
use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.
the class OrderEntryTest method doTest.
private void doTest(String fileName) throws Exception {
String testFullPath = BASE_PATH + fileName;
VirtualFile root = ModuleRootManager.getInstance(myModule).getContentRoots()[0].getParent();
VirtualFile virtualFile = root.findFileByRelativePath(fileName);
configureByExistingFile(virtualFile);
ActionHint actionHint = ActionHint.parse(getFile(), getFile().getText());
Collection<HighlightInfo> infosBefore = highlightErrors();
final IntentionAction action = findActionAndCheck(actionHint, infosBefore);
if (action != null) {
String text = action.getText();
WriteCommandAction.runWriteCommandAction(null, () -> action.invoke(getProject(), getEditor(), getFile()));
Collection<HighlightInfo> infosAfter = highlightErrors();
final IntentionAction afterAction = findActionWithText(text);
if (afterAction != null) {
fail("Action '" + text + "' is still available after its invocation in test " + testFullPath);
}
assertEquals(infosBefore.size() - 1, infosAfter.size());
}
}
use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.
the class StaticImportMethodWithCommonNameTest method testFindStaticMember.
public void testFindStaticMember() throws Exception {
myFixture.configureByText("a.java", "class A { {String s = for<caret>mat(\"\",\"\");}}");
final IntentionAction intention = myFixture.findSingleIntention(QuickFixBundle.message("static.import.method.text"));
assertNotNull(intention);
myFixture.launchAction(intention);
myFixture.checkResult("import static java.lang.String.format;\n" + "\n" + "class A { {String s = format(\"\",\"\");}}", false);
}
Aggregations