1 package org.eclipse.emf.codegen.ecore.templates.model; 2 3 import java.util.*; 4 import org.eclipse.emf.codegen.ecore.genmodel.*; 5 6 public class EnumClass 7 { 8 protected static String nl; 9 public static synchronized EnumClass create(String lineSeparator) 10 { 11 nl = lineSeparator; 12 EnumClass result = new EnumClass(); 13 nl = null; 14 return result; 15 } 16 17 protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; 18 protected final String TEXT_1 = ""; 19 protected final String TEXT_2 = "/**" + NL + " * <copyright>" + NL + " * </copyright>" + NL + " *" + NL + " * "; 20 protected final String TEXT_3 = "Id"; 21 protected final String TEXT_4 = NL + " */" + NL + "package "; 22 protected final String TEXT_5 = ";" + NL; 23 protected final String TEXT_6 = NL + NL + "/**" + NL + " * <!-- begin-user-doc -->" + NL + " * A representation of the literals of the enumeration '<em><b>"; 24 protected final String TEXT_7 = "</b></em>'," + NL + " * and utility methods for working with them." + NL + " * <!-- end-user-doc -->"; 25 protected final String TEXT_8 = NL + " * <!-- begin-model-doc -->" + NL + " * "; 26 protected final String TEXT_9 = NL + " * <!-- end-model-doc -->"; 27 protected final String TEXT_10 = NL + " * @see "; 28 protected final String TEXT_11 = "#get"; 29 protected final String TEXT_12 = "()" + NL + " * @model" + NL + " * @generated" + NL + " */" + NL + "public final class "; 30 protected final String TEXT_13 = " extends AbstractEnumerator" + NL + "{"; 31 protected final String TEXT_14 = NL + "\t/**" + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final "; 32 protected final String TEXT_15 = " copyright = \""; 33 protected final String TEXT_16 = "\";"; 34 protected final String TEXT_17 = NL; 35 protected final String TEXT_18 = NL + "\t/**" + NL + "\t * The '<em><b>"; 36 protected final String TEXT_19 = "</b></em>' literal value." + NL + "\t * <!-- begin-user-doc -->"; 37 protected final String TEXT_20 = NL + "\t * <p>" + NL + "\t * If the meaning of '<em><b>"; 38 protected final String TEXT_21 = "</b></em>' literal object isn't clear," + NL + "\t * there really should be more of a description here..." + NL + "\t * </p>"; 39 protected final String TEXT_22 = NL + "\t * <!-- end-user-doc -->"; 40 protected final String TEXT_23 = NL + "\t * <!-- begin-model-doc -->" + NL + "\t * "; 41 protected final String TEXT_24 = NL + "\t * <!-- end-model-doc -->"; 42 protected final String TEXT_25 = NL + "\t * @see #"; 43 protected final String TEXT_26 = "_LITERAL"; 44 protected final String TEXT_27 = NL + "\t * @model "; 45 protected final String TEXT_28 = NL + "\t * "; 46 protected final String TEXT_29 = NL + "\t * @model"; 47 protected final String TEXT_30 = NL + "\t * @generated" + NL + "\t * @ordered" + NL + "\t */" + NL + "\tpublic static final int "; 48 protected final String TEXT_31 = " = "; 49 protected final String TEXT_32 = ";" + NL; 50 protected final String TEXT_33 = NL + "\t/**" + NL + "\t * The '<em><b>"; 51 protected final String TEXT_34 = "</b></em>' literal object." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @see #"; 52 protected final String TEXT_35 = NL + "\t * @generated" + NL + "\t * @ordered" + NL + "\t */" + NL + "\tpublic static final "; 53 protected final String TEXT_36 = " "; 54 protected final String TEXT_37 = "_LITERAL = new "; 55 protected final String TEXT_38 = "("; 56 protected final String TEXT_39 = ", \""; 57 protected final String TEXT_40 = "\");"; 58 protected final String TEXT_41 = NL; 59 protected final String TEXT_42 = NL + "\t/**" + NL + "\t * An array of all the '<em><b>"; 60 protected final String TEXT_43 = "</b></em>' enumerators." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static final "; 61 protected final String TEXT_44 = "[] VALUES_ARRAY =" + NL + "\t\tnew "; 62 protected final String TEXT_45 = "[]" + NL + "\t\t{"; 63 protected final String TEXT_46 = NL + "\t\t\t"; 64 protected final String TEXT_47 = "_LITERAL,"; 65 protected final String TEXT_48 = NL + "\t\t};" + NL + "" + NL + "\t/**" + NL + "\t * A public read-only list of all the '<em><b>"; 66 protected final String TEXT_49 = "</b></em>' enumerators." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final List VALUES = Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY));" + NL + "" + NL + "\t/**" + NL + "\t * Returns the '<em><b>"; 67 protected final String TEXT_50 = "</b></em>' literal with the specified name." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static "; 68 protected final String TEXT_51 = " get("; 69 protected final String TEXT_52 = " name)" + NL + "\t{" + NL + "\t\tfor (int i = 0; i < VALUES_ARRAY.length; ++i)" + NL + "\t\t{" + NL + "\t\t\t"; 70 protected final String TEXT_53 = " result = VALUES_ARRAY[i];" + NL + "\t\t\tif (result.toString().equals(name))" + NL + "\t\t\t{" + NL + "\t\t\t\treturn result;" + NL + "\t\t\t}" + NL + "\t\t}" + NL + "\t\treturn null;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * Returns the '<em><b>"; 71 protected final String TEXT_54 = "</b></em>' literal with the specified value." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static "; 72 protected final String TEXT_55 = " get(int value)" + NL + "\t{" + NL + "\t\tswitch (value)" + NL + "\t\t{"; 73 protected final String TEXT_56 = NL + "\t\t\tcase "; 74 protected final String TEXT_57 = ": return "; 75 protected final String TEXT_58 = "_LITERAL;"; 76 protected final String TEXT_59 = NL + "\t\t}" + NL + "\t\treturn null;\t" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * Only this class can construct instances." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate "; 77 protected final String TEXT_60 = "(int value, "; 78 protected final String TEXT_61 = " name)" + NL + "\t{" + NL + "\t\tsuper(value, name);" + NL + "\t}" + NL + "" + NL + "} //"; 79 protected final String TEXT_62 = NL; 80 81 public String generate(Object argument) 82 { 83 StringBuffer stringBuffer = new StringBuffer (); 84 85 99 100 GenEnum genEnum = (GenEnum)argument; GenPackage genPackage = genEnum.getGenPackage(); GenModel genModel=genPackage.getGenModel(); 101 stringBuffer.append(TEXT_1); 102 stringBuffer.append(TEXT_2); 103 stringBuffer.append("$"); 104 stringBuffer.append(TEXT_3); 105 stringBuffer.append("$"); 106 stringBuffer.append(TEXT_4); 107 stringBuffer.append(genPackage.getInterfacePackageName()); 108 stringBuffer.append(TEXT_5); 109 genModel.addImport("java.util.Arrays"); 110 genModel.addImport("java.util.List"); 111 genModel.addImport("java.util.Collections"); 112 genModel.addImport("org.eclipse.emf.common.util.AbstractEnumerator"); 113 genModel.markImportLocation(stringBuffer, genPackage); 114 stringBuffer.append(TEXT_6); 115 stringBuffer.append(genEnum.getFormattedName()); 116 stringBuffer.append(TEXT_7); 117 if (genEnum.hasDocumentation()) { 118 stringBuffer.append(TEXT_8); 119 stringBuffer.append(genEnum.getDocumentation(genModel.getIndentation(stringBuffer))); 120 stringBuffer.append(TEXT_9); 121 } 122 stringBuffer.append(TEXT_10); 123 stringBuffer.append(genPackage.getQualifiedPackageInterfaceName()); 124 stringBuffer.append(TEXT_11); 125 stringBuffer.append(genEnum.getName()); 126 stringBuffer.append(TEXT_12); 127 stringBuffer.append(genEnum.getName()); 128 stringBuffer.append(TEXT_13); 129 if (genModel.getCopyrightText() != null) { 130 stringBuffer.append(TEXT_14); 131 stringBuffer.append(genModel.getImportedName("java.lang.String")); 132 stringBuffer.append(TEXT_15); 133 stringBuffer.append(genModel.getCopyrightText()); 134 stringBuffer.append(TEXT_16); 135 stringBuffer.append(genModel.getNonNLS()); 136 stringBuffer.append(TEXT_17); 137 } 138 for (Iterator l=genEnum.getGenEnumLiterals().iterator(); l.hasNext();) { GenEnumLiteral genEnumLiteral = (GenEnumLiteral)l.next(); 139 stringBuffer.append(TEXT_18); 140 stringBuffer.append(genEnumLiteral.getFormattedName()); 141 stringBuffer.append(TEXT_19); 142 if (!genEnumLiteral.hasDocumentation()) { 143 stringBuffer.append(TEXT_20); 144 stringBuffer.append(genEnumLiteral.getFormattedName()); 145 stringBuffer.append(TEXT_21); 146 } 147 stringBuffer.append(TEXT_22); 148 if (genEnumLiteral.hasDocumentation()) { 149 stringBuffer.append(TEXT_23); 150 stringBuffer.append(genEnumLiteral.getDocumentation(genModel.getIndentation(stringBuffer))); 151 stringBuffer.append(TEXT_24); 152 } 153 stringBuffer.append(TEXT_25); 154 stringBuffer.append(genEnumLiteral.getEnumLiteralID()); 155 stringBuffer.append(TEXT_26); 156 {boolean first = true; for (StringTokenizer stringTokenizer = new StringTokenizer(genEnumLiteral.getModelInfo(), "\n\r"); stringTokenizer.hasMoreTokens(); ) { String modelInfo = stringTokenizer.nextToken(); if (first) { first = false; 157 stringBuffer.append(TEXT_27); 158 stringBuffer.append(modelInfo); 159 } else { 160 stringBuffer.append(TEXT_28); 161 stringBuffer.append(modelInfo); 162 }} if (first) { 163 stringBuffer.append(TEXT_29); 164 }} 165 stringBuffer.append(TEXT_30); 166 stringBuffer.append(genEnumLiteral.getEnumLiteralID()); 167 stringBuffer.append(TEXT_31); 168 stringBuffer.append(genEnumLiteral.getValue()); 169 stringBuffer.append(TEXT_32); 170 } 171 for (Iterator l=genEnum.getGenEnumLiterals().iterator(); l.hasNext();) { GenEnumLiteral genEnumLiteral = (GenEnumLiteral)l.next(); 172 stringBuffer.append(TEXT_33); 173 stringBuffer.append(genEnumLiteral.getFormattedName()); 174 stringBuffer.append(TEXT_34); 175 stringBuffer.append(genEnumLiteral.getEnumLiteralID()); 176 stringBuffer.append(TEXT_35); 177 stringBuffer.append(genEnum.getName()); 178 stringBuffer.append(TEXT_36); 179 stringBuffer.append(genEnumLiteral.getEnumLiteralID()); 180 stringBuffer.append(TEXT_37); 181 stringBuffer.append(genEnum.getName()); 182 stringBuffer.append(TEXT_38); 183 stringBuffer.append(genEnumLiteral.getEnumLiteralID()); 184 stringBuffer.append(TEXT_39); 185 stringBuffer.append(genEnumLiteral.getName()); 186 stringBuffer.append(TEXT_40); 187 stringBuffer.append(genModel.getNonNLS()); 188 stringBuffer.append(TEXT_41); 189 } 190 stringBuffer.append(TEXT_42); 191 stringBuffer.append(genEnum.getFormattedName()); 192 stringBuffer.append(TEXT_43); 193 stringBuffer.append(genEnum.getName()); 194 stringBuffer.append(TEXT_44); 195 stringBuffer.append(genEnum.getName()); 196 stringBuffer.append(TEXT_45); 197 for (Iterator l=genEnum.getGenEnumLiterals().iterator(); l.hasNext();) { GenEnumLiteral genEnumLiteral = (GenEnumLiteral)l.next(); 198 stringBuffer.append(TEXT_46); 199 stringBuffer.append(genEnumLiteral.getEnumLiteralID()); 200 stringBuffer.append(TEXT_47); 201 } 202 stringBuffer.append(TEXT_48); 203 stringBuffer.append(genEnum.getFormattedName()); 204 stringBuffer.append(TEXT_49); 205 stringBuffer.append(genEnum.getFormattedName()); 206 stringBuffer.append(TEXT_50); 207 stringBuffer.append(genEnum.getName()); 208 stringBuffer.append(TEXT_51); 209 stringBuffer.append(genModel.getImportedName("java.lang.String")); 210 stringBuffer.append(TEXT_52); 211 stringBuffer.append(genEnum.getName()); 212 stringBuffer.append(TEXT_53); 213 stringBuffer.append(genEnum.getFormattedName()); 214 stringBuffer.append(TEXT_54); 215 stringBuffer.append(genEnum.getName()); 216 stringBuffer.append(TEXT_55); 217 for (Iterator l=genEnum.getUniqueValuedGenEnumLiterals().iterator(); l.hasNext();) { GenEnumLiteral genEnumLiteral = (GenEnumLiteral)l.next(); 218 stringBuffer.append(TEXT_56); 219 stringBuffer.append(genEnumLiteral.getEnumLiteralID()); 220 stringBuffer.append(TEXT_57); 221 stringBuffer.append(genEnumLiteral.getEnumLiteralID()); 222 stringBuffer.append(TEXT_58); 223 } 224 stringBuffer.append(TEXT_59); 225 stringBuffer.append(genEnum.getName()); 226 stringBuffer.append(TEXT_60); 227 stringBuffer.append(genModel.getImportedName("java.lang.String")); 228 stringBuffer.append(TEXT_61); 229 stringBuffer.append(genEnum.getName()); 230 genModel.emitSortedImports(); 231 stringBuffer.append(TEXT_62); 232 return stringBuffer.toString(); 233 } 234 } 235 | Popular Tags |