package Schmortopf.FileStructure.Descriptions;
/**
* Used in FileStructureDescriptions.
* For example in FileStructureDescriptionForConstructor
* it's used to describe the passed parameters.
*
* ParameterType is like Parameter, but has no objectname.
*
*/
import java.util.*;
import Schmortopf.Utility.Vectorizable;
import Schmortopf.Utility.BooleanInteger;
import Schmortopf.Utility.StringUtilities;
public class ParameterTypeDescription implements Vectorizable
{
// Caution: Update the Vectorizable methods, when this datastructure changes.
public boolean isPrimitiveType;
public BooleanInteger isArrayType;
public String packageName; // package part only
public String simpleClassName; // leafname without package part
public int lineNumber;
public GenericTypeRestrictionDescription[] genericRestrictions = new GenericTypeRestrictionDescription[0];
public ParameterTypeDescription( final boolean isPrimitiveType,
final BooleanInteger isArrayType,
final String packageName,
final String simpleClassName,
final int lineNumber,
final GenericTypeRestrictionDescription[] theGenericRestrictions )
{
this.isPrimitiveType = isPrimitiveType;
this.isArrayType = isArrayType;
this.packageName = packageName;
this.simpleClassName = simpleClassName;
this.lineNumber = lineNumber;
this.genericRestrictions = theGenericRestrictions;
}
public ParameterTypeDescription( Vector representation )
{
this.createFromVectorRepresentation( representation );
}
public String getJavaSourceCompatibleTextDescription()
{
StringBuffer buf = new StringBuffer();
buf.append(this.simpleClassName);
// append generic restrictions, if there are some:
if( this.genericRestrictions.length > 0 )
{
buf.append(" <");
for( int i=0; i < this.genericRestrictions.length; i++ )
{
buf.append( this.genericRestrictions[i].getJavaSourceCompatibleTextDescription() );
if( i < this.genericRestrictions.length -1 ) buf.append(",");
}
buf.append(">");
} // if
return buf.toString();
}
/**
* This one only uses the last identifier in the possibly qualified names.
*
* Used for the name of method leafs in the fileComponentsTree
* and the CodeCompletion menu.
*/
public String getShortTextDescription()
{
StringBuffer buf = new StringBuffer();
buf.append( this.getLastIdentifier(this.simpleClassName) + " ");
// append generic restrictions, if there are some:
if( this.genericRestrictions.length > 0 )
{
buf.append("<");
for( int i=0; i < this.genericRestrictions.length; i++ )
{
buf.append( this.genericRestrictions[i].getJavaSourceCompatibleTextDescription() );
if( i < this.genericRestrictions.length -1 ) buf.append(",");
}
buf.append(">");
} // if
return buf.toString();
}
/**
* Returns the last token in a string delimited by points.
*/
private String getLastIdentifier( String fullyQualifiedName )
{
String[] tokens = StringUtilities.SplitString(fullyQualifiedName,".");
return tokens[ tokens.length-1 ]; // The last token
}
public boolean equals( final ParameterTypeDescription otherType )
{
return( ( this.isPrimitiveType == otherType.isPrimitiveType ) &&
( this.isArrayType.booleanValue == otherType.isArrayType.booleanValue ) &&
( this.packageName.equals(otherType.packageName) ) &&
( this.simpleClassName.equals(otherType.simpleClassName) ) );
// Note that the lineNumber really doesn't count for this.
}
/**
* Implementation of the Vectorizable interface.
* Returns the VectorRepresentation of the object's datacontent
*/
public Vector getVectorRepresentation() throws Exception
{
final Vector rep = new Vector();
rep.addElement( new Boolean(this.isPrimitiveType) );
rep.addElement( this.isArrayType.getVectorRepresentation() );
rep.addElement( this.packageName );
rep.addElement( this.simpleClassName );
rep.addElement( new Integer( this.lineNumber ) );
rep.addElement( new Integer(this.genericRestrictions.length) );
for( int i=0; i < this.genericRestrictions.length; i++ )
{
rep.addElement( this.genericRestrictions[i].getVectorRepresentation() );
}
return rep;
} // getVectorRepresentation
/**
* Implementation of the Vectorizable interface.
* Sets the object's content to the passed vectorRepresentation.
*/
public void createFromVectorRepresentation( final Vector rep )
{
int repCounter = 0;
this.isPrimitiveType = ((Boolean)rep.elementAt(repCounter++)).booleanValue();
Vector arrayRep = (Vector)rep.elementAt(repCounter++);
this.isArrayType = new BooleanInteger( arrayRep );
this.packageName = (String)rep.elementAt(repCounter++);
this.simpleClassName = (String)rep.elementAt(repCounter++);
this.lineNumber = ((Integer)rep.elementAt(repCounter++)).intValue();
int numberOfGenericRestrictions = ((Integer)rep.elementAt(repCounter++)).intValue();
this.genericRestrictions = new GenericTypeRestrictionDescription[numberOfGenericRestrictions];
for( int i=0; i < numberOfGenericRestrictions; i++ )
{
final Vector thisGenericRep = (Vector)rep.elementAt(repCounter++);
this.genericRestrictions[i] = new GenericTypeRestrictionDescription();
this.genericRestrictions[i].createFromVectorRepresentation( thisGenericRep );
}
} // createFromVectorRepresentation
/**
* GC assistance
*/
public void clearAttributes()
{
this.isArrayType = null;
this.packageName = null;
this.simpleClassName = null;
}
} // ParameterTypeDescription
|