Nope'n Annotations

An error-prone checker which requires that classes be final, abstract or annotated with @Open.

License

License

GroupId

GroupId

com.jakewharton.nopen
ArtifactId

ArtifactId

nopen-annotations
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Nope'n Annotations
An error-prone checker which requires that classes be final, abstract or annotated with @Open.
Project URL

Project URL

https://github.com/JakeWharton/nopen/
Source Code Management

Source Code Management

https://github.com/JakeWharton/nopen/

Download nopen-annotations

How to add to project

<!-- https://jarcasting.com/artifacts/com.jakewharton.nopen/nopen-annotations/ -->
<dependency>
    <groupId>com.jakewharton.nopen</groupId>
    <artifactId>nopen-annotations</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.jakewharton.nopen/nopen-annotations/
implementation 'com.jakewharton.nopen:nopen-annotations:1.0.1'
// https://jarcasting.com/artifacts/com.jakewharton.nopen/nopen-annotations/
implementation ("com.jakewharton.nopen:nopen-annotations:1.0.1")
'com.jakewharton.nopen:nopen-annotations:jar:1.0.1'
<dependency org="com.jakewharton.nopen" name="nopen-annotations" rev="1.0.1">
  <artifact name="nopen-annotations" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.jakewharton.nopen', module='nopen-annotations', version='1.0.1')
)
libraryDependencies += "com.jakewharton.nopen" % "nopen-annotations" % "1.0.1"
[com.jakewharton.nopen/nopen-annotations "1.0.1"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Nope'n!

An error-prone checker which requires that classes be final, abstract, or annotated with @Open.

Design and document for inheritance or else prohibit it

– Item 19, Effective Java, Third Edition

Usage

Java creates new types as open by default which can be dangerous. This checker ensures that the intent to leave a class open is explicitly declared.

import com.jakewharton.nopen.annotation.Open;

final class Foo {}
abstract class Bar {}
@Open class Baz {}

Non-final, Non-abstract classes without the @Open annotation will be marked with an error.

class Bad {}
Bad.java:1: error: [Nopen] Classes should be explicitly marked final, abstract, or @Open
class Bad {}
^

For more information see Item 19 of Effective Java, Third Edition.

Download

Gradle, using net.ltgt.errorprone plugin:

dependencies {
  compileOnly 'com.jakewharton.nopen:nopen-annotations:1.0.1'
  errorprone 'com.jakewharton.nopen:nopen-checker:1.0.1'
}

By default the check will operate everywhere that error-prone runs. You can disable it for tests, for example, where the extra safety isn't necessary.

For Java projects:

import net.ltgt.gradle.errorprone.CheckSeverity

tasks.named("compileTestJava").configure {
  options.errorprone.check("Nopen", CheckSeverity.OFF)
}

For Android projects:

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)
  }
}

License

Copyright 2019 Jake Wharton

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Versions

Version
1.0.1
1.0.0