1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 02:06:01 +02:00

Patch for Hoda Amer:

- Delta Builder Helper Functions in the CModel
- Plus some cleanups
This commit is contained in:
Doug Schaefer 2003-04-04 14:01:31 +00:00
parent 3b0adc309f
commit c045393b50
19 changed files with 114 additions and 173 deletions

View file

@ -8,9 +8,4 @@ package org.eclipse.cdt.core.model;
* Represents a package declaration in a C translation unit. * Represents a package declaration in a C translation unit.
*/ */
public interface INamespace extends ICElement, IParent, ISourceManipulation, ISourceReference { public interface INamespace extends ICElement, IParent, ISourceManipulation, ISourceReference {
/**
* Returns the name of the package the statement refers to.
* This is a handle-only method.
*/
String getElementName();
} }

View file

@ -9,8 +9,4 @@ package org.eclipse.cdt.core.model;
* Represents a field declared in a type. * Represents a field declared in a type.
*/ */
public interface ITypeDef extends ICElement, ISourceManipulation, ISourceReference { public interface ITypeDef extends ICElement, ISourceManipulation, ISourceReference {
/**
* Return the type beeing alias.
*/
String getType() throws CModelException;
} }

View file

@ -185,7 +185,7 @@ public abstract class CElement extends PlatformObject implements ICElement {
return false; return false;
if (fType != other.fType) if (fType != other.fType)
return false; return false;
if (other.fName != null && fName.equals(other.fName)) { if (fName.equals(other.fName)) {
if (fParent != null && fParent.equals(other.fParent)) { if (fParent != null && fParent.equals(other.fParent)) {
return true; return true;
} }

View file

@ -16,19 +16,17 @@ import org.eclipse.cdt.core.model.IEnumeration;
public class Enumeration extends SourceManipulation implements IEnumeration{ public class Enumeration extends SourceManipulation implements IEnumeration{
String typeName = "";
boolean isStatic = false;
boolean isConst = false;
boolean isVolatile = false;
public Enumeration(ICElement parent, String name) { public Enumeration(ICElement parent, String name) {
super(parent, name, CElement.C_ENUMERATION); super(parent, name, CElement.C_ENUMERATION);
} }
protected CElementInfo createElementInfo () { protected CElementInfo createElementInfo () {
return new SourceManipulationInfo(this); return new EnumerationInfo(this);
} }
private EnumerationInfo getEnumerationInfo(){
return (EnumerationInfo) getElementInfo();
}
/** /**
* @see org.eclipse.cdt.core.model.IVariable#getInitializer() * @see org.eclipse.cdt.core.model.IVariable#getInitializer()
*/ */
@ -40,14 +38,14 @@ public class Enumeration extends SourceManipulation implements IEnumeration{
* @see org.eclipse.cdt.core.model.IVariableDeclaration#getTypeName() * @see org.eclipse.cdt.core.model.IVariableDeclaration#getTypeName()
*/ */
public String getTypeName() { public String getTypeName() {
return typeName; return getEnumerationInfo().getTypeName();
} }
/** /**
* @see org.eclipse.cdt.core.model.IVariableDeclaration#setTypeName(java.lang.String) * @see org.eclipse.cdt.core.model.IVariableDeclaration#setTypeName(java.lang.String)
*/ */
public void setTypeName(String type) { public void setTypeName(String type) {
typeName = type; getEnumerationInfo().setTypeName(type);
} }
/** /**
@ -61,21 +59,21 @@ public class Enumeration extends SourceManipulation implements IEnumeration{
* @see org.eclipse.cdt.core.model.IDeclaration#isConst() * @see org.eclipse.cdt.core.model.IDeclaration#isConst()
*/ */
public boolean isConst() { public boolean isConst() {
return isConst; return getEnumerationInfo().isConst();
} }
/** /**
* @see org.eclipse.cdt.core.model.IDeclaration#isStatic() * @see org.eclipse.cdt.core.model.IDeclaration#isStatic()
*/ */
public boolean isStatic() { public boolean isStatic() {
return isStatic; return getEnumerationInfo().isStatic();
} }
/** /**
* @see org.eclipse.cdt.core.model.IDeclaration#isVolatile() * @see org.eclipse.cdt.core.model.IDeclaration#isVolatile()
*/ */
public boolean isVolatile() { public boolean isVolatile() {
return isVolatile; return getEnumerationInfo().isVolatile();
} }
/** /**
@ -83,7 +81,7 @@ public class Enumeration extends SourceManipulation implements IEnumeration{
* @param isConst The isConst to set * @param isConst The isConst to set
*/ */
public void setConst(boolean isConst) { public void setConst(boolean isConst) {
this.isConst = isConst; getEnumerationInfo().setConst(isConst);
} }
/** /**
@ -91,7 +89,7 @@ public class Enumeration extends SourceManipulation implements IEnumeration{
* @param isStatic The isStatic to set * @param isStatic The isStatic to set
*/ */
public void setStatic(boolean isStatic) { public void setStatic(boolean isStatic) {
this.isStatic = isStatic; getEnumerationInfo().setStatic( isStatic);
} }
/** /**
@ -99,7 +97,7 @@ public class Enumeration extends SourceManipulation implements IEnumeration{
* @param isVolatile The isVolatile to set * @param isVolatile The isVolatile to set
*/ */
public void setVolatile(boolean isVolatile) { public void setVolatile(boolean isVolatile) {
this.isVolatile = isVolatile; getEnumerationInfo().setVolatile(isVolatile);
} }
} }

View file

@ -0,0 +1,21 @@
package org.eclipse.cdt.internal.core.model;
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* Rational Software - Initial API and implementation
***********************************************************************/
public class EnumerationInfo extends VariableInfo{
protected EnumerationInfo(CElement element) {
super(element);
}
}

View file

@ -86,15 +86,4 @@ public class Field extends SourceManipulation implements IField {
protected CElementInfo createElementInfo () { protected CElementInfo createElementInfo () {
return new FieldInfo(this); return new FieldInfo(this);
} }
// tests both info stored in element and element info
public boolean isIdentical(Field other){
FieldInfo otherInfo= other.getFieldInfo();
if ( (this.equals(other))
&& (getFieldInfo().hasSameContentsAs(otherInfo))
)
return true;
else
return false;
}
} }

View file

@ -36,25 +36,6 @@ public class FieldInfo extends SourceManipulationInfo {
protected String getTypeName(){ protected String getTypeName(){
return typeStr; return typeStr;
} }
/**
* Tests info stored in element info only
* @param otherInfo
* @return boolean
*/
public boolean hasSameContentsAs( SourceManipulationInfo info){
FieldInfo otherInfo = (FieldInfo) info;
if( (typeStr.equals(otherInfo.getTypeName()))
&& (isConst == otherInfo.isConst())
&& (isVolatile == otherInfo.isVolatile())
&& (isMutable == otherInfo.isMutable())
&& (visibility == otherInfo.getVisibility())
&& (isStatic == otherInfo.isStatic())
)
return true;
else
return false;
}
protected void setAccessControl(int flags) { protected void setAccessControl(int flags) {
this.flags = flags; this.flags = flags;
@ -110,4 +91,20 @@ public class FieldInfo extends SourceManipulationInfo {
public void setVisibility(int visibility) { public void setVisibility(int visibility) {
this.visibility = visibility; this.visibility = visibility;
} }
/**
* @see org.eclipse.cdt.internal.core.model.SourceManipulationInfo#hasSameContentsAs(SourceManipulationInfo)
*/
public boolean hasSameContentsAs( SourceManipulationInfo info){
return( super.hasSameContentsAs(info)
&& (typeStr.equals(((FieldInfo)info).getTypeName()))
&& (isConst == ((FieldInfo)info).isConst())
&& (isVolatile == ((FieldInfo)info).isVolatile())
&& (isMutable == ((FieldInfo)info).isMutable())
&& (visibility == ((FieldInfo)info).getVisibility())
&& (isStatic == ((FieldInfo)info).isStatic())
);
}
} }

View file

@ -35,7 +35,6 @@ public class FunctionDeclaration extends SourceManipulation implements IFunction
public void setReturnType(String type){ public void setReturnType(String type){
returnType = type; returnType = type;
getFunctionInfo().setReturnType(type);
} }
public int getNumberOfParameters() { public int getNumberOfParameters() {
@ -91,8 +90,12 @@ public class FunctionDeclaration extends SourceManipulation implements IFunction
} }
public boolean equals(Object other) { public boolean equals(Object other) {
// Two function declarations are equal if
// Their parents and names are equal and
return ( super.equals(other) return ( super.equals(other)
// their parameter types are equal and
&& Util.equalArraysOrNull(fParameterTypes, ((FunctionDeclaration)other).fParameterTypes) && Util.equalArraysOrNull(fParameterTypes, ((FunctionDeclaration)other).fParameterTypes)
// their return types are equal
&& getReturnType().equals(((FunctionDeclaration)other).getReturnType()) && getReturnType().equals(((FunctionDeclaration)other).getReturnType())
); );
} }

View file

@ -8,8 +8,6 @@ package org.eclipse.cdt.internal.core.model;
class FunctionInfo extends SourceManipulationInfo { class FunctionInfo extends SourceManipulationInfo {
protected int flags; protected int flags;
protected String returnType = "";
protected int numOfParams;
protected boolean isStatic; protected boolean isStatic;
protected boolean isVolatile; protected boolean isVolatile;
@ -27,13 +25,6 @@ class FunctionInfo extends SourceManipulationInfo {
this.flags = flags; this.flags = flags;
} }
protected String getReturnType(){
return returnType;
}
protected void setReturnType(String type){
returnType = type;
}
/** /**
* Returns the isStatic. * Returns the isStatic.
* @return boolean * @return boolean
@ -66,4 +57,14 @@ class FunctionInfo extends SourceManipulationInfo {
this.isVolatile = isVolatile; this.isVolatile = isVolatile;
} }
/**
* @see org.eclipse.cdt.internal.core.model.SourceManipulationInfo#hasSameContentsAs(org.eclipse.cdt.internal.core.model.SourceManipulationInfo)
*/
public boolean hasSameContentsAs(SourceManipulationInfo otherInfo) {
return (super.hasSameContentsAs(otherInfo)
&& (this.isStatic() == ((FunctionInfo)otherInfo).isStatic())
&& (this.isVolatile() == ((FunctionInfo)otherInfo).isVolatile())
);
}
} }

View file

@ -17,7 +17,7 @@ import org.eclipse.cdt.core.model.IMethodDeclaration;
public class MethodDeclaration extends FunctionDeclaration implements IMethodDeclaration{ public class MethodDeclaration extends FunctionDeclaration implements IMethodDeclaration{
boolean isConst; boolean isConst;
boolean isVolatile; ;
public MethodDeclaration(ICElement parent, String name){ public MethodDeclaration(ICElement parent, String name){
super(parent, name, CElement.C_METHOD_DECLARATION); super(parent, name, CElement.C_METHOD_DECLARATION);
@ -90,15 +90,6 @@ public class MethodDeclaration extends FunctionDeclaration implements IMethodDec
getMethodInfo().setConst(isConst); getMethodInfo().setConst(isConst);
} }
public boolean isVolatile(){
return isVolatile;
}
public void setVolatile(boolean isVolatile){
this.isVolatile = isVolatile;
getMethodInfo().setVolatile(isVolatile);
}
public int getVisibility(){ public int getVisibility(){
return getMethodInfo().getVisibility(); return getMethodInfo().getVisibility();
} }
@ -119,9 +110,11 @@ public class MethodDeclaration extends FunctionDeclaration implements IMethodDec
* See if we need anything else to put in equals here * See if we need anything else to put in equals here
*/ */
public boolean equals(Object other) { public boolean equals(Object other) {
// Two methods are equal if
// their parents, names, parameter types and return types are equal and
return ( super.equals(other) return ( super.equals(other)
// their constant directive is the same
&& isConst() == ((MethodDeclaration)other).isConst() && isConst() == ((MethodDeclaration)other).isConst()
&& isVolatile() == ((MethodDeclaration)other).isVolatile()
); );
} }

View file

@ -83,4 +83,18 @@ public class MethodInfo extends FunctionInfo {
this.visibility = visibility; this.visibility = visibility;
} }
/**
* @see org.eclipse.cdt.internal.core.model.SourceManipulationInfo#hasSameContentsAs(org.eclipse.cdt.internal.core.model.SourceManipulationInfo)
*/
public boolean hasSameContentsAs(SourceManipulationInfo otherInfo) {
return (super.hasSameContentsAs(otherInfo)
&& (isConst == ((MethodInfo)otherInfo).isConst())
&& (isAbstract == ((MethodInfo)otherInfo).isAbstract())
&& (isInline == ((MethodInfo)otherInfo).isInline())
&& (isVirtual == ((MethodInfo)otherInfo).isVirtual())
&& (isFriend == ((MethodInfo)otherInfo).isFriend())
&& (visibility == ((MethodInfo)otherInfo).getVisibility())
);
}
} }

View file

@ -20,8 +20,4 @@ public class Namespace extends SourceManipulation implements INamespace{
super(parent, name, CElement.C_NAMESPACE); super(parent, name, CElement.C_NAMESPACE);
} }
protected CElementInfo createElementInfo () {
return new SourceManipulationInfo(this);
}
} }

View file

@ -152,4 +152,9 @@ public class SourceManipulation extends Parent implements ISourceManipulation, I
protected SourceManipulationInfo getSourceManipulationInfo() { protected SourceManipulationInfo getSourceManipulationInfo() {
return (SourceManipulationInfo)getElementInfo(); return (SourceManipulationInfo)getElementInfo();
} }
public boolean isIdentical(SourceManipulation other){
return (this.equals(other)
&& (this.getSourceManipulationInfo().hasSameContentsAs(other.getSourceManipulationInfo())));
}
} }

View file

@ -146,7 +146,7 @@ class SourceManipulationInfo extends CElementInfo {
* subclasses should override * subclasses should override
*/ */
public boolean hasSameContentsAs( SourceManipulationInfo otherInfo){ public boolean hasSameContentsAs( SourceManipulationInfo otherInfo){
return true; return (this.element.fType == otherInfo.element.fType);
} }
} }

View file

@ -12,22 +12,17 @@ package org.eclipse.cdt.internal.core.model;
***********************************************************************/ ***********************************************************************/
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
public class StructureInfo extends SourceManipulationInfo { public class StructureInfo extends VariableInfo {
String type;
boolean isConst = false;
boolean isVolatile = false;
boolean isStatic = false;
protected StructureInfo (CElement element) { protected StructureInfo (CElement element) {
super(element); super(element);
if (element.getElementType() == ICElement.C_CLASS) if (element.getElementType() == ICElement.C_CLASS)
type = "class"; this.setTypeName("class");
else if (element.getElementType() == ICElement.C_UNION) else if (element.getElementType() == ICElement.C_UNION)
type = "union"; this.setTypeName("union");
else else
type = "struct"; this.setTypeName("struct");
} }
public boolean isUnion() { public boolean isUnion() {
@ -42,64 +37,5 @@ public class StructureInfo extends SourceManipulationInfo {
return element.getElementType() == ICElement.C_STRUCT; return element.getElementType() == ICElement.C_STRUCT;
} }
public String getTypeName(){
return type;
}
public void setTypeString(String elmType){
type = elmType;
}
public boolean hasSameContentsAs( StructureInfo otherInfo){
return true;
}
/**
* Returns the isConst.
* @return boolean
*/
public boolean isConst() {
return isConst;
}
/**
* Returns the isStatic.
* @return boolean
*/
public boolean isStatic() {
return isStatic;
}
/**
* Returns the isVolatile.
* @return boolean
*/
public boolean isVolatile() {
return isVolatile;
}
/**
* Sets the isConst.
* @param isConst The isConst to set
*/
public void setConst(boolean isConst) {
this.isConst = isConst;
}
/**
* Sets the isStatic.
* @param isStatic The isStatic to set
*/
public void setStatic(boolean isStatic) {
this.isStatic = isStatic;
}
/**
* Sets the isVolatile.
* @param isVolatile The isVolatile to set
*/
public void setVolatile(boolean isVolatile) {
this.isVolatile = isVolatile;
}
} }

View file

@ -11,26 +11,13 @@ package org.eclipse.cdt.internal.core.model;
* Rational Software - Initial API and implementation * Rational Software - Initial API and implementation
***********************************************************************/ ***********************************************************************/
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ITypeDef; import org.eclipse.cdt.core.model.ITypeDef;
public class TypeDef extends SourceManipulation implements ITypeDef{ public class TypeDef extends SourceManipulation implements ITypeDef{
public TypeDef(ICElement parent, String name) { public TypeDef(ICElement parent, String name) {
super(parent, name, CElement.C_TYPEDEF); super(parent, name, CElement.C_TYPEDEF);
} }
protected CElementInfo createElementInfo () {
return new SourceManipulationInfo(this);
}
/**
* @see org.eclipse.cdt.core.model.ITypeDef#getType()
*/
public String getType() throws CModelException {
return null;
}
} }

View file

@ -29,13 +29,6 @@ class VariableInfo extends SourceManipulationInfo {
protected void setTypeName(String type){ protected void setTypeName(String type){
typeStr = type; typeStr = type;
} }
protected boolean hasSameContentsAs( VariableInfo otherInfo){
if(typeStr.equals(otherInfo.getTypeName()))
return true;
else
return false;
}
protected void setAccessControl(int flags) { protected void setAccessControl(int flags) {
this.flags = flags; this.flags = flags;
@ -60,12 +53,25 @@ class VariableInfo extends SourceManipulationInfo {
this.isVolatile = isVolatile; this.isVolatile = isVolatile;
} }
public boolean isStatic() { protected boolean isStatic() {
return isStatic; return isStatic;
} }
public void setStatic(boolean isStatic) { protected void setStatic(boolean isStatic) {
this.isStatic = isStatic; this.isStatic = isStatic;
} }
/**
* @see org.eclipse.cdt.internal.core.model.SourceManipulationInfo#hasSameContentsAs(org.eclipse.cdt.internal.core.model.SourceManipulationInfo)
*/
public boolean hasSameContentsAs(SourceManipulationInfo otherInfo) {
return
( super.hasSameContentsAs(otherInfo)
&& ( typeStr.equals(((VariableInfo)otherInfo).getTypeName()) )
&& ( isConst() == ((VariableInfo)otherInfo).isConst() )
&& (isVolatile() == ((VariableInfo)otherInfo).isVolatile() )
&& (isStatic() == ((VariableInfo)otherInfo).isStatic() )
);
}
} }

View file

@ -325,6 +325,7 @@ public class SimpleDeclarationWrapper extends DeclSpecifier implements DeclSpeci
newElement.setVisibility(this.getCurrentVisibility()); newElement.setVisibility(this.getCurrentVisibility());
newElement.setVolatile(isVolatile()); newElement.setVolatile(isVolatile());
newElement.setStatic(isStatic()); newElement.setStatic(isStatic());
newElement.setConst(isConst());
return newElement; return newElement;
} }
@ -349,6 +350,7 @@ public class SimpleDeclarationWrapper extends DeclSpecifier implements DeclSpeci
newElement.setVisibility(this.getCurrentVisibility()); newElement.setVisibility(this.getCurrentVisibility());
newElement.setVolatile(isVolatile()); newElement.setVolatile(isVolatile());
newElement.setStatic(isStatic()); newElement.setStatic(isStatic());
newElement.setConst(isConst());
return newElement; return newElement;
} }

View file

@ -74,6 +74,8 @@ public class CElementLabelProvider extends LabelProvider {
case ICElement.C_METHOD_DECLARATION: case ICElement.C_METHOD_DECLARATION:
IFunctionDeclaration fDecl = (IFunctionDeclaration) celem; IFunctionDeclaration fDecl = (IFunctionDeclaration) celem;
name = fDecl.getSignature(); name = fDecl.getSignature();
name += " : ";
name += fDecl.getReturnType();
break; break;
case ICElement.C_STRUCT: case ICElement.C_STRUCT:
case ICElement.C_UNION: case ICElement.C_UNION: