com.sun.tools.internal.xjc.model.CEnumConstant Java Examples

The following examples show how to use com.sun.tools.internal.xjc.model.CEnumConstant. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleTypeBuilder.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: SimpleTypeBuilder.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: BIEnumeration.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #4
Source File: SimpleTypeBuilder.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #5
Source File: BIEnumeration.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #6
Source File: BIEnumeration.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #7
Source File: SimpleTypeBuilder.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #8
Source File: SimpleTypeBuilder.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #9
Source File: BIEnumeration.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #10
Source File: BIEnumeration.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #11
Source File: BIEnumeration.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #12
Source File: SimpleTypeBuilder.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #13
Source File: SimpleTypeBuilder.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #14
Source File: BIEnumeration.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #15
Source File: SimpleTypeBuilder.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #16
Source File: BIEnumeration.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #17
Source File: EnumConstantOutline.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Reserved for {@link BeanGenerator}.
 */
protected EnumConstantOutline(CEnumConstant target, JEnumConstant constRef) {
    this.target = target;
    this.constRef = constRef;
}
 
Example #18
Source File: EnumConstantOutline.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Reserved for {@link BeanGenerator}.
 */
protected EnumConstantOutline(CEnumConstant target, JEnumConstant constRef) {
    this.target = target;
    this.constRef = constRef;
}
 
Example #19
Source File: SimpleTypeBuilder.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 *
 * @param errorRef
 *      if constant names couldn't be generated, return a reference to that enum facet.
 * @return
 *      null if unable to generate names for some of the constants.
 */
private List<CEnumConstant> buildCEnumConstants(XSRestrictionSimpleType type, boolean needsToGenerateMemberName, Map<String, BIEnumMember> members, XSFacet[] errorRef) {
    List<CEnumConstant> memberList = new ArrayList<CEnumConstant>();
    int idx=1;
    Set<String> enums = new HashSet<String>(); // to avoid duplicates. See issue #366

    for( XSFacet facet : type.getDeclaredFacets(XSFacet.FACET_ENUMERATION)) {
        String name=null;
        String mdoc=builder.getBindInfo(facet).getDocumentation();

        if(!enums.add(facet.getValue().value))
            continue;   // ignore the 2nd occasion

        if( needsToGenerateMemberName ) {
            // generate names for all member names.
            // this will even override names specified by the user. that's crazy.
            name = "VALUE_"+(idx++);
        } else {
            String facetValue = facet.getValue().value;
            BIEnumMember mem = members.get(facetValue);
            if( mem==null )
                // look at the one attached to the facet object
                mem = builder.getBindInfo(facet).get(BIEnumMember.class);

            if (mem!=null) {
                name = mem.name;
                if (mdoc == null) {
                    mdoc = mem.javadoc;
                }
            }

            if(name==null) {
                StringBuilder sb = new StringBuilder();
                for( int i=0; i<facetValue.length(); i++) {
                    char ch = facetValue.charAt(i);
                    if(Character.isJavaIdentifierPart(ch))
                        sb.append(ch);
                    else
                        sb.append('_');
                }
                name = model.getNameConverter().toConstantName(sb.toString());
            }
        }

        if(!JJavaName.isJavaIdentifier(name)) {
            if(errorRef!=null)  errorRef[0] = facet;
            return null;    // unable to generate a name
        }

        memberList.add(new CEnumConstant(name,mdoc,facet.getValue().value,facet,builder.getBindInfo(facet).toCustomizationList(),facet.getLocator()));
    }
    return memberList;
}
 
Example #20
Source File: SimpleTypeBuilder.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 *
 * @param errorRef
 *      if constant names couldn't be generated, return a reference to that enum facet.
 * @return
 *      null if unable to generate names for some of the constants.
 */
private List<CEnumConstant> buildCEnumConstants(XSRestrictionSimpleType type, boolean needsToGenerateMemberName, Map<String, BIEnumMember> members, XSFacet[] errorRef) {
    List<CEnumConstant> memberList = new ArrayList<CEnumConstant>();
    int idx=1;
    Set<String> enums = new HashSet<String>(); // to avoid duplicates. See issue #366

    for( XSFacet facet : type.getDeclaredFacets(XSFacet.FACET_ENUMERATION)) {
        String name=null;
        String mdoc=builder.getBindInfo(facet).getDocumentation();

        if(!enums.add(facet.getValue().value))
            continue;   // ignore the 2nd occasion

        if( needsToGenerateMemberName ) {
            // generate names for all member names.
            // this will even override names specified by the user. that's crazy.
            name = "VALUE_"+(idx++);
        } else {
            String facetValue = facet.getValue().value;
            BIEnumMember mem = members.get(facetValue);
            if( mem==null )
                // look at the one attached to the facet object
                mem = builder.getBindInfo(facet).get(BIEnumMember.class);

            if (mem!=null) {
                name = mem.name;
                if (mdoc == null) {
                    mdoc = mem.javadoc;
                }
            }

            if(name==null) {
                StringBuilder sb = new StringBuilder();
                for( int i=0; i<facetValue.length(); i++) {
                    char ch = facetValue.charAt(i);
                    if(Character.isJavaIdentifierPart(ch))
                        sb.append(ch);
                    else
                        sb.append('_');
                }
                name = model.getNameConverter().toConstantName(sb.toString());
            }
        }

        if(!JJavaName.isJavaIdentifier(name)) {
            if(errorRef!=null)  errorRef[0] = facet;
            return null;    // unable to generate a name
        }

        memberList.add(new CEnumConstant(name,mdoc,facet.getValue().value,facet,builder.getBindInfo(facet).toCustomizationList(),facet.getLocator()));
    }
    return memberList;
}
 
Example #21
Source File: EnumConstantOutline.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Reserved for {@link BeanGenerator}.
 */
protected EnumConstantOutline(CEnumConstant target, JEnumConstant constRef) {
    this.target = target;
    this.constRef = constRef;
}
 
Example #22
Source File: SimpleTypeBuilder.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 *
 * @param errorRef
 *      if constant names couldn't be generated, return a reference to that enum facet.
 * @return
 *      null if unable to generate names for some of the constants.
 */
private List<CEnumConstant> buildCEnumConstants(XSRestrictionSimpleType type, boolean needsToGenerateMemberName, Map<String, BIEnumMember> members, XSFacet[] errorRef) {
    List<CEnumConstant> memberList = new ArrayList<CEnumConstant>();
    int idx=1;
    Set<String> enums = new HashSet<String>(); // to avoid duplicates. See issue #366

    for( XSFacet facet : type.getDeclaredFacets(XSFacet.FACET_ENUMERATION)) {
        String name=null;
        String mdoc=builder.getBindInfo(facet).getDocumentation();

        if(!enums.add(facet.getValue().value))
            continue;   // ignore the 2nd occasion

        if( needsToGenerateMemberName ) {
            // generate names for all member names.
            // this will even override names specified by the user. that's crazy.
            name = "VALUE_"+(idx++);
        } else {
            String facetValue = facet.getValue().value;
            BIEnumMember mem = members.get(facetValue);
            if( mem==null )
                // look at the one attached to the facet object
                mem = builder.getBindInfo(facet).get(BIEnumMember.class);

            if (mem!=null) {
                name = mem.name;
                if (mdoc == null) {
                    mdoc = mem.javadoc;
                }
            }

            if(name==null) {
                StringBuilder sb = new StringBuilder();
                for( int i=0; i<facetValue.length(); i++) {
                    char ch = facetValue.charAt(i);
                    if(Character.isJavaIdentifierPart(ch))
                        sb.append(ch);
                    else
                        sb.append('_');
                }
                name = model.getNameConverter().toConstantName(sb.toString());
            }
        }

        if(!JJavaName.isJavaIdentifier(name)) {
            if(errorRef!=null)  errorRef[0] = facet;
            return null;    // unable to generate a name
        }

        memberList.add(new CEnumConstant(name,mdoc,facet.getValue().value,facet,builder.getBindInfo(facet).toCustomizationList(),facet.getLocator()));
    }
    return memberList;
}
 
Example #23
Source File: EnumConstantOutline.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Reserved for {@link BeanGenerator}.
 */
protected EnumConstantOutline(CEnumConstant target, JEnumConstant constRef) {
    this.target = target;
    this.constRef = constRef;
}
 
Example #24
Source File: SimpleTypeBuilder.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 *
 * @param errorRef
 *      if constant names couldn't be generated, return a reference to that enum facet.
 * @return
 *      null if unable to generate names for some of the constants.
 */
private List<CEnumConstant> buildCEnumConstants(XSRestrictionSimpleType type, boolean needsToGenerateMemberName, Map<String, BIEnumMember> members, XSFacet[] errorRef) {
    List<CEnumConstant> memberList = new ArrayList<CEnumConstant>();
    int idx=1;
    Set<String> enums = new HashSet<String>(); // to avoid duplicates. See issue #366

    for( XSFacet facet : type.getDeclaredFacets(XSFacet.FACET_ENUMERATION)) {
        String name=null;
        String mdoc=builder.getBindInfo(facet).getDocumentation();

        if(!enums.add(facet.getValue().value))
            continue;   // ignore the 2nd occasion

        if( needsToGenerateMemberName ) {
            // generate names for all member names.
            // this will even override names specified by the user. that's crazy.
            name = "VALUE_"+(idx++);
        } else {
            String facetValue = facet.getValue().value;
            BIEnumMember mem = members.get(facetValue);
            if( mem==null )
                // look at the one attached to the facet object
                mem = builder.getBindInfo(facet).get(BIEnumMember.class);

            if (mem!=null) {
                name = mem.name;
                if (mdoc == null) {
                    mdoc = mem.javadoc;
                }
            }

            if(name==null) {
                StringBuilder sb = new StringBuilder();
                for( int i=0; i<facetValue.length(); i++) {
                    char ch = facetValue.charAt(i);
                    if(Character.isJavaIdentifierPart(ch))
                        sb.append(ch);
                    else
                        sb.append('_');
                }
                name = model.getNameConverter().toConstantName(sb.toString());
            }
        }

        if(!JJavaName.isJavaIdentifier(name)) {
            if(errorRef!=null)  errorRef[0] = facet;
            return null;    // unable to generate a name
        }

        memberList.add(new CEnumConstant(name,mdoc,facet.getValue().value,facet,builder.getBindInfo(facet).toCustomizationList(),facet.getLocator()));
    }
    return memberList;
}
 
Example #25
Source File: EnumConstantOutline.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Reserved for {@link BeanGenerator}.
 */
protected EnumConstantOutline(CEnumConstant target, JEnumConstant constRef) {
    this.target = target;
    this.constRef = constRef;
}
 
Example #26
Source File: SimpleTypeBuilder.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 *
 * @param errorRef
 *      if constant names couldn't be generated, return a reference to that enum facet.
 * @return
 *      null if unable to generate names for some of the constants.
 */
private List<CEnumConstant> buildCEnumConstants(XSRestrictionSimpleType type, boolean needsToGenerateMemberName, Map<String, BIEnumMember> members, XSFacet[] errorRef) {
    List<CEnumConstant> memberList = new ArrayList<CEnumConstant>();
    int idx=1;
    Set<String> enums = new HashSet<String>(); // to avoid duplicates. See issue #366

    for( XSFacet facet : type.getDeclaredFacets(XSFacet.FACET_ENUMERATION)) {
        String name=null;
        String mdoc=builder.getBindInfo(facet).getDocumentation();

        if(!enums.add(facet.getValue().value))
            continue;   // ignore the 2nd occasion

        if( needsToGenerateMemberName ) {
            // generate names for all member names.
            // this will even override names specified by the user. that's crazy.
            name = "VALUE_"+(idx++);
        } else {
            String facetValue = facet.getValue().value;
            BIEnumMember mem = members.get(facetValue);
            if( mem==null )
                // look at the one attached to the facet object
                mem = builder.getBindInfo(facet).get(BIEnumMember.class);

            if (mem!=null) {
                name = mem.name;
                if (mdoc == null) {
                    mdoc = mem.javadoc;
                }
            }

            if(name==null) {
                StringBuilder sb = new StringBuilder();
                for( int i=0; i<facetValue.length(); i++) {
                    char ch = facetValue.charAt(i);
                    if(Character.isJavaIdentifierPart(ch))
                        sb.append(ch);
                    else
                        sb.append('_');
                }
                name = model.getNameConverter().toConstantName(sb.toString());
            }
        }

        if(!JJavaName.isJavaIdentifier(name)) {
            if(errorRef!=null)  errorRef[0] = facet;
            return null;    // unable to generate a name
        }

        memberList.add(new CEnumConstant(name,mdoc,facet.getValue().value,facet,builder.getBindInfo(facet).toCustomizationList(),facet.getLocator()));
    }
    return memberList;
}
 
Example #27
Source File: EnumConstantOutline.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Reserved for {@link BeanGenerator}.
 */
protected EnumConstantOutline(CEnumConstant target, JEnumConstant constRef) {
    this.target = target;
    this.constRef = constRef;
}
 
Example #28
Source File: SimpleTypeBuilder.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 *
 * @param errorRef
 *      if constant names couldn't be generated, return a reference to that enum facet.
 * @return
 *      null if unable to generate names for some of the constants.
 */
private List<CEnumConstant> buildCEnumConstants(XSRestrictionSimpleType type, boolean needsToGenerateMemberName, Map<String, BIEnumMember> members, XSFacet[] errorRef) {
    List<CEnumConstant> memberList = new ArrayList<CEnumConstant>();
    int idx=1;
    Set<String> enums = new HashSet<String>(); // to avoid duplicates. See issue #366

    for( XSFacet facet : type.getDeclaredFacets(XSFacet.FACET_ENUMERATION)) {
        String name=null;
        String mdoc=builder.getBindInfo(facet).getDocumentation();

        if(!enums.add(facet.getValue().value))
            continue;   // ignore the 2nd occasion

        if( needsToGenerateMemberName ) {
            // generate names for all member names.
            // this will even override names specified by the user. that's crazy.
            name = "VALUE_"+(idx++);
        } else {
            String facetValue = facet.getValue().value;
            BIEnumMember mem = members.get(facetValue);
            if( mem==null )
                // look at the one attached to the facet object
                mem = builder.getBindInfo(facet).get(BIEnumMember.class);

            if (mem!=null) {
                name = mem.name;
                if (mdoc == null) {
                    mdoc = mem.javadoc;
                }
            }

            if(name==null) {
                StringBuilder sb = new StringBuilder();
                for( int i=0; i<facetValue.length(); i++) {
                    char ch = facetValue.charAt(i);
                    if(Character.isJavaIdentifierPart(ch))
                        sb.append(ch);
                    else
                        sb.append('_');
                }
                name = model.getNameConverter().toConstantName(sb.toString());
            }
        }

        if(!JJavaName.isJavaIdentifier(name)) {
            if(errorRef!=null)  errorRef[0] = facet;
            return null;    // unable to generate a name
        }

        memberList.add(new CEnumConstant(name,mdoc,facet.getValue().value,facet,builder.getBindInfo(facet).toCustomizationList(),facet.getLocator()));
    }
    return memberList;
}
 
Example #29
Source File: EnumConstantOutline.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Reserved for {@link BeanGenerator}.
 */
protected EnumConstantOutline(CEnumConstant target, JEnumConstant constRef) {
    this.target = target;
    this.constRef = constRef;
}
 
Example #30
Source File: SimpleTypeBuilder.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 *
 * @param errorRef
 *      if constant names couldn't be generated, return a reference to that enum facet.
 * @return
 *      null if unable to generate names for some of the constants.
 */
private List<CEnumConstant> buildCEnumConstants(XSRestrictionSimpleType type, boolean needsToGenerateMemberName, Map<String, BIEnumMember> members, XSFacet[] errorRef) {
    List<CEnumConstant> memberList = new ArrayList<CEnumConstant>();
    int idx=1;
    Set<String> enums = new HashSet<String>(); // to avoid duplicates. See issue #366

    for( XSFacet facet : type.getDeclaredFacets(XSFacet.FACET_ENUMERATION)) {
        String name=null;
        String mdoc=builder.getBindInfo(facet).getDocumentation();

        if(!enums.add(facet.getValue().value))
            continue;   // ignore the 2nd occasion

        if( needsToGenerateMemberName ) {
            // generate names for all member names.
            // this will even override names specified by the user. that's crazy.
            name = "VALUE_"+(idx++);
        } else {
            String facetValue = facet.getValue().value;
            BIEnumMember mem = members.get(facetValue);
            if( mem==null )
                // look at the one attached to the facet object
                mem = builder.getBindInfo(facet).get(BIEnumMember.class);

            if (mem!=null) {
                name = mem.name;
                if (mdoc == null) {
                    mdoc = mem.javadoc;
                }
            }

            if(name==null) {
                StringBuilder sb = new StringBuilder();
                for( int i=0; i<facetValue.length(); i++) {
                    char ch = facetValue.charAt(i);
                    if(Character.isJavaIdentifierPart(ch))
                        sb.append(ch);
                    else
                        sb.append('_');
                }
                name = model.getNameConverter().toConstantName(sb.toString());
            }
        }

        if(!JJavaName.isJavaIdentifier(name)) {
            if(errorRef!=null)  errorRef[0] = facet;
            return null;    // unable to generate a name
        }

        memberList.add(new CEnumConstant(name,mdoc,facet.getValue().value,facet,builder.getBindInfo(facet).toCustomizationList(),facet.getLocator()));
    }
    return memberList;
}