1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-14 11:45:38 +02:00

Pretty printing qualified names.

This commit is contained in:
John Camelon 2005-02-08 14:59:35 +00:00
parent cc8d114f90
commit e20bdb8813
2 changed files with 128 additions and 119 deletions

View file

@ -17,7 +17,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
/** /**
* @author jcamelon * @author jcamelon
*/ */
public class CPPASTQualifiedName extends CPPASTNode implements ICPPASTQualifiedName { public class CPPASTQualifiedName extends CPPASTNode implements
ICPPASTQualifiedName {
/** /**
* @param duple * @param duple
@ -25,7 +26,9 @@ public class CPPASTQualifiedName extends CPPASTNode implements ICPPASTQualifiedN
public CPPASTQualifiedName() { public CPPASTQualifiedName() {
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTName#resolveBinding() * @see org.eclipse.cdt.core.dom.ast.IASTName#resolveBinding()
*/ */
public IBinding resolveBinding() { public IBinding resolveBinding() {
@ -34,39 +37,26 @@ public class CPPASTQualifiedName extends CPPASTNode implements ICPPASTQualifiedN
return names[names.length - 1].resolveBinding(); return names[names.length - 1].resolveBinding();
} }
/*
* (non-Javadoc)
/* (non-Javadoc) *
* @see java.lang.Object#toString() * @see java.lang.Object#toString()
*/ */
public String toString() { public String toString() {
if( names == null ) return null; return signature;
removeNullNames();
StringBuffer buffer = new StringBuffer();
for( int i = 0; i < names.length; ++i )
{
String n = names[i].toString();
if( n == null )
return null;
buffer.append( n );
if( i != names.length - 1 )
buffer.append( "::"); //$NON-NLS-1$
}
return buffer.toString();
} }
/*
/* (non-Javadoc) * (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName#addName(org.eclipse.cdt.core.dom.ast.IASTName) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName#addName(org.eclipse.cdt.core.dom.ast.IASTName)
*/ */
public void addName(IASTName name) { public void addName(IASTName name) {
if( names == null ) if (names == null) {
{
names = new IASTName[DEFAULT_NAMES_LIST_SIZE]; names = new IASTName[DEFAULT_NAMES_LIST_SIZE];
currentIndex = 0; currentIndex = 0;
} }
if( names.length == currentIndex ) if (names.length == currentIndex) {
{
IASTName[] old = names; IASTName[] old = names;
names = new IASTName[old.length * 2]; names = new IASTName[old.length * 2];
for (int i = 0; i < old.length; ++i) for (int i = 0; i < old.length; ++i)
@ -83,7 +73,8 @@ public class CPPASTQualifiedName extends CPPASTNode implements ICPPASTQualifiedN
for (int i = 0; i < names.length; ++i) for (int i = 0; i < names.length; ++i)
if (names[i] == null) if (names[i] == null)
++nullCount; ++nullCount;
if( nullCount == 0 ) return; if (nullCount == 0)
return;
IASTName[] old = names; IASTName[] old = names;
int newSize = old.length - nullCount; int newSize = old.length - nullCount;
names = new IASTName[newSize]; names = new IASTName[newSize];
@ -96,27 +87,33 @@ public class CPPASTQualifiedName extends CPPASTNode implements ICPPASTQualifiedN
private IASTName[] names = null; private IASTName[] names = null;
private static final int DEFAULT_NAMES_LIST_SIZE = 4; private static final int DEFAULT_NAMES_LIST_SIZE = 4;
private boolean value; private boolean value;
private String signature;
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName#getNames() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName#getNames()
*/ */
public IASTName[] getNames() { public IASTName[] getNames() {
if( names == null ) return IASTName.EMPTY_NAME_ARRAY; if (names == null)
return IASTName.EMPTY_NAME_ARRAY;
removeNullNames(); removeNullNames();
return names; return names;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTName#toCharArray() * @see org.eclipse.cdt.core.dom.ast.IASTName#toCharArray()
*/ */
public char[] toCharArray() { public char[] toCharArray() {
if( names == null ) return null; if (names == null)
return null;
removeNullNames(); removeNullNames();
//count first //count first
int len = 0; int len = 0;
for( int i = 0; i < names.length; ++i ) for (int i = 0; i < names.length; ++i) {
{
char[] n = names[i].toCharArray(); char[] n = names[i].toCharArray();
if (n == null) if (n == null)
return null; return null;
@ -139,19 +136,30 @@ public class CPPASTQualifiedName extends CPPASTNode implements ICPPASTQualifiedN
return nameArray; return nameArray;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName#isFullyQualified() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName#isFullyQualified()
*/ */
public boolean isFullyQualified() { public boolean isFullyQualified() {
return value; return value;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName#setFullyQualified(boolean) * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName#setFullyQualified(boolean)
*/ */
public void setFullyQualified(boolean value) { public void setFullyQualified(boolean value) {
this.value = value; this.value = value;
} }
/**
* @param string
*/
public void setValue(String string) {
this.signature = string;
}
} }

View file

@ -2486,6 +2486,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
CPPASTQualifiedName result = new CPPASTQualifiedName(); CPPASTQualifiedName result = new CPPASTQualifiedName();
result.setOffsetAndLength(duple.getStartOffset(), duple.getEndOffset() result.setOffsetAndLength(duple.getStartOffset(), duple.getEndOffset()
- duple.getStartOffset()); - duple.getStartOffset());
result.setValue( duple.toString() );
ITokenDuple[] segments = duple.getSegments(); ITokenDuple[] segments = duple.getSegments();
int startingValue = 0; int startingValue = 0;
if( segments.length > 0 && if( segments.length > 0 &&