File tree 11 files changed +183
-0
lines changed
src/main/java/com/relogiclabs/jschema/extension
11 files changed +183
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .relogiclabs .jschema .extension ;
2
+
3
+ import com .relogiclabs .jschema .tree .RuntimeContext ;
4
+ import lombok .Getter ;
5
+ import lombok .Setter ;
6
+
7
+ import java .lang .reflect .Method ;
8
+
9
+ @ Getter @ Setter
10
+ public abstract class AbstractExtension implements InvokableNative {
11
+ private RuntimeContext runtime ;
12
+ private Method method ;
13
+
14
+ public String getOutline (Object object ) {
15
+ return getRuntime ().getOutlineFormatter ().getOutline (object );
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ package com .relogiclabs .jschema .extension ;
2
+
3
+ import com .relogiclabs .jschema .node .JNode ;
4
+ import lombok .Getter ;
5
+ import lombok .Setter ;
6
+
7
+ @ Getter @ Setter
8
+ public class ConstraintExtension extends AbstractExtension implements ConstraintFunctions {
9
+ private JNode invoker ;
10
+
11
+ public <T extends JNode > T getInvoker (Class <T > type ) {
12
+ return type .cast (invoker );
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ package com .relogiclabs .jschema .extension ;
2
+
3
+ import java .lang .annotation .Documented ;
4
+ import java .lang .annotation .ElementType ;
5
+ import java .lang .annotation .Retention ;
6
+ import java .lang .annotation .RetentionPolicy ;
7
+ import java .lang .annotation .Target ;
8
+
9
+ @ Retention (RetentionPolicy .RUNTIME )
10
+ @ Target (ElementType .METHOD )
11
+ @ Documented
12
+ // To use this, interface ConstraintFunctions must be implemented
13
+ public @interface ConstraintFunction {
14
+ String [] value () default {};
15
+ }
Original file line number Diff line number Diff line change
1
+ package com .relogiclabs .jschema .extension ;
2
+
3
+ import com .relogiclabs .jschema .node .JNode ;
4
+ import com .relogiclabs .jschema .tree .RuntimeContext ;
5
+
6
+ public interface ConstraintFunctions extends InvokableNative {
7
+ void setRuntime (RuntimeContext runtime );
8
+ JNode getInvoker ();
9
+ void setInvoker (JNode invoker );
10
+
11
+ default void setContext (ConstraintFunctions context ) {
12
+ setInvoker (context .getInvoker ());
13
+ setRuntime (context .getRuntime ());
14
+ setMethod (context .getMethod ());
15
+ }
16
+
17
+ default boolean fail (RuntimeException exception ) {
18
+ return getRuntime ().getExceptions ().fail (exception );
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ package com .relogiclabs .jschema .extension ;
2
+
3
+ import com .relogiclabs .jschema .node .JNode ;
4
+ import lombok .Getter ;
5
+ import lombok .Setter ;
6
+
7
+ @ Getter @ Setter
8
+ public class GeneralExtension extends ScriptExtension implements ConstraintFunctions {
9
+ private JNode invoker ;
10
+
11
+ public <T extends JNode > T getInvoker (Class <T > type ) {
12
+ return type .cast (invoker );
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ package com .relogiclabs .jschema .extension ;
2
+
3
+ import com .relogiclabs .jschema .tree .RuntimeContext ;
4
+
5
+ import java .lang .reflect .Method ;
6
+
7
+ public interface InvokableNative {
8
+ RuntimeContext getRuntime ();
9
+ Method getMethod ();
10
+ void setMethod (Method method );
11
+ }
Original file line number Diff line number Diff line change
1
+ package com .relogiclabs .jschema .extension ;
2
+
3
+ import com .relogiclabs .jschema .internal .engine .ScriptScope ;
4
+ import com .relogiclabs .jschema .tree .RuntimeContext ;
5
+ import com .relogiclabs .jschema .type .EValue ;
6
+ import lombok .Getter ;
7
+ import lombok .Setter ;
8
+
9
+ @ Setter @ Getter
10
+ public class ScriptExtension extends AbstractExtension implements ScriptFunctions , ScriptMethods {
11
+ private ScriptScope scope ;
12
+ private EValue self ;
13
+
14
+ @ Override
15
+ public void setScope (ScriptScope scope ) {
16
+ this .scope = scope ;
17
+ setRuntime (null );
18
+ }
19
+
20
+ @ Override
21
+ public RuntimeContext getRuntime () {
22
+ var runtime = super .getRuntime ();
23
+ if (runtime != null ) return runtime ;
24
+ setRuntime (runtime = scope .getRuntime ());
25
+ return runtime ;
26
+ }
27
+
28
+ public <T extends EValue > T getSelf (Class <T > type ) {
29
+ return type .cast (self );
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ package com .relogiclabs .jschema .extension ;
2
+
3
+ import java .lang .annotation .Documented ;
4
+ import java .lang .annotation .ElementType ;
5
+ import java .lang .annotation .Retention ;
6
+ import java .lang .annotation .RetentionPolicy ;
7
+ import java .lang .annotation .Target ;
8
+
9
+ @ Retention (RetentionPolicy .RUNTIME )
10
+ @ Target (ElementType .METHOD )
11
+ @ Documented
12
+ // To use this, interface ScriptFunctions must be implemented
13
+ public @interface ScriptFunction {
14
+ String [] value () default {};
15
+ }
Original file line number Diff line number Diff line change
1
+ package com .relogiclabs .jschema .extension ;
2
+
3
+ import com .relogiclabs .jschema .internal .engine .ScriptScope ;
4
+
5
+ public interface ScriptFunctions extends InvokableNative {
6
+ ScriptScope getScope ();
7
+ void setScope (ScriptScope scope );
8
+
9
+ default void setContext (ScriptFunctions context ) {
10
+ setScope (context .getScope ());
11
+ setMethod (context .getMethod ());
12
+ }
13
+ }
Original file line number Diff line number Diff line change
1
+ package com .relogiclabs .jschema .extension ;
2
+
3
+ import com .relogiclabs .jschema .type .EType ;
4
+
5
+ import java .lang .annotation .Documented ;
6
+ import java .lang .annotation .ElementType ;
7
+ import java .lang .annotation .Retention ;
8
+ import java .lang .annotation .RetentionPolicy ;
9
+ import java .lang .annotation .Target ;
10
+
11
+ @ Retention (RetentionPolicy .RUNTIME )
12
+ @ Target (ElementType .METHOD )
13
+ @ Documented
14
+ // To use this, interface ScriptMethods must be implemented
15
+ public @interface ScriptMethod {
16
+ EType [] value () default {}; // alias of types
17
+ String [] names () default {};
18
+ EType [] types () default {};
19
+ }
Original file line number Diff line number Diff line change
1
+ package com .relogiclabs .jschema .extension ;
2
+
3
+ import com .relogiclabs .jschema .type .EValue ;
4
+
5
+ public interface ScriptMethods extends ScriptFunctions {
6
+ EValue getSelf ();
7
+ void setSelf (EValue self );
8
+
9
+ default void setContext (ScriptMethods context ) {
10
+ setSelf (context .getSelf ());
11
+ setScope (context .getScope ());
12
+ setMethod (context .getMethod ());
13
+ }
14
+ }
You can’t perform that action at this time.
0 commit comments