Search in sources :

Example 11 with TTCN3_Set_Type

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

the class ChangeCreator method calculateEditLocations.

private WorkspaceJob calculateEditLocations(final NavigableSet<ILocateableNode> nodes, final IFile file, final MultiTextEdit rootEdit) throws CoreException {
    final WorkspaceJob job = new WorkspaceJob("InsertFieldRefactoring: calculate edit locations") {

        @Override
        public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
            for (ILocateableNode node : nodes) {
                int vmLen = settings.getType().length() + settings.getId().getTtcnName().length();
                if (node instanceof Def_Type) {
                    Def_Type df = (Def_Type) node;
                    Type type = df.getType(CompilationTimeStamp.getBaseTimestamp());
                    if (type instanceof TTCN3_Sequence_Type || type instanceof TTCN3_Set_Type) {
                        vmLen = insertField((TTCN3_Set_Seq_Choice_BaseType) type, node, rootEdit, vmLen);
                    }
                } else if (node instanceof Sequence_Value) {
                    Sequence_Value sv = (Sequence_Value) node;
                    vmLen += 6;
                    final Location nodeLocation = node.getLocation();
                    if (settings.getPosition() < sv.getNofComponents()) {
                        final Location valueLocation = sv.getSeqValueByIndex(settings.getPosition()).getLocation();
                        Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), valueLocation.getOffset(), valueLocation.getEndOffset() + vmLen);
                        rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getId().getTtcnName() + " := " + settings.getValue() + ", "));
                    } else {
                        int max = sv.getNofComponents();
                        final Location valueLocation = sv.getSeqValueByIndex(max - 1).getLocation();
                        Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), valueLocation.getEndOffset(), valueLocation.getEndOffset() + vmLen);
                        rootEdit.addChild(new InsertEdit(l.getOffset(), ", " + settings.getId().getTtcnName() + " := " + settings.getValue()));
                    }
                } else if (node instanceof TTCN3Template) {
                    TTCN3Template template = (TTCN3Template) node;
                    vmLen += 6;
                    if (template instanceof Named_Template_List) {
                        Named_Template_List ntl = (Named_Template_List) template;
                        final Location nodeLocation = node.getLocation();
                        if (settings.getPosition() < ntl.getNofTemplates()) {
                            final Location templateLocation = ntl.getTemplateByIndex(settings.getPosition()).getLocation();
                            Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getOffset(), templateLocation.getEndOffset() + vmLen);
                            rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getId().getTtcnName() + " := " + settings.getValue() + ", "));
                        } else {
                            int max = ntl.getNofTemplates();
                            final Location templateLocation = ntl.getTemplateByIndex(max - 1).getLocation();
                            Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getEndOffset(), templateLocation.getEndOffset() + vmLen);
                            rootEdit.addChild(new InsertEdit(l.getOffset(), ", " + settings.getId().getTtcnName() + " := " + settings.getValue()));
                        }
                    } else if (template instanceof Template_List) {
                        Template_List tl = (Template_List) template;
                        final Location nodeLocation = node.getLocation();
                        if (settings.getPosition() < tl.getNofTemplates()) {
                            final Location templateLocation = tl.getTemplateByIndex(settings.getPosition()).getLocation();
                            Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getOffset(), templateLocation.getEndOffset() + vmLen);
                            rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getValue() + ","));
                        } else {
                            int max = tl.getNofTemplates();
                            final Location templateLocation = tl.getTemplateByIndex(max - 1).getLocation();
                            Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getEndOffset(), templateLocation.getEndOffset() + vmLen);
                            rootEdit.addChild(new InsertEdit(l.getOffset(), "," + settings.getValue()));
                        }
                    }
                }
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
    return job;
}
Also used : Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) InsertEdit(org.eclipse.text.edits.InsertEdit) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Sequence_Value(org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) TTCN3_Set_Seq_Choice_BaseType(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Seq_Choice_BaseType) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type) Type(org.eclipse.titan.designer.AST.Type) Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) Template_List(org.eclipse.titan.designer.AST.TTCN3.templates.Template_List) Named_Template_List(org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List) ILocateableNode(org.eclipse.titan.designer.AST.ILocateableNode) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) Named_Template_List(org.eclipse.titan.designer.AST.TTCN3.templates.Named_Template_List) TTCN3_Set_Seq_Choice_BaseType(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Seq_Choice_BaseType) Location(org.eclipse.titan.designer.AST.Location)

Example 12 with TTCN3_Set_Type

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

the class InsertFieldWizardInputPage method checkPosition.

public void checkPosition() {
    try {
        settings.setPosition(Integer.parseInt(positionField.getText().trim()));
        final IType type = selection.getType(CompilationTimeStamp.getBaseTimestamp());
        if (type instanceof TTCN3_Sequence_Type || type instanceof TTCN3_Set_Type) {
            final TTCN3_Set_Seq_Choice_BaseType ss = (TTCN3_Set_Seq_Choice_BaseType) type;
            final int noc = ss.getNofComponents();
            if (settings.getPosition() < 0) {
                positionErrorMessage = NEGATIVEPOSITION;
                posDone = false;
            } else if (settings.getPosition() > noc) {
                positionErrorMessage = String.format(INVALIDUPPERBOUNDPOSITION, noc);
                posDone = false;
            } else {
                positionErrorMessage = "";
                posDone = true;
            }
        }
    } catch (NumberFormatException ex) {
        positionErrorMessage = NOTNUMBERPOSITION;
        posDone = false;
    }
    setErrorMessage(positionErrorMessage + typeErrorMessage + nameErrorMessage + valueErrorMessage);
    setPageComplete(posDone && typeDone && nameDone && valueDone);
}
Also used : TTCN3_Set_Seq_Choice_BaseType(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Seq_Choice_BaseType) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 13 with TTCN3_Set_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type 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);
}
Also used : ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.ParsedSubType) Length_ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Length_ParsedSubType) SubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType) ArrayList(java.util.ArrayList) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Length_ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Length_ParsedSubType) ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.ParsedSubType) Length_ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Length_ParsedSubType) ArrayDimension(org.eclipse.titan.designer.AST.TTCN3.values.ArrayDimension) SingleLenghtRestriction(org.eclipse.titan.designer.AST.TTCN3.templates.SingleLenghtRestriction)

Example 14 with TTCN3_Set_Type

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

the class Named_Template_List method generateCodeInit.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
    if (lastTimeBuilt != null && !lastTimeBuilt.isLess(aData.getBuildTimstamp())) {
        return;
    }
    lastTimeBuilt = aData.getBuildTimstamp();
    if (asValue != null) {
        asValue.generateCodeInit(aData, source, name);
        return;
    }
    if (myGovernor == null) {
        return;
    }
    // FIXME actually a bit more complex
    final IType type = myGovernor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
    if (type == null) {
        return;
    }
    if (namedTemplates.getNofTemplates() == 0) {
        aData.addBuiltinTypeImport("TitanNull_Type");
        source.append(MessageFormat.format("{0}.assign(TitanNull_Type.NULL_VALUE);\n", name));
    }
    // else is not needed as the loop will not run
    for (int i = 0; i < namedTemplates.getNofTemplates(); i++) {
        final NamedTemplate namedTemplate = namedTemplates.getTemplateByIndex(i);
        final String fieldName = namedTemplate.getName().getName();
        // FIXME handle needs_temp_ref case
        final String generatedFieldName = FieldSubReference.getJavaGetterName(fieldName);
        final TTCN3Template template = namedTemplate.getTemplate();
        if (template.needsTemporaryReference()) {
            Type fieldType;
            switch(type.getTypetype()) {
                case TYPE_SIGNATURE:
                    fieldType = ((Signature_Type) type).getParameterByName(fieldName).getType();
                    break;
                case TYPE_TTCN3_SEQUENCE:
                    fieldType = ((TTCN3_Sequence_Type) type).getComponentByName(fieldName).getType();
                    break;
                case TYPE_TTCN3_SET:
                    fieldType = ((TTCN3_Set_Type) type).getComponentByName(fieldName).getType();
                    break;
                case TYPE_ASN1_SEQUENCE:
                    fieldType = ((ASN1_Sequence_Type) type).getComponentByName(new Identifier(Identifier_type.ID_NAME, fieldName)).getType();
                    break;
                case TYPE_ASN1_SET:
                    fieldType = ((ASN1_Set_Type) type).getComponentByName(new Identifier(Identifier_type.ID_NAME, fieldName)).getType();
                    break;
                case TYPE_ASN1_CHOICE:
                    fieldType = ((ASN1_Choice_Type) type).getComponentByName(new Identifier(Identifier_type.ID_NAME, fieldName)).getType();
                    break;
                case TYPE_TTCN3_CHOICE:
                    fieldType = ((TTCN3_Choice_Type) type).getComponentByName(fieldName).getType();
                    break;
                case TYPE_OPENTYPE:
                    fieldType = ((Open_Type) type).getComponentByName(new Identifier(Identifier_type.ID_NAME, fieldName)).getType();
                    break;
                case TYPE_ANYTYPE:
                    fieldType = ((Anytype_Type) type).getComponentByName(fieldName).getType();
                    break;
                default:
                    ErrorReporter.INTERNAL_ERROR("FATAL ERROR while processing named template list `" + getFullName() + "''");
                    return;
            }
            final String tempId = aData.getTemporaryVariableName();
            source.append("{\n");
            source.append(MessageFormat.format("{0} {1} = {2}.get{3}();\n", fieldType.getGenNameTemplate(aData, source, myScope), tempId, name, generatedFieldName));
            template.generateCodeInit(aData, source, tempId);
            source.append("}\n");
        } else {
            final String embeddedName = MessageFormat.format("{0}.get{1}()", name, generatedFieldName);
            template.generateCodeInit(aData, source, embeddedName);
        }
    }
    if (lengthRestriction != null) {
        if (getCodeSection() == CodeSectionType.CS_POST_INIT) {
            lengthRestriction.reArrangeInitCode(aData, source, myScope.getModuleScope());
        }
        lengthRestriction.generateCodeInit(aData, source, name);
    }
    if (isIfpresent) {
        source.append(name);
        source.append(".set_ifPresent();\n");
    }
}
Also used : Open_Type(org.eclipse.titan.designer.AST.ASN1.types.Open_Type) Signature_Type(org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) IType(org.eclipse.titan.designer.AST.IType) Anytype_Type(org.eclipse.titan.designer.AST.TTCN3.types.Anytype_Type) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) Anytype_Type(org.eclipse.titan.designer.AST.TTCN3.types.Anytype_Type) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) TTCN3_Choice_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type) Open_Type(org.eclipse.titan.designer.AST.ASN1.types.Open_Type) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) Signature_Type(org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type) Type(org.eclipse.titan.designer.AST.Type) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) TTCN3_Choice_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type)

Aggregations

IType (org.eclipse.titan.designer.AST.IType)12 Identifier (org.eclipse.titan.designer.AST.Identifier)9 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)8 TTCN3_Set_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type)7 IValue (org.eclipse.titan.designer.AST.IValue)6 TTCN3_Sequence_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type)5 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)4 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)4 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)4 ISubReference (org.eclipse.titan.designer.AST.ISubReference)4 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)3 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)3 TTCN3_Set_Seq_Choice_BaseType (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Seq_Choice_BaseType)3 Value (org.eclipse.titan.designer.AST.Value)3 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)2 Open_Type (org.eclipse.titan.designer.AST.ASN1.types.Open_Type)2 TTCN3_Choice_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type)2 Type (org.eclipse.titan.designer.AST.Type)2 ArrayList (java.util.ArrayList)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1