mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Added toString method.
This commit is contained in:
parent
8111176e94
commit
9d578b5f13
1 changed files with 48 additions and 41 deletions
|
@ -33,29 +33,30 @@ import org.eclipse.core.runtime.PlatformObject;
|
||||||
*/
|
*/
|
||||||
public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContainer, ICPPInternalBinding {
|
public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContainer, ICPPInternalBinding {
|
||||||
public static class CPPTypedefDelegate extends CPPDelegate implements ITypedef, ITypeContainer {
|
public static class CPPTypedefDelegate extends CPPDelegate implements ITypedef, ITypeContainer {
|
||||||
public CPPTypedefDelegate( ICPPUsingDeclaration name, ITypedef binding ) {
|
public CPPTypedefDelegate(ICPPUsingDeclaration name, ITypedef binding) {
|
||||||
super( name, binding );
|
super(name, binding);
|
||||||
}
|
}
|
||||||
public IType getType() throws DOMException {
|
public IType getType() throws DOMException {
|
||||||
return ((ITypedef)getBinding()).getType();
|
return ((ITypedef)getBinding()).getType();
|
||||||
}
|
}
|
||||||
public boolean isSameType( IType type ) {
|
public boolean isSameType(IType type) {
|
||||||
return ((ITypedef)getBinding()).isSameType( type );
|
return ((ITypedef)getBinding()).isSameType(type);
|
||||||
}
|
}
|
||||||
public void setType(IType type) {
|
public void setType(IType type) {
|
||||||
((ITypeContainer)getBinding()).setType( type );
|
((ITypeContainer)getBinding()).setType(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private IASTName [] declarations = null;
|
|
||||||
|
private IASTName[] declarations = null;
|
||||||
private IType type = null;
|
private IType type = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param declarator
|
* @param declarator
|
||||||
*/
|
*/
|
||||||
public CPPTypedef(IASTName name) {
|
public CPPTypedef(IASTName name) {
|
||||||
this.declarations = new IASTName[] { name };
|
this.declarations = new IASTName[] { name };
|
||||||
if (name != null)
|
if (name != null)
|
||||||
name.setBinding( this );
|
name.setBinding(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -72,36 +73,37 @@ public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContain
|
||||||
return declarations[0];
|
return declarations[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSameType( IType o ){
|
public boolean isSameType(IType o) {
|
||||||
if( o == this )
|
if (o == this)
|
||||||
return true;
|
return true;
|
||||||
if( o instanceof ITypedef )
|
if (o instanceof ITypedef) {
|
||||||
try {
|
try {
|
||||||
IType t = getType();
|
IType t = getType();
|
||||||
if( t != null )
|
if (t != null)
|
||||||
return t.isSameType( ((ITypedef)o).getType());
|
return t.isSameType(((ITypedef)o).getType());
|
||||||
return false;
|
return false;
|
||||||
} catch ( DOMException e ) {
|
} catch (DOMException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
IType t = getType();
|
IType t = getType();
|
||||||
if( t != null )
|
if (t != null)
|
||||||
return t.isSameType( o );
|
return t.isSameType(o);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.ITypedef#getType()
|
* @see org.eclipse.cdt.core.dom.ast.ITypedef#getType()
|
||||||
*/
|
*/
|
||||||
public IType getType() {
|
public IType getType() {
|
||||||
if( type == null ){
|
if (type == null) {
|
||||||
type = CPPVisitor.createType( (IASTDeclarator) declarations[0].getParent() );
|
type = CPPVisitor.createType((IASTDeclarator) declarations[0].getParent());
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType( IType t ){
|
public void setType(IType t) {
|
||||||
type = t;
|
type = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,14 +125,14 @@ public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContain
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
|
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
|
||||||
*/
|
*/
|
||||||
public IScope getScope() {
|
public IScope getScope() {
|
||||||
return CPPVisitor.getContainingScope( declarations[0].getParent() );
|
return CPPVisitor.getContainingScope(declarations[0].getParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone(){
|
public Object clone() {
|
||||||
IType t = null;
|
IType t = null;
|
||||||
try {
|
try {
|
||||||
t = (IType) super.clone();
|
t = (IType) super.clone();
|
||||||
} catch ( CloneNotSupportedException e ) {
|
} catch (CloneNotSupportedException e) {
|
||||||
//not going to happen
|
//not going to happen
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
|
@ -139,14 +141,14 @@ public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContain
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getFullyQualifiedName()
|
* @see org.eclipse.cdt.core.dom.ast.IBinding#getFullyQualifiedName()
|
||||||
*/
|
*/
|
||||||
public String[] getQualifiedName() {
|
public String[] getQualifiedName() {
|
||||||
return CPPVisitor.getQualifiedName( this );
|
return CPPVisitor.getQualifiedName(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IBinding#getFullyQualifiedNameCharArray()
|
* @see org.eclipse.cdt.core.dom.ast.IBinding#getFullyQualifiedNameCharArray()
|
||||||
*/
|
*/
|
||||||
public char[][] getQualifiedNameCharArray() {
|
public char[][] getQualifiedNameCharArray() {
|
||||||
return CPPVisitor.getQualifiedNameCharArray( this );
|
return CPPVisitor.getQualifiedNameCharArray(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -154,8 +156,8 @@ public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContain
|
||||||
*/
|
*/
|
||||||
public boolean isGloballyQualified() throws DOMException {
|
public boolean isGloballyQualified() throws DOMException {
|
||||||
IScope scope = getScope();
|
IScope scope = getScope();
|
||||||
while( scope != null ){
|
while(scope != null) {
|
||||||
if( scope instanceof ICPPBlockScope )
|
if (scope instanceof ICPPBlockScope)
|
||||||
return false;
|
return false;
|
||||||
scope = scope.getParent();
|
scope = scope.getParent();
|
||||||
}
|
}
|
||||||
|
@ -165,42 +167,47 @@ public class CPPTypedef extends PlatformObject implements ITypedef, ITypeContain
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#createDelegate(org.eclipse.cdt.core.dom.ast.IASTName)
|
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#createDelegate(org.eclipse.cdt.core.dom.ast.IASTName)
|
||||||
*/
|
*/
|
||||||
public ICPPDelegate createDelegate(ICPPUsingDeclaration usingDecl ) {
|
public ICPPDelegate createDelegate(ICPPUsingDeclaration usingDecl) {
|
||||||
return new CPPTypedefDelegate( usingDecl, this );
|
return new CPPTypedefDelegate(usingDecl, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDefinition(org.eclipse.cdt.core.dom.ast.IASTNode)
|
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDefinition(org.eclipse.cdt.core.dom.ast.IASTNode)
|
||||||
*/
|
*/
|
||||||
public void addDefinition(IASTNode node) {
|
public void addDefinition(IASTNode node) {
|
||||||
addDeclaration( node );
|
addDeclaration(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDeclaration(org.eclipse.cdt.core.dom.ast.IASTNode)
|
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDeclaration(org.eclipse.cdt.core.dom.ast.IASTNode)
|
||||||
*/
|
*/
|
||||||
public void addDeclaration(IASTNode node) {
|
public void addDeclaration(IASTNode node) {
|
||||||
if( !(node instanceof IASTName) )
|
if (!(node instanceof IASTName))
|
||||||
return;
|
return;
|
||||||
IASTName name = (IASTName) node;
|
IASTName name = (IASTName) node;
|
||||||
|
|
||||||
if( declarations == null )
|
if (declarations == null) {
|
||||||
declarations = new IASTName[] { name };
|
declarations = new IASTName[] { name };
|
||||||
else {
|
} else {
|
||||||
//keep the lowest offset declaration in [0]
|
// keep the lowest offset declaration in [0]
|
||||||
if( declarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode)declarations[0]).getOffset() ){
|
if (declarations.length > 0 &&
|
||||||
declarations = (IASTName[]) ArrayUtil.prepend( IASTName.class, declarations, name );
|
((ASTNode )node).getOffset() < ((ASTNode) declarations[0]).getOffset()) {
|
||||||
|
declarations = (IASTName[]) ArrayUtil.prepend(IASTName.class, declarations, name);
|
||||||
} else {
|
} else {
|
||||||
declarations = (IASTName[]) ArrayUtil.append( IASTName.class, declarations, name );
|
declarations = (IASTName[]) ArrayUtil.append(IASTName.class, declarations, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeDeclaration(IASTNode node) {
|
public void removeDeclaration(IASTNode node) {
|
||||||
ArrayUtil.remove(declarations, node);
|
ArrayUtil.remove(declarations, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ILinkage getLinkage() {
|
public ILinkage getLinkage() {
|
||||||
return Linkage.CPP_LINKAGE;
|
return Linkage.CPP_LINKAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return getName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue