33import dev .latvian .mods .rhino .annotations .typing .JSInfo ;
44import dev .latvian .mods .rhino .annotations .typing .JSParams ;
55import lombok .val ;
6+ import net .minecraftforge .api .distmarker .OnlyIn ;
67import zzzank .probejs .features .rhizo .RhizoState ;
78import zzzank .probejs .lang .java .base .AnnotationHolder ;
89import zzzank .probejs .lang .java .clazz .Clazz ;
@@ -30,17 +31,16 @@ public void transformMethod(Clazz clazz, MethodInfo methodInfo, MethodDecl decl)
3031 applyInfo (methodInfo , decl );
3132 applyDeprecated (methodInfo , decl );
3233 applyJSParams (methodInfo , decl .params );
34+ applySideOnly (methodInfo , decl );
3335
3436 if (RhizoState .INFO_ANNOTATION ) {
3537 val paramLines = methodInfo .params .stream ()
3638 .filter (p -> p .hasAnnotation (JSInfo .class ))
3739 .map (p -> String .format ("@param %s - %s" , p .name , p .getAnnotation (JSInfo .class ).value ()))
38- .collect ( Collectors . toList () );
39- if (! paramLines .isEmpty () ) {
40+ .toArray ( String []:: new );
41+ if (paramLines .length != 0 ) {
4042 decl .linebreak ();
41- for (String line : paramLines ) {
42- decl .addComment (line );
43- }
43+ decl .addComment (paramLines );
4444 }
4545 }
4646 }
@@ -49,13 +49,15 @@ public void transformMethod(Clazz clazz, MethodInfo methodInfo, MethodDecl decl)
4949 public void transformField (Clazz clazz , FieldInfo fieldInfo , FieldDecl decl ) {
5050 applyInfo (fieldInfo , decl );
5151 applyDeprecated (fieldInfo , decl );
52+ applySideOnly (fieldInfo , decl );
5253 }
5354
5455 @ Override
5556 public void transformConstructor (Clazz clazz , ConstructorInfo constructorInfo , ConstructorDecl decl ) {
5657 applyInfo (constructorInfo , decl );
5758 applyDeprecated (constructorInfo , decl );
5859 applyJSParams (constructorInfo , decl .params );
60+ applySideOnly (constructorInfo , decl );
5961 }
6062
6163 public void applyDeprecated (AnnotationHolder info , CommentableCode decl ) {
@@ -94,4 +96,19 @@ public void applyJSParams(AnnotationHolder parent, Collection<ParamDecl> params)
9496 }
9597 }
9698 }
99+
100+ public void applySideOnly (AnnotationHolder target , CommentableCode decl ) {
101+ val dist = target .getAnnotationOptional (OnlyIn .class )
102+ .map (OnlyIn ::value )
103+ .orElse (null );
104+ if (dist == null ) {
105+ return ;
106+ }
107+ decl .linebreak ();
108+ if (dist .isClient ()) {
109+ decl .addComment ("Client only, do not use in server scripts" );
110+ } else if (dist .isDedicatedServer ()) {
111+ decl .addComment ("Server only, do not use in client scripts" );
112+ }
113+ }
97114}
0 commit comments