use of org.eclipse.titan.designer.AST.TTCN3.attributes.VersionRequirementAttribute 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;
}
}
}
Aggregations