本文整理匯總了Java中com.intellij.codeInsight.intention.IntentionAction.isAvailable方法的典型用法代碼示例。如果您正苦於以下問題:Java IntentionAction.isAvailable方法的具體用法?Java IntentionAction.isAvailable怎麽用?Java IntentionAction.isAvailable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.codeInsight.intention.IntentionAction
的用法示例。
在下文中一共展示了IntentionAction.isAvailable方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: findIntentionAction
import com.intellij.codeInsight.intention.IntentionAction; //導入方法依賴的package包/類
protected static IntentionAction findIntentionAction(@NotNull Collection<HighlightInfo> infos, @NotNull String intentionActionName, @NotNull Editor editor,
@NotNull PsiFile file) {
List<IntentionAction> actions = LightQuickFixTestCase.getAvailableActions(editor, file);
IntentionAction intentionAction = LightQuickFixTestCase.findActionWithText(actions, intentionActionName);
if (intentionAction == null) {
final List<IntentionAction> availableActions = new ArrayList<IntentionAction>();
for (HighlightInfo info :infos) {
if (info.quickFixActionRanges != null) {
for (Pair<HighlightInfo.IntentionActionDescriptor, TextRange> pair : info.quickFixActionRanges) {
IntentionAction action = pair.first.getAction();
if (action.isAvailable(file.getProject(), editor, file)) availableActions.add(action);
}
}
}
intentionAction = LightQuickFixTestCase.findActionWithText(
availableActions,
intentionActionName
);
}
return intentionAction;
}
示例3: createActionGroupPopup
import com.intellij.codeInsight.intention.IntentionAction; //導入方法依賴的package包/類
@Nullable
protected JBPopup createActionGroupPopup(PsiFile file, Project project, Editor editor) {
final DefaultActionGroup group = new DefaultActionGroup();
for (final IntentionAction action : IntentionManager.getInstance().getAvailableIntentionActions()) {
if (shouldShowInGutterPopup(action) && action.isAvailable(project, editor, file)) {
group.add(new ApplyIntentionAction(action, action.getText(), editor, file));
}
}
if (group.getChildrenCount() > 0) {
final DataContext context = SimpleDataContext.getProjectContext(null);
return JBPopupFactory.getInstance()
.createActionGroupPopup(null, group, context, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, true);
}
return null;
}
示例4: isAvailableHere
import com.intellij.codeInsight.intention.IntentionAction; //導入方法依賴的package包/類
private static boolean isAvailableHere(Editor editor, PsiFile psiFile, PsiElement psiElement, boolean inProject, IntentionAction action) {
try {
Project project = psiFile.getProject();
if (action instanceof SuppressIntentionActionFromFix) {
final ThreeState shouldBeAppliedToInjectionHost = ((SuppressIntentionActionFromFix)action).isShouldBeAppliedToInjectionHost();
if (editor instanceof EditorWindow && shouldBeAppliedToInjectionHost == ThreeState.YES) {
return false;
}
if (!(editor instanceof EditorWindow) && shouldBeAppliedToInjectionHost == ThreeState.NO) {
return false;
}
}
if (action instanceof PsiElementBaseIntentionAction) {
if (!inProject || psiElement == null || !((PsiElementBaseIntentionAction)action).isAvailable(project, editor, psiElement)) return false;
}
else if (!action.isAvailable(project, editor, psiFile)) {
return false;
}
}
catch (IndexNotReadyException e) {
return false;
}
return true;
}
示例5: doApplyInformationToEditor
import com.intellij.codeInsight.intention.IntentionAction; //導入方法依賴的package包/類
@Override
public void doApplyInformationToEditor() {
if (myUnusedDeclarations == null || myUnusedImports == null) {
return;
}
AnnotationHolder annotationHolder = new AnnotationHolderImpl(new AnnotationSession(myFile));
List<HighlightInfo> infos = new ArrayList<HighlightInfo>(myUnusedDeclarations);
for (GrImportStatement unusedImport : myUnusedImports) {
Annotation annotation = annotationHolder.createWarningAnnotation(calculateRangeToUse(unusedImport), GroovyInspectionBundle.message("unused.import"));
annotation.setHighlightType(ProblemHighlightType.LIKE_UNUSED_SYMBOL);
annotation.registerFix(GroovyQuickFixFactory.getInstance().createOptimizeImportsFix(false));
infos.add(HighlightInfo.fromAnnotation(annotation));
}
UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, 0, myFile.getTextLength(), infos, getColorsScheme(), getId());
if (myUnusedImports != null && !myUnusedImports.isEmpty()) {
IntentionAction fix = GroovyQuickFixFactory.getInstance().createOptimizeImportsFix(true);
if (fix.isAvailable(myProject, myEditor, myFile) && myFile.isWritable()) {
fix.invoke(myProject, myEditor, myFile);
}
}
}
示例6: 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()));
}
示例7: showAddImportHint
import com.intellij.codeInsight.intention.IntentionAction; //導入方法依賴的package包/類
private boolean showAddImportHint(HighlightInfo info) {
if (!DaemonCodeAnalyzerSettings.getInstance().isImportHintEnabled()) return false;
if (!DaemonCodeAnalyzer.getInstance(myProject).isImportHintsEnabled(myFile)) return false;
PsiElement element = myFile.findElementAt(info.startOffset);
if (element == null || !element.isValid()) return false;
final List<Pair<HighlightInfo.IntentionActionDescriptor, TextRange>> list = info.quickFixActionRanges;
for (Pair<HighlightInfo.IntentionActionDescriptor, TextRange> pair : list) {
final IntentionAction action = pair.getFirst().getAction();
if (action instanceof HintAction && action.isAvailable(myProject, myEditor, myFile)) {
return ((HintAction)action).showHint(myEditor);
}
}
return false;
}
示例8: addActions
import com.intellij.codeInsight.intention.IntentionAction; //導入方法依賴的package包/類
private static void addActions(@NotNull Project project,
@NotNull Editor editor,
@NotNull PsiFile psiFile,
@Nullable AnAction action,
@NotNull List<HighlightInfo.IntentionActionDescriptor> descriptors,
@NotNull GutterIconRenderer renderer,
int order) {
if (action == null) {
return;
}
if (action instanceof ActionGroup) {
AnAction[] children = ((ActionGroup)action).getChildren(null);
for (int i = 0; i < children.length; i++) {
AnAction child = children[i];
addActions(project, editor, psiFile, child, descriptors, renderer, i + order);
}
}
Icon icon = action.getTemplatePresentation().getIcon();
if (icon == null) icon = renderer.getIcon();
if (icon.getIconWidth() < 16) icon = IconUtil.toSize(icon, 16, 16);
final IntentionAction gutterAction = new GutterIntentionAction(action, order, icon);
if (!gutterAction.isAvailable(project, editor, psiFile)) return;
HighlightInfo.IntentionActionDescriptor descriptor =
new HighlightInfo.IntentionActionDescriptor(gutterAction, Collections.<IntentionAction>emptyList(), null, icon) {
@Nullable
@Override
public String getDisplayName() {
return gutterAction.getText();
}
};
descriptors.add(descriptor);
}
示例9: wrapAction
import com.intellij.codeInsight.intention.IntentionAction; //導入方法依賴的package包/類
@NotNull
IntentionActionWithTextCaching wrapAction(@NotNull HighlightInfo.IntentionActionDescriptor descriptor,
@NotNull PsiElement element,
@NotNull PsiFile containingFile,
@NotNull Editor containingEditor) {
IntentionActionWithTextCaching cachedAction = new IntentionActionWithTextCaching(descriptor);
final List<IntentionAction> options = descriptor.getOptions(element, containingEditor);
if (options == null) return cachedAction;
for (IntentionAction option : options) {
if (!option.isAvailable(myProject, containingEditor, containingFile)) {
// if option is not applicable in injected fragment, check in host file context
if (containingEditor == myEditor || !option.isAvailable(myProject, myEditor, myFile)) {
continue;
}
}
IntentionActionWithTextCaching textCaching = new IntentionActionWithTextCaching(option);
boolean isErrorFix = myCachedErrorFixes.contains(textCaching);
if (isErrorFix) {
cachedAction.addErrorFix(option);
}
boolean isInspectionFix = myCachedInspectionFixes.contains(textCaching);
if (isInspectionFix) {
cachedAction.addInspectionFix(option);
}
else {
cachedAction.addIntention(option);
}
}
return cachedAction;
}