本文整理汇总了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;
}
};
}
示例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);
}
示例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;
}
};
}
示例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;
}
示例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())))));
}
示例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;
}
示例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);
}
示例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;
}
示例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));
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}