| 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.jdt.core.Signature; | 
| 14 | import org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor; | 
| 15 | import org.eclipse.pde.api.tools.internal.provisional.descriptors.IMethodDescriptor; | 
| 16 | import org.eclipse.pde.api.tools.internal.provisional.descriptors.IReferenceTypeDescriptor; | 
| 17 |   | 
| 18 | /** | 
| 19 |  * Description of a method. | 
| 20 |  *  | 
| 21 |  * @since 1.0.0 | 
| 22 |  */ | 
| 23 | public class MethodDescriptorImpl extends MemberDescriptorImpl implements IMethodDescriptor { | 
| 24 |          | 
| 25 |         /** | 
| 26 |          * Method signature | 
| 27 |          */ | 
| 28 |         private String fSignature; | 
| 29 |                  | 
| 30 |         /** | 
| 31 |          * Constructs a method descriptor. | 
| 32 |          *  | 
| 33 |          * @param name method name | 
| 34 |          * @param enclosingType enclosing type | 
| 35 |          * @param signature method signature | 
| 36 |          */ | 
| 37 |         MethodDescriptorImpl(String name, IReferenceTypeDescriptor enclosingType, String signature) { | 
| 38 |                 super(name, enclosingType); | 
| 39 |                 fSignature = signature; | 
| 40 |         } | 
| 41 |          | 
| 42 |         /* (non-Javadoc) | 
| 43 |          * @see java.lang.Object#toString() | 
| 44 |          */ | 
| 45 |         public String toString() { | 
| 46 |                 StringBuffer buffer = new StringBuffer(); | 
| 47 |                 buffer.append(getEnclosingType().getQualifiedName()); | 
| 48 |                 buffer.append("#"); //$NON-NLS-1$ | 
| 49 |                 buffer.append(Signature.toString(getSignature(), getName(), null, true, true)); | 
| 50 |                 return buffer.toString(); | 
| 51 |         } | 
| 52 |   | 
| 53 |         /* (non-Javadoc) | 
| 54 |          * @see java.lang.Object#equals(java.lang.Object) | 
| 55 |          */ | 
| 56 |         public boolean equals(Object obj) { | 
| 57 |                 if (obj instanceof IMethodDescriptor) { | 
| 58 |                         IMethodDescriptor method = (IMethodDescriptor) obj; | 
| 59 |                         return getName().equals(method.getName()) | 
| 60 |                                         && getEnclosingType().equals(method.getEnclosingType()) | 
| 61 |                                         && getSignature().equals(method.getSignature()); | 
| 62 |                 } | 
| 63 |                 return false; | 
| 64 |         } | 
| 65 |          | 
| 66 |         /* (non-Javadoc) | 
| 67 |          * @see java.lang.Object#hashCode() | 
| 68 |          */ | 
| 69 |         public int hashCode() { | 
| 70 |                 return getName().hashCode() + getEnclosingType().hashCode(); | 
| 71 |         }         | 
| 72 |          | 
| 73 |         /* (non-Javadoc) | 
| 74 |          * @see org.eclipse.pde.api.tools.model.component.IElementDescriptor#getElementType() | 
| 75 |          */ | 
| 76 |         public int getElementType() { | 
| 77 |                 return IElementDescriptor.METHOD; | 
| 78 |         } | 
| 79 |   | 
| 80 |         /* (non-Javadoc) | 
| 81 |          * @see org.eclipse.pde.api.tools.model.component.IMethodDescriptor#getSignature() | 
| 82 |          */ | 
| 83 |         public String getSignature() { | 
| 84 |                 return fSignature; | 
| 85 |         } | 
| 86 |          | 
| 87 |         /* (non-Javadoc) | 
| 88 |          * @see org.eclipse.pde.api.tools.internal.provisional.descriptors.IMethodDescriptor#isConstructor() | 
| 89 |          */ | 
| 90 |         public boolean isConstructor() { | 
| 91 |                 return "<init>".equals(getName()); //$NON-NLS-1$ | 
| 92 |         } | 
| 93 | } |