| 1 | /******************************************************************************* | 
| 2 |  * Copyright (c) 2007, 2008 IBM Corporation and others. | 
| 3 |  * All rights reserved. This program and the accompanying materials | 
| 4 |  * are made available under the terms of the Eclipse Public License v1.0 | 
| 5 |  * which accompanies this distribution, and is available at | 
| 6 |  * http://www.eclipse.org/legal/epl-v10.html | 
| 7 |  * | 
| 8 |  * Contributors: | 
| 9 |  *     IBM Corporation - initial API and implementation | 
| 10 |  *******************************************************************************/ | 
| 11 | package org.eclipse.pde.api.tools.internal.descriptors; | 
| 12 |   | 
| 13 | import org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor; | 
| 14 | import org.eclipse.pde.api.tools.internal.provisional.descriptors.IFieldDescriptor; | 
| 15 | import org.eclipse.pde.api.tools.internal.provisional.descriptors.IReferenceTypeDescriptor; | 
| 16 |   | 
| 17 | /** | 
| 18 |  * Description of a field. | 
| 19 |  *  | 
| 20 |  * @since 1.0.0 | 
| 21 |  */ | 
| 22 | public class FieldDescriptorImpl extends MemberDescriptorImpl implements IFieldDescriptor { | 
| 23 |          | 
| 24 |         /** | 
| 25 |          * Constructs a field descriptor with the given name, declared by the given type. | 
| 26 |          *  | 
| 27 |          * @param name field name | 
| 28 |          * @param parent type containing the field declaration | 
| 29 |          */ | 
| 30 |         FieldDescriptorImpl(String name, IReferenceTypeDescriptor parent) { | 
| 31 |                 super(name, parent); | 
| 32 |         } | 
| 33 |   | 
| 34 |         /* (non-Javadoc) | 
| 35 |          * @see java.lang.Object#toString() | 
| 36 |          */ | 
| 37 |         public String toString() { | 
| 38 |                 StringBuffer buffer = new StringBuffer(); | 
| 39 |                 buffer.append(getEnclosingType().getQualifiedName()); | 
| 40 |                 buffer.append("#"); //$NON-NLS-1$ | 
| 41 |                 buffer.append(getName()); | 
| 42 |                 return buffer.toString(); | 
| 43 |         } | 
| 44 |          | 
| 45 |         /* (non-Javadoc) | 
| 46 |          * @see java.lang.Object#equals(java.lang.Object) | 
| 47 |          */ | 
| 48 |         public boolean equals(Object obj) { | 
| 49 |                 if (obj instanceof IFieldDescriptor) { | 
| 50 |                         IFieldDescriptor field = (IFieldDescriptor) obj; | 
| 51 |                         return getName().equals(field.getName()) && getEnclosingType().equals(field.getEnclosingType()); | 
| 52 |                 } | 
| 53 |                 return false; | 
| 54 |         } | 
| 55 |          | 
| 56 |         /* (non-Javadoc) | 
| 57 |          * @see java.lang.Object#hashCode() | 
| 58 |          */ | 
| 59 |         public int hashCode() { | 
| 60 |                 return getName().hashCode() + getEnclosingType().hashCode(); | 
| 61 |         }                 | 
| 62 |          | 
| 63 |         /* (non-Javadoc) | 
| 64 |          * @see org.eclipse.pde.api.tools.model.component.IElementDescriptor#getElementType() | 
| 65 |          */ | 
| 66 |         public int getElementType() { | 
| 67 |                 return IElementDescriptor.FIELD; | 
| 68 |         }         | 
| 69 | } |