本文整理匯總了Java中com.intellij.codeInsight.intention.IntentionAction.invoke方法的典型用法代碼示例。如果您正苦於以下問題:Java IntentionAction.invoke方法的具體用法?Java IntentionAction.invoke怎麽用?Java IntentionAction.invoke使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.codeInsight.intention.IntentionAction
的用法示例。
在下文中一共展示了IntentionAction.invoke方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doAction
import com.intellij.codeInsight.intention.IntentionAction; //導入方法依賴的package包/類
@Override
protected void doAction(final String text, final boolean actionShouldBeAvailable, final String testFullPath, final String testName)
throws Exception {
boolean old = CodeInsightSettings.getInstance().OPTIMIZE_IMPORTS_ON_THE_FLY;
try {
CodeInsightSettings.getInstance().OPTIMIZE_IMPORTS_ON_THE_FLY = false;
IntentionAction action = findActionWithText(text);
if (action == null && actionShouldBeAvailable) {
fail("Action with text '" + text + "' is not available in test " + testFullPath);
}
if (action != null && actionShouldBeAvailable) {
action.invoke(getProject(), getEditor(), getFile());
assertTrue(CodeInsightSettings.getInstance().OPTIMIZE_IMPORTS_ON_THE_FLY);
}
}
finally {
CodeInsightSettings.getInstance().OPTIMIZE_IMPORTS_ON_THE_FLY = old;
}
}
示例2: 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);
}
}
}
示例3: isAvailable
import com.intellij.codeInsight.intention.IntentionAction; //導入方法依賴的package包/類
public static boolean isAvailable(PsiFile file) {
final Project project = file.getProject();
final String title = CodeInsightBundle.message("i18nize.dialog.error.jdk.title");
try {
return ResourceBundleManager.getManager(file) != null;
}
catch (ResourceBundleManager.ResourceBundleNotFoundException e) {
final IntentionAction fix = e.getFix();
if (fix != null) {
if (Messages.showOkCancelDialog(project, e.getMessage(), title, Messages.getErrorIcon()) == Messages.OK) {
try {
fix.invoke(project, null, file);
return false;
}
catch (IncorrectOperationException e1) {
LOG.error(e1);
}
}
}
Messages.showErrorDialog(project, e.getMessage(), title);
return false;
}
}
示例4: createConstructor
import com.intellij.codeInsight.intention.IntentionAction; //導入方法依賴的package包/類
@NotNull
private static Collection<PsiMethod> createConstructor(@NotNull Project project,
@NotNull Editor editor,
PsiFile file,
@NotNull PsiClass aClass) {
final IntentionAction addDefaultConstructorFix = QuickFixFactory.getInstance().createAddDefaultConstructorFix(aClass);
final int offset = editor.getCaretModel().getOffset();
addDefaultConstructorFix.invoke(project, editor, file);
editor.getCaretModel().moveToOffset(offset); //restore caret
return Arrays.asList(aClass.getConstructors());
}
示例5: convertToFix
import com.intellij.codeInsight.intention.IntentionAction; //導入方法依賴的package包/類
@Override
@NotNull
public LocalQuickFix convertToFix(@NotNull final IntentionAction action) {
if (action instanceof LocalQuickFix) {
return (LocalQuickFix)action;
}
return new LocalQuickFix() {
@Override
@NotNull
public String getName() {
return action.getText();
}
@Override
@NotNull
public String getFamilyName() {
return action.getFamilyName();
}
@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
final PsiFile psiFile = descriptor.getPsiElement().getContainingFile();
try {
action.invoke(project, new LazyEditor(psiFile), psiFile);
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
}
};
}
示例6: testFetchDtd
import com.intellij.codeInsight.intention.IntentionAction; //導入方法依賴的package包/類
public void testFetchDtd() throws Exception {
final String url = "http://helpserver.labs.intellij.net/help/images.dtd";
assertEquals(url, ExternalResourceManager.getInstance().getResourceLocation(url, getProject()));
myFixture.configureByText(XmlFileType.INSTANCE, "<!DOCTYPE images SYSTEM \"http://helpserver.labs.intellij.net/help/ima<caret>ges.dtd\">");
IntentionAction intention = myFixture.getAvailableIntention(XmlBundle.message("fetch.external.resource"));
assertNotNull(intention);
intention.invoke(getProject(), myFixture.getEditor(), myFixture.getFile());
assertNotSame(url, ExternalResourceManager.getInstance().getResourceLocation(url, getProject()));
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
ExternalResourceManager.getInstance().removeResource(url);
}
});
}
示例7: testAddDependency
import com.intellij.codeInsight.intention.IntentionAction; //導入方法依賴的package包/類
public void testAddDependency() throws IOException {
VirtualFile f = createProjectSubFile("src/main/java/A.java", "import org.apache.commons.io.IOUtils;\n" +
"\n" +
"public class Aaa {\n" +
"\n" +
" public void xxx() {\n" +
" IOUtil<caret>s u;\n" +
" }\n" +
"\n" +
"}");
importProject("<groupId>test</groupId>" +
"<artifactId>project</artifactId>" +
"<version>1</version>");
myFixture.configureFromExistingVirtualFile(f);
IntentionAction intentionAction = findAddMavenIntention();
MavenArtifactSearchDialog.ourResultForTest = Collections.singletonList(new MavenId("commons-io", "commons-io", "2.4"));
intentionAction.invoke(myProject, myFixture.getEditor(), myFixture.getFile());
String pomText = PsiManager.getInstance(myProject).findFile(myProjectPom).getText();
assertTrue(pomText.matches(
"(?s).*<dependency>\\s*<groupId>commons-io</groupId>\\s*<artifactId>commons-io</artifactId>\\s*<version>2.4</version>\\s*</dependency>.*"));
}
示例8: testAddDependencyInTest
import com.intellij.codeInsight.intention.IntentionAction; //導入方法依賴的package包/類
public void testAddDependencyInTest() throws IOException {
VirtualFile f = createProjectSubFile("src/test/java/A.java", "import org.apache.commons.io.IOUtils;\n" +
"\n" +
"public class Aaa {\n" +
"\n" +
" public void xxx() {\n" +
" IOUtil<caret>s u;\n" +
" }\n" +
"\n" +
"}");
importProject("<groupId>test</groupId>" +
"<artifactId>project</artifactId>" +
"<version>1</version>");
myFixture.configureFromExistingVirtualFile(f);
IntentionAction intentionAction = findAddMavenIntention();
MavenArtifactSearchDialog.ourResultForTest = Collections.singletonList(new MavenId("commons-io", "commons-io", "2.4"));
intentionAction.invoke(myProject, myFixture.getEditor(), myFixture.getFile());
String pomText = PsiManager.getInstance(myProject).findFile(myProjectPom).getText();
assertTrue(pomText.matches(
"(?s).*<dependency>\\s*<groupId>commons-io</groupId>\\s*<artifactId>commons-io</artifactId>\\s*<version>2.4</version>\\s*<scope>test</scope>\\s*</dependency>.*"));
}
示例9: getOrCreateConstructors
import com.intellij.codeInsight.intention.IntentionAction; //導入方法依賴的package包/類
@NotNull
private static Collection<PsiMethod> getOrCreateConstructors(@NotNull PsiClass aClass) {
PsiMethod[] constructors = aClass.getConstructors();
if (constructors.length == 0) {
final IntentionAction addDefaultConstructorFix = QuickFixFactory.getInstance().createAddDefaultConstructorFix(aClass);
addDefaultConstructorFix.invoke(aClass.getProject(), null, aClass.getContainingFile());
}
constructors = aClass.getConstructors();
return removeChainedConstructors(ContainerUtil.newArrayList(constructors));
}
示例10: chooseActionAndInvoke
import com.intellij.codeInsight.intention.IntentionAction; //導入方法依賴的package包/類
public static boolean chooseActionAndInvoke(@NotNull PsiFile hostFile,
@NotNull final Editor hostEditor,
@NotNull final IntentionAction action,
@NotNull String text) {
if (!hostFile.isValid()) return false;
final Project project = hostFile.getProject();
FeatureUsageTracker.getInstance().triggerFeatureUsed("codeassists.quickFix");
((FeatureUsageTrackerImpl)FeatureUsageTracker.getInstance()).getFixesStats().registerInvocation();
Pair<PsiFile, Editor> pair = chooseBetweenHostAndInjected(hostFile, hostEditor, new PairProcessor<PsiFile, Editor>() {
@Override
public boolean process(PsiFile psiFile, Editor editor) {
return availableFor(psiFile, editor, action);
}
});
if (pair == null) return false;
final Editor editorToApply = pair.second;
final PsiFile fileToApply = pair.first;
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
action.invoke(project, editorToApply, fileToApply);
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
DaemonCodeAnalyzer.getInstance(project).updateVisibleHighlighters(hostEditor);
}
};
if (action.startInWriteAction()) {
final Runnable _runnable = runnable;
runnable = new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().runWriteAction(_runnable);
}
};
}
CommandProcessor.getInstance().executeCommand(project, runnable, text, null);
return true;
}