Skip to content

Commit b8593fc

Browse files
j2objc-copybaracopybara-github
authored andcommitted
Ignore method without return value for property annotation.
PiperOrigin-RevId: 702828504
1 parent 0eef5fb commit b8593fc

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

translator/src/main/java/com/google/devtools/j2objc/translate/Rewriter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ public void endVisit(PropertyAnnotation node) {
272272
MethodDeclaration method = (MethodDeclaration) body;
273273
if (method.getParameters().isEmpty()
274274
&& !method.isConstructor()
275+
&& !TypeUtil.isVoid(method.getReturnTypeMirror())
275276
&& !ElementUtil.hasAnnotation(method.getExecutableElement(), Property.Suppress.class)) {
276277
method.setIsPseudoProperty(true);
277278
}

translator/src/test/java/com/google/devtools/j2objc/gen/ObjectiveCHeaderGeneratorTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,18 @@ public void testPropertiesOfGetTypesWithSettersNullable() throws IOException {
887887
+ " NSString * fooField;");
888888
}
889889

890+
public void testPropertyAnnotationIgnoresVoidMethod() throws IOException {
891+
String sourceContent =
892+
" import com.google.j2objc.annotations.Property;"
893+
+ "@Property "
894+
+ "public class FooBar {"
895+
+ " public void doFoo() {}"
896+
+ " "
897+
+ "}";
898+
String translation = translateSourceFile(sourceContent, "FooBar", "FooBar.h");
899+
assertNotInTranslation(translation, "@property");
900+
}
901+
890902
public void testPropertiesOfClassTypes() throws IOException {
891903
String sourceContent =
892904
" import com.google.j2objc.annotations.Property;"

0 commit comments

Comments
 (0)