本文整理汇总了Java中com.intellij.codeInsight.intention.AddAnnotationFix类的典型用法代码示例。如果您正苦于以下问题:Java AddAnnotationFix类的具体用法?Java AddAnnotationFix怎么用?Java AddAnnotationFix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AddAnnotationFix类属于com.intellij.codeInsight.intention包,在下文中一共展示了AddAnnotationFix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isAvailable
import com.intellij.codeInsight.intention.AddAnnotationFix; //导入依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
if (!PsiUtil.isLanguageLevel5OrHigher(file)) return false;
if (!file.getManager().isInProject(file)) return false;
PsiMethod method = findMethod(file, editor.getCaretModel().getOffset());
if (method == null) return false;
if (method.getModifierList().findAnnotation(CommonClassNames.JAVA_LANG_OVERRIDE) != null) return false;
PsiMethod[] superMethods = method.findSuperMethods();
for (PsiMethod superMethod : superMethods) {
if (!superMethod.hasModifierProperty(PsiModifier.ABSTRACT)
&& new AddAnnotationFix(CommonClassNames.JAVA_LANG_OVERRIDE, method).isAvailable(project, editor, file)) {
return true;
}
}
return false;
}
示例2: addSuppressAnnotation
import com.intellij.codeInsight.intention.AddAnnotationFix; //导入依赖的package包/类
private static void addSuppressAnnotation(final Project project,
final PsiElement container,
final PsiModifierListOwner modifierOwner,
final String id) throws IncorrectOperationException {
PsiAnnotation annotation = AnnotationUtil.findAnnotation(modifierOwner, FQCN_SUPPRESS_LINT);
final PsiAnnotation newAnnotation = createNewAnnotation(project, container, annotation, id);
if (newAnnotation != null) {
if (annotation != null && annotation.isPhysical()) {
annotation.replace(newAnnotation);
}
else {
final PsiNameValuePair[] attributes = newAnnotation.getParameterList().getAttributes();
//noinspection ConstantConditions
new AddAnnotationFix(FQCN_SUPPRESS_LINT, modifierOwner, attributes).invoke(project, null /*editor*/,
container.getContainingFile());
}
}
}
示例3: invoke
import com.intellij.codeInsight.intention.AddAnnotationFix; //导入依赖的package包/类
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
final PsiModifierListOwner modifierListOwner = getElement(editor, file);
if (modifierListOwner == null) throw new IncorrectOperationException();
BaseListPopupStep<Nls.Capitalization> step =
new BaseListPopupStep<Nls.Capitalization>(null, Nls.Capitalization.Title, Nls.Capitalization.Sentence) {
@Override
public PopupStep onChosen(final Nls.Capitalization selectedValue, boolean finalChoice) {
new WriteCommandAction.Simple(project) {
@Override
protected void run() throws Throwable {
String nls = Nls.class.getName();
PsiAnnotation annotation = JavaPsiFacade.getInstance(project).getElementFactory()
.createAnnotationFromText("@" + nls + "(capitalization = " +
nls + ".Capitalization." + selectedValue.toString() + ")", modifierListOwner);
new AddAnnotationFix(Nls.class.getName(), modifierListOwner, annotation.getParameterList().getAttributes()).applyFix();
}
}.execute();
return FINAL_CHOICE;
}
};
JBPopupFactory.getInstance().createListPopup(step).showInBestPositionFor(editor);
}
示例4: buildVisitor
import com.intellij.codeInsight.intention.AddAnnotationFix; //导入依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new JavaElementVisitor() {
@Override
public void visitField(PsiField field) {
super.visitField(field);
PsiModifierList modifierList = field.getModifierList();
if (modifierList != null) {
PsiAnnotation optional = modifierList.findAnnotation("butterknife.Optional");
if (optional != null) {
PsiAnnotation nullable = modifierList.findAnnotation("android.support.annotation.Nullable");
if (nullable == null) {
holder.registerProblem(optional, "Optional, but not @Nullable", new AddAnnotationFix("android.support.annotation.Nullable", field));
}
}
}
}
};
}
开发者ID:erikzielke,项目名称:butterknife_inspections,代码行数:21,代码来源:ButterKnifeOptionalNonNullableFieldInspection.java
示例5: isAvailable
import com.intellij.codeInsight.intention.AddAnnotationFix; //导入依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
if (!PsiUtil.isLanguageLevel5OrHigher(file)) return false;
if (!file.getManager().isInProject(file)) return false;
PsiMethod method = findMethod(file, editor.getCaretModel().getOffset());
if (method == null) return false;
if (method.getModifierList().findAnnotation(JAVA_LANG_OVERRIDE) != null) return false;
PsiMethod[] superMethods = method.findSuperMethods();
for (PsiMethod superMethod : superMethods) {
if (!superMethod.hasModifierProperty(PsiModifier.ABSTRACT)
&& new AddAnnotationFix(JAVA_LANG_OVERRIDE, method).isAvailable(project, editor, file)) {
return true;
}
}
return false;
}
示例6: invoke
import com.intellij.codeInsight.intention.AddAnnotationFix; //导入依赖的package包/类
private static void invoke(final Project project,
final PsiModifierListOwner element,
final String fqn, final String toRemove) {
WriteCommandAction.runWriteCommandAction(project, new Runnable() {
@Override
public void run() {
new AddAnnotationFix(fqn, element, toRemove).invoke(project, null, element.getContainingFile());
}
});
}
示例7: annotate
import com.intellij.codeInsight.intention.AddAnnotationFix; //导入依赖的package包/类
public static void annotate(@NotNull PsiMethod result, String fqn, String... annosToRemove) throws IncorrectOperationException {
Project project = result.getProject();
AddAnnotationFix fix = new AddAnnotationFix(fqn, result, annosToRemove);
if (fix.isAvailable(project, null, result.getContainingFile())) {
fix.invoke(project, null, result.getContainingFile());
}
}
示例8: invoke
import com.intellij.codeInsight.intention.AddAnnotationFix; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
PsiModifierListOwner owner = AddAnnotationPsiFix.getContainer(file, editor.getCaretModel().getOffset());
if (owner == null || !owner.isValid()) return;
Pair<String, String[]> annotations = getAnnotations(project);
String toAdd = annotations.first;
String[] toRemove = annotations.second;
AddAnnotationFix fix = new AddAnnotationFix(toAdd, owner, toRemove);
fix.invoke(project, editor, file);
}
示例9: invoke
import com.intellij.codeInsight.intention.AddAnnotationFix; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
PsiMethod method = findMethod(file, editor.getCaretModel().getOffset());
if (method != null) {
new AddAnnotationFix(CommonClassNames.JAVA_LANG_OVERRIDE, method).invoke(project, editor, file);
}
}
示例10: findOrCreateSetUpMethod
import com.intellij.codeInsight.intention.AddAnnotationFix; //导入依赖的package包/类
@Override
@Nullable
protected PsiMethod findOrCreateSetUpMethod(PsiClass clazz) throws IncorrectOperationException {
PsiMethod method = findSetUpMethod(clazz);
if (method != null) return method;
PsiManager manager = clazz.getManager();
PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
method = createSetUpPatternMethod(factory);
PsiMethod existingMethod = clazz.findMethodBySignature(method, false);
if (existingMethod != null) {
int exit = ApplicationManager.getApplication().isUnitTestMode() ?
Messages.OK :
Messages.showOkCancelDialog("Method setUp already exist but is not annotated as @Before. Annotate?",
CommonBundle.getWarningTitle(),
Messages.getWarningIcon());
if (exit == Messages.OK) {
new AddAnnotationFix(JUnitUtil.BEFORE_ANNOTATION_NAME, existingMethod).invoke(existingMethod.getProject(), null, existingMethod.getContainingFile());
return existingMethod;
}
}
final PsiMethod testMethod = JUnitUtil.findFirstTestMethod(clazz);
if (testMethod != null) {
method = (PsiMethod)clazz.addBefore(method, testMethod);
} else {
method = (PsiMethod)clazz.add(method);
}
JavaCodeStyleManager.getInstance(manager.getProject()).shortenClassReferences(method);
return method;
}
示例11: annotateNotNull
import com.intellij.codeInsight.intention.AddAnnotationFix; //导入依赖的package包/类
private void annotateNotNull(Project project,
NullableNotNullManager manager,
SmartPsiElementPointer<? extends PsiModifierListOwner> pointer) {
final PsiModifierListOwner element = pointer.getElement();
if (element != null) {
if (shouldIgnore(element)) return;
if (element instanceof PsiField && ((PsiField)element).hasInitializer() && element.hasModifierProperty(PsiModifier.FINAL)) return;
new AddAnnotationFix(manager.getDefaultNotNull(), element, manager.getDefaultNullable()).invoke(project, null,
element.getContainingFile());
}
}
示例12: annotateNullable
import com.intellij.codeInsight.intention.AddAnnotationFix; //导入依赖的package包/类
private void annotateNullable(Project project,
NullableNotNullManager manager,
SmartPsiElementPointer<? extends PsiModifierListOwner> pointer) {
final PsiModifierListOwner element = pointer.getElement();
if (element != null) {
if (shouldIgnore(element)) return;
new AddAnnotationFix(manager.getDefaultNullable(), element, manager.getDefaultNotNull()).invoke(project, null, element.getContainingFile());
}
}
示例13: invoke
import com.intellij.codeInsight.intention.AddAnnotationFix; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
CaretModel caretModel = editor.getCaretModel();
int position = caretModel.getOffset();
PsiElement element = file.findElementAt(position);
PsiModifierListOwner owner = AddAnnotationPsiFix.getContainer(element);
if (owner == null || !owner.isValid()) return;
Pair<String, String[]> annotations = getAnnotations(project);
String toAdd = annotations.first;
String[] toRemove = annotations.second;
AddAnnotationFix fix = new AddAnnotationFix(toAdd, owner, toRemove);
fix.invoke(project, editor, file);
}
示例14: invoke
import com.intellij.codeInsight.intention.AddAnnotationFix; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
PsiMethod method = findMethod(file, editor.getCaretModel().getOffset());
if (method != null) {
new AddAnnotationFix(JAVA_LANG_OVERRIDE, method).invoke(project, editor, file);
}
}
示例15: findOrCreateSetUpMethod
import com.intellij.codeInsight.intention.AddAnnotationFix; //导入依赖的package包/类
@Override
@Nullable
protected PsiMethod findOrCreateSetUpMethod(PsiClass clazz) throws IncorrectOperationException {
PsiMethod method = findSetUpMethod(clazz);
if (method != null) return method;
PsiManager manager = clazz.getManager();
PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
method = createSetUpPatternMethod(factory);
PsiMethod existingMethod = clazz.findMethodBySignature(method, false);
if (existingMethod != null) {
int exit = ApplicationManager.getApplication().isUnitTestMode() ?
DialogWrapper.OK_EXIT_CODE :
Messages.showOkCancelDialog("Method setUp already exist but is not annotated as @Before. Annotate?",
CommonBundle.getWarningTitle(),
Messages.getWarningIcon());
if (exit == DialogWrapper.OK_EXIT_CODE) {
new AddAnnotationFix(JUnitUtil.BEFORE_ANNOTATION_NAME, existingMethod).invoke(existingMethod.getProject(), null, existingMethod.getContainingFile());
return existingMethod;
}
}
final PsiMethod testMethod = JUnitUtil.findFirstTestMethod(clazz);
if (testMethod != null) {
method = (PsiMethod)clazz.addBefore(method, testMethod);
} else {
method = (PsiMethod)clazz.add(method);
}
JavaCodeStyleManager.getInstance(manager.getProject()).shortenClassReferences(method);
return method;
}