diff options
author | Gunhyeong Kim <gunhyeong@google.com> | 2018-08-20 11:08:51 +0900 |
---|---|---|
committer | Gunhyeong Kim <gunhyeong@google.com> | 2018-08-21 10:48:07 +0900 |
commit | 10b8316939399b94b847a1768c41234ff6974125 (patch) | |
tree | cda61b6bbc34fd0c387bfe5d95b078da1ba1a1e7 /tests/src | |
parent | 8e169cf9241a2ef7eaec3a13307be1576ae98658 (diff) | |
download | xsdc-10b8316939399b94b847a1768c41234ff6974125.tar.gz |
Create class for code prettifying
It uses class CodeWriter for printing Java codes.
This removes hard indenting in code output.
Bug: 112397805
Test: 'm -j xsdc', 'm -j xsdc-tests'
Change-Id: I5320340ba9d76c1a446548b1f86d99fde65c9a32
Diffstat (limited to 'tests/src')
-rw-r--r-- | tests/src/com/android/xsdc/tests/TestHelper.java | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/tests/src/com/android/xsdc/tests/TestHelper.java b/tests/src/com/android/xsdc/tests/TestHelper.java index 4dd48a7..467e849 100644 --- a/tests/src/com/android/xsdc/tests/TestHelper.java +++ b/tests/src/com/android/xsdc/tests/TestHelper.java @@ -1,5 +1,6 @@ package com.android.xsdc.tests; +import com.android.xsdc.CodeWriter; import com.android.xsdc.XmlSchema; import com.android.xsdc.XsdHandler; import com.android.xsdc.descriptor.ClassDescriptor; @@ -22,7 +23,8 @@ class TestHelper { private final String contents; InMemoryJavaFileObject(String className, String contents) { - super(URI.create("string:///" + className.replace('.', '/') + Kind.SOURCE.extension), Kind.SOURCE); + super(URI.create("string:///" + className.replace('.', '/') + Kind.SOURCE.extension), + Kind.SOURCE); this.contents = contents; } @@ -65,7 +67,8 @@ class TestHelper { } @Override - public JavaFileObject getJavaFileForOutput(Location location, String name, JavaFileObject.Kind kind, FileObject sibling) { + public JavaFileObject getJavaFileForOutput(Location location, String name, + JavaFileObject.Kind kind, FileObject sibling) { InMemoryJavaClassObject object = new InMemoryJavaClassObject(name, kind); classObjects.add(object); return object; @@ -89,23 +92,27 @@ class TestHelper { SchemaDescriptor schemaDescriptor = schema.explain(); for (ClassDescriptor descriptor : schemaDescriptor.getClassDescriptorMap().values()) { StringWriter codeOutput = new StringWriter(); - descriptor.print(packageName, new PrintWriter(codeOutput)); - javaFileObjects.add(new InMemoryJavaFileObject(descriptor.getName(), codeOutput.toString())); + descriptor.print(packageName, new CodeWriter(new PrintWriter(codeOutput))); + javaFileObjects.add( + new InMemoryJavaFileObject(descriptor.getName(), codeOutput.toString())); } StringWriter codeOutput = new StringWriter(); - schemaDescriptor.printXmlParser(packageName, new PrintWriter(codeOutput)); + schemaDescriptor.printXmlParser(packageName, new CodeWriter(new PrintWriter(codeOutput))); javaFileObjects.add(new InMemoryJavaFileObject("XmlParser", codeOutput.toString())); return new TestCompilationResult(compile(javaFileObjects)); } - private static List<InMemoryJavaClassObject> compile(List<JavaFileObject> javaFileObjects) throws IOException { + private static List<InMemoryJavaClassObject> compile(List<JavaFileObject> javaFileObjects) + throws IOException { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>(); List<InMemoryJavaClassObject> ret = null; - try (InMemoryClassManager fileManager = new InMemoryClassManager(compiler.getStandardFileManager(diagnostics,null,null))) { - JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, null, null, javaFileObjects); + try (InMemoryClassManager fileManager = new InMemoryClassManager( + compiler.getStandardFileManager(diagnostics, null, null))) { + JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, + null, null, javaFileObjects); boolean success = task.call(); if (!success) { |