use of org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension in project titan.EclipsePlug-ins by eclipse.
the class Port_Type method generateCodePort.
/**
* Generate the classes to represent a port array.
*
* @param aData only used to update imports if needed
* @param source where the source code should be generated
* @param dimensions the dimensions of the array to use.
*/
public void generateCodePort(final JavaGenData aData, final StringBuilder source, final ArrayDimensions dimensions) {
String className = getGenNameValue(aData, source, myScope);
String elementName;
for (int i = 0; i < dimensions.size(); i++) {
final ArrayDimension dimension = dimensions.get(i);
if (i == dimensions.size() - 1) {
elementName = getGenNameOwn();
} else {
elementName = aData.getTemporaryVariableName();
}
source.append(MessageFormat.format("public static class {0} extends TitanPortArray<{1}> '{'\n", className, elementName));
source.append(MessageFormat.format("public {0}() '{'\n", className));
source.append(MessageFormat.format("super({0}.class, {1} , {2});\n", elementName, dimension.getSize(), dimension.getOffset()));
source.append("}\n");
source.append(MessageFormat.format("public {0}({0} otherValue) '{'\n", className));
source.append("super(otherValue);\n");
source.append("}\n");
source.append("}\n\n");
className = elementName;
}
aData.addBuiltinTypeImport("TitanPortArray");
}
use of org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension in project titan.EclipsePlug-ins by eclipse.
the class AbstractOfType method isSubtypeCompatible.
/**
* Checks that the provided type is sub-type compatible with the actual
* set of type.
* <p>
* In case of sequence/set/array this means that the number of their
* fields fulfills the length restriction of the set of type.
*
* @param timestamp
* the timestamp of the actual semantic check cycle
* @param other
* the type to check against.
*
* @return true if they are sub-type compatible, false otherwise.
*/
public boolean isSubtypeCompatible(final CompilationTimeStamp timestamp, final IType other) {
if (subType == null || other == null) {
return true;
}
long nofComponents;
switch(other.getTypetype()) {
case TYPE_ASN1_SEQUENCE:
nofComponents = ((ASN1_Sequence_Type) other).getNofComponents(timestamp);
break;
case TYPE_TTCN3_SEQUENCE:
nofComponents = ((TTCN3_Sequence_Type) other).getNofComponents();
break;
case TYPE_ASN1_SET:
nofComponents = ((ASN1_Set_Type) other).getNofComponents(timestamp);
break;
case TYPE_TTCN3_SET:
nofComponents = ((TTCN3_Set_Type) other).getNofComponents();
break;
case TYPE_SEQUENCE_OF:
case TYPE_SET_OF:
if (other.getSubtype() == null) {
return true;
}
return subType.isCompatible(timestamp, other.getSubtype());
case TYPE_ARRAY:
{
final ArrayDimension dimension = ((Array_Type) other).getDimension();
if (dimension.getIsErroneous(timestamp)) {
return false;
}
nofComponents = dimension.getSize();
break;
}
default:
return false;
}
final List<ParsedSubType> tempRestrictions = new ArrayList<ParsedSubType>(1);
final Integer_Value length = new Integer_Value(nofComponents);
tempRestrictions.add(new Length_ParsedSubType(new SingleLenghtRestriction(length)));
final SubType tempSubtype = new SubType(getSubtypeType(), this, tempRestrictions, null);
tempSubtype.check(timestamp);
return subType.isCompatible(timestamp, tempSubtype);
}
use of org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension in project titan.EclipsePlug-ins by eclipse.
the class Array_Type method generateCodeTemplate.
/**
* Generate the template class to represent an array.
* (Also generates the template classes of the of type if it is an array)
*
* @param aData only used to update imports if needed
* @param source where the source code should be generated
*/
public void generateCodeTemplate(final JavaGenData aData, final StringBuilder source) {
final String className = getGenNameValue(aData, source, myScope);
final String classTemplateName = getGenNameTemplate(aData, source, myScope);
final IType elementType = getElementType();
final String ofValueType = elementType.getGenNameValue(aData, source, getMyScope());
final String ofTemplateType = elementType.getGenNameTemplate(aData, source, getMyScope());
if (elementType.getTypetype() == Type_type.TYPE_ARRAY) {
((Array_Type) elementType).generateCodeTemplate(aData, source);
}
final ArrayDimension dim = getDimension();
aData.addBuiltinTypeImport("TitanTemplateArray");
source.append(MessageFormat.format("public static class {0} extends TitanTemplateArray<{1}, {2}> '{'\n", classTemplateName, ofValueType, ofTemplateType));
source.append(MessageFormat.format("public {0}() '{'\n", classTemplateName));
source.append(MessageFormat.format("super({0}.class, {1}.class, {2}, {3});\n", ofValueType, ofTemplateType, dim.getSize(), dim.getOffset()));
source.append("}\n");
source.append(MessageFormat.format("public {0} valueOf() '{'\n", className));
source.append(MessageFormat.format("return ({0})super.valueOf();\n", className));
source.append("}\n");
source.append("}\n");
}
Aggregations