UNPKG

2.11 kBJavaScriptView Raw
1/*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14
15'use strict';
16
17const ClassDeclaration = require('./classdeclaration');
18
19/**
20 * EnumDeclaration defines an enumeration of static values.
21 *
22 * @extends ClassDeclaration
23 * @see See {@link ClassDeclaration}
24 * @class
25 * @memberof module:concerto-core
26 */
27class EnumDeclaration extends ClassDeclaration {
28
29 /**
30 * Create an AssetDeclaration.
31 * @param {ModelFile} modelFile the ModelFile for this class
32 * @param {Object} ast - The AST created by the parser
33 * @throws {IllegalModelException}
34 */
35 constructor(modelFile, ast) {
36 super(modelFile, ast);
37 this._isEnumDeclaration = true;
38 }
39
40 /**
41 * Returns true if this class is an enumeration.
42 *
43 * @return {boolean} true if the class is an enumerated type
44 */
45 isEnum() {
46 return true;
47 }
48
49 /**
50 * Returns the string representation of this class
51 * @return {String} the string representation of the class
52 */
53 toString() {
54 return 'EnumDeclaration {id=' + this.getFullyQualifiedName() + '}';
55 }
56
57 /**
58 * Alternative instanceof that is reliable across different module instances
59 * @see https://github.com/hyperledger/composer-concerto/issues/47
60 *
61 * @param {object} object - The object to test against
62 * @returns {boolean} - True, if the object is an instance of a Class Declaration
63 */
64 static [Symbol.hasInstance](object){
65 return typeof object !== 'undefined' && object !== null && Boolean(object._isEnumDeclaration);
66 }
67}
68
69module.exports = EnumDeclaration;