Skip to content

Commit

Permalink
Remove lodash
Browse files Browse the repository at this point in the history
  • Loading branch information
niklauslee committed May 24, 2018
1 parent 801394b commit 950a24c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
34 changes: 17 additions & 17 deletions code-analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

const fs = require('fs')
const path = require('path')
const _ = require('lodash')
const csharp = require('./grammar/csharp')

// C# Primitive Types
Expand Down Expand Up @@ -371,22 +370,22 @@ class CSharpCodeAnalyzer {
association.end2.navigable = true

// Final Modifier
if (_.includes(_asso.node.modifiers, 'final')) {
if (_asso.node.modifiers && _asso.node.modifiers.includes('final')) {
association.end2.isReadOnly = true
}

// Static Modifier
if (_.includes(_asso.node.modifiers, 'static')) {
if (_asso.node.modifiers && _asso.node.modifiers.includes('static')) {
this._addTag(association.end2, type.Tag.TK_BOOLEAN, 'static', true)
}

// Volatile Modifier
if (_.includes(_asso.node.modifiers, 'volatile')) {
if (_asso.node.modifiers && _asso.node.modifiers.includes('volatile')) {
this._addTag(association.end2, type.Tag.TK_BOOLEAN, 'volatile', true)
}

// Transient Modifier
if (_.includes(_asso.node.modifiers, 'transient')) {
if (_asso.node.modifiers && _asso.node.modifiers.includes('transient')) {
this._addTag(association.end2, type.Tag.TK_BOOLEAN, 'transient', true)
}
}
Expand Down Expand Up @@ -418,7 +417,7 @@ class CSharpCodeAnalyzer {
}

// if type is primitive type
if (_.includes(csharpPrimitiveTypes, _typeName)) {
if (csharpPrimitiveTypes.includes(_typeName)) {
_typedFeature.feature.type = _typeName
// otherwise
} else {
Expand Down Expand Up @@ -626,11 +625,12 @@ class CSharpCodeAnalyzer {
* @return {string} Visibility constants for UML Elements
*/
_getVisibility (modifiers) {
if (_.includes(modifiers, 'public')) {
modifiers = modifiers || []
if (modifiers.includes('public')) {
return type.UMLModelElement.VK_PUBLIC
} else if (_.includes(modifiers, 'protected')) {
} else if (modifiers.includes('protected')) {
return type.UMLModelElement.VK_PROTECTED
} else if (_.includes(modifiers, 'private')) {
} else if (modifiers.includes('private')) {
return type.UMLModelElement.VK_PRIVATE
}
return type.UMLModelElement.VK_PACKAGE
Expand All @@ -654,12 +654,12 @@ class CSharpCodeAnalyzer {
_class.visibility = this._getVisibility(classNode.modifiers)

// Abstract Class
if (_.includes(classNode.modifiers, 'abstract')) {
if (classNode.modifiers && classNode.modifiers.includes('abstract')) {
_class.isAbstract = true
}

// Final Class
if (_.includes(classNode.modifiers, 'sealed')) {
if (classNode.modifiers && classNode.modifiers.includes('sealed')) {
_class.isFinalSpecialization = true
_class.isLeaf = true
}
Expand Down Expand Up @@ -774,13 +774,13 @@ class CSharpCodeAnalyzer {

// Modifiers
_operation.visibility = this._getVisibility(methodNode.modifiers)
if (_.includes(methodNode.modifiers, 'static')) {
if (methodNode.modifiers && methodNode.modifiers.includes('static')) {
_operation.isStatic = true
}
if (_.includes(methodNode.modifiers, 'abstract')) {
if (methodNode.modifiers && methodNode.modifiers.includes('abstract')) {
_operation.isAbstract = true
}
if (_.includes(methodNode.modifiers, 'sealed')) {
if (methodNode.modifiers && methodNode.modifiers.includes('sealed')) {
_operation.isLeaf = true
}

Expand Down Expand Up @@ -907,18 +907,18 @@ class CSharpCodeAnalyzer {
}

// Static Modifier
if (_.includes(fieldNode.modifiers, 'static')) {
if (fieldNode.modifiers && fieldNode.modifiers.includes('static')) {
_attribute.isStatic = true
}

// Final Modifier
if (_.includes(fieldNode.modifiers, 'sealed')) {
if (fieldNode.modifiers && fieldNode.modifiers.includes('sealed')) {
_attribute.isLeaf = true
_attribute.isReadOnly = true
}

// Volatile Modifier
if (_.includes(fieldNode.modifiers, 'volatile')) {
if (fieldNode.modifiers && fieldNode.modifiers.includes('volatile')) {
this._addTag(_attribute, type.Tag.TK_BOOLEAN, 'volatile', true)
}

Expand Down
27 changes: 13 additions & 14 deletions code-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

const fs = require('fs')
const path = require('path')
const _ = require('lodash')
const codegen = require('./codegen-utils')

/**
Expand Down Expand Up @@ -148,7 +147,7 @@ class CSharpCodeGenerator {
writeNamespace (writeFunction, codeWriter, elem, options) {
var path = null
if (elem._parent) {
path = _.map(elem._parent.getPath(this.baseModel), function (e) { return e.name }).join('.')
path = elem._parent.getPath(this.baseModel).map(function (e) { return e.name }).join('.')
}
if (path) {
codeWriter.writeLine('namespace ' + path + '{')
Expand Down Expand Up @@ -228,7 +227,7 @@ class CSharpCodeGenerator {
// Extends
var _extends = this.getSuperClasses(elem)
if (_extends.length > 0) {
terms.push(': ' + _.map(_extends, function (e) { return e.name }).join(', '))
terms.push(': ' + _extends.map(function (e) { return e.name }).join(', '))
}
codeWriter.writeLine(terms.join(' ') + ' {')
codeWriter.writeLine()
Expand Down Expand Up @@ -302,7 +301,7 @@ class CSharpCodeGenerator {

// Modifiers
var _modifiers = this.getModifiers(elem)
if (_.some(elem.operations, function (op) { return op.isAbstract === true })) {
if (elem.operations.some(function (op) { return op.isAbstract === true })) {
_modifiers.push('abstract')
}
if (_modifiers.length > 0) {
Expand Down Expand Up @@ -392,7 +391,7 @@ class CSharpCodeGenerator {

// Modifiers
var _modifiers = this.getModifiers(elem)
if (_.some(elem.operations, function (op) { return op.isAbstract === true })) {
if (elem.operations.some(function (op) { return op.isAbstract === true })) {
_modifiers.push('abstract')
}
if (_modifiers.length > 0) {
Expand All @@ -413,9 +412,9 @@ class CSharpCodeGenerator {
var _implements = this.getSuperInterfaces(elem)
if (_implements.length > 0) {
if (_extends.length > 0) {
terms.push(', ' + _.map(_implements, function (e) { return e.name }).join(', '))
terms.push(', ' + _implements.map(function (e) { return e.name }).join(', '))
} else {
terms.push(': ' + _.map(_implements, function (e) { return e.name }).join(', '))
terms.push(': ' + _implements.map(function (e) { return e.name }).join(', '))
}
}

Expand Down Expand Up @@ -494,7 +493,7 @@ class CSharpCodeGenerator {

// doc
var doc = elem.documentation.trim()
_.each(params, function (param) {
params.forEach(function (param) {
doc += '\n@param ' + param.name + ' ' + param.documentation
})
if (returnParam) {
Expand Down Expand Up @@ -531,7 +530,7 @@ class CSharpCodeGenerator {
terms.push(elem.name + '(' + paramTerms.join(', ') + ')')

// body
if (skipBody === true || _.includes(_modifiers, 'abstract')) {
if (skipBody === true || _modifiers.includes('abstract')) {
codeWriter.writeLine(terms.join(' ') + ';')
} else {
codeWriter.writeLine(terms.join(' ') + ' {')
Expand Down Expand Up @@ -583,14 +582,14 @@ class CSharpCodeGenerator {
} else {
if (elem.type instanceof type.UMLModelElement && elem.type.name.length > 0) {
_type = elem.type.name
} else if (_.isString(elem.type) && elem.type.length > 0) {
} else if ((typeof elem.type === 'string') && elem.type.length > 0) {
_type = elem.type
}
}

// multiplicity
if (elem.multiplicity) {
if (_.includes(['0..*', '1..*', '*'], elem.multiplicity.trim())) {
if (['0..*', '1..*', '*'].includes(elem.multiplicity.trim())) {
if (elem.isOrdered === true) {
_type = 'List<' + _type + '>'
} else {
Expand Down Expand Up @@ -661,7 +660,7 @@ class CSharpCodeGenerator {
*/
writeDoc (codeWriter, text, options) {
var i, len, lines
if (options.csharpDoc && _.isString(text)) {
if (options.csharpDoc && (typeof text === 'string')) {
lines = text.trim().split('\n')
codeWriter.writeLine('/**')
for (i = 0, len = lines.length; i < len; i++) {
Expand Down Expand Up @@ -729,7 +728,7 @@ class CSharpCodeGenerator {
var generalizations = app.repository.getRelationshipsOf(elem, function (rel) {
return (rel instanceof type.UMLGeneralization && rel.source === elem)
})
return _.map(generalizations, function (gen) { return gen.target })
return generalizations.map(function (gen) { return gen.target })
};

/**
Expand All @@ -741,7 +740,7 @@ class CSharpCodeGenerator {
var realizations = app.repository.getRelationshipsOf(elem, function (rel) {
return (rel instanceof type.UMLInterfaceRealization && rel.source === elem)
})
return _.map(realizations, function (gen) { return gen.target })
return realizations.map(function (gen) { return gen.target })
}

}
Expand Down

0 comments on commit 950a24c

Please sign in to comment.