use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.
the class IPPTestCase method assertIntentionNotAvailable.
protected void assertIntentionNotAvailable(Class<? extends IntentionAction> intentionClass) {
myFixture.configureByFile(getTestName(false) + ".java");
final List<IntentionAction> result = new SmartList<>();
for (final IntentionAction intention : myFixture.getAvailableIntentions()) {
if (intentionClass.isInstance(intention)) {
result.add(intention);
} else if (intention instanceof IntentionActionWrapper) {
final IntentionActionWrapper wrapper = (IntentionActionWrapper) intention;
if (intentionClass.isInstance(wrapper.getDelegate())) {
result.add(intention);
}
}
}
assertEmpty("Intention of class \'" + intentionClass + "\' is available but should not", result);
}
use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.
the class HighlightUtil method registerAccessQuickFixAction.
/**
* make element protected/package-private/public suggestion
*/
static void registerAccessQuickFixAction(@NotNull PsiMember refElement, @NotNull PsiJavaCodeReferenceElement place, @Nullable HighlightInfo errorResult, final PsiElement fileResolveScope) {
if (errorResult == null)
return;
PsiClass accessObjectClass = null;
PsiElement qualifier = place.getQualifier();
if (qualifier instanceof PsiExpression) {
accessObjectClass = (PsiClass) PsiUtil.getAccessObjectClass((PsiExpression) qualifier).getElement();
}
registerReplaceInaccessibleFieldWithGetterSetterFix(refElement, place, accessObjectClass, errorResult);
if (refElement instanceof PsiCompiledElement)
return;
PsiModifierList modifierList = refElement.getModifierList();
if (modifierList == null)
return;
PsiClass packageLocalClassInTheMiddle = getPackageLocalClassInTheMiddle(place);
if (packageLocalClassInTheMiddle != null) {
IntentionAction fix = QUICK_FIX_FACTORY.createModifierListFix(packageLocalClassInTheMiddle, PsiModifier.PUBLIC, true, true);
QuickFixAction.registerQuickFixAction(errorResult, fix);
return;
}
try {
Project project = refElement.getProject();
JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
PsiModifierList modifierListCopy = facade.getElementFactory().createFieldFromText("int a;", null).getModifierList();
modifierListCopy.setModifierProperty(PsiModifier.STATIC, modifierList.hasModifierProperty(PsiModifier.STATIC));
String minModifier = PsiModifier.PACKAGE_LOCAL;
if (refElement.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) {
minModifier = PsiModifier.PROTECTED;
}
if (refElement.hasModifierProperty(PsiModifier.PROTECTED)) {
minModifier = PsiModifier.PUBLIC;
}
String[] modifiers = { PsiModifier.PACKAGE_LOCAL, PsiModifier.PROTECTED, PsiModifier.PUBLIC };
for (int i = ArrayUtil.indexOf(modifiers, minModifier); i < modifiers.length; i++) {
@PsiModifier.ModifierConstant String modifier = modifiers[i];
modifierListCopy.setModifierProperty(modifier, true);
if (facade.getResolveHelper().isAccessible(refElement, modifierListCopy, place, accessObjectClass, fileResolveScope)) {
IntentionAction fix = QUICK_FIX_FACTORY.createModifierListFix(refElement, modifier, true, true);
TextRange fixRange = new TextRange(errorResult.startOffset, errorResult.endOffset);
PsiElement ref = place.getReferenceNameElement();
if (ref != null) {
fixRange = fixRange.union(ref.getTextRange());
}
QuickFixAction.registerQuickFixAction(errorResult, fixRange, fix);
}
}
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.
the class HighlightUtil method getChangeVariableTypeFixes.
@NotNull
public static List<IntentionAction> getChangeVariableTypeFixes(@NotNull PsiVariable parameter, PsiType itemType) {
if (itemType instanceof PsiMethodReferenceType)
return Collections.emptyList();
List<IntentionAction> result = new ArrayList<>();
if (itemType != null) {
for (ChangeVariableTypeQuickFixProvider fixProvider : Extensions.getExtensions(ChangeVariableTypeQuickFixProvider.EP_NAME)) {
Collections.addAll(result, fixProvider.getFixes(parameter, itemType));
}
}
IntentionAction changeFix = getChangeParameterClassFix(parameter.getType(), itemType);
if (changeFix != null)
result.add(changeFix);
return result;
}
use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.
the class PostHighlightingVisitor method processMethod.
@Nullable
private HighlightInfo processMethod(@NotNull final Project project, @NotNull final PsiMethod method, @NotNull PsiIdentifier identifier, @NotNull ProgressIndicator progress, @NotNull GlobalUsageHelper helper) {
if (UnusedSymbolUtil.isMethodReferenced(myProject, myFile, method, progress, helper))
return null;
String key;
if (method.hasModifierProperty(PsiModifier.PRIVATE)) {
key = method.isConstructor() ? "private.constructor.is.not.used" : "private.method.is.not.used";
} else {
key = method.isConstructor() ? "constructor.is.not.used" : "method.is.not.used";
}
String symbolName = HighlightMessageUtil.getSymbolName(method, PsiSubstitutor.EMPTY);
String message = JavaErrorMessages.message(key, symbolName);
final HighlightInfo highlightInfo = UnusedSymbolUtil.createUnusedSymbolInfo(identifier, message, myDeadCodeInfoType);
QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixFactory.getInstance().createSafeDeleteFix(method), myDeadCodeKey);
SpecialAnnotationsUtilBase.createAddToSpecialAnnotationFixes(method, annoName -> {
IntentionAction fix = QuickFixFactory.getInstance().createAddToDependencyInjectionAnnotationsFix(project, annoName, "methods");
QuickFixAction.registerQuickFixAction(highlightInfo, fix);
return true;
});
return highlightInfo;
}
use of com.intellij.codeInsight.intention.IntentionAction in project intellij-community by JetBrains.
the class StaticPseudoFunctionalStyleMethodTest method doTest.
private void doTest() {
myFixture.configureByFile(getTestName(true) + "/test.java");
myFixture.enableInspections(new StaticPseudoFunctionalStyleMethodInspection());
boolean isQuickFixFound = false;
for (IntentionAction action : myFixture.getAvailableIntentions()) {
if (action instanceof QuickFixWrapper) {
final LocalQuickFix fix = ((QuickFixWrapper) action).getFix();
if (fix instanceof StaticPseudoFunctionalStyleMethodInspection.ReplacePseudoLambdaWithLambda) {
myFixture.launchAction(action);
isQuickFixFound = true;
break;
}
}
}
assertTrue("Quick fix isn't found", isQuickFixFound);
myFixture.checkResultByFile(getTestName(true) + "/test_after.java");
}
Aggregations