001: package org.kohsuke.rngom.parse.host;
002:
003: import org.kohsuke.rngom.ast.builder.Annotations;
004: import org.kohsuke.rngom.ast.builder.BuildException;
005: import org.kohsuke.rngom.ast.builder.CommentList;
006: import org.kohsuke.rngom.ast.builder.NameClassBuilder;
007: import org.kohsuke.rngom.ast.om.Location;
008: import org.kohsuke.rngom.ast.om.ParsedElementAnnotation;
009: import org.kohsuke.rngom.ast.om.ParsedNameClass;
010:
011: import java.util.List;
012: import java.util.ArrayList;
013:
014: /**
015: *
016: * @author
017: * Kohsuke Kawaguchi (kk@kohsuke.org)
018: */
019: final class NameClassBuilderHost extends Base implements
020: NameClassBuilder {
021: final NameClassBuilder lhs;
022: final NameClassBuilder rhs;
023:
024: NameClassBuilderHost(NameClassBuilder lhs, NameClassBuilder rhs) {
025: this .lhs = lhs;
026: this .rhs = rhs;
027: }
028:
029: public ParsedNameClass annotate(ParsedNameClass _nc,
030: Annotations _anno) throws BuildException {
031: ParsedNameClassHost nc = (ParsedNameClassHost) _nc;
032: AnnotationsHost anno = cast(_anno);
033:
034: return new ParsedNameClassHost(lhs.annotate(nc.lhs, anno.lhs),
035: rhs.annotate(nc.rhs, anno.rhs));
036: }
037:
038: public ParsedNameClass annotateAfter(ParsedNameClass _nc,
039: ParsedElementAnnotation _e) throws BuildException {
040: ParsedNameClassHost nc = (ParsedNameClassHost) _nc;
041: ParsedElementAnnotationHost e = (ParsedElementAnnotationHost) _e;
042:
043: return new ParsedNameClassHost(
044: lhs.annotateAfter(nc.lhs, e.lhs), rhs.annotateAfter(
045: nc.rhs, e.rhs));
046: }
047:
048: public ParsedNameClass commentAfter(ParsedNameClass _nc,
049: CommentList _comments) throws BuildException {
050: ParsedNameClassHost nc = (ParsedNameClassHost) _nc;
051: CommentListHost comments = (CommentListHost) _comments;
052:
053: return new ParsedNameClassHost(lhs.commentAfter(nc.lhs,
054: comments == null ? null : comments.lhs), rhs
055: .commentAfter(nc.rhs, comments == null ? null
056: : comments.rhs));
057: }
058:
059: public ParsedNameClass makeChoice(List _nameClasses, Location _loc,
060: Annotations _anno) {
061: List<ParsedNameClass> lnc = new ArrayList<ParsedNameClass>();
062: List<ParsedNameClass> rnc = new ArrayList<ParsedNameClass>();
063: for (int i = 0; i < _nameClasses.size(); i++) {
064: lnc.add(((ParsedNameClassHost) _nameClasses.get(i)).lhs);
065: rnc.add(((ParsedNameClassHost) _nameClasses.get(i)).rhs);
066: }
067: LocationHost loc = cast(_loc);
068: AnnotationsHost anno = cast(_anno);
069:
070: return new ParsedNameClassHost(lhs.makeChoice(lnc, loc.lhs,
071: anno.lhs), rhs.makeChoice(rnc, loc.rhs, anno.rhs));
072: }
073:
074: public ParsedNameClass makeName(String ns, String localName,
075: String prefix, Location _loc, Annotations _anno) {
076: LocationHost loc = cast(_loc);
077: AnnotationsHost anno = cast(_anno);
078:
079: return new ParsedNameClassHost(lhs.makeName(ns, localName,
080: prefix, loc.lhs, anno.lhs), rhs.makeName(ns, localName,
081: prefix, loc.rhs, anno.rhs));
082: }
083:
084: public ParsedNameClass makeNsName(String ns, Location _loc,
085: Annotations _anno) {
086: LocationHost loc = cast(_loc);
087: AnnotationsHost anno = cast(_anno);
088:
089: return new ParsedNameClassHost(lhs.makeNsName(ns, loc.lhs,
090: anno.lhs), rhs.makeNsName(ns, loc.rhs, anno.rhs));
091: }
092:
093: public ParsedNameClass makeNsName(String ns,
094: ParsedNameClass _except, Location _loc, Annotations _anno) {
095: ParsedNameClassHost except = (ParsedNameClassHost) _except;
096: LocationHost loc = cast(_loc);
097: AnnotationsHost anno = cast(_anno);
098:
099: return new ParsedNameClassHost(lhs.makeNsName(ns, except.lhs,
100: loc.lhs, anno.lhs), rhs.makeNsName(ns, except.rhs,
101: loc.rhs, anno.rhs));
102: }
103:
104: public ParsedNameClass makeAnyName(Location _loc, Annotations _anno) {
105: LocationHost loc = cast(_loc);
106: AnnotationsHost anno = cast(_anno);
107:
108: return new ParsedNameClassHost(lhs.makeAnyName(loc.lhs,
109: anno.lhs), rhs.makeAnyName(loc.rhs, anno.rhs));
110: }
111:
112: public ParsedNameClass makeAnyName(ParsedNameClass _except,
113: Location _loc, Annotations _anno) {
114: ParsedNameClassHost except = (ParsedNameClassHost) _except;
115: LocationHost loc = cast(_loc);
116: AnnotationsHost anno = cast(_anno);
117:
118: return new ParsedNameClassHost(lhs.makeAnyName(except.lhs,
119: loc.lhs, anno.lhs), rhs.makeAnyName(except.rhs,
120: loc.rhs, anno.rhs));
121: }
122:
123: public ParsedNameClass makeErrorNameClass() {
124: return new ParsedNameClassHost(lhs.makeErrorNameClass(), rhs
125: .makeErrorNameClass());
126: }
127: }
|