2121import java .util .List ;
2222
2323public class ModuleInfoRequiresParser {
24+ private static final String RUNTIME_KEYWORD = "/*runtime*/" ;
2425
25- public static List <String > parse (String moduleInfoFileContent ) {
26+ public static List <String > parse (String moduleInfoFileContent , boolean runtimeOnly ) {
2627 List <String > requires = new ArrayList <>();
2728 boolean insideComment = false ;
2829 for (String line : moduleInfoFileContent .split ("\n " )) {
29- insideComment = parseLine (line , insideComment , requires );
30+ insideComment = parseLine (line , insideComment , requires , runtimeOnly );
3031 }
3132 return requires ;
3233 }
3334
3435 /**
3536 * @return true, if we are inside a multi-line comment after this line
3637 */
37- private static boolean parseLine (String moduleLine , boolean insideComment , List <String > requires ) {
38+ private static boolean parseLine (String moduleLine , boolean insideComment , List <String > requires , boolean runtimeOnly ) {
3839 if (insideComment ) {
3940 return !moduleLine .contains ("*/" );
4041 }
4142
4243 List <String > tokens = Arrays .asList (moduleLine
4344 .replace (";" , "" )
4445 .replace ("{" , "" )
46+ .replace (RUNTIME_KEYWORD , "runtime" )
4547 .replaceAll ("/\\ *.*?\\ */" , " " )
4648 .trim ().split ("\\ s+" ));
4749 int singleLineCommentStartIndex = tokens .indexOf ("//" );
@@ -50,14 +52,20 @@ private static boolean parseLine(String moduleLine, boolean insideComment, List<
5052 }
5153
5254 if (tokens .size () > 1 && tokens .get (0 ).equals ("requires" )) {
53- if (tokens .size () > 3 && tokens .contains ("static" ) && tokens .contains ("transitive" )) {
54- requires .add (tokens .get (3 ));
55- } else if (tokens .size () > 2 && tokens .contains ("transitive" )) {
56- requires .add (tokens .get (2 ));
57- } else if (tokens .size () > 2 && tokens .contains ("static" )) {
58- requires .add (tokens .get (2 ));
55+ if (runtimeOnly ) {
56+ if (tokens .size () > 2 && tokens .contains ("runtime" )) {
57+ requires .add (tokens .get (2 ));
58+ }
5959 } else {
60- requires .add (tokens .get (1 ));
60+ if (tokens .size () > 3 && tokens .contains ("static" ) && tokens .contains ("transitive" )) {
61+ requires .add (tokens .get (3 ));
62+ } else if (tokens .size () > 2 && tokens .contains ("transitive" )) {
63+ requires .add (tokens .get (2 ));
64+ } else if (tokens .size () > 2 && tokens .contains ("static" )) {
65+ requires .add (tokens .get (2 ));
66+ } else if (!tokens .contains ("runtime" )) {
67+ requires .add (tokens .get (1 ));
68+ }
6169 }
6270 }
6371 return moduleLine .lastIndexOf ("/*" ) > moduleLine .lastIndexOf ("*/" );
0 commit comments