/** * The spec says the value field in the enum class will be generated * only under certain circumstances. * * @return * true if the generated enum class should have the value field. */ public boolean needsValueField() { for (CEnumConstant cec : members) { if(!cec.getName().equals(cec.getLexicalValue())) return true; } return false; }
private static List<CEnumConstant> buildMemberList( Model model, Element dom ) { List<CEnumConstant> r = new ArrayList<CEnumConstant>(); String members = DOMUtil.getAttribute(dom,"members"); if(members==null) members=""; // TODO: error handling StringTokenizer tokens = new StringTokenizer(members); while(tokens.hasMoreTokens()) { String token = tokens.nextToken(); r.add(new CEnumConstant(model.getNameConverter().toConstantName(token), null,token,null)); } return r; } }
@Override public JAnnotatable getAnnotatable(Outline outline, EnumConstantOutline enumConstantOutline) throws IllegalArgumentException, UnsupportedOperationException { final CEnumLeafInfo enclosingClass = enumConstantOutline.target .getEnclosingClass(); return getAnnotatable(outline, outline.getEnum(enclosingClass)); }
} else { CEnumConstant[] collision = checkMemberNameCollision(memberList); getErrorReporter().error( collision[0].getLocator(), Messages.ERR_ENUM_MEMBER_NAME_COLLISION, collision[0].getName() ); getErrorReporter().error( collision[1].getLocator(), Messages.ERR_ENUM_MEMBER_NAME_COLLISION_RELATED );
/** * Returns non-null if {@link CEnumConstant}s have name collisions among them. * * @return * if there's a collision, return two {@link CEnumConstant}s that collided. * otherwise return null. */ private CEnumConstant[] checkMemberNameCollision( List<CEnumConstant> memberList ) { Map<String,CEnumConstant> names = new HashMap<String,CEnumConstant>(); for (CEnumConstant c : memberList) { CEnumConstant old = names.put(c.getName(),c); if(old!=null) // collision detected return new CEnumConstant[]{old,c}; } return null; }
public CEnumLeafInfo(Model model, QName typeName, CClassInfoParent container, String shortName, CNonElement base, Collection<CEnumConstant> _members, XSComponent source, CCustomizations customizations, Locator _sourceLocator) { this.model = model; this.parent = container; this.shortName = model.allocator.assignClassName(parent,shortName); this.base = base; this.members = _members; this.source = source; if(customizations==null) customizations = CCustomizations.EMPTY; this.customizations = customizations; this.sourceLocator = _sourceLocator; this.typeName = typeName; for( CEnumConstant mem : members ) mem.setParent(this); model.add(this); // TODO: can we take advantage of the fact that enum can be XmlRootElement? }
/** * Retrieve the enum constant that correlates to the string value. * @param enumType Type identifying an Enum in the code model * @param enumStringValue Lexical value of the constant to search * @param outline Outline of the code model * @return The matching Constant from the enum type or NULL if not found */ private JEnumConstant findEnumConstant(JType enumType, String enumStringValue, Outline outline) { // Search all Enums generated for (EnumOutline eo : outline.getEnums()) { // Is it the type of my variable? if (eo.clazz == enumType) { // Search all Constants of that enum for (EnumConstantOutline eco : eo.constants) { // Is the enum generated from the XML defaut value string? if (eco.target.getLexicalValue().equals(enumStringValue)) { return eco.constRef; } } // for Constants // Did not find the constant??? System.out.println("[WARN] Could not find EnumConstant for value: "+enumStringValue); return null; } } // Did not find the type?? System.out.println("[WARN] Could not find Enum class for type: "+enumType.fullName()); return null; }
} else { CEnumConstant[] collision = checkMemberNameCollision(memberList); getErrorReporter().error( collision[0].getLocator(), Messages.ERR_ENUM_MEMBER_NAME_COLLISION, collision[0].getName() ); getErrorReporter().error( collision[1].getLocator(), Messages.ERR_ENUM_MEMBER_NAME_COLLISION_RELATED );
/** * Returns non-null if {@link CEnumConstant}s have name collisions among them. * * @return * if there's a collision, return two {@link CEnumConstant}s that collided. * otherwise return null. */ private CEnumConstant[] checkMemberNameCollision( List<CEnumConstant> memberList ) { Map<String,CEnumConstant> names = new HashMap<String,CEnumConstant>(); for (CEnumConstant c : memberList) { CEnumConstant old = names.put(c.getName(),c); if(old!=null) // collision detected return new CEnumConstant[]{old,c}; } return null; }
public CEnumLeafInfo(Model model, QName typeName, CClassInfoParent container, String shortName, CNonElement base, Collection<CEnumConstant> _members, XSComponent source, CCustomizations customizations, Locator _sourceLocator) { this.model = model; this.parent = container; this.shortName = model.allocator.assignClassName(parent,shortName); this.base = base; this.members = _members; this.source = source; if(customizations==null) customizations = CCustomizations.EMPTY; this.customizations = customizations; this.sourceLocator = _sourceLocator; this.typeName = typeName; for( CEnumConstant mem : members ) mem.setParent(this); model.add(this); // TODO: can we take advantage of the fact that enum can be XmlRootElement? }
.param("value", enumConstantOutline.target.getLexicalValue());
/** * The spec says the value field in the enum class will be generated * only under certain circumstances. * * @return * true if the generated enum class should have the value field. */ public boolean needsValueField() { for (CEnumConstant cec : members) { if(!cec.getName().equals(cec.getLexicalValue())) return true; } return false; }
} else { CEnumConstant[] collision = checkMemberNameCollision(memberList); getErrorReporter().error( collision[0].getLocator(), Messages.ERR_ENUM_MEMBER_NAME_COLLISION, collision[0].getName() ); getErrorReporter().error( collision[1].getLocator(), Messages.ERR_ENUM_MEMBER_NAME_COLLISION_RELATED );
private static List<CEnumConstant> buildMemberList( Model model, Element dom ) { List<CEnumConstant> r = new ArrayList<CEnumConstant>(); String members = DOMUtil.getAttribute(dom,"members"); if(members==null) members=""; // TODO: error handling StringTokenizer tokens = new StringTokenizer(members); while(tokens.hasMoreTokens()) { String token = tokens.nextToken(); r.add(new CEnumConstant(model.getNameConverter().toConstantName(token), null,token,null/*TODO*/,null,null)); } return r; } }
/** * Returns non-null if {@link CEnumConstant}s have name collisions among them. * * @return * if there's a collision, return two {@link CEnumConstant}s that collided. * otherwise return null. */ private CEnumConstant[] checkMemberNameCollision( List<CEnumConstant> memberList ) { Map<String,CEnumConstant> names = new HashMap<String,CEnumConstant>(); for (CEnumConstant c : memberList) { CEnumConstant old = names.put(c.getName(),c); if(old!=null) // collision detected return new CEnumConstant[]{old,c}; } return null; }
public CEnumLeafInfo(Model model, QName typeName, CClassInfoParent container, String shortName, CNonElement base, Collection<CEnumConstant> _members, XSComponent source, CCustomizations customizations, Locator _sourceLocator) { this.model = model; this.parent = container; this.shortName = model.allocator.assignClassName(parent,shortName); this.base = base; this.members = _members; this.source = source; if(customizations==null) customizations = CCustomizations.EMPTY; this.customizations = customizations; this.sourceLocator = _sourceLocator; this.typeName = typeName; for( CEnumConstant mem : members ) mem.setParent(this); model.add(this); // TODO: can we take advantage of the fact that enum can be XmlRootElement? }
@Override public JAnnotatable getAnnotatable(Outline outline, EnumConstantOutline enumConstantOutline) throws IllegalArgumentException, UnsupportedOperationException { final CEnumLeafInfo enclosingClass = enumConstantOutline.target .getEnclosingClass(); return getAnnotatable(outline, outline.getEnum(enclosingClass)); }
/** * The spec says the value field in the enum class will be generated * only under certain circumstances. * * @return * true if the generated enum class should have the value field. */ public boolean needsValueField() { for (CEnumConstant cec : members) { if(!cec.getName().equals(cec.getLexicalValue())) return true; } return false; }
} else { CEnumConstant[] collision = checkMemberNameCollision(memberList); getErrorReporter().error( collision[0].getLocator(), Messages.ERR_ENUM_MEMBER_NAME_COLLISION, collision[0].getName() ); getErrorReporter().error( collision[1].getLocator(), Messages.ERR_ENUM_MEMBER_NAME_COLLISION_RELATED );
private static List<CEnumConstant> buildMemberList( Model model, Element dom ) { List<CEnumConstant> r = new ArrayList<CEnumConstant>(); String members = DOMUtil.getAttribute(dom,"members"); if(members==null) members=""; // TODO: error handling StringTokenizer tokens = new StringTokenizer(members); while(tokens.hasMoreTokens()) { String token = tokens.nextToken(); r.add(new CEnumConstant(model.getNameConverter().toConstantName(token), null,token,null/*TODO*/,null,null)); } return r; } }