id
int32 0
165k
| repo
stringlengths 7
58
| path
stringlengths 12
218
| func_name
stringlengths 3
140
| original_string
stringlengths 73
34.1k
| language
stringclasses 1
value | code
stringlengths 73
34.1k
| code_tokens
list | docstring
stringlengths 3
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 105
339
|
|---|---|---|---|---|---|---|---|---|---|---|---|
21,700
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/fixes/SuggestedFix.java
|
SuggestedFix.replace
|
public static SuggestedFix replace(int startPos, int endPos, String replaceWith) {
return builder().replace(startPos, endPos, replaceWith).build();
}
|
java
|
public static SuggestedFix replace(int startPos, int endPos, String replaceWith) {
return builder().replace(startPos, endPos, replaceWith).build();
}
|
[
"public",
"static",
"SuggestedFix",
"replace",
"(",
"int",
"startPos",
",",
"int",
"endPos",
",",
"String",
"replaceWith",
")",
"{",
"return",
"builder",
"(",
")",
".",
"replace",
"(",
"startPos",
",",
"endPos",
",",
"replaceWith",
")",
".",
"build",
"(",
")",
";",
"}"
] |
Replace the characters from startPos, inclusive, until endPos, exclusive, with the given
string.
@param startPos The position from which to start replacing, inclusive
@param endPos The position at which to end replacing, exclusive
@param replaceWith The string to replace with
|
[
"Replace",
"the",
"characters",
"from",
"startPos",
"inclusive",
"until",
"endPos",
"exclusive",
"with",
"the",
"given",
"string",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/fixes/SuggestedFix.java#L109-L111
|
21,701
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/NameInCommentHeuristic.java
|
NameInCommentHeuristic.isAcceptableChange
|
@Override
public boolean isAcceptableChange(
Changes changes, Tree node, MethodSymbol symbol, VisitorState state) {
// Now check to see if there is a comment in the position of any actual parameter we want to
// change which matches the formal parameter
ImmutableList<Commented<ExpressionTree>> comments = findCommentsForArguments(node, state);
return changes.changedPairs().stream()
.noneMatch(
p -> {
MatchType match =
NamedParameterComment.match(comments.get(p.formal().index()), p.formal().name())
.matchType();
return match == MatchType.EXACT_MATCH || match == MatchType.APPROXIMATE_MATCH;
});
}
|
java
|
@Override
public boolean isAcceptableChange(
Changes changes, Tree node, MethodSymbol symbol, VisitorState state) {
// Now check to see if there is a comment in the position of any actual parameter we want to
// change which matches the formal parameter
ImmutableList<Commented<ExpressionTree>> comments = findCommentsForArguments(node, state);
return changes.changedPairs().stream()
.noneMatch(
p -> {
MatchType match =
NamedParameterComment.match(comments.get(p.formal().index()), p.formal().name())
.matchType();
return match == MatchType.EXACT_MATCH || match == MatchType.APPROXIMATE_MATCH;
});
}
|
[
"@",
"Override",
"public",
"boolean",
"isAcceptableChange",
"(",
"Changes",
"changes",
",",
"Tree",
"node",
",",
"MethodSymbol",
"symbol",
",",
"VisitorState",
"state",
")",
"{",
"// Now check to see if there is a comment in the position of any actual parameter we want to",
"// change which matches the formal parameter",
"ImmutableList",
"<",
"Commented",
"<",
"ExpressionTree",
">>",
"comments",
"=",
"findCommentsForArguments",
"(",
"node",
",",
"state",
")",
";",
"return",
"changes",
".",
"changedPairs",
"(",
")",
".",
"stream",
"(",
")",
".",
"noneMatch",
"(",
"p",
"->",
"{",
"MatchType",
"match",
"=",
"NamedParameterComment",
".",
"match",
"(",
"comments",
".",
"get",
"(",
"p",
".",
"formal",
"(",
")",
".",
"index",
"(",
")",
")",
",",
"p",
".",
"formal",
"(",
")",
".",
"name",
"(",
")",
")",
".",
"matchType",
"(",
")",
";",
"return",
"match",
"==",
"MatchType",
".",
"EXACT_MATCH",
"||",
"match",
"==",
"MatchType",
".",
"APPROXIMATE_MATCH",
";",
"}",
")",
";",
"}"
] |
Return true if there are no comments on the original actual parameter of a change which match
the name of the formal parameter.
|
[
"Return",
"true",
"if",
"there",
"are",
"no",
"comments",
"on",
"the",
"original",
"actual",
"parameter",
"of",
"a",
"change",
"which",
"match",
"the",
"name",
"of",
"the",
"formal",
"parameter",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/NameInCommentHeuristic.java#L42-L57
|
21,702
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/ModifyingCollectionWithItself.java
|
ModifyingCollectionWithItself.matchMethodInvocation
|
@Override
public Description matchMethodInvocation(MethodInvocationTree t, VisitorState state) {
if (IS_COLLECTION_MODIFIED_WITH_ITSELF.matches(t, state)) {
return describe(t, state);
}
return Description.NO_MATCH;
}
|
java
|
@Override
public Description matchMethodInvocation(MethodInvocationTree t, VisitorState state) {
if (IS_COLLECTION_MODIFIED_WITH_ITSELF.matches(t, state)) {
return describe(t, state);
}
return Description.NO_MATCH;
}
|
[
"@",
"Override",
"public",
"Description",
"matchMethodInvocation",
"(",
"MethodInvocationTree",
"t",
",",
"VisitorState",
"state",
")",
"{",
"if",
"(",
"IS_COLLECTION_MODIFIED_WITH_ITSELF",
".",
"matches",
"(",
"t",
",",
"state",
")",
")",
"{",
"return",
"describe",
"(",
"t",
",",
"state",
")",
";",
"}",
"return",
"Description",
".",
"NO_MATCH",
";",
"}"
] |
Matches calls to addAll, containsAll, removeAll, and retainAll on itself
|
[
"Matches",
"calls",
"to",
"addAll",
"containsAll",
"removeAll",
"and",
"retainAll",
"on",
"itself"
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/ModifyingCollectionWithItself.java#L78-L84
|
21,703
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/JUnit3FloatingPointComparisonWithoutDelta.java
|
JUnit3FloatingPointComparisonWithoutDelta.getArgumentTypesWithoutMessage
|
private List<Type> getArgumentTypesWithoutMessage(
MethodInvocationTree methodInvocationTree, VisitorState state) {
List<Type> argumentTypes = new ArrayList<>();
for (ExpressionTree argument : methodInvocationTree.getArguments()) {
JCTree tree = (JCTree) argument;
argumentTypes.add(tree.type);
}
removeMessageArgumentIfPresent(state, argumentTypes);
return argumentTypes;
}
|
java
|
private List<Type> getArgumentTypesWithoutMessage(
MethodInvocationTree methodInvocationTree, VisitorState state) {
List<Type> argumentTypes = new ArrayList<>();
for (ExpressionTree argument : methodInvocationTree.getArguments()) {
JCTree tree = (JCTree) argument;
argumentTypes.add(tree.type);
}
removeMessageArgumentIfPresent(state, argumentTypes);
return argumentTypes;
}
|
[
"private",
"List",
"<",
"Type",
">",
"getArgumentTypesWithoutMessage",
"(",
"MethodInvocationTree",
"methodInvocationTree",
",",
"VisitorState",
"state",
")",
"{",
"List",
"<",
"Type",
">",
"argumentTypes",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"ExpressionTree",
"argument",
":",
"methodInvocationTree",
".",
"getArguments",
"(",
")",
")",
"{",
"JCTree",
"tree",
"=",
"(",
"JCTree",
")",
"argument",
";",
"argumentTypes",
".",
"add",
"(",
"tree",
".",
"type",
")",
";",
"}",
"removeMessageArgumentIfPresent",
"(",
"state",
",",
"argumentTypes",
")",
";",
"return",
"argumentTypes",
";",
"}"
] |
Gets the argument types, excluding the message argument if present.
|
[
"Gets",
"the",
"argument",
"types",
"excluding",
"the",
"message",
"argument",
"if",
"present",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/JUnit3FloatingPointComparisonWithoutDelta.java#L76-L85
|
21,704
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/JUnit3FloatingPointComparisonWithoutDelta.java
|
JUnit3FloatingPointComparisonWithoutDelta.removeMessageArgumentIfPresent
|
private void removeMessageArgumentIfPresent(VisitorState state, List<Type> argumentTypes) {
if (argumentTypes.size() == 2) {
return;
}
Types types = state.getTypes();
Type firstType = argumentTypes.get(0);
if (types.isSameType(firstType, state.getSymtab().stringType)) {
argumentTypes.remove(0);
}
}
|
java
|
private void removeMessageArgumentIfPresent(VisitorState state, List<Type> argumentTypes) {
if (argumentTypes.size() == 2) {
return;
}
Types types = state.getTypes();
Type firstType = argumentTypes.get(0);
if (types.isSameType(firstType, state.getSymtab().stringType)) {
argumentTypes.remove(0);
}
}
|
[
"private",
"void",
"removeMessageArgumentIfPresent",
"(",
"VisitorState",
"state",
",",
"List",
"<",
"Type",
">",
"argumentTypes",
")",
"{",
"if",
"(",
"argumentTypes",
".",
"size",
"(",
")",
"==",
"2",
")",
"{",
"return",
";",
"}",
"Types",
"types",
"=",
"state",
".",
"getTypes",
"(",
")",
";",
"Type",
"firstType",
"=",
"argumentTypes",
".",
"get",
"(",
"0",
")",
";",
"if",
"(",
"types",
".",
"isSameType",
"(",
"firstType",
",",
"state",
".",
"getSymtab",
"(",
")",
".",
"stringType",
")",
")",
"{",
"argumentTypes",
".",
"remove",
"(",
"0",
")",
";",
"}",
"}"
] |
Removes the message argument if it is present.
|
[
"Removes",
"the",
"message",
"argument",
"if",
"it",
"is",
"present",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/JUnit3FloatingPointComparisonWithoutDelta.java#L88-L97
|
21,705
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/JUnit3FloatingPointComparisonWithoutDelta.java
|
JUnit3FloatingPointComparisonWithoutDelta.canBeConvertedToJUnit4
|
private boolean canBeConvertedToJUnit4(VisitorState state, List<Type> argumentTypes) {
// Delta argument is used.
if (argumentTypes.size() > 2) {
return true;
}
Type firstType = argumentTypes.get(0);
Type secondType = argumentTypes.get(1);
// Neither argument is floating-point.
if (!isFloatingPoint(state, firstType) && !isFloatingPoint(state, secondType)) {
return true;
}
// One argument is not numeric.
if (!isNumeric(state, firstType) || !isNumeric(state, secondType)) {
return true;
}
// Neither argument is primitive.
if (!firstType.isPrimitive() && !secondType.isPrimitive()) {
return true;
}
return false;
}
|
java
|
private boolean canBeConvertedToJUnit4(VisitorState state, List<Type> argumentTypes) {
// Delta argument is used.
if (argumentTypes.size() > 2) {
return true;
}
Type firstType = argumentTypes.get(0);
Type secondType = argumentTypes.get(1);
// Neither argument is floating-point.
if (!isFloatingPoint(state, firstType) && !isFloatingPoint(state, secondType)) {
return true;
}
// One argument is not numeric.
if (!isNumeric(state, firstType) || !isNumeric(state, secondType)) {
return true;
}
// Neither argument is primitive.
if (!firstType.isPrimitive() && !secondType.isPrimitive()) {
return true;
}
return false;
}
|
[
"private",
"boolean",
"canBeConvertedToJUnit4",
"(",
"VisitorState",
"state",
",",
"List",
"<",
"Type",
">",
"argumentTypes",
")",
"{",
"// Delta argument is used.",
"if",
"(",
"argumentTypes",
".",
"size",
"(",
")",
">",
"2",
")",
"{",
"return",
"true",
";",
"}",
"Type",
"firstType",
"=",
"argumentTypes",
".",
"get",
"(",
"0",
")",
";",
"Type",
"secondType",
"=",
"argumentTypes",
".",
"get",
"(",
"1",
")",
";",
"// Neither argument is floating-point.",
"if",
"(",
"!",
"isFloatingPoint",
"(",
"state",
",",
"firstType",
")",
"&&",
"!",
"isFloatingPoint",
"(",
"state",
",",
"secondType",
")",
")",
"{",
"return",
"true",
";",
"}",
"// One argument is not numeric.",
"if",
"(",
"!",
"isNumeric",
"(",
"state",
",",
"firstType",
")",
"||",
"!",
"isNumeric",
"(",
"state",
",",
"secondType",
")",
")",
"{",
"return",
"true",
";",
"}",
"// Neither argument is primitive.",
"if",
"(",
"!",
"firstType",
".",
"isPrimitive",
"(",
")",
"&&",
"!",
"secondType",
".",
"isPrimitive",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Determines if the invocation can be safely converted to JUnit 4 based on its argument types.
|
[
"Determines",
"if",
"the",
"invocation",
"can",
"be",
"safely",
"converted",
"to",
"JUnit",
"4",
"based",
"on",
"its",
"argument",
"types",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/JUnit3FloatingPointComparisonWithoutDelta.java#L102-L122
|
21,706
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/JUnit3FloatingPointComparisonWithoutDelta.java
|
JUnit3FloatingPointComparisonWithoutDelta.isFloatingPoint
|
private boolean isFloatingPoint(VisitorState state, Type type) {
Type trueType = unboxedTypeOrType(state, type);
return (trueType.getKind() == TypeKind.DOUBLE) || (trueType.getKind() == TypeKind.FLOAT);
}
|
java
|
private boolean isFloatingPoint(VisitorState state, Type type) {
Type trueType = unboxedTypeOrType(state, type);
return (trueType.getKind() == TypeKind.DOUBLE) || (trueType.getKind() == TypeKind.FLOAT);
}
|
[
"private",
"boolean",
"isFloatingPoint",
"(",
"VisitorState",
"state",
",",
"Type",
"type",
")",
"{",
"Type",
"trueType",
"=",
"unboxedTypeOrType",
"(",
"state",
",",
"type",
")",
";",
"return",
"(",
"trueType",
".",
"getKind",
"(",
")",
"==",
"TypeKind",
".",
"DOUBLE",
")",
"||",
"(",
"trueType",
".",
"getKind",
"(",
")",
"==",
"TypeKind",
".",
"FLOAT",
")",
";",
"}"
] |
Determines if the type is a floating-point type, including reference types.
|
[
"Determines",
"if",
"the",
"type",
"is",
"a",
"floating",
"-",
"point",
"type",
"including",
"reference",
"types",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/JUnit3FloatingPointComparisonWithoutDelta.java#L125-L128
|
21,707
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/JUnit3FloatingPointComparisonWithoutDelta.java
|
JUnit3FloatingPointComparisonWithoutDelta.isNumeric
|
private boolean isNumeric(VisitorState state, Type type) {
Type trueType = unboxedTypeOrType(state, type);
return trueType.isNumeric();
}
|
java
|
private boolean isNumeric(VisitorState state, Type type) {
Type trueType = unboxedTypeOrType(state, type);
return trueType.isNumeric();
}
|
[
"private",
"boolean",
"isNumeric",
"(",
"VisitorState",
"state",
",",
"Type",
"type",
")",
"{",
"Type",
"trueType",
"=",
"unboxedTypeOrType",
"(",
"state",
",",
"type",
")",
";",
"return",
"trueType",
".",
"isNumeric",
"(",
")",
";",
"}"
] |
Determines if the type is a numeric type, including reference types.
<p>Type.isNumeric() does not handle reference types properly.
|
[
"Determines",
"if",
"the",
"type",
"is",
"a",
"numeric",
"type",
"including",
"reference",
"types",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/JUnit3FloatingPointComparisonWithoutDelta.java#L135-L138
|
21,708
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/JUnit3FloatingPointComparisonWithoutDelta.java
|
JUnit3FloatingPointComparisonWithoutDelta.unboxedTypeOrType
|
private Type unboxedTypeOrType(VisitorState state, Type type) {
Types types = state.getTypes();
return types.unboxedTypeOrType(type);
}
|
java
|
private Type unboxedTypeOrType(VisitorState state, Type type) {
Types types = state.getTypes();
return types.unboxedTypeOrType(type);
}
|
[
"private",
"Type",
"unboxedTypeOrType",
"(",
"VisitorState",
"state",
",",
"Type",
"type",
")",
"{",
"Types",
"types",
"=",
"state",
".",
"getTypes",
"(",
")",
";",
"return",
"types",
".",
"unboxedTypeOrType",
"(",
"type",
")",
";",
"}"
] |
Gets the unboxed type, or the original type if it is not unboxable.
|
[
"Gets",
"the",
"unboxed",
"type",
"or",
"the",
"original",
"type",
"if",
"it",
"is",
"not",
"unboxable",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/JUnit3FloatingPointComparisonWithoutDelta.java#L141-L144
|
21,709
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/JUnit3FloatingPointComparisonWithoutDelta.java
|
JUnit3FloatingPointComparisonWithoutDelta.addDeltaArgument
|
private Fix addDeltaArgument(
MethodInvocationTree methodInvocationTree, VisitorState state, List<Type> argumentTypes) {
int insertionIndex = getDeltaInsertionIndex(methodInvocationTree, state);
String deltaArgument = getDeltaArgument(state, argumentTypes);
return SuggestedFix.replace(insertionIndex, insertionIndex, deltaArgument);
}
|
java
|
private Fix addDeltaArgument(
MethodInvocationTree methodInvocationTree, VisitorState state, List<Type> argumentTypes) {
int insertionIndex = getDeltaInsertionIndex(methodInvocationTree, state);
String deltaArgument = getDeltaArgument(state, argumentTypes);
return SuggestedFix.replace(insertionIndex, insertionIndex, deltaArgument);
}
|
[
"private",
"Fix",
"addDeltaArgument",
"(",
"MethodInvocationTree",
"methodInvocationTree",
",",
"VisitorState",
"state",
",",
"List",
"<",
"Type",
">",
"argumentTypes",
")",
"{",
"int",
"insertionIndex",
"=",
"getDeltaInsertionIndex",
"(",
"methodInvocationTree",
",",
"state",
")",
";",
"String",
"deltaArgument",
"=",
"getDeltaArgument",
"(",
"state",
",",
"argumentTypes",
")",
";",
"return",
"SuggestedFix",
".",
"replace",
"(",
"insertionIndex",
",",
"insertionIndex",
",",
"deltaArgument",
")",
";",
"}"
] |
Creates the fix to add a delta argument.
|
[
"Creates",
"the",
"fix",
"to",
"add",
"a",
"delta",
"argument",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/JUnit3FloatingPointComparisonWithoutDelta.java#L147-L152
|
21,710
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/JUnit3FloatingPointComparisonWithoutDelta.java
|
JUnit3FloatingPointComparisonWithoutDelta.getDeltaInsertionIndex
|
private int getDeltaInsertionIndex(
MethodInvocationTree methodInvocationTree, VisitorState state) {
JCTree lastArgument = (JCTree) Iterables.getLast(methodInvocationTree.getArguments());
return state.getEndPosition(lastArgument);
}
|
java
|
private int getDeltaInsertionIndex(
MethodInvocationTree methodInvocationTree, VisitorState state) {
JCTree lastArgument = (JCTree) Iterables.getLast(methodInvocationTree.getArguments());
return state.getEndPosition(lastArgument);
}
|
[
"private",
"int",
"getDeltaInsertionIndex",
"(",
"MethodInvocationTree",
"methodInvocationTree",
",",
"VisitorState",
"state",
")",
"{",
"JCTree",
"lastArgument",
"=",
"(",
"JCTree",
")",
"Iterables",
".",
"getLast",
"(",
"methodInvocationTree",
".",
"getArguments",
"(",
")",
")",
";",
"return",
"state",
".",
"getEndPosition",
"(",
"lastArgument",
")",
";",
"}"
] |
Gets the index of where to insert the delta argument.
|
[
"Gets",
"the",
"index",
"of",
"where",
"to",
"insert",
"the",
"delta",
"argument",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/JUnit3FloatingPointComparisonWithoutDelta.java#L155-L159
|
21,711
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/JUnit3FloatingPointComparisonWithoutDelta.java
|
JUnit3FloatingPointComparisonWithoutDelta.getDeltaArgument
|
private String getDeltaArgument(VisitorState state, List<Type> argumentTypes) {
Type firstType = argumentTypes.get(0);
Type secondType = argumentTypes.get(1);
boolean doublePrecisionUsed = isDouble(state, firstType) || isDouble(state, secondType);
return doublePrecisionUsed ? ", 0.0" : ", 0.0f";
}
|
java
|
private String getDeltaArgument(VisitorState state, List<Type> argumentTypes) {
Type firstType = argumentTypes.get(0);
Type secondType = argumentTypes.get(1);
boolean doublePrecisionUsed = isDouble(state, firstType) || isDouble(state, secondType);
return doublePrecisionUsed ? ", 0.0" : ", 0.0f";
}
|
[
"private",
"String",
"getDeltaArgument",
"(",
"VisitorState",
"state",
",",
"List",
"<",
"Type",
">",
"argumentTypes",
")",
"{",
"Type",
"firstType",
"=",
"argumentTypes",
".",
"get",
"(",
"0",
")",
";",
"Type",
"secondType",
"=",
"argumentTypes",
".",
"get",
"(",
"1",
")",
";",
"boolean",
"doublePrecisionUsed",
"=",
"isDouble",
"(",
"state",
",",
"firstType",
")",
"||",
"isDouble",
"(",
"state",
",",
"secondType",
")",
";",
"return",
"doublePrecisionUsed",
"?",
"\", 0.0\"",
":",
"\", 0.0f\"",
";",
"}"
] |
Gets the text for the delta argument to be added.
|
[
"Gets",
"the",
"text",
"for",
"the",
"delta",
"argument",
"to",
"be",
"added",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/JUnit3FloatingPointComparisonWithoutDelta.java#L162-L167
|
21,712
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/JUnit3FloatingPointComparisonWithoutDelta.java
|
JUnit3FloatingPointComparisonWithoutDelta.isDouble
|
private boolean isDouble(VisitorState state, Type type) {
Type trueType = unboxedTypeOrType(state, type);
return trueType.getKind() == TypeKind.DOUBLE;
}
|
java
|
private boolean isDouble(VisitorState state, Type type) {
Type trueType = unboxedTypeOrType(state, type);
return trueType.getKind() == TypeKind.DOUBLE;
}
|
[
"private",
"boolean",
"isDouble",
"(",
"VisitorState",
"state",
",",
"Type",
"type",
")",
"{",
"Type",
"trueType",
"=",
"unboxedTypeOrType",
"(",
"state",
",",
"type",
")",
";",
"return",
"trueType",
".",
"getKind",
"(",
")",
"==",
"TypeKind",
".",
"DOUBLE",
";",
"}"
] |
Determines if the type is a double, including reference types.
|
[
"Determines",
"if",
"the",
"type",
"is",
"a",
"double",
"including",
"reference",
"types",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/JUnit3FloatingPointComparisonWithoutDelta.java#L170-L173
|
21,713
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/ThreeLetterTimeZoneID.java
|
ThreeLetterTimeZoneID.handleNonDaylightSavingsZone
|
static Replacement handleNonDaylightSavingsZone(
boolean inJodaTimeContext, String daylightSavingsZone, String fixedOffset) {
if (inJodaTimeContext) {
String newDescription =
SUMMARY
+ "\n\n"
+ observesDaylightSavingsMessage("DateTimeZone", daylightSavingsZone, fixedOffset);
return new Replacement(newDescription, ImmutableList.of(daylightSavingsZone, fixedOffset));
} else {
String newDescription =
SUMMARY
+ "\n\n"
+ "This TimeZone will not observe daylight savings. "
+ "If this is intended, use "
+ fixedOffset
+ " instead; to observe daylight savings, use "
+ daylightSavingsZone
+ ".";
return new Replacement(newDescription, ImmutableList.of(fixedOffset, daylightSavingsZone));
}
}
|
java
|
static Replacement handleNonDaylightSavingsZone(
boolean inJodaTimeContext, String daylightSavingsZone, String fixedOffset) {
if (inJodaTimeContext) {
String newDescription =
SUMMARY
+ "\n\n"
+ observesDaylightSavingsMessage("DateTimeZone", daylightSavingsZone, fixedOffset);
return new Replacement(newDescription, ImmutableList.of(daylightSavingsZone, fixedOffset));
} else {
String newDescription =
SUMMARY
+ "\n\n"
+ "This TimeZone will not observe daylight savings. "
+ "If this is intended, use "
+ fixedOffset
+ " instead; to observe daylight savings, use "
+ daylightSavingsZone
+ ".";
return new Replacement(newDescription, ImmutableList.of(fixedOffset, daylightSavingsZone));
}
}
|
[
"static",
"Replacement",
"handleNonDaylightSavingsZone",
"(",
"boolean",
"inJodaTimeContext",
",",
"String",
"daylightSavingsZone",
",",
"String",
"fixedOffset",
")",
"{",
"if",
"(",
"inJodaTimeContext",
")",
"{",
"String",
"newDescription",
"=",
"SUMMARY",
"+",
"\"\\n\\n\"",
"+",
"observesDaylightSavingsMessage",
"(",
"\"DateTimeZone\"",
",",
"daylightSavingsZone",
",",
"fixedOffset",
")",
";",
"return",
"new",
"Replacement",
"(",
"newDescription",
",",
"ImmutableList",
".",
"of",
"(",
"daylightSavingsZone",
",",
"fixedOffset",
")",
")",
";",
"}",
"else",
"{",
"String",
"newDescription",
"=",
"SUMMARY",
"+",
"\"\\n\\n\"",
"+",
"\"This TimeZone will not observe daylight savings. \"",
"+",
"\"If this is intended, use \"",
"+",
"fixedOffset",
"+",
"\" instead; to observe daylight savings, use \"",
"+",
"daylightSavingsZone",
"+",
"\".\"",
";",
"return",
"new",
"Replacement",
"(",
"newDescription",
",",
"ImmutableList",
".",
"of",
"(",
"fixedOffset",
",",
"daylightSavingsZone",
")",
")",
";",
"}",
"}"
] |
How we handle it depends upon whether we are in a JodaTime context or not.
|
[
"How",
"we",
"handle",
"it",
"depends",
"upon",
"whether",
"we",
"are",
"in",
"a",
"JodaTime",
"context",
"or",
"not",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/ThreeLetterTimeZoneID.java#L127-L147
|
21,714
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/ConstantOverflow.java
|
ConstantOverflow.longFix
|
private Fix longFix(ExpressionTree expr, VisitorState state) {
BinaryTree binExpr = null;
while (expr instanceof BinaryTree) {
binExpr = (BinaryTree) expr;
expr = binExpr.getLeftOperand();
}
if (!(expr instanceof LiteralTree) || expr.getKind() != Kind.INT_LITERAL) {
return null;
}
Type intType = state.getSymtab().intType;
if (!isSameType(getType(binExpr), intType, state)) {
return null;
}
SuggestedFix.Builder fix = SuggestedFix.builder().postfixWith(expr, "L");
Tree parent = state.getPath().getParentPath().getLeaf();
if (parent instanceof VariableTree && isSameType(getType(parent), intType, state)) {
fix.replace(((VariableTree) parent).getType(), "long");
}
return fix.build();
}
|
java
|
private Fix longFix(ExpressionTree expr, VisitorState state) {
BinaryTree binExpr = null;
while (expr instanceof BinaryTree) {
binExpr = (BinaryTree) expr;
expr = binExpr.getLeftOperand();
}
if (!(expr instanceof LiteralTree) || expr.getKind() != Kind.INT_LITERAL) {
return null;
}
Type intType = state.getSymtab().intType;
if (!isSameType(getType(binExpr), intType, state)) {
return null;
}
SuggestedFix.Builder fix = SuggestedFix.builder().postfixWith(expr, "L");
Tree parent = state.getPath().getParentPath().getLeaf();
if (parent instanceof VariableTree && isSameType(getType(parent), intType, state)) {
fix.replace(((VariableTree) parent).getType(), "long");
}
return fix.build();
}
|
[
"private",
"Fix",
"longFix",
"(",
"ExpressionTree",
"expr",
",",
"VisitorState",
"state",
")",
"{",
"BinaryTree",
"binExpr",
"=",
"null",
";",
"while",
"(",
"expr",
"instanceof",
"BinaryTree",
")",
"{",
"binExpr",
"=",
"(",
"BinaryTree",
")",
"expr",
";",
"expr",
"=",
"binExpr",
".",
"getLeftOperand",
"(",
")",
";",
"}",
"if",
"(",
"!",
"(",
"expr",
"instanceof",
"LiteralTree",
")",
"||",
"expr",
".",
"getKind",
"(",
")",
"!=",
"Kind",
".",
"INT_LITERAL",
")",
"{",
"return",
"null",
";",
"}",
"Type",
"intType",
"=",
"state",
".",
"getSymtab",
"(",
")",
".",
"intType",
";",
"if",
"(",
"!",
"isSameType",
"(",
"getType",
"(",
"binExpr",
")",
",",
"intType",
",",
"state",
")",
")",
"{",
"return",
"null",
";",
"}",
"SuggestedFix",
".",
"Builder",
"fix",
"=",
"SuggestedFix",
".",
"builder",
"(",
")",
".",
"postfixWith",
"(",
"expr",
",",
"\"L\"",
")",
";",
"Tree",
"parent",
"=",
"state",
".",
"getPath",
"(",
")",
".",
"getParentPath",
"(",
")",
".",
"getLeaf",
"(",
")",
";",
"if",
"(",
"parent",
"instanceof",
"VariableTree",
"&&",
"isSameType",
"(",
"getType",
"(",
"parent",
")",
",",
"intType",
",",
"state",
")",
")",
"{",
"fix",
".",
"replace",
"(",
"(",
"(",
"VariableTree",
")",
"parent",
")",
".",
"getType",
"(",
")",
",",
"\"long\"",
")",
";",
"}",
"return",
"fix",
".",
"build",
"(",
")",
";",
"}"
] |
If the left operand of an int binary expression is an int literal, suggest making it a long.
|
[
"If",
"the",
"left",
"operand",
"of",
"an",
"int",
"binary",
"expression",
"is",
"an",
"int",
"literal",
"suggest",
"making",
"it",
"a",
"long",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/ConstantOverflow.java#L86-L105
|
21,715
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.anything
|
public static <T extends Tree> Matcher<T> anything() {
return new Matcher<T>() {
@Override
public boolean matches(T t, VisitorState state) {
return true;
}
};
}
|
java
|
public static <T extends Tree> Matcher<T> anything() {
return new Matcher<T>() {
@Override
public boolean matches(T t, VisitorState state) {
return true;
}
};
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Matcher",
"<",
"T",
">",
"anything",
"(",
")",
"{",
"return",
"new",
"Matcher",
"<",
"T",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"T",
"t",
",",
"VisitorState",
"state",
")",
"{",
"return",
"true",
";",
"}",
"}",
";",
"}"
] |
A matcher that matches any AST node.
|
[
"A",
"matcher",
"that",
"matches",
"any",
"AST",
"node",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L98-L105
|
21,716
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.nothing
|
public static <T extends Tree> Matcher<T> nothing() {
return new Matcher<T>() {
@Override
public boolean matches(T t, VisitorState state) {
return false;
}
};
}
|
java
|
public static <T extends Tree> Matcher<T> nothing() {
return new Matcher<T>() {
@Override
public boolean matches(T t, VisitorState state) {
return false;
}
};
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Matcher",
"<",
"T",
">",
"nothing",
"(",
")",
"{",
"return",
"new",
"Matcher",
"<",
"T",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"T",
"t",
",",
"VisitorState",
"state",
")",
"{",
"return",
"false",
";",
"}",
"}",
";",
"}"
] |
A matcher that matches no AST node.
|
[
"A",
"matcher",
"that",
"matches",
"no",
"AST",
"node",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L108-L115
|
21,717
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.not
|
public static <T extends Tree> Matcher<T> not(final Matcher<T> matcher) {
return new Matcher<T>() {
@Override
public boolean matches(T t, VisitorState state) {
return !matcher.matches(t, state);
}
};
}
|
java
|
public static <T extends Tree> Matcher<T> not(final Matcher<T> matcher) {
return new Matcher<T>() {
@Override
public boolean matches(T t, VisitorState state) {
return !matcher.matches(t, state);
}
};
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Matcher",
"<",
"T",
">",
"not",
"(",
"final",
"Matcher",
"<",
"T",
">",
"matcher",
")",
"{",
"return",
"new",
"Matcher",
"<",
"T",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"T",
"t",
",",
"VisitorState",
"state",
")",
"{",
"return",
"!",
"matcher",
".",
"matches",
"(",
"t",
",",
"state",
")",
";",
"}",
"}",
";",
"}"
] |
Matches an AST node iff it does not match the given matcher.
|
[
"Matches",
"an",
"AST",
"node",
"iff",
"it",
"does",
"not",
"match",
"the",
"given",
"matcher",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L118-L125
|
21,718
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.allOf
|
@SafeVarargs
public static <T extends Tree> Matcher<T> allOf(final Matcher<? super T>... matchers) {
return new Matcher<T>() {
@Override
public boolean matches(T t, VisitorState state) {
for (Matcher<? super T> matcher : matchers) {
if (!matcher.matches(t, state)) {
return false;
}
}
return true;
}
};
}
|
java
|
@SafeVarargs
public static <T extends Tree> Matcher<T> allOf(final Matcher<? super T>... matchers) {
return new Matcher<T>() {
@Override
public boolean matches(T t, VisitorState state) {
for (Matcher<? super T> matcher : matchers) {
if (!matcher.matches(t, state)) {
return false;
}
}
return true;
}
};
}
|
[
"@",
"SafeVarargs",
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Matcher",
"<",
"T",
">",
"allOf",
"(",
"final",
"Matcher",
"<",
"?",
"super",
"T",
">",
"...",
"matchers",
")",
"{",
"return",
"new",
"Matcher",
"<",
"T",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"T",
"t",
",",
"VisitorState",
"state",
")",
"{",
"for",
"(",
"Matcher",
"<",
"?",
"super",
"T",
">",
"matcher",
":",
"matchers",
")",
"{",
"if",
"(",
"!",
"matcher",
".",
"matches",
"(",
"t",
",",
"state",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
"}",
";",
"}"
] |
Compose several matchers together, such that the composite matches an AST node iff all the
given matchers do.
|
[
"Compose",
"several",
"matchers",
"together",
"such",
"that",
"the",
"composite",
"matches",
"an",
"AST",
"node",
"iff",
"all",
"the",
"given",
"matchers",
"do",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L131-L144
|
21,719
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.anyOf
|
public static <T extends Tree> Matcher<T> anyOf(
final Iterable<? extends Matcher<? super T>> matchers) {
return new Matcher<T>() {
@Override
public boolean matches(T t, VisitorState state) {
for (Matcher<? super T> matcher : matchers) {
if (matcher.matches(t, state)) {
return true;
}
}
return false;
}
};
}
|
java
|
public static <T extends Tree> Matcher<T> anyOf(
final Iterable<? extends Matcher<? super T>> matchers) {
return new Matcher<T>() {
@Override
public boolean matches(T t, VisitorState state) {
for (Matcher<? super T> matcher : matchers) {
if (matcher.matches(t, state)) {
return true;
}
}
return false;
}
};
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Matcher",
"<",
"T",
">",
"anyOf",
"(",
"final",
"Iterable",
"<",
"?",
"extends",
"Matcher",
"<",
"?",
"super",
"T",
">",
">",
"matchers",
")",
"{",
"return",
"new",
"Matcher",
"<",
"T",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"T",
"t",
",",
"VisitorState",
"state",
")",
"{",
"for",
"(",
"Matcher",
"<",
"?",
"super",
"T",
">",
"matcher",
":",
"matchers",
")",
"{",
"if",
"(",
"matcher",
".",
"matches",
"(",
"t",
",",
"state",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}",
"}",
";",
"}"
] |
Compose several matchers together, such that the composite matches an AST node if any of the
given matchers do.
|
[
"Compose",
"several",
"matchers",
"together",
"such",
"that",
"the",
"composite",
"matches",
"an",
"AST",
"node",
"if",
"any",
"of",
"the",
"given",
"matchers",
"do",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L150-L163
|
21,720
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.isInstance
|
public static <T extends Tree> Matcher<T> isInstance(final java.lang.Class<?> klass) {
return new Matcher<T>() {
@Override
public boolean matches(T t, VisitorState state) {
return klass.isInstance(t);
}
};
}
|
java
|
public static <T extends Tree> Matcher<T> isInstance(final java.lang.Class<?> klass) {
return new Matcher<T>() {
@Override
public boolean matches(T t, VisitorState state) {
return klass.isInstance(t);
}
};
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Matcher",
"<",
"T",
">",
"isInstance",
"(",
"final",
"java",
".",
"lang",
".",
"Class",
"<",
"?",
">",
"klass",
")",
"{",
"return",
"new",
"Matcher",
"<",
"T",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"T",
"t",
",",
"VisitorState",
"state",
")",
"{",
"return",
"klass",
".",
"isInstance",
"(",
"t",
")",
";",
"}",
"}",
";",
"}"
] |
Matches if an AST node is an instance of the given class.
|
[
"Matches",
"if",
"an",
"AST",
"node",
"is",
"an",
"instance",
"of",
"the",
"given",
"class",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L171-L178
|
21,721
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.kindIs
|
public static <T extends Tree> Matcher<T> kindIs(final Kind kind) {
return new Matcher<T>() {
@Override
public boolean matches(T tree, VisitorState state) {
return tree.getKind() == kind;
}
};
}
|
java
|
public static <T extends Tree> Matcher<T> kindIs(final Kind kind) {
return new Matcher<T>() {
@Override
public boolean matches(T tree, VisitorState state) {
return tree.getKind() == kind;
}
};
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Matcher",
"<",
"T",
">",
"kindIs",
"(",
"final",
"Kind",
"kind",
")",
"{",
"return",
"new",
"Matcher",
"<",
"T",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"T",
"tree",
",",
"VisitorState",
"state",
")",
"{",
"return",
"tree",
".",
"getKind",
"(",
")",
"==",
"kind",
";",
"}",
"}",
";",
"}"
] |
Matches an AST node of a given kind, for example, an Annotation or a switch block.
|
[
"Matches",
"an",
"AST",
"node",
"of",
"a",
"given",
"kind",
"for",
"example",
"an",
"Annotation",
"or",
"a",
"switch",
"block",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L181-L188
|
21,722
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.isSame
|
public static <T extends Tree> Matcher<T> isSame(final Tree t) {
return new Matcher<T>() {
@Override
public boolean matches(T tree, VisitorState state) {
return tree == t;
}
};
}
|
java
|
public static <T extends Tree> Matcher<T> isSame(final Tree t) {
return new Matcher<T>() {
@Override
public boolean matches(T tree, VisitorState state) {
return tree == t;
}
};
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Matcher",
"<",
"T",
">",
"isSame",
"(",
"final",
"Tree",
"t",
")",
"{",
"return",
"new",
"Matcher",
"<",
"T",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"T",
"tree",
",",
"VisitorState",
"state",
")",
"{",
"return",
"tree",
"==",
"t",
";",
"}",
"}",
";",
"}"
] |
Matches an AST node which is the same object reference as the given node.
|
[
"Matches",
"an",
"AST",
"node",
"which",
"is",
"the",
"same",
"object",
"reference",
"as",
"the",
"given",
"node",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L191-L198
|
21,723
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.isInstanceField
|
public static Matcher<ExpressionTree> isInstanceField() {
return new Matcher<ExpressionTree>() {
@Override
public boolean matches(ExpressionTree expressionTree, VisitorState state) {
Symbol symbol = ASTHelpers.getSymbol(expressionTree);
return symbol != null && symbol.getKind() == ElementKind.FIELD && !symbol.isStatic();
}
};
}
|
java
|
public static Matcher<ExpressionTree> isInstanceField() {
return new Matcher<ExpressionTree>() {
@Override
public boolean matches(ExpressionTree expressionTree, VisitorState state) {
Symbol symbol = ASTHelpers.getSymbol(expressionTree);
return symbol != null && symbol.getKind() == ElementKind.FIELD && !symbol.isStatic();
}
};
}
|
[
"public",
"static",
"Matcher",
"<",
"ExpressionTree",
">",
"isInstanceField",
"(",
")",
"{",
"return",
"new",
"Matcher",
"<",
"ExpressionTree",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"ExpressionTree",
"expressionTree",
",",
"VisitorState",
"state",
")",
"{",
"Symbol",
"symbol",
"=",
"ASTHelpers",
".",
"getSymbol",
"(",
"expressionTree",
")",
";",
"return",
"symbol",
"!=",
"null",
"&&",
"symbol",
".",
"getKind",
"(",
")",
"==",
"ElementKind",
".",
"FIELD",
"&&",
"!",
"symbol",
".",
"isStatic",
"(",
")",
";",
"}",
"}",
";",
"}"
] |
Matches an AST node that represents a non-static field.
|
[
"Matches",
"an",
"AST",
"node",
"that",
"represents",
"a",
"non",
"-",
"static",
"field",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L221-L229
|
21,724
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.isVariable
|
public static Matcher<ExpressionTree> isVariable() {
return new Matcher<ExpressionTree>() {
@Override
public boolean matches(ExpressionTree expressionTree, VisitorState state) {
Symbol symbol = ASTHelpers.getSymbol(expressionTree);
if (symbol == null) {
return false;
}
return symbol.getKind() == ElementKind.LOCAL_VARIABLE
|| symbol.getKind() == ElementKind.PARAMETER;
}
};
}
|
java
|
public static Matcher<ExpressionTree> isVariable() {
return new Matcher<ExpressionTree>() {
@Override
public boolean matches(ExpressionTree expressionTree, VisitorState state) {
Symbol symbol = ASTHelpers.getSymbol(expressionTree);
if (symbol == null) {
return false;
}
return symbol.getKind() == ElementKind.LOCAL_VARIABLE
|| symbol.getKind() == ElementKind.PARAMETER;
}
};
}
|
[
"public",
"static",
"Matcher",
"<",
"ExpressionTree",
">",
"isVariable",
"(",
")",
"{",
"return",
"new",
"Matcher",
"<",
"ExpressionTree",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"ExpressionTree",
"expressionTree",
",",
"VisitorState",
"state",
")",
"{",
"Symbol",
"symbol",
"=",
"ASTHelpers",
".",
"getSymbol",
"(",
"expressionTree",
")",
";",
"if",
"(",
"symbol",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"return",
"symbol",
".",
"getKind",
"(",
")",
"==",
"ElementKind",
".",
"LOCAL_VARIABLE",
"||",
"symbol",
".",
"getKind",
"(",
")",
"==",
"ElementKind",
".",
"PARAMETER",
";",
"}",
"}",
";",
"}"
] |
Matches an AST node that represents a local variable or parameter.
|
[
"Matches",
"an",
"AST",
"node",
"that",
"represents",
"a",
"local",
"variable",
"or",
"parameter",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L232-L244
|
21,725
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.compoundAssignment
|
public static CompoundAssignment compoundAssignment(
Kind operator,
Matcher<ExpressionTree> leftOperandMatcher,
Matcher<ExpressionTree> rightOperandMatcher) {
Set<Kind> operators = new HashSet<>(1);
operators.add(operator);
return new CompoundAssignment(operators, leftOperandMatcher, rightOperandMatcher);
}
|
java
|
public static CompoundAssignment compoundAssignment(
Kind operator,
Matcher<ExpressionTree> leftOperandMatcher,
Matcher<ExpressionTree> rightOperandMatcher) {
Set<Kind> operators = new HashSet<>(1);
operators.add(operator);
return new CompoundAssignment(operators, leftOperandMatcher, rightOperandMatcher);
}
|
[
"public",
"static",
"CompoundAssignment",
"compoundAssignment",
"(",
"Kind",
"operator",
",",
"Matcher",
"<",
"ExpressionTree",
">",
"leftOperandMatcher",
",",
"Matcher",
"<",
"ExpressionTree",
">",
"rightOperandMatcher",
")",
"{",
"Set",
"<",
"Kind",
">",
"operators",
"=",
"new",
"HashSet",
"<>",
"(",
"1",
")",
";",
"operators",
".",
"add",
"(",
"operator",
")",
";",
"return",
"new",
"CompoundAssignment",
"(",
"operators",
",",
"leftOperandMatcher",
",",
"rightOperandMatcher",
")",
";",
"}"
] |
Matches a compound assignment operator AST node which matches a given left-operand matcher, a
given right-operand matcher, and a specific compound assignment operator.
@param operator Which compound assignment operator to match against.
@param leftOperandMatcher The matcher to apply to the left operand.
@param rightOperandMatcher The matcher to apply to the right operand.
|
[
"Matches",
"a",
"compound",
"assignment",
"operator",
"AST",
"node",
"which",
"matches",
"a",
"given",
"left",
"-",
"operand",
"matcher",
"a",
"given",
"right",
"-",
"operand",
"matcher",
"and",
"a",
"specific",
"compound",
"assignment",
"operator",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L254-L261
|
21,726
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.compoundAssignment
|
public static CompoundAssignment compoundAssignment(
Set<Kind> operators,
Matcher<ExpressionTree> receiverMatcher,
Matcher<ExpressionTree> expressionMatcher) {
return new CompoundAssignment(operators, receiverMatcher, expressionMatcher);
}
|
java
|
public static CompoundAssignment compoundAssignment(
Set<Kind> operators,
Matcher<ExpressionTree> receiverMatcher,
Matcher<ExpressionTree> expressionMatcher) {
return new CompoundAssignment(operators, receiverMatcher, expressionMatcher);
}
|
[
"public",
"static",
"CompoundAssignment",
"compoundAssignment",
"(",
"Set",
"<",
"Kind",
">",
"operators",
",",
"Matcher",
"<",
"ExpressionTree",
">",
"receiverMatcher",
",",
"Matcher",
"<",
"ExpressionTree",
">",
"expressionMatcher",
")",
"{",
"return",
"new",
"CompoundAssignment",
"(",
"operators",
",",
"receiverMatcher",
",",
"expressionMatcher",
")",
";",
"}"
] |
Matches a compound assignment operator AST node which matches a given left-operand matcher, a
given right-operand matcher, and is one of a set of compound assignment operators. Does not
match compound assignment operators.
@param operators Which compound assignment operators to match against.
@param receiverMatcher The matcher to apply to the receiver.
@param expressionMatcher The matcher to apply to the expression.
|
[
"Matches",
"a",
"compound",
"assignment",
"operator",
"AST",
"node",
"which",
"matches",
"a",
"given",
"left",
"-",
"operand",
"matcher",
"a",
"given",
"right",
"-",
"operand",
"matcher",
"and",
"is",
"one",
"of",
"a",
"set",
"of",
"compound",
"assignment",
"operators",
".",
"Does",
"not",
"match",
"compound",
"assignment",
"operators",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L272-L277
|
21,727
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.annotations
|
public static <T extends Tree> MultiMatcher<T, AnnotationTree> annotations(
MatchType matchType, Matcher<AnnotationTree> annotationMatcher) {
return new AnnotationMatcher<>(matchType, annotationMatcher);
}
|
java
|
public static <T extends Tree> MultiMatcher<T, AnnotationTree> annotations(
MatchType matchType, Matcher<AnnotationTree> annotationMatcher) {
return new AnnotationMatcher<>(matchType, annotationMatcher);
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"MultiMatcher",
"<",
"T",
",",
"AnnotationTree",
">",
"annotations",
"(",
"MatchType",
"matchType",
",",
"Matcher",
"<",
"AnnotationTree",
">",
"annotationMatcher",
")",
"{",
"return",
"new",
"AnnotationMatcher",
"<>",
"(",
"matchType",
",",
"annotationMatcher",
")",
";",
"}"
] |
Matches if the given annotation matcher matches all of or any of the annotations on this tree
node.
@param matchType Whether to match if the matchers match any of or all of the annotations on
this tree.
@param annotationMatcher The annotation matcher to use.
|
[
"Matches",
"if",
"the",
"given",
"annotation",
"matcher",
"matches",
"all",
"of",
"or",
"any",
"of",
"the",
"annotations",
"on",
"this",
"tree",
"node",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L328-L331
|
21,728
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.methodInvocation
|
public static Matcher<ExpressionTree> methodInvocation(
Matcher<ExpressionTree> methodSelectMatcher,
MatchType matchType,
Matcher<ExpressionTree> methodArgumentMatcher) {
return new MethodInvocation(methodSelectMatcher, matchType, methodArgumentMatcher);
}
|
java
|
public static Matcher<ExpressionTree> methodInvocation(
Matcher<ExpressionTree> methodSelectMatcher,
MatchType matchType,
Matcher<ExpressionTree> methodArgumentMatcher) {
return new MethodInvocation(methodSelectMatcher, matchType, methodArgumentMatcher);
}
|
[
"public",
"static",
"Matcher",
"<",
"ExpressionTree",
">",
"methodInvocation",
"(",
"Matcher",
"<",
"ExpressionTree",
">",
"methodSelectMatcher",
",",
"MatchType",
"matchType",
",",
"Matcher",
"<",
"ExpressionTree",
">",
"methodArgumentMatcher",
")",
"{",
"return",
"new",
"MethodInvocation",
"(",
"methodSelectMatcher",
",",
"matchType",
",",
"methodArgumentMatcher",
")",
";",
"}"
] |
Matches an AST node if it is a method invocation and the given matchers match.
@param methodSelectMatcher matcher identifying the method being called
@param matchType how to match method arguments with {@code methodArgumentMatcher}
@param methodArgumentMatcher matcher applied to each method argument
|
[
"Matches",
"an",
"AST",
"node",
"if",
"it",
"is",
"a",
"method",
"invocation",
"and",
"the",
"given",
"matchers",
"match",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L363-L368
|
21,729
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.isSameType
|
public static <T extends Tree> Matcher<T> isSameType(Supplier<Type> type) {
return new IsSameType<>(type);
}
|
java
|
public static <T extends Tree> Matcher<T> isSameType(Supplier<Type> type) {
return new IsSameType<>(type);
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Matcher",
"<",
"T",
">",
"isSameType",
"(",
"Supplier",
"<",
"Type",
">",
"type",
")",
"{",
"return",
"new",
"IsSameType",
"<>",
"(",
"type",
")",
";",
"}"
] |
Matches an AST node if it has the same erased type as the given type.
|
[
"Matches",
"an",
"AST",
"node",
"if",
"it",
"has",
"the",
"same",
"erased",
"type",
"as",
"the",
"given",
"type",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L436-L438
|
21,730
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.isSameType
|
public static <T extends Tree> Matcher<T> isSameType(Class<?> clazz) {
return new IsSameType<>(typeFromClass(clazz));
}
|
java
|
public static <T extends Tree> Matcher<T> isSameType(Class<?> clazz) {
return new IsSameType<>(typeFromClass(clazz));
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Matcher",
"<",
"T",
">",
"isSameType",
"(",
"Class",
"<",
"?",
">",
"clazz",
")",
"{",
"return",
"new",
"IsSameType",
"<>",
"(",
"typeFromClass",
"(",
"clazz",
")",
")",
";",
"}"
] |
Matches an AST node if it has the same erased type as the given class.
|
[
"Matches",
"an",
"AST",
"node",
"if",
"it",
"has",
"the",
"same",
"erased",
"type",
"as",
"the",
"given",
"class",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L446-L448
|
21,731
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.isArrayType
|
public static <T extends Tree> Matcher<T> isArrayType() {
return new Matcher<T>() {
@Override
public boolean matches(Tree t, VisitorState state) {
Type type = getType(t);
return type != null && state.getTypes().isArray(type);
}
};
}
|
java
|
public static <T extends Tree> Matcher<T> isArrayType() {
return new Matcher<T>() {
@Override
public boolean matches(Tree t, VisitorState state) {
Type type = getType(t);
return type != null && state.getTypes().isArray(type);
}
};
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Matcher",
"<",
"T",
">",
"isArrayType",
"(",
")",
"{",
"return",
"new",
"Matcher",
"<",
"T",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"Tree",
"t",
",",
"VisitorState",
"state",
")",
"{",
"Type",
"type",
"=",
"getType",
"(",
"t",
")",
";",
"return",
"type",
"!=",
"null",
"&&",
"state",
".",
"getTypes",
"(",
")",
".",
"isArray",
"(",
"type",
")",
";",
"}",
"}",
";",
"}"
] |
Matches an AST node if its type is an array type.
|
[
"Matches",
"an",
"AST",
"node",
"if",
"its",
"type",
"is",
"an",
"array",
"type",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L451-L459
|
21,732
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.isPrimitiveArrayType
|
public static <T extends Tree> Matcher<T> isPrimitiveArrayType() {
return new Matcher<T>() {
@Override
public boolean matches(Tree t, VisitorState state) {
Type type = getType(t);
return type != null
&& state.getTypes().isArray(type)
&& state.getTypes().elemtype(type).isPrimitive();
}
};
}
|
java
|
public static <T extends Tree> Matcher<T> isPrimitiveArrayType() {
return new Matcher<T>() {
@Override
public boolean matches(Tree t, VisitorState state) {
Type type = getType(t);
return type != null
&& state.getTypes().isArray(type)
&& state.getTypes().elemtype(type).isPrimitive();
}
};
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Matcher",
"<",
"T",
">",
"isPrimitiveArrayType",
"(",
")",
"{",
"return",
"new",
"Matcher",
"<",
"T",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"Tree",
"t",
",",
"VisitorState",
"state",
")",
"{",
"Type",
"type",
"=",
"getType",
"(",
"t",
")",
";",
"return",
"type",
"!=",
"null",
"&&",
"state",
".",
"getTypes",
"(",
")",
".",
"isArray",
"(",
"type",
")",
"&&",
"state",
".",
"getTypes",
"(",
")",
".",
"elemtype",
"(",
"type",
")",
".",
"isPrimitive",
"(",
")",
";",
"}",
"}",
";",
"}"
] |
Matches an AST node if its type is a primitive array type.
|
[
"Matches",
"an",
"AST",
"node",
"if",
"its",
"type",
"is",
"a",
"primitive",
"array",
"type",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L462-L472
|
21,733
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.isPrimitiveType
|
public static <T extends Tree> Matcher<T> isPrimitiveType() {
return new Matcher<T>() {
@Override
public boolean matches(Tree t, VisitorState state) {
Type type = getType(t);
return type != null && type.isPrimitive();
}
};
}
|
java
|
public static <T extends Tree> Matcher<T> isPrimitiveType() {
return new Matcher<T>() {
@Override
public boolean matches(Tree t, VisitorState state) {
Type type = getType(t);
return type != null && type.isPrimitive();
}
};
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Matcher",
"<",
"T",
">",
"isPrimitiveType",
"(",
")",
"{",
"return",
"new",
"Matcher",
"<",
"T",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"Tree",
"t",
",",
"VisitorState",
"state",
")",
"{",
"Type",
"type",
"=",
"getType",
"(",
"t",
")",
";",
"return",
"type",
"!=",
"null",
"&&",
"type",
".",
"isPrimitive",
"(",
")",
";",
"}",
"}",
";",
"}"
] |
Matches an AST node if its type is a primitive type.
|
[
"Matches",
"an",
"AST",
"node",
"if",
"its",
"type",
"is",
"a",
"primitive",
"type",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L475-L483
|
21,734
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.isPrimitiveOrBoxedPrimitiveType
|
public static <T extends Tree> Matcher<T> isPrimitiveOrBoxedPrimitiveType() {
return new Matcher<T>() {
@Override
public boolean matches(Tree t, VisitorState state) {
Type type = getType(t);
return type != null && state.getTypes().unboxedTypeOrType(type).isPrimitive();
}
};
}
|
java
|
public static <T extends Tree> Matcher<T> isPrimitiveOrBoxedPrimitiveType() {
return new Matcher<T>() {
@Override
public boolean matches(Tree t, VisitorState state) {
Type type = getType(t);
return type != null && state.getTypes().unboxedTypeOrType(type).isPrimitive();
}
};
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Matcher",
"<",
"T",
">",
"isPrimitiveOrBoxedPrimitiveType",
"(",
")",
"{",
"return",
"new",
"Matcher",
"<",
"T",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"Tree",
"t",
",",
"VisitorState",
"state",
")",
"{",
"Type",
"type",
"=",
"getType",
"(",
"t",
")",
";",
"return",
"type",
"!=",
"null",
"&&",
"state",
".",
"getTypes",
"(",
")",
".",
"unboxedTypeOrType",
"(",
"type",
")",
".",
"isPrimitive",
"(",
")",
";",
"}",
"}",
";",
"}"
] |
Matches an AST node if its type is a primitive type, or a boxed version of a primitive type.
|
[
"Matches",
"an",
"AST",
"node",
"if",
"its",
"type",
"is",
"a",
"primitive",
"type",
"or",
"a",
"boxed",
"version",
"of",
"a",
"primitive",
"type",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L510-L518
|
21,735
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.enclosingBlock
|
public static <T extends Tree> Enclosing.Block<T> enclosingBlock(Matcher<BlockTree> matcher) {
return new Enclosing.Block<>(matcher);
}
|
java
|
public static <T extends Tree> Enclosing.Block<T> enclosingBlock(Matcher<BlockTree> matcher) {
return new Enclosing.Block<>(matcher);
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Enclosing",
".",
"Block",
"<",
"T",
">",
"enclosingBlock",
"(",
"Matcher",
"<",
"BlockTree",
">",
"matcher",
")",
"{",
"return",
"new",
"Enclosing",
".",
"Block",
"<>",
"(",
"matcher",
")",
";",
"}"
] |
Matches an AST node which is enclosed by a block node that matches the given matcher.
|
[
"Matches",
"an",
"AST",
"node",
"which",
"is",
"enclosed",
"by",
"a",
"block",
"node",
"that",
"matches",
"the",
"given",
"matcher",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L521-L523
|
21,736
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.enclosingClass
|
public static <T extends Tree> Enclosing.Class<T> enclosingClass(Matcher<ClassTree> matcher) {
return new Enclosing.Class<>(matcher);
}
|
java
|
public static <T extends Tree> Enclosing.Class<T> enclosingClass(Matcher<ClassTree> matcher) {
return new Enclosing.Class<>(matcher);
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Enclosing",
".",
"Class",
"<",
"T",
">",
"enclosingClass",
"(",
"Matcher",
"<",
"ClassTree",
">",
"matcher",
")",
"{",
"return",
"new",
"Enclosing",
".",
"Class",
"<>",
"(",
"matcher",
")",
";",
"}"
] |
Matches an AST node which is enclosed by a class node that matches the given matcher.
|
[
"Matches",
"an",
"AST",
"node",
"which",
"is",
"enclosed",
"by",
"a",
"class",
"node",
"that",
"matches",
"the",
"given",
"matcher",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L526-L528
|
21,737
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.enclosingMethod
|
public static <T extends Tree> Enclosing.Method<T> enclosingMethod(Matcher<MethodTree> matcher) {
return new Enclosing.Method<>(matcher);
}
|
java
|
public static <T extends Tree> Enclosing.Method<T> enclosingMethod(Matcher<MethodTree> matcher) {
return new Enclosing.Method<>(matcher);
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Enclosing",
".",
"Method",
"<",
"T",
">",
"enclosingMethod",
"(",
"Matcher",
"<",
"MethodTree",
">",
"matcher",
")",
"{",
"return",
"new",
"Enclosing",
".",
"Method",
"<>",
"(",
"matcher",
")",
";",
"}"
] |
Matches an AST node which is enclosed by a method node that matches the given matcher.
|
[
"Matches",
"an",
"AST",
"node",
"which",
"is",
"enclosed",
"by",
"a",
"method",
"node",
"that",
"matches",
"the",
"given",
"matcher",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L531-L533
|
21,738
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.enclosingNode
|
public static <T extends Tree> Matcher<Tree> enclosingNode(final Matcher<T> matcher) {
return new Matcher<Tree>() {
@SuppressWarnings("unchecked") // TODO(cushon): this should take a Class<T>
@Override
public boolean matches(Tree t, VisitorState state) {
TreePath path = state.getPath().getParentPath();
while (path != null) {
Tree node = path.getLeaf();
state = state.withPath(path);
if (matcher.matches((T) node, state)) {
return true;
}
path = path.getParentPath();
}
return false;
}
};
}
|
java
|
public static <T extends Tree> Matcher<Tree> enclosingNode(final Matcher<T> matcher) {
return new Matcher<Tree>() {
@SuppressWarnings("unchecked") // TODO(cushon): this should take a Class<T>
@Override
public boolean matches(Tree t, VisitorState state) {
TreePath path = state.getPath().getParentPath();
while (path != null) {
Tree node = path.getLeaf();
state = state.withPath(path);
if (matcher.matches((T) node, state)) {
return true;
}
path = path.getParentPath();
}
return false;
}
};
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Matcher",
"<",
"Tree",
">",
"enclosingNode",
"(",
"final",
"Matcher",
"<",
"T",
">",
"matcher",
")",
"{",
"return",
"new",
"Matcher",
"<",
"Tree",
">",
"(",
")",
"{",
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"// TODO(cushon): this should take a Class<T>",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"Tree",
"t",
",",
"VisitorState",
"state",
")",
"{",
"TreePath",
"path",
"=",
"state",
".",
"getPath",
"(",
")",
".",
"getParentPath",
"(",
")",
";",
"while",
"(",
"path",
"!=",
"null",
")",
"{",
"Tree",
"node",
"=",
"path",
".",
"getLeaf",
"(",
")",
";",
"state",
"=",
"state",
".",
"withPath",
"(",
"path",
")",
";",
"if",
"(",
"matcher",
".",
"matches",
"(",
"(",
"T",
")",
"node",
",",
"state",
")",
")",
"{",
"return",
"true",
";",
"}",
"path",
"=",
"path",
".",
"getParentPath",
"(",
")",
";",
"}",
"return",
"false",
";",
"}",
"}",
";",
"}"
] |
Matches an AST node that is enclosed by some node that matches the given matcher.
<p>TODO(eaftan): This could be used instead of enclosingBlock and enclosingClass.
|
[
"Matches",
"an",
"AST",
"node",
"that",
"is",
"enclosed",
"by",
"some",
"node",
"that",
"matches",
"the",
"given",
"matcher",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L540-L557
|
21,739
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.nextStatement
|
public static <T extends StatementTree> NextStatement<T> nextStatement(
Matcher<StatementTree> matcher) {
return new NextStatement<>(matcher);
}
|
java
|
public static <T extends StatementTree> NextStatement<T> nextStatement(
Matcher<StatementTree> matcher) {
return new NextStatement<>(matcher);
}
|
[
"public",
"static",
"<",
"T",
"extends",
"StatementTree",
">",
"NextStatement",
"<",
"T",
">",
"nextStatement",
"(",
"Matcher",
"<",
"StatementTree",
">",
"matcher",
")",
"{",
"return",
"new",
"NextStatement",
"<>",
"(",
"matcher",
")",
";",
"}"
] |
Matches a statement AST node if the following statement in the enclosing block matches the
given matcher.
|
[
"Matches",
"a",
"statement",
"AST",
"node",
"if",
"the",
"following",
"statement",
"in",
"the",
"enclosing",
"block",
"matches",
"the",
"given",
"matcher",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L563-L566
|
21,740
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.previousStatement
|
public static <T extends StatementTree> Matcher<T> previousStatement(
Matcher<StatementTree> matcher) {
return (T statement, VisitorState state) -> {
BlockTree block = state.findEnclosing(BlockTree.class);
if (block == null) {
return false;
}
List<? extends StatementTree> statements = block.getStatements();
int idx = statements.indexOf(statement);
if (idx <= 0) {
// The block wrapping us doesn't contain this statement, or doesn't contain a previous
// statement.
return false;
}
return matcher.matches(statements.get(idx - 1), state);
};
}
|
java
|
public static <T extends StatementTree> Matcher<T> previousStatement(
Matcher<StatementTree> matcher) {
return (T statement, VisitorState state) -> {
BlockTree block = state.findEnclosing(BlockTree.class);
if (block == null) {
return false;
}
List<? extends StatementTree> statements = block.getStatements();
int idx = statements.indexOf(statement);
if (idx <= 0) {
// The block wrapping us doesn't contain this statement, or doesn't contain a previous
// statement.
return false;
}
return matcher.matches(statements.get(idx - 1), state);
};
}
|
[
"public",
"static",
"<",
"T",
"extends",
"StatementTree",
">",
"Matcher",
"<",
"T",
">",
"previousStatement",
"(",
"Matcher",
"<",
"StatementTree",
">",
"matcher",
")",
"{",
"return",
"(",
"T",
"statement",
",",
"VisitorState",
"state",
")",
"->",
"{",
"BlockTree",
"block",
"=",
"state",
".",
"findEnclosing",
"(",
"BlockTree",
".",
"class",
")",
";",
"if",
"(",
"block",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"List",
"<",
"?",
"extends",
"StatementTree",
">",
"statements",
"=",
"block",
".",
"getStatements",
"(",
")",
";",
"int",
"idx",
"=",
"statements",
".",
"indexOf",
"(",
"statement",
")",
";",
"if",
"(",
"idx",
"<=",
"0",
")",
"{",
"// The block wrapping us doesn't contain this statement, or doesn't contain a previous",
"// statement.",
"return",
"false",
";",
"}",
"return",
"matcher",
".",
"matches",
"(",
"statements",
".",
"get",
"(",
"idx",
"-",
"1",
")",
",",
"state",
")",
";",
"}",
";",
"}"
] |
Matches a statement AST node if the previous statement in the enclosing block matches the given
matcher.
|
[
"Matches",
"a",
"statement",
"AST",
"node",
"if",
"the",
"previous",
"statement",
"in",
"the",
"enclosing",
"block",
"matches",
"the",
"given",
"matcher",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L572-L588
|
21,741
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.nonNullLiteral
|
public static Matcher<ExpressionTree> nonNullLiteral() {
return new Matcher<ExpressionTree>() {
@Override
public boolean matches(ExpressionTree tree, VisitorState state) {
switch (tree.getKind()) {
case MEMBER_SELECT:
return ((MemberSelectTree) tree).getIdentifier().contentEquals("class");
case INT_LITERAL:
case LONG_LITERAL:
case FLOAT_LITERAL:
case DOUBLE_LITERAL:
case BOOLEAN_LITERAL:
case CHAR_LITERAL:
// fall through
case STRING_LITERAL:
return true;
default:
return false;
}
}
};
}
|
java
|
public static Matcher<ExpressionTree> nonNullLiteral() {
return new Matcher<ExpressionTree>() {
@Override
public boolean matches(ExpressionTree tree, VisitorState state) {
switch (tree.getKind()) {
case MEMBER_SELECT:
return ((MemberSelectTree) tree).getIdentifier().contentEquals("class");
case INT_LITERAL:
case LONG_LITERAL:
case FLOAT_LITERAL:
case DOUBLE_LITERAL:
case BOOLEAN_LITERAL:
case CHAR_LITERAL:
// fall through
case STRING_LITERAL:
return true;
default:
return false;
}
}
};
}
|
[
"public",
"static",
"Matcher",
"<",
"ExpressionTree",
">",
"nonNullLiteral",
"(",
")",
"{",
"return",
"new",
"Matcher",
"<",
"ExpressionTree",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"ExpressionTree",
"tree",
",",
"VisitorState",
"state",
")",
"{",
"switch",
"(",
"tree",
".",
"getKind",
"(",
")",
")",
"{",
"case",
"MEMBER_SELECT",
":",
"return",
"(",
"(",
"MemberSelectTree",
")",
"tree",
")",
".",
"getIdentifier",
"(",
")",
".",
"contentEquals",
"(",
"\"class\"",
")",
";",
"case",
"INT_LITERAL",
":",
"case",
"LONG_LITERAL",
":",
"case",
"FLOAT_LITERAL",
":",
"case",
"DOUBLE_LITERAL",
":",
"case",
"BOOLEAN_LITERAL",
":",
"case",
"CHAR_LITERAL",
":",
"// fall through",
"case",
"STRING_LITERAL",
":",
"return",
"true",
";",
"default",
":",
"return",
"false",
";",
"}",
"}",
"}",
";",
"}"
] |
Matches an AST node if it is a literal other than null.
|
[
"Matches",
"an",
"AST",
"node",
"if",
"it",
"is",
"a",
"literal",
"other",
"than",
"null",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L596-L617
|
21,742
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.methodReturnsNonNull
|
public static Matcher<ExpressionTree> methodReturnsNonNull() {
return anyOf(
instanceMethod().onDescendantOf("java.lang.Object").named("toString"),
instanceMethod().onExactClass("java.lang.String"),
staticMethod().onClass("java.lang.String"),
instanceMethod().onExactClass("java.util.StringTokenizer").named("nextToken"));
}
|
java
|
public static Matcher<ExpressionTree> methodReturnsNonNull() {
return anyOf(
instanceMethod().onDescendantOf("java.lang.Object").named("toString"),
instanceMethod().onExactClass("java.lang.String"),
staticMethod().onClass("java.lang.String"),
instanceMethod().onExactClass("java.util.StringTokenizer").named("nextToken"));
}
|
[
"public",
"static",
"Matcher",
"<",
"ExpressionTree",
">",
"methodReturnsNonNull",
"(",
")",
"{",
"return",
"anyOf",
"(",
"instanceMethod",
"(",
")",
".",
"onDescendantOf",
"(",
"\"java.lang.Object\"",
")",
".",
"named",
"(",
"\"toString\"",
")",
",",
"instanceMethod",
"(",
")",
".",
"onExactClass",
"(",
"\"java.lang.String\"",
")",
",",
"staticMethod",
"(",
")",
".",
"onClass",
"(",
"\"java.lang.String\"",
")",
",",
"instanceMethod",
"(",
")",
".",
"onExactClass",
"(",
"\"java.util.StringTokenizer\"",
")",
".",
"named",
"(",
"\"nextToken\"",
")",
")",
";",
"}"
] |
Matches a whitelisted method invocation that is known to never return null
|
[
"Matches",
"a",
"whitelisted",
"method",
"invocation",
"that",
"is",
"known",
"to",
"never",
"return",
"null"
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L882-L888
|
21,743
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.methodIsNamed
|
public static Matcher<MethodTree> methodIsNamed(final String methodName) {
return new Matcher<MethodTree>() {
@Override
public boolean matches(MethodTree methodTree, VisitorState state) {
return methodTree.getName().contentEquals(methodName);
}
};
}
|
java
|
public static Matcher<MethodTree> methodIsNamed(final String methodName) {
return new Matcher<MethodTree>() {
@Override
public boolean matches(MethodTree methodTree, VisitorState state) {
return methodTree.getName().contentEquals(methodName);
}
};
}
|
[
"public",
"static",
"Matcher",
"<",
"MethodTree",
">",
"methodIsNamed",
"(",
"final",
"String",
"methodName",
")",
"{",
"return",
"new",
"Matcher",
"<",
"MethodTree",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"MethodTree",
"methodTree",
",",
"VisitorState",
"state",
")",
"{",
"return",
"methodTree",
".",
"getName",
"(",
")",
".",
"contentEquals",
"(",
"methodName",
")",
";",
"}",
"}",
";",
"}"
] |
Match a method declaration with a specific name.
@param methodName The name of the method to match, e.g., "equals"
|
[
"Match",
"a",
"method",
"declaration",
"with",
"a",
"specific",
"name",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L918-L925
|
21,744
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.methodNameStartsWith
|
public static Matcher<MethodTree> methodNameStartsWith(final String prefix) {
return new Matcher<MethodTree>() {
@Override
public boolean matches(MethodTree methodTree, VisitorState state) {
return methodTree.getName().toString().startsWith(prefix);
}
};
}
|
java
|
public static Matcher<MethodTree> methodNameStartsWith(final String prefix) {
return new Matcher<MethodTree>() {
@Override
public boolean matches(MethodTree methodTree, VisitorState state) {
return methodTree.getName().toString().startsWith(prefix);
}
};
}
|
[
"public",
"static",
"Matcher",
"<",
"MethodTree",
">",
"methodNameStartsWith",
"(",
"final",
"String",
"prefix",
")",
"{",
"return",
"new",
"Matcher",
"<",
"MethodTree",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"MethodTree",
"methodTree",
",",
"VisitorState",
"state",
")",
"{",
"return",
"methodTree",
".",
"getName",
"(",
")",
".",
"toString",
"(",
")",
".",
"startsWith",
"(",
"prefix",
")",
";",
"}",
"}",
";",
"}"
] |
Match a method declaration that starts with a given string.
@param prefix The prefix.
|
[
"Match",
"a",
"method",
"declaration",
"that",
"starts",
"with",
"a",
"given",
"string",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L932-L939
|
21,745
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.methodWithClassAndName
|
public static Matcher<MethodTree> methodWithClassAndName(
final String className, final String methodName) {
return new Matcher<MethodTree>() {
@Override
public boolean matches(MethodTree methodTree, VisitorState state) {
return ASTHelpers.getSymbol(methodTree)
.getEnclosingElement()
.getQualifiedName()
.contentEquals(className)
&& methodTree.getName().contentEquals(methodName);
}
};
}
|
java
|
public static Matcher<MethodTree> methodWithClassAndName(
final String className, final String methodName) {
return new Matcher<MethodTree>() {
@Override
public boolean matches(MethodTree methodTree, VisitorState state) {
return ASTHelpers.getSymbol(methodTree)
.getEnclosingElement()
.getQualifiedName()
.contentEquals(className)
&& methodTree.getName().contentEquals(methodName);
}
};
}
|
[
"public",
"static",
"Matcher",
"<",
"MethodTree",
">",
"methodWithClassAndName",
"(",
"final",
"String",
"className",
",",
"final",
"String",
"methodName",
")",
"{",
"return",
"new",
"Matcher",
"<",
"MethodTree",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"MethodTree",
"methodTree",
",",
"VisitorState",
"state",
")",
"{",
"return",
"ASTHelpers",
".",
"getSymbol",
"(",
"methodTree",
")",
".",
"getEnclosingElement",
"(",
")",
".",
"getQualifiedName",
"(",
")",
".",
"contentEquals",
"(",
"className",
")",
"&&",
"methodTree",
".",
"getName",
"(",
")",
".",
"contentEquals",
"(",
"methodName",
")",
";",
"}",
"}",
";",
"}"
] |
Match a method declaration with a specific enclosing class and method name.
@param className The fully-qualified name of the enclosing class, e.g.
"com.google.common.base.Preconditions"
@param methodName The name of the method to match, e.g., "checkNotNull"
|
[
"Match",
"a",
"method",
"declaration",
"with",
"a",
"specific",
"enclosing",
"class",
"and",
"method",
"name",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L948-L960
|
21,746
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.constructorOfClass
|
public static Matcher<MethodTree> constructorOfClass(final String className) {
return new Matcher<MethodTree>() {
@Override
public boolean matches(MethodTree methodTree, VisitorState state) {
Symbol symbol = ASTHelpers.getSymbol(methodTree);
return symbol.getEnclosingElement().getQualifiedName().contentEquals(className)
&& symbol.isConstructor();
}
};
}
|
java
|
public static Matcher<MethodTree> constructorOfClass(final String className) {
return new Matcher<MethodTree>() {
@Override
public boolean matches(MethodTree methodTree, VisitorState state) {
Symbol symbol = ASTHelpers.getSymbol(methodTree);
return symbol.getEnclosingElement().getQualifiedName().contentEquals(className)
&& symbol.isConstructor();
}
};
}
|
[
"public",
"static",
"Matcher",
"<",
"MethodTree",
">",
"constructorOfClass",
"(",
"final",
"String",
"className",
")",
"{",
"return",
"new",
"Matcher",
"<",
"MethodTree",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"MethodTree",
"methodTree",
",",
"VisitorState",
"state",
")",
"{",
"Symbol",
"symbol",
"=",
"ASTHelpers",
".",
"getSymbol",
"(",
"methodTree",
")",
";",
"return",
"symbol",
".",
"getEnclosingElement",
"(",
")",
".",
"getQualifiedName",
"(",
")",
".",
"contentEquals",
"(",
"className",
")",
"&&",
"symbol",
".",
"isConstructor",
"(",
")",
";",
"}",
"}",
";",
"}"
] |
Matches a constructor declaration in a specific enclosing class.
@param className The fully-qualified name of the enclosing class, e.g.
"com.google.common.base.Preconditions"
|
[
"Matches",
"a",
"constructor",
"declaration",
"in",
"a",
"specific",
"enclosing",
"class",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L1032-L1041
|
21,747
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.hasMethod
|
public static Matcher<ClassTree> hasMethod(final Matcher<MethodTree> methodMatcher) {
return new Matcher<ClassTree>() {
@Override
public boolean matches(ClassTree t, VisitorState state) {
for (Tree member : t.getMembers()) {
if (member instanceof MethodTree) {
if (methodMatcher.matches((MethodTree) member, state)) {
return true;
}
}
}
return false;
}
};
}
|
java
|
public static Matcher<ClassTree> hasMethod(final Matcher<MethodTree> methodMatcher) {
return new Matcher<ClassTree>() {
@Override
public boolean matches(ClassTree t, VisitorState state) {
for (Tree member : t.getMembers()) {
if (member instanceof MethodTree) {
if (methodMatcher.matches((MethodTree) member, state)) {
return true;
}
}
}
return false;
}
};
}
|
[
"public",
"static",
"Matcher",
"<",
"ClassTree",
">",
"hasMethod",
"(",
"final",
"Matcher",
"<",
"MethodTree",
">",
"methodMatcher",
")",
"{",
"return",
"new",
"Matcher",
"<",
"ClassTree",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"ClassTree",
"t",
",",
"VisitorState",
"state",
")",
"{",
"for",
"(",
"Tree",
"member",
":",
"t",
".",
"getMembers",
"(",
")",
")",
"{",
"if",
"(",
"member",
"instanceof",
"MethodTree",
")",
"{",
"if",
"(",
"methodMatcher",
".",
"matches",
"(",
"(",
"MethodTree",
")",
"member",
",",
"state",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}",
"}",
";",
"}"
] |
Matches a class in which at least one method matches the given methodMatcher.
@param methodMatcher A matcher on MethodTrees to run against all methods in this class.
@return True if some method in the class matches the given methodMatcher.
|
[
"Matches",
"a",
"class",
"in",
"which",
"at",
"least",
"one",
"method",
"matches",
"the",
"given",
"methodMatcher",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L1049-L1063
|
21,748
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.variableType
|
public static Matcher<VariableTree> variableType(final Matcher<Tree> treeMatcher) {
return new Matcher<VariableTree>() {
@Override
public boolean matches(VariableTree variableTree, VisitorState state) {
return treeMatcher.matches(variableTree.getType(), state);
}
};
}
|
java
|
public static Matcher<VariableTree> variableType(final Matcher<Tree> treeMatcher) {
return new Matcher<VariableTree>() {
@Override
public boolean matches(VariableTree variableTree, VisitorState state) {
return treeMatcher.matches(variableTree.getType(), state);
}
};
}
|
[
"public",
"static",
"Matcher",
"<",
"VariableTree",
">",
"variableType",
"(",
"final",
"Matcher",
"<",
"Tree",
">",
"treeMatcher",
")",
"{",
"return",
"new",
"Matcher",
"<",
"VariableTree",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"VariableTree",
"variableTree",
",",
"VisitorState",
"state",
")",
"{",
"return",
"treeMatcher",
".",
"matches",
"(",
"variableTree",
".",
"getType",
"(",
")",
",",
"state",
")",
";",
"}",
"}",
";",
"}"
] |
Matches on the type of a VariableTree AST node.
@param treeMatcher A matcher on the type of the variable.
|
[
"Matches",
"on",
"the",
"type",
"of",
"a",
"VariableTree",
"AST",
"node",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L1070-L1077
|
21,749
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.variableInitializer
|
public static Matcher<VariableTree> variableInitializer(
final Matcher<ExpressionTree> expressionTreeMatcher) {
return new Matcher<VariableTree>() {
@Override
public boolean matches(VariableTree variableTree, VisitorState state) {
ExpressionTree initializer = variableTree.getInitializer();
return initializer == null ? false : expressionTreeMatcher.matches(initializer, state);
}
};
}
|
java
|
public static Matcher<VariableTree> variableInitializer(
final Matcher<ExpressionTree> expressionTreeMatcher) {
return new Matcher<VariableTree>() {
@Override
public boolean matches(VariableTree variableTree, VisitorState state) {
ExpressionTree initializer = variableTree.getInitializer();
return initializer == null ? false : expressionTreeMatcher.matches(initializer, state);
}
};
}
|
[
"public",
"static",
"Matcher",
"<",
"VariableTree",
">",
"variableInitializer",
"(",
"final",
"Matcher",
"<",
"ExpressionTree",
">",
"expressionTreeMatcher",
")",
"{",
"return",
"new",
"Matcher",
"<",
"VariableTree",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"VariableTree",
"variableTree",
",",
"VisitorState",
"state",
")",
"{",
"ExpressionTree",
"initializer",
"=",
"variableTree",
".",
"getInitializer",
"(",
")",
";",
"return",
"initializer",
"==",
"null",
"?",
"false",
":",
"expressionTreeMatcher",
".",
"matches",
"(",
"initializer",
",",
"state",
")",
";",
"}",
"}",
";",
"}"
] |
Matches on the initializer of a VariableTree AST node.
@param expressionTreeMatcher A matcher on the initializer of the variable.
|
[
"Matches",
"on",
"the",
"initializer",
"of",
"a",
"VariableTree",
"AST",
"node",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L1084-L1093
|
21,750
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.nestingKind
|
public static Matcher<ClassTree> nestingKind(final NestingKind kind) {
return new Matcher<ClassTree>() {
@Override
public boolean matches(ClassTree classTree, VisitorState state) {
ClassSymbol sym = ASTHelpers.getSymbol(classTree);
return sym.getNestingKind() == kind;
}
};
}
|
java
|
public static Matcher<ClassTree> nestingKind(final NestingKind kind) {
return new Matcher<ClassTree>() {
@Override
public boolean matches(ClassTree classTree, VisitorState state) {
ClassSymbol sym = ASTHelpers.getSymbol(classTree);
return sym.getNestingKind() == kind;
}
};
}
|
[
"public",
"static",
"Matcher",
"<",
"ClassTree",
">",
"nestingKind",
"(",
"final",
"NestingKind",
"kind",
")",
"{",
"return",
"new",
"Matcher",
"<",
"ClassTree",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"ClassTree",
"classTree",
",",
"VisitorState",
"state",
")",
"{",
"ClassSymbol",
"sym",
"=",
"ASTHelpers",
".",
"getSymbol",
"(",
"classTree",
")",
";",
"return",
"sym",
".",
"getNestingKind",
"(",
")",
"==",
"kind",
";",
"}",
"}",
";",
"}"
] |
Matches an class based on whether it is nested in another class or method.
@param kind The kind of nesting to match, eg ANONYMOUS, LOCAL, MEMBER, TOP_LEVEL
|
[
"Matches",
"an",
"class",
"based",
"on",
"whether",
"it",
"is",
"nested",
"in",
"another",
"class",
"or",
"method",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L1114-L1122
|
21,751
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.isStatic
|
public static <T extends Tree> Matcher<T> isStatic() {
return new Matcher<T>() {
@Override
public boolean matches(Tree tree, VisitorState state) {
Symbol sym = ASTHelpers.getSymbol(tree);
return sym != null && sym.isStatic();
}
};
}
|
java
|
public static <T extends Tree> Matcher<T> isStatic() {
return new Matcher<T>() {
@Override
public boolean matches(Tree tree, VisitorState state) {
Symbol sym = ASTHelpers.getSymbol(tree);
return sym != null && sym.isStatic();
}
};
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Matcher",
"<",
"T",
">",
"isStatic",
"(",
")",
"{",
"return",
"new",
"Matcher",
"<",
"T",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"Tree",
"tree",
",",
"VisitorState",
"state",
")",
"{",
"Symbol",
"sym",
"=",
"ASTHelpers",
".",
"getSymbol",
"(",
"tree",
")",
";",
"return",
"sym",
"!=",
"null",
"&&",
"sym",
".",
"isStatic",
"(",
")",
";",
"}",
"}",
";",
"}"
] |
Matches an AST node that is static.
|
[
"Matches",
"an",
"AST",
"node",
"that",
"is",
"static",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L1167-L1175
|
21,752
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.isTransient
|
public static <T extends Tree> Matcher<T> isTransient() {
return new Matcher<T>() {
@Override
public boolean matches(Tree tree, VisitorState state) {
Symbol sym = ASTHelpers.getSymbol(tree);
// NOTE(yorick): there is no isTransient() on Symbol. This is what it would be.
return sym.getModifiers().contains(Modifier.TRANSIENT);
}
};
}
|
java
|
public static <T extends Tree> Matcher<T> isTransient() {
return new Matcher<T>() {
@Override
public boolean matches(Tree tree, VisitorState state) {
Symbol sym = ASTHelpers.getSymbol(tree);
// NOTE(yorick): there is no isTransient() on Symbol. This is what it would be.
return sym.getModifiers().contains(Modifier.TRANSIENT);
}
};
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Matcher",
"<",
"T",
">",
"isTransient",
"(",
")",
"{",
"return",
"new",
"Matcher",
"<",
"T",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"Tree",
"tree",
",",
"VisitorState",
"state",
")",
"{",
"Symbol",
"sym",
"=",
"ASTHelpers",
".",
"getSymbol",
"(",
"tree",
")",
";",
"// NOTE(yorick): there is no isTransient() on Symbol. This is what it would be.",
"return",
"sym",
".",
"getModifiers",
"(",
")",
".",
"contains",
"(",
"Modifier",
".",
"TRANSIENT",
")",
";",
"}",
"}",
";",
"}"
] |
Matches an AST node that is transient.
|
[
"Matches",
"an",
"AST",
"node",
"that",
"is",
"transient",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L1178-L1187
|
21,753
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.inSynchronized
|
public static final <T extends Tree> Matcher<T> inSynchronized() {
return new Matcher<T>() {
@Override
public boolean matches(T tree, VisitorState state) {
SynchronizedTree synchronizedTree =
ASTHelpers.findEnclosingNode(state.getPath(), SynchronizedTree.class);
if (synchronizedTree != null) {
return true;
}
MethodTree methodTree = ASTHelpers.findEnclosingNode(state.getPath(), MethodTree.class);
return methodTree != null
&& methodTree.getModifiers().getFlags().contains(Modifier.SYNCHRONIZED);
}
};
}
|
java
|
public static final <T extends Tree> Matcher<T> inSynchronized() {
return new Matcher<T>() {
@Override
public boolean matches(T tree, VisitorState state) {
SynchronizedTree synchronizedTree =
ASTHelpers.findEnclosingNode(state.getPath(), SynchronizedTree.class);
if (synchronizedTree != null) {
return true;
}
MethodTree methodTree = ASTHelpers.findEnclosingNode(state.getPath(), MethodTree.class);
return methodTree != null
&& methodTree.getModifiers().getFlags().contains(Modifier.SYNCHRONIZED);
}
};
}
|
[
"public",
"static",
"final",
"<",
"T",
"extends",
"Tree",
">",
"Matcher",
"<",
"T",
">",
"inSynchronized",
"(",
")",
"{",
"return",
"new",
"Matcher",
"<",
"T",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"T",
"tree",
",",
"VisitorState",
"state",
")",
"{",
"SynchronizedTree",
"synchronizedTree",
"=",
"ASTHelpers",
".",
"findEnclosingNode",
"(",
"state",
".",
"getPath",
"(",
")",
",",
"SynchronizedTree",
".",
"class",
")",
";",
"if",
"(",
"synchronizedTree",
"!=",
"null",
")",
"{",
"return",
"true",
";",
"}",
"MethodTree",
"methodTree",
"=",
"ASTHelpers",
".",
"findEnclosingNode",
"(",
"state",
".",
"getPath",
"(",
")",
",",
"MethodTree",
".",
"class",
")",
";",
"return",
"methodTree",
"!=",
"null",
"&&",
"methodTree",
".",
"getModifiers",
"(",
")",
".",
"getFlags",
"(",
")",
".",
"contains",
"(",
"Modifier",
".",
"SYNCHRONIZED",
")",
";",
"}",
"}",
";",
"}"
] |
Matches if this Tree is enclosed by either a synchronized block or a synchronized method.
|
[
"Matches",
"if",
"this",
"Tree",
"is",
"enclosed",
"by",
"either",
"a",
"synchronized",
"block",
"or",
"a",
"synchronized",
"method",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L1255-L1270
|
21,754
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.sameVariable
|
public static Matcher<ExpressionTree> sameVariable(final ExpressionTree expr) {
return new Matcher<ExpressionTree>() {
@Override
public boolean matches(ExpressionTree tree, VisitorState state) {
return ASTHelpers.sameVariable(tree, expr);
}
};
}
|
java
|
public static Matcher<ExpressionTree> sameVariable(final ExpressionTree expr) {
return new Matcher<ExpressionTree>() {
@Override
public boolean matches(ExpressionTree tree, VisitorState state) {
return ASTHelpers.sameVariable(tree, expr);
}
};
}
|
[
"public",
"static",
"Matcher",
"<",
"ExpressionTree",
">",
"sameVariable",
"(",
"final",
"ExpressionTree",
"expr",
")",
"{",
"return",
"new",
"Matcher",
"<",
"ExpressionTree",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"ExpressionTree",
"tree",
",",
"VisitorState",
"state",
")",
"{",
"return",
"ASTHelpers",
".",
"sameVariable",
"(",
"tree",
",",
"expr",
")",
";",
"}",
"}",
";",
"}"
] |
Matches if this ExpressionTree refers to the same variable as the one passed into the matcher.
|
[
"Matches",
"if",
"this",
"ExpressionTree",
"refers",
"to",
"the",
"same",
"variable",
"as",
"the",
"one",
"passed",
"into",
"the",
"matcher",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L1275-L1282
|
21,755
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.enhancedForLoop
|
public static Matcher<EnhancedForLoopTree> enhancedForLoop(
final Matcher<VariableTree> variableMatcher,
final Matcher<ExpressionTree> expressionMatcher,
final Matcher<StatementTree> statementMatcher) {
return new Matcher<EnhancedForLoopTree>() {
@Override
public boolean matches(EnhancedForLoopTree t, VisitorState state) {
return variableMatcher.matches(t.getVariable(), state)
&& expressionMatcher.matches(t.getExpression(), state)
&& statementMatcher.matches(t.getStatement(), state);
}
};
}
|
java
|
public static Matcher<EnhancedForLoopTree> enhancedForLoop(
final Matcher<VariableTree> variableMatcher,
final Matcher<ExpressionTree> expressionMatcher,
final Matcher<StatementTree> statementMatcher) {
return new Matcher<EnhancedForLoopTree>() {
@Override
public boolean matches(EnhancedForLoopTree t, VisitorState state) {
return variableMatcher.matches(t.getVariable(), state)
&& expressionMatcher.matches(t.getExpression(), state)
&& statementMatcher.matches(t.getStatement(), state);
}
};
}
|
[
"public",
"static",
"Matcher",
"<",
"EnhancedForLoopTree",
">",
"enhancedForLoop",
"(",
"final",
"Matcher",
"<",
"VariableTree",
">",
"variableMatcher",
",",
"final",
"Matcher",
"<",
"ExpressionTree",
">",
"expressionMatcher",
",",
"final",
"Matcher",
"<",
"StatementTree",
">",
"statementMatcher",
")",
"{",
"return",
"new",
"Matcher",
"<",
"EnhancedForLoopTree",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"EnhancedForLoopTree",
"t",
",",
"VisitorState",
"state",
")",
"{",
"return",
"variableMatcher",
".",
"matches",
"(",
"t",
".",
"getVariable",
"(",
")",
",",
"state",
")",
"&&",
"expressionMatcher",
".",
"matches",
"(",
"t",
".",
"getExpression",
"(",
")",
",",
"state",
")",
"&&",
"statementMatcher",
".",
"matches",
"(",
"t",
".",
"getStatement",
"(",
")",
",",
"state",
")",
";",
"}",
"}",
";",
"}"
] |
Matches an enhanced for loop if all the given matchers match.
@param variableMatcher The matcher to apply to the variable.
@param expressionMatcher The matcher to apply to the expression.
@param statementMatcher The matcher to apply to the statement.
|
[
"Matches",
"an",
"enhanced",
"for",
"loop",
"if",
"all",
"the",
"given",
"matchers",
"match",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L1301-L1313
|
21,756
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.inLoop
|
public static <T extends Tree> Matcher<T> inLoop() {
return new Matcher<T>() {
@Override
public boolean matches(Tree tree, VisitorState state) {
TreePath path = state.getPath().getParentPath();
Tree node = path.getLeaf();
while (path != null) {
switch (node.getKind()) {
case METHOD:
case CLASS:
return false;
case WHILE_LOOP:
case FOR_LOOP:
case ENHANCED_FOR_LOOP:
case DO_WHILE_LOOP:
return true;
default:
path = path.getParentPath();
node = path.getLeaf();
break;
}
}
return false;
}
};
}
|
java
|
public static <T extends Tree> Matcher<T> inLoop() {
return new Matcher<T>() {
@Override
public boolean matches(Tree tree, VisitorState state) {
TreePath path = state.getPath().getParentPath();
Tree node = path.getLeaf();
while (path != null) {
switch (node.getKind()) {
case METHOD:
case CLASS:
return false;
case WHILE_LOOP:
case FOR_LOOP:
case ENHANCED_FOR_LOOP:
case DO_WHILE_LOOP:
return true;
default:
path = path.getParentPath();
node = path.getLeaf();
break;
}
}
return false;
}
};
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Matcher",
"<",
"T",
">",
"inLoop",
"(",
")",
"{",
"return",
"new",
"Matcher",
"<",
"T",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"Tree",
"tree",
",",
"VisitorState",
"state",
")",
"{",
"TreePath",
"path",
"=",
"state",
".",
"getPath",
"(",
")",
".",
"getParentPath",
"(",
")",
";",
"Tree",
"node",
"=",
"path",
".",
"getLeaf",
"(",
")",
";",
"while",
"(",
"path",
"!=",
"null",
")",
"{",
"switch",
"(",
"node",
".",
"getKind",
"(",
")",
")",
"{",
"case",
"METHOD",
":",
"case",
"CLASS",
":",
"return",
"false",
";",
"case",
"WHILE_LOOP",
":",
"case",
"FOR_LOOP",
":",
"case",
"ENHANCED_FOR_LOOP",
":",
"case",
"DO_WHILE_LOOP",
":",
"return",
"true",
";",
"default",
":",
"path",
"=",
"path",
".",
"getParentPath",
"(",
")",
";",
"node",
"=",
"path",
".",
"getLeaf",
"(",
")",
";",
"break",
";",
"}",
"}",
"return",
"false",
";",
"}",
"}",
";",
"}"
] |
Matches if the given tree is inside a loop.
|
[
"Matches",
"if",
"the",
"given",
"tree",
"is",
"inside",
"a",
"loop",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L1316-L1341
|
21,757
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.assignment
|
public static Matcher<AssignmentTree> assignment(
final Matcher<ExpressionTree> variableMatcher,
final Matcher<? super ExpressionTree> expressionMatcher) {
return new Matcher<AssignmentTree>() {
@Override
public boolean matches(AssignmentTree t, VisitorState state) {
return variableMatcher.matches(t.getVariable(), state)
&& expressionMatcher.matches(t.getExpression(), state);
}
};
}
|
java
|
public static Matcher<AssignmentTree> assignment(
final Matcher<ExpressionTree> variableMatcher,
final Matcher<? super ExpressionTree> expressionMatcher) {
return new Matcher<AssignmentTree>() {
@Override
public boolean matches(AssignmentTree t, VisitorState state) {
return variableMatcher.matches(t.getVariable(), state)
&& expressionMatcher.matches(t.getExpression(), state);
}
};
}
|
[
"public",
"static",
"Matcher",
"<",
"AssignmentTree",
">",
"assignment",
"(",
"final",
"Matcher",
"<",
"ExpressionTree",
">",
"variableMatcher",
",",
"final",
"Matcher",
"<",
"?",
"super",
"ExpressionTree",
">",
"expressionMatcher",
")",
"{",
"return",
"new",
"Matcher",
"<",
"AssignmentTree",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"AssignmentTree",
"t",
",",
"VisitorState",
"state",
")",
"{",
"return",
"variableMatcher",
".",
"matches",
"(",
"t",
".",
"getVariable",
"(",
")",
",",
"state",
")",
"&&",
"expressionMatcher",
".",
"matches",
"(",
"t",
".",
"getExpression",
"(",
")",
",",
"state",
")",
";",
"}",
"}",
";",
"}"
] |
Matches an assignment operator AST node if both of the given matchers match.
@param variableMatcher The matcher to apply to the variable.
@param expressionMatcher The matcher to apply to the expression.
|
[
"Matches",
"an",
"assignment",
"operator",
"AST",
"node",
"if",
"both",
"of",
"the",
"given",
"matchers",
"match",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L1349-L1359
|
21,758
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.typeCast
|
public static Matcher<TypeCastTree> typeCast(
final Matcher<Tree> typeMatcher, final Matcher<ExpressionTree> expressionMatcher) {
return new Matcher<TypeCastTree>() {
@Override
public boolean matches(TypeCastTree t, VisitorState state) {
return typeMatcher.matches(t.getType(), state)
&& expressionMatcher.matches(t.getExpression(), state);
}
};
}
|
java
|
public static Matcher<TypeCastTree> typeCast(
final Matcher<Tree> typeMatcher, final Matcher<ExpressionTree> expressionMatcher) {
return new Matcher<TypeCastTree>() {
@Override
public boolean matches(TypeCastTree t, VisitorState state) {
return typeMatcher.matches(t.getType(), state)
&& expressionMatcher.matches(t.getExpression(), state);
}
};
}
|
[
"public",
"static",
"Matcher",
"<",
"TypeCastTree",
">",
"typeCast",
"(",
"final",
"Matcher",
"<",
"Tree",
">",
"typeMatcher",
",",
"final",
"Matcher",
"<",
"ExpressionTree",
">",
"expressionMatcher",
")",
"{",
"return",
"new",
"Matcher",
"<",
"TypeCastTree",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"TypeCastTree",
"t",
",",
"VisitorState",
"state",
")",
"{",
"return",
"typeMatcher",
".",
"matches",
"(",
"t",
".",
"getType",
"(",
")",
",",
"state",
")",
"&&",
"expressionMatcher",
".",
"matches",
"(",
"t",
".",
"getExpression",
"(",
")",
",",
"state",
")",
";",
"}",
"}",
";",
"}"
] |
Matches a type cast AST node if both of the given matchers match.
@param typeMatcher The matcher to apply to the type.
@param expressionMatcher The matcher to apply to the expression.
|
[
"Matches",
"a",
"type",
"cast",
"AST",
"node",
"if",
"both",
"of",
"the",
"given",
"matchers",
"match",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L1367-L1376
|
21,759
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.assertionWithCondition
|
public static Matcher<AssertTree> assertionWithCondition(
final Matcher<ExpressionTree> conditionMatcher) {
return new Matcher<AssertTree>() {
@Override
public boolean matches(AssertTree tree, VisitorState state) {
return conditionMatcher.matches(tree.getCondition(), state);
}
};
}
|
java
|
public static Matcher<AssertTree> assertionWithCondition(
final Matcher<ExpressionTree> conditionMatcher) {
return new Matcher<AssertTree>() {
@Override
public boolean matches(AssertTree tree, VisitorState state) {
return conditionMatcher.matches(tree.getCondition(), state);
}
};
}
|
[
"public",
"static",
"Matcher",
"<",
"AssertTree",
">",
"assertionWithCondition",
"(",
"final",
"Matcher",
"<",
"ExpressionTree",
">",
"conditionMatcher",
")",
"{",
"return",
"new",
"Matcher",
"<",
"AssertTree",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"AssertTree",
"tree",
",",
"VisitorState",
"state",
")",
"{",
"return",
"conditionMatcher",
".",
"matches",
"(",
"tree",
".",
"getCondition",
"(",
")",
",",
"state",
")",
";",
"}",
"}",
";",
"}"
] |
Matches an assertion AST node if the given matcher matches its condition.
@param conditionMatcher The matcher to apply to the condition in the assertion, e.g. in "assert
false", the "false" part of the statement
|
[
"Matches",
"an",
"assertion",
"AST",
"node",
"if",
"the",
"given",
"matcher",
"matches",
"its",
"condition",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L1384-L1392
|
21,760
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.contains
|
public static <T extends Tree, V extends Tree> Matcher<T> contains(
Class<V> clazz, Matcher<V> treeMatcher) {
final Matcher<Tree> contains = new Contains(toType(clazz, treeMatcher));
return contains::matches;
}
|
java
|
public static <T extends Tree, V extends Tree> Matcher<T> contains(
Class<V> clazz, Matcher<V> treeMatcher) {
final Matcher<Tree> contains = new Contains(toType(clazz, treeMatcher));
return contains::matches;
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
",",
"V",
"extends",
"Tree",
">",
"Matcher",
"<",
"T",
">",
"contains",
"(",
"Class",
"<",
"V",
">",
"clazz",
",",
"Matcher",
"<",
"V",
">",
"treeMatcher",
")",
"{",
"final",
"Matcher",
"<",
"Tree",
">",
"contains",
"=",
"new",
"Contains",
"(",
"toType",
"(",
"clazz",
",",
"treeMatcher",
")",
")",
";",
"return",
"contains",
"::",
"matches",
";",
"}"
] |
Applies the given matcher recursively to all descendants of an AST node, and matches if any
matching descendant node is found.
@param clazz The type of node to be matched.
@param treeMatcher The matcher to apply recursively to the tree.
|
[
"Applies",
"the",
"given",
"matcher",
"recursively",
"to",
"all",
"descendants",
"of",
"an",
"AST",
"node",
"and",
"matches",
"if",
"any",
"matching",
"descendant",
"node",
"is",
"found",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L1411-L1415
|
21,761
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.methodHasArity
|
public static Matcher<MethodTree> methodHasArity(final int arity) {
return new Matcher<MethodTree>() {
@Override
public boolean matches(MethodTree methodTree, VisitorState state) {
return methodTree.getParameters().size() == arity;
}
};
}
|
java
|
public static Matcher<MethodTree> methodHasArity(final int arity) {
return new Matcher<MethodTree>() {
@Override
public boolean matches(MethodTree methodTree, VisitorState state) {
return methodTree.getParameters().size() == arity;
}
};
}
|
[
"public",
"static",
"Matcher",
"<",
"MethodTree",
">",
"methodHasArity",
"(",
"final",
"int",
"arity",
")",
"{",
"return",
"new",
"Matcher",
"<",
"MethodTree",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"MethodTree",
"methodTree",
",",
"VisitorState",
"state",
")",
"{",
"return",
"methodTree",
".",
"getParameters",
"(",
")",
".",
"size",
"(",
")",
"==",
"arity",
";",
"}",
"}",
";",
"}"
] |
Matches if the method accepts the given number of arguments.
@param arity the number of arguments the method should accept
|
[
"Matches",
"if",
"the",
"method",
"accepts",
"the",
"given",
"number",
"of",
"arguments",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L1422-L1429
|
21,762
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.isDirectImplementationOf
|
public static Matcher<ClassTree> isDirectImplementationOf(String clazz) {
Matcher<Tree> isProvidedType = isSameType(clazz);
return new IsDirectImplementationOf(isProvidedType);
}
|
java
|
public static Matcher<ClassTree> isDirectImplementationOf(String clazz) {
Matcher<Tree> isProvidedType = isSameType(clazz);
return new IsDirectImplementationOf(isProvidedType);
}
|
[
"public",
"static",
"Matcher",
"<",
"ClassTree",
">",
"isDirectImplementationOf",
"(",
"String",
"clazz",
")",
"{",
"Matcher",
"<",
"Tree",
">",
"isProvidedType",
"=",
"isSameType",
"(",
"clazz",
")",
";",
"return",
"new",
"IsDirectImplementationOf",
"(",
"isProvidedType",
")",
";",
"}"
] |
Matches any node that is directly an implementation, but not extension, of the given Class.
<p>E.x. {@code class C implements I} will match, but {@code class C extends A} will not.
<p>Additionally, this will only match <i>direct</i> implementations of interfaces. E.g. the
following will not match:
<p>{@code interface I1 {} interface I2 extends I1 {} class C implements I2 {} ...
isDirectImplementationOf(I1).match(\/*class tree for C*\/); // will not match }
|
[
"Matches",
"any",
"node",
"that",
"is",
"directly",
"an",
"implementation",
"but",
"not",
"extension",
"of",
"the",
"given",
"Class",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L1442-L1445
|
21,763
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.packageMatches
|
public static <T extends Tree> Matcher<T> packageMatches(Pattern pattern) {
return (tree, state) -> pattern.matcher(getPackageFullName(state)).matches();
}
|
java
|
public static <T extends Tree> Matcher<T> packageMatches(Pattern pattern) {
return (tree, state) -> pattern.matcher(getPackageFullName(state)).matches();
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Matcher",
"<",
"T",
">",
"packageMatches",
"(",
"Pattern",
"pattern",
")",
"{",
"return",
"(",
"tree",
",",
"state",
")",
"->",
"pattern",
".",
"matcher",
"(",
"getPackageFullName",
"(",
"state",
")",
")",
".",
"matches",
"(",
")",
";",
"}"
] |
Matches an AST node whose compilation unit's package name matches the given pattern.
|
[
"Matches",
"an",
"AST",
"node",
"whose",
"compilation",
"unit",
"s",
"package",
"name",
"matches",
"the",
"given",
"pattern",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L1476-L1478
|
21,764
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/Matchers.java
|
Matchers.packageStartsWith
|
public static <T extends Tree> Matcher<T> packageStartsWith(String prefix) {
return (tree, state) -> getPackageFullName(state).startsWith(prefix);
}
|
java
|
public static <T extends Tree> Matcher<T> packageStartsWith(String prefix) {
return (tree, state) -> getPackageFullName(state).startsWith(prefix);
}
|
[
"public",
"static",
"<",
"T",
"extends",
"Tree",
">",
"Matcher",
"<",
"T",
">",
"packageStartsWith",
"(",
"String",
"prefix",
")",
"{",
"return",
"(",
"tree",
",",
"state",
")",
"->",
"getPackageFullName",
"(",
"state",
")",
".",
"startsWith",
"(",
"prefix",
")",
";",
"}"
] |
Matches an AST node whose compilation unit starts with this prefix.
|
[
"Matches",
"an",
"AST",
"node",
"whose",
"compilation",
"unit",
"starts",
"with",
"this",
"prefix",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/Matchers.java#L1481-L1483
|
21,765
|
google/error-prone
|
core/src/main/java/com/google/errorprone/refaster/UTry.java
|
UTry.inlineFinallyBlock
|
@Nullable
private JCBlock inlineFinallyBlock(Inliner inliner) throws CouldNotResolveImportException {
if (getFinallyBlock() != null) {
JCBlock block = getFinallyBlock().inline(inliner);
if (!block.getStatements().isEmpty()) {
return block;
}
}
return null;
}
|
java
|
@Nullable
private JCBlock inlineFinallyBlock(Inliner inliner) throws CouldNotResolveImportException {
if (getFinallyBlock() != null) {
JCBlock block = getFinallyBlock().inline(inliner);
if (!block.getStatements().isEmpty()) {
return block;
}
}
return null;
}
|
[
"@",
"Nullable",
"private",
"JCBlock",
"inlineFinallyBlock",
"(",
"Inliner",
"inliner",
")",
"throws",
"CouldNotResolveImportException",
"{",
"if",
"(",
"getFinallyBlock",
"(",
")",
"!=",
"null",
")",
"{",
"JCBlock",
"block",
"=",
"getFinallyBlock",
"(",
")",
".",
"inline",
"(",
"inliner",
")",
";",
"if",
"(",
"!",
"block",
".",
"getStatements",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"block",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Skips the finally block if the result would be empty.
|
[
"Skips",
"the",
"finally",
"block",
"if",
"the",
"result",
"would",
"be",
"empty",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/refaster/UTry.java#L81-L90
|
21,766
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/inject/dagger/RefersToDaggerCodegen.java
|
RefersToDaggerCodegen.isGeneratedFactoryType
|
private static boolean isGeneratedFactoryType(ClassSymbol symbol, VisitorState state) {
// TODO(ronshapiro): check annotation creators, inaccessible map key proxies, or inaccessible
// module constructor proxies?
return GENERATED_BASE_TYPES.stream()
.anyMatch(baseType -> isGeneratedBaseType(symbol, state, baseType));
}
|
java
|
private static boolean isGeneratedFactoryType(ClassSymbol symbol, VisitorState state) {
// TODO(ronshapiro): check annotation creators, inaccessible map key proxies, or inaccessible
// module constructor proxies?
return GENERATED_BASE_TYPES.stream()
.anyMatch(baseType -> isGeneratedBaseType(symbol, state, baseType));
}
|
[
"private",
"static",
"boolean",
"isGeneratedFactoryType",
"(",
"ClassSymbol",
"symbol",
",",
"VisitorState",
"state",
")",
"{",
"// TODO(ronshapiro): check annotation creators, inaccessible map key proxies, or inaccessible",
"// module constructor proxies?",
"return",
"GENERATED_BASE_TYPES",
".",
"stream",
"(",
")",
".",
"anyMatch",
"(",
"baseType",
"->",
"isGeneratedBaseType",
"(",
"symbol",
",",
"state",
",",
"baseType",
")",
")",
";",
"}"
] |
instead of checking for subtypes of generated code
|
[
"instead",
"of",
"checking",
"for",
"subtypes",
"of",
"generated",
"code"
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/inject/dagger/RefersToDaggerCodegen.java#L93-L98
|
21,767
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ImmutableAnalysis.java
|
ImmutableAnalysis.areFieldsImmutable
|
Violation areFieldsImmutable(
Optional<ClassTree> tree,
ImmutableSet<String> immutableTyParams,
ClassType classType,
ViolationReporter reporter) {
ClassSymbol classSym = (ClassSymbol) classType.tsym;
if (classSym.members() == null) {
return Violation.absent();
}
Filter<Symbol> instanceFieldFilter =
new Filter<Symbol>() {
@Override
public boolean accepts(Symbol symbol) {
return symbol.getKind() == ElementKind.FIELD && !symbol.isStatic();
}
};
Map<Symbol, Tree> declarations = new HashMap<>();
if (tree.isPresent()) {
for (Tree member : tree.get().getMembers()) {
Symbol sym = ASTHelpers.getSymbol(member);
if (sym != null) {
declarations.put(sym, member);
}
}
}
// javac gives us members in reverse declaration order
// handling them in declaration order leads to marginally better diagnostics
List<Symbol> members =
ImmutableList.copyOf(classSym.members().getSymbols(instanceFieldFilter)).reverse();
for (Symbol member : members) {
Optional<Tree> memberTree = Optional.ofNullable(declarations.get(member));
Violation info =
isFieldImmutable(
memberTree, immutableTyParams, classSym, classType, (VarSymbol) member, reporter);
if (info.isPresent()) {
return info;
}
}
return Violation.absent();
}
|
java
|
Violation areFieldsImmutable(
Optional<ClassTree> tree,
ImmutableSet<String> immutableTyParams,
ClassType classType,
ViolationReporter reporter) {
ClassSymbol classSym = (ClassSymbol) classType.tsym;
if (classSym.members() == null) {
return Violation.absent();
}
Filter<Symbol> instanceFieldFilter =
new Filter<Symbol>() {
@Override
public boolean accepts(Symbol symbol) {
return symbol.getKind() == ElementKind.FIELD && !symbol.isStatic();
}
};
Map<Symbol, Tree> declarations = new HashMap<>();
if (tree.isPresent()) {
for (Tree member : tree.get().getMembers()) {
Symbol sym = ASTHelpers.getSymbol(member);
if (sym != null) {
declarations.put(sym, member);
}
}
}
// javac gives us members in reverse declaration order
// handling them in declaration order leads to marginally better diagnostics
List<Symbol> members =
ImmutableList.copyOf(classSym.members().getSymbols(instanceFieldFilter)).reverse();
for (Symbol member : members) {
Optional<Tree> memberTree = Optional.ofNullable(declarations.get(member));
Violation info =
isFieldImmutable(
memberTree, immutableTyParams, classSym, classType, (VarSymbol) member, reporter);
if (info.isPresent()) {
return info;
}
}
return Violation.absent();
}
|
[
"Violation",
"areFieldsImmutable",
"(",
"Optional",
"<",
"ClassTree",
">",
"tree",
",",
"ImmutableSet",
"<",
"String",
">",
"immutableTyParams",
",",
"ClassType",
"classType",
",",
"ViolationReporter",
"reporter",
")",
"{",
"ClassSymbol",
"classSym",
"=",
"(",
"ClassSymbol",
")",
"classType",
".",
"tsym",
";",
"if",
"(",
"classSym",
".",
"members",
"(",
")",
"==",
"null",
")",
"{",
"return",
"Violation",
".",
"absent",
"(",
")",
";",
"}",
"Filter",
"<",
"Symbol",
">",
"instanceFieldFilter",
"=",
"new",
"Filter",
"<",
"Symbol",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"accepts",
"(",
"Symbol",
"symbol",
")",
"{",
"return",
"symbol",
".",
"getKind",
"(",
")",
"==",
"ElementKind",
".",
"FIELD",
"&&",
"!",
"symbol",
".",
"isStatic",
"(",
")",
";",
"}",
"}",
";",
"Map",
"<",
"Symbol",
",",
"Tree",
">",
"declarations",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"if",
"(",
"tree",
".",
"isPresent",
"(",
")",
")",
"{",
"for",
"(",
"Tree",
"member",
":",
"tree",
".",
"get",
"(",
")",
".",
"getMembers",
"(",
")",
")",
"{",
"Symbol",
"sym",
"=",
"ASTHelpers",
".",
"getSymbol",
"(",
"member",
")",
";",
"if",
"(",
"sym",
"!=",
"null",
")",
"{",
"declarations",
".",
"put",
"(",
"sym",
",",
"member",
")",
";",
"}",
"}",
"}",
"// javac gives us members in reverse declaration order",
"// handling them in declaration order leads to marginally better diagnostics",
"List",
"<",
"Symbol",
">",
"members",
"=",
"ImmutableList",
".",
"copyOf",
"(",
"classSym",
".",
"members",
"(",
")",
".",
"getSymbols",
"(",
"instanceFieldFilter",
")",
")",
".",
"reverse",
"(",
")",
";",
"for",
"(",
"Symbol",
"member",
":",
"members",
")",
"{",
"Optional",
"<",
"Tree",
">",
"memberTree",
"=",
"Optional",
".",
"ofNullable",
"(",
"declarations",
".",
"get",
"(",
"member",
")",
")",
";",
"Violation",
"info",
"=",
"isFieldImmutable",
"(",
"memberTree",
",",
"immutableTyParams",
",",
"classSym",
",",
"classType",
",",
"(",
"VarSymbol",
")",
"member",
",",
"reporter",
")",
";",
"if",
"(",
"info",
".",
"isPresent",
"(",
")",
")",
"{",
"return",
"info",
";",
"}",
"}",
"return",
"Violation",
".",
"absent",
"(",
")",
";",
"}"
] |
Check a single class' fields for immutability.
@param immutableTyParams the in-scope immutable type parameters
@param classType the type to check the fields of
|
[
"Check",
"a",
"single",
"class",
"fields",
"for",
"immutability",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ImmutableAnalysis.java#L222-L261
|
21,768
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ImmutableAnalysis.java
|
ImmutableAnalysis.isFieldImmutable
|
private Violation isFieldImmutable(
Optional<Tree> tree,
ImmutableSet<String> immutableTyParams,
ClassSymbol classSym,
ClassType classType,
VarSymbol var,
ViolationReporter reporter) {
if (bugChecker.isSuppressed(var)) {
return Violation.absent();
}
if (!var.getModifiers().contains(Modifier.FINAL)
&& !ASTHelpers.hasAnnotation(var, LazyInit.class, state)) {
Violation info =
Violation.of(
String.format(
"'%s' has non-final field '%s'",
threadSafety.getPrettyName(classSym), var.getSimpleName()));
if (tree.isPresent()) {
// If we have a tree to attach diagnostics to, report the error immediately instead of
// accumulating the path to the error from the top-level class being checked
state.reportMatch(
reporter.report(
tree.get(), info, SuggestedFixes.addModifiers(tree.get(), state, Modifier.FINAL)));
return Violation.absent();
}
return info;
}
Type varType = state.getTypes().memberType(classType, var);
Violation info =
threadSafety.isThreadSafeType(
/* allowContainerTypeParameters= */ true, immutableTyParams, varType);
if (info.isPresent()) {
info =
info.plus(
String.format(
"'%s' has field '%s' of type '%s'",
threadSafety.getPrettyName(classSym), var.getSimpleName(), varType));
if (tree.isPresent()) {
// If we have a tree to attach diagnostics to, report the error immediately instead of
// accumulating the path to the error from the top-level class being checked
state.reportMatch(reporter.report(tree.get(), info, Optional.empty()));
return Violation.absent();
}
return info;
}
return Violation.absent();
}
|
java
|
private Violation isFieldImmutable(
Optional<Tree> tree,
ImmutableSet<String> immutableTyParams,
ClassSymbol classSym,
ClassType classType,
VarSymbol var,
ViolationReporter reporter) {
if (bugChecker.isSuppressed(var)) {
return Violation.absent();
}
if (!var.getModifiers().contains(Modifier.FINAL)
&& !ASTHelpers.hasAnnotation(var, LazyInit.class, state)) {
Violation info =
Violation.of(
String.format(
"'%s' has non-final field '%s'",
threadSafety.getPrettyName(classSym), var.getSimpleName()));
if (tree.isPresent()) {
// If we have a tree to attach diagnostics to, report the error immediately instead of
// accumulating the path to the error from the top-level class being checked
state.reportMatch(
reporter.report(
tree.get(), info, SuggestedFixes.addModifiers(tree.get(), state, Modifier.FINAL)));
return Violation.absent();
}
return info;
}
Type varType = state.getTypes().memberType(classType, var);
Violation info =
threadSafety.isThreadSafeType(
/* allowContainerTypeParameters= */ true, immutableTyParams, varType);
if (info.isPresent()) {
info =
info.plus(
String.format(
"'%s' has field '%s' of type '%s'",
threadSafety.getPrettyName(classSym), var.getSimpleName(), varType));
if (tree.isPresent()) {
// If we have a tree to attach diagnostics to, report the error immediately instead of
// accumulating the path to the error from the top-level class being checked
state.reportMatch(reporter.report(tree.get(), info, Optional.empty()));
return Violation.absent();
}
return info;
}
return Violation.absent();
}
|
[
"private",
"Violation",
"isFieldImmutable",
"(",
"Optional",
"<",
"Tree",
">",
"tree",
",",
"ImmutableSet",
"<",
"String",
">",
"immutableTyParams",
",",
"ClassSymbol",
"classSym",
",",
"ClassType",
"classType",
",",
"VarSymbol",
"var",
",",
"ViolationReporter",
"reporter",
")",
"{",
"if",
"(",
"bugChecker",
".",
"isSuppressed",
"(",
"var",
")",
")",
"{",
"return",
"Violation",
".",
"absent",
"(",
")",
";",
"}",
"if",
"(",
"!",
"var",
".",
"getModifiers",
"(",
")",
".",
"contains",
"(",
"Modifier",
".",
"FINAL",
")",
"&&",
"!",
"ASTHelpers",
".",
"hasAnnotation",
"(",
"var",
",",
"LazyInit",
".",
"class",
",",
"state",
")",
")",
"{",
"Violation",
"info",
"=",
"Violation",
".",
"of",
"(",
"String",
".",
"format",
"(",
"\"'%s' has non-final field '%s'\"",
",",
"threadSafety",
".",
"getPrettyName",
"(",
"classSym",
")",
",",
"var",
".",
"getSimpleName",
"(",
")",
")",
")",
";",
"if",
"(",
"tree",
".",
"isPresent",
"(",
")",
")",
"{",
"// If we have a tree to attach diagnostics to, report the error immediately instead of",
"// accumulating the path to the error from the top-level class being checked",
"state",
".",
"reportMatch",
"(",
"reporter",
".",
"report",
"(",
"tree",
".",
"get",
"(",
")",
",",
"info",
",",
"SuggestedFixes",
".",
"addModifiers",
"(",
"tree",
".",
"get",
"(",
")",
",",
"state",
",",
"Modifier",
".",
"FINAL",
")",
")",
")",
";",
"return",
"Violation",
".",
"absent",
"(",
")",
";",
"}",
"return",
"info",
";",
"}",
"Type",
"varType",
"=",
"state",
".",
"getTypes",
"(",
")",
".",
"memberType",
"(",
"classType",
",",
"var",
")",
";",
"Violation",
"info",
"=",
"threadSafety",
".",
"isThreadSafeType",
"(",
"/* allowContainerTypeParameters= */",
"true",
",",
"immutableTyParams",
",",
"varType",
")",
";",
"if",
"(",
"info",
".",
"isPresent",
"(",
")",
")",
"{",
"info",
"=",
"info",
".",
"plus",
"(",
"String",
".",
"format",
"(",
"\"'%s' has field '%s' of type '%s'\"",
",",
"threadSafety",
".",
"getPrettyName",
"(",
"classSym",
")",
",",
"var",
".",
"getSimpleName",
"(",
")",
",",
"varType",
")",
")",
";",
"if",
"(",
"tree",
".",
"isPresent",
"(",
")",
")",
"{",
"// If we have a tree to attach diagnostics to, report the error immediately instead of",
"// accumulating the path to the error from the top-level class being checked",
"state",
".",
"reportMatch",
"(",
"reporter",
".",
"report",
"(",
"tree",
".",
"get",
"(",
")",
",",
"info",
",",
"Optional",
".",
"empty",
"(",
")",
")",
")",
";",
"return",
"Violation",
".",
"absent",
"(",
")",
";",
"}",
"return",
"info",
";",
"}",
"return",
"Violation",
".",
"absent",
"(",
")",
";",
"}"
] |
Check a single field for immutability.
|
[
"Check",
"a",
"single",
"field",
"for",
"immutability",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/threadsafety/ImmutableAnalysis.java#L264-L311
|
21,769
|
google/error-prone
|
core/src/main/java/com/google/errorprone/ErrorProneCompiler.java
|
ErrorProneCompiler.compile
|
public static Result compile(DiagnosticListener<JavaFileObject> listener, String[] args) {
return ErrorProneCompiler.builder().listenToDiagnostics(listener).build().run(args);
}
|
java
|
public static Result compile(DiagnosticListener<JavaFileObject> listener, String[] args) {
return ErrorProneCompiler.builder().listenToDiagnostics(listener).build().run(args);
}
|
[
"public",
"static",
"Result",
"compile",
"(",
"DiagnosticListener",
"<",
"JavaFileObject",
">",
"listener",
",",
"String",
"[",
"]",
"args",
")",
"{",
"return",
"ErrorProneCompiler",
".",
"builder",
"(",
")",
".",
"listenToDiagnostics",
"(",
"listener",
")",
".",
"build",
"(",
")",
".",
"run",
"(",
"args",
")",
";",
"}"
] |
Compiles in-process.
@param listener listens to the diagnostics produced by error-prone
@param args the same args which would be passed to javac on the command line
@return result from the compiler invocation
|
[
"Compiles",
"in",
"-",
"process",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/ErrorProneCompiler.java#L57-L59
|
21,770
|
google/error-prone
|
core/src/main/java/com/google/errorprone/ErrorProneCompiler.java
|
ErrorProneCompiler.compile
|
public static Result compile(String[] args, PrintWriter out) {
return ErrorProneCompiler.builder().redirectOutputTo(out).build().run(args);
}
|
java
|
public static Result compile(String[] args, PrintWriter out) {
return ErrorProneCompiler.builder().redirectOutputTo(out).build().run(args);
}
|
[
"public",
"static",
"Result",
"compile",
"(",
"String",
"[",
"]",
"args",
",",
"PrintWriter",
"out",
")",
"{",
"return",
"ErrorProneCompiler",
".",
"builder",
"(",
")",
".",
"redirectOutputTo",
"(",
"out",
")",
".",
"build",
"(",
")",
".",
"run",
"(",
"args",
")",
";",
"}"
] |
Programmatic interface to the error-prone Java compiler.
@param args the same args which would be passed to javac on the command line
@param out a {@link PrintWriter} to which to send diagnostic output
@return result from the compiler invocation
|
[
"Programmatic",
"interface",
"to",
"the",
"error",
"-",
"prone",
"Java",
"compiler",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/ErrorProneCompiler.java#L78-L80
|
21,771
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/AbstractReturnValueIgnored.java
|
AbstractReturnValueIgnored.functionalInterfaceReturnsExactlyVoid
|
private static boolean functionalInterfaceReturnsExactlyVoid(
Type interfaceType, VisitorState state) {
return state.getTypes().findDescriptorType(interfaceType).getReturnType().getKind()
== TypeKind.VOID;
}
|
java
|
private static boolean functionalInterfaceReturnsExactlyVoid(
Type interfaceType, VisitorState state) {
return state.getTypes().findDescriptorType(interfaceType).getReturnType().getKind()
== TypeKind.VOID;
}
|
[
"private",
"static",
"boolean",
"functionalInterfaceReturnsExactlyVoid",
"(",
"Type",
"interfaceType",
",",
"VisitorState",
"state",
")",
"{",
"return",
"state",
".",
"getTypes",
"(",
")",
".",
"findDescriptorType",
"(",
"interfaceType",
")",
".",
"getReturnType",
"(",
")",
".",
"getKind",
"(",
")",
"==",
"TypeKind",
".",
"VOID",
";",
"}"
] |
Checks that the return value of a functional interface is void. Note, we do not use
ASTHelpers.isVoidType here, return values of Void are actually type-checked. Only
void-returning functions silently ignore return values of any type.
|
[
"Checks",
"that",
"the",
"return",
"value",
"of",
"a",
"functional",
"interface",
"is",
"void",
".",
"Note",
"we",
"do",
"not",
"use",
"ASTHelpers",
".",
"isVoidType",
"here",
"return",
"values",
"of",
"Void",
"are",
"actually",
"type",
"-",
"checked",
".",
"Only",
"void",
"-",
"returning",
"functions",
"silently",
"ignore",
"return",
"values",
"of",
"any",
"type",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/AbstractReturnValueIgnored.java#L124-L128
|
21,772
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/formatstring/FormatStringAnnotationChecker.java
|
FormatStringAnnotationChecker.matchInvocation
|
private Description matchInvocation(
ExpressionTree tree,
MethodSymbol symbol,
List<? extends ExpressionTree> args,
VisitorState state) {
if (!ASTHelpers.hasAnnotation(symbol, FormatMethod.class, state)) {
return Description.NO_MATCH;
}
Type stringType = state.getSymtab().stringType;
List<VarSymbol> params = symbol.getParameters();
int firstStringIndex = -1;
int formatString = -1;
for (int i = 0; i < params.size(); i++) {
VarSymbol param = params.get(i);
if (ASTHelpers.hasAnnotation(param, FormatString.class, state)) {
formatString = i;
break;
}
if (firstStringIndex < 0 && ASTHelpers.isSameType(params.get(i).type, stringType, state)) {
firstStringIndex = i;
}
}
if (formatString < 0) {
formatString = firstStringIndex;
}
FormatStringValidation.ValidationResult result =
StrictFormatStringValidation.validate(
args.get(formatString), args.subList(formatString + 1, args.size()), state);
if (result != null) {
return buildDescription(tree).setMessage(result.message()).build();
} else {
return Description.NO_MATCH;
}
}
|
java
|
private Description matchInvocation(
ExpressionTree tree,
MethodSymbol symbol,
List<? extends ExpressionTree> args,
VisitorState state) {
if (!ASTHelpers.hasAnnotation(symbol, FormatMethod.class, state)) {
return Description.NO_MATCH;
}
Type stringType = state.getSymtab().stringType;
List<VarSymbol> params = symbol.getParameters();
int firstStringIndex = -1;
int formatString = -1;
for (int i = 0; i < params.size(); i++) {
VarSymbol param = params.get(i);
if (ASTHelpers.hasAnnotation(param, FormatString.class, state)) {
formatString = i;
break;
}
if (firstStringIndex < 0 && ASTHelpers.isSameType(params.get(i).type, stringType, state)) {
firstStringIndex = i;
}
}
if (formatString < 0) {
formatString = firstStringIndex;
}
FormatStringValidation.ValidationResult result =
StrictFormatStringValidation.validate(
args.get(formatString), args.subList(formatString + 1, args.size()), state);
if (result != null) {
return buildDescription(tree).setMessage(result.message()).build();
} else {
return Description.NO_MATCH;
}
}
|
[
"private",
"Description",
"matchInvocation",
"(",
"ExpressionTree",
"tree",
",",
"MethodSymbol",
"symbol",
",",
"List",
"<",
"?",
"extends",
"ExpressionTree",
">",
"args",
",",
"VisitorState",
"state",
")",
"{",
"if",
"(",
"!",
"ASTHelpers",
".",
"hasAnnotation",
"(",
"symbol",
",",
"FormatMethod",
".",
"class",
",",
"state",
")",
")",
"{",
"return",
"Description",
".",
"NO_MATCH",
";",
"}",
"Type",
"stringType",
"=",
"state",
".",
"getSymtab",
"(",
")",
".",
"stringType",
";",
"List",
"<",
"VarSymbol",
">",
"params",
"=",
"symbol",
".",
"getParameters",
"(",
")",
";",
"int",
"firstStringIndex",
"=",
"-",
"1",
";",
"int",
"formatString",
"=",
"-",
"1",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"params",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"VarSymbol",
"param",
"=",
"params",
".",
"get",
"(",
"i",
")",
";",
"if",
"(",
"ASTHelpers",
".",
"hasAnnotation",
"(",
"param",
",",
"FormatString",
".",
"class",
",",
"state",
")",
")",
"{",
"formatString",
"=",
"i",
";",
"break",
";",
"}",
"if",
"(",
"firstStringIndex",
"<",
"0",
"&&",
"ASTHelpers",
".",
"isSameType",
"(",
"params",
".",
"get",
"(",
"i",
")",
".",
"type",
",",
"stringType",
",",
"state",
")",
")",
"{",
"firstStringIndex",
"=",
"i",
";",
"}",
"}",
"if",
"(",
"formatString",
"<",
"0",
")",
"{",
"formatString",
"=",
"firstStringIndex",
";",
"}",
"FormatStringValidation",
".",
"ValidationResult",
"result",
"=",
"StrictFormatStringValidation",
".",
"validate",
"(",
"args",
".",
"get",
"(",
"formatString",
")",
",",
"args",
".",
"subList",
"(",
"formatString",
"+",
"1",
",",
"args",
".",
"size",
"(",
")",
")",
",",
"state",
")",
";",
"if",
"(",
"result",
"!=",
"null",
")",
"{",
"return",
"buildDescription",
"(",
"tree",
")",
".",
"setMessage",
"(",
"result",
".",
"message",
"(",
")",
")",
".",
"build",
"(",
")",
";",
"}",
"else",
"{",
"return",
"Description",
".",
"NO_MATCH",
";",
"}",
"}"
] |
Matches a method or constructor invocation. The input symbol should match the invoked method or
contructor and the args should be the parameters in the invocation.
|
[
"Matches",
"a",
"method",
"or",
"constructor",
"invocation",
".",
"The",
"input",
"symbol",
"should",
"match",
"the",
"invoked",
"method",
"or",
"contructor",
"and",
"the",
"args",
"should",
"be",
"the",
"parameters",
"in",
"the",
"invocation",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/formatstring/FormatStringAnnotationChecker.java#L54-L92
|
21,773
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/StaticImports.java
|
StaticImports.lookup
|
private static ImmutableSet<Symbol> lookup(
Symbol.TypeSymbol typeSym,
Symbol.TypeSymbol start,
Name identifier,
Types types,
Symbol.PackageSymbol pkg) {
if (typeSym == null) {
return ImmutableSet.of();
}
ImmutableSet.Builder<Symbol> members = ImmutableSet.builder();
members.addAll(lookup(types.supertype(typeSym.type).tsym, start, identifier, types, pkg));
for (Type i : types.interfaces(typeSym.type)) {
members.addAll(lookup(i.tsym, start, identifier, types, pkg));
}
OUTER:
for (Symbol member : typeSym.members().getSymbolsByName(identifier)) {
if (!member.isStatic()) {
continue;
}
switch ((int) (member.flags() & Flags.AccessFlags)) {
case Flags.PRIVATE:
continue OUTER;
case 0:
case Flags.PROTECTED:
if (member.packge() != pkg) {
continue OUTER;
}
break;
case Flags.PUBLIC:
default:
break;
}
if (member.isMemberOf(start, types)) {
members.add(member);
}
}
return members.build();
}
|
java
|
private static ImmutableSet<Symbol> lookup(
Symbol.TypeSymbol typeSym,
Symbol.TypeSymbol start,
Name identifier,
Types types,
Symbol.PackageSymbol pkg) {
if (typeSym == null) {
return ImmutableSet.of();
}
ImmutableSet.Builder<Symbol> members = ImmutableSet.builder();
members.addAll(lookup(types.supertype(typeSym.type).tsym, start, identifier, types, pkg));
for (Type i : types.interfaces(typeSym.type)) {
members.addAll(lookup(i.tsym, start, identifier, types, pkg));
}
OUTER:
for (Symbol member : typeSym.members().getSymbolsByName(identifier)) {
if (!member.isStatic()) {
continue;
}
switch ((int) (member.flags() & Flags.AccessFlags)) {
case Flags.PRIVATE:
continue OUTER;
case 0:
case Flags.PROTECTED:
if (member.packge() != pkg) {
continue OUTER;
}
break;
case Flags.PUBLIC:
default:
break;
}
if (member.isMemberOf(start, types)) {
members.add(member);
}
}
return members.build();
}
|
[
"private",
"static",
"ImmutableSet",
"<",
"Symbol",
">",
"lookup",
"(",
"Symbol",
".",
"TypeSymbol",
"typeSym",
",",
"Symbol",
".",
"TypeSymbol",
"start",
",",
"Name",
"identifier",
",",
"Types",
"types",
",",
"Symbol",
".",
"PackageSymbol",
"pkg",
")",
"{",
"if",
"(",
"typeSym",
"==",
"null",
")",
"{",
"return",
"ImmutableSet",
".",
"of",
"(",
")",
";",
"}",
"ImmutableSet",
".",
"Builder",
"<",
"Symbol",
">",
"members",
"=",
"ImmutableSet",
".",
"builder",
"(",
")",
";",
"members",
".",
"addAll",
"(",
"lookup",
"(",
"types",
".",
"supertype",
"(",
"typeSym",
".",
"type",
")",
".",
"tsym",
",",
"start",
",",
"identifier",
",",
"types",
",",
"pkg",
")",
")",
";",
"for",
"(",
"Type",
"i",
":",
"types",
".",
"interfaces",
"(",
"typeSym",
".",
"type",
")",
")",
"{",
"members",
".",
"addAll",
"(",
"lookup",
"(",
"i",
".",
"tsym",
",",
"start",
",",
"identifier",
",",
"types",
",",
"pkg",
")",
")",
";",
"}",
"OUTER",
":",
"for",
"(",
"Symbol",
"member",
":",
"typeSym",
".",
"members",
"(",
")",
".",
"getSymbolsByName",
"(",
"identifier",
")",
")",
"{",
"if",
"(",
"!",
"member",
".",
"isStatic",
"(",
")",
")",
"{",
"continue",
";",
"}",
"switch",
"(",
"(",
"int",
")",
"(",
"member",
".",
"flags",
"(",
")",
"&",
"Flags",
".",
"AccessFlags",
")",
")",
"{",
"case",
"Flags",
".",
"PRIVATE",
":",
"continue",
"OUTER",
";",
"case",
"0",
":",
"case",
"Flags",
".",
"PROTECTED",
":",
"if",
"(",
"member",
".",
"packge",
"(",
")",
"!=",
"pkg",
")",
"{",
"continue",
"OUTER",
";",
"}",
"break",
";",
"case",
"Flags",
".",
"PUBLIC",
":",
"default",
":",
"break",
";",
"}",
"if",
"(",
"member",
".",
"isMemberOf",
"(",
"start",
",",
"types",
")",
")",
"{",
"members",
".",
"add",
"(",
"member",
")",
";",
"}",
"}",
"return",
"members",
".",
"build",
"(",
")",
";",
"}"
] |
to filter on method signature.
|
[
"to",
"filter",
"on",
"method",
"signature",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/StaticImports.java#L166-L208
|
21,774
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/Costs.java
|
Costs.invalidateAllAlternatives
|
void invalidateAllAlternatives(Parameter formal) {
for (int actualIndex = 0; actualIndex < costMatrix[formal.index()].length; actualIndex++) {
if (actualIndex != formal.index()) {
costMatrix[formal.index()][actualIndex] = Double.POSITIVE_INFINITY;
}
}
}
|
java
|
void invalidateAllAlternatives(Parameter formal) {
for (int actualIndex = 0; actualIndex < costMatrix[formal.index()].length; actualIndex++) {
if (actualIndex != formal.index()) {
costMatrix[formal.index()][actualIndex] = Double.POSITIVE_INFINITY;
}
}
}
|
[
"void",
"invalidateAllAlternatives",
"(",
"Parameter",
"formal",
")",
"{",
"for",
"(",
"int",
"actualIndex",
"=",
"0",
";",
"actualIndex",
"<",
"costMatrix",
"[",
"formal",
".",
"index",
"(",
")",
"]",
".",
"length",
";",
"actualIndex",
"++",
")",
"{",
"if",
"(",
"actualIndex",
"!=",
"formal",
".",
"index",
"(",
")",
")",
"{",
"costMatrix",
"[",
"formal",
".",
"index",
"(",
")",
"]",
"[",
"actualIndex",
"]",
"=",
"Double",
".",
"POSITIVE_INFINITY",
";",
"}",
"}",
"}"
] |
Set the cost of all the alternatives for this formal parameter to be Inf.
|
[
"Set",
"the",
"cost",
"of",
"all",
"the",
"alternatives",
"for",
"this",
"formal",
"parameter",
"to",
"be",
"Inf",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/Costs.java#L98-L104
|
21,775
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/Costs.java
|
Costs.updatePair
|
void updatePair(ParameterPair p, double cost) {
costMatrix[p.formal().index()][p.actual().index()] = cost;
}
|
java
|
void updatePair(ParameterPair p, double cost) {
costMatrix[p.formal().index()][p.actual().index()] = cost;
}
|
[
"void",
"updatePair",
"(",
"ParameterPair",
"p",
",",
"double",
"cost",
")",
"{",
"costMatrix",
"[",
"p",
".",
"formal",
"(",
")",
".",
"index",
"(",
")",
"]",
"[",
"p",
".",
"actual",
"(",
")",
".",
"index",
"(",
")",
"]",
"=",
"cost",
";",
"}"
] |
Update the cost of the given pairing.
|
[
"Update",
"the",
"cost",
"of",
"the",
"given",
"pairing",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/Costs.java#L107-L109
|
21,776
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/VisitorState.java
|
VisitorState.createForUtilityPurposes
|
public static VisitorState createForUtilityPurposes(Context context) {
return new VisitorState(
context,
VisitorState::nullListener,
ImmutableMap.of(),
ErrorProneOptions.empty(),
// Can't use this VisitorState to report results, so no-op collector.
StatisticsCollector.createNoOpCollector(),
null,
null,
SuppressedState.UNSUPPRESSED);
}
|
java
|
public static VisitorState createForUtilityPurposes(Context context) {
return new VisitorState(
context,
VisitorState::nullListener,
ImmutableMap.of(),
ErrorProneOptions.empty(),
// Can't use this VisitorState to report results, so no-op collector.
StatisticsCollector.createNoOpCollector(),
null,
null,
SuppressedState.UNSUPPRESSED);
}
|
[
"public",
"static",
"VisitorState",
"createForUtilityPurposes",
"(",
"Context",
"context",
")",
"{",
"return",
"new",
"VisitorState",
"(",
"context",
",",
"VisitorState",
"::",
"nullListener",
",",
"ImmutableMap",
".",
"of",
"(",
")",
",",
"ErrorProneOptions",
".",
"empty",
"(",
")",
",",
"// Can't use this VisitorState to report results, so no-op collector.",
"StatisticsCollector",
".",
"createNoOpCollector",
"(",
")",
",",
"null",
",",
"null",
",",
"SuppressedState",
".",
"UNSUPPRESSED",
")",
";",
"}"
] |
Return a VisitorState that has no Error Prone configuration, and can't report results.
<p>If using this method, consider moving to using utility methods not needing VisitorSate
|
[
"Return",
"a",
"VisitorState",
"that",
"has",
"no",
"Error",
"Prone",
"configuration",
"and",
"can",
"t",
"report",
"results",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/VisitorState.java#L82-L93
|
21,777
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/VisitorState.java
|
VisitorState.createConfiguredForCompilation
|
public static VisitorState createConfiguredForCompilation(
Context context,
DescriptionListener listener,
Map<String, SeverityLevel> severityMap,
ErrorProneOptions errorProneOptions) {
return new VisitorState(
context,
listener,
severityMap,
errorProneOptions,
StatisticsCollector.createCollector(),
null,
null,
SuppressedState.UNSUPPRESSED);
}
|
java
|
public static VisitorState createConfiguredForCompilation(
Context context,
DescriptionListener listener,
Map<String, SeverityLevel> severityMap,
ErrorProneOptions errorProneOptions) {
return new VisitorState(
context,
listener,
severityMap,
errorProneOptions,
StatisticsCollector.createCollector(),
null,
null,
SuppressedState.UNSUPPRESSED);
}
|
[
"public",
"static",
"VisitorState",
"createConfiguredForCompilation",
"(",
"Context",
"context",
",",
"DescriptionListener",
"listener",
",",
"Map",
"<",
"String",
",",
"SeverityLevel",
">",
"severityMap",
",",
"ErrorProneOptions",
"errorProneOptions",
")",
"{",
"return",
"new",
"VisitorState",
"(",
"context",
",",
"listener",
",",
"severityMap",
",",
"errorProneOptions",
",",
"StatisticsCollector",
".",
"createCollector",
"(",
")",
",",
"null",
",",
"null",
",",
"SuppressedState",
".",
"UNSUPPRESSED",
")",
";",
"}"
] |
Return a VisitorState configured for a new compilation, including Error Prone configuration.
|
[
"Return",
"a",
"VisitorState",
"configured",
"for",
"a",
"new",
"compilation",
"including",
"Error",
"Prone",
"configuration",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/VisitorState.java#L115-L129
|
21,778
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/VisitorState.java
|
VisitorState.inferBinaryName
|
private static String inferBinaryName(String classname) {
StringBuilder sb = new StringBuilder();
boolean first = true;
char sep = '.';
for (String bit : Splitter.on('.').split(classname)) {
if (!first) {
sb.append(sep);
}
sb.append(bit);
if (Character.isUpperCase(bit.charAt(0))) {
sep = '$';
}
first = false;
}
return sb.toString();
}
|
java
|
private static String inferBinaryName(String classname) {
StringBuilder sb = new StringBuilder();
boolean first = true;
char sep = '.';
for (String bit : Splitter.on('.').split(classname)) {
if (!first) {
sb.append(sep);
}
sb.append(bit);
if (Character.isUpperCase(bit.charAt(0))) {
sep = '$';
}
first = false;
}
return sb.toString();
}
|
[
"private",
"static",
"String",
"inferBinaryName",
"(",
"String",
"classname",
")",
"{",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"boolean",
"first",
"=",
"true",
";",
"char",
"sep",
"=",
"'",
"'",
";",
"for",
"(",
"String",
"bit",
":",
"Splitter",
".",
"on",
"(",
"'",
"'",
")",
".",
"split",
"(",
"classname",
")",
")",
"{",
"if",
"(",
"!",
"first",
")",
"{",
"sb",
".",
"append",
"(",
"sep",
")",
";",
"}",
"sb",
".",
"append",
"(",
"bit",
")",
";",
"if",
"(",
"Character",
".",
"isUpperCase",
"(",
"bit",
".",
"charAt",
"(",
"0",
")",
")",
")",
"{",
"sep",
"=",
"'",
"'",
";",
"}",
"first",
"=",
"false",
";",
"}",
"return",
"sb",
".",
"toString",
"(",
")",
";",
"}"
] |
so it may not end up being a performance win.)
|
[
"so",
"it",
"may",
"not",
"end",
"up",
"being",
"a",
"performance",
"win",
".",
")"
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/VisitorState.java#L406-L421
|
21,779
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/VisitorState.java
|
VisitorState.getType
|
public Type getType(Type baseType, boolean isArray, List<Type> typeParams) {
boolean isGeneric = typeParams != null && !typeParams.isEmpty();
if (!isArray && !isGeneric) {
// Simple type.
return baseType;
} else if (isArray && !isGeneric) {
// Array type, not generic.
ClassSymbol arraySymbol = getSymtab().arrayClass;
return new ArrayType(baseType, arraySymbol);
} else if (!isArray && isGeneric) {
// Generic type, not array.
com.sun.tools.javac.util.List<Type> typeParamsCopy =
com.sun.tools.javac.util.List.from(typeParams);
return new ClassType(Type.noType, typeParamsCopy, baseType.tsym);
} else {
throw new IllegalArgumentException("Unsupported arguments to getType");
}
}
|
java
|
public Type getType(Type baseType, boolean isArray, List<Type> typeParams) {
boolean isGeneric = typeParams != null && !typeParams.isEmpty();
if (!isArray && !isGeneric) {
// Simple type.
return baseType;
} else if (isArray && !isGeneric) {
// Array type, not generic.
ClassSymbol arraySymbol = getSymtab().arrayClass;
return new ArrayType(baseType, arraySymbol);
} else if (!isArray && isGeneric) {
// Generic type, not array.
com.sun.tools.javac.util.List<Type> typeParamsCopy =
com.sun.tools.javac.util.List.from(typeParams);
return new ClassType(Type.noType, typeParamsCopy, baseType.tsym);
} else {
throw new IllegalArgumentException("Unsupported arguments to getType");
}
}
|
[
"public",
"Type",
"getType",
"(",
"Type",
"baseType",
",",
"boolean",
"isArray",
",",
"List",
"<",
"Type",
">",
"typeParams",
")",
"{",
"boolean",
"isGeneric",
"=",
"typeParams",
"!=",
"null",
"&&",
"!",
"typeParams",
".",
"isEmpty",
"(",
")",
";",
"if",
"(",
"!",
"isArray",
"&&",
"!",
"isGeneric",
")",
"{",
"// Simple type.",
"return",
"baseType",
";",
"}",
"else",
"if",
"(",
"isArray",
"&&",
"!",
"isGeneric",
")",
"{",
"// Array type, not generic.",
"ClassSymbol",
"arraySymbol",
"=",
"getSymtab",
"(",
")",
".",
"arrayClass",
";",
"return",
"new",
"ArrayType",
"(",
"baseType",
",",
"arraySymbol",
")",
";",
"}",
"else",
"if",
"(",
"!",
"isArray",
"&&",
"isGeneric",
")",
"{",
"// Generic type, not array.",
"com",
".",
"sun",
".",
"tools",
".",
"javac",
".",
"util",
".",
"List",
"<",
"Type",
">",
"typeParamsCopy",
"=",
"com",
".",
"sun",
".",
"tools",
".",
"javac",
".",
"util",
".",
"List",
".",
"from",
"(",
"typeParams",
")",
";",
"return",
"new",
"ClassType",
"(",
"Type",
".",
"noType",
",",
"typeParamsCopy",
",",
"baseType",
".",
"tsym",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Unsupported arguments to getType\"",
")",
";",
"}",
"}"
] |
Build an instance of a Type.
|
[
"Build",
"an",
"instance",
"of",
"a",
"Type",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/VisitorState.java#L424-L441
|
21,780
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/VisitorState.java
|
VisitorState.findEnclosing
|
@Nullable
@SuppressWarnings("unchecked") // findPathToEnclosing guarantees that the type is from |classes|
@SafeVarargs
public final <T extends Tree> T findEnclosing(Class<? extends T>... classes) {
TreePath pathToEnclosing = findPathToEnclosing(classes);
return (pathToEnclosing == null) ? null : (T) pathToEnclosing.getLeaf();
}
|
java
|
@Nullable
@SuppressWarnings("unchecked") // findPathToEnclosing guarantees that the type is from |classes|
@SafeVarargs
public final <T extends Tree> T findEnclosing(Class<? extends T>... classes) {
TreePath pathToEnclosing = findPathToEnclosing(classes);
return (pathToEnclosing == null) ? null : (T) pathToEnclosing.getLeaf();
}
|
[
"@",
"Nullable",
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"// findPathToEnclosing guarantees that the type is from |classes|",
"@",
"SafeVarargs",
"public",
"final",
"<",
"T",
"extends",
"Tree",
">",
"T",
"findEnclosing",
"(",
"Class",
"<",
"?",
"extends",
"T",
">",
"...",
"classes",
")",
"{",
"TreePath",
"pathToEnclosing",
"=",
"findPathToEnclosing",
"(",
"classes",
")",
";",
"return",
"(",
"pathToEnclosing",
"==",
"null",
")",
"?",
"null",
":",
"(",
"T",
")",
"pathToEnclosing",
".",
"getLeaf",
"(",
")",
";",
"}"
] |
Find the first enclosing tree node of one of the given types.
@return the node, or {@code null} if there is no match
|
[
"Find",
"the",
"first",
"enclosing",
"tree",
"node",
"of",
"one",
"of",
"the",
"given",
"types",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/VisitorState.java#L474-L480
|
21,781
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/VisitorState.java
|
VisitorState.getSourceCode
|
@Nullable
public CharSequence getSourceCode() {
try {
return getPath().getCompilationUnit().getSourceFile().getCharContent(false);
} catch (IOException e) {
return null;
}
}
|
java
|
@Nullable
public CharSequence getSourceCode() {
try {
return getPath().getCompilationUnit().getSourceFile().getCharContent(false);
} catch (IOException e) {
return null;
}
}
|
[
"@",
"Nullable",
"public",
"CharSequence",
"getSourceCode",
"(",
")",
"{",
"try",
"{",
"return",
"getPath",
"(",
")",
".",
"getCompilationUnit",
"(",
")",
".",
"getSourceFile",
"(",
")",
".",
"getCharContent",
"(",
"false",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"return",
"null",
";",
"}",
"}"
] |
Gets the current source file.
@return the source file as a sequence of characters, or null if it is not available
|
[
"Gets",
"the",
"current",
"source",
"file",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/VisitorState.java#L487-L494
|
21,782
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/VisitorState.java
|
VisitorState.getSourceForNode
|
@Nullable
public String getSourceForNode(Tree tree) {
JCTree node = (JCTree) tree;
int start = node.getStartPosition();
int end = getEndPosition(node);
if (end < 0) {
return null;
}
return getSourceCode().subSequence(start, end).toString();
}
|
java
|
@Nullable
public String getSourceForNode(Tree tree) {
JCTree node = (JCTree) tree;
int start = node.getStartPosition();
int end = getEndPosition(node);
if (end < 0) {
return null;
}
return getSourceCode().subSequence(start, end).toString();
}
|
[
"@",
"Nullable",
"public",
"String",
"getSourceForNode",
"(",
"Tree",
"tree",
")",
"{",
"JCTree",
"node",
"=",
"(",
"JCTree",
")",
"tree",
";",
"int",
"start",
"=",
"node",
".",
"getStartPosition",
"(",
")",
";",
"int",
"end",
"=",
"getEndPosition",
"(",
"node",
")",
";",
"if",
"(",
"end",
"<",
"0",
")",
"{",
"return",
"null",
";",
"}",
"return",
"getSourceCode",
"(",
")",
".",
"subSequence",
"(",
"start",
",",
"end",
")",
".",
"toString",
"(",
")",
";",
"}"
] |
Gets the original source code that represents the given node.
<p>Note that this may be different from what is returned by calling .toString() on the node.
This returns exactly what is in the source code, whereas .toString() pretty-prints the node
from its AST representation.
@return the source code that represents the node.
|
[
"Gets",
"the",
"original",
"source",
"code",
"that",
"represents",
"the",
"given",
"node",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/VisitorState.java#L505-L514
|
21,783
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/VisitorState.java
|
VisitorState.getEndPosition
|
public int getEndPosition(Tree node) {
JCCompilationUnit compilationUnit = (JCCompilationUnit) getPath().getCompilationUnit();
if (compilationUnit.endPositions == null) {
return -1;
}
return ((JCTree) node).getEndPosition(compilationUnit.endPositions);
}
|
java
|
public int getEndPosition(Tree node) {
JCCompilationUnit compilationUnit = (JCCompilationUnit) getPath().getCompilationUnit();
if (compilationUnit.endPositions == null) {
return -1;
}
return ((JCTree) node).getEndPosition(compilationUnit.endPositions);
}
|
[
"public",
"int",
"getEndPosition",
"(",
"Tree",
"node",
")",
"{",
"JCCompilationUnit",
"compilationUnit",
"=",
"(",
"JCCompilationUnit",
")",
"getPath",
"(",
")",
".",
"getCompilationUnit",
"(",
")",
";",
"if",
"(",
"compilationUnit",
".",
"endPositions",
"==",
"null",
")",
"{",
"return",
"-",
"1",
";",
"}",
"return",
"(",
"(",
"JCTree",
")",
"node",
")",
".",
"getEndPosition",
"(",
"compilationUnit",
".",
"endPositions",
")",
";",
"}"
] |
Returns the end position of the node, or -1 if it is not available.
|
[
"Returns",
"the",
"end",
"position",
"of",
"the",
"node",
"or",
"-",
"1",
"if",
"it",
"is",
"not",
"available",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/VisitorState.java#L527-L533
|
21,784
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/VisitorState.java
|
VisitorState.validateTypeStr
|
private static void validateTypeStr(String typeStr) {
if (typeStr.contains("[") || typeStr.contains("]")) {
throw new IllegalArgumentException(
String.format(
"Cannot convert array types (%s), please build them using getType()", typeStr));
}
if (typeStr.contains("<") || typeStr.contains(">")) {
throw new IllegalArgumentException(
String.format(
"Cannot convert generic types (%s), please build them using getType()", typeStr));
}
}
|
java
|
private static void validateTypeStr(String typeStr) {
if (typeStr.contains("[") || typeStr.contains("]")) {
throw new IllegalArgumentException(
String.format(
"Cannot convert array types (%s), please build them using getType()", typeStr));
}
if (typeStr.contains("<") || typeStr.contains(">")) {
throw new IllegalArgumentException(
String.format(
"Cannot convert generic types (%s), please build them using getType()", typeStr));
}
}
|
[
"private",
"static",
"void",
"validateTypeStr",
"(",
"String",
"typeStr",
")",
"{",
"if",
"(",
"typeStr",
".",
"contains",
"(",
"\"[\"",
")",
"||",
"typeStr",
".",
"contains",
"(",
"\"]\"",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"String",
".",
"format",
"(",
"\"Cannot convert array types (%s), please build them using getType()\"",
",",
"typeStr",
")",
")",
";",
"}",
"if",
"(",
"typeStr",
".",
"contains",
"(",
"\"<\"",
")",
"||",
"typeStr",
".",
"contains",
"(",
"\">\"",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"String",
".",
"format",
"(",
"\"Cannot convert generic types (%s), please build them using getType()\"",
",",
"typeStr",
")",
")",
";",
"}",
"}"
] |
Validates a type string, ensuring it is not generic and not an array type.
|
[
"Validates",
"a",
"type",
"string",
"ensuring",
"it",
"is",
"not",
"generic",
"and",
"not",
"an",
"array",
"type",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/VisitorState.java#L536-L547
|
21,785
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/util/Reachability.java
|
Reachability.canCompleteNormally
|
public static boolean canCompleteNormally(CaseTree caseTree) {
List<? extends StatementTree> statements = caseTree.getStatements();
if (statements.isEmpty()) {
return true;
}
// We only care whether the last statement completes; javac would have already
// reported an error if that statement wasn't reachable, and the answer is
// independent of any preceding statements.
// TODO(cushon): This isn't really making an exception for System.exit in the prior statements.
return canCompleteNormally(getLast(statements));
}
|
java
|
public static boolean canCompleteNormally(CaseTree caseTree) {
List<? extends StatementTree> statements = caseTree.getStatements();
if (statements.isEmpty()) {
return true;
}
// We only care whether the last statement completes; javac would have already
// reported an error if that statement wasn't reachable, and the answer is
// independent of any preceding statements.
// TODO(cushon): This isn't really making an exception for System.exit in the prior statements.
return canCompleteNormally(getLast(statements));
}
|
[
"public",
"static",
"boolean",
"canCompleteNormally",
"(",
"CaseTree",
"caseTree",
")",
"{",
"List",
"<",
"?",
"extends",
"StatementTree",
">",
"statements",
"=",
"caseTree",
".",
"getStatements",
"(",
")",
";",
"if",
"(",
"statements",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"// We only care whether the last statement completes; javac would have already",
"// reported an error if that statement wasn't reachable, and the answer is",
"// independent of any preceding statements.",
"// TODO(cushon): This isn't really making an exception for System.exit in the prior statements.",
"return",
"canCompleteNormally",
"(",
"getLast",
"(",
"statements",
")",
")",
";",
"}"
] |
Returns true if the given case tree can complete normally, as defined by JLS 14.21.
<p>An exception is made for {@code System.exit}, which cannot complete normally in practice.
|
[
"Returns",
"true",
"if",
"the",
"given",
"case",
"tree",
"can",
"complete",
"normally",
"as",
"defined",
"by",
"JLS",
"14",
".",
"21",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/util/Reachability.java#L74-L84
|
21,786
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/BaseErrorProneJavaCompiler.java
|
BaseErrorProneJavaCompiler.setupMessageBundle
|
public static void setupMessageBundle(Context context) {
ResourceBundle bundle = ResourceBundle.getBundle("com.google.errorprone.errors");
JavacMessages.instance(context).add(l -> bundle);
}
|
java
|
public static void setupMessageBundle(Context context) {
ResourceBundle bundle = ResourceBundle.getBundle("com.google.errorprone.errors");
JavacMessages.instance(context).add(l -> bundle);
}
|
[
"public",
"static",
"void",
"setupMessageBundle",
"(",
"Context",
"context",
")",
"{",
"ResourceBundle",
"bundle",
"=",
"ResourceBundle",
".",
"getBundle",
"(",
"\"com.google.errorprone.errors\"",
")",
";",
"JavacMessages",
".",
"instance",
"(",
"context",
")",
".",
"add",
"(",
"l",
"->",
"bundle",
")",
";",
"}"
] |
Registers our message bundle.
|
[
"Registers",
"our",
"message",
"bundle",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/BaseErrorProneJavaCompiler.java#L200-L203
|
21,787
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/NamedParameterComment.java
|
NamedParameterComment.match
|
static MatchedComment match(Commented<ExpressionTree> actual, String formal) {
Optional<Comment> lastBlockComment =
Streams.findLast(
actual.beforeComments().stream().filter(c -> c.getStyle() == CommentStyle.BLOCK));
if (lastBlockComment.isPresent()) {
Matcher m =
PARAMETER_COMMENT_PATTERN.matcher(Comments.getTextFromComment(lastBlockComment.get()));
if (m.matches()) {
return MatchedComment.create(
lastBlockComment.get(),
m.group(1).equals(formal) ? MatchType.EXACT_MATCH : MatchType.BAD_MATCH);
}
}
Optional<Comment> approximateMatchComment =
Stream.concat(actual.beforeComments().stream(), actual.afterComments().stream())
.filter(comment -> isApproximateMatchingComment(comment, formal))
.findFirst();
if (approximateMatchComment.isPresent()) {
// Report EXACT_MATCH for comments that don't use the recommended style (e.g. `/*foo*/`
// instead of `/* foo= */`), but which match the formal parameter name exactly, since it's
// a style nit rather than a possible correctness issue.
// TODO(cushon): revisit this if we standardize on the recommended comment style.
String text =
CharMatcher.anyOf("=:")
.trimTrailingFrom(Comments.getTextFromComment(approximateMatchComment.get()).trim());
return MatchedComment.create(
approximateMatchComment.get(),
text.equals(formal) ? MatchType.EXACT_MATCH : MatchType.APPROXIMATE_MATCH);
}
return MatchedComment.notAnnotated();
}
|
java
|
static MatchedComment match(Commented<ExpressionTree> actual, String formal) {
Optional<Comment> lastBlockComment =
Streams.findLast(
actual.beforeComments().stream().filter(c -> c.getStyle() == CommentStyle.BLOCK));
if (lastBlockComment.isPresent()) {
Matcher m =
PARAMETER_COMMENT_PATTERN.matcher(Comments.getTextFromComment(lastBlockComment.get()));
if (m.matches()) {
return MatchedComment.create(
lastBlockComment.get(),
m.group(1).equals(formal) ? MatchType.EXACT_MATCH : MatchType.BAD_MATCH);
}
}
Optional<Comment> approximateMatchComment =
Stream.concat(actual.beforeComments().stream(), actual.afterComments().stream())
.filter(comment -> isApproximateMatchingComment(comment, formal))
.findFirst();
if (approximateMatchComment.isPresent()) {
// Report EXACT_MATCH for comments that don't use the recommended style (e.g. `/*foo*/`
// instead of `/* foo= */`), but which match the formal parameter name exactly, since it's
// a style nit rather than a possible correctness issue.
// TODO(cushon): revisit this if we standardize on the recommended comment style.
String text =
CharMatcher.anyOf("=:")
.trimTrailingFrom(Comments.getTextFromComment(approximateMatchComment.get()).trim());
return MatchedComment.create(
approximateMatchComment.get(),
text.equals(formal) ? MatchType.EXACT_MATCH : MatchType.APPROXIMATE_MATCH);
}
return MatchedComment.notAnnotated();
}
|
[
"static",
"MatchedComment",
"match",
"(",
"Commented",
"<",
"ExpressionTree",
">",
"actual",
",",
"String",
"formal",
")",
"{",
"Optional",
"<",
"Comment",
">",
"lastBlockComment",
"=",
"Streams",
".",
"findLast",
"(",
"actual",
".",
"beforeComments",
"(",
")",
".",
"stream",
"(",
")",
".",
"filter",
"(",
"c",
"->",
"c",
".",
"getStyle",
"(",
")",
"==",
"CommentStyle",
".",
"BLOCK",
")",
")",
";",
"if",
"(",
"lastBlockComment",
".",
"isPresent",
"(",
")",
")",
"{",
"Matcher",
"m",
"=",
"PARAMETER_COMMENT_PATTERN",
".",
"matcher",
"(",
"Comments",
".",
"getTextFromComment",
"(",
"lastBlockComment",
".",
"get",
"(",
")",
")",
")",
";",
"if",
"(",
"m",
".",
"matches",
"(",
")",
")",
"{",
"return",
"MatchedComment",
".",
"create",
"(",
"lastBlockComment",
".",
"get",
"(",
")",
",",
"m",
".",
"group",
"(",
"1",
")",
".",
"equals",
"(",
"formal",
")",
"?",
"MatchType",
".",
"EXACT_MATCH",
":",
"MatchType",
".",
"BAD_MATCH",
")",
";",
"}",
"}",
"Optional",
"<",
"Comment",
">",
"approximateMatchComment",
"=",
"Stream",
".",
"concat",
"(",
"actual",
".",
"beforeComments",
"(",
")",
".",
"stream",
"(",
")",
",",
"actual",
".",
"afterComments",
"(",
")",
".",
"stream",
"(",
")",
")",
".",
"filter",
"(",
"comment",
"->",
"isApproximateMatchingComment",
"(",
"comment",
",",
"formal",
")",
")",
".",
"findFirst",
"(",
")",
";",
"if",
"(",
"approximateMatchComment",
".",
"isPresent",
"(",
")",
")",
"{",
"// Report EXACT_MATCH for comments that don't use the recommended style (e.g. `/*foo*/`",
"// instead of `/* foo= */`), but which match the formal parameter name exactly, since it's",
"// a style nit rather than a possible correctness issue.",
"// TODO(cushon): revisit this if we standardize on the recommended comment style.",
"String",
"text",
"=",
"CharMatcher",
".",
"anyOf",
"(",
"\"=:\"",
")",
".",
"trimTrailingFrom",
"(",
"Comments",
".",
"getTextFromComment",
"(",
"approximateMatchComment",
".",
"get",
"(",
")",
")",
".",
"trim",
"(",
")",
")",
";",
"return",
"MatchedComment",
".",
"create",
"(",
"approximateMatchComment",
".",
"get",
"(",
")",
",",
"text",
".",
"equals",
"(",
"formal",
")",
"?",
"MatchType",
".",
"EXACT_MATCH",
":",
"MatchType",
".",
"APPROXIMATE_MATCH",
")",
";",
"}",
"return",
"MatchedComment",
".",
"notAnnotated",
"(",
")",
";",
"}"
] |
Determine the kind of match we have between the comments on this argument and the formal
parameter name.
|
[
"Determine",
"the",
"kind",
"of",
"match",
"we",
"have",
"between",
"the",
"comments",
"on",
"this",
"argument",
"and",
"the",
"formal",
"parameter",
"name",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/NamedParameterComment.java#L131-L165
|
21,788
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/NamedParameterComment.java
|
NamedParameterComment.containsSyntheticParameterName
|
public static boolean containsSyntheticParameterName(MethodSymbol sym) {
return sym.getParameters().stream()
.anyMatch(p -> SYNTHETIC_PARAMETER_NAME.matcher(p.getSimpleName()).matches());
}
|
java
|
public static boolean containsSyntheticParameterName(MethodSymbol sym) {
return sym.getParameters().stream()
.anyMatch(p -> SYNTHETIC_PARAMETER_NAME.matcher(p.getSimpleName()).matches());
}
|
[
"public",
"static",
"boolean",
"containsSyntheticParameterName",
"(",
"MethodSymbol",
"sym",
")",
"{",
"return",
"sym",
".",
"getParameters",
"(",
")",
".",
"stream",
"(",
")",
".",
"anyMatch",
"(",
"p",
"->",
"SYNTHETIC_PARAMETER_NAME",
".",
"matcher",
"(",
"p",
".",
"getSimpleName",
"(",
")",
")",
".",
"matches",
"(",
")",
")",
";",
"}"
] |
Returns true if the method has synthetic parameter names, indicating the real names are not
available.
|
[
"Returns",
"true",
"if",
"the",
"method",
"has",
"synthetic",
"parameter",
"names",
"indicating",
"the",
"real",
"names",
"are",
"not",
"available",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/NamedParameterComment.java#L185-L188
|
21,789
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/AnnotationPosition.java
|
AnnotationPosition.checkAnnotations
|
private Description checkAnnotations(
Tree tree,
int treePos,
List<? extends AnnotationTree> annotations,
Comment danglingJavadoc,
int firstModifierPos,
int lastModifierPos,
VisitorState state) {
SuggestedFix.Builder builder = SuggestedFix.builder();
List<AnnotationTree> moveBefore = new ArrayList<>();
List<AnnotationTree> moveAfter = new ArrayList<>();
boolean annotationProblem = false;
for (AnnotationTree annotation : annotations) {
int annotationPos = ((JCTree) annotation).getStartPosition();
if (annotationPos <= firstModifierPos) {
continue;
}
AnnotationType annotationType =
ASTHelpers.getAnnotationType(annotation, getSymbol(tree), state);
if (annotationPos >= lastModifierPos) {
if (tree instanceof ClassTree || annotationType == AnnotationType.DECLARATION) {
annotationProblem = true;
moveBefore.add(annotation);
}
} else {
annotationProblem = true;
if (tree instanceof ClassTree
|| annotationType == AnnotationType.DECLARATION
|| annotationType == null) {
moveBefore.add(annotation);
} else {
moveAfter.add(annotation);
}
}
}
if (annotationProblem) {
for (AnnotationTree annotation : moveBefore) {
builder.delete(annotation);
}
for (AnnotationTree annotation : moveAfter) {
builder.delete(annotation);
}
String javadoc =
danglingJavadoc == null ? "" : removeJavadoc(state, treePos, danglingJavadoc, builder);
builder
.replace(
firstModifierPos,
firstModifierPos,
String.format("%s%s ", javadoc, joinSource(state, moveBefore)))
.replace(
lastModifierPos, lastModifierPos, String.format("%s ", joinSource(state, moveAfter)));
ImmutableList<String> names =
annotations.stream()
.map(ASTHelpers::getSymbol)
.filter(Objects::nonNull)
.map(Symbol::getSimpleName)
.map(a -> "@" + a)
.collect(toImmutableList());
String flattened = names.stream().collect(joining(", "));
String isAre = names.size() > 1 ? "are not type annotations" : "is not a type annotation";
String message =
String.format(
"%s %s, so should appear before any modifiers and after Javadocs.", flattened, isAre);
return buildDescription(tree).setMessage(message).addFix(builder.build()).build();
}
return NO_MATCH;
}
|
java
|
private Description checkAnnotations(
Tree tree,
int treePos,
List<? extends AnnotationTree> annotations,
Comment danglingJavadoc,
int firstModifierPos,
int lastModifierPos,
VisitorState state) {
SuggestedFix.Builder builder = SuggestedFix.builder();
List<AnnotationTree> moveBefore = new ArrayList<>();
List<AnnotationTree> moveAfter = new ArrayList<>();
boolean annotationProblem = false;
for (AnnotationTree annotation : annotations) {
int annotationPos = ((JCTree) annotation).getStartPosition();
if (annotationPos <= firstModifierPos) {
continue;
}
AnnotationType annotationType =
ASTHelpers.getAnnotationType(annotation, getSymbol(tree), state);
if (annotationPos >= lastModifierPos) {
if (tree instanceof ClassTree || annotationType == AnnotationType.DECLARATION) {
annotationProblem = true;
moveBefore.add(annotation);
}
} else {
annotationProblem = true;
if (tree instanceof ClassTree
|| annotationType == AnnotationType.DECLARATION
|| annotationType == null) {
moveBefore.add(annotation);
} else {
moveAfter.add(annotation);
}
}
}
if (annotationProblem) {
for (AnnotationTree annotation : moveBefore) {
builder.delete(annotation);
}
for (AnnotationTree annotation : moveAfter) {
builder.delete(annotation);
}
String javadoc =
danglingJavadoc == null ? "" : removeJavadoc(state, treePos, danglingJavadoc, builder);
builder
.replace(
firstModifierPos,
firstModifierPos,
String.format("%s%s ", javadoc, joinSource(state, moveBefore)))
.replace(
lastModifierPos, lastModifierPos, String.format("%s ", joinSource(state, moveAfter)));
ImmutableList<String> names =
annotations.stream()
.map(ASTHelpers::getSymbol)
.filter(Objects::nonNull)
.map(Symbol::getSimpleName)
.map(a -> "@" + a)
.collect(toImmutableList());
String flattened = names.stream().collect(joining(", "));
String isAre = names.size() > 1 ? "are not type annotations" : "is not a type annotation";
String message =
String.format(
"%s %s, so should appear before any modifiers and after Javadocs.", flattened, isAre);
return buildDescription(tree).setMessage(message).addFix(builder.build()).build();
}
return NO_MATCH;
}
|
[
"private",
"Description",
"checkAnnotations",
"(",
"Tree",
"tree",
",",
"int",
"treePos",
",",
"List",
"<",
"?",
"extends",
"AnnotationTree",
">",
"annotations",
",",
"Comment",
"danglingJavadoc",
",",
"int",
"firstModifierPos",
",",
"int",
"lastModifierPos",
",",
"VisitorState",
"state",
")",
"{",
"SuggestedFix",
".",
"Builder",
"builder",
"=",
"SuggestedFix",
".",
"builder",
"(",
")",
";",
"List",
"<",
"AnnotationTree",
">",
"moveBefore",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"List",
"<",
"AnnotationTree",
">",
"moveAfter",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"boolean",
"annotationProblem",
"=",
"false",
";",
"for",
"(",
"AnnotationTree",
"annotation",
":",
"annotations",
")",
"{",
"int",
"annotationPos",
"=",
"(",
"(",
"JCTree",
")",
"annotation",
")",
".",
"getStartPosition",
"(",
")",
";",
"if",
"(",
"annotationPos",
"<=",
"firstModifierPos",
")",
"{",
"continue",
";",
"}",
"AnnotationType",
"annotationType",
"=",
"ASTHelpers",
".",
"getAnnotationType",
"(",
"annotation",
",",
"getSymbol",
"(",
"tree",
")",
",",
"state",
")",
";",
"if",
"(",
"annotationPos",
">=",
"lastModifierPos",
")",
"{",
"if",
"(",
"tree",
"instanceof",
"ClassTree",
"||",
"annotationType",
"==",
"AnnotationType",
".",
"DECLARATION",
")",
"{",
"annotationProblem",
"=",
"true",
";",
"moveBefore",
".",
"add",
"(",
"annotation",
")",
";",
"}",
"}",
"else",
"{",
"annotationProblem",
"=",
"true",
";",
"if",
"(",
"tree",
"instanceof",
"ClassTree",
"||",
"annotationType",
"==",
"AnnotationType",
".",
"DECLARATION",
"||",
"annotationType",
"==",
"null",
")",
"{",
"moveBefore",
".",
"add",
"(",
"annotation",
")",
";",
"}",
"else",
"{",
"moveAfter",
".",
"add",
"(",
"annotation",
")",
";",
"}",
"}",
"}",
"if",
"(",
"annotationProblem",
")",
"{",
"for",
"(",
"AnnotationTree",
"annotation",
":",
"moveBefore",
")",
"{",
"builder",
".",
"delete",
"(",
"annotation",
")",
";",
"}",
"for",
"(",
"AnnotationTree",
"annotation",
":",
"moveAfter",
")",
"{",
"builder",
".",
"delete",
"(",
"annotation",
")",
";",
"}",
"String",
"javadoc",
"=",
"danglingJavadoc",
"==",
"null",
"?",
"\"\"",
":",
"removeJavadoc",
"(",
"state",
",",
"treePos",
",",
"danglingJavadoc",
",",
"builder",
")",
";",
"builder",
".",
"replace",
"(",
"firstModifierPos",
",",
"firstModifierPos",
",",
"String",
".",
"format",
"(",
"\"%s%s \"",
",",
"javadoc",
",",
"joinSource",
"(",
"state",
",",
"moveBefore",
")",
")",
")",
".",
"replace",
"(",
"lastModifierPos",
",",
"lastModifierPos",
",",
"String",
".",
"format",
"(",
"\"%s \"",
",",
"joinSource",
"(",
"state",
",",
"moveAfter",
")",
")",
")",
";",
"ImmutableList",
"<",
"String",
">",
"names",
"=",
"annotations",
".",
"stream",
"(",
")",
".",
"map",
"(",
"ASTHelpers",
"::",
"getSymbol",
")",
".",
"filter",
"(",
"Objects",
"::",
"nonNull",
")",
".",
"map",
"(",
"Symbol",
"::",
"getSimpleName",
")",
".",
"map",
"(",
"a",
"->",
"\"@\"",
"+",
"a",
")",
".",
"collect",
"(",
"toImmutableList",
"(",
")",
")",
";",
"String",
"flattened",
"=",
"names",
".",
"stream",
"(",
")",
".",
"collect",
"(",
"joining",
"(",
"\", \"",
")",
")",
";",
"String",
"isAre",
"=",
"names",
".",
"size",
"(",
")",
">",
"1",
"?",
"\"are not type annotations\"",
":",
"\"is not a type annotation\"",
";",
"String",
"message",
"=",
"String",
".",
"format",
"(",
"\"%s %s, so should appear before any modifiers and after Javadocs.\"",
",",
"flattened",
",",
"isAre",
")",
";",
"return",
"buildDescription",
"(",
"tree",
")",
".",
"setMessage",
"(",
"message",
")",
".",
"addFix",
"(",
"builder",
".",
"build",
"(",
")",
")",
".",
"build",
"(",
")",
";",
"}",
"return",
"NO_MATCH",
";",
"}"
] |
Checks that annotations are on the right side of the modifiers.
|
[
"Checks",
"that",
"annotations",
"are",
"on",
"the",
"right",
"side",
"of",
"the",
"modifiers",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/AnnotationPosition.java#L178-L245
|
21,790
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/matchers/AnnotationMatcherUtils.java
|
AnnotationMatcherUtils.getArgument
|
@Nullable
public static ExpressionTree getArgument(AnnotationTree annotationTree, String name) {
for (ExpressionTree argumentTree : annotationTree.getArguments()) {
if (argumentTree.getKind() != Tree.Kind.ASSIGNMENT) {
continue;
}
AssignmentTree assignmentTree = (AssignmentTree) argumentTree;
if (!assignmentTree.getVariable().toString().equals(name)) {
continue;
}
ExpressionTree expressionTree = assignmentTree.getExpression();
return expressionTree;
}
return null;
}
|
java
|
@Nullable
public static ExpressionTree getArgument(AnnotationTree annotationTree, String name) {
for (ExpressionTree argumentTree : annotationTree.getArguments()) {
if (argumentTree.getKind() != Tree.Kind.ASSIGNMENT) {
continue;
}
AssignmentTree assignmentTree = (AssignmentTree) argumentTree;
if (!assignmentTree.getVariable().toString().equals(name)) {
continue;
}
ExpressionTree expressionTree = assignmentTree.getExpression();
return expressionTree;
}
return null;
}
|
[
"@",
"Nullable",
"public",
"static",
"ExpressionTree",
"getArgument",
"(",
"AnnotationTree",
"annotationTree",
",",
"String",
"name",
")",
"{",
"for",
"(",
"ExpressionTree",
"argumentTree",
":",
"annotationTree",
".",
"getArguments",
"(",
")",
")",
"{",
"if",
"(",
"argumentTree",
".",
"getKind",
"(",
")",
"!=",
"Tree",
".",
"Kind",
".",
"ASSIGNMENT",
")",
"{",
"continue",
";",
"}",
"AssignmentTree",
"assignmentTree",
"=",
"(",
"AssignmentTree",
")",
"argumentTree",
";",
"if",
"(",
"!",
"assignmentTree",
".",
"getVariable",
"(",
")",
".",
"toString",
"(",
")",
".",
"equals",
"(",
"name",
")",
")",
"{",
"continue",
";",
"}",
"ExpressionTree",
"expressionTree",
"=",
"assignmentTree",
".",
"getExpression",
"(",
")",
";",
"return",
"expressionTree",
";",
"}",
"return",
"null",
";",
"}"
] |
Gets the value for an argument, or null if the argument does not exist.
@param annotationTree the AST node for the annotation
@param name the name of the argument whose value to get
@return the value of the argument, or null if the argument does not exist
|
[
"Gets",
"the",
"value",
"for",
"an",
"argument",
"or",
"null",
"if",
"the",
"argument",
"does",
"not",
"exist",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/matchers/AnnotationMatcherUtils.java#L39-L53
|
21,791
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/EnclosedByReverseHeuristic.java
|
EnclosedByReverseHeuristic.isAcceptableChange
|
@Override
public boolean isAcceptableChange(
Changes changes, Tree node, MethodSymbol symbol, VisitorState state) {
return findReverseWordsMatchInParentNodes(state) == null;
}
|
java
|
@Override
public boolean isAcceptableChange(
Changes changes, Tree node, MethodSymbol symbol, VisitorState state) {
return findReverseWordsMatchInParentNodes(state) == null;
}
|
[
"@",
"Override",
"public",
"boolean",
"isAcceptableChange",
"(",
"Changes",
"changes",
",",
"Tree",
"node",
",",
"MethodSymbol",
"symbol",
",",
"VisitorState",
"state",
")",
"{",
"return",
"findReverseWordsMatchInParentNodes",
"(",
"state",
")",
"==",
"null",
";",
"}"
] |
Return true if this call is not enclosed in a method call about reversing things
|
[
"Return",
"true",
"if",
"this",
"call",
"is",
"not",
"enclosed",
"in",
"a",
"method",
"call",
"about",
"reversing",
"things"
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/argumentselectiondefects/EnclosedByReverseHeuristic.java#L71-L75
|
21,792
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/UnsynchronizedOverridesSynchronized.java
|
UnsynchronizedOverridesSynchronized.ignore
|
private static boolean ignore(MethodTree method, VisitorState state) {
return firstNonNull(
new TreeScanner<Boolean, Void>() {
@Override
public Boolean visitBlock(BlockTree tree, Void unused) {
switch (tree.getStatements().size()) {
case 0:
return true;
case 1:
return scan(getOnlyElement(tree.getStatements()), null);
default:
return false;
}
}
@Override
public Boolean visitReturn(ReturnTree tree, Void unused) {
return scan(tree.getExpression(), null);
}
@Override
public Boolean visitExpressionStatement(ExpressionStatementTree tree, Void unused) {
return scan(tree.getExpression(), null);
}
@Override
public Boolean visitTypeCast(TypeCastTree tree, Void unused) {
return scan(tree.getExpression(), null);
}
@Override
public Boolean visitMethodInvocation(MethodInvocationTree node, Void aVoid) {
ExpressionTree receiver = ASTHelpers.getReceiver(node);
return receiver instanceof IdentifierTree
&& ((IdentifierTree) receiver).getName().contentEquals("super")
&& overrides(ASTHelpers.getSymbol(method), ASTHelpers.getSymbol(node));
}
private boolean overrides(MethodSymbol sym, MethodSymbol other) {
return !sym.isStatic()
&& !other.isStatic()
&& (((sym.flags() | other.flags()) & Flags.SYNTHETIC) == 0)
&& sym.name.contentEquals(other.name)
&& sym.overrides(
other, sym.owner.enclClass(), state.getTypes(), /* checkResult= */ false);
}
}.scan(method.getBody(), null),
false);
}
|
java
|
private static boolean ignore(MethodTree method, VisitorState state) {
return firstNonNull(
new TreeScanner<Boolean, Void>() {
@Override
public Boolean visitBlock(BlockTree tree, Void unused) {
switch (tree.getStatements().size()) {
case 0:
return true;
case 1:
return scan(getOnlyElement(tree.getStatements()), null);
default:
return false;
}
}
@Override
public Boolean visitReturn(ReturnTree tree, Void unused) {
return scan(tree.getExpression(), null);
}
@Override
public Boolean visitExpressionStatement(ExpressionStatementTree tree, Void unused) {
return scan(tree.getExpression(), null);
}
@Override
public Boolean visitTypeCast(TypeCastTree tree, Void unused) {
return scan(tree.getExpression(), null);
}
@Override
public Boolean visitMethodInvocation(MethodInvocationTree node, Void aVoid) {
ExpressionTree receiver = ASTHelpers.getReceiver(node);
return receiver instanceof IdentifierTree
&& ((IdentifierTree) receiver).getName().contentEquals("super")
&& overrides(ASTHelpers.getSymbol(method), ASTHelpers.getSymbol(node));
}
private boolean overrides(MethodSymbol sym, MethodSymbol other) {
return !sym.isStatic()
&& !other.isStatic()
&& (((sym.flags() | other.flags()) & Flags.SYNTHETIC) == 0)
&& sym.name.contentEquals(other.name)
&& sym.overrides(
other, sym.owner.enclClass(), state.getTypes(), /* checkResult= */ false);
}
}.scan(method.getBody(), null),
false);
}
|
[
"private",
"static",
"boolean",
"ignore",
"(",
"MethodTree",
"method",
",",
"VisitorState",
"state",
")",
"{",
"return",
"firstNonNull",
"(",
"new",
"TreeScanner",
"<",
"Boolean",
",",
"Void",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"Boolean",
"visitBlock",
"(",
"BlockTree",
"tree",
",",
"Void",
"unused",
")",
"{",
"switch",
"(",
"tree",
".",
"getStatements",
"(",
")",
".",
"size",
"(",
")",
")",
"{",
"case",
"0",
":",
"return",
"true",
";",
"case",
"1",
":",
"return",
"scan",
"(",
"getOnlyElement",
"(",
"tree",
".",
"getStatements",
"(",
")",
")",
",",
"null",
")",
";",
"default",
":",
"return",
"false",
";",
"}",
"}",
"@",
"Override",
"public",
"Boolean",
"visitReturn",
"(",
"ReturnTree",
"tree",
",",
"Void",
"unused",
")",
"{",
"return",
"scan",
"(",
"tree",
".",
"getExpression",
"(",
")",
",",
"null",
")",
";",
"}",
"@",
"Override",
"public",
"Boolean",
"visitExpressionStatement",
"(",
"ExpressionStatementTree",
"tree",
",",
"Void",
"unused",
")",
"{",
"return",
"scan",
"(",
"tree",
".",
"getExpression",
"(",
")",
",",
"null",
")",
";",
"}",
"@",
"Override",
"public",
"Boolean",
"visitTypeCast",
"(",
"TypeCastTree",
"tree",
",",
"Void",
"unused",
")",
"{",
"return",
"scan",
"(",
"tree",
".",
"getExpression",
"(",
")",
",",
"null",
")",
";",
"}",
"@",
"Override",
"public",
"Boolean",
"visitMethodInvocation",
"(",
"MethodInvocationTree",
"node",
",",
"Void",
"aVoid",
")",
"{",
"ExpressionTree",
"receiver",
"=",
"ASTHelpers",
".",
"getReceiver",
"(",
"node",
")",
";",
"return",
"receiver",
"instanceof",
"IdentifierTree",
"&&",
"(",
"(",
"IdentifierTree",
")",
"receiver",
")",
".",
"getName",
"(",
")",
".",
"contentEquals",
"(",
"\"super\"",
")",
"&&",
"overrides",
"(",
"ASTHelpers",
".",
"getSymbol",
"(",
"method",
")",
",",
"ASTHelpers",
".",
"getSymbol",
"(",
"node",
")",
")",
";",
"}",
"private",
"boolean",
"overrides",
"(",
"MethodSymbol",
"sym",
",",
"MethodSymbol",
"other",
")",
"{",
"return",
"!",
"sym",
".",
"isStatic",
"(",
")",
"&&",
"!",
"other",
".",
"isStatic",
"(",
")",
"&&",
"(",
"(",
"(",
"sym",
".",
"flags",
"(",
")",
"|",
"other",
".",
"flags",
"(",
")",
")",
"&",
"Flags",
".",
"SYNTHETIC",
")",
"==",
"0",
")",
"&&",
"sym",
".",
"name",
".",
"contentEquals",
"(",
"other",
".",
"name",
")",
"&&",
"sym",
".",
"overrides",
"(",
"other",
",",
"sym",
".",
"owner",
".",
"enclClass",
"(",
")",
",",
"state",
".",
"getTypes",
"(",
")",
",",
"/* checkResult= */",
"false",
")",
";",
"}",
"}",
".",
"scan",
"(",
"method",
".",
"getBody",
"(",
")",
",",
"null",
")",
",",
"false",
")",
";",
"}"
] |
Don't flag methods that are empty or trivially delegate to a super-implementation.
|
[
"Don",
"t",
"flag",
"methods",
"that",
"are",
"empty",
"or",
"trivially",
"delegate",
"to",
"a",
"super",
"-",
"implementation",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/UnsynchronizedOverridesSynchronized.java#L88-L136
|
21,793
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/UnnecessaryTypeArgument.java
|
UnnecessaryTypeArgument.buildFix
|
private Fix buildFix(Tree tree, List<? extends Tree> arguments, VisitorState state) {
JCTree node = (JCTree) tree;
int startAbsolute = node.getStartPosition();
int lower = ((JCTree) arguments.get(0)).getStartPosition() - startAbsolute;
int upper = state.getEndPosition(arguments.get(arguments.size() - 1)) - startAbsolute;
CharSequence source = state.getSourceForNode(node);
while (lower >= 0 && source.charAt(lower) != '<') {
lower--;
}
while (upper < source.length() && source.charAt(upper) != '>') {
upper++;
}
// There's a small chance that the fix will be incorrect because there's a '<' or '>' in
// a comment (e.g. `this.</*<*/T/*>*/>f()`), it should never be the case that we don't find
// any angle brackets.
verify(source.charAt(lower) == '<' && source.charAt(upper) == '>');
Fix fix = SuggestedFix.replace(startAbsolute + lower, startAbsolute + upper + 1, "");
return fix;
}
|
java
|
private Fix buildFix(Tree tree, List<? extends Tree> arguments, VisitorState state) {
JCTree node = (JCTree) tree;
int startAbsolute = node.getStartPosition();
int lower = ((JCTree) arguments.get(0)).getStartPosition() - startAbsolute;
int upper = state.getEndPosition(arguments.get(arguments.size() - 1)) - startAbsolute;
CharSequence source = state.getSourceForNode(node);
while (lower >= 0 && source.charAt(lower) != '<') {
lower--;
}
while (upper < source.length() && source.charAt(upper) != '>') {
upper++;
}
// There's a small chance that the fix will be incorrect because there's a '<' or '>' in
// a comment (e.g. `this.</*<*/T/*>*/>f()`), it should never be the case that we don't find
// any angle brackets.
verify(source.charAt(lower) == '<' && source.charAt(upper) == '>');
Fix fix = SuggestedFix.replace(startAbsolute + lower, startAbsolute + upper + 1, "");
return fix;
}
|
[
"private",
"Fix",
"buildFix",
"(",
"Tree",
"tree",
",",
"List",
"<",
"?",
"extends",
"Tree",
">",
"arguments",
",",
"VisitorState",
"state",
")",
"{",
"JCTree",
"node",
"=",
"(",
"JCTree",
")",
"tree",
";",
"int",
"startAbsolute",
"=",
"node",
".",
"getStartPosition",
"(",
")",
";",
"int",
"lower",
"=",
"(",
"(",
"JCTree",
")",
"arguments",
".",
"get",
"(",
"0",
")",
")",
".",
"getStartPosition",
"(",
")",
"-",
"startAbsolute",
";",
"int",
"upper",
"=",
"state",
".",
"getEndPosition",
"(",
"arguments",
".",
"get",
"(",
"arguments",
".",
"size",
"(",
")",
"-",
"1",
")",
")",
"-",
"startAbsolute",
";",
"CharSequence",
"source",
"=",
"state",
".",
"getSourceForNode",
"(",
"node",
")",
";",
"while",
"(",
"lower",
">=",
"0",
"&&",
"source",
".",
"charAt",
"(",
"lower",
")",
"!=",
"'",
"'",
")",
"{",
"lower",
"--",
";",
"}",
"while",
"(",
"upper",
"<",
"source",
".",
"length",
"(",
")",
"&&",
"source",
".",
"charAt",
"(",
"upper",
")",
"!=",
"'",
"'",
")",
"{",
"upper",
"++",
";",
"}",
"// There's a small chance that the fix will be incorrect because there's a '<' or '>' in",
"// a comment (e.g. `this.</*<*/T/*>*/>f()`), it should never be the case that we don't find",
"// any angle brackets.",
"verify",
"(",
"source",
".",
"charAt",
"(",
"lower",
")",
"==",
"'",
"'",
"&&",
"source",
".",
"charAt",
"(",
"upper",
")",
"==",
"'",
"'",
")",
";",
"Fix",
"fix",
"=",
"SuggestedFix",
".",
"replace",
"(",
"startAbsolute",
"+",
"lower",
",",
"startAbsolute",
"+",
"upper",
"+",
"1",
",",
"\"\"",
")",
";",
"return",
"fix",
";",
"}"
] |
Constructor a fix that deletes the set of type arguments.
|
[
"Constructor",
"a",
"fix",
"that",
"deletes",
"the",
"set",
"of",
"type",
"arguments",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/UnnecessaryTypeArgument.java#L84-L107
|
21,794
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/CompatibleWithMisuse.java
|
CompatibleWithMisuse.valueArgumentFromCompatibleWithAnnotation
|
private String valueArgumentFromCompatibleWithAnnotation(AnnotationTree tree) {
ExpressionTree argumentValue = Iterables.getOnlyElement(tree.getArguments());
if (argumentValue.getKind() != Kind.ASSIGNMENT) {
// :-| Annotation symbol broken. Punt?
return null;
}
return ASTHelpers.constValue(((AssignmentTree) argumentValue).getExpression(), String.class);
}
|
java
|
private String valueArgumentFromCompatibleWithAnnotation(AnnotationTree tree) {
ExpressionTree argumentValue = Iterables.getOnlyElement(tree.getArguments());
if (argumentValue.getKind() != Kind.ASSIGNMENT) {
// :-| Annotation symbol broken. Punt?
return null;
}
return ASTHelpers.constValue(((AssignmentTree) argumentValue).getExpression(), String.class);
}
|
[
"private",
"String",
"valueArgumentFromCompatibleWithAnnotation",
"(",
"AnnotationTree",
"tree",
")",
"{",
"ExpressionTree",
"argumentValue",
"=",
"Iterables",
".",
"getOnlyElement",
"(",
"tree",
".",
"getArguments",
"(",
")",
")",
";",
"if",
"(",
"argumentValue",
".",
"getKind",
"(",
")",
"!=",
"Kind",
".",
"ASSIGNMENT",
")",
"{",
"// :-| Annotation symbol broken. Punt?",
"return",
"null",
";",
"}",
"return",
"ASTHelpers",
".",
"constValue",
"(",
"(",
"(",
"AssignmentTree",
")",
"argumentValue",
")",
".",
"getExpression",
"(",
")",
",",
"String",
".",
"class",
")",
";",
"}"
] |
is required.
|
[
"is",
"required",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/CompatibleWithMisuse.java#L127-L135
|
21,795
|
google/error-prone
|
core/src/main/java/com/google/errorprone/refaster/Choice.java
|
Choice.fromOptional
|
public static <T> Choice<T> fromOptional(Optional<T> optional) {
return optional.isPresent() ? of(optional.get()) : Choice.<T>none();
}
|
java
|
public static <T> Choice<T> fromOptional(Optional<T> optional) {
return optional.isPresent() ? of(optional.get()) : Choice.<T>none();
}
|
[
"public",
"static",
"<",
"T",
">",
"Choice",
"<",
"T",
">",
"fromOptional",
"(",
"Optional",
"<",
"T",
">",
"optional",
")",
"{",
"return",
"optional",
".",
"isPresent",
"(",
")",
"?",
"of",
"(",
"optional",
".",
"get",
"(",
")",
")",
":",
"Choice",
".",
"<",
"T",
">",
"none",
"(",
")",
";",
"}"
] |
Returns a choice of the optional value, if it is present, or the empty choice if it is absent.
|
[
"Returns",
"a",
"choice",
"of",
"the",
"optional",
"value",
"if",
"it",
"is",
"present",
"or",
"the",
"empty",
"choice",
"if",
"it",
"is",
"absent",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/refaster/Choice.java#L151-L153
|
21,796
|
google/error-prone
|
core/src/main/java/com/google/errorprone/refaster/Choice.java
|
Choice.any
|
public static <T> Choice<T> any(final Collection<Choice<T>> choices) {
return from(choices).thenChoose(Functions.<Choice<T>>identity());
}
|
java
|
public static <T> Choice<T> any(final Collection<Choice<T>> choices) {
return from(choices).thenChoose(Functions.<Choice<T>>identity());
}
|
[
"public",
"static",
"<",
"T",
">",
"Choice",
"<",
"T",
">",
"any",
"(",
"final",
"Collection",
"<",
"Choice",
"<",
"T",
">",
">",
"choices",
")",
"{",
"return",
"from",
"(",
"choices",
")",
".",
"thenChoose",
"(",
"Functions",
".",
"<",
"Choice",
"<",
"T",
">",
">",
"identity",
"(",
")",
")",
";",
"}"
] |
Returns a choice between any of the options from any of the specified choices.
|
[
"Returns",
"a",
"choice",
"between",
"any",
"of",
"the",
"options",
"from",
"any",
"of",
"the",
"specified",
"choices",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/refaster/Choice.java#L177-L179
|
21,797
|
google/error-prone
|
core/src/main/java/com/google/errorprone/refaster/Choice.java
|
Choice.transform
|
public <R> Choice<R> transform(final Function<? super T, R> function) {
checkNotNull(function);
final Choice<T> thisChoice = this;
return new Choice<R>() {
@Override
protected Iterator<R> iterator() {
return Iterators.transform(thisChoice.iterator(), function);
}
};
}
|
java
|
public <R> Choice<R> transform(final Function<? super T, R> function) {
checkNotNull(function);
final Choice<T> thisChoice = this;
return new Choice<R>() {
@Override
protected Iterator<R> iterator() {
return Iterators.transform(thisChoice.iterator(), function);
}
};
}
|
[
"public",
"<",
"R",
">",
"Choice",
"<",
"R",
">",
"transform",
"(",
"final",
"Function",
"<",
"?",
"super",
"T",
",",
"R",
">",
"function",
")",
"{",
"checkNotNull",
"(",
"function",
")",
";",
"final",
"Choice",
"<",
"T",
">",
"thisChoice",
"=",
"this",
";",
"return",
"new",
"Choice",
"<",
"R",
">",
"(",
")",
"{",
"@",
"Override",
"protected",
"Iterator",
"<",
"R",
">",
"iterator",
"(",
")",
"{",
"return",
"Iterators",
".",
"transform",
"(",
"thisChoice",
".",
"iterator",
"(",
")",
",",
"function",
")",
";",
"}",
"}",
";",
"}"
] |
Maps the choices with the specified function.
|
[
"Maps",
"the",
"choices",
"with",
"the",
"specified",
"function",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/refaster/Choice.java#L248-L257
|
21,798
|
google/error-prone
|
check_api/src/main/java/com/google/errorprone/util/ErrorProneTokens.java
|
ErrorProneTokens.getTokens
|
public static ImmutableList<ErrorProneToken> getTokens(String source, Context context) {
return new ErrorProneTokens(source, context).getTokens();
}
|
java
|
public static ImmutableList<ErrorProneToken> getTokens(String source, Context context) {
return new ErrorProneTokens(source, context).getTokens();
}
|
[
"public",
"static",
"ImmutableList",
"<",
"ErrorProneToken",
">",
"getTokens",
"(",
"String",
"source",
",",
"Context",
"context",
")",
"{",
"return",
"new",
"ErrorProneTokens",
"(",
"source",
",",
"context",
")",
".",
"getTokens",
"(",
")",
";",
"}"
] |
Returns the tokens for the given source text, including comments.
|
[
"Returns",
"the",
"tokens",
"for",
"the",
"given",
"source",
"text",
"including",
"comments",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/check_api/src/main/java/com/google/errorprone/util/ErrorProneTokens.java#L59-L61
|
21,799
|
google/error-prone
|
core/src/main/java/com/google/errorprone/bugpatterns/inject/dagger/Util.java
|
Util.hasAnyParameter
|
private static Matcher<AnnotationTree> hasAnyParameter(String... parameters) {
return anyOf(
transform(
asList(parameters),
new Function<String, Matcher<AnnotationTree>>() {
@Override
public Matcher<AnnotationTree> apply(String parameter) {
return hasArgumentWithValue(parameter, Matchers.<ExpressionTree>anything());
}
}));
}
|
java
|
private static Matcher<AnnotationTree> hasAnyParameter(String... parameters) {
return anyOf(
transform(
asList(parameters),
new Function<String, Matcher<AnnotationTree>>() {
@Override
public Matcher<AnnotationTree> apply(String parameter) {
return hasArgumentWithValue(parameter, Matchers.<ExpressionTree>anything());
}
}));
}
|
[
"private",
"static",
"Matcher",
"<",
"AnnotationTree",
">",
"hasAnyParameter",
"(",
"String",
"...",
"parameters",
")",
"{",
"return",
"anyOf",
"(",
"transform",
"(",
"asList",
"(",
"parameters",
")",
",",
"new",
"Function",
"<",
"String",
",",
"Matcher",
"<",
"AnnotationTree",
">",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"Matcher",
"<",
"AnnotationTree",
">",
"apply",
"(",
"String",
"parameter",
")",
"{",
"return",
"hasArgumentWithValue",
"(",
"parameter",
",",
"Matchers",
".",
"<",
"ExpressionTree",
">",
"anything",
"(",
")",
")",
";",
"}",
"}",
")",
")",
";",
"}"
] |
Matches an annotation that has an argument for at least one of the given parameters.
|
[
"Matches",
"an",
"annotation",
"that",
"has",
"an",
"argument",
"for",
"at",
"least",
"one",
"of",
"the",
"given",
"parameters",
"."
] |
fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d
|
https://github.com/google/error-prone/blob/fe2e3cc2cf1958cb7c487bfe89852bb4c225ba9d/core/src/main/java/com/google/errorprone/bugpatterns/inject/dagger/Util.java#L95-L105
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.