Java Code Examples for com.intellij.lang.surroundWith.Surrounder#isApplicable()
The following examples show how to use
com.intellij.lang.surroundWith.Surrounder#isApplicable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PostfixTemplatesUtils.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public static TextRange surround(@Nonnull Surrounder surrounder, @Nonnull Editor editor, @Nonnull PsiElement expr) { Project project = expr.getProject(); PsiElement[] elements = {expr}; if (surrounder.isApplicable(elements)) { return surrounder.surroundElements(project, editor, elements); } else { showErrorHint(project, editor); } return null; }
Example 2
Source File: SurroundWithHandler.java From consulo with Apache License 2.0 | 4 votes |
@Nullable private static List<AnAction> doBuildSurroundActions(Project project, Editor editor, PsiFile file, Map<Surrounder, PsiElement[]> surrounders) { final List<AnAction> applicable = new ArrayList<AnAction>(); boolean hasEnabledSurrounders = false; Set<Character> usedMnemonicsSet = new HashSet<Character>(); int index = 0; for (Map.Entry<Surrounder, PsiElement[]> entry : surrounders.entrySet()) { Surrounder surrounder = entry.getKey(); PsiElement[] elements = entry.getValue(); if (surrounder.isApplicable(elements)) { char mnemonic; if (index < 9) { mnemonic = (char)('0' + index + 1); } else if (index == 9) { mnemonic = '0'; } else { mnemonic = (char)('A' + index - 10); } index++; usedMnemonicsSet.add(Character.toUpperCase(mnemonic)); applicable.add(new InvokeSurrounderAction(surrounder, project, editor, elements, mnemonic)); hasEnabledSurrounders = true; } } List<CustomLiveTemplate> customTemplates = TemplateManagerImpl.listApplicableCustomTemplates(editor, file, true); List<TemplateImpl> templates = TemplateManagerImpl.listApplicableTemplateWithInsertingDummyIdentifier(editor, file, true); if (!templates.isEmpty() || !customTemplates.isEmpty()) { applicable.add(new AnSeparator("Live templates")); } for (TemplateImpl template : templates) { applicable.add(new InvokeTemplateAction(template, editor, project, usedMnemonicsSet)); hasEnabledSurrounders = true; } for (CustomLiveTemplate customTemplate : customTemplates) { applicable.add(new WrapWithCustomTemplateAction(customTemplate, editor, file, usedMnemonicsSet)); hasEnabledSurrounders = true; } if (!templates.isEmpty() || !customTemplates.isEmpty()) { applicable.add(AnSeparator.getInstance()); applicable.add(new ConfigureTemplatesAction()); } return hasEnabledSurrounders ? applicable : null; }