From 771180f217317e615ad11de50023dceec8200c07 Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Wed, 17 Jul 2024 14:50:19 -0700 Subject: [PATCH 1/3] Update lang package to new annotation conventions, new warning conventions, and use try-with-resources for loggers --- .../java/ch/njol/skript/classes/Changer.java | 36 +++--- .../java/ch/njol/skript/lang/Condition.java | 7 +- .../java/ch/njol/skript/lang/Debuggable.java | 2 +- src/main/java/ch/njol/skript/lang/Effect.java | 12 +- .../ch/njol/skript/lang/EffectSection.java | 7 +- .../njol/skript/lang/EffectSectionEffect.java | 2 +- .../java/ch/njol/skript/lang/Expression.java | 22 ++-- .../ch/njol/skript/lang/ExpressionInfo.java | 8 +- .../ch/njol/skript/lang/ExpressionList.java | 25 ++-- .../java/ch/njol/skript/lang/InputSource.java | 6 +- .../java/ch/njol/skript/lang/Literal.java | 5 +- .../java/ch/njol/skript/lang/LiteralList.java | 8 +- .../njol/skript/lang/ReturnableTrigger.java | 2 +- .../java/ch/njol/skript/lang/Section.java | 4 +- .../njol/skript/lang/SectionSkriptEvent.java | 2 +- .../java/ch/njol/skript/lang/SkriptEvent.java | 9 +- .../ch/njol/skript/lang/SkriptEventInfo.java | 31 ++--- .../ch/njol/skript/lang/SkriptParser.java | 108 ++++++------------ .../java/ch/njol/skript/lang/Statement.java | 10 +- .../java/ch/njol/skript/lang/Trigger.java | 13 +-- .../java/ch/njol/skript/lang/TriggerItem.java | 23 ++-- .../ch/njol/skript/lang/TriggerSection.java | 11 +- .../ch/njol/skript/lang/UnparsedLiteral.java | 13 +-- .../java/ch/njol/skript/lang/Variable.java | 83 ++++++-------- .../ch/njol/skript/lang/VariableString.java | 31 ++--- .../skript/lang/function/EffFunctionCall.java | 4 +- .../lang/function/ExprFunctionCall.java | 14 +-- .../njol/skript/lang/function/Function.java | 21 ++-- .../lang/function/FunctionReference.java | 46 +++----- .../njol/skript/lang/function/Functions.java | 52 +++------ .../skript/lang/function/JavaFunction.java | 38 +++--- .../njol/skript/lang/function/Namespace.java | 26 ++--- .../njol/skript/lang/function/Parameter.java | 18 ++- .../skript/lang/function/ScriptFunction.java | 23 ++-- .../njol/skript/lang/function/Signature.java | 17 +-- .../lang/function/SimpleJavaFunction.java | 13 +-- .../skript/lang/parser/ParserInstance.java | 34 ++---- .../skript/lang/util/ContainerExpression.java | 10 +- .../skript/lang/util/ContextlessEvent.java | 3 +- .../skript/lang/util/ConvertedExpression.java | 30 ++--- .../skript/lang/util/ConvertedLiteral.java | 8 +- .../ch/njol/skript/lang/util/SimpleEvent.java | 5 +- .../skript/lang/util/SimpleExpression.java | 40 +++---- .../njol/skript/lang/util/SimpleLiteral.java | 13 +-- 44 files changed, 343 insertions(+), 552 deletions(-) diff --git a/src/main/java/ch/njol/skript/classes/Changer.java b/src/main/java/ch/njol/skript/classes/Changer.java index d3b413531fe..a73f40b439a 100644 --- a/src/main/java/ch/njol/skript/classes/Changer.java +++ b/src/main/java/ch/njol/skript/classes/Changer.java @@ -29,14 +29,13 @@ * isn't overridden. *

* Some useful Changers can be found in {@link DefaultChangers} - * - * @author Peter Güttinger + * * @see DefaultChangers * @see Expression */ public interface Changer { - public static enum ChangeMode { + enum ChangeMode { ADD, SET, REMOVE, REMOVE_ALL, DELETE, RESET; } @@ -45,45 +44,44 @@ public static enum ChangeMode { *

* Unlike {@link Expression#acceptChange(ChangeMode)} this method must not print errors. * - * @param mode + * @param mode The {@link ChangeMode} to test. * @return An array of types that {@link #change(Object[], Object[], ChangeMode)} accepts as its delta parameter (which can be arrays to denote that multiple of * that type are accepted), or null if the given mode is not supported. For {@link ChangeMode#DELETE} and {@link ChangeMode#RESET} this can return any non-null array to * mark them as supported. */ - @Nullable - public abstract Class[] acceptChange(ChangeMode mode); + Class @Nullable [] acceptChange(ChangeMode mode); /** * @param what The objects to change * @param delta An array with one or more instances of one or more of the the classes returned by {@link #acceptChange(ChangeMode)} for the given change mode (null for * {@link ChangeMode#DELETE} and {@link ChangeMode#RESET}). This can be a Object[], thus casting is not allowed. - * @param mode + * @param mode The {@link ChangeMode} to test. * @throws UnsupportedOperationException (optional) if this method was called on an unsupported ChangeMode. */ - public abstract void change(T[] what, @Nullable Object[] delta, ChangeMode mode); + void change(T[] what, Object @Nullable [] delta, ChangeMode mode); - public static abstract class ChangerUtils { - - @SuppressWarnings("unchecked") - public static void change(final Changer changer, final Object[] what, final @Nullable Object[] delta, final ChangeMode mode) { + abstract class ChangerUtils { + + public static void change(Changer changer, Object[] what, Object @Nullable [] delta, ChangeMode mode) { + //noinspection unchecked changer.change((T[]) what, delta, mode); } /** * Tests whether an expression accepts changes of a certain type. If multiple types are given it test for whether any of the types is accepted. * - * @param e The expression to test + * @param expression The expression to test * @param mode The ChangeMode to use in the test * @param types The types to test for - * @return Whether e.{@link Expression#change(Event, Object[], ChangeMode) change}(event, type[], mode) can be used or not. + * @return Whether expression.{@link Expression#change(Event, Object[], ChangeMode) change}(event, type[], mode) can be used or not. */ - public static boolean acceptsChange(final Expression e, final ChangeMode mode, final Class... types) { - final Class[] cs = e.acceptChange(mode); - if (cs == null) + public static boolean acceptsChange(final Expression expression, final ChangeMode mode, final Class... types) { + final Class[] validTypes = expression.acceptChange(mode); + if (validTypes == null) return false; for (final Class type : types) { - for (final Class c : cs) { - if (c.isArray() ? c.getComponentType().isAssignableFrom(type) : c.isAssignableFrom(type)) + for (final Class validType : validTypes) { + if (validType.isArray() ? validType.getComponentType().isAssignableFrom(type) : validType.isAssignableFrom(type)) return true; } } diff --git a/src/main/java/ch/njol/skript/lang/Condition.java b/src/main/java/ch/njol/skript/lang/Condition.java index c4d67cc5fa4..3388f43bbc0 100644 --- a/src/main/java/ch/njol/skript/lang/Condition.java +++ b/src/main/java/ch/njol/skript/lang/Condition.java @@ -22,7 +22,7 @@ import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.util.Checker; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import java.util.Iterator; @@ -67,12 +67,11 @@ public final boolean isNegated() { return negated; } - @Nullable - @SuppressWarnings({"rawtypes", "unchecked"}) - public static Condition parse(String input, @Nullable String defaultError) { + public static @Nullable Condition parse(String input, @Nullable String defaultError) { input = input.trim(); while (input.startsWith("(") && SkriptParser.next(input, 0, ParseContext.DEFAULT) == input.length()) input = input.substring(1, input.length() - 1); + //noinspection unchecked,rawtypes return (Condition) SkriptParser.parse(input, (Iterator) Skript.getConditions().iterator(), defaultError); } diff --git a/src/main/java/ch/njol/skript/lang/Debuggable.java b/src/main/java/ch/njol/skript/lang/Debuggable.java index 3de15921825..98714194d32 100644 --- a/src/main/java/ch/njol/skript/lang/Debuggable.java +++ b/src/main/java/ch/njol/skript/lang/Debuggable.java @@ -19,7 +19,7 @@ package ch.njol.skript.lang; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; /** * Represents an element that can print details involving an event. diff --git a/src/main/java/ch/njol/skript/lang/Effect.java b/src/main/java/ch/njol/skript/lang/Effect.java index 0b734ad4372..e8d2338313a 100644 --- a/src/main/java/ch/njol/skript/lang/Effect.java +++ b/src/main/java/ch/njol/skript/lang/Effect.java @@ -23,7 +23,7 @@ import ch.njol.skript.log.ParseLogHandler; import ch.njol.skript.log.SkriptLogger; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import java.util.Iterator; @@ -50,11 +50,8 @@ public final boolean run(Event event) { return true; } - @Nullable - @SuppressWarnings({"rawtypes", "unchecked"}) - public static Effect parse(String input, @Nullable String defaultError) { - ParseLogHandler log = SkriptLogger.startParseLogHandler(); - try { + public static @Nullable Effect parse(String input, @Nullable String defaultError) { + try (ParseLogHandler log = SkriptLogger.startParseLogHandler()) { EffFunctionCall functionCall = EffFunctionCall.parse(input); if (functionCall != null) { log.printLog(); @@ -72,6 +69,7 @@ public static Effect parse(String input, @Nullable String defaultError) { } log.clear(); + //noinspection unchecked,rawtypes Effect effect = (Effect) SkriptParser.parse(input, (Iterator) Skript.getEffects().iterator(), defaultError); if (effect != null) { log.printLog(); @@ -80,8 +78,6 @@ public static Effect parse(String input, @Nullable String defaultError) { log.printError(); return null; - } finally { - log.stop(); } } diff --git a/src/main/java/ch/njol/skript/lang/EffectSection.java b/src/main/java/ch/njol/skript/lang/EffectSection.java index 4da3a5a5bc5..070812277c6 100644 --- a/src/main/java/ch/njol/skript/lang/EffectSection.java +++ b/src/main/java/ch/njol/skript/lang/EffectSection.java @@ -23,7 +23,7 @@ import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.parser.ParserInstance; import ch.njol.util.Kleenean; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import java.util.Iterator; import java.util.List; @@ -69,11 +69,10 @@ public abstract boolean init(Expression[] expressions, /** * Similar to {@link Section#parse(String, String, SectionNode, List)}, but will only attempt to parse from other {@link EffectSection}s. */ - @Nullable - @SuppressWarnings({"unchecked", "rawtypes"}) - public static EffectSection parse(String input, @Nullable String defaultError, @Nullable SectionNode sectionNode, @Nullable List triggerItems) { + public static @Nullable EffectSection parse(String input, @Nullable String defaultError, @Nullable SectionNode sectionNode, @Nullable List triggerItems) { SectionContext sectionContext = ParserInstance.get().getData(SectionContext.class); + //noinspection unchecked,rawtypes return sectionContext.modify(sectionNode, triggerItems, () -> (EffectSection) SkriptParser.parse( input, diff --git a/src/main/java/ch/njol/skript/lang/EffectSectionEffect.java b/src/main/java/ch/njol/skript/lang/EffectSectionEffect.java index 2b93bef0b60..3cc1916e700 100644 --- a/src/main/java/ch/njol/skript/lang/EffectSectionEffect.java +++ b/src/main/java/ch/njol/skript/lang/EffectSectionEffect.java @@ -21,7 +21,7 @@ import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; /** * Represents the Effect aspect of an EffectSection. This allows for the use of EffectSections as effects, rather than just sections. diff --git a/src/main/java/ch/njol/skript/lang/Expression.java b/src/main/java/ch/njol/skript/lang/Expression.java index 9c7439f7585..4be74231f5e 100644 --- a/src/main/java/ch/njol/skript/lang/Expression.java +++ b/src/main/java/ch/njol/skript/lang/Expression.java @@ -31,8 +31,7 @@ import ch.njol.util.Checker; import org.bukkit.event.Event; import org.bukkit.inventory.ItemStack; -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import org.skriptlang.skript.lang.converter.Converter; import java.util.HashMap; @@ -64,8 +63,7 @@ public interface Expression extends SyntaxElement, Debuggable { * @return The value or null if this expression doesn't have any value for the event * @throws UnsupportedOperationException (optional) if this was called on a non-single expression */ - @Nullable - T getSingle(Event event); + @Nullable T getSingle(Event event); /** * Get an optional of the single value of this expression. @@ -107,7 +105,7 @@ default Optional getOptionalSingle(Event event) { * @param event The event * @return A non-null stream of this expression's non-null values */ - default Stream<@NonNull ? extends T> stream(Event event) { + default Stream stream(Event event) { Iterator iterator = iterator(event); if (iterator == null) { return Stream.empty(); @@ -178,9 +176,8 @@ default boolean canBeSingle() { * @see Converter * @see ConvertedExpression */ - @Nullable @SuppressWarnings("unchecked") - Expression getConvertedExpression(Class... to); + @Nullable Expression getConvertedExpression(Class... to); /** * Gets the return type of this expression. @@ -265,8 +262,7 @@ default boolean canReturn(Class returnType) { * @param event The event to be used for evaluation * @return An iterator to iterate over all values of this expression which may be empty and/or null, but must not return null elements. */ - @Nullable - Iterator iterator(Event event); + @Nullable Iterator iterator(Event event); /** * Checks whether the given 'loop-...' expression should match this loop, e.g. loop-block matches any loops that loop through blocks and loop-argument matches an @@ -316,8 +312,7 @@ default boolean canReturn(Class returnType) { * that type are accepted), or null if the given mode is not supported. For {@link ChangeMode#DELETE} and {@link ChangeMode#RESET} this can return any non-null array to * mark them as supported. */ - @Nullable - Class[] acceptChange(ChangeMode mode); + Class @Nullable [] acceptChange(ChangeMode mode); /** * Tests all accepted change modes, and if so what type it expects the delta to be. @@ -343,7 +338,7 @@ default Map[]> getAcceptedChangeModes() { * @param mode The {@link ChangeMode} of the attempted change * @throws UnsupportedOperationException (optional) - If this method was called on an unsupported ChangeMode. */ - void change(Event event, @Nullable Object[] delta, ChangeMode mode); + void change(Event event, Object @Nullable [] delta, ChangeMode mode); /** * This method is called before this expression is set to another one. @@ -356,8 +351,7 @@ default Map[]> getAcceptedChangeModes() { * @param delta Initial delta array. * @return Delta array to use for change. */ - @Nullable - default Object[] beforeChange(Expression changed, @Nullable Object[] delta) { + default Object @Nullable [] beforeChange(Expression changed, Object @Nullable [] delta) { if (delta == null || delta.length == 0) // Nothing to nothing return null; diff --git a/src/main/java/ch/njol/skript/lang/ExpressionInfo.java b/src/main/java/ch/njol/skript/lang/ExpressionInfo.java index 0c2c0c2bc62..2d4f1ec83c0 100644 --- a/src/main/java/ch/njol/skript/lang/ExpressionInfo.java +++ b/src/main/java/ch/njol/skript/lang/ExpressionInfo.java @@ -18,15 +18,14 @@ */ package ch.njol.skript.lang; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; /** * Represents an expression's information, for use when creating new instances of expressions. */ public class ExpressionInfo, T> extends SyntaxElementInfo { - @Nullable - public ExpressionType expressionType; + public @Nullable ExpressionType expressionType; public Class returnType; public ExpressionInfo(String[] patterns, Class returnType, Class expressionClass, String originClassPath) throws IllegalArgumentException { @@ -51,8 +50,7 @@ public Class getReturnType() { * Get the type of this expression. * @return The type of this Expression */ - @Nullable - public ExpressionType getExpressionType() { + public @Nullable ExpressionType getExpressionType() { return expressionType; } diff --git a/src/main/java/ch/njol/skript/lang/ExpressionList.java b/src/main/java/ch/njol/skript/lang/ExpressionList.java index fa6612b3422..9c89358431d 100644 --- a/src/main/java/ch/njol/skript/lang/ExpressionList.java +++ b/src/main/java/ch/njol/skript/lang/ExpressionList.java @@ -27,7 +27,7 @@ import ch.njol.util.Kleenean; import ch.njol.util.coll.CollectionUtils; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import java.lang.reflect.Array; import java.util.ArrayList; @@ -47,8 +47,7 @@ public class ExpressionList implements Expression { protected boolean and; private final boolean single; - @Nullable - private final ExpressionList source; + private final @Nullable ExpressionList source; public ExpressionList(Expression[] expressions, Class returnType, boolean and) { this(expressions, returnType, and, null); @@ -89,8 +88,7 @@ public boolean init(Expression[] expressions, int matchedPattern, Kleenean is } @Override - @Nullable - public T getSingle(Event event) { + public @Nullable T getSingle(Event event) { if (!single) throw new UnsupportedOperationException(); Expression expression = CollectionUtils.getRandom(expressions); @@ -98,31 +96,30 @@ public T getSingle(Event event) { } @Override - @SuppressWarnings("unchecked") public T[] getArray(Event event) { if (and) return getAll(event); Expression expression = CollectionUtils.getRandom(expressions); + //noinspection unchecked return expression != null ? expression.getArray(event) : (T[]) Array.newInstance(returnType, 0); } @Override - @SuppressWarnings("unchecked") public T[] getAll(Event event) { List values = new ArrayList<>(); for (Expression expr : expressions) values.addAll(Arrays.asList(expr.getAll(event))); + //noinspection unchecked return values.toArray((T[]) Array.newInstance(returnType, values.size())); } @Override - @Nullable - public Iterator iterator(Event event) { + public @Nullable Iterator iterator(Event event) { if (!and) { Expression expression = CollectionUtils.getRandom(expressions); return expression != null ? expression.iterator(event) : null; } - return new Iterator() { + return new Iterator<>() { private int i = 0; @Nullable private Iterator current = null; @@ -178,9 +175,8 @@ public boolean check(Event event, Checker checker) { } @Override - @Nullable @SuppressWarnings("unchecked") - public Expression getConvertedExpression(Class... to) { + public @Nullable Expression getConvertedExpression(Class... to) { Expression[] exprs = new Expression[expressions.length]; Class[] returnTypes = new Class[expressions.length]; for (int i = 0; i < exprs.length; i++) { @@ -215,8 +211,7 @@ public void invertAnd() { } @Override - @Nullable - public Class[] acceptChange(ChangeMode mode) { + public Class @Nullable [] acceptChange(ChangeMode mode) { Class[] exprClasses = expressions[0].acceptChange(mode); if (exprClasses == null) return null; @@ -234,7 +229,7 @@ public Class[] acceptChange(ChangeMode mode) { } @Override - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) throws UnsupportedOperationException { + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) throws UnsupportedOperationException { for (Expression expr : expressions) { expr.change(event, delta, mode); } diff --git a/src/main/java/ch/njol/skript/lang/InputSource.java b/src/main/java/ch/njol/skript/lang/InputSource.java index df541a0e40f..f996557bcdc 100644 --- a/src/main/java/ch/njol/skript/lang/InputSource.java +++ b/src/main/java/ch/njol/skript/lang/InputSource.java @@ -69,8 +69,7 @@ default boolean hasIndices() { */ class InputData extends ParserInstance.Data { - @Nullable - private InputSource source; + private @Nullable InputSource source; public InputData(ParserInstance parserInstance) { super(parserInstance); @@ -92,8 +91,7 @@ public void setSource(@Nullable InputSource source) { * * @return the source of information. */ - @Nullable - public InputSource getSource() { + public @Nullable InputSource getSource() { return source; } diff --git a/src/main/java/ch/njol/skript/lang/Literal.java b/src/main/java/ch/njol/skript/lang/Literal.java index 890b41b2e12..c3fe27cf0aa 100644 --- a/src/main/java/ch/njol/skript/lang/Literal.java +++ b/src/main/java/ch/njol/skript/lang/Literal.java @@ -18,7 +18,7 @@ */ package ch.njol.skript.lang; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; /** * A literal, e.g. a number, string or item. Literals are constants which do not depend on the event and can thus e.g. be used in events. @@ -32,9 +32,8 @@ public interface Literal extends Expression { T getSingle(); @Override - @Nullable @SuppressWarnings("unchecked") - Literal getConvertedExpression(Class... to); + @Nullable Literal getConvertedExpression(Class... to); T[] getAll(); diff --git a/src/main/java/ch/njol/skript/lang/LiteralList.java b/src/main/java/ch/njol/skript/lang/LiteralList.java index f432bd1c095..df2d8d51966 100644 --- a/src/main/java/ch/njol/skript/lang/LiteralList.java +++ b/src/main/java/ch/njol/skript/lang/LiteralList.java @@ -18,9 +18,9 @@ */ package ch.njol.skript.lang; -import ch.njol.skript.registrations.Classes; import ch.njol.skript.lang.util.SimpleLiteral; -import org.eclipse.jdt.annotation.Nullable; +import ch.njol.skript.registrations.Classes; +import org.jetbrains.annotations.Nullable; import java.lang.reflect.Array; @@ -63,8 +63,8 @@ public T[] getAll() { } @Override - @Nullable - public Literal getConvertedExpression(final Class... to) { + @SuppressWarnings("unchecked") + public @Nullable Literal getConvertedExpression(final Class... to) { Literal[] exprs = new Literal[expressions.length]; Class[] returnTypes = new Class[expressions.length]; for (int i = 0; i < exprs.length; i++) { diff --git a/src/main/java/ch/njol/skript/lang/ReturnableTrigger.java b/src/main/java/ch/njol/skript/lang/ReturnableTrigger.java index 4b8b601d990..08b6cea873e 100644 --- a/src/main/java/ch/njol/skript/lang/ReturnableTrigger.java +++ b/src/main/java/ch/njol/skript/lang/ReturnableTrigger.java @@ -19,7 +19,7 @@ package ch.njol.skript.lang; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import org.skriptlang.skript.lang.script.Script; import java.util.Collections; diff --git a/src/main/java/ch/njol/skript/lang/Section.java b/src/main/java/ch/njol/skript/lang/Section.java index 5a665165eff..6c4445c2634 100644 --- a/src/main/java/ch/njol/skript/lang/Section.java +++ b/src/main/java/ch/njol/skript/lang/Section.java @@ -25,7 +25,7 @@ import ch.njol.skript.lang.parser.ParserInstance; import ch.njol.util.Kleenean; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Iterator; @@ -172,9 +172,9 @@ protected void loadOptionalCode(SectionNode sectionNode) { } @Nullable - @SuppressWarnings({"unchecked", "rawtypes"}) public static Section parse(String expr, @Nullable String defaultError, SectionNode sectionNode, List triggerItems) { SectionContext sectionContext = ParserInstance.get().getData(SectionContext.class); + //noinspection unchecked,rawtypes return sectionContext.modify(sectionNode, triggerItems, () -> (Section) SkriptParser.parse(expr, (Iterator) Skript.getSections().iterator(), defaultError)); } diff --git a/src/main/java/ch/njol/skript/lang/SectionSkriptEvent.java b/src/main/java/ch/njol/skript/lang/SectionSkriptEvent.java index d6f56f294b6..05d8490aae7 100644 --- a/src/main/java/ch/njol/skript/lang/SectionSkriptEvent.java +++ b/src/main/java/ch/njol/skript/lang/SectionSkriptEvent.java @@ -22,7 +22,7 @@ import ch.njol.skript.config.SectionNode; import ch.njol.skript.lang.SkriptParser.ParseResult; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; /** * To be used in sections that delay the execution of their code through a {@link Trigger}. diff --git a/src/main/java/ch/njol/skript/lang/SkriptEvent.java b/src/main/java/ch/njol/skript/lang/SkriptEvent.java index 145115a4460..e7a72c00db0 100644 --- a/src/main/java/ch/njol/skript/lang/SkriptEvent.java +++ b/src/main/java/ch/njol/skript/lang/SkriptEvent.java @@ -30,7 +30,7 @@ import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.EventPriority; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import org.skriptlang.skript.lang.entry.EntryContainer; import org.skriptlang.skript.lang.script.Script; import org.skriptlang.skript.lang.structure.Structure; @@ -55,10 +55,8 @@ public abstract class SkriptEvent extends Structure { private String expr; private SectionNode source; - @Nullable - protected EventPriority eventPriority; - @Nullable - protected ListeningBehavior listeningBehavior; + protected @Nullable EventPriority eventPriority; + protected @Nullable ListeningBehavior listeningBehavior; protected boolean supportsListeningBehavior; private SkriptEventInfo skriptEventInfo; @@ -132,7 +130,6 @@ public boolean load() { if (!shouldLoadEvent()) return false; - // noinspection ConstantConditions - entry container cannot be null as this structure is not simple if (Skript.debug() || source.debug()) Skript.debug(expr + " (" + this + "):"); diff --git a/src/main/java/ch/njol/skript/lang/SkriptEventInfo.java b/src/main/java/ch/njol/skript/lang/SkriptEventInfo.java index b645f7675b1..5bcc8384c1e 100644 --- a/src/main/java/ch/njol/skript/lang/SkriptEventInfo.java +++ b/src/main/java/ch/njol/skript/lang/SkriptEventInfo.java @@ -20,11 +20,11 @@ import ch.njol.skript.SkriptAPIException; import ch.njol.skript.SkriptConfig; +import ch.njol.skript.lang.SkriptEvent.ListeningBehavior; import org.bukkit.event.Event; import org.bukkit.event.player.PlayerInteractAtEntityEvent; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import org.skriptlang.skript.lang.structure.StructureInfo; -import ch.njol.skript.lang.SkriptEvent.ListeningBehavior; import java.util.Locale; @@ -34,12 +34,8 @@ public final class SkriptEventInfo extends StructureInfo< public final String name; private ListeningBehavior listeningBehavior; - - @Nullable - private String[] description, examples, keywords, requiredPlugins; - - @Nullable - private String since, documentationID; + private String @Nullable [] description, examples, keywords, requiredPlugins; + private @Nullable String since, documentationID; private final String id; @@ -180,33 +176,28 @@ public ListeningBehavior getListeningBehavior() { return listeningBehavior; } - @Nullable - public String[] getDescription() { + public String @Nullable[] getDescription() { return description; } - @Nullable - public String[] getExamples() { + public String @Nullable[] getExamples() { return examples; } - @Nullable - public String[] getKeywords() { + public String @Nullable[] getKeywords() { return keywords; } - @Nullable - public String getSince() { + public @Nullable String getSince() { return since; } - @Nullable - public String[] getRequiredPlugins() { + public String @Nullable[] getRequiredPlugins() { return requiredPlugins; } - @Nullable - public String getDocumentationID() { + public @Nullable String getDocumentationID() { return documentationID; } + } diff --git a/src/main/java/ch/njol/skript/lang/SkriptParser.java b/src/main/java/ch/njol/skript/lang/SkriptParser.java index 4adcf7d2c5a..8535879c253 100644 --- a/src/main/java/ch/njol/skript/lang/SkriptParser.java +++ b/src/main/java/ch/njol/skript/lang/SkriptParser.java @@ -50,8 +50,8 @@ import ch.njol.util.coll.CollectionUtils; import com.google.common.primitives.Booleans; import org.bukkit.plugin.java.JavaPlugin; -import org.eclipse.jdt.annotation.Nullable; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.skriptlang.skript.lang.script.Script; import org.skriptlang.skript.lang.script.ScriptWarning; @@ -121,8 +121,7 @@ public SkriptParser(SkriptParser other, String expr) { public static final String WILDCARD = "[^\"]*?(?:\"[^\"]*?\"[^\"]*?)*?"; public static class ParseResult { - @Nullable - public SkriptPattern source; + public @Nullable SkriptPattern source; public Expression[] exprs; public List regexes = new ArrayList<>(1); public String expr; @@ -153,12 +152,11 @@ public boolean hasTag(String tag) { *

* Prints errors. */ - @Nullable - @SuppressWarnings("unchecked") - public static Literal parseLiteral(String expr, Class expectedClass, ParseContext context) { + public static @Nullable Literal parseLiteral(String expr, Class expectedClass, ParseContext context) { expr = "" + expr.trim(); if (expr.isEmpty()) return null; + //noinspection ReassignedVariable,unchecked return new UnparsedLiteral(expr).getConvertedExpression(context, expectedClass); } @@ -167,15 +165,13 @@ public static Literal parseLiteral(String expr, Class expect *

* Can print an error. */ - @Nullable - public static T parse(String expr, Iterator> source, @Nullable String defaultError) { + public static @Nullable T parse(String expr, Iterator> source, @Nullable String defaultError) { expr = "" + expr.trim(); if (expr.isEmpty()) { Skript.error(defaultError); return null; } - ParseLogHandler log = SkriptLogger.startParseLogHandler(); - try { + try (ParseLogHandler log = SkriptLogger.startParseLogHandler()) { T element = new SkriptParser(expr).parse(source); if (element != null) { log.printLog(); @@ -183,27 +179,22 @@ public static T parse(String expr, Iterator T parseStatic(String expr, Iterator> source, @Nullable String defaultError) { + public static @Nullable T parseStatic(String expr, Iterator> source, @Nullable String defaultError) { return parseStatic(expr, source, ParseContext.DEFAULT, defaultError); } - @Nullable - public static T parseStatic(String expr, Iterator> source, ParseContext parseContext, @Nullable String defaultError) { + public static @Nullable T parseStatic(String expr, Iterator> source, ParseContext parseContext, @Nullable String defaultError) { expr = expr.trim(); if (expr.isEmpty()) { Skript.error(defaultError); return null; } - ParseLogHandler log = SkriptLogger.startParseLogHandler(); T element; - try { + try (ParseLogHandler log = SkriptLogger.startParseLogHandler()) { element = new SkriptParser(expr, PARSE_LITERALS, parseContext).parse(source); if (element != null) { log.printLog(); @@ -211,15 +202,11 @@ public static T parseStatic(String expr, Iterator T parse(Iterator> source) { - ParseLogHandler log = SkriptLogger.startParseLogHandler(); - try { + private @Nullable T parse(Iterator> source) { + try (ParseLogHandler log = SkriptLogger.startParseLogHandler()) { while (source.hasNext()) { SyntaxElementInfo info = source.next(); patternsLoop: for (int patternIndex = 0; patternIndex < info.patterns.length; patternIndex++) { @@ -268,12 +255,10 @@ private T parse(Iterator @NotNull DefaultExpression getDefaultExpression(ExprInfo exprInfo, String pattern) { + private static @NotNull DefaultExpression getDefaultExpression(ExprInfo exprInfo, String pattern) { DefaultExpression expr = exprInfo.classes[0].getDefaultExpression(); if (expr == null) throw new SkriptAPIException("The class '" + exprInfo.classes[0].getCodeName() + "' does not provide a default expression. Either allow null (with %-" + exprInfo.classes[0].getCodeName() + "%) or make it mandatory [pattern: " + pattern + "]"); @@ -293,8 +278,7 @@ private T parse(Iterator Variable parseVariable(String expr, Class[] returnTypes) { + private static @Nullable Variable parseVariable(String expr, Class[] returnTypes) { if (VARIABLE_PATTERN.matcher(expr).matches()) { String variableName = "" + expr.substring(expr.indexOf('{') + 1, expr.lastIndexOf('}')); boolean inExpression = false; @@ -317,19 +301,18 @@ private static Variable parseVariable(String expr, Class[] r return null; } - @Nullable - private static Expression parseExpression(Class[] types, String expr) {; + private static @Nullable Expression parseExpression(Class[] types, String expr) {; if (expr.startsWith("\"") && expr.length() != 1 && nextQuote(expr, 1) == expr.length() - 1) { return VariableString.newInstance("" + expr.substring(1, expr.length() - 1)); } else { + //noinspection unchecked,rawtypes return (Expression) parse(expr, (Iterator) Skript.getExpressions(types), null); } } - @Nullable - @SuppressWarnings({"unchecked", "rawtypes"}) - private Expression parseSingleExpr(boolean allowUnparsedLiteral, @Nullable LogEntry error, Class... types) { + @SuppressWarnings({"unchecked"}) + private @Nullable Expression parseSingleExpr(boolean allowUnparsedLiteral, @Nullable LogEntry error, Class... types) { assert types.length > 0; assert types.length == 1 || !CollectionUtils.contains(types, Object.class); if (expr.isEmpty()) @@ -339,8 +322,7 @@ private Expression parseSingleExpr(boolean allowUnparsedLiteral expr.startsWith("(") && expr.endsWith(")") && next(expr, 0, context) == expr.length()) return new SkriptParser(this, "" + expr.substring(1, expr.length() - 1)).parseSingleExpr(allowUnparsedLiteral, error, types); - ParseLogHandler log = SkriptLogger.startParseLogHandler(); - try { + try (ParseLogHandler log = SkriptLogger.startParseLogHandler()) { if (context == ParseContext.DEFAULT || context == ParseContext.EVENT) { Variable parsedVariable = parseVariable(expr, types); if (parsedVariable != null) { @@ -358,6 +340,7 @@ private Expression parseSingleExpr(boolean allowUnparsedLiteral FunctionReference functionReference = parseFunction(types); if (functionReference != null) { log.printLog(); + //noinspection rawtypes return new ExprFunctionCall(functionReference); } else if (log.hasError()) { log.printError(); @@ -414,13 +397,10 @@ private Expression parseSingleExpr(boolean allowUnparsedLiteral } log.printError(); return null; - } finally { - log.stop(); } } - @Nullable - private Expression parseSingleExpr(boolean allowUnparsedLiteral, @Nullable LogEntry error, ExprInfo exprInfo) { + private @Nullable Expression parseSingleExpr(boolean allowUnparsedLiteral, @Nullable LogEntry error, ExprInfo exprInfo) { if (expr.isEmpty()) // Empty expressions return nothing, obviously return null; @@ -430,8 +410,7 @@ private Expression parseSingleExpr(boolean allowUnparsedLiteral, @Nullable Lo expr.startsWith("(") && expr.endsWith(")") && next(expr, 0, context) == expr.length()) return new SkriptParser(this, "" + expr.substring(1, expr.length() - 1)).parseSingleExpr(allowUnparsedLiteral, error, exprInfo); - ParseLogHandler log = SkriptLogger.startParseLogHandler(); - try { + try (ParseLogHandler log = SkriptLogger.startParseLogHandler()) { // Construct types array which contains all potential classes Class[] types = new Class[exprInfo.classes.length]; // This may contain nulls! boolean hasSingular = false; @@ -614,8 +593,6 @@ private Expression parseSingleExpr(boolean allowUnparsedLiteral, @Nullable Lo } log.printError(); return null; - } finally { - log.stop(); } } @@ -637,13 +614,12 @@ private SkriptParser suppressMissingAndOrWarnings() { return this; } - @Nullable @SuppressWarnings("unchecked") - public Expression parseExpression(Class... types) { + public @Nullable Expression parseExpression(Class... types) { if (expr.length() == 0) return null; - assert types != null && types.length > 0; + assert types.length > 0; assert types.length == 1 || !CollectionUtils.contains(types, Object.class); ParseLogHandler log = SkriptLogger.startParseLogHandler(); @@ -661,8 +637,7 @@ public Expression parseExpression(Class... types) } } - @Nullable - private Expression parseExpressionList(ParseLogHandler log, Class... types) { + private @Nullable Expression parseExpressionList(ParseLogHandler log, Class... types) { boolean isObject = types.length == 1 && types[0] == Object.class; List> parsedExpressions = new ArrayList<>(); Kleenean and = Kleenean.UNKNOWN; @@ -769,14 +744,12 @@ private Expression parseExpressionList(ParseLogHandler log, Cla } } - @Nullable - public Expression parseExpression(ExprInfo exprInfo) { + public @Nullable Expression parseExpression(ExprInfo exprInfo) { if (expr.length() == 0) return null; boolean isObject = exprInfo.classes.length == 1 && exprInfo.classes[0].getC() == Object.class; - ParseLogHandler log = SkriptLogger.startParseLogHandler(); - try { + try (ParseLogHandler log = SkriptLogger.startParseLogHandler()) { // Attempt to parse a single expression Expression parsedExpression = parseSingleExpr(true, null, exprInfo); if (parsedExpression != null) { @@ -900,8 +873,6 @@ public Expression parseExpression(ExprInfo exprInfo) { return new ExpressionList(expressions, Classes.getSuperClassInfo(exprReturnTypes).getC(), exprReturnTypes, !and.isFalse()); } - } finally { - log.stop(); } } @@ -911,14 +882,13 @@ public Expression parseExpression(ExprInfo exprInfo) { * @param types The required return type or null if it is not used (e.g. when calling a void function) * @return The parsed function, or null if the given expression is not a function call or is an invalid function call (check for an error to differentiate these two) */ - @Nullable + @SuppressWarnings("unchecked") - public FunctionReference parseFunction(@Nullable Class... types) { + public @Nullable FunctionReference parseFunction(@Nullable Class... types) { if (context != ParseContext.DEFAULT && context != ParseContext.EVENT) return null; - ParseLogHandler log = SkriptLogger.startParseLogHandler(); AtomicBoolean unaryArgument = new AtomicBoolean(false); - try { + try (ParseLogHandler log = SkriptLogger.startParseLogHandler()) { Matcher matcher = FUNCTION_CALL_PATTERN.matcher(expr); if (!matcher.matches()) { log.printLog(); @@ -973,8 +943,6 @@ public FunctionReference parseFunction(@Nullable Class... ty } log.printLog(); return functionReference; - } finally { - log.stop(); } } @@ -1026,8 +994,7 @@ public static boolean parseArguments(String args, ScriptCommand command, ScriptC *

* Prints parse errors (i.e. must start a ParseLog before calling this method) */ - @Nullable - public static ParseResult parse(String text, String pattern) { + public static @Nullable ParseResult parse(String text, String pattern) { return new SkriptParser(text, PARSE_LITERALS, ParseContext.COMMAND).parse_i(pattern); } @@ -1036,8 +1003,7 @@ public static ParseResult parse(String text, String pattern) { *

* Prints parse errors (i.e. must start a ParseLog before calling this method) */ - @Nullable - public static ParseResult parse(String text, String pattern, int parseFlags, ParseContext parseContext) { + public static @Nullable ParseResult parse(String text, String pattern, int parseFlags, ParseContext parseContext) { return new SkriptParser(text, parseFlags, parseContext).parse_i(pattern); } @@ -1046,8 +1012,7 @@ public static ParseResult parse(String text, String pattern, int parseFlags, Par *

* Prints parse errors (i.e. must start a ParseLog before calling this method) */ - @Nullable - public static ParseResult parse(String text, SkriptPattern pattern, int parseFlags, ParseContext parseContext) { + public static @Nullable ParseResult parse(String text, SkriptPattern pattern, int parseFlags, ParseContext parseContext) { return parse(text, pattern.toString(), parseFlags, parseContext); } @@ -1317,8 +1282,7 @@ public static int nextOccurrence(String haystack, String needle, int startIndex, private static final Map patterns = new ConcurrentHashMap<>(); - @Nullable - private ParseResult parse_i(String pattern) { + private @Nullable ParseResult parse_i(String pattern) { SkriptPattern skriptPattern = patterns.computeIfAbsent(pattern, PatternCompiler::compile); ch.njol.skript.patterns.MatchResult matchResult = skriptPattern.match(expr, flags, context); if (matchResult == null) @@ -1332,8 +1296,7 @@ private ParseResult parse_i(String pattern) { * @param pattern The pattern string to validate * @return The pattern with %codenames% and a boolean array that contains whether the expressions are plural or not */ - @Nullable - public static NonNullPair, Boolean>[]> validatePattern(String pattern) { + public static @Nullable NonNullPair, Boolean>[]> validatePattern(String pattern) { List, Boolean>> pairs = new ArrayList<>(); int groupLevel = 0, optionalLevel = 0; Deque groups = new LinkedList<>(); @@ -1400,8 +1363,7 @@ public static NonNullPair, Boolean>[]> validate return new NonNullPair<>(stringBuilder.toString(), pairs.toArray(new NonNullPair[0])); } - @Nullable - private static NonNullPair, Boolean>[]> error(final String error) { + private static @Nullable NonNullPair, Boolean>[]> error(final String error) { Skript.error("Invalid pattern: " + error); return null; } diff --git a/src/main/java/ch/njol/skript/lang/Statement.java b/src/main/java/ch/njol/skript/lang/Statement.java index 2f4f783541c..b19689f1bc2 100644 --- a/src/main/java/ch/njol/skript/lang/Statement.java +++ b/src/main/java/ch/njol/skript/lang/Statement.java @@ -40,11 +40,8 @@ public abstract class Statement extends TriggerItem implements SyntaxElement { return parse(input, null, defaultError); } - @Nullable - @SuppressWarnings({"rawtypes", "unchecked"}) - public static Statement parse(String input, @Nullable List items, String defaultError) { - ParseLogHandler log = SkriptLogger.startParseLogHandler(); - try { + public static @Nullable Statement parse(String input, @Nullable List items, String defaultError) { + try (ParseLogHandler log = SkriptLogger.startParseLogHandler()) { EffFunctionCall functionCall = EffFunctionCall.parse(input); if (functionCall != null) { log.printLog(); @@ -62,6 +59,7 @@ public static Statement parse(String input, @Nullable List items, S } log.clear(); + //noinspection unchecked,rawtypes Statement statement = (Statement) SkriptParser.parse(input, (Iterator) Skript.getStatements().iterator(), defaultError); if (statement != null) { log.printLog(); @@ -70,8 +68,6 @@ public static Statement parse(String input, @Nullable List items, S log.printError(); return null; - } finally { - log.stop(); } } diff --git a/src/main/java/ch/njol/skript/lang/Trigger.java b/src/main/java/ch/njol/skript/lang/Trigger.java index b9092703247..d6e18a1f5ee 100644 --- a/src/main/java/ch/njol/skript/lang/Trigger.java +++ b/src/main/java/ch/njol/skript/lang/Trigger.java @@ -18,10 +18,10 @@ */ package ch.njol.skript.lang; -import org.skriptlang.skript.lang.script.Script; import ch.njol.skript.variables.Variables; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; +import org.skriptlang.skript.lang.script.Script; import java.util.List; @@ -30,8 +30,7 @@ public class Trigger extends TriggerSection { private final String name; private final SkriptEvent event; - @Nullable - private final Script script; + private final @Nullable Script script; private int line = -1; // -1 is default: it means there is no line number available private String debugLabel; @@ -70,8 +69,7 @@ public boolean execute(Event event) { } @Override - @Nullable - protected TriggerItem walk(Event event) { + protected @Nullable TriggerItem walk(Event event) { return walk(event, true); } @@ -94,8 +92,7 @@ public SkriptEvent getEvent() { /** * @return The script this trigger was created from. */ - @Nullable - public Script getScript() { + public @Nullable Script getScript() { return script; } diff --git a/src/main/java/ch/njol/skript/lang/TriggerItem.java b/src/main/java/ch/njol/skript/lang/TriggerItem.java index ce4965c64f4..eb192be11f4 100644 --- a/src/main/java/ch/njol/skript/lang/TriggerItem.java +++ b/src/main/java/ch/njol/skript/lang/TriggerItem.java @@ -22,7 +22,7 @@ import ch.njol.skript.util.SkriptColor; import ch.njol.util.StringUtils; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import org.skriptlang.skript.lang.script.Script; import java.io.File; @@ -37,10 +37,8 @@ */ public abstract class TriggerItem implements Debuggable { - @Nullable - protected TriggerSection parent = null; - @Nullable - private TriggerItem next = null; + protected @Nullable TriggerSection parent = null; + private @Nullable TriggerItem next = null; protected TriggerItem() {} @@ -56,8 +54,7 @@ protected TriggerItem(TriggerSection parent) { * @param event The event * @return The next item to run or null to stop execution */ - @Nullable - protected TriggerItem walk(Event event) { + protected @Nullable TriggerItem walk(Event event) { if (run(event)) { debug(event, true); return next; @@ -118,8 +115,7 @@ public static boolean walk(TriggerItem start, Event event) { */ private final static String INDENT = " "; - @Nullable - private String indentation = null; + private @Nullable String indentation = null; public String getIndentation() { if (indentation == null) { @@ -148,16 +144,14 @@ public TriggerItem setParent(@Nullable TriggerSection parent) { return this; } - @Nullable - public final TriggerSection getParent() { + public final @Nullable TriggerSection getParent() { return parent; } /** * @return The trigger this item belongs to, or null if this is a stand-alone item (e.g. the effect of an effect command) */ - @Nullable - public final Trigger getTrigger() { + public final @Nullable Trigger getTrigger() { TriggerItem triggerItem = this; while (triggerItem != null && !(triggerItem instanceof Trigger)) triggerItem = triggerItem.getParent(); @@ -169,8 +163,7 @@ public TriggerItem setNext(@Nullable TriggerItem next) { return this; } - @Nullable - public TriggerItem getNext() { + public @Nullable TriggerItem getNext() { return next; } diff --git a/src/main/java/ch/njol/skript/lang/TriggerSection.java b/src/main/java/ch/njol/skript/lang/TriggerSection.java index e7945784752..c861805525a 100644 --- a/src/main/java/ch/njol/skript/lang/TriggerSection.java +++ b/src/main/java/ch/njol/skript/lang/TriggerSection.java @@ -22,7 +22,7 @@ import ch.njol.skript.config.SectionNode; import ch.njol.skript.lang.parser.ParserInstance; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -32,8 +32,7 @@ */ public abstract class TriggerSection extends TriggerItem { - @Nullable - protected TriggerItem first, last; + protected @Nullable TriggerItem first, last; /** * Reserved for new Trigger(...) @@ -103,11 +102,9 @@ protected final boolean run(Event event) { } @Override - @Nullable - protected abstract TriggerItem walk(Event event); + protected abstract @Nullable TriggerItem walk(Event event); - @Nullable - protected final TriggerItem walk(Event event, boolean run) { + protected final @Nullable TriggerItem walk(Event event, boolean run) { debug(event, run); if (run && first != null) { return first; diff --git a/src/main/java/ch/njol/skript/lang/UnparsedLiteral.java b/src/main/java/ch/njol/skript/lang/UnparsedLiteral.java index 9afe7bf664d..469ef7aa81d 100644 --- a/src/main/java/ch/njol/skript/lang/UnparsedLiteral.java +++ b/src/main/java/ch/njol/skript/lang/UnparsedLiteral.java @@ -31,7 +31,7 @@ import ch.njol.util.coll.CollectionUtils; import ch.njol.util.coll.iterator.NonNullIterator; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import java.util.logging.Level; @@ -43,8 +43,7 @@ public class UnparsedLiteral implements Literal { private final String data; - @Nullable - private final LogEntry error; + private final @Nullable LogEntry error; /** * @param data non-null, non-empty & trimmed string @@ -76,13 +75,11 @@ public Class getReturnType() { } @Override - @Nullable - public Literal getConvertedExpression(Class... to) { + public @Nullable Literal getConvertedExpression(Class... to) { return getConvertedExpression(ParseContext.DEFAULT, to); } - @Nullable - public Literal getConvertedExpression(ParseContext context, Class... to) { + public @Nullable Literal getConvertedExpression(ParseContext context, Class... to) { assert to.length > 0; assert to.length == 1 || !CollectionUtils.contains(to, Object.class); ParseLogHandler log = SkriptLogger.startParseLogHandler(); @@ -178,7 +175,7 @@ public NonNullIterator iterator(Event event) { } @Override - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) throws UnsupportedOperationException { + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) throws UnsupportedOperationException { throw invalidAccessException(); } diff --git a/src/main/java/ch/njol/skript/lang/Variable.java b/src/main/java/ch/njol/skript/lang/Variable.java index 160276e11d3..a9cfa472000 100644 --- a/src/main/java/ch/njol/skript/lang/Variable.java +++ b/src/main/java/ch/njol/skript/lang/Variable.java @@ -18,16 +18,6 @@ */ package ch.njol.skript.lang; -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.NoSuchElementException; -import java.util.TreeMap; - import ch.njol.skript.Skript; import ch.njol.skript.SkriptAPIException; import ch.njol.skript.SkriptConfig; @@ -35,9 +25,6 @@ import ch.njol.skript.classes.Changer.ChangeMode; import ch.njol.skript.classes.Changer.ChangerUtils; import ch.njol.skript.classes.ClassInfo; -import org.skriptlang.skript.lang.arithmetic.Arithmetics; -import org.skriptlang.skript.lang.arithmetic.OperationInfo; -import org.skriptlang.skript.lang.arithmetic.Operator; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.parser.ParserInstance; import ch.njol.skript.lang.util.SimpleExpression; @@ -58,13 +45,26 @@ import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; +import org.skriptlang.skript.lang.arithmetic.Arithmetics; +import org.skriptlang.skript.lang.arithmetic.OperationInfo; +import org.skriptlang.skript.lang.arithmetic.Operator; import org.skriptlang.skript.lang.comparator.Comparators; import org.skriptlang.skript.lang.comparator.Relation; import org.skriptlang.skript.lang.converter.Converters; import org.skriptlang.skript.lang.script.Script; import org.skriptlang.skript.lang.script.ScriptWarning; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.NoSuchElementException; +import java.util.TreeMap; + public class Variable implements Expression { private final static String SINGLE_SEPARATOR_CHAR = ":"; @@ -74,8 +74,7 @@ public class Variable implements Expression { /** * Script this variable was created in. */ - @Nullable - private final Script script; + private final @Nullable Script script; /** * The name of this variable, excluding the local variable token, but including the list variable token '::*'. @@ -88,8 +87,7 @@ public class Variable implements Expression { private final boolean local; private final boolean list; - @Nullable - private final Variable source; + private final @Nullable Variable source; @SuppressWarnings("unchecked") private Variable(VariableString name, Class[] types, boolean local, boolean list, @Nullable Variable source) { @@ -173,8 +171,7 @@ else if (character == '%') /** * Prints errors */ - @Nullable - public static Variable newInstance(String name, Class[] types) { + public static @Nullable Variable newInstance(String name, Class[] types) { name = "" + name.trim(); if (!isValidVariableName(name, true, true)) return null; @@ -301,8 +298,7 @@ public Variable getConvertedExpression(Class... to) { * Gets the value of this variable as stored in the variables map. * This method also checks against default variables. */ - @Nullable - public Object getRaw(Event event) { + public @Nullable Object getRaw(Event event) { DefaultVariables data = script == null ? null : script.getData(DefaultVariables.class); if (data != null) data.enterScope(); @@ -332,9 +328,7 @@ public Object getRaw(Event event) { return null; } - @Nullable - @SuppressWarnings("unchecked") - private Object get(Event event) { + private @Nullable Object get(Event event) { Object rawValue = getRaw(event); if (!list) return rawValue; @@ -342,10 +336,12 @@ private Object get(Event event) { return Array.newInstance(types[0], 0); List convertedValues = new ArrayList<>(); String name = StringUtils.substring(this.name.toString(event), 0, -1); + //noinspection unchecked for (Entry variable : ((Map) rawValue).entrySet()) { if (variable.getKey() != null && variable.getValue() != null) { Object value; if (variable.getValue() instanceof Map) + //noinspection unchecked value = ((Map) variable.getValue()).get(null); else value = variable.getValue(); @@ -361,8 +357,7 @@ private Object get(Event event) { * because the player object inside the variable will be a (kinda) dead variable * as a new player object has been created by the server. */ - @Nullable - Object convertIfOldPlayer(String key, Event event, @Nullable Object object) { + @Nullable Object convertIfOldPlayer(String key, Event event, @Nullable Object object) { if (SkriptConfig.enablePlayerVariableFix.value() && object instanceof Player) { Player oldPlayer = (Player) object; if (!oldPlayer.isValid() && oldPlayer.isOnline()) { @@ -385,11 +380,9 @@ public Iterator> variablesIterator(Event event) { // temporary list to prevent CMEs @SuppressWarnings("unchecked") Iterator keys = new ArrayList<>(((Map) val).keySet()).iterator(); - return new Iterator>() { - @Nullable - private String key; - @Nullable - private Object next = null; + return new Iterator<>() { + private @Nullable String key; + private @Nullable Object next = null; @Override public boolean hasNext() { @@ -424,9 +417,7 @@ public void remove() { } @Override - @Nullable - @SuppressWarnings("unchecked") - public Iterator iterator(Event event) { + public @Nullable Iterator iterator(Event event) { if (!list) { T value = getSingle(event); return value != null ? new SingleItemIterator<>(value) : null; @@ -437,22 +428,20 @@ public Iterator iterator(Event event) { return new EmptyIterator<>(); assert value instanceof TreeMap; // temporary list to prevent CMEs + //noinspection unchecked Iterator keys = new ArrayList<>(((Map) value).keySet()).iterator(); - return new Iterator() { - @Nullable - private String key; - @Nullable - private T next = null; + return new Iterator<>() { + private @Nullable T next = null; @Override - @SuppressWarnings({"unchecked"}) public boolean hasNext() { if (next != null) return true; while (keys.hasNext()) { - key = keys.next(); + @Nullable String key = keys.next(); if (key != null) { next = Converters.convert(Variables.getVariable(name + key, event, local), types); + //noinspection unchecked next = (T) convertIfOldPlayer(name + key, event, next); if (next != null && !(next instanceof TreeMap)) return true; @@ -479,8 +468,7 @@ public void remove() { }; } - @Nullable - private T getConverted(Event event) { + private @Nullable T getConverted(Event event) { assert !list; return Converters.convert(get(event), types); } @@ -502,7 +490,7 @@ private void setIndex(Event event, String index, @Nullable Object value) { } @Override - public Class[] acceptChange(ChangeMode mode) { + public Class @Nullable [] acceptChange(ChangeMode mode) { if (!list && mode == ChangeMode.SET) return CollectionUtils.array(Object.class); return CollectionUtils.array(Object[].class); @@ -510,7 +498,7 @@ public Class[] acceptChange(ChangeMode mode) { @Override @SuppressWarnings({"unchecked", "rawtypes"}) - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) throws UnsupportedOperationException { + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) throws UnsupportedOperationException { switch (mode) { case DELETE: if (list) { @@ -667,8 +655,7 @@ public void change(Event event, @Nullable Object[] delta, ChangeMode mode) throw } @Override - @Nullable - public T getSingle(Event event) { + public @Nullable T getSingle(Event event) { if (list) throw new SkriptAPIException("Invalid call to getSingle"); return getConverted(event); diff --git a/src/main/java/ch/njol/skript/lang/VariableString.java b/src/main/java/ch/njol/skript/lang/VariableString.java index b9f914b1ddc..a44694cc6d3 100644 --- a/src/main/java/ch/njol/skript/lang/VariableString.java +++ b/src/main/java/ch/njol/skript/lang/VariableString.java @@ -58,8 +58,7 @@ */ public class VariableString implements Expression { - @Nullable - private final Script script; + private final @Nullable Script script; protected final String original; @@ -69,8 +68,7 @@ public class VariableString implements Expression { private Object @Nullable [] stringsUnformatted; private final boolean isSimple; - @Nullable - private final String simple, simpleUnformatted; + private final @Nullable String simple, simpleUnformatted; private final StringMode mode; /** @@ -141,8 +139,7 @@ private VariableString(String original, Object[] strings, StringMode mode) { /** * Prints errors */ - @Nullable - public static VariableString newInstance(String input) { + public static @Nullable VariableString newInstance(String input) { return newInstance(input, StringMode.MESSAGE); } @@ -153,8 +150,7 @@ public static VariableString newInstance(String input) { * @param original Unquoted string to parse. * @return A new VariableString instance. */ - @Nullable - public static VariableString newInstance(String original, StringMode mode) { + public static @Nullable VariableString newInstance(String original, StringMode mode) { if (mode != StringMode.VARIABLE_NAME && !isQuotedCorrectly(original, false)) return null; @@ -364,8 +360,7 @@ public static VariableString[] makeStrings(String[] args) { * @param args Quoted strings - This is not checked! * @return a new array containing all newly created VariableStrings, or null if one is invalid */ - @Nullable - public static VariableString[] makeStringsFromQuoted(List args) { + public static VariableString @Nullable [] makeStringsFromQuoted(List args) { VariableString[] strings = new VariableString[args.size()]; for (int i = 0; i < args.size(); i++) { assert args.get(i).startsWith("\"") && args.get(i).endsWith("\""); @@ -491,8 +486,7 @@ public String toChatString(Event event) { return ChatMessages.toJson(getMessageComponents(event)); } - @Nullable - private static ChatColor getLastColor(CharSequence sequence) { + private static @Nullable ChatColor getLastColor(CharSequence sequence) { for (int i = sequence.length() - 2; i >= 0; i--) { if (sequence.charAt(i) == ChatColor.COLOR_CHAR) { ChatColor color = ChatColor.getByChar(sequence.charAt(i + 1)); @@ -574,8 +568,7 @@ public String toString(@Nullable Event event, boolean debug) { * * @return List of all possible super class code names. */ - @NotNull - public List getDefaultVariableNames(String variableName, Event event) { + public @NotNull List getDefaultVariableNames(String variableName, Event event) { if (script == null || mode != StringMode.VARIABLE_NAME) return Lists.newArrayList(); @@ -672,9 +665,8 @@ public boolean check(Event event, Checker checker) { } @Override - @Nullable @SuppressWarnings("unchecked") - public Expression getConvertedExpression(Class... to) { + public @Nullable Expression getConvertedExpression(Class... to) { if (CollectionUtils.containsSuperclass(to, String.class)) return (Expression) this; return ConvertedExpression.newInstance(this, to); @@ -686,13 +678,12 @@ public Class getReturnType() { } @Override - @Nullable - public Class[] acceptChange(ChangeMode mode) { + public Class @Nullable [] acceptChange(ChangeMode mode) { return null; } @Override - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) throws UnsupportedOperationException { + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } @@ -731,7 +722,6 @@ public Expression getSource() { return this; } - @SuppressWarnings("unchecked") public static Expression setStringMode(Expression expression, StringMode mode) { if (expression instanceof ExpressionList) { Expression[] expressions = ((ExpressionList) expression).getExpressions(); @@ -741,6 +731,7 @@ public static Expression setStringMode(Expression expression, StringMo expressions[i] = setStringMode(expr, mode); } } else if (expression instanceof VariableString) { + //noinspection unchecked return (Expression) ((VariableString) expression).setMode(mode); } return expression; diff --git a/src/main/java/ch/njol/skript/lang/function/EffFunctionCall.java b/src/main/java/ch/njol/skript/lang/function/EffFunctionCall.java index adec5001679..3b52f3bf07e 100644 --- a/src/main/java/ch/njol/skript/lang/function/EffFunctionCall.java +++ b/src/main/java/ch/njol/skript/lang/function/EffFunctionCall.java @@ -54,8 +54,8 @@ protected void execute(final Event e) { } @Override - public String toString(@Nullable final Event e, final boolean debug) { - return function.toString(e, debug); + public String toString(@Nullable final Event event, final boolean debug) { + return function.toString(event, debug); } @Override diff --git a/src/main/java/ch/njol/skript/lang/function/ExprFunctionCall.java b/src/main/java/ch/njol/skript/lang/function/ExprFunctionCall.java index 09d9966c586..5028a277fe6 100644 --- a/src/main/java/ch/njol/skript/lang/function/ExprFunctionCall.java +++ b/src/main/java/ch/njol/skript/lang/function/ExprFunctionCall.java @@ -21,12 +21,12 @@ import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.util.SimpleExpression; -import org.skriptlang.skript.lang.converter.Converters; import ch.njol.skript.util.Utils; import ch.njol.util.Kleenean; import ch.njol.util.coll.CollectionUtils; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; +import org.skriptlang.skript.lang.converter.Converters; public class ExprFunctionCall extends SimpleExpression { @@ -55,17 +55,15 @@ public ExprFunctionCall(FunctionReference function, Class[] expe } @Override - @Nullable - protected T[] get(Event e) { + protected T @Nullable [] get(Event e) { Object[] returnValue = function.execute(e); function.resetReturnValue(); return Converters.convert(returnValue, returnTypes, returnType); } @Override - @Nullable @SuppressWarnings("unchecked") - public Expression getConvertedExpression(Class... to) { + public @Nullable Expression getConvertedExpression(Class... to) { if (CollectionUtils.containsSuperclass(to, getReturnType())) return (Expression) this; assert function.getReturnType() != null; @@ -86,8 +84,8 @@ public Class getReturnType() { } @Override - public String toString(@Nullable Event e, boolean debug) { - return function.toString(e, debug); + public String toString(@Nullable Event event, boolean debug) { + return function.toString(event, debug); } @Override diff --git a/src/main/java/ch/njol/skript/lang/function/Function.java b/src/main/java/ch/njol/skript/lang/function/Function.java index 166191f5f21..d7b9893bb14 100644 --- a/src/main/java/ch/njol/skript/lang/function/Function.java +++ b/src/main/java/ch/njol/skript/lang/function/Function.java @@ -18,14 +18,13 @@ */ package ch.njol.skript.lang.function; -import java.util.Arrays; - -import org.bukkit.Bukkit; -import org.eclipse.jdt.annotation.Nullable; - import ch.njol.skript.SkriptConfig; import ch.njol.skript.classes.ClassInfo; import ch.njol.util.coll.CollectionUtils; +import org.bukkit.Bukkit; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; /** * Functions can be called using arguments. @@ -68,9 +67,8 @@ public Parameter getParameter(int index) { public boolean isSingle() { return sign.isSingle(); } - - @Nullable - public ClassInfo getReturnType() { + + public @Nullable ClassInfo getReturnType() { return sign.getReturnType(); } @@ -83,9 +81,7 @@ public ClassInfo getReturnType() { * {@link Signature#getMaxParameters()} elements. * @return The result(s) of this function */ - @SuppressWarnings("null") - @Nullable - public final T[] execute(Object[][] params) { + public final T @Nullable [] execute(Object[][] params) { FunctionEvent e = new FunctionEvent<>(this); // Call function event only if requested by addon @@ -148,8 +144,7 @@ public final T[] execute(Object[][] params) { * you need to manually handle default values. * @return Function return value(s). */ - @Nullable - public abstract T[] execute(FunctionEvent e, Object[][] params); + public abstract T @Nullable [] execute(FunctionEvent e, Object[][] params); /** * Resets the return value of the {@code Function}. diff --git a/src/main/java/ch/njol/skript/lang/function/FunctionReference.java b/src/main/java/ch/njol/skript/lang/function/FunctionReference.java index 409e4edd686..f60f480ad8c 100644 --- a/src/main/java/ch/njol/skript/lang/function/FunctionReference.java +++ b/src/main/java/ch/njol/skript/lang/function/FunctionReference.java @@ -28,12 +28,12 @@ import ch.njol.skript.log.RetainingLogHandler; import ch.njol.skript.log.SkriptLogger; import ch.njol.skript.registrations.Classes; -import org.skriptlang.skript.lang.converter.Converters; +import ch.njol.skript.util.Contract; import ch.njol.skript.util.LiteralUtils; import ch.njol.util.StringUtils; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; -import ch.njol.skript.util.Contract; +import org.jetbrains.annotations.Nullable; +import org.skriptlang.skript.lang.converter.Converters; import java.util.ArrayList; import java.util.Arrays; @@ -53,15 +53,13 @@ public class FunctionReference implements Contract { * Signature of referenced function. If {@link #validateFunction(boolean)} * succeeds, this is not null. */ - @Nullable - private Signature signature; + private @Nullable Signature signature; /** * Actual function reference. Null before the function is called for first * time. */ - @Nullable - private Function function; + private @Nullable Function function; /** * If all function parameters can be condensed to a single list. @@ -89,15 +87,13 @@ public class FunctionReference implements Contract { /** * Node for {@link #validateFunction(boolean)} to use for logging. */ - @Nullable - private final Node node; + private final @Nullable Node node; /** * Script in which this reference is found. Used for function unload * safety checks. */ - @Nullable - public final String script; + public final @Nullable String script; /** * The contract for this function (typically the function reference itself). @@ -133,7 +129,6 @@ public boolean validateParameterArity(boolean first) { * this is called when the function signature changes. * @return True if validation succeeded. */ - @SuppressWarnings("unchecked") public boolean validateFunction(boolean first) { if (!first && script == null) return false; @@ -230,6 +225,7 @@ public boolean validateFunction(boolean first) { Parameter p = sign.parameters[singleListParam ? 0 : i]; RetainingLogHandler log = SkriptLogger.startRetainingLog(); try { + //noinspection unchecked Expression e = parameters[i].getConvertedExpression(p.type.getC()); if (e == null) { if (first) { @@ -262,7 +258,8 @@ public boolean validateFunction(boolean first) { log.printLog(); } } - + + //noinspection unchecked signature = (Signature) sign; sign.calls.add(this); @@ -273,8 +270,7 @@ public boolean validateFunction(boolean first) { return true; } - @Nullable - public Function getFunction() { + public @Nullable Function getFunction() { return function; } @@ -284,11 +280,10 @@ public boolean resetReturnValue() { return false; } - @SuppressWarnings("unchecked") - @Nullable - protected T[] execute(Event e) { + protected T @Nullable [] execute(Event event) { // If needed, acquire the function reference if (function == null) + //noinspection unchecked function = (Function) Functions.getFunction(functionName, script); if (function == null) { // It might be impossible to resolve functions in some cases! @@ -301,7 +296,7 @@ protected T[] execute(Event e) { if (singleListParam && parameters.length > 1) { // All parameters to one list List l = new ArrayList<>(); for (Expression parameter : parameters) - l.addAll(Arrays.asList(parameter.getArray(e))); + l.addAll(Arrays.asList(parameter.getArray(event))); params[0] = l.toArray(); // Don't allow mutating across function boundary; same hack is applied to variables @@ -310,7 +305,7 @@ protected T[] execute(Event e) { } } else { // Use parameters in normal way for (int i = 0; i < parameters.length; i++) { - Object[] array = parameters[i].getArray(e); + Object[] array = parameters[i].getArray(event); params[i] = Arrays.copyOf(array, array.length); // Don't allow mutating across function boundary; same hack is applied to variables for (int j = 0; j < params[i].length; j++) { @@ -332,19 +327,16 @@ public boolean isSingle(Expression... arguments) { return single; } - @Nullable - public Class getReturnType() { + public @Nullable Class getReturnType() { //noinspection unchecked return (Class) contract.getReturnType(parameters); } @Override - @Nullable - public Class getReturnType(Expression... arguments) { + public @Nullable Class getReturnType(Expression... arguments) { if (signature == null) throw new SkriptAPIException("Signature of function is null when return type is asked!"); - @SuppressWarnings("ConstantConditions") ClassInfo ret = signature.returnType; return ret == null ? null : ret.getC(); } @@ -357,12 +349,12 @@ public Contract getContract() { return contract; } - public String toString(@Nullable Event e, boolean debug) { + public String toString(@Nullable Event event, boolean debug) { StringBuilder b = new StringBuilder(functionName + "("); for (int i = 0; i < parameters.length; i++) { if (i != 0) b.append(", "); - b.append(parameters[i].toString(e, debug)); + b.append(parameters[i].toString(event, debug)); } b.append(")"); return b.toString(); diff --git a/src/main/java/ch/njol/skript/lang/function/Functions.java b/src/main/java/ch/njol/skript/lang/function/Functions.java index 2eee7ea6c18..71bbd568d5d 100644 --- a/src/main/java/ch/njol/skript/lang/function/Functions.java +++ b/src/main/java/ch/njol/skript/lang/function/Functions.java @@ -23,14 +23,11 @@ import ch.njol.skript.SkriptAddon; import ch.njol.skript.classes.ClassInfo; import ch.njol.skript.config.SectionNode; -import ch.njol.skript.lang.ParseContext; -import ch.njol.skript.lang.SkriptParser; -import ch.njol.skript.log.SkriptLogger; import ch.njol.skript.registrations.Classes; import ch.njol.skript.util.Utils; import ch.njol.util.NonNullPair; import ch.njol.util.StringUtils; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import org.skriptlang.skript.lang.script.Script; import java.util.ArrayList; @@ -53,8 +50,7 @@ public abstract class Functions { private Functions() {} - @Nullable - public static ScriptFunction currentFunction = null; + public static @Nullable ScriptFunction currentFunction = null; /** * Function namespaces. @@ -105,8 +101,7 @@ public static JavaFunction registerFunction(JavaFunction function) { * to get a new signature instance and {@link Functions#registerSignature(Signature)} to register the signature * @return Script function, or null if something went wrong. */ - @Nullable - public static Function loadFunction(Script script, SectionNode node, Signature signature) { + public static @Nullable Function loadFunction(Script script, SectionNode node, Signature signature) { String name = signature.name; Namespace namespace = getScriptNamespace(script.getConfig().getFileName()); if (namespace == null) { @@ -140,9 +135,7 @@ public static Function loadFunction(Script script, SectionNode node, Signatur * @return Parsed signature or null if something went wrong. * @see Functions#registerSignature(Signature) */ - @Nullable - @SuppressWarnings({"unchecked", "null"}) - public static Signature parseSignature(String script, String name, String args, @Nullable String returnType, boolean local) { + public static @Nullable Signature parseSignature(String script, String name, String args, @Nullable String returnType, boolean local) { List> parameters = Parameter.parse(args); if (parameters == null) return null; @@ -162,6 +155,7 @@ public static Signature parseSignature(String script, String name, String arg if (returnClass == null) return signError("Cannot recognise the type '" + returnType + "'"); } + //noinspection unchecked return new Signature<>(script, name, parameters.toArray(new Parameter[0]), local, (ClassInfo) returnClass, singleReturn, null); } @@ -171,8 +165,7 @@ public static Signature parseSignature(String script, String name, String arg * @return Signature of function, or null if something went wrong. * @see Functions#parseSignature(String, String, String, String, boolean) */ - @Nullable - public static Signature registerSignature(Signature signature) { + public static @Nullable Signature registerSignature(Signature signature) { // Ensure there are no duplicate functions if (signature.local) { Namespace namespace = getScriptNamespace(signature.script); @@ -207,8 +200,7 @@ public static Signature registerSignature(Signature signature) { * @param error Error message. * @return Null. */ - @Nullable - private static Function error(String error) { + private static @Nullable Function error(String error) { Skript.error(error); return null; } @@ -218,8 +210,7 @@ private static Function error(String error) { * @param error Error message. * @return Null. */ - @Nullable - private static Signature signError(String error) { + private static @Nullable Signature signError(String error) { Skript.error(error); return null; } @@ -234,8 +225,7 @@ private static Signature signError(String error) { * @return Function, or null if it does not exist. */ @Deprecated - @Nullable - public static Function getFunction(String name) { + public static @Nullable Function getFunction(String name) { return getGlobalFunction(name); } @@ -247,8 +237,7 @@ public static Function getFunction(String name) { * @param name Name of function. * @return Function, or null if it does not exist. */ - @Nullable - public static Function getGlobalFunction(String name) { + public static @Nullable Function getGlobalFunction(String name) { Namespace namespace = globalFunctions.get(name); if (namespace == null) return null; @@ -264,8 +253,7 @@ public static Function getGlobalFunction(String name) { * @param script The script where the function is declared in. Used to get local functions. * @return Function, or null if it does not exist. */ - @Nullable - public static Function getLocalFunction(String name, String script) { + public static @Nullable Function getLocalFunction(String name, String script) { Namespace namespace = null; Function function = null; namespace = getScriptNamespace(script); @@ -284,8 +272,7 @@ public static Function getLocalFunction(String name, String script) { * @param script The script where the function is declared in. Used to get local functions. * @return Function, or null if it does not exist. */ - @Nullable - public static Function getFunction(String name, @Nullable String script) { + public static @Nullable Function getFunction(String name, @Nullable String script) { if (script == null) return getGlobalFunction(name); Function function = getLocalFunction(name, script); @@ -302,8 +289,7 @@ public static Function getFunction(String name, @Nullable String script) { * @return Signature, or null if function does not exist. */ @Deprecated - @Nullable - public static Signature getSignature(String name) { + public static @Nullable Signature getSignature(String name) { return getGlobalSignature(name); } @@ -313,8 +299,7 @@ public static Signature getSignature(String name) { * @param name Name of function. * @return Signature, or null if function does not exist. */ - @Nullable - public static Signature getGlobalSignature(String name) { + public static @Nullable Signature getGlobalSignature(String name) { Namespace namespace = globalFunctions.get(name); if (namespace == null) return null; @@ -328,8 +313,7 @@ public static Signature getGlobalSignature(String name) { * @param script The script where the function is declared in. Used to get local functions. * @return Signature, or null if function does not exist. */ - @Nullable - public static Signature getLocalSignature(String name, String script) { + public static @Nullable Signature getLocalSignature(String name, String script) { Namespace namespace = null; Signature signature = null; namespace = getScriptNamespace(script); @@ -346,8 +330,7 @@ public static Signature getLocalSignature(String name, String script) { * @param script The script where the function is declared in. Used to get local functions. * @return Signature, or null if function does not exist. */ - @Nullable - public static Signature getSignature(String name, @Nullable String script) { + public static @Nullable Signature getSignature(String name, @Nullable String script) { if (script == null) return getGlobalSignature(name); Signature signature = getLocalSignature(name, script); @@ -356,8 +339,7 @@ public static Signature getSignature(String name, @Nullable String script) { return signature; } - @Nullable - public static Namespace getScriptNamespace(String script) { + public static @Nullable Namespace getScriptNamespace(String script) { return namespaces.get(new Namespace.Key(Namespace.Origin.SCRIPT, script)); } diff --git a/src/main/java/ch/njol/skript/lang/function/JavaFunction.java b/src/main/java/ch/njol/skript/lang/function/JavaFunction.java index 5b23f304d77..877df44ee3e 100644 --- a/src/main/java/ch/njol/skript/lang/function/JavaFunction.java +++ b/src/main/java/ch/njol/skript/lang/function/JavaFunction.java @@ -18,10 +18,9 @@ */ package ch.njol.skript.lang.function; -import org.eclipse.jdt.annotation.Nullable; - import ch.njol.skript.classes.ClassInfo; import ch.njol.skript.util.Contract; +import org.jetbrains.annotations.Nullable; /** * @author Peter Güttinger @@ -41,17 +40,12 @@ public JavaFunction(String name, Parameter[] parameters, ClassInfo returnT } @Override - @Nullable - public abstract T[] execute(FunctionEvent e, Object[][] params); - - @Nullable - private String[] description = null; - @Nullable - private String[] examples = null; - @Nullable - private String[] keywords; - @Nullable - private String since = null; + public abstract T @Nullable [] execute(FunctionEvent e, Object[][] params); + + private String @Nullable [] description = null; + private String @Nullable [] examples = null; + private String @Nullable [] keywords; + private @Nullable String since = null; /** * Only used for Skript's documentation. @@ -97,24 +91,20 @@ public JavaFunction since(final String since) { this.since = since; return this; } - - @Nullable - public String[] getDescription() { + + public String @Nullable [] getDescription() { return description; } - - @Nullable - public String[] getExamples() { + + public String @Nullable [] getExamples() { return examples; } - @Nullable - public String[] getKeywords() { + public String @Nullable [] getKeywords() { return keywords; } - - @Nullable - public String getSince() { + + public @Nullable String getSince() { return since; } diff --git a/src/main/java/ch/njol/skript/lang/function/Namespace.java b/src/main/java/ch/njol/skript/lang/function/Namespace.java index 7834e7f8899..be649efd1b0 100644 --- a/src/main/java/ch/njol/skript/lang/function/Namespace.java +++ b/src/main/java/ch/njol/skript/lang/function/Namespace.java @@ -18,13 +18,13 @@ */ package ch.njol.skript.lang.function; +import org.jetbrains.annotations.Nullable; + import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Objects; -import org.eclipse.jdt.annotation.Nullable; - /** * Contains a set of functions. */ @@ -52,8 +52,7 @@ public static class Key { private final Origin origin; - @Nullable - private final String scriptName; + private final @Nullable String scriptName; public Key(Origin origin, @Nullable String scriptName) { super(); @@ -65,8 +64,7 @@ public Origin getOrigin() { return origin; } - @Nullable - public String getScriptName() { + public @Nullable String getScriptName() { return scriptName; } @@ -156,14 +154,12 @@ public Namespace() { this.signatures = new HashMap<>(); this.functions = new HashMap<>(); } - - @Nullable - public Signature getSignature(String name, boolean local) { + + public @Nullable Signature getSignature(String name, boolean local) { return signatures.get(new Info(name, local)); } - @Nullable - public Signature getSignature(String name) { + public @Nullable Signature getSignature(String name) { Signature signature = getSignature(name, true); return signature == null ? getSignature(name, false) : signature; } @@ -187,14 +183,12 @@ public boolean removeSignature(Signature sign) { public Collection> getSignatures() { return signatures.values(); } - - @Nullable - public Function getFunction(String name, boolean local) { + + public @Nullable Function getFunction(String name, boolean local) { return functions.get(new Info(name, local)); } - @Nullable - public Function getFunction(String name) { + public @Nullable Function getFunction(String name) { Function function = getFunction(name, true); return function == null ? getFunction(name, false) : function; } diff --git a/src/main/java/ch/njol/skript/lang/function/Parameter.java b/src/main/java/ch/njol/skript/lang/function/Parameter.java index b77a95b8c5d..deee1d1593e 100644 --- a/src/main/java/ch/njol/skript/lang/function/Parameter.java +++ b/src/main/java/ch/njol/skript/lang/function/Parameter.java @@ -32,7 +32,7 @@ import ch.njol.skript.util.Utils; import ch.njol.util.NonNullPair; import ch.njol.util.StringUtils; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -61,8 +61,7 @@ public final class Parameter { * Expression that will provide default value of this parameter * when the function is called. */ - @Nullable - final Expression def; + final @Nullable Expression def; /** * Whether this parameter takes one or many values. @@ -84,10 +83,8 @@ public Parameter(String name, ClassInfo type, boolean single, @Nullable Expre public ClassInfo getType() { return type; } - - @SuppressWarnings("unchecked") - @Nullable - public static Parameter newInstance(String name, ClassInfo type, boolean single, @Nullable String def) { + + public static @Nullable Parameter newInstance(String name, ClassInfo type, boolean single, @Nullable String def) { if (!Variable.isValidVariableName(name, true, false)) { Skript.error("A parameter's name must be a valid variable name."); // ... because it will be made available as local variable @@ -99,6 +96,7 @@ public static Parameter newInstance(String name, ClassInfo type, boole // Parse the default value expression try { + //noinspection unchecked d = new SkriptParser(def, SkriptParser.ALL_FLAGS, ParseContext.DEFAULT).parseExpression(type.getC()); if (d == null || LiteralUtils.hasUnparsedLiteral(d)) { log.printErrors("Can't understand this expression: " + def); @@ -118,8 +116,7 @@ public static Parameter newInstance(String name, ClassInfo type, boole * @param args The string to parse. * @return The parsed parameters */ - @Nullable - public static List> parse(String args) { + public static @Nullable List> parse(String args) { List> params = new ArrayList<>(); boolean caseInsensitive = SkriptConfig.caseInsensitiveVariables.value(); int j = 0; @@ -188,8 +185,7 @@ public String getName() { * Get the Expression that will be used to provide the default value of this parameter when the function is called. * @return Expression that will provide default value of this parameter */ - @Nullable - public Expression getDefaultExpression() { + public @Nullable Expression getDefaultExpression() { return def; } diff --git a/src/main/java/ch/njol/skript/lang/function/ScriptFunction.java b/src/main/java/ch/njol/skript/lang/function/ScriptFunction.java index c34f26fd448..a864537cb00 100644 --- a/src/main/java/ch/njol/skript/lang/function/ScriptFunction.java +++ b/src/main/java/ch/njol/skript/lang/function/ScriptFunction.java @@ -19,17 +19,16 @@ package ch.njol.skript.lang.function; import ch.njol.skript.classes.ClassInfo; +import ch.njol.skript.config.SectionNode; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.ReturnHandler; -import org.bukkit.event.Event; -import org.jetbrains.annotations.ApiStatus; -import org.skriptlang.skript.lang.script.Script; -import org.eclipse.jdt.annotation.Nullable; - -import ch.njol.skript.config.SectionNode; import ch.njol.skript.lang.Trigger; import ch.njol.skript.lang.util.SimpleEvent; import ch.njol.skript.variables.Variables; +import org.bukkit.event.Event; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; +import org.skriptlang.skript.lang.script.Script; public class ScriptFunction extends Function implements ReturnHandler { @@ -61,21 +60,21 @@ public ScriptFunction(Signature sign, SectionNode node) { // REMIND track possible types of local variables (including undefined variables) (consider functions, commands, and EffChange) - maybe make a general interface for this purpose // REM: use patterns, e.g. {_a%b%} is like "a.*", and thus subsequent {_axyz} may be set and of that type. @Override - public T @Nullable [] execute(final FunctionEvent e, final Object[][] params) { + public T @Nullable [] execute(FunctionEvent event, Object[][] params) { Parameter[] parameters = getSignature().getParameters(); for (int i = 0; i < parameters.length; i++) { - Parameter p = parameters[i]; + Parameter parameter = parameters[i]; Object[] val = params[i]; - if (p.single && val.length > 0) { - Variables.setVariable(p.name, val[0], e, true); + if (parameter.single && val.length > 0) { + Variables.setVariable(parameter.name, val[0], event, true); } else { for (int j = 0; j < val.length; j++) { - Variables.setVariable(p.name + "::" + (j + 1), val[j], e, true); + Variables.setVariable(parameter.name + "::" + (j + 1), val[j], event, true); } } } - trigger.execute(e); + trigger.execute(event); ClassInfo returnType = getReturnType(); return returnType != null ? returnValues : null; } diff --git a/src/main/java/ch/njol/skript/lang/function/Signature.java b/src/main/java/ch/njol/skript/lang/function/Signature.java index 3b30e2273de..e7e8477d633 100644 --- a/src/main/java/ch/njol/skript/lang/function/Signature.java +++ b/src/main/java/ch/njol/skript/lang/function/Signature.java @@ -19,8 +19,8 @@ package ch.njol.skript.lang.function; import ch.njol.skript.classes.ClassInfo; -import org.eclipse.jdt.annotation.Nullable; import ch.njol.skript.util.Contract; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Collections; @@ -56,8 +56,7 @@ public class Signature { * is null. void is never used as return type, because it is not registered * to Skript's type system. */ - @Nullable - final ClassInfo returnType; + final @Nullable ClassInfo returnType; /** * Whether this function returns a single value, or multiple ones. @@ -73,14 +72,12 @@ public class Signature { /** * The class path for the origin of this signature. */ - @Nullable - final String originClassPath; + final @Nullable String originClassPath; /** * An overriding contract for this function (e.g. to base its return on its arguments). */ - @Nullable - final Contract contract; + final @Nullable Contract contract; public Signature(String script, String name, @@ -131,8 +128,7 @@ public boolean isLocal() { return local; } - @Nullable - public ClassInfo getReturnType() { + public @Nullable ClassInfo getReturnType() { return returnType; } @@ -144,8 +140,7 @@ public String getOriginClassPath() { return originClassPath; } - @Nullable - public Contract getContract() { + public @Nullable Contract getContract() { return contract; } diff --git a/src/main/java/ch/njol/skript/lang/function/SimpleJavaFunction.java b/src/main/java/ch/njol/skript/lang/function/SimpleJavaFunction.java index 87e3bd4f26a..5f7d4c7ebb2 100644 --- a/src/main/java/ch/njol/skript/lang/function/SimpleJavaFunction.java +++ b/src/main/java/ch/njol/skript/lang/function/SimpleJavaFunction.java @@ -18,10 +18,10 @@ */ package ch.njol.skript.lang.function; -import org.eclipse.jdt.annotation.Nullable; import ch.njol.skript.classes.ClassInfo; import ch.njol.skript.util.Contract; +import org.jetbrains.annotations.Nullable; /** * A {@link JavaFunction} which doesn't make use of @@ -41,19 +41,16 @@ public SimpleJavaFunction(String name, Parameter[] parameters, ClassInfo r public SimpleJavaFunction(String name, Parameter[] parameters, ClassInfo returnType, boolean single, Contract contract) { super(name, parameters, returnType, single, contract); } - - @SuppressWarnings("ConstantConditions") - @Nullable + @Override - public final T[] execute(FunctionEvent e, Object[][] params) { + public final T @Nullable [] execute(FunctionEvent e, Object[][] params) { for (Object[] param : params) { if (param == null || param.length == 0 || param[0] == null) return null; } return executeSimple(params); } - - @Nullable - public abstract T[] executeSimple(Object[][] params); + + public abstract T @Nullable [] executeSimple(Object[][] params); } diff --git a/src/main/java/ch/njol/skript/lang/parser/ParserInstance.java b/src/main/java/ch/njol/skript/lang/parser/ParserInstance.java index 8ed8cd5a919..5e1300d974a 100644 --- a/src/main/java/ch/njol/skript/lang/parser/ParserInstance.java +++ b/src/main/java/ch/njol/skript/lang/parser/ParserInstance.java @@ -112,8 +112,7 @@ public void reset() { // Script API - @Nullable - private Script currentScript = null; + private @Nullable Script currentScript = null; /** * Internal method for updating the current script. Allows null parameter. @@ -151,8 +150,7 @@ public Script getCurrentScript() { // Structure API - @Nullable - private Structure currentStructure = null; + private @Nullable Structure currentStructure = null; /** * Updates the Structure currently being handled by this ParserInstance. @@ -165,8 +163,7 @@ public void setCurrentStructure(@Nullable Structure structure) { /** * @return The Structure currently being handled by this ParserInstance. */ - @Nullable - public Structure getCurrentStructure() { + public @Nullable Structure getCurrentStructure() { return currentStructure; } @@ -191,8 +188,7 @@ public final boolean isCurrentStructure(Class... structureC // Event API - @Nullable - private String currentEventName; + private @Nullable String currentEventName; private Class @Nullable [] currentEvents = null; @@ -200,8 +196,7 @@ public void setCurrentEventName(@Nullable String currentEventName) { this.currentEventName = currentEventName; } - @Nullable - public String getCurrentEventName() { + public @Nullable String getCurrentEventName() { return currentEventName; } @@ -298,12 +293,11 @@ public List getCurrentSections() { * Returns {@code null} if {@link #isCurrentSection(Class)} returns {@code false}. * @see #getCurrentSections() */ - @Nullable - @SuppressWarnings("unchecked") - public T getCurrentSection(Class sectionClass) { + public @Nullable T getCurrentSection(Class sectionClass) { for (int i = currentSections.size(); i-- > 0;) { TriggerSection triggerSection = currentSections.get(i); if (sectionClass.isInstance(triggerSection)) + //noinspection unchecked return (T) triggerSection; } return null; @@ -314,12 +308,11 @@ public T getCurrentSection(Class sectionClass) { * Modifications to the returned list are not saved. * @see #getCurrentSections() */ - @NotNull - @SuppressWarnings("unchecked") - public List getCurrentSections(Class sectionClass) { + public @NotNull List getCurrentSections(Class sectionClass) { List list = new ArrayList<>(); for (TriggerSection triggerSection : currentSections) { if (sectionClass.isInstance(triggerSection)) + //noinspection unchecked list.add((T) triggerSection); } return list; @@ -388,8 +381,7 @@ public HandlerList getHandlers() { return handlers; } - @Nullable - private Node node; + private @Nullable Node node; /** * @param node The node to mark as being handled. This is mainly used for logging. @@ -403,8 +395,7 @@ public void setNode(@Nullable Node node) { * @return The node currently marked as being handled. This is mainly used for logging. * Null indicates no node is currently being handled (that the ParserInstance is aware of). */ - @Nullable - public Node getNode() { + public @Nullable Node getNode() { return node; } @@ -636,9 +627,8 @@ public HashMap getCurrentOptions() { /** * @deprecated Use {@link #getCurrentStructure()} */ - @Nullable @Deprecated - public SkriptEvent getCurrentSkriptEvent() { + public @Nullable SkriptEvent getCurrentSkriptEvent() { Structure structure = getCurrentStructure(); if (structure instanceof SkriptEvent) return (SkriptEvent) structure; diff --git a/src/main/java/ch/njol/skript/lang/util/ContainerExpression.java b/src/main/java/ch/njol/skript/lang/util/ContainerExpression.java index e23c43c476f..c0aa1518128 100644 --- a/src/main/java/ch/njol/skript/lang/util/ContainerExpression.java +++ b/src/main/java/ch/njol/skript/lang/util/ContainerExpression.java @@ -23,7 +23,7 @@ import ch.njol.skript.util.Container; import ch.njol.util.Kleenean; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import java.util.Iterator; import java.util.NoSuchElementException; @@ -47,14 +47,12 @@ protected Object[] get(Event e) { } @Override - @Nullable - public Iterator iterator(Event event) { + public @Nullable Iterator iterator(Event event) { Iterator> iterator = expr.iterator(event); if (iterator == null) return null; - return new Iterator() { - @Nullable - private Iterator current; + return new Iterator<>() { + private @Nullable Iterator current; @Override public boolean hasNext() { diff --git a/src/main/java/ch/njol/skript/lang/util/ContextlessEvent.java b/src/main/java/ch/njol/skript/lang/util/ContextlessEvent.java index 3e9208a2694..9338fcc73ee 100644 --- a/src/main/java/ch/njol/skript/lang/util/ContextlessEvent.java +++ b/src/main/java/ch/njol/skript/lang/util/ContextlessEvent.java @@ -47,8 +47,7 @@ public static ContextlessEvent get() { * This method should never be called. */ @Override - @NotNull - public HandlerList getHandlers() { + public @NotNull HandlerList getHandlers() { throw new IllegalStateException(); } diff --git a/src/main/java/ch/njol/skript/lang/util/ConvertedExpression.java b/src/main/java/ch/njol/skript/lang/util/ConvertedExpression.java index 5fff6740da5..cdda53f68bd 100644 --- a/src/main/java/ch/njol/skript/lang/util/ConvertedExpression.java +++ b/src/main/java/ch/njol/skript/lang/util/ConvertedExpression.java @@ -28,7 +28,7 @@ import ch.njol.util.Kleenean; import ch.njol.util.coll.CollectionUtils; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import org.skriptlang.skript.lang.converter.Converter; import org.skriptlang.skript.lang.converter.ConverterInfo; import org.skriptlang.skript.lang.converter.Converters; @@ -93,8 +93,7 @@ public ConvertedExpression(Expression source, Class to, Collecti } @SafeVarargs - @Nullable - public static ConvertedExpression newInstance(Expression from, Class... to) { + public static @Nullable ConvertedExpression newInstance(Expression from, Class... to) { assert !CollectionUtils.containsSuperclass(to, from.getReturnType()); // we track a list of converters that may work List> converters = new ArrayList<>(); @@ -146,20 +145,17 @@ public boolean isSingle() { } @Override - @Nullable @SuppressWarnings("unchecked") - public Expression getConvertedExpression(Class... to) { + public @Nullable Expression getConvertedExpression(Class... to) { if (CollectionUtils.containsSuperclass(to, this.to)) return (Expression) this; return source.getConvertedExpression(to); } - @Nullable - private ClassInfo returnTypeInfo; + private @Nullable ClassInfo returnTypeInfo; @Override - @Nullable - public Class[] acceptChange(ChangeMode mode) { + public Class @Nullable [] acceptChange(ChangeMode mode) { Class[] validClasses = source.acceptChange(mode); if (validClasses == null) { ClassInfo returnTypeInfo; @@ -171,7 +167,7 @@ public Class[] acceptChange(ChangeMode mode) { } @Override - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { ClassInfo returnTypeInfo = this.returnTypeInfo; if (returnTypeInfo != null) { Changer changer = returnTypeInfo.getChanger(); @@ -183,8 +179,7 @@ public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { } @Override - @Nullable - public T getSingle(Event event) { + public @Nullable T getSingle(Event event) { F value = source.getSingle(event); if (value == null) return null; @@ -243,14 +238,12 @@ public boolean isLoopOf(String input) { } @Override - @Nullable - public Iterator iterator(Event event) { + public @Nullable Iterator iterator(Event event) { Iterator iterator = source.iterator(event); if (iterator == null) return null; - return new Iterator() { - @Nullable - T next = null; + return new Iterator<>() { + @Nullable T next = null; @Override public boolean hasNext() { @@ -295,8 +288,7 @@ public Expression simplify() { } @Override - @Nullable - public Object[] beforeChange(Expression changed, @Nullable Object[] delta) { + public Object @Nullable [] beforeChange(Expression changed, Object @Nullable [] delta) { return source.beforeChange(changed, delta); // Forward to source // TODO this is not entirely safe, even though probably works well enough } diff --git a/src/main/java/ch/njol/skript/lang/util/ConvertedLiteral.java b/src/main/java/ch/njol/skript/lang/util/ConvertedLiteral.java index e404deadcc6..23d8890f924 100644 --- a/src/main/java/ch/njol/skript/lang/util/ConvertedLiteral.java +++ b/src/main/java/ch/njol/skript/lang/util/ConvertedLiteral.java @@ -25,7 +25,7 @@ import ch.njol.util.coll.CollectionUtils; import ch.njol.util.coll.iterator.ArrayIterator; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import org.skriptlang.skript.lang.converter.ConverterInfo; import org.skriptlang.skript.lang.converter.Converters; @@ -46,9 +46,8 @@ public ConvertedLiteral(Literal source, T[] data, Class to) { } @Override - @Nullable @SuppressWarnings("unchecked") - public Literal getConvertedExpression(Class... to) { + public @Nullable Literal getConvertedExpression(Class... to) { if (CollectionUtils.containsSuperclass(to, this.to)) return (Literal) this; return ((Literal) source).getConvertedExpression(to); @@ -87,8 +86,7 @@ public T getSingle(Event event) { } @Override - @Nullable - public Iterator iterator(Event event) { + public @Nullable Iterator iterator(Event event) { return new ArrayIterator<>(data); } diff --git a/src/main/java/ch/njol/skript/lang/util/SimpleEvent.java b/src/main/java/ch/njol/skript/lang/util/SimpleEvent.java index bfaf485f851..b482204af33 100644 --- a/src/main/java/ch/njol/skript/lang/util/SimpleEvent.java +++ b/src/main/java/ch/njol/skript/lang/util/SimpleEvent.java @@ -18,13 +18,12 @@ */ package ch.njol.skript.lang.util; -import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; - import ch.njol.skript.SkriptAPIException; import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptParser.ParseResult; +import org.bukkit.event.Event; +import org.jetbrains.annotations.Nullable; /** * A very basic SkriptEvent which returns true for all events (i.e. all registered events). diff --git a/src/main/java/ch/njol/skript/lang/util/SimpleExpression.java b/src/main/java/ch/njol/skript/lang/util/SimpleExpression.java index daa44c7f9f8..d53af1042fd 100644 --- a/src/main/java/ch/njol/skript/lang/util/SimpleExpression.java +++ b/src/main/java/ch/njol/skript/lang/util/SimpleExpression.java @@ -32,8 +32,8 @@ import ch.njol.util.coll.CollectionUtils; import ch.njol.util.coll.iterator.ArrayIterator; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.skriptlang.skript.lang.converter.Converter; import org.skriptlang.skript.lang.converter.ConverterInfo; @@ -55,8 +55,7 @@ public abstract class SimpleExpression implements Expression { protected SimpleExpression() {} @Override - @Nullable - public final T getSingle(Event event) { + public final @Nullable T getSingle(Event event) { T[] values = getArray(event); if (values.length == 0) return null; @@ -66,10 +65,10 @@ public final T getSingle(Event event) { } @Override - @SuppressWarnings("unchecked") public T[] getAll(Event event) { T[] values = get(event); if (values == null) { + //noinspection unchecked T[] emptyArray = (T[]) Array.newInstance(getReturnType(), 0); assert emptyArray != null; return emptyArray; @@ -82,6 +81,7 @@ public T[] getAll(Event event) { numNonNull++; if (numNonNull == values.length) return Arrays.copyOf(values, values.length); + //noinspection unchecked T[] valueArray = (T[]) Array.newInstance(getReturnType(), numNonNull); assert valueArray != null; int i = 0; @@ -92,10 +92,10 @@ public T[] getAll(Event event) { } @Override - @SuppressWarnings("unchecked") public final T[] getArray(Event event) { T[] values = get(event); if (values == null) { + //noinspection unchecked return (T[]) Array.newInstance(getReturnType(), 0); } if (values.length == 0) @@ -110,6 +110,7 @@ public final T[] getArray(Event event) { if (values.length == 1 && values[0] != null) return Arrays.copyOf(values, 1); int rand = Utils.random(0, numNonNull); + //noinspection unchecked T[] valueArray = (T[]) Array.newInstance(getReturnType(), 1); for (T value : values) { if (value != null) { @@ -125,6 +126,7 @@ public final T[] getArray(Event event) { if (numNonNull == values.length) return Arrays.copyOf(values, values.length); + //noinspection unchecked T[] valueArray = (T[]) Array.newInstance(getReturnType(), numNonNull); int i = 0; for (T value : values) @@ -140,8 +142,7 @@ public final T[] getArray(Event event) { * @param event The event with which this expression is evaluated. * @return An array of values for this event. May not contain nulls. */ - @Nullable - protected abstract T[] get(Event event); + protected abstract T @Nullable [] get(Event event); @Override public final boolean check(Event event, Checker checker) { @@ -154,7 +155,7 @@ public final boolean check(Event event, Checker checker, boolean nega } // TODO return a kleenean (UNKNOWN if 'values' is null or empty) - public static boolean check(@Nullable T[] values, Checker checker, boolean invert, boolean and) { + public static boolean check(T @Nullable [] values, Checker checker, boolean invert, boolean and) { if (values == null) return invert; boolean hasElement = false; @@ -184,8 +185,7 @@ public static boolean check(@Nullable T[] values, Checker checker * @see ConvertedExpression#newInstance(Expression, Class...) * @see Converter */ - @Nullable - protected ConvertedExpression getConvertedExpr(Class... to) { + protected @Nullable ConvertedExpression getConvertedExpr(Class... to) { assert !CollectionUtils.containsSuperclass(to, getReturnType()); return ConvertedExpression.newInstance(this, to); } @@ -200,9 +200,8 @@ public static boolean check(@Nullable T[] values, Checker checker * @return The converted expression */ @Override - @Nullable @SuppressWarnings("unchecked") - public Expression getConvertedExpression(Class... to) { + public @Nullable Expression getConvertedExpression(Class... to) { // check whether this expression is already of type R if (CollectionUtils.containsSuperclass(to, getReturnType())) return (Expression) this; @@ -236,12 +235,10 @@ public Expression getConvertedExpression(Class... to) { return this.getConvertedExpr(to); } - @Nullable - private ClassInfo returnTypeInfo; + private @Nullable ClassInfo returnTypeInfo; @Override - @Nullable - public Class[] acceptChange(ChangeMode mode) { + public Class @Nullable [] acceptChange(ChangeMode mode) { ClassInfo returnTypeInfo = this.returnTypeInfo; if (returnTypeInfo == null) this.returnTypeInfo = returnTypeInfo = Classes.getSuperClassInfo(getReturnType()); @@ -252,14 +249,14 @@ public Class[] acceptChange(ChangeMode mode) { } @Override - @SuppressWarnings("unchecked") - public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { ClassInfo returnTypeInfo = this.returnTypeInfo; if (returnTypeInfo == null) throw new UnsupportedOperationException(); Changer changer = returnTypeInfo.getChanger(); if (changer == null) throw new UnsupportedOperationException(); + //noinspection unchecked ((Changer) changer).change(getArray(event), delta, mode); } @@ -304,7 +301,7 @@ protected final boolean setTime(int time, Class... applicableEv return true; } - protected final boolean setTime(int time, Class applicableEvent, @NonNull Expression... mustbeDefaultVars) { + protected final boolean setTime(int time, Class applicableEvent, @NotNull Expression... mustbeDefaultVars) { if (getParser().getHasDelayBefore() == Kleenean.TRUE && time != 0) { Skript.error("Can't use time states after the event has already passed."); return false; @@ -356,8 +353,7 @@ public boolean isLoopOf(String input) { } @Override - @Nullable - public Iterator iterator(Event event) { + public @Nullable Iterator iterator(Event event) { return new ArrayIterator<>(getArray(event)); } diff --git a/src/main/java/ch/njol/skript/lang/util/SimpleLiteral.java b/src/main/java/ch/njol/skript/lang/util/SimpleLiteral.java index 030db308993..db7ed90f29c 100644 --- a/src/main/java/ch/njol/skript/lang/util/SimpleLiteral.java +++ b/src/main/java/ch/njol/skript/lang/util/SimpleLiteral.java @@ -34,7 +34,7 @@ import ch.njol.util.coll.CollectionUtils; import ch.njol.util.coll.iterator.NonNullIterator; import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import org.skriptlang.skript.lang.converter.Converters; import java.lang.reflect.Array; @@ -52,8 +52,7 @@ public class SimpleLiteral implements Literal, DefaultExpression { private final boolean isDefault; private final boolean and; - @Nullable - private UnparsedLiteral source = null; + private @Nullable UnparsedLiteral source = null; protected transient T[] data; @@ -136,9 +135,8 @@ public Class getReturnType() { } @Override - @Nullable @SuppressWarnings("unchecked") - public Literal getConvertedExpression(Class... to) { + public @Nullable Literal getConvertedExpression(Class... to) { if (CollectionUtils.containsSuperclass(to, type)) return (Literal) this; R[] parsedData = Converters.convert(this.data(), to, (Class) Utils.getSuperType(to)); @@ -183,8 +181,7 @@ public boolean check(Event event, Checker checker) { private ClassInfo returnTypeInfo; @Override - @Nullable - public Class[] acceptChange(ChangeMode mode) { + public Class @Nullable [] acceptChange(ChangeMode mode) { ClassInfo returnTypeInfo = this.returnTypeInfo; if (returnTypeInfo == null) this.returnTypeInfo = returnTypeInfo = Classes.getSuperClassInfo(getReturnType()); @@ -193,7 +190,7 @@ public Class[] acceptChange(ChangeMode mode) { } @Override - public void change(final Event event, final @Nullable Object[] delta, final ChangeMode mode) throws UnsupportedOperationException { + public void change(final Event event, final Object @Nullable [] delta, final ChangeMode mode) throws UnsupportedOperationException { final ClassInfo returnTypeInfo = this.returnTypeInfo; if (returnTypeInfo == null) throw new UnsupportedOperationException(); From 7c6c5cd59425a4f9192a958b58aaad81efc9ea04 Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Wed, 24 Jul 2024 10:57:48 -0700 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Patrick Miller --- src/main/java/ch/njol/skript/lang/SkriptEventInfo.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/njol/skript/lang/SkriptEventInfo.java b/src/main/java/ch/njol/skript/lang/SkriptEventInfo.java index 5bcc8384c1e..78d32c9b023 100644 --- a/src/main/java/ch/njol/skript/lang/SkriptEventInfo.java +++ b/src/main/java/ch/njol/skript/lang/SkriptEventInfo.java @@ -176,15 +176,15 @@ public ListeningBehavior getListeningBehavior() { return listeningBehavior; } - public String @Nullable[] getDescription() { + public String @Nullable [] getDescription() { return description; } - public String @Nullable[] getExamples() { + public String @Nullable [] getExamples() { return examples; } - public String @Nullable[] getKeywords() { + public String @Nullable [] getKeywords() { return keywords; } @@ -192,7 +192,7 @@ public ListeningBehavior getListeningBehavior() { return since; } - public String @Nullable[] getRequiredPlugins() { + public String @Nullable [] getRequiredPlugins() { return requiredPlugins; } From 33ca8f91cbe9cf5162984024eac270ecf2e01af3 Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Wed, 24 Jul 2024 11:00:12 -0700 Subject: [PATCH 3/3] Requested changes --- .../java/ch/njol/skript/classes/data/DefaultFunctions.java | 2 +- src/main/java/ch/njol/skript/lang/SkriptParser.java | 1 - .../java/ch/njol/skript/lang/function/EffFunctionCall.java | 4 ++-- .../java/ch/njol/skript/lang/function/ExprFunctionCall.java | 4 ++-- src/main/java/ch/njol/skript/lang/function/Function.java | 4 ++-- src/main/java/ch/njol/skript/lang/function/JavaFunction.java | 2 +- .../java/ch/njol/skript/lang/function/SimpleJavaFunction.java | 2 +- 7 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java b/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java index b331ca49c32..10baab6fb8c 100644 --- a/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java +++ b/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java @@ -379,7 +379,7 @@ public World[] executeSimple(Object[][] params) { }, DefaultClasses.LOCATION, true) { @Override @Nullable - public Location[] execute(FunctionEvent e, Object[][] params) { + public Location[] execute(FunctionEvent event, Object[][] params) { for (int i : new int[] {0, 1, 2, 4, 5}) { if (params[i] == null || params[i].length == 0 || params[i][0] == null) return null; diff --git a/src/main/java/ch/njol/skript/lang/SkriptParser.java b/src/main/java/ch/njol/skript/lang/SkriptParser.java index 8535879c253..880011b4ca5 100644 --- a/src/main/java/ch/njol/skript/lang/SkriptParser.java +++ b/src/main/java/ch/njol/skript/lang/SkriptParser.java @@ -882,7 +882,6 @@ private SkriptParser suppressMissingAndOrWarnings() { * @param types The required return type or null if it is not used (e.g. when calling a void function) * @return The parsed function, or null if the given expression is not a function call or is an invalid function call (check for an error to differentiate these two) */ - @SuppressWarnings("unchecked") public @Nullable FunctionReference parseFunction(@Nullable Class... types) { if (context != ParseContext.DEFAULT && context != ParseContext.EVENT) diff --git a/src/main/java/ch/njol/skript/lang/function/EffFunctionCall.java b/src/main/java/ch/njol/skript/lang/function/EffFunctionCall.java index 3b52f3bf07e..e9098a70cef 100644 --- a/src/main/java/ch/njol/skript/lang/function/EffFunctionCall.java +++ b/src/main/java/ch/njol/skript/lang/function/EffFunctionCall.java @@ -48,8 +48,8 @@ public static EffFunctionCall parse(final String line) { } @Override - protected void execute(final Event e) { - function.execute(e); + protected void execute(final Event event) { + function.execute(event); function.resetReturnValue(); // Function might have return value that we're ignoring } diff --git a/src/main/java/ch/njol/skript/lang/function/ExprFunctionCall.java b/src/main/java/ch/njol/skript/lang/function/ExprFunctionCall.java index 5028a277fe6..1352788ecfe 100644 --- a/src/main/java/ch/njol/skript/lang/function/ExprFunctionCall.java +++ b/src/main/java/ch/njol/skript/lang/function/ExprFunctionCall.java @@ -55,8 +55,8 @@ public ExprFunctionCall(FunctionReference function, Class[] expe } @Override - protected T @Nullable [] get(Event e) { - Object[] returnValue = function.execute(e); + protected T @Nullable [] get(Event event) { + Object[] returnValue = function.execute(event); function.resetReturnValue(); return Converters.convert(returnValue, returnTypes, returnType); } diff --git a/src/main/java/ch/njol/skript/lang/function/Function.java b/src/main/java/ch/njol/skript/lang/function/Function.java index d7b9893bb14..b358844dea4 100644 --- a/src/main/java/ch/njol/skript/lang/function/Function.java +++ b/src/main/java/ch/njol/skript/lang/function/Function.java @@ -138,13 +138,13 @@ public boolean isSingle() { * Executes this function with given parameters. Usually, using * {@link #execute(Object[][])} is better; it handles optional arguments * and function event creation automatically. - * @param e Associated function event. This is usually created by Skript. + * @param event Associated function event. This is usually created by Skript. * @param params Function parameters. * There must be {@link Signature#getMaxParameters()} amount of them, and * you need to manually handle default values. * @return Function return value(s). */ - public abstract T @Nullable [] execute(FunctionEvent e, Object[][] params); + public abstract T @Nullable [] execute(FunctionEvent event, Object[][] params); /** * Resets the return value of the {@code Function}. diff --git a/src/main/java/ch/njol/skript/lang/function/JavaFunction.java b/src/main/java/ch/njol/skript/lang/function/JavaFunction.java index 877df44ee3e..6806a5b97c8 100644 --- a/src/main/java/ch/njol/skript/lang/function/JavaFunction.java +++ b/src/main/java/ch/njol/skript/lang/function/JavaFunction.java @@ -40,7 +40,7 @@ public JavaFunction(String name, Parameter[] parameters, ClassInfo returnT } @Override - public abstract T @Nullable [] execute(FunctionEvent e, Object[][] params); + public abstract T @Nullable [] execute(FunctionEvent event, Object[][] params); private String @Nullable [] description = null; private String @Nullable [] examples = null; diff --git a/src/main/java/ch/njol/skript/lang/function/SimpleJavaFunction.java b/src/main/java/ch/njol/skript/lang/function/SimpleJavaFunction.java index 5f7d4c7ebb2..b38c169fa81 100644 --- a/src/main/java/ch/njol/skript/lang/function/SimpleJavaFunction.java +++ b/src/main/java/ch/njol/skript/lang/function/SimpleJavaFunction.java @@ -43,7 +43,7 @@ public SimpleJavaFunction(String name, Parameter[] parameters, ClassInfo r } @Override - public final T @Nullable [] execute(FunctionEvent e, Object[][] params) { + public final T @Nullable [] execute(FunctionEvent event, Object[][] params) { for (Object[] param : params) { if (param == null || param.length == 0 || param[0] == null) return null;