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


Java VisitorState.reportMatch方法代码示例

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


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

示例1: matchNewClass

import com.google.errorprone.VisitorState; //导入方法依赖的package包/类
@Override
public Description matchNewClass(NewClassTree tree, VisitorState state) {
  // check instantiations of `@ImmutableTypeParameter`s in generic constructor invocations
  checkInvocation(
      tree, ((JCNewClass) tree).constructorType, state, ((JCNewClass) tree).constructor);
  // check instantiations of `@ImmutableTypeParameter`s in class constructor invocations
  ImmutableAnalysis analysis = new ImmutableAnalysis(this, state, wellKnownMutability);
  Violation info =
      analysis.checkInstantiation(
          ASTHelpers.getSymbol(tree.getIdentifier()).getTypeParameters(),
          ASTHelpers.getType(tree).getTypeArguments());
  if (info.isPresent()) {
    state.reportMatch(buildDescription(tree).setMessage(info.message()).build());
  }
  return NO_MATCH;
}
 
开发者ID:google,项目名称:error-prone,代码行数:17,代码来源:ImmutableChecker.java

示例2: matchSynchronized

import com.google.errorprone.VisitorState; //导入方法依赖的package包/类
@Override
public Description matchSynchronized(SynchronizedTree tree, VisitorState state) {
  Symbol lock = ASTHelpers.getSymbol(stripParentheses(tree.getExpression()));
  if (!(lock instanceof VarSymbol)) {
    return Description.NO_MATCH;
  }
  if (lock.isStatic()) {
    return Description.NO_MATCH;
  }
  Multimap<VarSymbol, Tree> writes = WriteVisitor.scan(tree.getBlock());
  for (Entry<VarSymbol, Tree> write : writes.entries()) {
    if (!write.getKey().isStatic()) {
      continue;
    }
    state.reportMatch(
        buildDescription(write.getValue()).setMessage(String.format(MESSAGE, lock)).build());
  }
  return Description.NO_MATCH;
}
 
开发者ID:google,项目名称:error-prone,代码行数:20,代码来源:StaticGuardedByInstance.java

示例3: reportAnyViolations

import com.google.errorprone.VisitorState; //导入方法依赖的package包/类
private void reportAnyViolations(
    List<? extends ExpressionTree> arguments,
    List<RequiredType> requiredArgumentTypes,
    VisitorState state) {
  Types types = state.getTypes();
  for (int i = 0; i < requiredArgumentTypes.size(); i++) {
    RequiredType requiredType = requiredArgumentTypes.get(i);
    if (requiredType == null) {
      continue;
    }
    ExpressionTree argument = arguments.get(i);
    Type argType = ASTHelpers.getType(argument);
    if (requiredType.type() != null) {
      // Report a violation for this type
      EqualsIncompatibleType.TypeCompatibilityReport report =
          EqualsIncompatibleType.compatibilityOfTypes(requiredType.type(), argType, state);
      if (!report.compatible()) {
        state.reportMatch(describeViolation(argument, argType, requiredType.type(), types));
      }
    }
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:23,代码来源:IncompatibleArgumentType.java

示例4: reportMatch

import com.google.errorprone.VisitorState; //导入方法依赖的package包/类
protected <T extends Tree> void reportMatch(
    Description description, T match, VisitorState state) {
  if (description == null || description == Description.NO_MATCH) {
    return;
  }
  state.reportMatch(description);
}
 
开发者ID:google,项目名称:error-prone,代码行数:8,代码来源:Scanner.java

示例5: checkDeclarations

import com.google.errorprone.VisitorState; //导入方法依赖的package包/类
private Description checkDeclarations(List<? extends Tree> children, VisitorState state) {
  PeekingIterator<Tree> it = Iterators.<Tree>peekingIterator(children.iterator());
  while (it.hasNext()) {
    if (it.peek().getKind() != Tree.Kind.VARIABLE) {
      it.next();
      continue;
    }
    VariableTree variableTree = (VariableTree) it.next();
    ArrayList<VariableTree> fragments = new ArrayList<>();
    fragments.add(variableTree);
    // Javac handles multi-variable declarations by lowering them in the parser into a series of
    // individual declarations, all of which have the same start position. We search for the first
    // declaration in the group, which is either the first variable declared in this scope or has
    // a distinct end position from the previous declaration.
    while (it.hasNext()
        && it.peek().getKind() == Tree.Kind.VARIABLE
        && ((JCTree) variableTree).getStartPosition()
            == ((JCTree) it.peek()).getStartPosition()) {
      fragments.add((VariableTree) it.next());
    }
    if (fragments.size() == 1) {
      continue;
    }
    Fix fix =
        SuggestedFix.replace(
            ((JCTree) fragments.get(0)).getStartPosition(),
            state.getEndPosition(Iterables.getLast(fragments)),
            Joiner.on("; ").join(fragments) + ";");
    state.reportMatch(describeMatch(fragments.get(0), fix));
  }
  return NO_MATCH;
}
 
开发者ID:google,项目名称:error-prone,代码行数:33,代码来源:MultiVariableDeclaration.java

示例6: checkForHiddenFields

import com.google.errorprone.VisitorState; //导入方法依赖的package包/类
private void checkForHiddenFields(
    List<VariableTree> originalClassMembers,
    Map<Name, VarSymbol> parentMembers,
    Name parentClassName,
    ClassTree classTree,
    VisitorState visitorState) {
  Iterator<VariableTree> origVariableIterator = originalClassMembers.iterator();
  VariableTree origVariable = null;

  while (origVariableIterator.hasNext()) {
    origVariable = origVariableIterator.next();

    if (parentMembers.containsKey(origVariable.getName())) {
      if (isPackagePrivateAndInDiffPackage(
          parentMembers.get(origVariable.getName()), classTree)) {
        continue;
      }

      Builder matchDesc = buildDescription(origVariable);

      matchDesc.setMessage(
          "Hiding fields of superclasses may cause confusion and errors. "
              + "This field is hiding a field of the same name in superclass: "
              + parentClassName);

      visitorState.reportMatch(matchDesc.build());
      origVariableIterator.remove();
    }
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:31,代码来源:HidingField.java

示例7: checkParameter

import com.google.errorprone.VisitorState; //导入方法依赖的package包/类
private void checkParameter(
    VarSymbol paramSym,
    ExpressionTree a,
    int start,
    Deque<ErrorProneToken> tokens,
    VisitorState state) {
  if (a.getKind() != Kind.BOOLEAN_LITERAL) {
    return;
  }
  String name = paramSym.getSimpleName().toString();
  if (name.length() < 2) {
    // single-character parameter names aren't helpful
    return;
  }
  if (BLACKLIST.contains(name)) {
    return;
  }
  while (!tokens.isEmpty()
      && ((start + tokens.peekFirst().pos()) < ((JCTree) a).getStartPosition())) {
    tokens.removeFirst();
  }
  if (tokens.isEmpty()) {
    return;
  }
  Range<Integer> argRange =
      Range.closedOpen(((JCTree) a).getStartPosition(), state.getEndPosition(a));
  if (!argRange.contains(start + tokens.peekFirst().pos())) {
    return;
  }
  if (hasParameterComment(tokens.removeFirst())) {
    return;
  }
  state.reportMatch(
      describeMatch(
          a, SuggestedFix.prefixWith(a, String.format("/* %s= */", paramSym.getSimpleName()))));
}
 
开发者ID:google,项目名称:error-prone,代码行数:37,代码来源:BooleanParameter.java

示例8: checkInvocation

import com.google.errorprone.VisitorState; //导入方法依赖的package包/类
private Description checkInvocation(
    Tree tree, Type methodType, VisitorState state, Symbol symbol) {
  ImmutableAnalysis analysis = new ImmutableAnalysis(this, state, wellKnownMutability);
  Violation info = analysis.checkInvocation(methodType, symbol);
  if (info.isPresent()) {
    state.reportMatch(buildDescription(tree).setMessage(info.message()).build());
  }
  return NO_MATCH;
}
 
开发者ID:google,项目名称:error-prone,代码行数:10,代码来源:ImmutableChecker.java

示例9: matchClass

import com.google.errorprone.VisitorState; //导入方法依赖的package包/类
@Override
public Description matchClass(ClassTree tree, VisitorState state) {
  ClassSymbol symbol = getSymbol(tree);
  if (symbol == null || !symbol.isEnum()) {
    return NO_MATCH;
  }

  if (ASTHelpers.hasAnnotation(symbol, Immutable.class, state)
      && !implementsImmutableInterface(symbol)) {
    AnnotationTree annotation =
        ASTHelpers.getAnnotationWithSimpleName(tree.getModifiers().getAnnotations(), "Immutable");
    if (annotation != null) {
      state.reportMatch(
          buildDescription(annotation)
              .setMessage(ANNOTATED_ENUM_MESSAGE)
              .addFix(SuggestedFix.delete(annotation))
              .build());
    } else {
      state.reportMatch(buildDescription(tree).setMessage(ANNOTATED_ENUM_MESSAGE).build());
    }
  }

  Violation info =
      new ImmutableAnalysis(
              this,
              state,
              wellKnownMutability,
              ImmutableSet.of(
                  Immutable.class.getName(),
                  javax.annotation.concurrent.Immutable.class.getName()))
          .checkForImmutability(
              Optional.of(tree), ImmutableSet.of(), getType(tree), this::describe);

  if (!info.isPresent()) {
    return NO_MATCH;
  }

  return describe(tree, info).build();
}
 
开发者ID:google,项目名称:error-prone,代码行数:40,代码来源:ImmutableEnumChecker.java

示例10: processGroupMethods

import com.google.errorprone.VisitorState; //导入方法依赖的package包/类
private void processGroupMethods(List<MethodTree> groupMethodTrees, VisitorState state) {
  Preconditions.checkArgument(!groupMethodTrees.isEmpty());
  for (ParameterOrderingViolation violation : getViolations(groupMethodTrees)) {
    MethodSymbol methodSymbol = getSymbol(violation.methodTree());
    if (ASTHelpers.findSuperMethods(methodSymbol, state.getTypes()).isEmpty()) {
      Description.Builder description = buildDescription(violation.methodTree());
      description.setMessage(violation.getDescription());
      state.reportMatch(description.build());
    }
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:12,代码来源:InconsistentOverloads.java

示例11: checkArgument

import com.google.errorprone.VisitorState; //导入方法依赖的package包/类
private void checkArgument(
    VarSymbol formal,
    ExpressionTree actual,
    int start,
    ErrorProneToken token,
    VisitorState state) {
  List<Comment> matches = new ArrayList<>();
  for (Comment comment : token.comments()) {
    if (comment.getStyle() != BLOCK) {
      continue;
    }
    Matcher m =
        NamedParameterComment.PARAMETER_COMMENT_PATTERN.matcher(
            Comments.getTextFromComment(comment));
    if (!m.matches()) {
      continue;
    }
    String name = m.group(1);
    if (formal.getSimpleName().contentEquals(name)) {
      // If there are multiple comments, bail if any one of them is an exact match.
      return;
    }
    matches.add(comment);
  }
  for (Comment match : matches) {
    state.reportMatch(
        buildDescription(actual)
            .setMessage(
                String.format(
                    "`%s` does not match formal parameter name `%s`",
                    match.getText(), formal.getSimpleName()))
            .addFix(
                SuggestedFix.replace(
                    start + match.getSourcePos(0),
                    start + match.getSourcePos(match.getText().length() - 1) + 1,
                    String.format("/* %s= */", formal.getSimpleName())))
            .build());
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:40,代码来源:ParameterName.java

示例12: checkForThis

import com.google.errorprone.VisitorState; //导入方法依赖的package包/类
private void checkForThis(
    ExpressionTree node, Name identifier, ClassSymbol thisClass, VisitorState state) {
  if (identifier.contentEquals("this") && thisClass.equals(ASTHelpers.getSymbol(node).owner)) {
    state.reportMatch(describeMatch(node));
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:7,代码来源:ConstructorLeaksThis.java

示例13: reportMatch

import com.google.errorprone.VisitorState; //导入方法依赖的package包/类
private void reportMatch(
    Tree diagnosticPosition, VisitorState state, Tree toReplace, String replaceWith) {
  state.reportMatch(describeMatch(diagnosticPosition, replace(toReplace, replaceWith)));
}
 
开发者ID:google,项目名称:error-prone,代码行数:5,代码来源:ChainingConstructorIgnoresParameter.java

示例14: report

import com.google.errorprone.VisitorState; //导入方法依赖的package包/类
private void report(Description description, VisitorState state) {
  if (description == null || description == NO_MATCH) {
    return;
  }
  state.reportMatch(description);
}
 
开发者ID:google,项目名称:error-prone,代码行数:7,代码来源:GuardedByChecker.java

示例15: matchClass

import com.google.errorprone.VisitorState; //导入方法依赖的package包/类
@Override
public Description matchClass(ClassTree tree, VisitorState state) {
  ClassSymbol symbol = getSymbol(tree);
  if (symbol == null
      || symbol.isAnnotationType()
      || !WellKnownMutability.isAnnotation(state, symbol.type)) {
    return NO_MATCH;
  }
  if (!Collections.disjoint(getGeneratedBy(symbol, state), PROCESSOR_BLACKLIST)) {
    return NO_MATCH;
  }

  if (ASTHelpers.hasAnnotation(symbol, Immutable.class, state)) {
    AnnotationTree annotation =
        ASTHelpers.getAnnotationWithSimpleName(tree.getModifiers().getAnnotations(), "Immutable");
    if (annotation != null) {
      state.reportMatch(
          buildDescription(annotation)
              .setMessage(ANNOTATED_ANNOTATION_MESSAGE)
              .addFix(SuggestedFix.delete(annotation))
              .build());
    } else {
      state.reportMatch(buildDescription(tree).setMessage(ANNOTATED_ANNOTATION_MESSAGE).build());
    }
  }

  Violation info =
      new ImmutableAnalysis(
              this,
              state,
              wellKnownMutability,
              ImmutableSet.of(
                  Immutable.class.getName(),
                  javax.annotation.concurrent.Immutable.class.getName()))
          .checkForImmutability(
              Optional.of(tree), ImmutableSet.of(), getType(tree), this::describeClass);

  if (!info.isPresent()) {
    return NO_MATCH;
  }
  return describeClass(tree, info).build();
}
 
开发者ID:google,项目名称:error-prone,代码行数:43,代码来源:ImmutableAnnotationChecker.java


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