Skip to content

Commit

Permalink
Merge pull request #235 from Sxtanna/feature/annotations
Browse files Browse the repository at this point in the history
Project Wide Static Analysis Annotations
  • Loading branch information
ljacqu authored Jun 4, 2022
2 parents 2cb36c4 + 9ea6971 commit 9dbf613
Show file tree
Hide file tree
Showing 79 changed files with 563 additions and 494 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@

<!-- FindBugs, has implementation for @Nullable -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
<scope>provided</scope>
<version>3.0.2</version>
</dependency>

<!-- Unit testing -->
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/ch/jalu/configme/Comment.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ch.jalu.configme;

import org.jetbrains.annotations.NotNull;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand All @@ -18,6 +20,6 @@
*
* @return the comment to associate with the property
*/
String[] value();
String @NotNull [] value();

}
3 changes: 2 additions & 1 deletion src/main/java/ch/jalu/configme/SettingsHolder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.jalu.configme;

import ch.jalu.configme.configurationdata.CommentsConfiguration;
import org.jetbrains.annotations.NotNull;

/**
* Marker interface for classes that define Property objects.
Expand All @@ -24,7 +25,7 @@ public interface SettingsHolder {
*
* @param conf the comments configuration
*/
default void registerComments(CommentsConfiguration conf) {
default void registerComments(@NotNull CommentsConfiguration conf) {
// override to register comments for sections
}
}
5 changes: 3 additions & 2 deletions src/main/java/ch/jalu/configme/SettingsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ch.jalu.configme.migration.MigrationService;
import ch.jalu.configme.properties.Property;
import org.jetbrains.annotations.NotNull;

/**
* Settings manager.
Expand All @@ -25,7 +26,7 @@ public interface SettingsManager {
* @param <T> The property's type
* @return The property's value
*/
<T> T getProperty(Property<T> property);
<T> T getProperty(@NotNull Property<T> property);

/**
* Sets a new value for the given property.
Expand All @@ -34,7 +35,7 @@ public interface SettingsManager {
* @param value The new value to assign to the property
* @param <T> The property's type
*/
<T> void setProperty(Property<T> property, T value);
<T> void setProperty(@NotNull Property<T> property, @NotNull T value);

/**
* Reloads the configuration.
Expand Down
27 changes: 14 additions & 13 deletions src/main/java/ch/jalu/configme/SettingsManagerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import ch.jalu.configme.resource.YamlFileResource;
import ch.jalu.configme.resource.YamlFileResourceOptions;
import ch.jalu.configme.utils.Utils;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.nio.file.Path;
import java.util.Objects;
Expand All @@ -21,9 +22,9 @@ public final class SettingsManagerBuilder {

private final PropertyResource resource;
private ConfigurationData configurationData;
private MigrationService migrationService;
private @Nullable MigrationService migrationService;

private SettingsManagerBuilder(PropertyResource resource) {
private SettingsManagerBuilder(@NotNull PropertyResource resource) {
this.resource = resource;
}

Expand All @@ -33,7 +34,7 @@ private SettingsManagerBuilder(PropertyResource resource) {
* @param file the yaml file to use
* @return settings manager builder
*/
public static SettingsManagerBuilder withYamlFile(Path file) {
public static @NotNull SettingsManagerBuilder withYamlFile(@NotNull Path file) {
return withYamlFile(file, YamlFileResourceOptions.builder().build());
}

Expand All @@ -43,7 +44,7 @@ public static SettingsManagerBuilder withYamlFile(Path file) {
* @param file the yaml file to use
* @return settings manager builder
*/
public static SettingsManagerBuilder withYamlFile(File file) {
public static @NotNull SettingsManagerBuilder withYamlFile(@NotNull File file) {
return withYamlFile(file.toPath());
}

Expand All @@ -54,7 +55,7 @@ public static SettingsManagerBuilder withYamlFile(File file) {
* @param resourceOptions the resource options
* @return settings manager builder
*/
public static SettingsManagerBuilder withYamlFile(Path path, YamlFileResourceOptions resourceOptions) {
public static @NotNull SettingsManagerBuilder withYamlFile(@NotNull Path path, @NotNull YamlFileResourceOptions resourceOptions) {
Utils.createFileIfNotExists(path);
return new SettingsManagerBuilder(new YamlFileResource(path, resourceOptions));
}
Expand All @@ -66,7 +67,7 @@ public static SettingsManagerBuilder withYamlFile(Path path, YamlFileResourceOpt
* @param resourceOptions the resource options
* @return settings manager builder
*/
public static SettingsManagerBuilder withYamlFile(File file, YamlFileResourceOptions resourceOptions) {
public static @NotNull SettingsManagerBuilder withYamlFile(@NotNull File file, @NotNull YamlFileResourceOptions resourceOptions) {
return withYamlFile(file.toPath(), resourceOptions);
}

Expand All @@ -76,7 +77,7 @@ public static SettingsManagerBuilder withYamlFile(File file, YamlFileResourceOpt
* @param resource the resource to use
* @return settings manager builder
*/
public static SettingsManagerBuilder withResource(PropertyResource resource) {
public static @NotNull SettingsManagerBuilder withResource(@NotNull PropertyResource resource) {
return new SettingsManagerBuilder(resource);
}

Expand All @@ -87,7 +88,7 @@ public static SettingsManagerBuilder withResource(PropertyResource resource) {
* @return this builder
*/
@SafeVarargs
public final SettingsManagerBuilder configurationData(Class<? extends SettingsHolder>... classes) {
public final @NotNull SettingsManagerBuilder configurationData(@NotNull Class<? extends SettingsHolder>... classes) {
this.configurationData = ConfigurationDataBuilder.createConfiguration(classes);
return this;
}
Expand All @@ -98,7 +99,7 @@ public final SettingsManagerBuilder configurationData(Class<? extends SettingsHo
* @param configurationData the configuration data
* @return this builder
*/
public SettingsManagerBuilder configurationData(ConfigurationData configurationData) {
public @NotNull SettingsManagerBuilder configurationData(@NotNull ConfigurationData configurationData) {
this.configurationData = configurationData;
return this;
}
Expand All @@ -109,7 +110,7 @@ public SettingsManagerBuilder configurationData(ConfigurationData configurationD
* @param migrationService the migration service to use (or null)
* @return this builder
*/
public SettingsManagerBuilder migrationService(@Nullable MigrationService migrationService) {
public @NotNull SettingsManagerBuilder migrationService(@Nullable MigrationService migrationService) {
this.migrationService = migrationService;
return this;
}
Expand All @@ -120,7 +121,7 @@ public SettingsManagerBuilder migrationService(@Nullable MigrationService migrat
*
* @return this builder
*/
public SettingsManagerBuilder useDefaultMigrationService() {
public @NotNull SettingsManagerBuilder useDefaultMigrationService() {
this.migrationService = new PlainMigrationService();
return this;
}
Expand All @@ -131,7 +132,7 @@ public SettingsManagerBuilder useDefaultMigrationService() {
*
* @return the settings manager
*/
public SettingsManager create() {
public @NotNull SettingsManager create() {
Objects.requireNonNull(resource, "resource");
Objects.requireNonNull(configurationData, "configurationData");
return new SettingsManagerImpl(resource, configurationData, migrationService);
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/ch/jalu/configme/SettingsManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import ch.jalu.configme.resource.PropertyReader;
import ch.jalu.configme.resource.PropertyResource;

import javax.annotation.Nullable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Default implementation of {@link SettingsManager}. Use the {@link SettingsManagerBuilder} to create instances.
Expand Down Expand Up @@ -37,7 +38,7 @@ public class SettingsManagerImpl implements SettingsManager {
* @param configurationData the configuration data
* @param migrationService migration service to check the property resource with
*/
protected SettingsManagerImpl(PropertyResource resource, ConfigurationData configurationData,
protected SettingsManagerImpl(@NotNull PropertyResource resource, @NotNull ConfigurationData configurationData,
@Nullable MigrationService migrationService) {
this.configurationData = configurationData;
this.resource = resource;
Expand All @@ -53,7 +54,7 @@ protected SettingsManagerImpl(PropertyResource resource, ConfigurationData confi
* @return the property's value
*/
@Override
public <T> T getProperty(Property<T> property) {
public <T> T getProperty(@NotNull Property<T> property) {
return configurationData.getValue(property);
}

Expand All @@ -65,7 +66,7 @@ public <T> T getProperty(Property<T> property) {
* @param <T> the property's type
*/
@Override
public <T> void setProperty(Property<T> property, T value) {
public <T> void setProperty(@NotNull Property<T> property, @NotNull T value) {
configurationData.setValue(property, value);
}

Expand Down Expand Up @@ -93,16 +94,15 @@ protected void loadFromResourceAndValidate() {
}
}

protected final PropertyResource getPropertyResource() {
protected final @NotNull PropertyResource getPropertyResource() {
return resource;
}

protected final ConfigurationData getConfigurationData() {
protected final @NotNull ConfigurationData getConfigurationData() {
return configurationData;
}

@Nullable
protected final MigrationService getMigrationService() {
protected final @Nullable MigrationService getMigrationService() {
return migrationService;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ch.jalu.configme.beanmapper;

import ch.jalu.configme.exception.ConfigMeException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Exception during a bean mapping process.
Expand All @@ -14,7 +16,7 @@ public class ConfigMeMapperException extends ConfigMeException {
*
* @param message the exception message
*/
public ConfigMeMapperException(String message) {
public ConfigMeMapperException(@NotNull String message) {
super(message);
}

Expand All @@ -24,7 +26,7 @@ public ConfigMeMapperException(String message) {
* @param message the exception message
* @param cause the cause
*/
public ConfigMeMapperException(String message, Throwable cause) {
public ConfigMeMapperException(@NotNull String message, @Nullable Throwable cause) {
super(message, cause);
}

Expand All @@ -34,7 +36,7 @@ public ConfigMeMapperException(String message, Throwable cause) {
* @param mappingContext the mapping context with which the message should be extended
* @param message basic message to extend
*/
public ConfigMeMapperException(MappingContext mappingContext, String message) {
public ConfigMeMapperException(@NotNull MappingContext mappingContext, @NotNull String message) {
super(constructMessage(mappingContext, message));
}

Expand All @@ -45,11 +47,11 @@ public ConfigMeMapperException(MappingContext mappingContext, String message) {
* @param message basic message to extend
* @param cause the cause
*/
public ConfigMeMapperException(MappingContext mappingContext, String message, Throwable cause) {
public ConfigMeMapperException(@NotNull MappingContext mappingContext, @NotNull String message, @Nullable Throwable cause) {
super(constructMessage(mappingContext, message), cause);
}

private static String constructMessage(MappingContext mappingContext, String message) {
private static @NotNull String constructMessage(@NotNull MappingContext mappingContext, @NotNull String message) {
return message + ", for mapping of: [" + mappingContext.createDescription() + "]";
}
}
4 changes: 3 additions & 1 deletion src/main/java/ch/jalu/configme/beanmapper/DefaultMapper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ch.jalu.configme.beanmapper;

import org.jetbrains.annotations.NotNull;

/**
* Provides the {@link Mapper} instance which is used by default.
*/
Expand All @@ -13,7 +15,7 @@ private DefaultMapper() {
/**
* @return default mapper instance
*/
public static Mapper getInstance() {
public static @NotNull Mapper getInstance() {
if (instance == null) {
instance = new DefaultMapper();
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/ch/jalu/configme/beanmapper/ExportName.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ch.jalu.configme.beanmapper;

import org.jetbrains.annotations.NotNull;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand All @@ -18,6 +20,6 @@
/**
* @return the name to use when interacting with property resources
*/
String value();
@NotNull String value();

}
12 changes: 5 additions & 7 deletions src/main/java/ch/jalu/configme/beanmapper/Mapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import ch.jalu.configme.properties.convertresult.ConvertErrorRecorder;
import ch.jalu.configme.utils.TypeInformation;

import javax.annotation.Nullable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Creates JavaBeans based on the values coming from a property reader. See the JavaDoc on the default implementation,
Expand All @@ -21,8 +21,7 @@ public interface Mapper {
* @param errorRecorder error recorder to register errors even if a valid value is returned
* @return object of the given type, or null if not possible
*/
@Nullable
Object convertToBean(@Nullable Object value, TypeInformation typeInformation, ConvertErrorRecorder errorRecorder);
@Nullable Object convertToBean(@Nullable Object value, @NotNull TypeInformation typeInformation, @NotNull ConvertErrorRecorder errorRecorder);

/**
* Converts the given value to an object of the given class, if possible. Returns null otherwise.
Expand All @@ -37,7 +36,7 @@ public interface Mapper {
*/
@Nullable
@SuppressWarnings("unchecked")
default <T> T convertToBean(@Nullable Object value, Class<T> clazz, ConvertErrorRecorder errorRecorder) {
default <T> T convertToBean(@Nullable Object value, @NotNull Class<T> clazz, @NotNull ConvertErrorRecorder errorRecorder) {
return (T) convertToBean(value, new TypeInformation(clazz), errorRecorder);
}

Expand All @@ -49,7 +48,6 @@ default <T> T convertToBean(@Nullable Object value, Class<T> clazz, ConvertError
* @param object the object to convert to its export value
* @return export value to use
*/
@Nullable
Object toExportValue(@Nullable Object object);
@Nullable Object toExportValue(@Nullable Object object);

}
Loading

0 comments on commit 9dbf613

Please sign in to comment.