當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。