Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@
summary = "Comparing protobuf fields of type String using reference equality")
public class ProtoStringFieldReferenceEquality extends BugChecker implements BinaryTreeMatcher {

private static final String PROTO_SUPER_CLASS = "com.google.protobuf.GeneratedMessage";

private static final String LITE_PROTO_SUPER_CLASS = "com.google.protobuf.GeneratedMessageLite";
private static final String LITE_PROTO_INTERFACE = "com.google.protobuf.MessageLite";

private static final Matcher<ExpressionTree> PROTO_STRING_METHOD =
allOf(
instanceMethod().onDescendantOfAny(PROTO_SUPER_CLASS, LITE_PROTO_SUPER_CLASS),
instanceMethod().onDescendantOf(LITE_PROTO_INTERFACE),
isSameType(Suppliers.STRING_TYPE));

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ public class ProtoStringFieldReferenceEqualityTest {
public void positive() {
compilationHelper
.addSourceLines(
"com/google/protobuf/GeneratedMessage.java",
"com/google/protobuf/MessageLite.java",
"""
package com.google.protobuf;

public class GeneratedMessage {}
public interface MessageLite {}
""")
.addSourceLines(
"Proto.java",
"""
public abstract class Proto extends com.google.protobuf.GeneratedMessage {
public abstract class Proto implements com.google.protobuf.MessageLite {
public abstract String getMessage();
}
""")
Expand All @@ -68,16 +68,16 @@ boolean g(Proto proto) {
public void negative() {
compilationHelper
.addSourceLines(
"com/google/protobuf/GeneratedMessage.java",
"com/google/protobuf/MessageLite.java",
"""
package com.google.protobuf;

public class GeneratedMessage {}
public interface MessageLite {}
""")
.addSourceLines(
"Proto.java",
"""
public abstract class Proto extends com.google.protobuf.GeneratedMessage {
public abstract class Proto implements com.google.protobuf.MessageLite {
public abstract int getId();

public abstract String getMessage();
Expand Down