Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c2869eeb957dc43679561a0a67eeaf1d8e16fc2b (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
/*******************************************************************************
 * Copyright (c) 2008 Wind River Systems, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Markus Schorn - initial API and implementation
 *******************************************************************************/ 
package org.eclipse.cdt.internal.core.dom.parser.cpp;

import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;

/**
 * Represents a using-directive found in the AST.
 */
public class CPPUsingDirective implements ICPPUsingDirective {

	private IASTName fNamespaceName;

	/**
	 * Constructor for explicit using directives
	 */
	public CPPUsingDirective(ICPPASTUsingDirective node) {
		fNamespaceName= node.getQualifiedName();
	}

	/**
	 * Constructor for unnamed namespaces introducing an implicit using directive.
	 */
	public CPPUsingDirective(ICPPASTNamespaceDefinition nsdef) {
		fNamespaceName= nsdef.getName();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective#getNamespaceScope()
	 */
	public ICPPNamespaceScope getNominatedScope() throws DOMException {
		IBinding binding= fNamespaceName.resolveBinding();
		if (binding instanceof ICPPNamespace) {
			return ((ICPPNamespace) binding).getNamespaceScope();
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective#getPointOfDeclaration()
	 */
	public int getPointOfDeclaration() {
		final ASTNode astNode = (ASTNode) fNamespaceName;
		return astNode.getOffset() + astNode.getLength();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective#getContainingScope()
	 */
	public IScope getContainingScope() {
		return CPPVisitor.getContainingScope(fNamespaceName);
	}

	@Override
	public String toString() {
		return fNamespaceName.toString();
	}
}

Back to the top