• Packages
  • Themes
  • Documentation
  • Blog
  • Discuss
Sign in

class-complete

Easily generate classes and methods.
  • #class
  • #complete
  • #completion
  • #parameters
  • #functions
anotherfrog
6.2.2 4,913
3
  • Repo
  • Bugs
  • Versions
  • License
Flag as spam or malicious

Class Complete

Class Complete is a plugin for Atom, that allows the user to easily generate classes.

Table of Contents

  • How-To
    • Parameters
    • Methods
    • Extending Classes
  • Examples
    • Class
    • Class with parameters
    • Class with member parameters
    • Class with type checking
    • Class with instance checking
  • Examples with Methods
    • Member method
    • Static method
    • Member methods and parameters
    • Extending classes
    • All together

Contributing

In the future, it will be easier to contribute to it's development. For now please read CONTRIBUTING.md.

How-to

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>.

Parameters

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

Methods

The <methods> section is structured as follows: (@)<name>(+<arguments>, ...)/....

  • @ - The method is static
    • Leaving this blank with make it a member

Extending

The <extending_class_name> section defines the class that the new class will extend.

Examples

Simple class creation

These examples are for JavaScript.

The classdef Class becomes:

Class = (function() {
function Class() {
}
 
return Class;
}());

Class with parameters

The classdef Class:a,b,c becomes:

Class = (function() {
function Class(a, b, c) {
}
 
return Class;
}());

Class with member parameters

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;
}());

Class with parameters and type checking

Checking type

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;
}());

Checking instance

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;
}());

Class with methods

Member method

The classef Class:;hello becomes:

Class = (function() {
function Class() {
}
 
Class.prototype.hello = function() {
};
 
return Class;
}());

Static method

The classdef Class:;@hello becomes:

Class = (function() {
function Class() {
}
 
Class.hello = function() {
};
 
return Class;
}());

Member method with parameters

The classdef Class:;hello+name,age becomes:

Class = (function() {
function Class() {
}
 
Class.prototype.hello = function(name, age) {
};
 
return Class;
}());

Extending classes

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;
}());

All together

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;
}());

I think this package is bad news.

Good catch. Let us know what about this package looks wrong to you, and we'll investigate right away.

  • Terms of Use
  • Privacy
  • Code of Conduct
  • Releases
  • FAQ
  • Contact
with by