| 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.IMemberDescriptor; |
| 15 | import org.eclipse.pde.api.tools.internal.provisional.descriptors.IPackageDescriptor; |
| 16 | import org.eclipse.pde.api.tools.internal.provisional.descriptors.IReferenceTypeDescriptor; |
| 17 | |
| 18 | /** |
| 19 | * Description of a field. |
| 20 | * |
| 21 | * @since 1.0.0 |
| 22 | */ |
| 23 | public abstract class MemberDescriptorImpl extends NamedElementDescriptorImpl implements IMemberDescriptor { |
| 24 | |
| 25 | /** |
| 26 | * parent element or <code>null</code> |
| 27 | */ |
| 28 | private IElementDescriptor fParent; |
| 29 | |
| 30 | /** |
| 31 | * Constructs a member with the given name and parent |
| 32 | * |
| 33 | * @param name field name |
| 34 | * @param parent type containing the field declaration or package containing the type |
| 35 | * @param modifiers |
| 36 | */ |
| 37 | MemberDescriptorImpl(String name, IElementDescriptor parent) { |
| 38 | super(name); |
| 39 | fParent = parent; |
| 40 | } |
| 41 | |
| 42 | /* (non-Javadoc) |
| 43 | * @see org.eclipse.pde.api.tools.model.component.IMemberDescriptor#getEnclosingType() |
| 44 | */ |
| 45 | public IReferenceTypeDescriptor getEnclosingType() { |
| 46 | IElementDescriptor parent = getParent(); |
| 47 | if (parent instanceof IReferenceTypeDescriptor) { |
| 48 | return (IReferenceTypeDescriptor)parent; |
| 49 | } |
| 50 | return null; |
| 51 | } |
| 52 | |
| 53 | /* (non-Javadoc) |
| 54 | * @see org.eclipse.pde.api.tools.model.component.IMemberDescriptor#getPackage() |
| 55 | */ |
| 56 | public IPackageDescriptor getPackage() { |
| 57 | IElementDescriptor parent = getParent(); |
| 58 | while (!(parent instanceof IPackageDescriptor)) { |
| 59 | parent = ((MemberDescriptorImpl)parent).getParent(); |
| 60 | } |
| 61 | return (IPackageDescriptor) parent; |
| 62 | } |
| 63 | |
| 64 | /* (non-Javadoc) |
| 65 | * @see org.eclipse.pde.api.tools.model.component.IElementDescriptor#getParent() |
| 66 | */ |
| 67 | public IElementDescriptor getParent() { |
| 68 | return fParent; |
| 69 | } |
| 70 | |
| 71 | } |