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

Jan Lahoda jlahoda at openjdk.org
Thu Mar 7 08:39:19 UTC 2024


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

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

Commit messages:
 - Updating copyright year.
 - Merge branch 'master' into JDK-8325362
 - Adding test.
 - Merge branch 'master' into JDK-8325362
 - 8325362: Allow to create a simple in-memory input JavaFileObject

Changes: https://git.openjdk.org/jdk/pull/18149/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=18149&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8325362
  Stats: 162 lines in 2 files changed: 162 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/18149.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18149/head:pull/18149

PR: https://git.openjdk.org/jdk/pull/18149


More information about the compiler-dev mailing list