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

COVERAGE SUMMARY FOR SOURCE FILE [ApiScope.java]

nameclass, %method, %block, %line, %
ApiScope.java100% (1/1)100% (6/6)100% (144/144)100% (46/46)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ApiScope100% (1/1)100% (6/6)100% (144/144)100% (46/46)
<static initializer> 100% (1/1)100% (4/4)100% (2/2)
ApiScope (): void 100% (1/1)100% (3/3)100% (1/1)
accept (ApiScopeVisitor): void 100% (1/1)100% (77/77)100% (29/29)
addElement (IApiElement): void 100% (1/1)100% (14/14)100% (4/4)
encloses (IApiElement): boolean 100% (1/1)100% (28/28)100% (8/8)
getApiElements (): IApiElement [] 100% (1/1)100% (18/18)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.provisional.comparator;
12 
13import java.util.ArrayList;
14import java.util.Iterator;
15 
16import org.eclipse.core.runtime.CoreException;
17import org.eclipse.core.runtime.IStatus;
18import org.eclipse.core.runtime.Status;
19import org.eclipse.osgi.util.NLS;
20import org.eclipse.pde.api.tools.internal.model.Messages;
21import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
22import org.eclipse.pde.api.tools.internal.provisional.model.ApiScopeVisitor;
23import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline;
24import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
25import org.eclipse.pde.api.tools.internal.provisional.model.IApiElement;
26import org.eclipse.pde.api.tools.internal.provisional.model.IApiScope;
27import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeContainer;
28import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeRoot;
29import org.eclipse.pde.api.tools.internal.util.Util;
30 
31/**
32 * Default implementation of a {@link IApiScope}.
33 */
34public class ApiScope implements IApiScope {
35        private static final IApiElement[] NO_ELEMENTS = new IApiElement[0];
36 
37        /**
38         * Contains all API elements of this scope
39         */
40        ArrayList elements;
41 
42        /* (non-Javadoc)
43         * @see org.eclipse.pde.api.tools.internal.provisional.model.IApiScope#accept(org.eclipse.pde.api.tools.internal.provisional.model.ApiScopeVisitor)
44         */
45        public void accept(ApiScopeVisitor visitor) throws CoreException {
46                IApiElement[] elements = getApiElements();
47                for (int i = 0; i < elements.length; i++) {
48                        IApiElement apiElement = elements[i];
49                        int type = apiElement.getType();
50                        switch(type) {
51                                case IApiElement.API_TYPE_CONTAINER : {
52                                        IApiTypeContainer container = (IApiTypeContainer) apiElement;
53                                        visitor.visit(container);
54                                        visitor.endVisit(container);
55                                        break;
56                                }
57                                case IApiElement.API_TYPE_ROOT : {
58                                        IApiTypeRoot root = (IApiTypeRoot) apiElement;
59                                        visitor.visit(root);
60                                        visitor.endVisit(root);
61                                        break;
62                                }
63                                case IApiElement.BASELINE : {
64                                        IApiBaseline baseline = (IApiBaseline) apiElement;
65                                        visitor.visit(baseline);
66                                        visitor.endVisit(baseline);
67                                        break;
68                                }
69                                case IApiElement.COMPONENT : {
70                                        IApiComponent component = (IApiComponent) apiElement;
71                                        visitor.visit(component);
72                                        visitor.endVisit(component);
73                                        break;
74                                }
75                                default:
76                                        throw new CoreException(
77                                                        new Status(
78                                                                        IStatus.ERROR,
79                                                                        ApiPlugin.PLUGIN_ID,
80                                                                        NLS.bind(
81                                                                                        Messages.ApiScope_0,
82                                                                                        Util.getApiElementType(type))));
83                        }
84                }
85        }
86 
87        /* (non-Javadoc)
88         * @see org.eclipse.pde.api.tools.internal.provisional.model.IApiScope#addElement(org.eclipse.pde.api.tools.internal.provisional.model.IApiElement)
89         */
90        public void addElement(IApiElement newelement) {
91                if (this.elements == null) {
92                        this.elements = new ArrayList();
93                }
94                this.elements.add(newelement);
95        }
96 
97        /* (non-Javadoc)
98         * @see org.eclipse.pde.api.tools.internal.provisional.model.IApiScope#encloses(org.eclipse.pde.api.tools.internal.provisional.model.IApiElement)
99         */
100        public boolean encloses(IApiElement element) {
101                if(element != null) {
102                        IApiComponent component = element.getApiComponent();
103                        IApiComponent enclosing = null;
104                        for(Iterator iter = this.elements.iterator(); iter.hasNext();) {
105                                enclosing = ((IApiElement)iter.next()).getApiComponent();
106                                if(component.equals(enclosing)) {
107                                        return true;
108                                }
109                        }
110                }
111                return false;
112        }
113        
114        /* (non-Javadoc)
115         * @see org.eclipse.pde.api.tools.internal.provisional.model.IApiScope#getApiElement()
116         */
117        public IApiElement[] getApiElements() {
118                if (this.elements == null || this.elements.size() == 0) {
119                        return NO_ELEMENTS;
120                }
121                return (IApiElement[]) this.elements.toArray(new IApiElement[this.elements.size()]);
122        }
123}

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