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


Java AnnotateFix.canApply方法代码示例

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


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

示例1: 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.canApply方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。