11/*
2- * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
@@ -107,11 +107,12 @@ public abstract class API {
107107 * @param ak the access kind, to filter the set of elements to be compared according
108108 * their declared access
109109 * @param log a log, to which any problems will be reported
110+ * @param verboseOptions whether to be verbose about internal opton details
110111 *
111112 * @return the API
112113 */
113- public static API of (APIOptions opts , Selector s , AccessKind ak , Log log ) {
114- return new JavacAPI (opts , s , ak , log );
114+ public static API of (APIOptions opts , Selector s , AccessKind ak , Log log , boolean verboseOptions ) {
115+ return new JavacAPI (opts , s , ak , log , verboseOptions );
115116 }
116117
117118 /**
@@ -145,20 +146,26 @@ public static API of(APIOptions opts, Selector s, AccessKind ak, Log log) {
145146 */
146147 protected final StandardJavaFileManager fileManager ;
147148
149+ /**
150+ * Whether to be verbose about internal option details.
151+ */
152+ protected final boolean verboseOptions ;
153+
148154 /**
149155 * Creates an instance of an API.
150156 *
151157 * @param opts the options for the API
152158 * @param s the selector for the elements to be compared
153159 * @param ak the access kind for the elements to be compared
154- * @param log the log, to which any any problems will be reported
160+ * @param log the log, to which any problems will be reported
155161 */
156- protected API (APIOptions opts , Selector s , AccessKind ak , Log log ) {
162+ protected API (APIOptions opts , Selector s , AccessKind ak , Log log , boolean verboseOptions ) {
157163 this .name = opts .name ;
158164 this .label = opts .label ;
159165 this .selector = s ;
160166 this .accessKind = ak ;
161167 this .log = log ;
168+ this .verboseOptions = verboseOptions ;
162169
163170 fileManager = compiler .getStandardFileManager (null , null , null );
164171 }
@@ -339,6 +346,7 @@ public abstract List<JavaFileObject> listFiles(LocationKind kind, Element e, Str
339346
340347 static class JavacAPI extends API {
341348 private List <String > javacOpts ;
349+ private List <String > fmOpts ; // just for verbose reporting
342350 private int platformVersion ;
343351 private Elements elements ;
344352 private Types types ;
@@ -352,7 +360,7 @@ static class JavacAPI extends API {
352360 /**
353361 * A tuple containing a location and the kinds of files that may be read from that location.
354362 */
355- private class LocationAndKinds {
363+ private static class LocationAndKinds {
356364 final Location locn ;
357365 final Set <JavaFileObject .Kind > kinds ;
358366 LocationAndKinds (Location locn , Set <JavaFileObject .Kind > kinds ) {
@@ -381,13 +389,16 @@ protected boolean removeEldestEntry(Map.Entry<Path,APIDocs> eldest) {
381389 }
382390 };
383391
384- JavacAPI (APIOptions opts , Selector s , AccessKind ak , Log log ) {
385- super (opts , s , ak , log );
392+ JavacAPI (APIOptions opts , Selector s , AccessKind ak , Log log , boolean verboseOptions ) {
393+ super (opts , s , ak , log , verboseOptions );
386394
395+ fmOpts = new ArrayList <>();
387396 for (Map .Entry <String , List <String >> e : opts .fileManagerOpts .entrySet ()) {
388397 String opt = e .getKey ();
398+ fmOpts .add (opt );
389399 List <String > args = e .getValue ();
390400 for (String arg : args ) {
401+ fmOpts .add (arg );
391402 Iterator <String > argIter = arg == null
392403 ? Collections .emptyIterator ()
393404 : Collections .singleton (arg ).iterator ();
@@ -441,6 +452,9 @@ void initJavac(Set<String> selectedModules) {
441452 javacOpts .add (String .join ("," , selectedModules ));
442453 }
443454 javacOpts .add ("-proc:only" );
455+ if (verboseOptions ) {
456+ showJavacOptions ();
457+ }
444458 JavacTask javacTask = (JavacTask ) compiler .getTask (log .err , fileManager , this ::reportDiagnostic , javacOpts , null , null );
445459 elements = javacTask .getElements ();
446460 elements .getModuleElement ("java.base" ); // forces module graph to be instantiated, etc
@@ -465,6 +479,32 @@ public SerializedFormDocs getSerializedFormDocs(TypeElement te) {
465479 };
466480 }
467481
482+ private void showJavacOptions () {
483+ log .err .println ("Effective javac options for API " + name );
484+ boolean needNewline = false ;
485+ // The following is a convenient fiction: to report all the javac options as "equivalent".
486+ // In reality, the file manager options have already been handled separately and are
487+ // now stashed in the file manager, without easy access (except via Locations).
488+ List <String > allOpts = new ArrayList <>();
489+ allOpts .addAll (fmOpts );
490+ allOpts .addAll (javacOpts );
491+ for (String opt : allOpts ) {
492+ if (opt .startsWith ("-" )) {
493+ if (needNewline ) {
494+ log .err .println ();
495+ }
496+ log .err .print (" " );
497+ } else {
498+ log .err .print (" " );
499+ }
500+ log .err .print (opt );
501+ needNewline = true ;
502+ }
503+ if (needNewline ) {
504+ log .err .println ();
505+ }
506+ }
507+
468508 @ Override
469509 public Set <PackageElement > getPackageElements () {
470510 if (packages == null ) {
@@ -566,7 +606,7 @@ public Set<PackageElement> getExportedPackageElements(ModuleElement m) {
566606 .filter (d -> d .getKind () == ModuleElement .DirectiveKind .EXPORTS )
567607 .map (d -> (ModuleElement .ExportsDirective ) d )
568608 .filter (d -> d .getTargetModules () == null )
569- .map (d -> d . getPackage () )
609+ .map (ModuleElement . ExportsDirective :: getPackage )
570610 .collect (Collectors .toSet ());
571611
572612 return getPackageElements (m ).stream ()
@@ -1070,7 +1110,7 @@ public Void visitPrimitive(PrimitiveType t, StringBuilder sb) {
10701110
10711111 @ Override
10721112 public Void visitNull (NullType t , StringBuilder sb ) {
1073- throw new IllegalArgumentException (t .getKind () + " " + t . toString () );
1113+ throw new IllegalArgumentException (t .getKind () + " " + t );
10741114 }
10751115
10761116 @ Override
0 commit comments