added some documentation

This commit is contained in:
Christian Klemm
2019-10-05 12:38:29 +02:00
parent 92eec664b1
commit 9da61ad562
2 changed files with 42 additions and 13 deletions

View File

@@ -6,16 +6,18 @@ let classes = {};
/**
* Function called by parser when a node definition has been found.
* @param id
* @public
*/
export const addClass = function(id) {
if (typeof classes[id] === 'undefined') {
classes[id] = {
id: id,
methods: [],
members: [],
annotations: []
};
}
// Only add class if not exists
if (typeof classes[id] !== 'undefined') return;
classes[id] = {
id: id,
methods: [],
members: [],
annotations: []
};
};
export const clear = function() {
@@ -41,15 +43,34 @@ export const addRelation = function(relation) {
relations.push(relation);
};
/**
* Adds an annotation to the specified class
* Annotations mark special properties of the given type (like 'interface' or 'service')
* @param className The class name
* @param annotation The name of the annotation without any brackets
* @public
*/
export const addAnnotation = function(className, annotation) {
classes[className].annotations.push(annotation);
};
/**
* Adds a member to the specified class
* @param className The class name
* @param member The full name of the member.
* If the member is enclosed in <<brackets>> it is treated as an annotation
* If the member is ending with a closing bracket ) it is treated as a method
* Otherwise the member will be treated as a normal property
* @public
*/
export const addMember = function(className, member) {
const theClass = classes[className];
if (typeof member === 'string') {
// Member can contain white spaces, we trim them out
const memberString = member.trim();
if (memberString.startsWith('<<') && memberString.endsWith('>>')) {
// Remove leading and trailing brackets
theClass.annotations.push(memberString.substring(2, memberString.length - 2));
} else if (memberString.endsWith(')')) {
theClass.methods.push(memberString);