]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 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.jdt.internal.corext.util; | |
12 | ||
13 | import java.util.Collection; | |
14 | ||
15 | import org.eclipse.core.runtime.Assert; | |
16 | ||
17 | import org.eclipse.jdt.core.IAccessRule; | |
18 | import org.eclipse.jdt.core.JavaCore; | |
19 | import org.eclipse.jdt.core.search.TypeNameMatch; | |
20 | import org.eclipse.jdt.core.search.TypeNameMatchRequestor; | |
21 | ||
22 | public class TypeNameMatchCollector extends TypeNameMatchRequestor { | |
23 | ||
24 | private final Collection<TypeNameMatch> fCollection; | |
25 | ||
26 | public TypeNameMatchCollector(Collection<TypeNameMatch> collection) { | |
27 | Assert.isNotNull(collection); | |
28 | fCollection= collection; | |
29 | } | |
30 | ||
31 | private boolean inScope(TypeNameMatch match) { | |
32 | if (TypeFilter.isFiltered(match)) | |
33 | return false; | |
34 | ||
35 | int accessibility= match.getAccessibility(); | |
36 | switch (accessibility) { | |
37 | case IAccessRule.K_NON_ACCESSIBLE: | |
38 | return JavaCore.DISABLED.equals(JavaCore.getOption(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK)); | |
39 | case IAccessRule.K_DISCOURAGED: | |
40 | return JavaCore.DISABLED.equals(JavaCore.getOption(JavaCore.CODEASSIST_DISCOURAGED_REFERENCE_CHECK)); | |
41 | default: | |
42 | return true; | |
43 | } | |
44 | } | |
45 | ||
46 | /* (non-Javadoc) | |
47 | * @see org.eclipse.jdt.core.search.TypeNameMatchRequestor#acceptTypeNameMatch(org.eclipse.jdt.core.search.TypeNameMatch) | |
48 | */ | |
49 | @Override | |
50 | public void acceptTypeNameMatch(TypeNameMatch match) { | |
51 | if (inScope(match)) { | |
52 | fCollection.add(match); | |
53 | } | |
54 | } | |
55 | ||
56 | } |