001    package org.mesopotamia.lang.java;
002    
003    import java.util.List;
004    
005    import org.mesopotamia.MesopotamiaException;
006    import org.mesopotamia.NodeData;
007    import org.mesopotamia.RepositoryLanguage;
008    import org.mesopotamia.Scan;
009    import org.mesopotamia.lang.java.ref.TypeInfo;
010    import org.mesopotamia.lang.java.ref.VariableInfo;
011    import org.w3c.dom.Element;
012    
013    import biz.hammurapi.util.CollectionVisitable;
014    import biz.hammurapi.util.Visitable;
015    import biz.hammurapi.util.Visitor;
016    
017    @SuppressWarnings("unchecked")
018    public class ParameterDefinition extends JavaLanguageElement implements VariableInfo {
019    
020            public ParameterDefinition(
021                            NodeData xData,
022                            Class<?> context,
023                            Scan scan,
024                            RepositoryLanguage language,
025                            Object environment) throws MesopotamiaException {
026                    
027                    super(xData, context, scan, language, environment);
028    
029                    // Select attributes
030                    Name = selectSingleElementText(Identifier.class, "IDENT|DOT");
031                    TypeSpecification = selectSingleElement(TypeSpecification.class, "TYPE");
032                    
033                    // Select attributes
034                    if (language.supportsTokenName("ANNOTATION")) {
035                            Modifiers = selectText(Modifier.class, "MODIFIERS/!ANNOTATION");
036                            Annotations = select(Annotation.class, "MODIFIERS/ANNOTATION");
037                    } else {
038                            Modifiers = selectText(Modifier.class, "MODIFIERS/*");                  
039                    }
040            }
041    
042            public void toDom(Element holder) {
043                    super.toDom(holder);
044    
045                    // Serialize attributes
046                    setAttribute(holder, "Name", Name);
047                    setElement(holder, "TypeSpecification", TypeSpecification);
048                    setElement(holder, "Modifiers", Modifiers);
049                    setElement(holder, "Annotations", Annotations);
050            }
051    
052            // Attributes
053            private String Name;
054    
055            private TypeSpecification TypeSpecification;
056    
057            private List<String> Modifiers;
058    
059            // Accessors
060            /* (non-Javadoc)
061             * @see org.mesopotamia.lang.java.VariableOrParameterDefinition#getName()
062             */
063            public String getName() {
064                    return Name;
065            }
066    
067            /* (non-Javadoc)
068             * @see org.mesopotamia.lang.java.VariableOrParameterDefinition#getTypeSpecification()
069             */
070            public TypeSpecification getTypeSpecification() {
071                    return TypeSpecification;
072            }
073    
074            /* (non-Javadoc)
075             * @see org.mesopotamia.lang.java.VariableOrParameterDefinition#getModifiers()
076             */
077            public List<String> getModifiers() {
078                    return Modifiers;
079            }
080    
081            protected void acceptChildren(Visitor visitor) {
082                    super.acceptChildren(visitor);
083                    // Visiting non-text attributes
084                    if (TypeSpecification instanceof Visitable) {
085                            ((Visitable) TypeSpecification).accept(visitor);
086                    }
087                    
088                    new CollectionVisitable(Annotations, false).accept(visitor);
089            }
090            
091            private List<Annotation> Annotations = emptyList;
092    
093            /* (non-Javadoc)
094             * @see org.mesopotamia.lang.java.VariableOrParameterDefinition#getAnnotations()
095             */
096            public List<Annotation> getAnnotations() {
097                    return Annotations;
098            }
099    
100            public TypeInfo getDeclaringType() {
101                    return null;
102            }
103    
104            public String getFcn() {
105                    return null;
106            }
107            
108    }