// copyAttributesOtherThanVariable(port);
// }
// }
if ((object instanceof Attribute)
&& !(object instanceof SharedParameter)) {
Attribute attribute = (Attribute) object;
// Ignore attributes that are ignorable.
if (ModelTransformer._isIgnorableAttribute(attribute)) {
return;
}
// PortParameters are handled specially.
// if (attribute instanceof PortParameter) {
// continue;
// }
// If we have an attribute that derives from
// stringAttribute, or Parameter then we need to grab some
// code for it. (i.e. FileParameter, and FileParameter)
if ((attribute instanceof StringAttribute && !attribute.getClass()
.equals(StringAttribute.class))
|| (attribute instanceof Parameter && !attribute.getClass()
.equals(Parameter.class))) {
String className = attribute.getClass().getName();
if (_debug) {
System.out.println("ComplexAttribute = " + attribute
+ " Class = " + className);
}
SootClass attributeClass = Scene.v().loadClassAndSupport(
className);
attributeClass.setLibraryClass();
String newClassName = ModelTransformer.getInstanceClassName(
attribute, _options);
// Create a new class for the attribute.
SootClass newClass = SootUtilities.copyClass(attributeClass,
newClassName);
// Make sure that we generate code for the new class.
newClass.setApplicationClass();
// Associate the new class with the attribute.
ModelTransformer.addAttributeForClass(newClass, attribute);
// Fold the copied class up to StringAttribute, or parameter
SootClass superClass = newClass.getSuperclass();
while ((superClass != PtolemyUtilities.objectClass)
&& (superClass != PtolemyUtilities.stringAttributeClass)
&& (superClass != PtolemyUtilities.parameterClass)) {
superClass.setLibraryClass();
SootUtilities.foldClass(newClass);
superClass = newClass.getSuperclass();
}
// Remove problematic methods for PortParameter
if (newClass.declaresMethodByName("setContainer")) {
SootMethod method = newClass
.getMethodByName("setContainer");
newClass.removeMethod(method);
}
if (newClass.declaresMethodByName("setName")) {
SootMethod method = newClass.getMethodByName("setName");
newClass.removeMethod(method);
}
if (newClass.declaresMethodByName("attributeChanged")) {
SootMethod method = newClass
.getMethodByName("attributeChanged");
newClass.removeMethod(method);
}
if (newClass.declaresFieldByName("_port")) {
SootField field = newClass.getFieldByName("_port");
Port port = ((PortParameter) attribute).getPort();
field.addTag(new ValueTag(port));
}
// Add a container field to the generated class.
// FIXME: this doesn't work for UnitSystems, e.g.,
// since their container isn't associated with a class.
FieldsForEntitiesTransformer._createContainerField(newClass);
HashMap oldSignatureToFieldMap = new HashMap();
// Loop over all the methods and replace the old class
// wherever it appears with the copied class.
for (Iterator classes = Scene.v().getApplicationClasses()
.iterator(); classes.hasNext();) {
SootClass theClass = (SootClass) classes.next();
if (theClass != newClass) {
_replaceObjectTypesInClassMethods(theClass, attribute,
attributeClass, newClass);
}
}
for (Iterator classes = Scene.v().getApplicationClasses()
.iterator(); classes.hasNext();) {
SootClass theClass = (SootClass) classes.next();
if (theClass != newClass) {
_replaceObjectTypesInClassFields(theClass, attribute,
attributeClass, newClass,
oldSignatureToFieldMap);
}
}
for (Iterator classes = Scene.v().getApplicationClasses()
.iterator(); classes.hasNext();) {
SootClass theClass = (SootClass) classes.next();
if (theClass != newClass) {
_fixFieldTypesInClassMethods(theClass, attribute,
attributeClass, newClass,
oldSignatureToFieldMap);
}
}
}
}
// Loop over all the attributes of the actor
for (Iterator attributes = object.attributeList(Attribute.class)
.iterator(); attributes.hasNext();) {
Attribute attribute = (Attribute) attributes.next();
copyAttributesOtherThanVariable(attribute);
}
}