1 16 package com.google.gwt.user.rebind; 17 18 import com.google.gwt.core.ext.GeneratorContext; 19 20 import java.io.PrintWriter ; 21 import java.util.HashMap ; 22 import java.util.HashSet ; 23 import java.util.Map ; 24 import java.util.Set ; 25 26 30 public class ClassSourceFileComposerFactory { 31 35 public static class JavaSourceCategory extends Enum { 36 39 public static final JavaSourceCategory CLASS; 40 41 44 public static final JavaSourceCategory INTERFACE; 45 static Map pool = new HashMap (); 46 47 static { 48 CLASS = new JavaSourceCategory("class"); 49 INTERFACE = new JavaSourceCategory("interface"); 50 } 51 52 public static JavaSourceCategory require(String key) { 53 return (JavaSourceCategory) Enum.require(key, pool); 54 } 55 56 protected JavaSourceCategory(String key) { 57 super(key, pool); 58 } 59 } 60 61 private JavaSourceCategory classCategory = JavaSourceCategory.CLASS; 62 63 private String classComment; 64 65 private String className; 66 67 private Set imports = new HashSet (); 68 69 private Set interfaceNames = new HashSet (); 70 71 private String packageName; 72 73 private String superClassName; 74 75 public ClassSourceFileComposerFactory(String packageName, String className) { 76 this.packageName = packageName; 77 this.className = className; 78 } 79 80 public void addImplementedInterface(String intfName) { 81 interfaceNames.add(intfName); 82 } 83 84 public void addImport(String typeName) { 85 imports.add(typeName); 86 } 87 88 96 public SourceWriter createSourceWriter(GeneratorContext ctx, 97 PrintWriter printWriter) { 98 return new ClassSourceFileComposer(ctx, printWriter, getCreatedPackage(), 99 getCreatedClassShortName(), getSuperclassName(), getInterfaceNames(), 100 getImports(), classCategory, classComment); 101 } 102 103 113 public SourceWriter createSourceWriter(PrintWriter printWriter) { 114 return new ClassSourceFileComposer(null, printWriter, getCreatedPackage(), 115 getCreatedClassShortName(), getSuperclassName(), getInterfaceNames(), 116 getImports(), classCategory, classComment); 117 } 118 119 public String getCreatedClassName() { 120 return getCreatedPackage() + "." + getCreatedClassShortName(); 121 } 122 123 public String getCreatedClassShortName() { 124 return className; 125 } 126 127 public String getCreatedPackage() { 128 return packageName; 129 } 130 131 public String [] getInterfaceNames() { 132 return (String []) interfaceNames.toArray(new String [interfaceNames.size()]); 133 } 134 135 public String getSuperclassName() { 136 return superClassName; 137 } 138 139 142 public void makeInterface() { 143 classCategory = JavaSourceCategory.INTERFACE; 144 } 145 146 151 public void setJavaDocCommentForClass(String comment) { 152 classComment = comment; 153 } 154 155 public void setSuperclass(String superclassName) { 156 superClassName = superclassName; 157 } 158 159 private String [] getImports() { 160 return (String []) imports.toArray(new String [imports.size()]); 161 } 162 } 163 | Popular Tags |