What is Nope'n!
masterfinal, abstract, or annotated with @Open. This helps prevent the accidental creation of open classes, following the principle from Effective Java (Item 19) to design and document for inheritance or prohibit it.repository·master·Indexed 43 days ago
https://github.com/jakewharton/nopenAn Error Prone checker that enforces explicit inheritance intent by requiring classes to be marked as final, abstract, or annotated with @Open.
final, abstract, or annotated with @Open. This helps prevent the accidental creation of open classes, following the principle from Effective Java (Item 19) to design and document for inheritance or prohibit it.To satisfy the checker, a class must meet one of three criteria:
final.abstract.@Open from the com.jakewharton.nopen.annotation package.Any class that is neither final nor abstract and lacks the @Open annotation will trigger an error: [Nopen] Classes should be explicitly marked final, abstract, or @Open.
import com.jakewharton.nopen.annotation.Open;
final class Foo {} // Valid
abstract class Bar {} // Valid
@Open class Baz {} // Valid
class Bad {} // Error: [Nopen] Classes should be explicitly marked final, abstract, or @OpenIf you want to disable the Nopen check specifically for test compilation in a standard Java project, configure the compileTestJava task to set the severity to OFF.
import net.ltgt.gradle.errorprone.CheckSeverity
tasks.named("compileTestJava").configure {
options.errorprone.check("Nopen", CheckSeverity.OFF)
}In Android projects, you can disable the Nopen check for both testVariants and unitTestVariants by configuring their javaCompileProvider.
import net.ltgt.gradle.errorprone.CheckSeverity
android.testVariants.all { variant ->
variant.javaCompileProvider.configure {
options.errorprone.check("Nopen", CheckSeverity.OFF)
}
}
android.unitTestVariants.all { variant ->
variant.javaCompileProvider.configure {
options.errorprone.check("Nopen", CheckSeverity.OFF)
}
}To use Nope'n!, add the annotations to your compileOnly configuration and the checker to your errorprone configuration using the net.ltgt.errorprone plugin.
dependencies {
compileOnly 'com.jakewharton.nopen:nopen-annotations:1.0.1'
errorprone 'com.jakewharton.nopen:nopen-checker:1.0.1'
}