RFR: 8325362: Allow to create a simple in-memory input JavaFileObject

Jaikiran Pai jpai at openjdk.org
Thu Mar 7 10:55:56 UTC 2024


On Thu, 7 Mar 2024 08:34:32 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> There are many subtypes of `SimpleJavaFileObject` scattered through various codebases, majority of them looking like:
> 
> 
>     private static class JavaSource extends SimpleJavaFileObject {
> 
>         private String code;
> 
>         public JavaSource(String code) {
>             super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
>             this.code = code;
>         }
> 
>         @Override
>         public CharSequence getCharContent(boolean ignoreEncodingErrors) {
>             return code;
>         }
>     }
> 
> 
> The proposal herein is a to add a factory method that would return an implementation of `SimpleJavaFileObject` based on the provided `URI` and source content.
> 
> The CSR for this change is available for review here:
> https://bugs.openjdk.org/browse/JDK-8327536

src/java.compiler/share/classes/javax/tools/SimpleJavaFileObject.java line 237:

> 235:      * if the constructor is called with {@code uri} and {@code Kind.SOURCE}.
> 236:      *
> 237:      * @param uri that should be used for this {@code JavaFileObject}

I realize this is a static method, but the use of "this" might mean to imply the current instance on which the method is invoked. Perhaps, we should change it to `that should be used by the returned {@code JavaFileObject}` ? Or maybe just replace "this" with "the"?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/18149#discussion_r1515954825


More information about the compiler-dev mailing list