1
/*******************************************************************************
2
* Copyright (c) 2004, 2010 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
9
* Andrew Niefer (IBM Corporation) - Initial API and implementation
10
* Markus Schorn (Wind River Systems)
11
*******************************************************************************/
12
package org.eclipse.cdt.internal.core.dom.parser.cpp;
14
import org.eclipse.cdt.core.dom.ILinkage;
15
import org.eclipse.cdt.core.dom.ast.DOMException;
16
import org.eclipse.cdt.core.dom.ast.IASTName;
17
import org.eclipse.cdt.core.dom.ast.IASTNode;
18
import org.eclipse.cdt.core.dom.ast.IBinding;
19
import org.eclipse.cdt.core.dom.ast.IScope;
20
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
21
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
22
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
23
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
24
import org.eclipse.cdt.internal.core.dom.Linkage;
25
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
26
import org.eclipse.core.runtime.PlatformObject;
28
public class CPPUsingDeclaration extends PlatformObject implements ICPPUsingDeclaration, ICPPInternalBinding {
29
private IASTName name;
30
private IBinding[] delegates;
32
public CPPUsingDeclaration(IASTName name, IBinding[] bindings) {
33
if (name instanceof ICPPASTQualifiedName) {
34
IASTName[] ns = ((ICPPASTQualifiedName) name).getNames();
35
name = ns[ns.length - 1];
38
this.delegates= bindings;
41
public IBinding[] getDelegates() {
45
public String[] getQualifiedName() {
46
return CPPVisitor.getQualifiedName(this);
49
public char[][] getQualifiedNameCharArray() {
50
return CPPVisitor.getQualifiedNameCharArray(this);
53
public boolean isGloballyQualified() throws DOMException {
54
IScope scope = getScope();
55
while (scope != null) {
56
if(scope instanceof ICPPBlockScope)
58
scope = scope.getParent();
63
public String getName() {
64
return new String(getNameCharArray());
67
public char[] getNameCharArray() {
68
return name.getSimpleID();
71
public IScope getScope() {
72
return CPPVisitor.getContainingScope(name.getParent());
75
public IASTNode[] getDeclarations() {
79
public IASTNode getDefinition() {
80
IASTNode n = name.getParent();
81
if (n instanceof ICPPASTTemplateId)
87
public void addDefinition(IASTNode node) {
90
public void addDeclaration(IASTNode node) {
93
public ILinkage getLinkage() {
94
return Linkage.CPP_LINKAGE;
97
public IBinding getOwner() {
98
return CPPVisitor.findDeclarationOwner(name, true);
102
public String toString() {
103
IASTNode node = name.getParent();
104
if (node instanceof ICPPASTQualifiedName) {
105
return node.toString();
107
return super.toString();