001: /*
002: * Copyright 2005 Joe Walker
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.directwebremoting.drapgen.ast;
017:
018: import nu.xom.Attribute;
019:
020: import static org.directwebremoting.drapgen.ast.SerializationStrings.*;
021:
022: /**
023: * We are assuming that there is no point to non-public methods for Drapgen
024: * @author Joe Walker [joe at getahead dot ltd dot uk]
025: */
026: public class Method extends Subroutine {
027: /**
028: * All {@link Method}s need a parent {@link Type}
029: * @param parent the type of which we are a part
030: */
031: protected Method(Type parent) {
032: super (parent);
033: }
034:
035: /**
036: * @return the name
037: */
038: public String getName() {
039: return name;
040: }
041:
042: /**
043: * @param name the name to set
044: */
045: public void setName(String name) {
046: this .name = name;
047: }
048:
049: /**
050: * @return the returnType
051: */
052: public Parameter getReturnType() {
053: return returnType;
054: }
055:
056: /**
057: * @param returnType the return Type to set
058: */
059: public void setReturnType(Parameter returnType) {
060: this .returnType = returnType;
061: }
062:
063: /**
064: * Create a XOM Element from this
065: * @return a Element representing this Type
066: */
067: protected nu.xom.Element toXomElement() {
068: nu.xom.Element element = super .toXomElement(METHOD);
069: element.addAttribute(new Attribute(NAME, name));
070: element.appendChild(returnType.toXomElement(RETURN_TYPE));
071:
072: return element;
073: }
074:
075: /**
076: * Load this type with data from the given document
077: * @param element The element to load from
078: */
079: @Override
080: protected void fromXomDocument(nu.xom.Element element) {
081: super .fromXomDocument(element);
082: name = element.getAttributeValue(NAME);
083: returnType.fromXomDocument(element
084: .getFirstChildElement(RETURN_TYPE));
085: }
086:
087: /* (non-Javadoc)
088: * @see java.lang.Object#hashCode()
089: */
090: @Override
091: public int hashCode() {
092: return getParent().hashCode() + name.hashCode()
093: + getParameters().hashCode();
094: }
095:
096: /* (non-Javadoc)
097: * @see java.lang.Object#equals(java.lang.Object)
098: */
099: @Override
100: public boolean equals(Object obj) {
101: if (obj == null) {
102: return false;
103: }
104:
105: if (obj == this ) {
106: return true;
107: }
108:
109: if (!this .getClass().equals(obj.getClass())) {
110: return false;
111: }
112:
113: Method that = (Method) obj;
114:
115: if (!this .getParent().equals(that.getParent())) {
116: return false;
117: }
118:
119: if (!this .name.equals(that.name)) {
120: return false;
121: }
122:
123: if (!this .getParameters().equals(that.getParameters())) {
124: return false;
125: }
126:
127: return true;
128: }
129:
130: /* (non-Javadoc)
131: * @see java.lang.Object#toString()
132: */
133: @Override
134: public String toString() {
135: return getParent() + "." + name + "(" + getParameters() + ")";
136: }
137:
138: private String name;
139:
140: private Parameter returnType;
141: }
|