001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package EDU.purdue.cs.bloat.editor;
022:
023: /**
024: * MemberRef represents a method or field (as a <tt>NameAndType</tt>) and the
025: * class (as a <tt>Type</tt>) in which it is declared.
026: *
027: * @author Nate Nystrom (<a
028: * href="mailto:nystrom@cs.purdue.edu">nystrom@cs.purdue.edu</a>)
029: */
030: public class MemberRef {
031: private Type declaringClass;
032:
033: private NameAndType nameAndType;
034:
035: /**
036: * Constructor.
037: *
038: * @param declaringClass
039: * The type of the class which declared the member.
040: * @param nameAndType
041: * The name and type of the member.
042: */
043: public MemberRef(final Type declaringClass,
044: final NameAndType nameAndType) {
045: this .declaringClass = declaringClass;
046: this .nameAndType = nameAndType;
047: }
048:
049: /**
050: * Get the type of the class which declared the member.
051: *
052: * @return The type of the class which declared the member.
053: */
054: public Type declaringClass() {
055: return declaringClass;
056: }
057:
058: /**
059: * Get the name of the member.
060: *
061: * @return The name of the member.
062: */
063: public String name() {
064: return nameAndType.name();
065: }
066:
067: /**
068: * Get the type of the member.
069: *
070: * @return The type of the member.
071: */
072: public Type type() {
073: return nameAndType.type();
074: }
075:
076: /**
077: * Get the name and type of the member.
078: *
079: * @return The name and type of the member.
080: */
081: public NameAndType nameAndType() {
082: return nameAndType;
083: }
084:
085: /**
086: * Convert the reference to a string.
087: *
088: * @return A string representation of the reference.
089: */
090: public String toString() {
091: // Take advantage of PRINT_TRUNCATED in Type
092: final String className = declaringClass.toString();
093: return "<" + (type().isMethod() ? "Method" : "Field") + " "
094: + className + "." + name() + " " + type() + ">";
095: }
096:
097: /**
098: * Check if an object is equal to this reference.
099: *
100: * @param obj
101: * The object to compare against.
102: * @return true if equal, false if not.
103: */
104: public boolean equals(final Object obj) {
105: return (obj instanceof MemberRef)
106: && ((MemberRef) obj).declaringClass
107: .equals(declaringClass)
108: && ((MemberRef) obj).nameAndType.equals(nameAndType);
109: }
110:
111: /**
112: * Hash the member reference.
113: *
114: * @return The hash code.
115: */
116: public int hashCode() {
117: return declaringClass.hashCode() ^ nameAndType.hashCode();
118: }
119: }
|