1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2009-05-31 00:29:07 +00:00
parent fc4176c35f
commit aecdc9e38c

View file

@ -37,54 +37,54 @@ import org.eclipse.core.runtime.PlatformObject;
*/ */
public class CEnumeration extends PlatformObject implements IEnumeration, ICInternalBinding { public class CEnumeration extends PlatformObject implements IEnumeration, ICInternalBinding {
private IASTName [] declarations = null; private IASTName[] declarations = null;
private IASTName definition = null; private IASTName definition = null;
public CEnumeration( IASTName enumeration ){ public CEnumeration(IASTName enumeration) {
ASTNodeProperty prop = enumeration.getPropertyInParent(); ASTNodeProperty prop = enumeration.getPropertyInParent();
if( prop == IASTElaboratedTypeSpecifier.TYPE_NAME ) if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME)
declarations = new IASTName[] { enumeration }; declarations = new IASTName[] { enumeration };
else else
definition = enumeration; definition = enumeration;
enumeration.setBinding( this ); enumeration.setBinding(this);
} }
public void addDeclaration(IASTName decl) { public void addDeclaration(IASTName decl) {
if (!decl.isActive()) if (!decl.isActive())
return; return;
if( decl.getPropertyInParent() != IASTElaboratedTypeSpecifier.TYPE_NAME ) if (decl.getPropertyInParent() != IASTElaboratedTypeSpecifier.TYPE_NAME)
return; return;
decl.setBinding( this ); decl.setBinding(this);
if( declarations == null ){ if (declarations == null) {
declarations = new IASTName[] { decl }; declarations = new IASTName[] { decl };
return; return;
} }
for( int i = 0; i < declarations.length; i++ ){ for (int i = 0; i < declarations.length; i++) {
if( declarations[i] == null ){ if (declarations[i] == null) {
declarations[i] = decl; declarations[i] = decl;
return; return;
} }
} }
IASTName tmp [] = new IASTName [ declarations.length * 2 ]; IASTName tmp[] = new IASTName[declarations.length * 2];
System.arraycopy( declarations, 0, tmp, 0, declarations.length ); System.arraycopy(declarations, 0, tmp, 0, declarations.length);
tmp[ declarations.length ] = decl; tmp[declarations.length] = decl;
declarations = tmp; declarations = tmp;
} }
public IASTNode getPhysicalNode(){ public IASTNode getPhysicalNode() {
if( definition != null ) if (definition != null)
return definition; return definition;
return declarations[0]; return declarations[0];
} }
private void checkForDefinition(){ private void checkForDefinition() {
IASTDeclSpecifier spec = CVisitor.findDefinition( (ICASTElaboratedTypeSpecifier) declarations[0].getParent() ); IASTDeclSpecifier spec = CVisitor.findDefinition((ICASTElaboratedTypeSpecifier) declarations[0].getParent());
if( spec != null && spec instanceof ICASTEnumerationSpecifier ){ if (spec != null && spec instanceof ICASTEnumerationSpecifier) {
ICASTEnumerationSpecifier enumSpec = (ICASTEnumerationSpecifier) spec; ICASTEnumerationSpecifier enumSpec = (ICASTEnumerationSpecifier) spec;
enumSpec.getName().setBinding( this ); enumSpec.getName().setBinding(this);
definition = enumSpec.getName(); definition = enumSpec.getName();
} }
return; return;
@ -94,13 +94,13 @@ public class CEnumeration extends PlatformObject implements IEnumeration, ICInte
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName() * @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
*/ */
public String getName() { public String getName() {
if( definition != null ) if (definition != null)
return definition.toString(); return definition.toString();
return declarations[0].toString(); return declarations[0].toString();
} }
public char[] getNameCharArray(){ public char[] getNameCharArray() {
if( definition != null ) if (definition != null)
return definition.toCharArray(); return definition.toCharArray();
return declarations[0].toCharArray(); return declarations[0].toCharArray();
@ -110,15 +110,15 @@ public class CEnumeration extends PlatformObject implements IEnumeration, ICInte
* @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 CVisitor.getContainingScope( definition != null ? definition : declarations[0].getParent() ); return CVisitor.getContainingScope(definition != null ? definition : declarations[0].getParent());
} }
@Override @Override
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;
@ -128,17 +128,17 @@ public class CEnumeration extends PlatformObject implements IEnumeration, ICInte
* @see org.eclipse.cdt.core.dom.ast.IEnumeration#getEnumerators() * @see org.eclipse.cdt.core.dom.ast.IEnumeration#getEnumerators()
*/ */
public IEnumerator[] getEnumerators() { public IEnumerator[] getEnumerators() {
if( definition == null ){ if (definition == null) {
checkForDefinition(); checkForDefinition();
if( definition == null ) if (definition == null)
return new IEnumerator[] { new CEnumerator.CEnumeratorProblem( declarations[0], IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, declarations[0].toCharArray() ) }; return new IEnumerator[] { new CEnumerator.CEnumeratorProblem(declarations[0], IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, declarations[0].toCharArray()) };
} }
IASTEnumerationSpecifier enumSpec = (IASTEnumerationSpecifier) definition.getParent(); IASTEnumerationSpecifier enumSpec = (IASTEnumerationSpecifier) definition.getParent();
IASTEnumerationSpecifier.IASTEnumerator[] enums = enumSpec.getEnumerators(); IASTEnumerationSpecifier.IASTEnumerator[] enums = enumSpec.getEnumerators();
IEnumerator [] bindings = new IEnumerator [ enums.length ]; IEnumerator[] bindings = new IEnumerator[enums.length];
for( int i = 0; i < enums.length; i++ ){ for (int i = 0; i < enums.length; i++) {
bindings[i] = (IEnumerator) enums[i].getName().resolveBinding(); bindings[i] = (IEnumerator) enums[i].getName().resolveBinding();
} }
return bindings; return bindings;
@ -152,11 +152,11 @@ public class CEnumeration extends PlatformObject implements IEnumeration, ICInte
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType) * @see org.eclipse.cdt.core.dom.ast.IType#isSameType(org.eclipse.cdt.core.dom.ast.IType)
*/ */
public boolean isSameType( IType type ) { public boolean isSameType(IType type) {
if( type == this ) if (type == this)
return true; return true;
if( type instanceof ITypedef || type instanceof IIndexType) if (type instanceof ITypedef || type instanceof IIndexType)
return type.isSameType( this ); return type.isSameType(this);
return false; return false;
} }