#604: Add Contract annotation to ConfigurationSection

By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
Bukkit/Spigot
2021-04-27 11:34:32 +10:00
parent 8ffd9aaa65
commit 2b580de08b
2 changed files with 22 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -180,6 +181,7 @@ public interface ConfigurationSection {
* @param def The default value to return if the path is not found.
* @return Requested Object.
*/
@Contract("_, !null -> !null")
@Nullable
public Object get(@NotNull String path, @Nullable Object def);
@@ -254,6 +256,7 @@ public interface ConfigurationSection {
* not a String.
* @return Requested String.
*/
@Contract("_, !null -> !null")
@Nullable
public String getString(@NotNull String path, @Nullable String def);
@@ -456,6 +459,7 @@ public interface ConfigurationSection {
* not a List.
* @return Requested List.
*/
@Contract("_, !null -> !null")
@Nullable
public List<?> getList(@NotNull String path, @Nullable List<?> def);
@@ -677,6 +681,7 @@ public interface ConfigurationSection {
* the path
* @return Requested object
*/
@Contract("_, _, !null -> !null")
@Nullable
public <T extends Object> T getObject(@NotNull String path, @NotNull Class<T> clazz, @Nullable T def);
@@ -711,6 +716,7 @@ public interface ConfigurationSection {
* the path
* @return Requested {@link ConfigurationSerializable} object
*/
@Contract("_, _, !null -> !null")
@Nullable
public <T extends ConfigurationSerializable> T getSerializable(@NotNull String path, @NotNull Class<T> clazz, @Nullable T def);
@@ -740,6 +746,7 @@ public interface ConfigurationSection {
* not a Vector.
* @return Requested Vector.
*/
@Contract("_, !null -> !null")
@Nullable
public Vector getVector(@NotNull String path, @Nullable Vector def);
@@ -783,6 +790,7 @@ public interface ConfigurationSection {
* not an OfflinePlayer.
* @return Requested OfflinePlayer.
*/
@Contract("_, !null -> !null")
@Nullable
public OfflinePlayer getOfflinePlayer(@NotNull String path, @Nullable OfflinePlayer def);
@@ -825,6 +833,7 @@ public interface ConfigurationSection {
* not an ItemStack.
* @return Requested ItemStack.
*/
@Contract("_, !null -> !null")
@Nullable
public ItemStack getItemStack(@NotNull String path, @Nullable ItemStack def);
@@ -867,6 +876,7 @@ public interface ConfigurationSection {
* not a Color.
* @return Requested Color.
*/
@Contract("_, !null -> !null")
@Nullable
public Color getColor(@NotNull String path, @Nullable Color def);
@@ -909,6 +919,7 @@ public interface ConfigurationSection {
* a Location.
* @return Requested Location.
*/
@Contract("_, !null -> !null")
@Nullable
public Location getLocation(@NotNull String path, @Nullable Location def);

View File

@@ -14,6 +14,7 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -230,6 +231,7 @@ public class MemorySection implements ConfigurationSection {
}
@Override
@Contract("_, !null -> !null")
@Nullable
public Object get(@NotNull String path, @Nullable Object def) {
Validate.notNull(path, "Path cannot be null");
@@ -321,6 +323,7 @@ public class MemorySection implements ConfigurationSection {
}
@Override
@Contract("_, !null -> !null")
@Nullable
public String getString(@NotNull String path, @Nullable String def) {
Object val = get(path, def);
@@ -414,6 +417,7 @@ public class MemorySection implements ConfigurationSection {
}
@Override
@Contract("_, !null -> !null")
@Nullable
public List<?> getList(@NotNull String path, @Nullable List<?> def) {
Object val = get(path, def);
@@ -702,6 +706,7 @@ public class MemorySection implements ConfigurationSection {
return getObject(path, clazz, (def != null && clazz.isInstance(def)) ? clazz.cast(def) : null);
}
@Contract("_, _, !null -> !null")
@Nullable
@Override
public <T extends Object> T getObject(@NotNull String path, @NotNull Class<T> clazz, @Nullable T def) {
@@ -716,6 +721,7 @@ public class MemorySection implements ConfigurationSection {
return getObject(path, clazz);
}
@Contract("_, _, !null -> !null")
@Nullable
@Override
public <T extends ConfigurationSerializable> T getSerializable(@NotNull String path, @NotNull Class<T> clazz, @Nullable T def) {
@@ -729,6 +735,7 @@ public class MemorySection implements ConfigurationSection {
}
@Override
@Contract("_, !null -> !null")
@Nullable
public Vector getVector(@NotNull String path, @Nullable Vector def) {
return getSerializable(path, Vector.class, def);
@@ -746,6 +753,7 @@ public class MemorySection implements ConfigurationSection {
}
@Override
@Contract("_, !null -> !null")
@Nullable
public OfflinePlayer getOfflinePlayer(@NotNull String path, @Nullable OfflinePlayer def) {
return getSerializable(path, OfflinePlayer.class, def);
@@ -763,6 +771,7 @@ public class MemorySection implements ConfigurationSection {
}
@Override
@Contract("_, !null -> !null")
@Nullable
public ItemStack getItemStack(@NotNull String path, @Nullable ItemStack def) {
return getSerializable(path, ItemStack.class, def);
@@ -780,6 +789,7 @@ public class MemorySection implements ConfigurationSection {
}
@Override
@Contract("_, !null -> !null")
@Nullable
public Color getColor(@NotNull String path, @Nullable Color def) {
return getSerializable(path, Color.class, def);
@@ -797,6 +807,7 @@ public class MemorySection implements ConfigurationSection {
}
@Override
@Contract("_, !null -> !null")
@Nullable
public Location getLocation(@NotNull String path, @Nullable Location def) {
return getSerializable(path, Location.class, def);