/
SarlSpecificationChecker.sarl
103 lines (93 loc) · 3.5 KB
/
SarlSpecificationChecker.sarl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2017 the original authors or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.sarl.sarlspecification
import org.osgi.framework.Version
import io.sarl.lang.^annotation.SarlSpecification
import io.sarl.lang.SARLVersion
/** Check if a given agent class follows a specific version of the SARL specifications.
*
* @author $Author: ssgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.5
*/
interface SarlSpecificationChecker {
/** Replies the supported SARL specification version of the given type.
*
* @param type the type from which the SARL specification version should be extracted.
* @return The SARL specification version. The version is a floating-point number, as for
* {@link SARLVersion#SPECIFICATION_RELEASE_VERSION}. The value {@link Float#NaN} is replied
* if the given type has no marker related to the SARL specification version.
*/
def getSarlSpecificationVersion(type : Class<?>) : float {
if (type !== null) {
var annotationInstance = type.getAnnotation(typeof(SarlSpecification))
if (annotationInstance !== null) {
val versionString = annotationInstance.value
val version = Version::parseVersion(versionString)
if (Version::emptyVersion != version) {
var minor = version.minor
var factor = 1f
while (minor > 0) {
factor *= 10
minor /= 10
}
return version.major + version.minor / factor
}
}
}
return Float::NaN
}
/** Compare the SARL specification version associated to the given type to the version of the
* current SARL.
*
* @param type the type to test.
* @return a negative integer value if the type's version is lower than the version of the current SARL,
* zero if the two versions are equal, a positive integer value if type's version is greater
* than the version of the current SARL.
*/
def compareToSarlSpecificationVersion(type : Class<?>) : int {
type.sarlSpecificationVersion <=> SARLVersion::SPECIFICATION_RELEASE_VERSION
}
/** Replies if the given type is a SARL element that is following the specification of the current SARL version.
*
* @param type the type to test.
* @return <code>true</code> if the given type follows the specification of the current version.
*/
def isValidSarlElement(type : Class<?>) : boolean {
// TODO: Unless we have reach the version 1.0, all the versions are incompatible.
type.sarlSpecificationVersion == SARLVersion::SPECIFICATION_RELEASE_VERSION
}
}
/** Check if a given agent class follows a specific version of the SARL specifications.
*
* <p>This implementation uses the default implementation given by the interface.
*
* @author $Author: ssgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.5
*/
final class StandardSarlSpecificationChecker implements SarlSpecificationChecker {
//
}