* 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 extends T> stream(Event event) {
Iterator extends T> iterator = iterator(event);
if (iterator == null) {
return Stream.empty();
@@ -178,9 +176,8 @@ default boolean canBeSingle() {
* @see Converter
* @see ConvertedExpression
*/
- @Nullable
@SuppressWarnings("unchecked")
- Expression extends R> getConvertedExpression(Class... to);
+ @Nullable Expression extends R> 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 extends T> iterator(Event event);
+ @Nullable Iterator extends T> 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 extends T>[] 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 extends T> 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 extends T> 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 extends T> expr : expressions)
values.addAll(Arrays.asList(expr.getAll(event)));
+ //noinspection unchecked
return values.toArray((T[]) Array.newInstance(returnType, values.size()));
}
@Override
- @Nullable
- public Iterator extends T> iterator(Event event) {
+ public @Nullable Iterator extends T> iterator(Event event) {
if (!and) {
Expression extends T> expression = CollectionUtils.getRandom(expressions);
return expression != null ? expression.iterator(event) : null;
}
- return new Iterator() {
+ return new Iterator<>() {
private int i = 0;
@Nullable
private Iterator extends T> current = null;
@@ -178,9 +175,8 @@ public boolean check(Event event, Checker super T> checker) {
}
@Override
- @Nullable
@SuppressWarnings("unchecked")
- public Expression extends R> getConvertedExpression(Class... to) {
+ public @Nullable Expression extends R> getConvertedExpression(Class... to) {
Expression extends R>[] 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 extends R> getConvertedExpression(Class... to);
+ @Nullable Literal extends R> 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 extends R> getConvertedExpression(final Class... to) {
+ @SuppressWarnings("unchecked")
+ public @Nullable Literal extends R> getConvertedExpression(final Class... to) {
Literal extends R>[] 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 extends T> parseLiteral(String expr, Class expectedClass, ParseContext context) {
+ public static @Nullable Literal extends T> 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 extends T> parseLiteral(String expr, Class expect
*
* Can print an error.
*/
- @Nullable
- public static T parse(String expr, Iterator extends SyntaxElementInfo> source, @Nullable String defaultError) {
+ public static @Nullable T parse(String expr, Iterator extends SyntaxElementInfo> 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 extends
}
log.printError(defaultError);
return null;
- } finally {
- log.stop();
}
}
- @Nullable
- public static T parseStatic(String expr, Iterator extends SyntaxElementInfo extends T>> source, @Nullable String defaultError) {
+ public static @Nullable T parseStatic(String expr, Iterator extends SyntaxElementInfo extends T>> source, @Nullable String defaultError) {
return parseStatic(expr, source, ParseContext.DEFAULT, defaultError);
}
- @Nullable
- public static T parseStatic(String expr, Iterator extends SyntaxElementInfo extends T>> source, ParseContext parseContext, @Nullable String defaultError) {
+ public static @Nullable T parseStatic(String expr, Iterator extends SyntaxElementInfo extends T>> 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 ex
}
log.printError(defaultError);
return null;
- } finally {
- log.stop();
}
}
- @Nullable
- private T parse(Iterator extends SyntaxElementInfo extends T>> source) {
- ParseLogHandler log = SkriptLogger.startParseLogHandler();
- try {
+ private @Nullable T parse(Iterator extends SyntaxElementInfo extends T>> source) {
+ try (ParseLogHandler log = SkriptLogger.startParseLogHandler()) {
while (source.hasNext()) {
SyntaxElementInfo extends T> info = source.next();
patternsLoop: for (int patternIndex = 0; patternIndex < info.patterns.length; patternIndex++) {
@@ -268,12 +255,10 @@ private T parse(Iterator extends SyntaxElementInfo
}
log.printError();
return null;
- } finally {
- log.stop();
}
}
- private static @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 extends SyntaxElementInfo
/**
* Prints errors
*/
- @Nullable
- private static Variable parseVariable(String expr, Class extends T>[] returnTypes) {
+ private static @Nullable Variable parseVariable(String expr, Class extends T>[] 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 extends T>[] 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 extends T> parseSingleExpr(boolean allowUnparsedLiteral, @Nullable LogEntry error, Class extends T>... types) {
+ @SuppressWarnings({"unchecked"})
+ private @Nullable Expression extends T> parseSingleExpr(boolean allowUnparsedLiteral, @Nullable LogEntry error, Class extends T>... types) {
assert types.length > 0;
assert types.length == 1 || !CollectionUtils.contains(types, Object.class);
if (expr.isEmpty())
@@ -339,8 +322,7 @@ private Expression extends T> 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 extends T> parsedVariable = parseVariable(expr, types);
if (parsedVariable != null) {
@@ -358,6 +340,7 @@ private Expression extends T> 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 extends T> 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 extends T> parseExpression(Class extends T>... types) {
+ public @Nullable Expression extends T> parseExpression(Class extends T>... 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 extends T> parseExpression(Class extends T>... types)
}
}
- @Nullable
- private Expression extends T> parseExpressionList(ParseLogHandler log, Class extends T>... types) {
+ private @Nullable Expression extends T> parseExpressionList(ParseLogHandler log, Class extends T>... types) {
boolean isObject = types.length == 1 && types[0] == Object.class;
List> parsedExpressions = new ArrayList<>();
Kleenean and = Kleenean.UNKNOWN;
@@ -769,14 +744,12 @@ private Expression extends T> 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 extends T>... types) {
+ public @Nullable FunctionReference parseFunction(@Nullable Class extends T>... 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 extends T>... 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