当前位置: 首页>>代码示例>>Java>>正文


Java AnnotateFix类代码示例

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


AnnotateFix类属于org.intellij.plugins.intelliLang.util包,在下文中一共展示了AnnotateFix类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildVisitor

import org.intellij.plugins.intelliLang.util.AnnotateFix; //导入依赖的package包/类
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
  return new JavaElementVisitor() {
    final Pair<String, ? extends Set<String>> annotationName = Configuration.getProjectInstance(holder.getProject()).getAdvancedConfiguration().getPatternAnnotationPair();

    @Override
    public void visitMethod(PsiMethod method) {
      final PsiIdentifier psiIdentifier = method.getNameIdentifier();
      if (psiIdentifier == null || !PsiUtilEx.isLanguageAnnotationTarget(method)) {
        return;
      }

      final PsiAnnotation[] annotationFrom = AnnotationUtilEx.getAnnotationFrom(method, annotationName, true, false);
      if (annotationFrom.length == 0) {
        final PsiAnnotation[] annotationFromHierarchy = AnnotationUtilEx.getAnnotationFrom(method, annotationName, true, true);
        if (annotationFromHierarchy.length > 0) {
          final String annotationClassname = annotationFromHierarchy[annotationFromHierarchy.length - 1].getQualifiedName();
          final String argList = annotationFromHierarchy[annotationFromHierarchy.length - 1].getParameterList().getText();
          holder.registerProblem(psiIdentifier, "Non-annotated Method overrides @Pattern Method",
                                 new AnnotateFix(method, annotationClassname, argList));
        }
      }
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:PatternOverriddenByNonAnnotatedMethod.java

示例2: checkExpression

import org.intellij.plugins.intelliLang.util.AnnotateFix; //导入依赖的package包/类
private void checkExpression(PsiExpression expression, ProblemsHolder holder, Pair<String, ? extends Set<String>> annotationName) {
  final PsiType type = expression.getType();
  if (type == null || !PsiUtilEx.isStringOrStringArray(type)) {
    return;
  }

  final PsiModifierListOwner contextOwner = AnnotationUtilEx.getAnnotatedElementFor(expression, AnnotationUtilEx.LookupType.CONTEXT_ONLY);
  if (contextOwner != null && PsiUtilEx.isLanguageAnnotationTarget(contextOwner)) {
    final PsiAnnotation[] annotations = AnnotationUtilEx.getAnnotationFrom(contextOwner, annotationName, true);
    if (annotations.length > 0) {
      final String expected = AnnotationUtilEx.calcAnnotationValue(annotations, "value");
      if (expected != null) {
        final PsiModifierListOwner declOwner =
            AnnotationUtilEx.getAnnotatedElementFor(expression, AnnotationUtilEx.LookupType.PREFER_DECLARATION);
        if (declOwner != null && PsiUtilEx.isLanguageAnnotationTarget(declOwner)) {
          final PsiAnnotation[] as = AnnotationUtilEx.getAnnotationFrom(declOwner, annotationName, true);
          if (as.length > 0) {
            final String actual = AnnotationUtilEx.calcAnnotationValue(as, "value");
            if (!expected.equals(actual)) {
              // language annotation values from context and declaration don't match
              holder.registerProblem(expression, "Language mismatch: Expected '" + expected + "', got '" + actual + "'");
            }
          }
          else if (CHECK_NON_ANNOTATED_REFERENCES) {
            final PsiElement var =
                PsiTreeUtil.getParentOfType(expression, PsiVariable.class, PsiExpressionList.class, PsiAssignmentExpression.class);
            // only nag about direct assignment or passing the reference as parameter
            if (var instanceof PsiVariable) {
              if (((PsiVariable)var).getInitializer() != expression) {
                return;
              }
            }
            else if (var instanceof PsiExpressionList) {
              final PsiExpressionList list = (PsiExpressionList)var;
              if (Arrays.asList(list.getExpressions()).indexOf(expression) == -1) {
                return;
              }
            }
            else if (var instanceof PsiAssignmentExpression) {
              final PsiAssignmentExpression a = (PsiAssignmentExpression)var;
              if (a.getRExpression() != expression) {
                return;
              }
            }
            // context implies language, but declaration isn't annotated
            final PsiAnnotation annotation = annotations[annotations.length - 1];
            final String initializer = annotation.getParameterList().getText();
            final AnnotateFix fix = new AnnotateFix(declOwner, annotation.getQualifiedName(), initializer) {
              @NotNull
              public String getName() {
                return initializer == null ? super.getName() : super.getName() + initializer;
              }
            };

            if (fix.canApply()) {
              holder.registerProblem(expression, "Language problem: Found non-annotated reference where '" + expected + "' is expected",
                                     fix);
            }
            else {
              holder.registerProblem(expression, "Language problem: Found non-annotated reference where '" + expected + "' is expected");
            }
          }
        }
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:68,代码来源:LanguageMismatch.java


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