本文整理匯總了Java中com.intellij.codeInsight.intention.IntentionAction類的典型用法代碼示例。如果您正苦於以下問題:Java IntentionAction類的具體用法?Java IntentionAction怎麽用?Java IntentionAction使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
IntentionAction類屬於com.intellij.codeInsight.intention包,在下文中一共展示了IntentionAction類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: assertIntentionIsAvailable
import com.intellij.codeInsight.intention.IntentionAction; //導入依賴的package包/類
public void assertIntentionIsAvailable(LanguageFileType languageFileType, String configureByText, String intentionText) {
myFixture.configureByText(languageFileType, configureByText);
PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
Set<String> items = new HashSet<>();
for (IntentionAction intentionAction : IntentionManager.getInstance().getIntentionActions()) {
if(!intentionAction.isAvailable(getProject(), getEditor(), psiElement.getContainingFile())) {
continue;
}
String text = intentionAction.getText();
items.add(text);
if(!text.equals(intentionText)) {
continue;
}
return;
}
fail(String.format("Fail intention action '%s' is available in element '%s' with '%s'", intentionText, psiElement.getText(), items));
}
示例2: doTest
import com.intellij.codeInsight.intention.IntentionAction; //導入依賴的package包/類
private void doTest(boolean available, final String attrName) throws Exception {
configureByFiles(null, getTestName(true) + ".fxml");
final List<HighlightInfo> infos = doHighlighting();
Editor editor = getEditor();
PsiFile file = getFile();
final String actionName = "Expand '" + attrName + "' to tag";
IntentionAction intentionAction = findIntentionAction(infos, actionName, editor, file);
if (available) {
assertNotNull(actionName, intentionAction);
assertTrue(ShowIntentionActionsHandler.chooseActionAndInvoke(file, editor, intentionAction, actionName));
checkResultByFile(getTestName(true) + "_after.fxml");
} else {
assertNull(intentionAction);
}
}
示例3: doTest
import com.intellij.codeInsight.intention.IntentionAction; //導入依賴的package包/類
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");
}
示例4: doApplyInformationToEditor
import com.intellij.codeInsight.intention.IntentionAction; //導入依賴的package包/類
@Override
public void doApplyInformationToEditor() {
HighlightInfo info = null;
if (myRange != null) {
TextAttributes attributes = new TextAttributes(null, null,
myEditor.getColorsScheme().getAttributes(CodeInsightColors.WEAK_WARNING_ATTRIBUTES)
.getEffectColor(),
null, Font.PLAIN);
HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(myRange);
builder.textAttributes(attributes);
builder.descriptionAndTooltip(SIGNATURE_SHOULD_BE_POSSIBLY_CHANGED);
info = builder.createUnconditionally();
final ArrayList<IntentionAction> options = new ArrayList<IntentionAction>();
options.add(new DismissNewSignatureIntentionAction());
QuickFixAction.registerQuickFixAction(info, new ChangeSignatureDetectorAction(), options, null);
}
Collection<HighlightInfo> infos = info != null ? Collections.singletonList(info) : Collections.<HighlightInfo>emptyList();
UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, 0, myFile.getTextLength(), infos, getColorsScheme(), getId());
}
示例5: registerPriorityActions
import com.intellij.codeInsight.intention.IntentionAction; //導入依賴的package包/類
private static void registerPriorityActions(@NotNull QuickFixActionRegistrar registrar,
@NotNull TextRange fixRange,
@NotNull PsiReferenceExpression refExpr) {
final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(refExpr.getProject());
final Map<VariableKind, IntentionAction> map = new EnumMap<VariableKind, IntentionAction>(VariableKind.class);
map.put(VariableKind.FIELD, new CreateFieldFromUsageFix(refExpr));
map.put(VariableKind.STATIC_FINAL_FIELD, new CreateConstantFieldFromUsageFix(refExpr));
if (!refExpr.isQualified()) {
map.put(VariableKind.LOCAL_VARIABLE, new CreateLocalFromUsageFix(refExpr));
map.put(VariableKind.PARAMETER, new CreateParameterFromUsageFix(refExpr));
}
final VariableKind kind = getKind(styleManager, refExpr);
if (map.containsKey(kind)) {
map.put(kind, PriorityIntentionActionWrapper.highPriority(map.get(kind)));
}
for (IntentionAction action : map.values()) {
registrar.register(fixRange, action, null);
}
}
示例6: registerFix
import com.intellij.codeInsight.intention.IntentionAction; //導入依賴的package包/類
public void registerFix(@Nullable IntentionAction action,
@Nullable List<IntentionAction> options,
@Nullable String displayName,
@Nullable TextRange fixRange,
@Nullable HighlightDisplayKey key) {
if (action == null) return;
if (fixRange == null) fixRange = new TextRange(startOffset, endOffset);
if (quickFixActionRanges == null) {
quickFixActionRanges = ContainerUtil.createLockFreeCopyOnWriteList();
}
IntentionActionDescriptor desc = new IntentionActionDescriptor(action, options, displayName, null, key, getProblemGroup(), getSeverity());
quickFixActionRanges.add(Pair.create(desc, fixRange));
fixStartOffset = Math.min (fixStartOffset, fixRange.getStartOffset());
fixEndOffset = Math.max (fixEndOffset, fixRange.getEndOffset());
if (action instanceof HintAction) {
setHint(true);
}
}
示例7: registerFixesForUnusedParameter
import com.intellij.codeInsight.intention.IntentionAction; //導入依賴的package包/類
@Override
public void registerFixesForUnusedParameter(@NotNull PsiParameter parameter, @NotNull Object highlightInfo) {
Project myProject = parameter.getProject();
InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getInspectionProfile();
UnusedParametersInspection unusedParametersInspection =
(UnusedParametersInspection)profile.getUnwrappedTool(UnusedSymbolLocalInspectionBase.UNUSED_PARAMETERS_SHORT_NAME, parameter);
LOG.assertTrue(ApplicationManager.getApplication().isUnitTestMode() || unusedParametersInspection != null);
List<IntentionAction> options = new ArrayList<IntentionAction>();
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));
}
示例8: addMessageWithFixes
import com.intellij.codeInsight.intention.IntentionAction; //導入依賴的package包/類
public static void addMessageWithFixes(final PsiElement context,
final String message,
@NotNull final Validator.ValidationHost.ErrorType type,
AnnotationHolder myHolder,
@NotNull final IntentionAction... fixes) {
if (message != null && !message.isEmpty()) {
if (context instanceof XmlTag) {
addMessagesForTag((XmlTag)context, message, type, myHolder, fixes);
}
else {
if (type == Validator.ValidationHost.ErrorType.ERROR) {
appendFixes(myHolder.createErrorAnnotation(context, message), fixes);
}
else {
appendFixes(myHolder.createWarningAnnotation(context, message), fixes);
}
}
}
}
示例9: testLowPriority
import com.intellij.codeInsight.intention.IntentionAction; //導入依賴的package包/類
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");
}
示例10: testInsertVisitLambda
import com.intellij.codeInsight.intention.IntentionAction; //導入依賴的package包/類
public void testInsertVisitLambda() {
myFixture.addClass("package com.intellij.psi;\n" +
"public interface PsiLambdaExpression{}");
myFixture.addClass("package com.intellij.psi;\n" +
"public abstract class JavaRecursiveElementVisitor{}");
myFixture.addClass("package com.intellij.psi;\n" +
"public interface PsiReturnStatement{}");
myFixture.addClass("package com.intellij.psi;\n" +
"public interface PsiClass{}");
myFixture.configureByText(JavaFileType.INSTANCE, "import com.intellij.psi.*;\n" +
"class Te<caret>st extends JavaRecursiveElementVisitor {\n" +
" public void visitReturnStatement(PsiReturnStatement statement) {}\n" +
" public void visitClass(PsiClass aClass) {}\n" +
"}");
IntentionAction intention = myFixture.findSingleIntention("Insert visitLambdaExpression method");
myFixture.launchAction(intention);
myFixture.checkResult("import com.intellij.psi.*;\n" +
"class Test extends JavaRecursiveElementVisitor {\n" +
" public void visitReturnStatement(PsiReturnStatement statement) {}\n" +
" public void visitClass(PsiClass aClass) {}\n" +
"\n" +
" public void visitLambdaExpression(PsiLambdaExpression expression) {\n" +
" }\n" +
"}");
}
示例11: getVariableContext
import com.intellij.codeInsight.intention.IntentionAction; //導入依賴的package包/類
@Override
@NotNull
public VariableContext getVariableContext() {
return new XsltVariableContext() {
@Override
@Nullable
protected XmlTag getContextTagImpl(XPathElement element) {
return PsiTreeUtil.getParentOfType(getContextElement(), XmlTag.class, false);
}
@Override
@NotNull
public IntentionAction[] getUnresolvedVariableFixes(XPathVariableReference reference) {
return IntentionAction.EMPTY_ARRAY;
}
};
}
示例12: quickFixesTest
import com.intellij.codeInsight.intention.IntentionAction; //導入依賴的package包/類
public void quickFixesTest(final String testFile) {
for (final IntentionAction quickFix : fixture.getAllQuickFixes()) {
fixture.launchAction(quickFix);
}
fixture.setTestDataPath(".");
final String fixedFilePath = testFile.substring(0, testFile.length() - 4) + ".fixed.php";
fixture.checkResultByFile(fixedFilePath);
}
示例13: assertIntentionIsAvailable
import com.intellij.codeInsight.intention.IntentionAction; //導入依賴的package包/類
public void assertIntentionIsAvailable(LanguageFileType languageFileType, String configureByText, String intentionText) {
myFixture.configureByText(languageFileType, configureByText);
PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
for (IntentionAction intentionAction : IntentionManager.getInstance().getIntentionActions()) {
if(intentionAction.isAvailable(getProject(), getEditor(), psiElement.getContainingFile()) && intentionAction.getText().equals(intentionText)) {
return;
}
}
fail(String.format("Fail intention action '%s' is available in element '%s'", intentionText, psiElement.getText()));
}
示例14: doTestIntention
import com.intellij.codeInsight.intention.IntentionAction; //導入依賴的package包/類
protected void doTestIntention(String testName, String hint) throws Throwable {
myFixture.configureByFile(testName + "/before.csv");
final IntentionAction action = myFixture.filterAvailableIntentions(hint).stream()
.filter(intentionAction -> intentionAction.getText().equals(hint))
.findFirst().get();
myFixture.launchAction(action);
myFixture.checkResultByFile(testName + "/after.csv");
}
示例15: doTestIntention
import com.intellij.codeInsight.intention.IntentionAction; //導入依賴的package包/類
protected void doTestIntention(String testName, String hint) throws Throwable {
myFixture.configureByFile(testName + "/before.csv");
final IntentionAction action = myFixture.filterAvailableIntentions(hint).stream()
.filter(intentionAction -> intentionAction.getText().equals(hint))
.findFirst().get();
myFixture.launchAction(action);
myFixture.checkResultByFile(testName + "/after.csv");
}