1 18 package org.objectweb.speedo.generation.mivisitor; 19 20 import org.objectweb.speedo.metadata.SpeedoField; 21 import org.objectweb.speedo.metadata.SpeedoMap; 22 import org.objectweb.speedo.metadata.SpeedoCollection; 23 import org.objectweb.speedo.metadata.SpeedoClass; 24 import org.objectweb.speedo.api.SpeedoException; 25 import org.objectweb.jorm.type.api.PTypeSpace; 26 import org.objectweb.jorm.type.api.PType; 27 28 35 public class JavaLangShorcutVisitor extends AbstractMetaInfoVisitor { 36 37 private final static String [][] STN2FQTN = { 38 {"Object", "java.lang.Object"}, 39 {"Date", "java.util.Date"}, 40 {"Locale", "java.util.Locale"}, 41 {"String", "java.lang.String"}, 42 {"Integer", "java.lang.Integer"} 43 }; 44 45 protected String getLoggerName() { 46 return super.getLoggerName() +".javalang"; 47 } 48 49 public void visitClass(SpeedoClass sc) throws SpeedoException { 50 super.visitClass(sc); 51 if (sc.objectidClass != null) { 52 int idx = sc.objectidClass.indexOf('.'); 53 if (idx == -1) { 54 sc.objectidClass = sc.jdoPackage.name + '.' + sc.objectidClass; 55 } 56 } 57 } 58 59 public void visitField(SpeedoField sf) throws SpeedoException { 60 super.visitField(sf); 61 62 if (sf.jdoTuple instanceof SpeedoMap) { 63 SpeedoMap sm = (SpeedoMap) sf.jdoTuple; 64 sm.keyType = toJavaFQN((String ) sm.keyType); 65 sm.valueType = toJavaFQN((String ) sm.valueType); 66 } else if (sf.jdoTuple instanceof SpeedoCollection) { 67 SpeedoCollection sc = (SpeedoCollection) sf.jdoTuple; 68 sc.elementType = toJavaFQN((String ) sc.elementType); 69 } 70 } 71 72 private static String toJavaFQN(String name) { 73 for(int i=0; i<STN2FQTN.length; i++) { 74 if (STN2FQTN[i][0].equals(name)) { 75 return STN2FQTN[i][1]; 76 } 77 } 78 for (int i = 0; i < PTypeSpace.PREDEFINEDPTYPES.length; i++) { 79 PType ptype = PTypeSpace.PREDEFINEDPTYPES[i]; 80 if (ptype.getJavaName().equals(name) 81 || ptype.getJormName().equals(name)) { 82 return ptype.getJavaName(); 83 } 84 } 85 return name; 86 } 87 } 88 | Popular Tags |