Skip to content

Commit c085bd0

Browse files
committed
Merge branch 'state-removal'
2 parents 5c16eed + e49e1af commit c085bd0

File tree

127 files changed

+1703
-1707
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+1703
-1707
lines changed

src/main/java/org/byteskript/skript/api/DataStore.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ public interface DataStore {
1010

1111
<Thing> Thing retrieve(String identifier, Class<Thing> type);
1212

13-
void store(String identifier, Object thing, Class<?> type);
14-
1513
default void store(String identifier, Object thing) {
1614
if (thing == null) store(identifier, null, void.class);
1715
else store(identifier, thing, thing.getClass());
1816
}
1917

18+
void store(String identifier, Object thing, Class<?> type);
19+
2020
}

src/main/java/org/byteskript/skript/api/Library.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ public interface Library {
2323

2424
Collection<PropertyHandler> getProperties();
2525

26-
SyntaxElement[] getSyntax();
27-
2826
LanguageElement[] getConstructs();
2927

3028
Type[] getTypes();
@@ -42,4 +40,6 @@ default Document[] generateDocumentation() {
4240
return documents.toArray(new Document[0]);
4341
}
4442

43+
SyntaxElement[] getSyntax();
44+
4545
}

src/main/java/org/byteskript/skript/api/ModifiableLibrary.java

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,49 +33,48 @@ public void registerSyntax(State state, SyntaxElement... elements) {
3333
}
3434
}
3535

36-
public void registerSyntax(State state, SyntaxElement element) {
37-
this.syntax.putIfAbsent(state, new ArrayList<>());
38-
this.syntax.get(state).add(element);
39-
}
40-
41-
4236
public void registerEvents(EventHolder... events) {
4337
for (EventHolder event : events) {
4438
this.registerEvent(event);
4539
}
4640
}
4741

48-
public void registerEvent(EventHolder event) {
49-
this.registerSyntax(CompileState.ROOT, event);
50-
this.registerValues(event);
51-
}
52-
5342
public void registerProperty(PropertyHandler handler) {
5443
this.properties.add(handler);
5544
}
5645

57-
public void registerProperty(String name, HandlerType type, Method handler) {
58-
this.properties.add(new PropertyHandler(type, handler, name));
59-
}
60-
6146
public void registerTypes(Class<?>... classes) {
6247
for (Class<?> aClass : classes) {
6348
this.registerType(aClass);
6449
}
6550
}
6651

67-
public void registerTypes(Type... types) {
68-
for (Type type : types) {
69-
if (!this.types.contains(type)) this.types.add(type);
70-
}
71-
}
72-
7352
public Type registerType(Class<?> cls) {
7453
final Type type = new Type(cls);
7554
if (!types.contains(type)) this.types.add(type);
7655
return type;
7756
}
7857

58+
public void registerSyntax(State state, SyntaxElement element) {
59+
this.syntax.putIfAbsent(state, new ArrayList<>());
60+
this.syntax.get(state).add(element);
61+
}
62+
63+
public void registerEvent(EventHolder event) {
64+
this.registerSyntax(CompileState.ROOT, event);
65+
this.registerValues(event);
66+
}
67+
68+
public void registerProperty(String name, HandlerType type, Method handler) {
69+
this.properties.add(new PropertyHandler(type, handler, name));
70+
}
71+
72+
public void registerTypes(Type... types) {
73+
for (Type type : types) {
74+
if (!this.types.contains(type)) this.types.add(type);
75+
}
76+
}
77+
7978
public Type registerType(String classPath) {
8079
final Type type = new Type(classPath);
8180
if (!types.contains(type)) this.types.add(type);
@@ -103,15 +102,6 @@ public Collection<PropertyHandler> getProperties() {
103102
return properties;
104103
}
105104

106-
@Override
107-
public SyntaxElement[] getSyntax() {
108-
final List<SyntaxElement> elements = new ArrayList<>();
109-
for (List<SyntaxElement> value : syntax.values()) {
110-
elements.addAll(value);
111-
}
112-
return elements.toArray(new SyntaxElement[0]);
113-
}
114-
115105
@Override
116106
public LanguageElement[] getConstructs() {
117107
return new LanguageElement[0];
@@ -126,4 +116,13 @@ public Type[] getTypes() {
126116
public Collection<PostCompileClass> getRuntime() {
127117
return Collections.emptyList();
128118
}
119+
120+
@Override
121+
public SyntaxElement[] getSyntax() {
122+
final List<SyntaxElement> elements = new ArrayList<>();
123+
for (List<SyntaxElement> value : syntax.values()) {
124+
elements.addAll(value);
125+
}
126+
return elements.toArray(new SyntaxElement[0]);
127+
}
129128
}

src/main/java/org/byteskript/skript/api/PropertyHandler.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@ public PropertyHandler(HandlerType type, Method method, String name) {
1717
this(name, type, createHolder(method), createValue(type, method), method);
1818
}
1919

20-
private static Type createValue(HandlerType type, Method method) {
21-
if (type.expectInputs()) {
20+
private static Type createHolder(Method method) {
21+
if (Modifier.isStatic(method.getModifiers())) {
2222
final Class<?>[] classes = method.getParameterTypes();
2323
assert classes.length > 0;
24-
return new Type(classes[classes.length - 1]);
25-
} else if (type.expectReturn()) {
26-
return new Type(method.getReturnType());
24+
return new Type(classes[0]);
2725
} else {
28-
return new Type(void.class);
26+
return new Type(method.getDeclaringClass());
2927
}
3028
}
3129

32-
private static Type createHolder(Method method) {
33-
if (Modifier.isStatic(method.getModifiers())) {
30+
private static Type createValue(HandlerType type, Method method) {
31+
if (type.expectInputs()) {
3432
final Class<?>[] classes = method.getParameterTypes();
3533
assert classes.length > 0;
36-
return new Type(classes[0]);
34+
return new Type(classes[classes.length - 1]);
35+
} else if (type.expectReturn()) {
36+
return new Type(method.getReturnType());
3737
} else {
38-
return new Type(method.getDeclaringClass());
38+
return new Type(void.class);
3939
}
4040
}
4141

src/main/java/org/byteskript/skript/api/SyntaxAnnotationUnwrapper.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ default void generateSyntaxFrom(Class<?> owner) {
7474
}
7575
}
7676

77+
Type registerType(Class<?> cls);
78+
79+
void registerEvent(EventHolder event);
80+
81+
void registerSyntax(State state, SyntaxElement element);
82+
83+
void registerProperty(String name, HandlerType type, Method handler);
84+
7785
default void registerValues(EventHolder event) {
7886
for (Method method : event.eventClass().getMethods()) {
7987
final EventValue value = method.getAnnotation(EventValue.class);
@@ -87,12 +95,4 @@ default void registerValues(EventHolder event) {
8795
}
8896
}
8997
}
90-
91-
Type registerType(Class<?> cls);
92-
93-
void registerSyntax(State state, SyntaxElement element);
94-
95-
void registerEvent(EventHolder event);
96-
97-
void registerProperty(String name, HandlerType type, Method handler);
9898
}

src/main/java/org/byteskript/skript/api/SyntaxElement.java

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,42 +27,14 @@
2727

2828
public interface SyntaxElement {
2929

30-
Pattern getPattern();
31-
3230
default Pattern.Match match(String thing, Context context) {
3331
return getPattern().match(thing, context);
3432
}
3533

36-
String[] getPatterns();
34+
Pattern getPattern();
3735

3836
Library getProvider();
3937

40-
LanguageElement getType();
41-
42-
default Type getReturnType() {
43-
return CommonTypes.VOID;
44-
}
45-
46-
default String name() {
47-
final Documentation documentation = this.getClass().getAnnotation(Documentation.class);
48-
if (documentation == null) return getPattern().name();
49-
return documentation.name();
50-
}
51-
52-
default String description() {
53-
final Documentation documentation = this.getClass().getAnnotation(Documentation.class);
54-
if (documentation == null) return "None.";
55-
return documentation.description();
56-
}
57-
58-
default String[] examples() {
59-
final Documentation documentation = this.getClass().getAnnotation(Documentation.class);
60-
if (documentation == null) return new String[0];
61-
return documentation.examples();
62-
}
63-
64-
boolean hasHandler(HandlerType type);
65-
6638
Method getHandler(HandlerType type);
6739

6840
void setHandler(HandlerType type, Method method);
@@ -86,6 +58,12 @@ default boolean allowAsInputFor(Type type) {
8658
return type.equals(CommonTypes.OBJECT) || type.equals(getReturnType());
8759
}
8860

61+
boolean hasHandler(HandlerType type);
62+
63+
default Type getReturnType() {
64+
return CommonTypes.VOID;
65+
}
66+
8967
default void preCompile(Context context, Pattern.Match match) throws Throwable {
9068
// Very few elements require a lookahead.
9169
}
@@ -96,12 +74,6 @@ default boolean allowedIn(State state, Context context) {
9674
return true;
9775
}
9876

99-
class Handlers extends HashMap<HandlerType, Method> {
100-
101-
public static final Handlers EMPTY = new Handlers();
102-
103-
}
104-
10577
default boolean isDelay() {
10678
return false;
10779
}
@@ -184,4 +156,32 @@ default Document createDocument() {
184156
return new Document(name(), getType().name(), getPatterns(), description(), examples());
185157
}
186158

159+
default String name() {
160+
final Documentation documentation = this.getClass().getAnnotation(Documentation.class);
161+
if (documentation == null) return getPattern().name();
162+
return documentation.name();
163+
}
164+
165+
LanguageElement getType();
166+
167+
String[] getPatterns();
168+
169+
default String description() {
170+
final Documentation documentation = this.getClass().getAnnotation(Documentation.class);
171+
if (documentation == null) return "None.";
172+
return documentation.description();
173+
}
174+
175+
default String[] examples() {
176+
final Documentation documentation = this.getClass().getAnnotation(Documentation.class);
177+
if (documentation == null) return new String[0];
178+
return documentation.examples();
179+
}
180+
181+
class Handlers extends HashMap<HandlerType, Method> {
182+
183+
public static final Handlers EMPTY = new Handlers();
184+
185+
}
186+
187187
}

src/main/java/org/byteskript/skript/api/automatic/GeneratedEntryNode.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ public GeneratedEntryNode(Library provider, final RecordComponent target, String
2828
this.target = target;
2929
}
3030

31-
@Override
32-
public boolean allowedIn(State state, Context context) {
33-
return super.allowedIn(state, context)
34-
&& context.getSection().handler() instanceof GeneratedEntrySection section
35-
&& section.getTarget() == target.getDeclaringRecord();
36-
}
37-
3831
@Override
3932
public void preCompile(Context context, Pattern.Match match) throws Throwable {
4033
final ElementTree tree = context.getCompileCurrent().nested()[0];
@@ -55,4 +48,11 @@ public void compile(Context context, Pattern.Match match) throws Throwable {
5548
context.setState(CompileState.AREA_BODY);
5649
}
5750

51+
@Override
52+
public boolean allowedIn(State state, Context context) {
53+
return super.allowedIn(state, context)
54+
&& context.getSection().handler() instanceof GeneratedEntrySection section
55+
&& section.getTarget() == target.getDeclaringRecord();
56+
}
57+
5858
}

src/main/java/org/byteskript/skript/api/automatic/GeneratedExpression.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public GeneratedExpression(Library provider, final Method target, String... patt
2828
this.value = new Type(target.getReturnType());
2929
}
3030

31+
@Override
32+
public Type getReturnType() {
33+
return value;
34+
}
35+
3136
@Override
3237
public void compile(Context context, Pattern.Match match) throws Throwable {
3338
final MethodBuilder method = context.getMethod();
@@ -36,9 +41,4 @@ public void compile(Context context, Pattern.Match match) throws Throwable {
3641
context.setState(CompileState.STATEMENT);
3742
}
3843

39-
@Override
40-
public Type getReturnType() {
41-
return value;
42-
}
43-
4444
}

src/main/java/org/byteskript/skript/api/syntax/Effect.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public CompileState getSubState() {
3131
return CompileState.STATEMENT; // looking for expressions here
3232
}
3333

34+
@Override
35+
public boolean allowAsInputFor(Type type) {
36+
return true; // support meta-effects
37+
}
38+
3439
@Override
3540
public void preCompile(Context context, Pattern.Match match) throws Throwable {
3641
final Method target = handlers.get(StandardHandlers.RUN);
@@ -54,9 +59,4 @@ public boolean allowedIn(State state, Context context) {
5459
return state == CompileState.CODE_BODY && context.hasCurrentUnit();
5560
}
5661

57-
@Override
58-
public boolean allowAsInputFor(Type type) {
59-
return true; // support meta-effects
60-
}
61-
6262
}

src/main/java/org/byteskript/skript/api/syntax/Element.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
public abstract class Element implements SyntaxElement {
1919

20-
private final Pattern pattern;
2120
protected final Library provider;
2221
protected final LanguageElement type;
2322
protected final Handlers handlers = new Handlers();
23+
private final Pattern pattern;
2424

2525
public Element(final Library provider, final LanguageElement type, final String... patterns) {
2626
this.pattern = new Pattern(Arrays.copyOf(patterns, patterns.length), provider);
@@ -53,13 +53,13 @@ public boolean hasHandler(HandlerType type) {
5353
}
5454

5555
@Override
56-
public void setHandler(HandlerType type, Method method) {
57-
this.handlers.put(type, method);
56+
public Method getHandler(HandlerType type) {
57+
return handlers.get(type);
5858
}
5959

6060
@Override
61-
public Method getHandler(HandlerType type) {
62-
return handlers.get(type);
61+
public void setHandler(HandlerType type, Method method) {
62+
this.handlers.put(type, method);
6363
}
6464

6565
}

0 commit comments

Comments
 (0)