Search in sources :

Example 1 with PortDefinition

use of org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.PortDefinition in project titan.EclipsePlug-ins by eclipse.

the class PortTypeBody method generateCode.

/**
 * Add generated java code on this level.
 * @param aData only used to update imports if needed
 * @param source the source code generated
 *
 * FIXME the implementation only serves as a minimal testing setup
 */
public void generateCode(final JavaGenData aData, final StringBuilder source) {
    final String genName = myType.getGenNameOwn();
    final Scope myScope = myType.getMyScope();
    final PortDefinition portDefinition = new PortDefinition(genName, getFullName());
    if (inMessages != null) {
        for (int i = 0; i < inMessages.getNofTypes(); i++) {
            final IType inType = inMessages.getTypeByIndex(i);
            final messageTypeInfo info = new messageTypeInfo(inType.getGenNameValue(aData, source, myScope), inType.getGenNameTemplate(aData, source, myScope), inType.getTypename());
            portDefinition.inMessages.add(info);
        }
    }
    if (outMessages != null) {
        for (int i = 0; i < outMessages.getNofTypes(); i++) {
            final IType outType = outMessages.getTypeByIndex(i);
            final messageTypeInfo info = new messageTypeInfo(outType.getGenNameValue(aData, source, myScope), outType.getGenNameTemplate(aData, source, myScope), outType.getTypename());
            portDefinition.outMessages.add(info);
        }
    }
    if (inSignatures != null) {
        for (int i = 0; i < inSignatures.getNofTypes(); i++) {
            final IType outType = inSignatures.getTypeByIndex(i);
            final Signature_Type signature = (Signature_Type) outType.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
            final procedureSignatureInfo info = new procedureSignatureInfo(outType.getGenNameValue(aData, source, myScope), outType.getTypename(), signature.isNonblocking(), signature.getSignatureExceptions() != null, false);
            portDefinition.inProcedures.add(info);
        }
    }
    if (outSignatures != null) {
        for (int i = 0; i < outSignatures.getNofTypes(); i++) {
            final IType outType = outSignatures.getTypeByIndex(i);
            final Signature_Type signature = (Signature_Type) outType.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
            final procedureSignatureInfo info = new procedureSignatureInfo(outType.getGenNameValue(aData, source, myScope), outType.getTypename(), signature.isNonblocking(), signature.getSignatureExceptions() != null, signature.getSignatureReturnType() != null);
            portDefinition.outProcedures.add(info);
        }
    }
    switch(testportType) {
        case TP_REGULAR:
            portDefinition.testportType = TestportType.NORMAL;
            break;
        case TP_INTERNAL:
            portDefinition.testportType = TestportType.INTERNAL;
            break;
        case TP_ADDRESS:
            portDefinition.testportType = TestportType.ADDRESS;
            portDefinition.addressName = "TitanAddress";
            break;
        default:
            portDefinition.testportType = TestportType.NORMAL;
    }
    if (vardefs != null) {
        portDefinition.varDefs = new StringBuilder();
        portDefinition.varInit = new StringBuilder();
        for (int i = 0; i < vardefs.getNofAssignments(); i++) {
            final Definition def = vardefs.getAssignmentByIndex(i);
            String type = "";
            switch(def.getAssignmentType()) {
                case A_VAR:
                    type = def.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameValue(aData, source, myScope);
                    if (((Def_Var) def).getInitialValue() == null) {
                        portDefinition.varInit.append(MessageFormat.format("{0}.cleanUp();\n", def.getGenName()));
                    } else {
                        def.generateCodeInitComp(aData, portDefinition.varInit, def);
                    }
                    break;
                case A_CONST:
                    type = def.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameValue(aData, source, myScope);
                    def.generateCodeInitComp(aData, portDefinition.varInit, def);
                    break;
                case A_VAR_TEMPLATE:
                    type = def.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameTemplate(aData, source, myScope);
                    if (((Def_Var_Template) def).getInitialValue() == null) {
                        portDefinition.varInit.append(MessageFormat.format("{0}.cleanUp();\n", def.getGenName()));
                    } else {
                        def.generateCodeInitComp(aData, portDefinition.varInit, def);
                    }
                    break;
                default:
                    // FATAL ERROR
                    break;
            }
            portDefinition.varDefs.append(MessageFormat.format("private {0} {1} = new {0}();\n", type, def.getGenName()));
        }
    }
    PortGenerator.generateClass(aData, source, portDefinition);
}
Also used : PortGenerator.messageTypeInfo(org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.messageTypeInfo) PortDefinition(org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.PortDefinition) Scope(org.eclipse.titan.designer.AST.Scope) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) PortDefinition(org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.PortDefinition) IType(org.eclipse.titan.designer.AST.IType) PortGenerator.procedureSignatureInfo(org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.procedureSignatureInfo)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)1 Scope (org.eclipse.titan.designer.AST.Scope)1 Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)1 PortDefinition (org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.PortDefinition)1 PortGenerator.messageTypeInfo (org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.messageTypeInfo)1 PortGenerator.procedureSignatureInfo (org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.procedureSignatureInfo)1