diff options
author | Michael Bien <[email protected]> | 2010-03-31 23:53:39 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-03-31 23:53:39 +0200 |
commit | 60790e1f5963c439aadb3511b417e66fd4748001 (patch) | |
tree | ba44f61dfd2fe1d1426bcf973ee9af9e2aceed6f /src/java/com/sun/gluegen/CodeGenUtils.java | |
parent | e37c383c4a09432fff009e81d572c8a92b42eef6 (diff) |
fixed generated imports rudimentary (not DRY).. cleanup in work.
Diffstat (limited to 'src/java/com/sun/gluegen/CodeGenUtils.java')
-rw-r--r-- | src/java/com/sun/gluegen/CodeGenUtils.java | 175 |
1 files changed, 86 insertions, 89 deletions
diff --git a/src/java/com/sun/gluegen/CodeGenUtils.java b/src/java/com/sun/gluegen/CodeGenUtils.java index a558c66..ac2e033 100644 --- a/src/java/com/sun/gluegen/CodeGenUtils.java +++ b/src/java/com/sun/gluegen/CodeGenUtils.java @@ -36,110 +36,107 @@ * Sun gratefully acknowledges that this software was originally authored * and developed by Kenneth Bradley Russell and Christopher John Kline. */ - package com.sun.gluegen; import java.io.*; import java.util.*; public class CodeGenUtils { - /** - * Given a java package name (e.g., "java.lang"), return the package as a - * directory path (i.e., "java/lang"). - */ - public static String packageAsPath(String packageName) { - String path = packageName.replace('.', File.separatorChar); - //System.out.println("Converted package [" + packageName + "] to path [" + path +"]"); - return path; - } - /** - * @param generator the object that is emitting the autogenerated code. If - * null, the generator will not be mentioned in the warning message. - */ - public static void emitAutogeneratedWarning(PrintWriter w, Object generator) { - w.print("/* !---- DO NOT EDIT: This file autogenerated "); - if (generator != null) { - w.print("by "); - w.print(packageAsPath(generator.getClass().getName())); - w.print(".java "); + /** + * Given a java package name (e.g., "java.lang"), return the package as a + * directory path (i.e., "java/lang"). + */ + public static String packageAsPath(String packageName) { + String path = packageName.replace('.', File.separatorChar); + //System.out.println("Converted package [" + packageName + "] to path [" + path +"]"); + return path; } - w.print("on "); - w.print((new Date()).toString()); - w.println(" ----! */"); - w.println(); - } - - /** - * Emit the opening headers for one java class/interface file. - */ - public static void emitJavaHeaders( PrintWriter w, - String packageName, - String className, - String gluegenRuntimePackage, - boolean isClassNotInterface, - String[] imports, - String[] accessModifiers, - String[] interfaces, - String classExtended, - EmissionCallback classDocComment) throws IOException { - w.println("package " + packageName + ";"); - w.println(); - for (int i = 0; imports != null && i < imports.length; ++i) { - w.print("import "); - w.print(imports[i]); - w.println(';'); + /** + * @param generator the object that is emitting the autogenerated code. If + * null, the generator will not be mentioned in the warning message. + */ + public static void emitAutogeneratedWarning(PrintWriter w, Object generator) { + w.print("/* !---- DO NOT EDIT: This file autogenerated "); + if (generator != null) { + w.print("by "); + w.print(packageAsPath(generator.getClass().getName())); + w.print(".java "); + } + w.print("on "); + w.print((new Date()).toString()); + w.println(" ----! */"); + w.println(); } - w.println("import " + gluegenRuntimePackage + ".*;"); - w.println(); + /** + * Emit the opening headers for one java class/interface file. + */ + public static void emitJavaHeaders(PrintWriter w, + String packageName, + String className, + boolean isClassNotInterface, + List<String> imports, + String[] accessModifiers, + String[] interfaces, + String classExtended, + EmissionCallback classDocComment) throws IOException { + w.println("package " + packageName + ";"); + w.println(); - if (classDocComment != null) - { - classDocComment.emit(w); - } - - for (int i = 0; accessModifiers != null && i < accessModifiers.length; ++i) { - w.print(accessModifiers[i]); - w.print(' '); - } + for (String imp : imports) { + w.print("import "); + w.print(imp); + w.println(';'); + } - if (isClassNotInterface) { - w.print("class "); - w.print(className); - w.print(' '); - if (classExtended != null) { - w.print("extends "); - w.print(classExtended); - } - } - else { - if (classExtended != null) { - throw new IllegalArgumentException( - "Autogenerated interface class " + className + - " cannot extend class " + classExtended); - } - w.print("interface "); - w.print(className); - w.print(' '); - } + w.println(); - for (int i = 0; interfaces != null && i < interfaces.length; ++i) { - if (i == 0) { w.print(isClassNotInterface ? "implements " : "extends "); } - w.print(interfaces[i]); - if (i < interfaces.length-1) { w.print(", "); } - } + if (classDocComment != null) { + classDocComment.emit(w); + } + + for (int i = 0; accessModifiers != null && i < accessModifiers.length; ++i) { + w.print(accessModifiers[i]); + w.print(' '); + } + + if (isClassNotInterface) { + w.print("class "); + w.print(className); + w.print(' '); + if (classExtended != null) { + w.print("extends "); + w.print(classExtended); + } + } else { + if (classExtended != null) { + throw new IllegalArgumentException("Autogenerated interface class " + className + " cannot extend class " + classExtended); + } + w.print("interface "); + w.print(className); + w.print(' '); + } - w.println(); - w.println('{'); - } + for (int i = 0; interfaces != null && i < interfaces.length; ++i) { + if (i == 0) { + w.print(isClassNotInterface ? "implements " : "extends "); + } + w.print(interfaces[i]); + if (i < interfaces.length - 1) { + w.print(", "); + } + } - //----------------------------------------- + w.println('{'); + } + + //----------------------------------------- + /** A class that emits source code of some time when activated. */ + public interface EmissionCallback { - /** A class that emits source code of some time when activated. */ - public interface EmissionCallback { - /** Emit appropriate source code through the given writer. */ - public void emit(PrintWriter output); - } + /** Emit appropriate source code through the given writer. */ + public void emit(PrintWriter output); + } } |