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

COVERAGE SUMMARY FOR SOURCE FILE [UseSearchRequestor.java]

nameclass, %method, %block, %line, %
UseSearchRequestor.java0%   (0/1)0%   (0/12)0%   (0/214)0%   (0/56)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class UseSearchRequestor0%   (0/1)0%   (0/12)0%   (0/214)0%   (0/56)
UseSearchRequestor (Set, IApiElement [], int): void 0%   (0/1)0%   (0/24)0%   (0/9)
acceptComponent (IApiComponent): boolean 0%   (0/1)0%   (0/2)0%   (0/1)
acceptContainer (IApiTypeContainer): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
acceptMember (IApiMember): boolean 0%   (0/1)0%   (0/18)0%   (0/4)
acceptReference (IReference): boolean 0%   (0/1)0%   (0/62)0%   (0/18)
considerTypeContainer (IApiTypeContainer): boolean 0%   (0/1)0%   (0/52)0%   (0/11)
getReferenceKinds (): int 0%   (0/1)0%   (0/4)0%   (0/2)
getScope (): IApiScope 0%   (0/1)0%   (0/3)0%   (0/1)
includesAPI (): boolean 0%   (0/1)0%   (0/9)0%   (0/1)
includesInternal (): boolean 0%   (0/1)0%   (0/9)0%   (0/1)
prepareScope (IApiElement []): void 0%   (0/1)0%   (0/23)0%   (0/5)
setJarPatterns (String []): void 0%   (0/1)0%   (0/4)0%   (0/2)

1/*******************************************************************************
2 * Copyright (c) 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.search;
12 
13import java.util.Set;
14 
15import org.eclipse.core.runtime.CoreException;
16import org.eclipse.pde.api.tools.internal.provisional.IApiAnnotations;
17import org.eclipse.pde.api.tools.internal.provisional.VisibilityModifiers;
18import org.eclipse.pde.api.tools.internal.provisional.builder.IReference;
19import org.eclipse.pde.api.tools.internal.provisional.comparator.ApiScope;
20import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
21import org.eclipse.pde.api.tools.internal.provisional.model.IApiElement;
22import org.eclipse.pde.api.tools.internal.provisional.model.IApiMember;
23import org.eclipse.pde.api.tools.internal.provisional.model.IApiScope;
24import org.eclipse.pde.api.tools.internal.provisional.model.IApiType;
25import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeContainer;
26import org.eclipse.pde.api.tools.internal.provisional.search.IApiSearchRequestor;
27 
28/**
29 * Default implementation of an {@link IApiSearchRequestor} to use with the
30 * {@link ApiSearchEngine}. This requestor returns a search scope
31 * composed of the dependent (visible) {@link IApiComponent}s for the given 
32 * {@link IApiElement}
33 * 
34 * @since 1.0.0
35 */
36public class UseSearchRequestor implements IApiSearchRequestor {
37 
38        /**
39         * The backing elements to search with
40         */
41        private Set fComponentIds = null;
42 
43        /**
44         * The mask to use while searching
45         */
46        private int fSearchMask = 0;
47        
48        /**
49         * The search scope for this requestor
50         */
51        private IApiScope fScope = null;
52        
53        /**
54         * Patterns for jar API type roots to not scan
55         */
56        private String[] jarPatterns = null;
57        
58        /**
59         * Constructor
60         * @param elements an array of {@link IApiElement}s for the search engine to use
61         * @param scope the raw list of {@link IApiElement}s to extract references from
62         * @param searchkinds the kinds of references to search for. 
63         * <br>Options include: 
64         * <ol>
65         * <li>{@link #INCLUDE_API}</li>
66         * <li>{@link #INCLUDE_INTERNAL}</li>
67         * </ol>
68         */
69        public UseSearchRequestor(Set/*<String>*/ elementnames, IApiElement[] scope, int searchkinds) {
70                fSearchMask = searchkinds;
71                fComponentIds = elementnames;
72                prepareScope(scope);
73        }
74        
75        /* (non-Javadoc)
76         * @see org.eclipse.pde.api.tools.internal.provisional.search.IApiSearchRequestor#acceptComponent(org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent)
77         */
78        public boolean acceptComponent(IApiComponent component) {
79                return true; //fComponentIds.contains(component);
80        }
81        
82        /* (non-Javadoc)
83         * @see org.eclipse.pde.api.tools.internal.provisional.search.IApiSearchRequestor#acceptContainer(org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeContainer)
84         */
85        public boolean acceptContainer(IApiTypeContainer container) {
86                return considerTypeContainer(container);
87        }
88        
89        /* (non-Javadoc)
90         * @see org.eclipse.pde.api.tools.internal.provisional.search.IApiSearchRequestor#acceptMember(org.eclipse.pde.api.tools.internal.provisional.model.IApiMember)
91         */
92        public boolean acceptMember(IApiMember member) {
93                // don't consider inner types, as they are considered with the root type
94                switch(member.getType()) {
95                        case IApiElement.TYPE: {
96                                IApiType type = (IApiType) member;
97                                return !(type.isMemberType() || type.isLocal());
98                        }
99                }
100                return true;
101        }
102        
103        /**
104         * Returns if the given {@link IApiTypeContainer} should be processed
105         * @param container
106         * @return true if the container should be processed false otherwise
107         */
108        boolean considerTypeContainer(IApiTypeContainer container) {
109                if(jarPatterns != null && container != null) {
110                        if(container.getContainerType() == IApiTypeContainer.ARCHIVE) {
111                                String[] pparts = null;
112                                for (int i = 0; i < jarPatterns.length; i++) {
113                                        pparts = jarPatterns[i].split(":"); //$NON-NLS-1$
114                                        if(pparts.length != 2) {
115                                                continue;
116                                        }
117                                        if(container.getApiComponent().getId().equals(pparts[0])) {
118                                                if(container.getName().endsWith(pparts[1])) {
119                                                        return false;
120                                                }
121                                        }
122                                }
123                        }
124                }
125                return true;
126        }
127        
128        /* (non-Javadoc)
129         * @see org.eclipse.pde.api.tools.internal.provisional.search.IApiSearchRequestor#acceptReference(org.eclipse.pde.api.tools.internal.provisional.builder.IReference)
130         */
131        public boolean acceptReference(IReference reference) {
132                try {
133                        IApiMember member = reference.getResolvedReference();
134                        if(member != null) {
135                                IApiComponent component = member.getApiComponent();
136                                if(!fComponentIds.contains(component.getId())) {
137                                        return false;
138                                }
139                                if(component.equals(reference.getMember().getApiComponent())) {
140                                        return false;
141                                }
142                                if(includesAPI() && includesInternal()) {
143                                        return true;
144                                }
145                                IApiAnnotations annots = component.getApiDescription().resolveAnnotations(member.getHandle());
146                                if(annots != null) {
147                                        int vis = annots.getVisibility();
148                                        if(VisibilityModifiers.isAPI(vis) && includesAPI()) {
149                                                return true;
150                                        }
151                                        else if(VisibilityModifiers.isPrivate(vis) && includesInternal()) {
152                                                return true;
153                                        }
154                                }
155                        }
156                }
157                catch(CoreException ce) {
158                        //ApiPlugin.log(ce);
159                }
160                return false;
161        }
162        
163        /* (non-Javadoc)
164         * @see org.eclipse.pde.api.tools.internal.provisional.search.IApiSearchRequestor#getReferenceKinds()
165         */
166        public int getReferenceKinds() {
167                int kinds = IReference.MASK_REF_ALL & ~IReference.REF_CONSTANTPOOL;
168                return kinds;
169        }
170        
171        /**
172         * Prepares the search scope based on the available entries in the constructor
173         * @param elements
174         */
175        private void prepareScope(IApiElement[] elements) {
176                if(elements != null) {
177                        fScope = new ApiScope();
178                        for(int i = 0; i < elements.length; i++) {
179                                fScope.addElement(elements[i].getApiComponent());
180                        }
181                }
182        }
183        
184        /* (non-Javadoc)
185         * @see org.eclipse.pde.api.tools.internal.provisional.search.IApiSearchRequestor#getScope()
186         */
187        public IApiScope getScope() {
188                return fScope;
189        }
190        
191        /* (non-Javadoc)
192         * @see org.eclipse.pde.api.tools.internal.provisional.search.IApiSearchRequestor#includesAPI()
193         */
194        public boolean includesAPI() {
195                return (fSearchMask & INCLUDE_API) > 0;
196        }
197        
198        /* (non-Javadoc)
199         * @see org.eclipse.pde.api.tools.internal.provisional.search.IApiSearchRequestor#includesInternal()
200         */
201        public boolean includesInternal() {
202                return (fSearchMask & INCLUDE_INTERNAL) > 0;
203        }
204        
205        /**
206         * The patterns for jar names to exclude from the search
207         * @param patterns
208         */
209        public void setJarPatterns(String[] patterns) {
210                jarPatterns = patterns;
211        }
212}

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