Class Complete is a plugin for the Atom text editor, and allows users to easily generate code from shorthand.
In the future, it will be easier to contribute to it's development. For now please read CONTRIBUTING.md.
All you need to write is a classdef
(Class Definition) that describes the class you want to create, select it, then press <ctrl-shift-space>
.
The basic structure of a classdef is as follows: <class_name>:<parameters>;<methods>:<extending_class_name>
.
The <parameter>
section is structured as follows: (@)<name>((!|^)<(type|instance)>), ...
.
@
- Argument will become a member variable.!<type>
- Ensure the argument is the correct type^<instance>
- Ensure the argument is the correct instance
The <methods>
section is structured as follows: (@)<name>(+<arguments>, ...)/...
.
@
- The method is static- Leaving this blank with make it a member
The <extending_class_name>
section defines the class that the new class will extend.
These examples are for JavaScript.
The classdef Class
becomes:
Class = (function() {
function Class() {
}
return Class;
}());
The classdef Class:a,b,c
becomes:
Class = (function() {
function Class(a, b, c) {
}
return Class;
}());
The classdef Class:@a,@b,@c
becomes:
Class = (function() {
function Class(a, b, c) {
this.a = a;
this.b = b;
this.c = c;
}
return Class;
}());
The classdef Class:a!string
becomes:
Class = (function() {
function Class(a) {
if (typeof a !== "string") throw new Error("Parameter 'a' expects to be type 'string'");
}
return Class;
}());
The classdef Class:a^Class2
becomes:
Class = (function() {
function Class(a) {
if (!(a instanceof Class2)) throw new Error("Parameter 'a' expects to be instance of 'Class2'");
}
return Class;
}());
The classef Class:;hello
becomes:
Class = (function() {
function Class() {
}
Class.prototype.hello = function() {
};
return Class;
}());
The classdef Class:;@hello
becomes:
Class = (function() {
function Class() {
}
Class.hello = function() {
};
return Class;
}());
The classdef Class:;hello+name,age
becomes:
Class = (function() {
function Class() {
}
Class.prototype.hello = function(name, age) {
};
return Class;
}());
The classdef Class::Class2
becomes:
Class = (function() {
function Class() {
Class2.apply(this, arguments);
}
Class.prototype = Object.create(Class2.prototype);
Class.prototype.constructor = Class;
return Class;
}());
The classdef Person:@name!string,@age!number;setName+@name!string/setAge+@age!number/hello+name!string:Homosapian
becomes:
Person = (function() {
function Person(name, age) {
Homosapian.apply(this, arguments);
if (typeof name !== "string") throw new Error("Parameter 'name' expects to be type 'string'");
if (typeof age !== "number") throw new Error("Parameter 'age' expects to be type 'number'");
this.name = name;
this.age = age;
}
Person.prototype = Object.create(Homosapian.prototype);
Person.prototype.constructor = Person;
Person.prototype.setName = function(name) {
if (typeof name !== "string") throw new Error("Parameter 'name' expects to be type 'string'");
this.name = name;
};
Person.prototype.setAge = function(age) {
if (typeof age !== "number") throw new Error("Parameter 'age' expects to be type 'number'");
this.age = age;
};
Person.prototype.hello = function(name) {
if (typeof name !== "string") throw new Error("Parameter 'name' expects to be type 'string'");
};
return Person;
}());