本文整理汇总了Java中com.google.errorprone.VisitorState.isAndroidCompatible方法的典型用法代码示例。如果您正苦于以下问题:Java VisitorState.isAndroidCompatible方法的具体用法?Java VisitorState.isAndroidCompatible怎么用?Java VisitorState.isAndroidCompatible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.errorprone.VisitorState
的用法示例。
在下文中一共展示了VisitorState.isAndroidCompatible方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getQualifiedName
import com.google.errorprone.VisitorState; //导入方法依赖的package包/类
private static String getQualifiedName(VisitorState state, SuggestedFix.Builder builder) {
// TODO(cpovirk): Suggest @NullableDecl if the code uses that.
Symbol sym = FindIdentifiers.findIdent("Nullable", state, KindSelector.VAL_TYP);
String defaultType =
state.isAndroidCompatible()
? "android.support.annotation.Nullable"
: "javax.annotation.Nullable";
if (sym != null) {
ClassSymbol classSym = (ClassSymbol) sym;
if (classSym.isAnnotationType()) {
// We've got an existing annotation called Nullable. We can use this.
return "Nullable";
} else {
// It's not an annotation type. We have to fully-qualify the import.
return defaultType;
}
}
// There is no symbol already. Import and use.
builder.addImport(defaultType);
return "Nullable";
}
示例2: matchClass
import com.google.errorprone.VisitorState; //导入方法依赖的package包/类
@Override
public final Description matchClass(ClassTree classTree, VisitorState state) {
if (SCOPE_OR_QUALIFIER_ANNOTATION_MATCHER.matches(classTree, state)) {
ClassSymbol classSymbol = ASTHelpers.getSymbol(classTree);
if (hasSourceRetention(classSymbol)) {
return describe(classTree, state, ASTHelpers.getAnnotation(classSymbol, Retention.class));
}
// TODO(glorioso): This is a poor hack to exclude android apps that are more likely to not
// have reflective DI than normal java. JSR spec still says the annotations should be
// runtime-retained, but this reduces the instances that are flagged.
if (!state.isAndroidCompatible() && doesNotHaveRuntimeRetention(classSymbol)) {
// Is this in a dagger component?
ClassTree outer = ASTHelpers.findEnclosingNode(state.getPath(), ClassTree.class);
if (outer != null && InjectMatchers.IS_DAGGER_COMPONENT_OR_MODULE.matches(outer, state)) {
return Description.NO_MATCH;
}
return describe(classTree, state, ASTHelpers.getAnnotation(classSymbol, Retention.class));
}
}
return Description.NO_MATCH;
}
示例3: matchNewClass
import com.google.errorprone.VisitorState; //导入方法依赖的package包/类
@Override
public Description matchNewClass(NewClassTree tree, VisitorState state) {
if (state.isAndroidCompatible()) {
return NO_MATCH;
}
if (CTOR.matches(tree, state)) {
Description.Builder description = buildDescription(tree);
appendCharsets(description, tree, tree.getIdentifier(), tree.getArguments(), state);
return description.build();
}
if (FILE_READER.matches(tree, state)) {
return handleFileReader(tree, state);
}
if (FILE_WRITER.matches(tree, state)) {
return handleFileWriter(tree, state);
}
if (PRINT_WRITER.matches(tree, state)) {
return handlePrintWriter(tree, state);
}
if (PRINT_WRITER_OUTPUTSTREAM.matches(tree, state)) {
return handlePrintWriterOutputStream(tree, state);
}
if (SCANNER_MATCHER.matches(tree, state)) {
return handleScanner(tree, state);
}
return NO_MATCH;
}
示例4: addFixes
import com.google.errorprone.VisitorState; //导入方法依赖的package包/类
protected void addFixes(Description.Builder builder, BinaryTree tree, VisitorState state) {
ExpressionTree lhs = tree.getLeftOperand();
ExpressionTree rhs = tree.getRightOperand();
Optional<Fix> fixToReplaceOrStatement = inOrStatementWithEqualsCheck(state, tree);
if (fixToReplaceOrStatement.isPresent()) {
builder.addFix(fixToReplaceOrStatement.get());
return;
}
// Swap the order (e.g. rhs.equals(lhs) if the rhs is a non-null constant, and the lhs is not
if (ASTHelpers.constValue(lhs) == null && ASTHelpers.constValue(rhs) != null) {
ExpressionTree tmp = lhs;
lhs = rhs;
rhs = tmp;
}
String prefix = tree.getKind() == Kind.NOT_EQUAL_TO ? "!" : "";
String lhsSource = state.getSourceForNode(lhs);
String rhsSource = state.getSourceForNode(rhs);
Nullness nullness = getNullness(lhs, state);
// If the lhs is possibly-null, provide both options.
if (nullness != NONNULL) {
if (state.isAndroidCompatible()) {
builder.addFix(
SuggestedFix.builder()
.replace(
tree, String.format("%sObjects.equal(%s, %s)", prefix, lhsSource, rhsSource))
.addImport("com.google.common.base.Objects")
.build());
} else {
builder.addFix(
SuggestedFix.builder()
.replace(
tree, String.format("%sObjects.equals(%s, %s)", prefix, lhsSource, rhsSource))
.addImport("java.util.Objects")
.build());
}
}
if (nullness != NULL) {
builder.addFix(
SuggestedFix.replace(
tree,
String.format(
"%s%s.equals(%s)",
prefix,
lhs instanceof BinaryTree ? String.format("(%s)", lhsSource) : lhsSource,
rhsSource)));
}
}