本文整理汇总了Java中com.google.errorprone.matchers.Description类的典型用法代码示例。如果您正苦于以下问题:Java Description类的具体用法?Java Description怎么用?Java Description使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Description类属于com.google.errorprone.matchers包,在下文中一共展示了Description类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: matchNewClass
import com.google.errorprone.matchers.Description; //导入依赖的package包/类
@Override
public Description matchNewClass(NewClassTree tree, VisitorState state) {
if (!matchWithinClass) {
return Description.NO_MATCH;
}
Symbol.MethodSymbol methodSymbol = ASTHelpers.getSymbol(tree);
if (methodSymbol == null) {
throw new RuntimeException("not expecting unresolved method here");
}
List<? extends ExpressionTree> actualParams = tree.getArguments();
if (tree.getClassBody() != null && actualParams.size() > 0) {
// passing parameters to constructor of anonymous class
// this constructor just invokes the constructor of the superclass, and
// in the AST does not have the parameter nullability annotations from the superclass.
// so, treat as if the superclass constructor is being invoked directly
// see https://github.com/uber/NullAway/issues/102
Type supertype = state.getTypes().supertype(methodSymbol.owner.type);
Symbol.MethodSymbol superConstructor =
findSuperConstructorInType(methodSymbol, supertype, state.getTypes());
if (superConstructor == null) {
throw new RuntimeException("must find constructor in supertype");
}
methodSymbol = superConstructor;
}
return handleInvocation(state, methodSymbol, actualParams);
}
开发者ID:uber,项目名称:NullAway,代码行数:27,代码来源:NullAway.java
示例2: matchMemberSelect
import com.google.errorprone.matchers.Description; //导入依赖的package包/类
@Override
public Description matchMemberSelect(MemberSelectTree tree, VisitorState state) {
if (!matchWithinClass) {
return Description.NO_MATCH;
}
Symbol symbol = ASTHelpers.getSymbol(tree);
// some checks for cases where we know it is not
// a null dereference
if (symbol == null || symbol.getSimpleName().toString().equals("class") || symbol.isEnum()) {
return Description.NO_MATCH;
}
Description badDeref = matchDereference(tree.getExpression(), tree, state);
if (!badDeref.equals(Description.NO_MATCH)) {
return badDeref;
}
// if we're accessing a field of this, make sure we're not reading the field before init
if (tree.getExpression() instanceof IdentifierTree
&& ((IdentifierTree) tree.getExpression()).getName().toString().equals("this")) {
return checkForReadBeforeInit(tree, state);
}
return Description.NO_MATCH;
}
开发者ID:uber,项目名称:NullAway,代码行数:24,代码来源:NullAway.java
示例3: checkReturnExpression
import com.google.errorprone.matchers.Description; //导入依赖的package包/类
private Description checkReturnExpression(
Tree tree, ExpressionTree retExpr, Symbol.MethodSymbol methodSymbol, VisitorState state) {
Type returnType = methodSymbol.getReturnType();
if (returnType.isPrimitive()) {
// check for unboxing
return doUnboxingCheck(state, retExpr);
}
if (returnType.toString().equals("java.lang.Void")) {
return Description.NO_MATCH;
}
if (NullabilityUtil.fromUnannotatedPackage(methodSymbol, config)
|| Nullness.hasNullableAnnotation(methodSymbol)) {
return Description.NO_MATCH;
}
if (mayBeNullExpr(state, retExpr)) {
String message = "returning @Nullable expression from method with @NonNull return type";
return createErrorDescriptionForNullAssignment(
MessageTypes.RETURN_NULLABLE, tree, message, retExpr, state.getPath());
}
return Description.NO_MATCH;
}
开发者ID:uber,项目名称:NullAway,代码行数:22,代码来源:NullAway.java
示例4: matchLambdaExpression
import com.google.errorprone.matchers.Description; //导入依赖的package包/类
@Override
public Description matchLambdaExpression(LambdaExpressionTree tree, VisitorState state) {
Symbol.MethodSymbol methodSymbol =
NullabilityUtil.getFunctionalInterfaceMethod(tree, state.getTypes());
handler.onMatchLambdaExpression(this, tree, state, methodSymbol);
Description description = checkParamOverriding(tree, tree.getParameters(), methodSymbol, true);
if (description != Description.NO_MATCH) {
return description;
}
if (tree.getBodyKind() == LambdaExpressionTree.BodyKind.EXPRESSION
&& methodSymbol.getReturnType().getKind() != TypeKind.VOID) {
ExpressionTree resExpr = (ExpressionTree) tree.getBody();
return checkReturnExpression(tree, resExpr, methodSymbol, state);
}
return Description.NO_MATCH;
}
开发者ID:uber,项目名称:NullAway,代码行数:17,代码来源:NullAway.java
示例5: checkPossibleUninitFieldRead
import com.google.errorprone.matchers.Description; //导入依赖的package包/类
private Description checkPossibleUninitFieldRead(
ExpressionTree tree,
VisitorState state,
Symbol symbol,
TreePath path,
TreePath enclosingBlockPath) {
if (!fieldInitializedByPreviousInitializer(symbol, enclosingBlockPath, state)
&& !fieldAlwaysInitializedBeforeRead(symbol, path, state, enclosingBlockPath)) {
return createErrorDescription(
MessageTypes.NONNULL_FIELD_READ_BEFORE_INIT,
tree,
"read of @NonNull field " + symbol + " before initialization",
path);
} else {
return Description.NO_MATCH;
}
}
开发者ID:uber,项目名称:NullAway,代码行数:18,代码来源:NullAway.java
示例6: matchBinary
import com.google.errorprone.matchers.Description; //导入依赖的package包/类
@Override
public Description matchBinary(BinaryTree tree, VisitorState state) {
ExpressionTree leftOperand = tree.getLeftOperand();
ExpressionTree rightOperand = tree.getRightOperand();
Type leftType = ASTHelpers.getType(leftOperand);
Type rightType = ASTHelpers.getType(rightOperand);
if (leftType == null || rightType == null) {
throw new RuntimeException();
}
if (leftType.isPrimitive() && !rightType.isPrimitive()) {
return doUnboxingCheck(state, rightOperand);
}
if (rightType.isPrimitive() && !leftType.isPrimitive()) {
return doUnboxingCheck(state, leftOperand);
}
return Description.NO_MATCH;
}
开发者ID:uber,项目名称:NullAway,代码行数:18,代码来源:NullAway.java
示例7: doUnboxingCheck
import com.google.errorprone.matchers.Description; //导入依赖的package包/类
/**
* if any expression has non-primitive type, we should check that it can't be null as it is
* getting unboxed
*
* @param expressions expressions to check
* @return error Description if an error is found, otherwise NO_MATCH
*/
private Description doUnboxingCheck(VisitorState state, ExpressionTree... expressions) {
for (ExpressionTree tree : expressions) {
Type type = ASTHelpers.getType(tree);
if (type == null) {
throw new RuntimeException("was not expecting null type");
}
if (!type.isPrimitive()) {
if (mayBeNullExpr(state, tree)) {
return createErrorDescription(
MessageTypes.UNBOX_NULLABLE, tree, "unboxing of a @Nullable value", state.getPath());
}
}
}
return Description.NO_MATCH;
}
开发者ID:uber,项目名称:NullAway,代码行数:23,代码来源:NullAway.java
示例8: matchDereference
import com.google.errorprone.matchers.Description; //导入依赖的package包/类
private Description matchDereference(
ExpressionTree baseExpression, ExpressionTree derefExpression, VisitorState state) {
Symbol dereferenced = ASTHelpers.getSymbol(baseExpression);
if (dereferenced == null
|| dereferenced.type.isPrimitive()
|| !kindMayDeferenceNull(dereferenced.getKind())) {
// we know we don't have a null dereference here
return Description.NO_MATCH;
}
if (mayBeNullExpr(state, baseExpression)) {
String message = "dereferenced expression " + baseExpression.toString() + " is @Nullable";
return createErrorDescriptionForNullAssignment(
MessageTypes.DEREFERENCE_NULLABLE,
derefExpression,
message,
baseExpression,
state.getPath());
}
return Description.NO_MATCH;
}
开发者ID:uber,项目名称:NullAway,代码行数:21,代码来源:NullAway.java
示例9: changeReturnNullabilityFix
import com.google.errorprone.matchers.Description; //导入依赖的package包/类
private Description.Builder changeReturnNullabilityFix(
Tree suggestTree, Description.Builder builder) {
if (suggestTree.getKind() != Tree.Kind.METHOD) {
throw new RuntimeException("This should be a MethodTree");
}
SuggestedFix.Builder fixBuilder = SuggestedFix.builder();
MethodTree methodTree = (MethodTree) suggestTree;
int countNullableAnnotations = 0;
for (AnnotationTree annotationTree : methodTree.getModifiers().getAnnotations()) {
if (annotationTree.getAnnotationType().toString().endsWith("Nullable")) {
fixBuilder.delete(annotationTree);
countNullableAnnotations += 1;
}
}
assert countNullableAnnotations > 1;
return builder.addFix(fixBuilder.build());
}
开发者ID:uber,项目名称:NullAway,代码行数:18,代码来源:NullAway.java
示例10: scan
import com.google.errorprone.matchers.Description; //导入依赖的package包/类
@Override
public Void scan(Tree tree, Context context) {
if (tree == null) {
return null;
}
JCCompilationUnit compilationUnit = context.get(JCCompilationUnit.class);
for (T beforeTemplate : rule().beforeTemplates()) {
for (M match : beforeTemplate.match((JCTree) tree, context)) {
if (rule().rejectMatchesWithComments()) {
String matchContents = match.getRange(compilationUnit);
if (matchContents.contains("//") || matchContents.contains("/*")) {
continue;
}
}
Fix fix;
if (rule().afterTemplate() == null) {
fix = SuggestedFix.delete(match.getLocation());
} else {
fix = rule().afterTemplate().replace(match);
}
listener().onDescribed(new Description(
match.getLocation(), rule().qualifiedTemplateClass(), fix, SeverityLevel.WARNING));
}
}
return super.scan(tree, context);
}
开发者ID:sivakumar-kailasam,项目名称:refactor-faster,代码行数:27,代码来源:RefasterScanner.java
示例11: twoDiffs
import com.google.errorprone.matchers.Description; //导入依赖的package包/类
@Test
public void twoDiffs() {
DescriptionBasedDiff diff = DescriptionBasedDiff.create(compilationUnit);
diff.onDescribed(new Description(null, "message",
SuggestedFix.builder()
.replace(83, 86, "longer")
.replace(96, 99, "bar")
.build(),
SeverityLevel.NOT_A_PROBLEM));
diff.applyDifferences(sourceFile);
assertThat(sourceFile.getLines()).iteratesAs(
"package foo.bar;",
"class Foo {",
" public static void main(String[] args) {",
" System.longer.println(\"bar\");",
" }",
"}");
}
开发者ID:sivakumar-kailasam,项目名称:refactor-faster,代码行数:19,代码来源:DescriptionBasedDiffTest.java
示例12: addImport
import com.google.errorprone.matchers.Description; //导入依赖的package包/类
@Test
public void addImport() {
DescriptionBasedDiff diff = DescriptionBasedDiff.create(compilationUnit);
diff.onDescribed(new Description(null, "message",
SuggestedFix.builder().addImport("com.google.foo.Bar").build(),
SeverityLevel.NOT_A_PROBLEM));
diff.applyDifferences(sourceFile);
assertThat(sourceFile.getLines()).iteratesAs(
"package foo.bar;",
"",
"import com.google.foo.Bar;",
"class Foo {",
" public static void main(String[] args) {",
" System.out.println(\"foo\");",
" }",
"}");
}
开发者ID:sivakumar-kailasam,项目名称:refactor-faster,代码行数:18,代码来源:DescriptionBasedDiffTest.java
示例13: twoDiffsWithImport
import com.google.errorprone.matchers.Description; //导入依赖的package包/类
@Test
public void twoDiffsWithImport() {
DescriptionBasedDiff diff = DescriptionBasedDiff.create(compilationUnit);
diff.onDescribed(new Description(null, "message",
SuggestedFix.builder()
.replace(83, 86, "longer")
.replace(96, 99, "bar")
.addImport("com.google.foo.Bar")
.build(),
SeverityLevel.NOT_A_PROBLEM));
diff.applyDifferences(sourceFile);
assertThat(sourceFile.getLines()).iteratesAs(
"package foo.bar;",
"",
"import com.google.foo.Bar;",
"class Foo {",
" public static void main(String[] args) {",
" System.longer.println(\"bar\");",
" }",
"}");
}
开发者ID:sivakumar-kailasam,项目名称:refactor-faster,代码行数:22,代码来源:DescriptionBasedDiffTest.java
示例14: matchMethodInvocation
import com.google.errorprone.matchers.Description; //导入依赖的package包/类
@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
ImmutableList<Parameter> formal =
Parameter.createListFromVarSymbols(ASTHelpers.getSymbol(tree).getParameters());
Stream<Parameter> actual =
Parameter.createListFromExpressionTrees(tree.getArguments()).stream();
Changes changes =
Changes.create(
formal.stream().map(f -> 1.0).collect(toImmutableList()),
formal.stream().map(f -> 0.0).collect(toImmutableList()),
Streams.zip(formal.stream(), actual, ParameterPair::create)
.collect(toImmutableList()));
boolean result =
!new NameInCommentHeuristic()
.isAcceptableChange(changes, tree, ASTHelpers.getSymbol(tree), state);
return buildDescription(tree).setMessage(String.valueOf(result)).build();
}
开发者ID:google,项目名称:error-prone,代码行数:20,代码来源:NameInCommentHeuristicTest.java
示例15: matchNewClass
import com.google.errorprone.matchers.Description; //导入依赖的package包/类
@Override
public Description matchNewClass(NewClassTree tree, VisitorState state) {
if (ASTHelpers.isSameType(
state.getSymtab().stringBuilderType, ASTHelpers.getType(tree.getIdentifier()), state)
&& tree.getArguments().size() == 1) {
ExpressionTree argument = tree.getArguments().get(0);
Type type = ((JCTree) argument).type;
if (type.getKind() == TypeKind.CHAR) {
if (argument.getKind() == Kind.CHAR_LITERAL) {
char ch = (Character) ((LiteralTree) argument).getValue();
return describeMatch(
tree,
SuggestedFix.replace(argument, "\"" + Convert.quote(Character.toString(ch)) + "\""));
} else {
return describeMatch(
tree,
SuggestedFix.replace(
tree,
"new StringBuilder().append(" + state.getSourceForNode((JCTree) argument) + ")"));
}
}
}
return Description.NO_MATCH;
}
开发者ID:google,项目名称:error-prone,代码行数:25,代码来源:StringBuilderInitWithChar.java
示例16: matchMethodInvocation
import com.google.errorprone.matchers.Description; //导入依赖的package包/类
@Override
public Description matchMethodInvocation(
MethodInvocationTree methodInvocationTree, VisitorState visitorState) {
if (!TO_ARRAY_MATCHER.matches(methodInvocationTree, visitorState)) {
return NO_MATCH;
}
Types types = visitorState.getTypes();
Type variableType =
types.elemtype(getType(getOnlyElement(methodInvocationTree.getArguments())));
if (variableType == null) {
return NO_MATCH;
}
Type collectionType =
types.asSuper(
ASTHelpers.getReceiverType(methodInvocationTree),
visitorState.getSymbolFromString("java.util.Collection"));
List<Type> typeArguments = collectionType.getTypeArguments();
if (!typeArguments.isEmpty()
&& !types.isCastable(
types.erasure(variableType), types.erasure(getOnlyElement(typeArguments)))) {
return describeMatch(methodInvocationTree);
}
return NO_MATCH;
}
开发者ID:google,项目名称:error-prone,代码行数:27,代码来源:CollectionToArraySafeParameter.java
示例17: matchBinary
import com.google.errorprone.matchers.Description; //导入依赖的package包/类
@Override
public Description matchBinary(BinaryTree tree, VisitorState state) {
switch (tree.getKind()) {
case AND:
case OR:
break;
default:
return NO_MATCH;
}
if (!isSameType(getType(tree), state.getSymtab().booleanType, state)) {
return NO_MATCH;
}
Iterator<Tree> stateIterator = state.getPath().getParentPath().iterator();
Tree parent = stateIterator.next();
if (parent instanceof BinaryTree
&& (parent.getKind() == Kind.AND || parent.getKind() == Kind.OR)) {
return NO_MATCH;
} else {
SuggestedFix.Builder fix = SuggestedFix.builder();
new TreeScannerBinary(state).scan(tree, fix);
return describeMatch(tree, fix.build());
}
}
开发者ID:google,项目名称:error-prone,代码行数:26,代码来源:ShortCircuitBoolean.java
示例18: matchMethodInvocation
import com.google.errorprone.matchers.Description; //导入依赖的package包/类
@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
if (!methodSelect(
instanceMethod(Matchers.<ExpressionTree>isSubtypeOf("java.lang.Class"), "getAnnotation"))
.matches(tree, state)) {
return Description.NO_MATCH;
}
MemberSelectTree memTree = (MemberSelectTree) tree.getArguments().get(0);
TypeSymbol annotation = ASTHelpers.getSymbol(memTree.getExpression()).type.tsym;
Retention retention = ASTHelpers.getAnnotation(annotation, Retention.class);
if (retention != null && retention.value().equals(RUNTIME)) {
return Description.NO_MATCH;
}
return describeMatch(tree, new SuggestedFix().replace(tree, "null"));
}
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:18,代码来源:NonRuntimeAnnotation.java
示例19: matchBinary
import com.google.errorprone.matchers.Description; //导入依赖的package包/类
@Override
public final Description matchBinary(BinaryTree tree, VisitorState state) {
switch (tree.getKind()) {
case EQUAL_TO:
case NOT_EQUAL_TO:
break;
default:
return Description.NO_MATCH;
}
if (tree.getLeftOperand().getKind() == Kind.NULL_LITERAL
|| !matchArgument(tree.getLeftOperand(), state)) {
return Description.NO_MATCH;
}
if (tree.getRightOperand().getKind() == Kind.NULL_LITERAL
|| !matchArgument(tree.getRightOperand(), state)) {
return Description.NO_MATCH;
}
Description.Builder builder = buildDescription(tree);
addFixes(builder, tree, state);
return builder.build();
}
开发者ID:google,项目名称:error-prone,代码行数:23,代码来源:AbstractReferenceEquality.java
示例20: matchMethodInvocation
import com.google.errorprone.matchers.Description; //导入依赖的package包/类
@Override
public Description matchMethodInvocation(
MethodInvocationTree methodInvocationTree, VisitorState state) {
if (!BAD_REGEX_USAGE.matches(methodInvocationTree, state)) {
return Description.NO_MATCH;
}
// TODO: Suggest fixes for more situations.
Fix fix = Fix.NO_FIX;
ExpressionTree arg = methodInvocationTree.getArguments().get(0);
String value = (String) ((JCExpression) arg).type.constValue();
String message = "";
if (".".equals(value)) {
fix = new SuggestedFix().replace(arg, "\"\\\\.\"");
message = "\".\" is a valid but useless regex";
} else {
try {
Pattern.compile(value);
} catch (PatternSyntaxException e) {
message = e.getMessage();
}
}
return new Description(methodInvocationTree, pattern, getDiagnosticMessage(message), fix);
}
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:26,代码来源:InvalidPatternSyntax.java
注:本文中的com.google.errorprone.matchers.Description类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论