Search in sources :

Example 6 with AttributeSpecification

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

the class TTCN3Module method analyzeExtensionAttributes.

/**
 * Convert and check the version, requires and titan version extension attributes.
 *
 * @param timestamp
 *                the timestamp of the actual build cycle.
 */
private void analyzeExtensionAttributes(final CompilationTimeStamp timestamp) {
    if (withAttributesPath == null) {
        return;
    }
    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>();
                }
                specifications.add(attribute.getAttributeSpecification());
            }
        }
    }
    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);
        }
    }
    ExtensionAttribute extensionAttribute;
    for (int i = 0; i < attributes.size(); i++) {
        extensionAttribute = attributes.get(i);
        switch(extensionAttribute.getAttributeType()) {
            case VERSION:
                {
                    final ModuleVersionAttribute moduleVersion = (ModuleVersionAttribute) extensionAttribute;
                    moduleVersion.parse();
                    if (versionNumber != null) {
                        moduleVersion.getLocation().reportSemanticError("Duplicate version attribute");
                    } else {
                        setVersion(moduleVersion.getVersionNumber());
                    }
                    break;
                }
            case REQUIRES:
                {
                    final VersionRequirementAttribute versionReq = (VersionRequirementAttribute) extensionAttribute;
                    versionReq.parse();
                    ImportModule theImport = null;
                    final String requiredModuleName = versionReq.getRequiredModule().getName();
                    for (final ImportModule impMod : importedModules) {
                        if (requiredModuleName.equals(impMod.getIdentifier().getName())) {
                            theImport = impMod;
                            break;
                        }
                    }
                    if (theImport == null) {
                        final String message = MessageFormat.format(ImportModule.MISSINGMODULE, versionReq.getRequiredModule().getDisplayName());
                        versionReq.getRequiredModule().getLocation().reportSemanticError(message);
                    } else {
                        final TTCN3Module theImportedModule = (TTCN3Module) theImport.getReferredModule();
                        // make sure the version attribute is parsed (if any)
                        theImportedModule.check(timestamp);
                        final ProductIdentity requiredVersion = versionReq.getVersionNumber();
                        if (requiredVersion != null && theImportedModule.versionNumber != null && theImportedModule.versionNumber.compareTo(requiredVersion) < 0) {
                            final String message = MessageFormat.format("Module `{0}'' requires version {1} of module `{2}'', but only version {3} is available", identifier.getDisplayName(), requiredVersion.toString(), theImportedModule.getIdentifier().getDisplayName(), theImportedModule.versionNumber.toString());
                            versionReq.getLocation().reportSemanticError(message);
                        }
                    }
                    break;
                }
            case TITANVERSION:
                {
                    final TitanVersionAttribute titanReq = (TitanVersionAttribute) extensionAttribute;
                    titanReq.parse();
                    final ProductIdentity requiredTITANVersion = titanReq.getVersionNumber();
                    final String temp = CompilerVersionInformationCollector.getCompilerProductNumber();
                    final ProductIdentity compilerVersion = ProductIdentityHelper.getProductIdentity(temp, null);
                    if (requiredTITANVersion != null && compilerVersion != null && compilerVersion.compareTo(requiredTITANVersion) < 0) {
                        final String message = MessageFormat.format("Module `{0}'' requires TITAN version {1}, but version {2} is used right now", identifier.getDisplayName(), requiredTITANVersion.toString(), compilerVersion.toString());
                        titanReq.getLocation().reportSemanticError(message);
                    }
                    if (requiredTITANVersion != null && GeneralConstants.ON_THE_FLY_ANALYZER_VERSION != null && GeneralConstants.ON_THE_FLY_ANALYZER_VERSION.compareTo(requiredTITANVersion) < 0) {
                        final String message = MessageFormat.format("Module `{0}'' requires TITAN version {1}, but the on-the-fly analyzer is of version {2}", identifier.getDisplayName(), requiredTITANVersion.toString(), GeneralConstants.ON_THE_FLY_ANALYZER_VERSION.toString());
                        titanReq.getLocation().reportSemanticError(message);
                    }
                    break;
                }
            default:
                // we don't care
                break;
        }
    }
}
Also used : ModuleVersionAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.ModuleVersionAttribute) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) 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) VersionRequirementAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.VersionRequirementAttribute) ProductIdentity(org.eclipse.titan.common.product.ProductIdentity) ExtensionAttributeAnalyzer(org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer) TitanVersionAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.TitanVersionAttribute) Qualifiers(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers)

Example 7 with AttributeSpecification

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

Example 8 with AttributeSpecification

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

the class ComponentTypeBody method collectExtensionAttributes.

/**
 * Collects the extends extension attributes, from the with attributes assigned to the component type.
 *
 * @param timestamp the timestamp of the actual semantic check cycle
 */
private void collectExtensionAttributes(final CompilationTimeStamp timestamp) {
    if (withAttributesPath == null) {
        return;
    }
    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>();
                }
                specifications.add(attribute.getAttributeSpecification());
            }
        }
    }
    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;
    }
    attrExtendsReferences = new ComponentTypeReferenceList();
    for (int i = 0, size = attributes.size(); i < size; i++) {
        final ExtensionAttribute tempAttribute = attributes.get(i);
        if (ExtensionAttribute_type.EXTENDS.equals(tempAttribute.getAttributeType())) {
            final ExtensionsAttribute extensionsAttribute = (ExtensionsAttribute) tempAttribute;
            for (int j = 0, size2 = extensionsAttribute.getNofTypes(); j < size2; j++) {
                final IType tempType = extensionsAttribute.getType(j);
                if (Type_type.TYPE_REFERENCED.equals(tempType.getTypetype())) {
                    attrExtendsReferences.addReference(((Referenced_Type) tempType).getReference());
                }
            }
        }
    }
    attrExtendsReferences.setFullNameParent(new BridgingNamedNode(this, ".<extends attribute>"));
    attrExtendsReferences.setMyScope(parentScope);
}
Also used : ArrayList(java.util.ArrayList) SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) ExtensionAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionAttribute) IType(org.eclipse.titan.designer.AST.IType) AttributeSpecification(org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification) ExtensionsAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionsAttribute) ExtensionAttributeAnalyzer(org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer) Qualifiers(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers)

Aggregations

ArrayList (java.util.ArrayList)7 AttributeSpecification (org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification)7 ExtensionAttribute (org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionAttribute)7 Qualifiers (org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers)7 SingleWithAttribute (org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute)7 ExtensionAttributeAnalyzer (org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer)7 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2 IType (org.eclipse.titan.designer.AST.IType)2 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)2 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 CharStream (org.antlr.v4.runtime.CharStream)1 CommonTokenFactory (org.antlr.v4.runtime.CommonTokenFactory)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 UnbufferedCharStream (org.antlr.v4.runtime.UnbufferedCharStream)1 IFile (org.eclipse.core.resources.IFile)1 SyntacticErrorStorage (org.eclipse.titan.common.parsers.SyntacticErrorStorage)1 TITANMarker (org.eclipse.titan.common.parsers.TITANMarker)1 TitanListener (org.eclipse.titan.common.parsers.TitanListener)1