Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 227705733ce554160acb6469588634fb7e8f8397 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*******************************************************************************
 * Copyright (c) 2007, 2009 Wind River Systems, Inc. and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *    Markus Schorn - initial API and implementation
 *    Andrew Ferguson (Symbian)
 *******************************************************************************/ 

package org.eclipse.cdt.internal.core.index;

import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.internal.core.index.composite.CompositeIndexBinding;
import org.eclipse.core.runtime.CoreException;

public class DeclaredBindingsFilter extends IndexFilter {
	final private int fLinkageID;
	final private boolean fAcceptImplicit;
	final private boolean fAllowInstances;

	public DeclaredBindingsFilter() {
		this(-1, false, true);
	}
	
	public DeclaredBindingsFilter(int linkageID, boolean acceptImplicit, boolean allowInstances) {
		fLinkageID= linkageID;
		fAcceptImplicit= acceptImplicit;
		fAllowInstances= allowInstances;
	}
	
	@Override
	public boolean acceptLinkage(ILinkage linkage) {
		return fLinkageID == -1 || fLinkageID == linkage.getLinkageID();
	}

	@Override
	public boolean acceptBinding(IBinding binding) throws CoreException {
		if (!fAllowInstances && binding instanceof ICPPTemplateInstance)
			return false;
		
		if (binding instanceof IIndexFragmentBinding) {
			return  ((IIndexFragmentBinding) binding).hasDeclaration()
					|| (fAcceptImplicit && isImplicit(binding));
		}
		// composite bindings don't support that kind of check.
		if (binding instanceof CompositeIndexBinding) {
			IIndexBinding raw= ((CompositeIndexBinding) binding).getRawBinding();
			if (raw instanceof IIndexFragmentBinding) {
				if (((IIndexFragmentBinding) raw).hasDeclaration()) {
					return true;
				}
			}
		}
		return fAcceptImplicit || !isImplicit(binding);	
	}

	private boolean isImplicit(IBinding binding) {
		if (binding instanceof ICPPSpecialization)
			return true;
		if (binding instanceof ICPPMethod) { 
			return ((ICPPMethod) binding).isImplicit();
		}
		return false;
	}
}

Back to the top