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


Java Matcher类代码示例

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


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

示例1: overridesMethodOfClass

import com.google.errorprone.matchers.Matcher; //导入依赖的package包/类
private static Matcher<MethodTree> overridesMethodOfClass(final Class<?> clazz) {
  checkNotNull(clazz);
  return new Matcher<MethodTree>() {
    @Override
    public boolean matches(MethodTree tree, VisitorState state) {
      MethodSymbol symbol = getSymbol(tree);
      if (symbol == null) {
        return false;
      }
      for (MethodSymbol superMethod : findSuperMethods(symbol, state.getTypes())) {
        if (superMethod.owner != null
            && superMethod.owner.getQualifiedName().contentEquals(clazz.getName())) {
          return true;
        }
      }
      return false;
    }
  };
}
 
开发者ID:google,项目名称:error-prone,代码行数:20,代码来源:AbstractAsyncTypeReturnsNull.java

示例2: MatchType

import com.google.errorprone.matchers.Matcher; //导入依赖的package包/类
MatchType(
    String componentType,
    String lifecycleMethod,
    ImmutableList<Matcher<VariableTree>> lifecycleMethodParameters,
    String staticMethodClass) {
  this.lifecycleMethod = lifecycleMethod;
  methodMatcher =
      allOf(
          methodIsNamed(lifecycleMethod),
          methodHasParameters(lifecycleMethodParameters),
          enclosingClass(isSubtypeOf(componentType)));
  methodInvocationMatcher =
      instanceMethod().onDescendantOf(componentType).named(lifecycleMethod);
  injectMethodMatcher =
      staticMethod().onClass(staticMethodClass).named("inject").withParameters(componentType);
}
 
开发者ID:google,项目名称:error-prone,代码行数:17,代码来源:AndroidInjectionBeforeSuper.java

示例3: receiverSameAsParentsArgument

import com.google.errorprone.matchers.Matcher; //导入依赖的package包/类
private static Matcher<? super MethodInvocationTree> receiverSameAsParentsArgument() {
  return new Matcher<MethodInvocationTree>() {
    @Override
    public boolean matches(MethodInvocationTree t, VisitorState state) {
      ExpressionTree rec = ASTHelpers.getReceiver(t);
      if (rec == null) {
        return false;
      }
      if (!ASSERT_THAT.matches(rec, state)) {
        return false;
      }
      if (!ASTHelpers.sameVariable(
          getOnlyElement(((MethodInvocationTree) rec).getArguments()),
          getOnlyElement(t.getArguments()))) {
        return false;
      }
      return true;
    }
  };
}
 
开发者ID:google,项目名称:error-prone,代码行数:21,代码来源:TruthSelfEquals.java

示例4: getReferencedArgumentsP

import com.google.errorprone.matchers.Matcher; //导入依赖的package包/类
private Set<Integer> getReferencedArgumentsP(String str) {
  java.util.regex.Matcher matcher = printfGroup.matcher(str);

  Set<Integer> set = new HashSet<Integer>();
  int i = 0;
  while (matcher.find()) {
    // %n is line break and %% is literal percent, they don't reference parameters.
    if (!matcher.group().endsWith("n") && !matcher.group().endsWith("%")) {
      if (matcher.group(1) != null) {
        set.add(Integer.parseInt(matcher.group(1).replaceAll("\\$", "")));
      } else {
        set.add(i);
        i++;
      }
    }
  }
  return set;
}
 
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:19,代码来源:MisusedFormattingLogger.java

示例5: assignmentIncrementDecrementMatcher

import com.google.errorprone.matchers.Matcher; //导入依赖的package包/类
/**
 * Matches patterns like i = i + 1 and i = i - 1 in which i is volatile, and the pattern is not
 * enclosed by a synchronized block.
 */
@SuppressWarnings("unchecked")
private static Matcher<AssignmentTree> assignmentIncrementDecrementMatcher(
    ExpressionTree variable) {
  return allOf(
        variableFromAssignmentTree(
            Matchers.<ExpressionTree>hasModifier(Modifier.VOLATILE)),
        not(inSynchronized()),
        expressionFromAssignmentTree(adaptMatcherType(ExpressionTree.class, BinaryTree.class,
            allOf(
                anyOf(
                    kindIs(Kind.PLUS),
                    kindIs(Kind.MINUS)),
                binaryTree(
                    sameVariable(variable),
                    Matchers.<ExpressionTree>anything())))));
}
 
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:21,代码来源:IncrementDecrementVolatile.java

示例6: getInvokeOfSafeInitMethod

import com.google.errorprone.matchers.Matcher; //导入依赖的package包/类
/**
 * A safe init method is an instance method that is either private or final (so no overriding is
 * possible)
 *
 * @param stmt the statement
 * @param enclosingClassSymbol symbol for enclosing constructor / initializer
 * @param state visitor state
 * @return element of safe init function if stmt invokes that function; null otherwise
 */
@Nullable
private Element getInvokeOfSafeInitMethod(
    StatementTree stmt, final Symbol.ClassSymbol enclosingClassSymbol, VisitorState state) {
  Matcher<ExpressionTree> invokeMatcher =
      (expressionTree, s) -> {
        if (!(expressionTree instanceof MethodInvocationTree)) {
          return false;
        }
        MethodInvocationTree methodInvocationTree = (MethodInvocationTree) expressionTree;
        Symbol.MethodSymbol symbol = ASTHelpers.getSymbol(methodInvocationTree);
        Set<Modifier> modifiers = symbol.getModifiers();
        if ((symbol.isPrivate() || modifiers.contains(Modifier.FINAL)) && !symbol.isStatic()) {
          // check it's the same class (could be an issue with inner classes)
          if (ASTHelpers.enclosingClass(symbol).equals(enclosingClassSymbol)) {
            // make sure the receiver is 'this'
            ExpressionTree receiver = ASTHelpers.getReceiver(expressionTree);
            return receiver == null || isThisIdentifier(receiver);
          }
        }
        return false;
      };
  if (stmt.getKind().equals(EXPRESSION_STATEMENT)) {
    ExpressionTree expression = ((ExpressionStatementTree) stmt).getExpression();
    if (invokeMatcher.matches(expression, state)) {
      return ASTHelpers.getSymbol(expression);
    }
  }
  return null;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:39,代码来源:NullAway.java

示例7: create

import com.google.errorprone.matchers.Matcher; //导入依赖的package包/类
public static UMatches create(Class<? extends Matcher<? super ExpressionTree>> matcherClass,
    boolean positive, UExpression expression) {
  // Verify that we can instantiate the Matcher
  makeMatcher(matcherClass);

  return new AutoValue_UMatches(positive, matcherClass, expression);
}
 
开发者ID:sivakumar-kailasam,项目名称:refactor-faster,代码行数:8,代码来源:UMatches.java

示例8: matchBinaryTree

import com.google.errorprone.matchers.Matcher; //导入依赖的package包/类
/**
 * Given a BinaryTree to match against and a list of two matchers, applies the matchers to the
 * operands in both orders. If both matchers match, returns a list with the operand that matched
 * each matcher in the corresponding position.
 *
 * @param tree a BinaryTree AST node
 * @param matchers a list of matchers
 * @param state the VisitorState
 * @return a list of matched operands, or null if at least one did not match
 */
public static List<ExpressionTree> matchBinaryTree(
    BinaryTree tree, List<Matcher<ExpressionTree>> matchers, VisitorState state) {
  ExpressionTree leftOperand = tree.getLeftOperand();
  ExpressionTree rightOperand = tree.getRightOperand();
  if (matchers.get(0).matches(leftOperand, state)
      && matchers.get(1).matches(rightOperand, state)) {
    return Arrays.asList(leftOperand, rightOperand);
  } else if (matchers.get(0).matches(rightOperand, state)
      && matchers.get(1).matches(leftOperand, state)) {
    return Arrays.asList(rightOperand, leftOperand);
  }
  return null;
}
 
开发者ID:google,项目名称:error-prone,代码行数:24,代码来源:ASTHelpers.java

示例9: create

import com.google.errorprone.matchers.Matcher; //导入依赖的package包/类
static PlaceholderMethod create(
    CharSequence name,
    UType returnType,
    ImmutableMap<UVariableDecl, ImmutableClassToInstanceMap<Annotation>> parameters,
    ClassToInstanceMap<Annotation> annotations) {
  final boolean allowsIdentity = annotations.getInstance(Placeholder.class).allowsIdentity();
  final Class<? extends Matcher<? super ExpressionTree>> matchesClass =
      annotations.containsKey(Matches.class)
          ? UTemplater.getValue(annotations.getInstance(Matches.class))
          : null;
  final Class<? extends Matcher<? super ExpressionTree>> notMatchesClass =
      annotations.containsKey(NotMatches.class)
          ? UTemplater.getValue(annotations.getInstance(NotMatches.class))
          : null;
  final Predicate<Tree.Kind> allowedKinds =
      annotations.containsKey(OfKind.class)
          ? Predicates.<Tree.Kind>in(Arrays.asList(annotations.getInstance(OfKind.class).value()))
          : Predicates.<Tree.Kind>alwaysTrue();
  class PlaceholderMatcher implements Serializable, Matcher<ExpressionTree> {

    @Override
    public boolean matches(ExpressionTree t, VisitorState state) {
      try {
        return (allowsIdentity || !(t instanceof PlaceholderParamIdent))
            && (matchesClass == null || matchesClass.newInstance().matches(t, state))
            && (notMatchesClass == null || !notMatchesClass.newInstance().matches(t, state))
            && allowedKinds.apply(t.getKind());
      } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
      }
    }
  }
  return new AutoValue_PlaceholderMethod(
      StringName.of(name),
      returnType,
      parameters,
      new PlaceholderMatcher(),
      ImmutableClassToInstanceMap.<Annotation, Annotation>copyOf(annotations));
}
 
开发者ID:google,项目名称:error-prone,代码行数:40,代码来源:PlaceholderMethod.java

示例10: create

import com.google.errorprone.matchers.Matcher; //导入依赖的package包/类
public static UMatches create(
    Class<? extends Matcher<? super ExpressionTree>> matcherClass,
    boolean positive,
    UExpression expression) {
  // Verify that we can instantiate the Matcher
  makeMatcher(matcherClass);

  return new AutoValue_UMatches(positive, matcherClass, expression);
}
 
开发者ID:google,项目名称:error-prone,代码行数:10,代码来源:UMatches.java

示例11: anyCatchBlockMatches

import com.google.errorprone.matchers.Matcher; //导入依赖的package包/类
private boolean anyCatchBlockMatches(TryTree tree, VisitorState state, Matcher<Tree> matcher) {
  for (CatchTree catchTree : tree.getCatches()) {
    if (matcher.matches(catchTree.getBlock(), state)) {
      return true;
    }
  }
  return false;
}
 
开发者ID:google,项目名称:error-prone,代码行数:9,代码来源:MissingFail.java

示例12: getLongLiteral

import com.google.errorprone.matchers.Matcher; //导入依赖的package包/类
/**
 * Extracts the long literal corresponding to a given {@link LiteralTree} node from the source
 * code as a string. Returns null if the source code is not available.
 */
private static String getLongLiteral(LiteralTree literalTree, VisitorState state) {
  JCLiteral longLiteral = (JCLiteral) literalTree;
  CharSequence sourceFile = state.getSourceCode();
  if (sourceFile == null) {
    return null;
  }
  int start = longLiteral.getStartPosition();
  java.util.regex.Matcher matcher =
      LONG_LITERAL_PATTERN.matcher(sourceFile.subSequence(start, sourceFile.length()));
  if (matcher.lookingAt()) {
    return matcher.group();
  }
  return null;
}
 
开发者ID:google,项目名称:error-prone,代码行数:19,代码来源:LongLiteralLowerCaseSuffix.java

示例13: shouldAllow

import com.google.errorprone.matchers.Matcher; //导入依赖的package包/类
private static Matcher<Tree> shouldAllow(RestrictedApi api, VisitorState state) {
  try {
    return anyAnnotation(api.whitelistAnnotations());
  } catch (MirroredTypesException e) {
    return anyAnnotation(e.getTypeMirrors(), state);
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:8,代码来源:RestrictedApiChecker.java

示例14: shouldAllowWithWarning

import com.google.errorprone.matchers.Matcher; //导入依赖的package包/类
private static Matcher<Tree> shouldAllowWithWarning(RestrictedApi api, VisitorState state) {
  try {
    return anyAnnotation(api.whitelistWithWarningAnnotations());
  } catch (MirroredTypesException e) {
    return anyAnnotation(e.getTypeMirrors(), state);
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:8,代码来源:RestrictedApiChecker.java

示例15: anyAnnotation

import com.google.errorprone.matchers.Matcher; //导入依赖的package包/类
private static Matcher<Tree> anyAnnotation(Class<? extends Annotation>[] annotations) {
  ArrayList<Matcher<Tree>> matchers = new ArrayList<>(annotations.length);
  for (Class<? extends Annotation> annotation : annotations) {
    matchers.add(Matchers.hasAnnotation(annotation));
  }
  return Matchers.anyOf(matchers);
}
 
开发者ID:google,项目名称:error-prone,代码行数:8,代码来源:RestrictedApiChecker.java


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