EMMA Coverage Report (generated Thu Nov 26 15:54:18 CST 2009)
[all classes][org.eclipse.pde.api.tools.internal.model]

COVERAGE SUMMARY FOR SOURCE FILE [ApiElement.java]

nameclass, %method, %block, %line, %
ApiElement.java100% (1/1)75%  (6/8)76%  (51/67)90%  (18/20)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ApiElement100% (1/1)75%  (6/8)76%  (51/67)90%  (18/20)
abort (String, Throwable): void 0%   (0/1)0%   (0/11)0%   (0/1)
getApiComponent (): IApiComponent 0%   (0/1)0%   (0/5)0%   (0/1)
ApiElement (IApiElement, int, String): void 100% (1/1)100% (21/21)100% (8/8)
getAncestor (int): IApiElement 100% (1/1)100% (15/15)100% (4/4)
getName (): String 100% (1/1)100% (3/3)100% (1/1)
getParent (): IApiElement 100% (1/1)100% (3/3)100% (1/1)
getType (): int 100% (1/1)100% (3/3)100% (1/1)
setName (String): void 100% (1/1)100% (6/6)100% (3/3)

1/*******************************************************************************
2 * Copyright (c) 2008, 2009 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 *******************************************************************************/
11package org.eclipse.pde.api.tools.internal.model;
12 
13import org.eclipse.core.runtime.CoreException;
14import org.eclipse.core.runtime.IStatus;
15import org.eclipse.core.runtime.Status;
16import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
17import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
18import org.eclipse.pde.api.tools.internal.provisional.model.IApiElement;
19 
20/**
21 * Abstract description of an API element.
22 * Each {@link IApiElement} has a specific type, name and parent.
23 * <br>
24 * API elements cannot be re-parented.
25 * 
26 * @since 1.0.0
27 */
28public abstract class ApiElement implements IApiElement {
29 
30        private int fType = 0;
31        private String fName = null;
32        private IApiElement fParent = null;
33        
34        /**
35         * Constructor
36         * @param parent the parent {@link IApiElement} for this element, may be <code>null</code>
37         * @param type the type of this element. See {@link IApiElement} for values.
38         * @param name the simple name of the element
39         */
40        protected ApiElement(IApiElement parent, int type, String name) {
41                fParent = parent;
42                fType = type;
43                fName = name;
44        }
45        
46        /**
47         * @see org.eclipse.pde.api.tools.internal.provisional.model.IApiElement#getAncestor(int)
48         */
49        public IApiElement getAncestor(int ancestorType) {
50                IApiElement parent = fParent;
51                while(parent != null && parent.getType() != ancestorType) {
52                        parent = parent.getParent();
53                }
54                return parent;
55        }
56 
57        /**
58         * @see org.eclipse.pde.api.tools.internal.provisional.model.IApiElement#getName()
59         */
60        public String getName() {
61                return fName;
62        }
63 
64        /**
65         * @see org.eclipse.pde.api.tools.internal.provisional.model.IApiElement#getParent()
66         */
67        public IApiElement getParent() {
68                return fParent;
69        }
70        
71        /**
72         * @see org.eclipse.pde.api.tools.internal.provisional.model.IApiElement#getType()
73         */
74        public int getType() {
75                return fType;
76        }
77 
78        /**
79         * Sets the name of this {@link ApiElement} to the new name, iff the new name
80         * is not <code>null</code>, otherwise no change is made.
81         * @param newname
82         */
83        protected void setName(String newname) {
84                if(newname != null) {
85                        fName = newname;
86                }
87        }
88        
89        /**
90         * Throws a core exception.
91         * 
92         * @param message message
93         * @param e underlying exception or <code>null</code>
94         * @throws CoreException
95         */
96        protected void abort(String message, Throwable e) throws CoreException {
97                throw new CoreException(new Status(IStatus.ERROR, ApiPlugin.PLUGIN_ID, message, e));
98        }
99        
100        /* (non-Javadoc)
101         * @see org.eclipse.pde.api.tools.internal.provisional.model.IApiElement#getApiComponent()
102         */
103        public IApiComponent getApiComponent() {
104                return (IApiComponent) getAncestor(COMPONENT);
105        }
106}

[all classes][org.eclipse.pde.api.tools.internal.model]
EMMA 2.0.5312 EclEmma Fix 1 (C) Vladimir Roubtsov