Search in sources :

Example 1 with ASN1_Choice_Type

use of org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type in project titan.EclipsePlug-ins by eclipse.

the class Type method fieldIsOptional.

@Override
public /**
 * {@inheritDoc}
 */
boolean fieldIsOptional(final List<ISubReference> subReferences) {
    // TODO there must be a better implementation
    if (subReferences == null) {
        return false;
    }
    if (subReferences.isEmpty()) {
        return false;
    }
    final ISubReference lastSubReference = subReferences.get(subReferences.size() - 1);
    if (!(lastSubReference instanceof FieldSubReference)) {
        return false;
    }
    IType type = this;
    CompField compField = null;
    for (int i = 1; i < subReferences.size(); i++) {
        if (type != null) {
            type = type.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
        }
        final ISubReference subreference = subReferences.get(i);
        if (Subreference_type.fieldSubReference.equals(subreference.getReferenceType())) {
            final Identifier id = ((FieldSubReference) subreference).getId();
            if (type != null) {
                switch(type.getTypetype()) {
                    case TYPE_TTCN3_CHOICE:
                    case TYPE_TTCN3_SEQUENCE:
                    case TYPE_TTCN3_SET:
                        compField = ((TTCN3_Set_Seq_Choice_BaseType) type).getComponentByName(id.getName());
                        break;
                    case TYPE_ANYTYPE:
                        compField = ((Anytype_Type) type).getComponentByName(id.getName());
                        break;
                    case TYPE_OPENTYPE:
                        compField = ((Open_Type) type).getComponentByName(id);
                        break;
                    case TYPE_ASN1_SEQUENCE:
                        ((ASN1_Sequence_Type) type).parseBlockSequence();
                        compField = ((ASN1_Sequence_Type) type).getComponentByName(id);
                        break;
                    case TYPE_ASN1_SET:
                        ((ASN1_Set_Type) type).parseBlockSet();
                        compField = ((ASN1_Set_Type) type).getComponentByName(id);
                        break;
                    case TYPE_ASN1_CHOICE:
                        ((ASN1_Choice_Type) type).parseBlockChoice();
                        compField = ((ASN1_Choice_Type) type).getComponentByName(id);
                        break;
                    default:
                        // TODO fatal error:
                        return false;
                }
                if (compField == null) {
                    // TODO fatal error
                    return false;
                }
                type = compField.getType();
            }
        } else if (Subreference_type.arraySubReference.equals(subreference.getReferenceType())) {
            final Value value = ((ArraySubReference) subreference).getValue();
            // TODO actually should get the last governor
            final IType pt = value.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
            if (type != null) {
                switch(type.getTypetype()) {
                    case TYPE_SEQUENCE_OF:
                    case TYPE_SET_OF:
                        type = ((AbstractOfType) type).getOfType();
                        break;
                    case TYPE_ARRAY:
                        type = ((Array_Type) type).getElementType();
                        break;
                    default:
                        type = null;
                        return false;
                }
            }
        }
    }
    if (compField != null && compField.isOptional()) {
        return true;
    }
    return false;
}
Also used : ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) AbstractOfType(org.eclipse.titan.designer.AST.TTCN3.types.AbstractOfType) Expression_Value(org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) Array_Type(org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)

Example 2 with ASN1_Choice_Type

use of org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type in project titan.EclipsePlug-ins by eclipse.

the class TableConstraint method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (null != lastTimeChecked && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    parseBlocks();
    if (null == myType) {
        return;
    }
    objectSet.setMyScope(myType.getMyScope());
    BridgingNamedNode bridge = new BridgingNamedNode(this, FULLNAMEPART);
    objectSet.setFullNameParent(bridge);
    // search the constrained type (not the reference to it)
    constrainedType = myType;
    while (true) {
        if (constrainedType.getIsErroneous(timestamp)) {
            return;
        }
        if (Type_type.TYPE_OPENTYPE.equals(constrainedType.getTypetype()) || Type_type.TYPE_OBJECTCLASSFIELDTYPE.equals(constrainedType.getTypetype())) {
            break;
        } else if (constrainedType instanceof IReferencingType) {
            IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
            constrainedType = ((IReferencingType) constrainedType).getTypeRefd(timestamp, chain);
            chain.release();
        } else {
            myType.getLocation().reportSemanticError(OCFTEXPECTED);
            return;
        }
    }
    if (Type_type.TYPE_OBJECTCLASSFIELDTYPE.equals(constrainedType.getTypetype())) {
        ObjectClassField_Type ocfType = (ObjectClassField_Type) constrainedType;
        objectClassFieldname = ocfType.getObjectClassFieldName();
        objectSet.setMyGovernor(ocfType.getMyObjectClass());
        objectSet.check(timestamp);
        return;
    }
    // opentype
    final Open_Type openType = (Open_Type) constrainedType;
    openType.setMyTableConstraint(this);
    objectClassFieldname = openType.getObjectClassFieldName();
    objectSet.setMyGovernor(openType.getMyObjectClass());
    objectSet.check(timestamp);
    if (null == atNotationList) {
        return;
    }
    // componentrelationconstraint...
    // search the outermost textually enclosing seq, set or choice
    IType outermostParent = null;
    IType tempType = myType;
    do {
        switch(tempType.getTypetype()) {
            case TYPE_ASN1_CHOICE:
            case TYPE_TTCN3_CHOICE:
            case TYPE_OPENTYPE:
            case TYPE_ASN1_SEQUENCE:
            case TYPE_TTCN3_SEQUENCE:
            case TYPE_ASN1_SET:
            case TYPE_TTCN3_SET:
                outermostParent = tempType;
                break;
            default:
                break;
        }
        tempType = tempType.getParentType();
    } while (null != tempType);
    if (null == outermostParent) {
        myType.getLocation().reportSemanticError(CANNOTDETERMINEPARENT);
        return;
    }
    // outermostparent->set_opentype_outermost();
    // TODO implement the setting of set_has_openType
    AtNotation atNotation;
    for (int i = 0; i < atNotationList.getNofAtNotations(); i++) {
        atNotation = atNotationList.getAtNotationByIndex(i);
        IType parent = null;
        if (0 == atNotation.getLevels()) {
            parent = outermostParent;
        } else {
            parent = myType;
            for (int level = atNotation.getLevels(); level > 0; level--) {
                parent = parent.getParentType();
                if (null == parent) {
                    myType.getLocation().reportSemanticError(MessageFormat.format(TOOMANYDOTS, atNotation.getLevels()));
                    return;
                }
            }
        }
        tempType = parent;
        atNotation.setFirstComponent(parent);
        // component identifiers... do they exist? yes, if the refd type is constrained
        FieldName componentIdentifiers = atNotation.getComponentIdentifiers();
        for (int j = 0; j < componentIdentifiers.getNofFields(); j++) {
            Identifier identifier = componentIdentifiers.getFieldByIndex(i);
            switch(tempType.getTypetype()) {
                case TYPE_ASN1_CHOICE:
                    {
                        final ASN1_Choice_Type temp2 = (ASN1_Choice_Type) tempType;
                        if (temp2.hasComponentWithName(identifier)) {
                            final CompField cf = temp2.getComponentByName(identifier);
                            tempType = cf.getType();
                        } else {
                            myType.getLocation().reportSemanticError(MessageFormat.format(NOCOMPONENTERROR, tempType.getFullName(), identifier.getDisplayName()));
                            return;
                        }
                        break;
                    }
                case TYPE_TTCN3_CHOICE:
                    {
                        final TTCN3_Choice_Type temp2 = (TTCN3_Choice_Type) tempType;
                        if (temp2.hasComponentWithName(identifier.getName())) {
                            tempType = temp2.getComponentByName(identifier.getName()).getType();
                        } else {
                            myType.getLocation().reportSemanticError(MessageFormat.format(NOCOMPONENTERROR, tempType.getFullName(), identifier.getDisplayName()));
                            return;
                        }
                        break;
                    }
                case TYPE_OPENTYPE:
                    {
                        final Open_Type temp2 = (Open_Type) tempType;
                        if (temp2.hasComponentWithName(identifier)) {
                            final CompField cf = temp2.getComponentByName(identifier);
                            tempType = cf.getType();
                        } else {
                            myType.getLocation().reportSemanticError(MessageFormat.format(NOCOMPONENTERROR, tempType.getFullName(), identifier.getDisplayName()));
                            return;
                        }
                        break;
                    }
                case TYPE_ASN1_SEQUENCE:
                    {
                        final ASN1_Sequence_Type temp2 = (ASN1_Sequence_Type) tempType;
                        if (temp2.hasComponentWithName(identifier)) {
                            final CompField cf = temp2.getComponentByName(identifier);
                            tempType = cf.getType();
                        } else {
                            myType.getLocation().reportSemanticError(MessageFormat.format(NOCOMPONENTERROR, tempType.getFullName(), identifier.getDisplayName()));
                            return;
                        }
                        break;
                    }
                case TYPE_TTCN3_SEQUENCE:
                    {
                        final TTCN3_Sequence_Type temp2 = (TTCN3_Sequence_Type) tempType;
                        if (temp2.hasComponentWithName(identifier.getName())) {
                            tempType = temp2.getComponentByName(identifier.getName()).getType();
                        } else {
                            myType.getLocation().reportSemanticError(MessageFormat.format(NOCOMPONENTERROR, tempType.getFullName(), identifier.getDisplayName()));
                            return;
                        }
                        break;
                    }
                case TYPE_ASN1_SET:
                    {
                        final ASN1_Set_Type temp2 = (ASN1_Set_Type) tempType;
                        if (temp2.hasComponentWithName(identifier)) {
                            final CompField cf = temp2.getComponentByName(identifier);
                            tempType = cf.getType();
                        } else {
                            myType.getLocation().reportSemanticError(MessageFormat.format(NOCOMPONENTERROR, tempType.getFullName(), identifier.getDisplayName()));
                            return;
                        }
                        break;
                    }
                case TYPE_TTCN3_SET:
                    {
                        final TTCN3_Set_Type temp2 = (TTCN3_Set_Type) tempType;
                        if (temp2.hasComponentWithName(identifier.getName())) {
                            tempType = temp2.getComponentByName(identifier.getName()).getType();
                        } else {
                            myType.getLocation().reportSemanticError(MessageFormat.format(NOCOMPONENTERROR, tempType.getFullName(), identifier.getDisplayName()));
                            return;
                        }
                        break;
                    }
                default:
                    myType.getLocation().reportSemanticError(MessageFormat.format(SECHOEXPECTED, tempType.getFullName()));
                    return;
            }
        }
        atNotation.setLastComponent(tempType);
        /*
			 * check if the referenced component is constrained by the same objectset...
			 */
        boolean ok = false;
        final Constraints constraints = tempType.getConstraints();
        if (constraints != null) {
            constraints.check(timestamp);
            final TableConstraint tableConstraint = constraints.getTableConstraint();
            if (tableConstraint != null) {
                IType ocft = tableConstraint.constrainedType;
                if (Type_type.TYPE_OBJECTCLASSFIELDTYPE.equals(ocft.getTypetype())) {
                    atNotation.setObjectClassFieldname(((ObjectClassField_Type) ocft).getObjectClassFieldName());
                    IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                    ObjectSet_definition osdef1 = tableConstraint.objectSet.getRefdLast(timestamp, chain);
                    chain.release();
                    chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                    final ObjectSet_definition osdef2 = objectSet.getRefdLast(timestamp, chain);
                    chain.release();
                    if (osdef1 == osdef2) {
                        ok = true;
                    } else {
                        ok = false;
                    }
                }
            }
        }
        if (!ok) {
            myType.getLocation().reportSemanticError(SAMECONSTRAINTEXPECTED);
            return;
        }
    }
    if (objectSet instanceof Referenced_ObjectSet) {
        final Identifier objectSetId = ((Referenced_ObjectSet) objectSet).getId();
        collectTypesOfOpenType(timestamp, objectSet, openType, objectSetId);
    } else {
        // TODO: is it posssible? Perhaps log error!
        return;
    }
}
Also used : Open_Type(org.eclipse.titan.designer.AST.ASN1.types.Open_Type) AtNotation(org.eclipse.titan.designer.AST.AtNotation) ObjectSet_definition(org.eclipse.titan.designer.AST.ASN1.Object.ObjectSet_definition) ObjectClassField_Type(org.eclipse.titan.designer.AST.ASN1.types.ObjectClassField_Type) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) 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) Constraint(org.eclipse.titan.designer.AST.Constraint) IType(org.eclipse.titan.designer.AST.IType) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) Identifier(org.eclipse.titan.designer.AST.Identifier) Constraints(org.eclipse.titan.designer.AST.Constraints) IReferencingType(org.eclipse.titan.designer.AST.IReferencingType) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) Referenced_ObjectSet(org.eclipse.titan.designer.AST.ASN1.Object.Referenced_ObjectSet) TTCN3_Choice_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type) FieldName(org.eclipse.titan.designer.AST.ASN1.Object.FieldName)

Example 3 with ASN1_Choice_Type

use of org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type in project titan.EclipsePlug-ins by eclipse.

the class Reference method generateCode.

// originally fieldOrArrayRefs
private void generateCode(final JavaGenData aData, final ExpressionStruct expression, final boolean isTemplate, final boolean isConst, IType type) {
    for (int i = 1; i < subReferences.size(); i++) {
        if (type != null) {
            type = type.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
        }
        final ISubReference subreference = subReferences.get(i);
        if (Subreference_type.fieldSubReference.equals(subreference.getReferenceType())) {
            final Identifier id = ((FieldSubReference) subreference).getId();
            expression.expression.append(".");
            if (isConst) {
                expression.expression.append("constGet");
            } else {
                expression.expression.append("get");
            }
            expression.expression.append(FieldSubReference.getJavaGetterName(id.getName()));
            expression.expression.append("()");
            if (type != null) {
                CompField compField = null;
                switch(type.getTypetype()) {
                    case TYPE_TTCN3_CHOICE:
                    case TYPE_TTCN3_SEQUENCE:
                    case TYPE_TTCN3_SET:
                        compField = ((TTCN3_Set_Seq_Choice_BaseType) type).getComponentByName(id.getName());
                        break;
                    case TYPE_ANYTYPE:
                        compField = ((Anytype_Type) type).getComponentByName(id.getName());
                        break;
                    case TYPE_OPENTYPE:
                        compField = ((Open_Type) type).getComponentByName(id);
                        break;
                    case TYPE_ASN1_SEQUENCE:
                        ((ASN1_Sequence_Type) type).parseBlockSequence();
                        compField = ((ASN1_Sequence_Type) type).getComponentByName(id);
                        break;
                    case TYPE_ASN1_SET:
                        ((ASN1_Set_Type) type).parseBlockSet();
                        compField = ((ASN1_Set_Type) type).getComponentByName(id);
                        break;
                    case TYPE_ASN1_CHOICE:
                        ((ASN1_Choice_Type) type).parseBlockChoice();
                        compField = ((ASN1_Choice_Type) type).getComponentByName(id);
                        break;
                    default:
                        ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for reference `" + getFullName() + "''");
                        return;
                }
                if (i < subReferences.size() - 1 && compField != null && compField.isOptional() && !isTemplate) {
                    if (isConst) {
                        expression.expression.append(".constGet()");
                    } else {
                        expression.expression.append(".get()");
                    }
                    type = compField.getType();
                }
            }
        } else if (Subreference_type.arraySubReference.equals(subreference.getReferenceType())) {
            final Value value = ((ArraySubReference) subreference).getValue();
            // TODO actually should get the last governor
            final IType pt = value.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
            // generate "getAt" functions instead of operator[]
            if (isConst) {
                expression.expression.append(".constGetAt(");
            } else {
                expression.expression.append(".getAt(");
            }
            value.generateCodeExpression(aData, expression, false);
            expression.expression.append(")");
            if (type != null) {
                switch(type.getTypetype()) {
                    case TYPE_SEQUENCE_OF:
                    case TYPE_SET_OF:
                        type = ((AbstractOfType) type).getOfType();
                        break;
                    case TYPE_ARRAY:
                        type = ((Array_Type) type).getElementType();
                        break;
                    default:
                        type = null;
                }
            }
        }
    }
}
Also used : ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) AbstractOfType(org.eclipse.titan.designer.AST.TTCN3.types.AbstractOfType) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) Array_Type(org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)

Example 4 with ASN1_Choice_Type

use of org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type in project titan.EclipsePlug-ins by eclipse.

the class TTCN3_Choice_Type method isCompatible.

@Override
public /**
 * {@inheritDoc}
 */
boolean isCompatible(final CompilationTimeStamp timestamp, final IType otherType, final TypeCompatibilityInfo info, final TypeCompatibilityInfo.Chain leftChain, final TypeCompatibilityInfo.Chain rightChain) {
    check(timestamp);
    otherType.check(timestamp);
    final IType temp = otherType.getTypeRefdLast(timestamp);
    if (getIsErroneous(timestamp) || temp.getIsErroneous(timestamp) || this == temp) {
        return true;
    }
    if (info == null || noStructuredTypeCompatibility) {
        return this == temp;
    }
    switch(temp.getTypetype()) {
        case TYPE_ASN1_CHOICE:
            {
                final ASN1_Choice_Type tempType = (ASN1_Choice_Type) temp;
                TypeCompatibilityInfo.Chain lChain = leftChain;
                TypeCompatibilityInfo.Chain rChain = rightChain;
                if (lChain == null) {
                    lChain = info.getChain();
                    lChain.add(this);
                }
                if (rChain == null) {
                    rChain = info.getChain();
                    rChain.add(tempType);
                }
                for (int i = 0, size = getNofComponents(); i < size; i++) {
                    final CompField cf = getComponentByIndex(i);
                    final IType cfType = cf.getType().getTypeRefdLast(timestamp);
                    for (int j = 0, size2 = tempType.getNofComponents(timestamp); j < size2; j++) {
                        final CompField tempComponentField = tempType.getComponentByIndex(j);
                        final IType tempTypeCompFieldType = tempComponentField.getType().getTypeRefdLast(timestamp);
                        if (!cf.getIdentifier().getDisplayName().equals(tempComponentField.getIdentifier().getDisplayName())) {
                            continue;
                        }
                        lChain.markState();
                        rChain.markState();
                        lChain.add(cfType);
                        rChain.add(tempTypeCompFieldType);
                        if (cfType.equals(tempTypeCompFieldType) || (lChain.hasRecursion() && rChain.hasRecursion()) || cfType.isCompatible(timestamp, tempTypeCompFieldType, info, lChain, rChain)) {
                            info.setNeedsConversion(true);
                            lChain.previousState();
                            rChain.previousState();
                            return true;
                        }
                        lChain.previousState();
                        rChain.previousState();
                    }
                }
                info.setErrorStr(MessageFormat.format(NOCOMPATIBLEFIELD, temp.getTypename(), getTypename()));
                return false;
            }
        case TYPE_TTCN3_CHOICE:
            {
                final TTCN3_Choice_Type tempType = (TTCN3_Choice_Type) temp;
                if (this == tempType) {
                    return true;
                }
                TypeCompatibilityInfo.Chain lChain = leftChain;
                TypeCompatibilityInfo.Chain rChain = rightChain;
                if (lChain == null) {
                    lChain = info.getChain();
                    lChain.add(this);
                }
                if (rChain == null) {
                    rChain = info.getChain();
                    rChain.add(tempType);
                }
                for (int i = 0, size = getNofComponents(); i < size; i++) {
                    final CompField cf = getComponentByIndex(i);
                    final IType cfType = cf.getType().getTypeRefdLast(timestamp);
                    for (int j = 0, size2 = tempType.getNofComponents(); j < size2; j++) {
                        final CompField tempComponentField = tempType.getComponentByIndex(j);
                        final IType tempTypeCompFieldType = tempComponentField.getType().getTypeRefdLast(timestamp);
                        if (!cf.getIdentifier().getDisplayName().equals(tempComponentField.getIdentifier().getDisplayName())) {
                            continue;
                        }
                        lChain.markState();
                        rChain.markState();
                        lChain.add(cfType);
                        rChain.add(tempTypeCompFieldType);
                        if (cfType.equals(tempTypeCompFieldType) || (lChain.hasRecursion() && rChain.hasRecursion()) || cfType.isCompatible(timestamp, tempTypeCompFieldType, info, lChain, rChain)) {
                            info.setNeedsConversion(true);
                            lChain.previousState();
                            rChain.previousState();
                            return true;
                        }
                        lChain.previousState();
                        rChain.previousState();
                    }
                }
                info.setErrorStr(MessageFormat.format(NOCOMPATIBLEFIELD, temp.getTypename(), getTypename()));
                return false;
            }
        case TYPE_ASN1_SEQUENCE:
        case TYPE_TTCN3_SEQUENCE:
        case TYPE_SEQUENCE_OF:
        case TYPE_ARRAY:
        case TYPE_ASN1_SET:
        case TYPE_TTCN3_SET:
        case TYPE_SET_OF:
        case TYPE_ANYTYPE:
            info.setErrorStr(NOTCOMPATIBLEUNION);
            return false;
        default:
            return false;
    }
}
Also used : ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) CachedReferenceChain(org.eclipse.titan.designer.AST.CachedReferenceChain) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ReferenceChain(org.eclipse.titan.designer.AST.ReferenceChain) IType(org.eclipse.titan.designer.AST.IType)

Example 5 with ASN1_Choice_Type

use of org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type in project titan.EclipsePlug-ins by eclipse.

the class RenameRefactoring method checkFinalConditions.

@Override
public RefactoringStatus checkFinalConditions(final IProgressMonitor pm) throws CoreException {
    RefactoringStatus result = new RefactoringStatus();
    final boolean reportDebugInformation = Platform.getPreferencesService().getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null);
    // search
    idsMap = rf.findAllReferences(module, file.getProject(), pm, reportDebugInformation);
    // add the referred identifier to the map of found identifiers
    Identifier refdIdentifier = rf.getReferredIdentifier();
    Module refdModule = rf.assignment.getMyScope().getModuleScope();
    if (idsMap.containsKey(refdModule)) {
        idsMap.get(refdModule).add(new Hit(refdIdentifier));
    } else {
        ArrayList<Hit> identifierList = new ArrayList<Hit>();
        identifierList.add(new Hit(refdIdentifier));
        idsMap.put(refdModule, identifierList);
    }
    // scopes
    if (rf.fieldId == null) {
        // check that in all affected scopes there is no
        // definition with the new name
        Identifier.Identifier_type idType = Identifier_type.ID_TTCN;
        if (rf.scope.getModuleScope() instanceof ASN1Module) {
            idType = Identifier_type.ID_ASN;
        }
        Identifier newId = new Identifier(idType, newIdentifierName);
        // check for assignment with given id in all sub-scopes
        // of the assignment's scope
        // TODO: this does not detect runs on <-> component
        // member conflicts because the RunsOnScope is not a
        // sub-scope of the ComponentTypeBody scope,
        // also it does not go into other modules
        Scope rootScope = rf.assignment.getMyScope();
        if (rootScope instanceof NamedBridgeScope && rootScope.getParentScope() != null) {
            rootScope = rootScope.getParentScope();
        }
        SubScopeVisitor subScopeVisitor = new SubScopeVisitor(rootScope);
        module.accept(subScopeVisitor);
        List<Scope> subScopes = subScopeVisitor.getSubScopes();
        subScopes.add(rootScope);
        for (Scope ss : subScopes) {
            if (ss.hasAssignmentWithId(CompilationTimeStamp.getBaseTimestamp(), newId)) {
                List<ISubReference> subReferences = new ArrayList<ISubReference>();
                subReferences.add(new FieldSubReference(newId));
                Reference reference = new Reference(null, subReferences);
                Assignment assignment = ss.getAssBySRef(CompilationTimeStamp.getBaseTimestamp(), reference);
                if (assignment != null && assignment.getLocation() != null) {
                    result.addError(MessageFormat.format(DEFINITIONALREADYEXISTS2, newId.getDisplayName(), module.getName(), assignment.getLocation().getLine()));
                } else {
                    result.addError(MessageFormat.format(DEFINITIONALREADYEXISTS, newId.getDisplayName()));
                }
                // to avoid spam and multiple messages for the same conflict
                return result;
            }
        }
    } else {
        boolean alreadyExists = false;
        // name
        if (rf.type instanceof TTCN3_Set_Seq_Choice_BaseType) {
            alreadyExists = ((TTCN3_Set_Seq_Choice_BaseType) rf.type).hasComponentWithName(newIdentifierName);
        } else if (rf.type instanceof TTCN3_Enumerated_Type) {
            alreadyExists = ((TTCN3_Enumerated_Type) rf.type).hasEnumItemWithName(new Identifier(Identifier_type.ID_TTCN, newIdentifierName));
        } else if (rf.type instanceof ASN1_Choice_Type) {
            alreadyExists = ((ASN1_Choice_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
        } else if (rf.type instanceof ASN1_Enumerated_Type) {
            alreadyExists = ((ASN1_Enumerated_Type) rf.type).hasEnumItemWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
        } else if (rf.type instanceof ASN1_Sequence_Type) {
            alreadyExists = ((ASN1_Sequence_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
        } else if (rf.type instanceof ASN1_Set_Type) {
            alreadyExists = ((ASN1_Set_Type) rf.type).hasComponentWithName(new Identifier(Identifier_type.ID_ASN, newIdentifierName));
        }
        if (alreadyExists) {
            result.addError(MessageFormat.format(FIELDALREADYEXISTS, newIdentifierName, rf.type.getTypename()));
        }
    }
    return result;
}
Also used : Identifier_type(org.eclipse.titan.designer.AST.Identifier.Identifier_type) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) SubScopeVisitor(org.eclipse.titan.designer.AST.SubScopeVisitor) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) ASN1_Enumerated_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Enumerated_Type) Assignment(org.eclipse.titan.designer.AST.Assignment) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) ISubReference(org.eclipse.titan.designer.AST.ISubReference) Hit(org.eclipse.titan.designer.AST.ReferenceFinder.Hit) ASN1Module(org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module) Identifier(org.eclipse.titan.designer.AST.Identifier) Scope(org.eclipse.titan.designer.AST.Scope) NamedBridgeScope(org.eclipse.titan.designer.AST.NamedBridgeScope) NamedBridgeScope(org.eclipse.titan.designer.AST.NamedBridgeScope) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) TTCN3_Set_Seq_Choice_BaseType(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Seq_Choice_BaseType) Module(org.eclipse.titan.designer.AST.Module) ASN1Module(org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module)

Aggregations

ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)8 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)5 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)5 IType (org.eclipse.titan.designer.AST.IType)5 Identifier (org.eclipse.titan.designer.AST.Identifier)4 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)4 Open_Type (org.eclipse.titan.designer.AST.ASN1.types.Open_Type)3 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)3 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)3 ISubReference (org.eclipse.titan.designer.AST.ISubReference)3 Reference (org.eclipse.titan.designer.AST.Reference)3 TTCN3_Choice_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type)3 Assignment (org.eclipse.titan.designer.AST.Assignment)2 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)2 IValue (org.eclipse.titan.designer.AST.IValue)2 AbstractOfType (org.eclipse.titan.designer.AST.TTCN3.types.AbstractOfType)2 Anytype_Type (org.eclipse.titan.designer.AST.TTCN3.types.Anytype_Type)2 Array_Type (org.eclipse.titan.designer.AST.TTCN3.types.Array_Type)2 TTCN3_Sequence_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type)2 TTCN3_Set_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type)2