UNPKG

4.2 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
17/**
18 * FunctionDeclaration defines a function that has been defined
19 * in a model file. If the name of the function starts with 'on'
20 * then the name of the function denotes the name of a transaction
21 * declaration that the function processes.
22 *
23 * @class
24 * @memberof module:ergo-compiler
25 */
26class FunctionDeclaration {
27
28 /**
29 * Create a FunctionDeclaration
30 *
31 * @param {ModelManager} modelManager - the ModelManager used to validate this function
32 * @param {string} language - the language that the function is written in. E.g. JS.
33 * @param {string} name - the name of the function
34 * @param {string} visibility - the visibility of the function
35 * @param {string} returnType - the return type of the function
36 * @param {string} throws - the type that is thrown by the function
37 * @param {string[]} parameterNames - the names of parameters of the function
38 * @param {string[]} parameterTypes - the type names of parameters of the function
39 * @param {string[]} decorators - the function decorators
40 * @param {string} functionText - the function as text
41 * @throws {IllegalModelException}
42 */
43 constructor(modelManager, language, name, visibility, returnType, throws, parameterNames, parameterTypes, decorators, functionText) {
44
45 if(modelManager === null) {
46 throw new Error('ModelManager is required.');
47 }
48
49 this.modelManager = modelManager;
50 this.name = name;
51 this.language = language;
52 this.visibility = visibility;
53 this.returnType = returnType;
54 this.throws = throws;
55 this.decorators = decorators;
56 this.parameterNames = parameterNames;
57 this.parameterTypes = parameterTypes;
58 this.functionText = functionText;
59 }
60
61 /**
62 * Returns the text of this function.
63 *
64 * @return {string} the text that defines the function
65 */
66 getFunctionText() {
67 return this.functionText;
68 }
69
70 /**
71 * Returns the type thrown by this function
72 *
73 * @return {string} the type thrown by the function
74 */
75 getThrows() {
76 return this.throws;
77 }
78
79 /**
80 * Returns the programming language that the function is written in
81 *
82 * @return {string} the language of the function
83 */
84 getLanguage() {
85 return this.language;
86 }
87
88 /**
89 * Returns the decorators that the function was tagged with
90 *
91 * @return {string[]} the @ prefixed decorators for the function
92 */
93 getDecorators() {
94 return this.decorators;
95 }
96
97 /**
98 * Returns the visibility of this function
99 *
100 * @return {string} the visibility of the function (+ is public),
101 * (- is private)
102 */
103 getVisibility() {
104 return this.visibility;
105 }
106
107 /**
108 * Returns the return type for this function
109 *
110 * @return {string} the return type for the function
111 */
112 getReturnType() {
113 return this.returnType;
114 }
115
116 /**
117 * Returns the name of the function
118 *
119 * @return {string} the name of the function.
120 */
121 getName() {
122 return this.name;
123 }
124
125 /**
126 * Returns the names of the parameters processed by the function.
127 *
128 * @return {string[]} the names of the parameters.
129 */
130 getParameterNames() {
131 return this.parameterNames;
132 }
133
134 /**
135 * Returns the types of the parameters processed by the function.
136 *
137 * @return {string[]} the types of the parameters.
138 */
139 getParameterTypes() {
140 return this.parameterTypes;
141 }
142
143}
144
145module.exports = FunctionDeclaration;
\No newline at end of file