Loading tools/processors/immutability/src/android/processor/immutability/ImmutabilityProcessor.kt +9 −0 Original line number Diff line number Diff line Loading @@ -323,8 +323,15 @@ class ImmutabilityProcessor : AbstractProcessor() { parentPolicyExceptions: Set<Immutable.Policy.Exception>, nonInterfaceClassFailure: () -> String = { MessageUtils.nonInterfaceReturnFailure() }, ): Boolean { // Skip if the symbol being considered is itself ignored if (isIgnored(symbol)) return false // Skip if the type being checked, like for a typeArg or return type, is ignored if (isIgnored(type)) return false // Skip if that typeArg is itself ignored when inspected at the class header level if (isIgnored(type.asElement())) return false if (type.isPrimitive) return false if (type.isPrimitiveOrVoid) { printError(parentChain, symbol, MessageUtils.voidReturnFailure()) Loading Loading @@ -355,6 +362,8 @@ class ImmutabilityProcessor : AbstractProcessor() { var anyError = false type.typeArguments.forEachIndexed { index, typeArg -> if (isIgnored(typeArg.asElement())) return@forEachIndexed val argError = visitType(parentChain, seenTypesByPolicy, symbol, typeArg, newPolicyExceptions) { MessageUtils.nonInterfaceReturnFailure( Loading tools/processors/immutability/test/android/processor/ImmutabilityProcessorTest.kt +36 −0 Original line number Diff line number Diff line Loading @@ -287,6 +287,42 @@ class ImmutabilityProcessorTest { ) } @Test fun ignoredClass() = test( JavaFileObjects.forSourceString( "$PACKAGE_PREFIX.$DATA_CLASS_NAME", /* language=JAVA */ """ package $PACKAGE_PREFIX; import java.util.List; import java.util.Map; @Immutable public interface $DATA_CLASS_NAME { IgnoredClass getInnerClassOne(); NotIgnoredClass getInnerClassTwo(); Map<String, IgnoredClass> getInnerClassThree(); Map<String, NotIgnoredClass> getInnerClassFour(); @Immutable.Ignore final class IgnoredClass { public String innerField; } final class NotIgnoredClass { public String innerField; } } """.trimIndent() ), errors = listOf( nonInterfaceReturnFailure(line = 9), nonInterfaceReturnFailure(line = 11, prefix = "Value NotIgnoredClass"), classNotImmutableFailure(line = 18, className = "NotIgnoredClass"), nonInterfaceClassFailure(line = 18), memberNotMethodFailure(line = 19), ) ) private fun test( source: JavaFileObject, errors: List<CompilationError>, Loading Loading
tools/processors/immutability/src/android/processor/immutability/ImmutabilityProcessor.kt +9 −0 Original line number Diff line number Diff line Loading @@ -323,8 +323,15 @@ class ImmutabilityProcessor : AbstractProcessor() { parentPolicyExceptions: Set<Immutable.Policy.Exception>, nonInterfaceClassFailure: () -> String = { MessageUtils.nonInterfaceReturnFailure() }, ): Boolean { // Skip if the symbol being considered is itself ignored if (isIgnored(symbol)) return false // Skip if the type being checked, like for a typeArg or return type, is ignored if (isIgnored(type)) return false // Skip if that typeArg is itself ignored when inspected at the class header level if (isIgnored(type.asElement())) return false if (type.isPrimitive) return false if (type.isPrimitiveOrVoid) { printError(parentChain, symbol, MessageUtils.voidReturnFailure()) Loading Loading @@ -355,6 +362,8 @@ class ImmutabilityProcessor : AbstractProcessor() { var anyError = false type.typeArguments.forEachIndexed { index, typeArg -> if (isIgnored(typeArg.asElement())) return@forEachIndexed val argError = visitType(parentChain, seenTypesByPolicy, symbol, typeArg, newPolicyExceptions) { MessageUtils.nonInterfaceReturnFailure( Loading
tools/processors/immutability/test/android/processor/ImmutabilityProcessorTest.kt +36 −0 Original line number Diff line number Diff line Loading @@ -287,6 +287,42 @@ class ImmutabilityProcessorTest { ) } @Test fun ignoredClass() = test( JavaFileObjects.forSourceString( "$PACKAGE_PREFIX.$DATA_CLASS_NAME", /* language=JAVA */ """ package $PACKAGE_PREFIX; import java.util.List; import java.util.Map; @Immutable public interface $DATA_CLASS_NAME { IgnoredClass getInnerClassOne(); NotIgnoredClass getInnerClassTwo(); Map<String, IgnoredClass> getInnerClassThree(); Map<String, NotIgnoredClass> getInnerClassFour(); @Immutable.Ignore final class IgnoredClass { public String innerField; } final class NotIgnoredClass { public String innerField; } } """.trimIndent() ), errors = listOf( nonInterfaceReturnFailure(line = 9), nonInterfaceReturnFailure(line = 11, prefix = "Value NotIgnoredClass"), classNotImmutableFailure(line = 18, className = "NotIgnoredClass"), nonInterfaceClassFailure(line = 18), memberNotMethodFailure(line = 19), ) ) private fun test( source: JavaFileObject, errors: List<CompilationError>, Loading