Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 0 additions & 62 deletions src/main/java/ch/njol/skript/effects/EffSuppressTypeHints.java

This file was deleted.

61 changes: 0 additions & 61 deletions src/main/java/ch/njol/skript/effects/EffSuppressWarnings.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.skriptlang.skript.addon.AddonModule;
import org.skriptlang.skript.addon.HierarchicalAddonModule;
import org.skriptlang.skript.addon.SkriptAddon;
import org.skriptlang.skript.common.elements.effects.*;
import org.skriptlang.skript.common.elements.expressions.*;
import org.skriptlang.skript.common.properties.PropertiesModule;
import org.skriptlang.skript.common.types.*;
Expand All @@ -30,6 +31,8 @@ protected void initSelf(SkriptAddon addon) {
@Override
protected void loadSelf(SkriptAddon addon) {
register(addon,
EffSecSuppressTypeHints::register,
EffSecSuppressWarnings::register,
ExprColorFromHexCode::register,
ExprHexCode::register,
ExprRecursiveSize::register,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package org.skriptlang.skript.common.elements.effects;

import ch.njol.skript.config.SectionNode;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Example;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.EffectSection;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.TriggerItem;
import ch.njol.skript.registrations.Feature;
import ch.njol.skript.variables.HintManager;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.experiment.ExperimentData;
import org.skriptlang.skript.lang.experiment.SimpleExperimentalSyntax;
import org.skriptlang.skript.registration.SyntaxInfo;
import org.skriptlang.skript.registration.SyntaxRegistry;

import java.util.List;

@Name("Suppress Type Hints (Experimental)")
@Description("""
An effect to suppress local variable type hint errors for the syntax lines that follow this effect.
NOTE: Suppressing type hints also prevents syntax from providing new type hints. \
For example, with type hints suppressed, 'set {_x} to true' would not provide 'boolean' as a type hint for '{_x}'
""")
@Example("""
start suppressing local variable type hints
# potentially unsafe code goes here
stop suppressing local variable type hints
""")
Comment on lines +30 to +34

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Example("""
start suppressing local variable type hints
# potentially unsafe code goes here
stop suppressing local variable type hints
""")
@Example("""
start suppressing local variable type hints
# potentially unsafe code goes here
stop suppressing local variable type hints
""")

@Since({"2.12", "INSERT VERSION (suppressing in a section)"})
public class EffSecSuppressTypeHints extends EffectSection implements SimpleExperimentalSyntax {

private static final ExperimentData EXPERIMENT_DATA = ExperimentData.createSingularData(Feature.TYPE_HINTS);

public static void register(SyntaxRegistry syntaxRegistry) {
syntaxRegistry.register(SyntaxRegistry.SECTION, SyntaxInfo.simple(EffSecSuppressTypeHints.class, EffSecSuppressTypeHints::new,
"[stop:un]suppress [local variable] type hints",
"(start|:stop) suppressing [local variable] type hints"));
}

private boolean stopSuppression;

@Override
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult,
@Nullable SectionNode sectionNode, @Nullable List<TriggerItem> triggerItems) {
stopSuppression = parseResult.hasTag("stop");
HintManager hintManager = getParser().getHintManager();
boolean wasActive = hintManager.isActive();
hintManager.setActive(stopSuppression);
if (sectionNode != null) {
loadCode(sectionNode);
hintManager.setActive(wasActive);
}
return true;
}

@Override
protected @Nullable TriggerItem walk(Event event) {
return walk(event, true);
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return (stopSuppression ? "stop" : "start") + " suppressing type hints";
}

@Override
public ExperimentData getExperimentData() {
return EXPERIMENT_DATA;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package org.skriptlang.skript.common.elements.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.config.SectionNode;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Example;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.EffectSection;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.TriggerItem;
import ch.njol.skript.lang.parser.ParserInstance;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.script.Script;
import org.skriptlang.skript.lang.script.ScriptWarning;
import org.skriptlang.skript.registration.SyntaxInfo;
import org.skriptlang.skript.registration.SyntaxRegistry;

import java.util.List;

@Name("Locally Suppress Warning")
@Description("Suppresses target warnings from the current script.")
@Example("locally suppress missing conjunction warnings")
@Example("suppress the variable save warnings")
@Since({"2.3", "INSERT VERSION (suppressing in a section)"})
public class EffSecSuppressWarnings extends EffectSection {

public static void register(SyntaxRegistry syntaxRegistry) {
StringBuilder warnings = new StringBuilder();
ScriptWarning[] values = ScriptWarning.values();
for (int i = 0; i < values.length; i++) {
if (i != 0) {
warnings.append('|');
}
warnings.append(values[i].ordinal())
.append(':')
.append(values[i].getPattern());
}
syntaxRegistry.register(SyntaxRegistry.SECTION, SyntaxInfo.simple(EffSecSuppressWarnings.class, EffSecSuppressWarnings::new,
"[local[ly]] [stop:un]suppress [the] (" + warnings + ") warning[s]",
"[start|:stop] [local[ly]] suppressing [the] (" + warnings + ") warning[s]"));
}

private ScriptWarning warning;
private boolean stop;

@Override
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult,
@Nullable SectionNode sectionNode, @Nullable List<TriggerItem> triggerItems) {
ParserInstance parser = getParser();
if (!parser.isActive()) {
Skript.error("You can't suppress warnings outside of a script!");
return false;
}

warning = ScriptWarning.values()[parseResult.mark];
stop = parseResult.hasTag("stop");
if (warning.isDeprecated()) {
Skript.warning(warning.getDeprecationMessage());
}

Script script = parser.getCurrentScript();
boolean wasSuppressed = script.suppressesWarning(warning);
if (stop) {
script.allowWarning(warning);
} else {
script.suppressWarning(warning);
}
if (sectionNode != null) {
loadCode(sectionNode);
if (wasSuppressed) {
script.suppressWarning(warning);
} else {
script.allowWarning(warning);
}
}

return true;
}

@Override
protected @Nullable TriggerItem walk(Event event) {
return walk(event, true);
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return (stop ? "un" : "") + "suppress " + warning.getWarningName() + " warnings";
}

}
29 changes: 29 additions & 0 deletions src/test/skript/tests/common/EffSuppressWarnings.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
test "EffSuppressWarnings":

parse:
stop
stop
assert last parse logs is "Unreachable code. The previous statement stops further execution."

suppress unreachable code warnings
parse:
stop
stop
assert last parse logs is not set
unsuppress unreachable code warnings

parse:
stop
stop
assert last parse logs is "Unreachable code. The previous statement stops further execution."

suppress unreachable code warnings:
parse:
stop
stop
assert last parse logs is not set

parse:
stop
stop
assert last parse logs is "Unreachable code. The previous statement stops further execution."
5 changes: 2 additions & 3 deletions src/test/skript/tests/misc/type hints.sk
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ test "type hints":
set {_a} to {_x} in lowercase
unsuppress local variable type hints
set {_x} to 10
suppress local variable type hints
set {_a} to {_x} in lowercase
unsuppress local variable type hints
suppress local variable type hints:
set {_a} to {_x} in lowercase
assert last parse logs is not set with "last parse logs is set (%last parse logs%)"
delete {_x}

Expand Down
Loading