• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java AddAnnotationFix类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.intellij.codeInsight.intention.AddAnnotationFix的典型用法代码示例。如果您正苦于以下问题:Java AddAnnotationFix类的具体用法?Java AddAnnotationFix怎么用?Java AddAnnotationFix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AddAnnotationFix类属于com.intellij.codeInsight.intention包,在下文中一共展示了AddAnnotationFix类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:AddOverrideAnnotationAction.java


示例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());
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:SuppressLintIntentionAction.java


示例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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:AnnotateCapitalizationIntention.java


示例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;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:18,代码来源:AddOverrideAnnotationAction.java


示例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());
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:NullityInferrer.java


示例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());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:OverrideImplementUtil.java


示例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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:AddAnnotationIntention.java


示例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);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:AddOverrideAnnotationAction.java


示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:JUnit4Framework.java


示例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());
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:12,代码来源:NullityInferrer.java


示例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());
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:10,代码来源:NullityInferrer.java


示例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);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:15,代码来源:AddAnnotationIntention.java


示例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);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:8,代码来源:AddOverrideAnnotationAction.java


示例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;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:33,代码来源:JUnit4Framework.java


示例16: createAddAnnotationQuickFix

import com.intellij.codeInsight.intention.AddAnnotationFix; //导入依赖的package包/类
public static LocalQuickFix createAddAnnotationQuickFix(@NotNull PsiClass psiClass, @NotNull String annotationFQN, @Nullable String annotationParam) {
  PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(psiClass.getProject());
  PsiAnnotation newAnnotation = elementFactory.createAnnotationFromText("@" + annotationFQN + "(" + StringUtil.notNullize(annotationParam) + ")", psiClass);
  final PsiNameValuePair[] attributes = newAnnotation.getParameterList().getAttributes();

  return new AddAnnotationFix(annotationFQN, psiClass, attributes);
}
 
开发者ID:mplushnikov,项目名称:lombok-intellij-plugin,代码行数:8,代码来源:PsiQuickFixFactory.java


示例17: 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());
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:10,代码来源:OverrideImplementUtil.java


示例18: 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);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:15,代码来源:AddAnnotationIntention.java


示例19: buildFix

import com.intellij.codeInsight.intention.AddAnnotationFix; //导入依赖的package包/类
@Override
protected InspectionGadgetsFix buildFix(Object... infos) {
  final Object info = infos[0];
  if (!(info instanceof PsiReferenceExpression)) {
    return null;
  }
  final PsiElement target = ((PsiReferenceExpression)info).resolve();
  if (!(target instanceof PsiVariable)) {
    return null;
  }
  final NullableNotNullManager manager = NullableNotNullManager.getInstance(target.getProject());
  return new DelegatingFix(new AddAnnotationFix(manager.getDefaultNullable(), (PsiVariable)target));
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:14,代码来源:AssignmentToNullInspection.java


示例20: buildFix

import com.intellij.codeInsight.intention.AddAnnotationFix; //导入依赖的package包/类
@Override
@Nullable
protected InspectionGadgetsFix buildFix(Object... infos) {
  final PsiReferenceExpression methodExpression =
    (PsiReferenceExpression)infos[0];
  final PsiModifierListOwner annotatableQualifier =
    NonNlsUtils.getAnnotatableQualifier(
      methodExpression);
  if (annotatableQualifier == null) {
    return null;
  }
  return new DelegatingFix(new AddAnnotationFix(
    AnnotationUtil.NON_NLS, annotatableQualifier));
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:15,代码来源:StringToUpperWithoutLocaleInspection.java



注:本文中的com.intellij.codeInsight.intention.AddAnnotationFix类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Enchantment类代码示例发布时间:2022-05-22
下一篇:
Java GroupingSearch类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap