|
| 1 | +/** |
| 2 | + * Provides classes and predicates for working with the Protobuf framework. |
| 3 | + */ |
| 4 | + |
| 5 | +import java |
| 6 | + |
| 7 | +/** |
| 8 | + * The interface `com.google.protobuf.Parser`. |
| 9 | + */ |
| 10 | +class ProtobufParser extends Interface { |
| 11 | + ProtobufParser() { this.hasQualifiedName("com.google.protobuf", "Parser") } |
| 12 | + |
| 13 | + /** |
| 14 | + * Gets a method named `parseFrom` (or similar) declared on a subtype of `com.google.protobuf.Parser`. |
| 15 | + */ |
| 16 | + Method getAParseFromMethod() { |
| 17 | + result.getDeclaringType().getASupertype*().getSourceDeclaration() = this and |
| 18 | + result.getName().matches("parse%From") |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +/** |
| 23 | + * The interface `com.google.protobuf.MessageLite`. |
| 24 | + */ |
| 25 | +class ProtobufMessageLite extends Interface { |
| 26 | + ProtobufMessageLite() { this.hasQualifiedName("com.google.protobuf", "MessageLite") } |
| 27 | + |
| 28 | + /** |
| 29 | + * Gets a static method named `parseFrom` (or similar) declared on a subtype of the `MessageLite` interface. |
| 30 | + */ |
| 31 | + Method getAParseFromMethod() { |
| 32 | + result = getASubtype+().getAMethod() and |
| 33 | + result.getName().matches("parse%From") and |
| 34 | + result.isStatic() |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Gets a getter method declared on a subtype of the `MessageLite` interface. |
| 39 | + */ |
| 40 | + Method getAGetterMethod() { |
| 41 | + exists(RefType decl | decl = result.getDeclaringType() and decl = this.getASubtype+() | |
| 42 | + exists(string name, string suffix | |
| 43 | + suffix = "" or |
| 44 | + suffix = "list" or |
| 45 | + suffix = "map" or |
| 46 | + suffix = "ordefault" or |
| 47 | + suffix = "orthrow" |
| 48 | + | |
| 49 | + exists(Field f | f.getDeclaringType() = decl | |
| 50 | + f.getName().toLowerCase().replaceAll("_", "") = name |
| 51 | + ) and |
| 52 | + result.getName().toLowerCase() = "get" + name + suffix |
| 53 | + ) |
| 54 | + ) |
| 55 | + } |
| 56 | +} |
0 commit comments