mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 06:05:01 +07:00
enable fix all for file for annotator problems, should work for localQuickFixes only (IDEA-87100)
This commit is contained in:
+7
@@ -0,0 +1,7 @@
|
||||
// "Fix all 'Annotator' problems" "true"
|
||||
public class Test {
|
||||
void fooF() {
|
||||
}
|
||||
|
||||
void barF(){}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Fix all 'Annotator' problems" "true"
|
||||
public class Test {
|
||||
void f<caret>oo() {
|
||||
}
|
||||
|
||||
void bar(){}
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* User: anna
|
||||
* Date: 17-Jun-2007
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.dataFlow.DataFlowInspection;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.LanguageAnnotators;
|
||||
import com.intellij.lang.annotation.Annotation;
|
||||
import com.intellij.lang.annotation.AnnotationHolder;
|
||||
import com.intellij.lang.annotation.Annotator;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.colors.CodeInsightColors;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FixAllAnnotatorQuickfixTest extends LightQuickFixTestCase {
|
||||
public void testAnnotator() throws Exception {
|
||||
Annotator annotator = new MyAnnotator();
|
||||
Language javaLanguage = StdFileTypes.JAVA.getLanguage();
|
||||
LanguageAnnotators.INSTANCE.addExplicitExtension(javaLanguage, annotator);
|
||||
enableInspectionTool(new DefaultHighlightVisitorBasedInspection.AnnotatorBasedInspection());
|
||||
try {
|
||||
doAllTests();
|
||||
}
|
||||
finally {
|
||||
LanguageAnnotators.INSTANCE.removeExplicitExtension(javaLanguage, annotator);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldBeAvailableAfterExecution() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNls
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/fixAllAnnotator";
|
||||
}
|
||||
|
||||
public static class MyAnnotator implements Annotator {
|
||||
@Override
|
||||
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
|
||||
if (element instanceof PsiMethod) {
|
||||
Annotation annotation = holder.createErrorAnnotation(((PsiMethod)element).getNameIdentifier(), null);
|
||||
annotation.registerFix(new MyFix());
|
||||
annotation.setTextAttributes(CodeInsightColors.DOC_COMMENT_TAG_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
static class MyFix implements IntentionAction, LocalQuickFix {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return "MyFix";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement element = descriptor.getPsiElement();
|
||||
if (element != null) {
|
||||
final PsiElement parent = element.getParent();
|
||||
if (parent instanceof PsiMethod) {
|
||||
((PsiMethod)parent).setName(((PsiMethod)parent).getName() + "F");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
fail();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user