Search in sources :

Example 1 with PortTypeAttribute

use of org.eclipse.titan.designer.AST.TTCN3.attributes.PortTypeAttribute in project titan.EclipsePlug-ins by eclipse.

the class PortTypeBody method checkAttributes.

/**
 * Does the semantic checking of the attributes assigned to the port type having this body.
 *
 * @param timestamp the time stamp of the actual semantic check cycle.
 * @param withAttributesPath the withAttributesPath assigned to the port type.
 */
public void checkAttributes(final CompilationTimeStamp timestamp, final WithAttributesPath withAttributesPath) {
    if (lastTimeAttributesChecked != null && !lastTimeAttributesChecked.isLess(timestamp)) {
        return;
    }
    lastTimeAttributesChecked = lastTimeChecked;
    final List<SingleWithAttribute> realAttributes = withAttributesPath.getRealAttributes(timestamp);
    SingleWithAttribute attribute;
    List<AttributeSpecification> specifications = null;
    for (int i = 0; i < realAttributes.size(); i++) {
        attribute = realAttributes.get(i);
        if (Attribute_Type.Extension_Attribute.equals(attribute.getAttributeType())) {
            final Qualifiers qualifiers = attribute.getQualifiers();
            if (qualifiers == null || qualifiers.getNofQualifiers() == 0) {
                if (specifications == null) {
                    specifications = new ArrayList<AttributeSpecification>();
                }
                final AttributeSpecification specification = attribute.getAttributeSpecification();
                if (specification.getSpecification() != null) {
                    // there is nothing to parse if specification string is null,
                    // anyway it would cause NPE in ExtensionAttributeAnalyzer.parse()
                    specifications.add(specification);
                }
            }
        }
    }
    if (specifications == null) {
        return;
    }
    final List<ExtensionAttribute> attributes = new ArrayList<ExtensionAttribute>();
    AttributeSpecification specification;
    for (int i = 0; i < specifications.size(); i++) {
        specification = specifications.get(i);
        final ExtensionAttributeAnalyzer analyzer = new ExtensionAttributeAnalyzer();
        analyzer.parse(specification);
        final List<ExtensionAttribute> temp = analyzer.getAttributes();
        if (temp != null) {
            attributes.addAll(temp);
        }
    }
    if (attributes.isEmpty()) {
        return;
    }
    // clear the old attributes
    testportType = TestPortAPI_type.TP_REGULAR;
    portType = PortType_type.PT_REGULAR;
    // check the new attributes
    for (int i = 0; i < attributes.size(); i++) {
        final ExtensionAttribute extensionAttribute = attributes.get(i);
        if (ExtensionAttribute_type.PORTTYPE.equals(extensionAttribute.getAttributeType())) {
            final PortTypeAttribute portAttribute = (PortTypeAttribute) extensionAttribute;
            switch(portAttribute.getPortTypeType()) {
                case INTERNAL:
                    switch(testportType) {
                        case TP_REGULAR:
                            break;
                        case TP_INTERNAL:
                            extensionAttribute.getLocation().reportSemanticWarning("Duplicate attribute `internal'");
                            break;
                        case TP_ADDRESS:
                            extensionAttribute.getLocation().reportSemanticError("Attributes `address' and `internal' cannot be used at the same time");
                            break;
                        default:
                            break;
                    }
                    testportType = TestPortAPI_type.TP_INTERNAL;
                    break;
                case ADDRESS:
                    switch(testportType) {
                        case TP_REGULAR:
                            break;
                        case TP_INTERNAL:
                            extensionAttribute.getLocation().reportSemanticError("Attributes `address' and `internal' cannot be used at the same time");
                            break;
                        case TP_ADDRESS:
                            extensionAttribute.getLocation().reportSemanticWarning("Duplicate attribute `address'");
                            break;
                        default:
                            break;
                    }
                    testportType = TestPortAPI_type.TP_ADDRESS;
                    break;
                case PROVIDER:
                    switch(portType) {
                        case PT_REGULAR:
                            break;
                        case PT_PROVIDER:
                            extensionAttribute.getLocation().reportSemanticWarning("Duplicate attribute `provider'");
                            break;
                        case PT_USER:
                            extensionAttribute.getLocation().reportSemanticError("Attributes `user' and `provider' cannot be used at the same time");
                            break;
                        default:
                            break;
                    }
                    addProviderAttribute();
                    break;
                case USER:
                    switch(portType) {
                        case PT_REGULAR:
                            break;
                        case PT_PROVIDER:
                            extensionAttribute.getLocation().reportSemanticError("Attributes `provider' and `user' cannot be used at the same time");
                            break;
                        case PT_USER:
                            extensionAttribute.getLocation().reportSemanticError("Duplicate attribute `user'");
                            break;
                        default:
                            break;
                    }
                    final UserPortTypeAttribute user = (UserPortTypeAttribute) portAttribute;
                    addUserAttribute(user.getReference(), user.getInMappings(), user.getOutMappings());
                    break;
                default:
                    break;
            }
        }
    }
    if (PortType_type.PT_USER.equals(portType)) {
        checkUserAttribute(timestamp);
    } else if (TestPortAPI_type.TP_ADDRESS.equals(testportType)) {
        final TTCN3Module module = (TTCN3Module) myType.getMyScope().getModuleScope();
        if (module.getAddressType(timestamp) == null) {
            location.reportSemanticError(MessageFormat.format("Type `address'' is not defined in module `{0}''", module.getIdentifier().getDisplayName()));
        }
    }
}
Also used : PortTypeAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.PortTypeAttribute) UserPortTypeAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.UserPortTypeAttribute) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) ArrayList(java.util.ArrayList) SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute) ExtensionAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionAttribute) AttributeSpecification(org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification) ExtensionAttributeAnalyzer(org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer) UserPortTypeAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.UserPortTypeAttribute) Qualifiers(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers)

Aggregations

ArrayList (java.util.ArrayList)1 AttributeSpecification (org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification)1 ExtensionAttribute (org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionAttribute)1 PortTypeAttribute (org.eclipse.titan.designer.AST.TTCN3.attributes.PortTypeAttribute)1 Qualifiers (org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers)1 SingleWithAttribute (org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute)1 UserPortTypeAttribute (org.eclipse.titan.designer.AST.TTCN3.attributes.UserPortTypeAttribute)1 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)1 ExtensionAttributeAnalyzer (org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer)1