Search in sources :

Example 6 with TTCN3_Enumerated_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_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)

Example 7 with TTCN3_Enumerated_Type

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

the class Def_Type_Visit_Handler method handleDefTypeNodes.

public void handleDefTypeNodes(IVisitableNode node) {
    Def_Type typeNode = (Def_Type) node;
    CompilationTimeStamp compilationCounter = CompilationTimeStamp.getNewCompilationCounter();
    myASTVisitor.currentFileName = typeNode.getIdentifier().toString();
    Type type = typeNode.getType(compilationCounter);
    if (type.getTypetype().equals(TYPE_TTCN3_SEQUENCE)) {
        // record
        Def_Type_Record_Writer recordNode = new Def_Type_Record_Writer(typeNode);
        // add component fields
        recordNode.add(compFieldTypes, compFieldNames);
        String[] typeArray = (String[]) compFieldTypes.toArray(new String[compFieldTypes.size()]);
        String[] nameArray = (String[]) compFieldNames.toArray(new String[compFieldNames.size()]);
        myASTVisitor.nodeNameChildrenTypesHashMap.put(parentName, typeArray);
        myASTVisitor.nodeNameChildrenNamesHashMap.put(parentName, nameArray);
        compFieldTypes.clear();
        compFieldNames.clear();
        myASTVisitor.visualizeNodeToJava(recordNode.getJavaSource());
    } else if (type.getTypetype().equals(TYPE_TTCN3_SET)) {
        // set
        Def_Type_Set_Writer setNode = new Def_Type_Set_Writer(typeNode);
        // add component fields
        setNode.add(compFieldTypes, compFieldNames);
        String[] typeArray = (String[]) compFieldTypes.toArray(new String[compFieldTypes.size()]);
        String[] nameArray = (String[]) compFieldNames.toArray(new String[compFieldNames.size()]);
        myASTVisitor.nodeNameChildrenTypesHashMap.put(parentName, typeArray);
        myASTVisitor.nodeNameChildrenNamesHashMap.put(parentName, nameArray);
        compFieldTypes.clear();
        compFieldNames.clear();
        myASTVisitor.visualizeNodeToJava(setNode.getJavaSource());
    } else if (type.getTypetype().equals(TYPE_TTCN3_CHOICE)) {
        // union
        Def_Type_Union_Writer union_writer = new Def_Type_Union_Writer(typeNode);
        // add component fields
        union_writer.add(compFieldTypes, compFieldNames);
        String[] typeArray = compFieldTypes.toArray(new String[compFieldTypes.size()]);
        String[] nameArray = compFieldNames.toArray(new String[compFieldNames.size()]);
        myASTVisitor.nodeNameChildrenTypesHashMap.put(parentName, typeArray);
        myASTVisitor.nodeNameChildrenNamesHashMap.put(parentName, nameArray);
        compFieldTypes.clear();
        compFieldNames.clear();
        myASTVisitor.visualizeNodeToJava(union_writer.getJavaSource());
    } else if (type instanceof Integer_Type) {
        Def_Type_Integer_Writer integerNode = Def_Type_Integer_Writer.getInstance(typeNode);
        integerNode.clearLists();
        myASTVisitor.visualizeNodeToJava(integerNode.getJavaSource());
    } else if (type instanceof CharString_Type) {
        Def_Type_Charstring_Writer charstringNode = Def_Type_Charstring_Writer.getInstance(typeNode);
        charstringNode.clearLists();
        charstringNode.addCharStringValue(charstringValue);
        charstringValue = null;
        myASTVisitor.visualizeNodeToJava(charstringNode.getJavaSource());
    } else if (type instanceof TTCN3_Enumerated_Type) {
        Def_Type_Enum_Writer enumTypeNode = Def_Type_Enum_Writer.getInstance(typeNode);
        enumTypeNode.clearLists();
        enumTypeNode.enumItems.addAll(enumItems);
        enumTypeNode.enumItemValues.addAll(enumItemValues);
        enumItemValues.clear();
        enumItems.clear();
        myASTVisitor.visualizeNodeToJava(enumTypeNode.getJavaSource());
    } else if (type.getTypetype().equals(TYPE_SET_OF)) {
        Def_Type_Set_Of_Writer setOfNode = new Def_Type_Set_Of_Writer(typeNode);
        setOfNode.setFieldType(setOfFieldType);
        setOfFieldType = null;
        myASTVisitor.visualizeNodeToJava(setOfNode.getJavaSource());
    } else if (type.getTypetype().equals(TYPE_SEQUENCE_OF)) {
        Def_Type_Record_Of_Writer writer = new Def_Type_Record_Of_Writer(typeNode);
        writer.setFieldType(recordOfFieldType);
        myASTVisitor.visualizeNodeToJava(writer.getJavaSource());
    } else if (type.getTypetype().equals(TYPE_PORT)) {
        Def_Type_Port_Writer portNode = Def_Type_Port_Writer.getInstance(typeNode);
        portNode.clearLists();
        portNode.inMessageName.addAll(inMessageName);
        portNode.outMessageName.addAll(outMessageName);
        portNode.inOutMessageName.addAll(inOutMessageName);
        portNode.setPortTypeAReferencedType(isPortTypeAReferencedType);
        waitingForPortAttriburtes = false;
        isPortTypeAReferencedType = false;
        inMessageName.clear();
        outMessageName.clear();
        inOutMessageName.clear();
        myASTVisitor.visualizeNodeToJava(portNode.getJavaSource());
    } else if (type.getTypetype().equals(TYPE_COMPONENT)) {
        Def_Type_Component_Writer compNode = Def_Type_Component_Writer.getInstance(typeNode);
        compNode.clearLists();
        // add component fields
        compNode.compFieldPortTypes.addAll(componentPortTypes);
        compNode.compFieldPortNames.addAll(componentPortNames);
        compNode.compFieldVarTypes.addAll(componentVarTypes);
        compNode.compFieldVarNames.addAll(componentVarNames);
        componentPortTypes.clear();
        componentPortNames.clear();
        componentVarTypes.clear();
        componentVarNames.clear();
        waitForCompReference = false;
        myASTVisitor.visualizeNodeToJava(compNode.getJavaSource());
    }
    parentName = null;
}
Also used : Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) CharString_Type(org.eclipse.titan.designer.AST.TTCN3.types.CharString_Type) Range_ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Range_ParsedSubType) SequenceOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) SetOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) Type(org.eclipse.titan.designer.AST.Type) Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) CharString_Type(org.eclipse.titan.designer.AST.TTCN3.types.CharString_Type) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) CompilationTimeStamp(org.eclipse.titan.designer.parsers.CompilationTimeStamp)

Example 8 with TTCN3_Enumerated_Type

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

the class LessThanOrEqualExpression method evaluateValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    isErroneous = false;
    lastTimeChecked = timestamp;
    lastValue = this;
    if (value1 == null || value2 == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp) || isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final IValue last1 = value1.getValueRefdLast(timestamp, referenceChain);
    final IValue last2 = value2.getValueRefdLast(timestamp, referenceChain);
    if (last1.getIsErroneous(timestamp) || last2.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return lastValue;
    }
    switch(last1.getValuetype()) {
        case INTEGER_VALUE:
            {
                lastValue = new Boolean_Value(((Integer_Value) last1).compareTo((Integer_Value) last2) <= 0);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case REAL_VALUE:
            {
                final double float1 = ((Real_Value) last1).getValue();
                final double float2 = ((Real_Value) last2).getValue();
                lastValue = new Boolean_Value(Double.compare(float1, float2) <= 0);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case ENUMERATED_VALUE:
            {
                IType governor1 = last1.getExpressionGovernor(timestamp, expectedValue);
                governor1 = governor1.getTypeRefdLast(timestamp);
                IType governor2 = last2.getExpressionGovernor(timestamp, expectedValue);
                governor2 = governor2.getTypeRefdLast(timestamp);
                if (governor1 instanceof TTCN3_Enumerated_Type) {
                    final EnumItem item1 = ((TTCN3_Enumerated_Type) governor1).getEnumItemWithName(((Enumerated_Value) last1).getValue());
                    final EnumItem item2 = ((TTCN3_Enumerated_Type) governor2).getEnumItemWithName(((Enumerated_Value) last2).getValue());
                    lastValue = new Boolean_Value(((Integer_Value) item1.getValue()).intValue() <= ((Integer_Value) item2.getValue()).intValue());
                    lastValue.copyGeneralProperties(this);
                } else {
                    final EnumItem item1 = ((ASN1_Enumerated_Type) governor1).getEnumItemWithName(((Enumerated_Value) last1).getValue());
                    final EnumItem item2 = ((ASN1_Enumerated_Type) governor2).getEnumItemWithName(((Enumerated_Value) last2).getValue());
                    lastValue = new Boolean_Value(((Integer_Value) item1.getValue()).intValue() <= ((Integer_Value) item2.getValue()).intValue());
                    lastValue.copyGeneralProperties(this);
                }
                break;
            }
        default:
            setIsErroneous(true);
    }
    return lastValue;
}
Also used : Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) IValue(org.eclipse.titan.designer.AST.IValue) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) EnumItem(org.eclipse.titan.designer.AST.TTCN3.types.EnumItem) Enumerated_Value(org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value) IType(org.eclipse.titan.designer.AST.IType)

Example 9 with TTCN3_Enumerated_Type

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

the class GreaterThanExpression method evaluateValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    isErroneous = false;
    lastTimeChecked = timestamp;
    lastValue = this;
    if (value1 == null || value2 == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp) || isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final IValue last1 = value1.getValueRefdLast(timestamp, referenceChain);
    final IValue last2 = value2.getValueRefdLast(timestamp, referenceChain);
    if (last1.getIsErroneous(timestamp) || last2.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return lastValue;
    }
    switch(last1.getValuetype()) {
        case INTEGER_VALUE:
            {
                lastValue = new Boolean_Value(((Integer_Value) last1).compareTo((Integer_Value) last2) > 0);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case REAL_VALUE:
            {
                final double float1 = ((Real_Value) last1).getValue();
                final double float2 = ((Real_Value) last2).getValue();
                lastValue = new Boolean_Value(Double.compare(float1, float2) > 0);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case ENUMERATED_VALUE:
            {
                IType governor1 = last1.getExpressionGovernor(timestamp, expectedValue);
                governor1 = governor1.getTypeRefdLast(timestamp);
                IType governor2 = last2.getExpressionGovernor(timestamp, expectedValue);
                governor2 = governor2.getTypeRefdLast(timestamp);
                if (governor1 instanceof TTCN3_Enumerated_Type) {
                    final EnumItem item1 = ((TTCN3_Enumerated_Type) governor1).getEnumItemWithName(((Enumerated_Value) last1).getValue());
                    final EnumItem item2 = ((TTCN3_Enumerated_Type) governor2).getEnumItemWithName(((Enumerated_Value) last2).getValue());
                    lastValue = new Boolean_Value(((Integer_Value) item1.getValue()).intValue() > ((Integer_Value) item2.getValue()).intValue());
                    lastValue.copyGeneralProperties(this);
                } else {
                    final EnumItem item1 = ((ASN1_Enumerated_Type) governor1).getEnumItemWithName(((Enumerated_Value) last1).getValue());
                    final EnumItem item2 = ((ASN1_Enumerated_Type) governor2).getEnumItemWithName(((Enumerated_Value) last2).getValue());
                    lastValue = new Boolean_Value(((Integer_Value) item1.getValue()).intValue() > ((Integer_Value) item2.getValue()).intValue());
                    lastValue.copyGeneralProperties(this);
                }
                break;
            }
        default:
            setIsErroneous(true);
    }
    return lastValue;
}
Also used : Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) IValue(org.eclipse.titan.designer.AST.IValue) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) EnumItem(org.eclipse.titan.designer.AST.TTCN3.types.EnumItem) Enumerated_Value(org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

TTCN3_Enumerated_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type)8 IType (org.eclipse.titan.designer.AST.IType)6 IValue (org.eclipse.titan.designer.AST.IValue)6 Enumerated_Value (org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value)6 EnumItem (org.eclipse.titan.designer.AST.TTCN3.types.EnumItem)5 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)5 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)4 Referenced_Type (org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)3 Identifier (org.eclipse.titan.designer.AST.Identifier)2 Def_Type (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type)2 CharString_Type (org.eclipse.titan.designer.AST.TTCN3.types.CharString_Type)2 Integer_Type (org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type)2 SequenceOf_Type (org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type)2 SetOf_Type (org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type)2 Range_ParsedSubType (org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Range_ParsedSubType)2 Type (org.eclipse.titan.designer.AST.Type)2 ArrayList (java.util.ArrayList)1 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)1 ASN1Module (org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module)1 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)1