SPIGOT-2540: Add nullability annotations to entire Bukkit API
By: Darkyenus <darkyenus@gmail.com>
This commit is contained in:
@@ -19,6 +19,8 @@ import java.io.Writer;
|
||||
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.MemoryConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* This is a base class for all File based implementations of {@link
|
||||
@@ -39,7 +41,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
*
|
||||
* @param defaults Default value provider
|
||||
*/
|
||||
public FileConfiguration(Configuration defaults) {
|
||||
public FileConfiguration(@Nullable Configuration defaults) {
|
||||
super(defaults);
|
||||
}
|
||||
|
||||
@@ -58,7 +60,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
* any reason.
|
||||
* @throws IllegalArgumentException Thrown when file is null.
|
||||
*/
|
||||
public void save(File file) throws IOException {
|
||||
public void save(@NotNull File file) throws IOException {
|
||||
Validate.notNull(file, "File cannot be null");
|
||||
|
||||
Files.createParentDirs(file);
|
||||
@@ -89,7 +91,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
* any reason.
|
||||
* @throws IllegalArgumentException Thrown when file is null.
|
||||
*/
|
||||
public void save(String file) throws IOException {
|
||||
public void save(@NotNull String file) throws IOException {
|
||||
Validate.notNull(file, "File cannot be null");
|
||||
|
||||
save(new File(file));
|
||||
@@ -100,6 +102,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
*
|
||||
* @return String containing this configuration.
|
||||
*/
|
||||
@NotNull
|
||||
public abstract String saveToString();
|
||||
|
||||
/**
|
||||
@@ -120,7 +123,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
* a valid Configuration.
|
||||
* @throws IllegalArgumentException Thrown when file is null.
|
||||
*/
|
||||
public void load(File file) throws FileNotFoundException, IOException, InvalidConfigurationException {
|
||||
public void load(@NotNull File file) throws FileNotFoundException, IOException, InvalidConfigurationException {
|
||||
Validate.notNull(file, "File cannot be null");
|
||||
|
||||
final FileInputStream stream = new FileInputStream(file);
|
||||
@@ -141,7 +144,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
* represent a valid Configuration
|
||||
* @throws IllegalArgumentException thrown when reader is null
|
||||
*/
|
||||
public void load(Reader reader) throws IOException, InvalidConfigurationException {
|
||||
public void load(@NotNull Reader reader) throws IOException, InvalidConfigurationException {
|
||||
BufferedReader input = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader);
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
@@ -178,7 +181,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
* a valid Configuration.
|
||||
* @throws IllegalArgumentException Thrown when file is null.
|
||||
*/
|
||||
public void load(String file) throws FileNotFoundException, IOException, InvalidConfigurationException {
|
||||
public void load(@NotNull String file) throws FileNotFoundException, IOException, InvalidConfigurationException {
|
||||
Validate.notNull(file, "File cannot be null");
|
||||
|
||||
load(new File(file));
|
||||
@@ -199,7 +202,7 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
* invalid.
|
||||
* @throws IllegalArgumentException Thrown if contents is null.
|
||||
*/
|
||||
public abstract void loadFromString(String contents) throws InvalidConfigurationException;
|
||||
public abstract void loadFromString(@NotNull String contents) throws InvalidConfigurationException;
|
||||
|
||||
/**
|
||||
* Compiles the header for this {@link FileConfiguration} and returns the
|
||||
@@ -211,8 +214,10 @@ public abstract class FileConfiguration extends MemoryConfiguration {
|
||||
*
|
||||
* @return Compiled header
|
||||
*/
|
||||
@NotNull
|
||||
protected abstract String buildHeader();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FileConfigurationOptions options() {
|
||||
if (options == null) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.bukkit.configuration.file;
|
||||
|
||||
import org.bukkit.configuration.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Various settings for controlling the input and output of a {@link
|
||||
@@ -10,21 +12,24 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
|
||||
private String header = null;
|
||||
private boolean copyHeader = true;
|
||||
|
||||
protected FileConfigurationOptions(MemoryConfiguration configuration) {
|
||||
protected FileConfigurationOptions(@NotNull MemoryConfiguration configuration) {
|
||||
super(configuration);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FileConfiguration configuration() {
|
||||
return (FileConfiguration) super.configuration();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FileConfigurationOptions copyDefaults(boolean value) {
|
||||
super.copyDefaults(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FileConfigurationOptions pathSeparator(char value) {
|
||||
super.pathSeparator(value);
|
||||
@@ -45,6 +50,7 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
|
||||
*
|
||||
* @return Header
|
||||
*/
|
||||
@Nullable
|
||||
public String header() {
|
||||
return header;
|
||||
}
|
||||
@@ -64,7 +70,8 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
|
||||
* @param value New header
|
||||
* @return This object, for chaining
|
||||
*/
|
||||
public FileConfigurationOptions header(String value) {
|
||||
@NotNull
|
||||
public FileConfigurationOptions header(@Nullable String value) {
|
||||
this.header = value;
|
||||
return this;
|
||||
}
|
||||
@@ -110,6 +117,7 @@ public class FileConfigurationOptions extends MemoryConfigurationOptions {
|
||||
* @param value Whether or not to copy the header
|
||||
* @return This object, for chaining
|
||||
*/
|
||||
@NotNull
|
||||
public FileConfigurationOptions copyHeader(boolean value) {
|
||||
copyHeader = value;
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
@@ -28,6 +29,7 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
private final Representer yamlRepresenter = new YamlRepresenter();
|
||||
private final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions);
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String saveToString() {
|
||||
yamlOptions.setIndent(options().indent());
|
||||
@@ -45,7 +47,7 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFromString(String contents) throws InvalidConfigurationException {
|
||||
public void loadFromString(@NotNull String contents) throws InvalidConfigurationException {
|
||||
Validate.notNull(contents, "Contents cannot be null");
|
||||
|
||||
Map<?, ?> input;
|
||||
@@ -67,7 +69,7 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
protected void convertMapsToSections(Map<?, ?> input, ConfigurationSection section) {
|
||||
protected void convertMapsToSections(@NotNull Map<?, ?> input, @NotNull ConfigurationSection section) {
|
||||
for (Map.Entry<?, ?> entry : input.entrySet()) {
|
||||
String key = entry.getKey().toString();
|
||||
Object value = entry.getValue();
|
||||
@@ -80,7 +82,8 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
protected String parseHeader(String input) {
|
||||
@NotNull
|
||||
protected String parseHeader(@NotNull String input) {
|
||||
String[] lines = input.split("\r?\n", -1);
|
||||
StringBuilder result = new StringBuilder();
|
||||
boolean readingHeader = true;
|
||||
@@ -109,6 +112,7 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String buildHeader() {
|
||||
String header = options().header();
|
||||
@@ -147,6 +151,7 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public YamlConfigurationOptions options() {
|
||||
if (options == null) {
|
||||
@@ -169,7 +174,8 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
* @return Resulting configuration
|
||||
* @throws IllegalArgumentException Thrown if file is null
|
||||
*/
|
||||
public static YamlConfiguration loadConfiguration(File file) {
|
||||
@NotNull
|
||||
public static YamlConfiguration loadConfiguration(@NotNull File file) {
|
||||
Validate.notNull(file, "File cannot be null");
|
||||
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
@@ -197,7 +203,8 @@ public class YamlConfiguration extends FileConfiguration {
|
||||
* @return resulting configuration
|
||||
* @throws IllegalArgumentException Thrown if stream is null
|
||||
*/
|
||||
public static YamlConfiguration loadConfiguration(Reader reader) {
|
||||
@NotNull
|
||||
public static YamlConfiguration loadConfiguration(@NotNull Reader reader) {
|
||||
Validate.notNull(reader, "Stream cannot be null");
|
||||
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.bukkit.configuration.file;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Various settings for controlling the input and output of a {@link
|
||||
@@ -9,33 +11,38 @@ import org.apache.commons.lang.Validate;
|
||||
public class YamlConfigurationOptions extends FileConfigurationOptions {
|
||||
private int indent = 2;
|
||||
|
||||
protected YamlConfigurationOptions(YamlConfiguration configuration) {
|
||||
protected YamlConfigurationOptions(@NotNull YamlConfiguration configuration) {
|
||||
super(configuration);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public YamlConfiguration configuration() {
|
||||
return (YamlConfiguration) super.configuration();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public YamlConfigurationOptions copyDefaults(boolean value) {
|
||||
super.copyDefaults(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public YamlConfigurationOptions pathSeparator(char value) {
|
||||
super.pathSeparator(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public YamlConfigurationOptions header(String value) {
|
||||
public YamlConfigurationOptions header(@Nullable String value) {
|
||||
super.header(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public YamlConfigurationOptions copyHeader(boolean value) {
|
||||
super.copyHeader(value);
|
||||
@@ -61,6 +68,7 @@ public class YamlConfigurationOptions extends FileConfigurationOptions {
|
||||
* @param value New indent
|
||||
* @return This object, for chaining
|
||||
*/
|
||||
@NotNull
|
||||
public YamlConfigurationOptions indent(int value) {
|
||||
Validate.isTrue(value >= 2, "Indent must be at least 2 characters");
|
||||
Validate.isTrue(value <= 9, "Indent cannot be greater than 9 characters");
|
||||
|
||||
@@ -3,6 +3,8 @@ package org.bukkit.configuration.file;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.yaml.snakeyaml.nodes.Node;
|
||||
import org.yaml.snakeyaml.constructor.SafeConstructor;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
@@ -17,8 +19,10 @@ public class YamlConstructor extends SafeConstructor {
|
||||
}
|
||||
|
||||
private class ConstructCustomObject extends ConstructYamlMap {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object construct(Node node) {
|
||||
public Object construct(@NotNull Node node) {
|
||||
if (node.isTwoStepsConstruction()) {
|
||||
throw new YAMLException("Unexpected referential mapping structure. Node: " + node);
|
||||
}
|
||||
@@ -42,7 +46,7 @@ public class YamlConstructor extends SafeConstructor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void construct2ndStep(Node node, Object object) {
|
||||
public void construct2ndStep(@NotNull Node node, @NotNull Object object) {
|
||||
throw new YAMLException("Unexpected referential mapping structure. Node: " + node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.yaml.snakeyaml.nodes.Node;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
|
||||
@@ -18,15 +19,19 @@ public class YamlRepresenter extends Representer {
|
||||
}
|
||||
|
||||
private class RepresentConfigurationSection extends RepresentMap {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Node representData(Object data) {
|
||||
public Node representData(@NotNull Object data) {
|
||||
return super.representData(((ConfigurationSection) data).getValues(false));
|
||||
}
|
||||
}
|
||||
|
||||
private class RepresentConfigurationSerializable extends RepresentMap {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Node representData(Object data) {
|
||||
public Node representData(@NotNull Object data) {
|
||||
ConfigurationSerializable serializable = (ConfigurationSerializable) data;
|
||||
Map<String, Object> values = new LinkedHashMap<String, Object>();
|
||||
values.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(serializable.getClass()));
|
||||
|
||||
Reference in New Issue
Block a user