📄 class.js
字号:
* Returns an array of Field objects.
* @return {Array}
*/
instance getFields()
{
return this.__getFields__(false);
}
/**
* Returns a Field object for this class.
* @example
The Field object has the following methods.
//From any jsx.lang.Class object (String.klass or "test".getClass()) you can get the Field object.
<code>var _field = String.klass.getField("length");</code>
//Returns the name of the jsx.lang.Class that the Field belongs to.
<code>_field.getDeclaringClass();</code>
//Returns the name of the field.
<code>_field.getName();</code>
//Returns whether the field is STATIC.
<code>_field.isStatic();</code>
//Returns the value of the field. If a parameter object is passed, this method will return the value for the Instance.
//If no paramerter object is passed, this method will return the value for the class.
<code>_field.getValue(_object);</code>
* @param {String} _name
* @return {Object}
*/
instance getField(_name)
{
var _fields = this.getFields();
for(var i=0;i<_fields.length;i++)
{
if(_fields[i].getName() == _name)
{
return _fields[i];
}
}
}
/**
* Returns a string of all the fields.
* @return {String}
*/
instance showFields()
{
return this.__toFieldsString__(this.getFields());
}
/**
* Returns an array of Field objects only declared in this class.
* @return {Array}
*/
instance getDeclaredFields()
{
return this.__getFields__(true);
}
/**
* Returns a Field object only declared in this class.
* @param {String} _name
* @return {Object} See getField(_name) for object details.
*/
instance getDeclaredField(_name)
{
var _fields = this.getDeclaredFields();
for(var i=0;i<_fields.length;i++)
{
if(_fields[i].getName() == _name)
{
return _fields[i];
}
}
}
/**
* Returns a string of all the fields only declared in this class.
* @return {String}
*/
instance showDeclaredFields()
{
return this.__toFieldsString__(this.getDeclaredFields());
}
/**
* Returns an array of Method objects.
* @return {Array}
*/
instance getMethods()
{
return this.__getMethods__(false);
}
/**
* Returns a Method object for this class.
* @example
The Method object has the following methods.
//From any jsx.lang.Class object (String.klass or "test".getClass()) you can get the Method object.
<code>var _method = String.klass.getMethod("match");</code>
//Returns the name of the jsx.lang.Class that the Method belongs to.
<code>_method.getDeclaringClass();</code>
//Returns the name of the method.
<code>_method.getName();</code>
//Returns whether the method is STATIC.
<code>_method.isStatic();</code>
//Returns an array of parameters for the method.
<code>_method.getParameters();</code>
//Returns the code body of the method.
<code>_method.getBody();</code>
//Invokes the method. Return object based on the method definition.
//The _obj parameter is the context object and the _params(Array) parameter is passed to the method.
//If _obj is null the method is invoked as a class level method.
<code>_method.invoke(_obj, _params);</code>
* @param {String} _name
* @return {Object}
*/
instance getMethod(_name)
{
var _methods = this.getMethods();
for(var i=0;i<_methods.length;i++)
{
if(_methods[i].getName() == _name)
{
return _methods[i];
}
}
}
/**
* Returns a string of all the methods.
* @return {String}
*/
instance showMethods()
{
return this.__toMethdsString__(this.getMethods());
}
/**
* Returns an array of Method objects only declared in this class.
* @return {Array}
*/
instance getDeclaredMethods()
{
return this.__getMethods__(true);
}
/**
* Returns a Method object only declared in this class.
* @param {String} _name
* @return {Object} See getMethod(_name) for object details.
*/
instance getDeclaredMethod(_name)
{
var _methods = this.getDeclaredMethods();
for(var i=0;i<_methods.length;i++)
{
if(_methods[i].getName() == _name)
{
return _methods[i];
}
}
}
/**
* Returns a string of all the methods only declared in this class.
* @return {String}
*/
instance showDeclaredMethods()
{
return this.__toMethdsString__(this.getDeclaredMethods());
}
/**
* Returns a Constructor object for this class.
* @example
The Constructor object has the following methods.
//From any jsx.lang.Class object (String.klass or "test".getClass()) you can get the Constructor object.
var _constructor = String.klass.getConstructor();
//Returns a jsx.lang.Class object.
_constructor.getDeclaringClass();
//Returns a array of parameters for the constructor.
_constructor.getParameters();
//Returns the code body of the constructor.
_constructor.getBody();
//Returns a new Instance of this class. Pass any number of parameters.
_constructor.newInstance();
* @return {Object}
*/
instance getConstructor()
{
var me = this;
var cmethod = this.__toMethod__("initialize", eval(this._className()).prototype.initialize);
return {
getDeclaringClass : function(){return me;},
getParameters : function(){return cmethod.parameters;},
getBody : function(){return cmethod.body;},
newInstance : function()
{
return me.__newInstance__(arguments);
}
};
}
/**
* Returns a Package object for this class.
* @example
The Package object has the following methods.
//From any jsx.lang.Class object (String.klass or "test".getClass()) you can get the Package object.
var _package = String.klass.getPackage();
//Returns the name of the package.
_package.getName();
//Returns an array of jsx.lang.Class objects that exist in the package.
_package.getClasses();
* @return {Object}
*/
instance getPackage()
{
var me = this;
return {
getName : function(){ return me._pakage();},
getClasses : function()
{
var pakageClasses = [];
var pkg = this.getName();
if(pkg && pkg != "jsx.lang")
{
var pakageObj = eval(pkg);
for(prop in pakageObj)
{
if("klass" in pakageObj[prop])
{
pakageClasses[pakageClasses.length] = pakageObj[prop].klass;
}
}
}
else
{
//get all the Global Objects, they don't have a namespace
for(var i=0;i < Class.CORE_CLASSES.length;i++)
{
pakageClasses[pakageClasses.length] = eval(Class.CORE_CLASSES[i]).klass;
}
// get all classes in jsx.lang namespace
var pakageObj = eval("jsx.lang");
for(prop in pakageObj)
{
if("klass" in pakageObj[prop])
{
pakageClasses[pakageClasses.length] = pakageObj[prop].klass;
}
}
}
return pakageClasses;
}
};
}
/**
* Returns a new Instance of the class
* @param parameters Pass any number of parameters. This methods uses the arguments implicit object.
* @return {Object}
*/
instance newInstance()
{
return this.__newInstance__(arguments);
}
/**
* Returns an array of the classes this class has for its imports.
* @return {Array[jsx.lang.Class]}
*/
instance getClasses()
{
return this.__toClasses__(this._classes());
}
/**
* Returns an array of the classes this class is implementating.
* @return {Array[jsx.lang.Class]}
*/
instance getInterfaces()
{
return this.__toClasses__(this._interfaces());
}
/**
* Returns an array of the classes this class is mixing in.
* @return {Array[jsx.lang.Class]}
*/
instance getMixins()
{
return this.__toClasses__(this._mixins());
}
/**
* Returns whether this class is the child of the _object parameter class.
* @param {Object} _object
* @return {Boolean}
*/
instance isChildOf(_object)
{
return _object.getClass().getName() == this._superClassName();
}
/**
* Returns whether this class is the parent of the _object parameter class.
* @param {Object} _object
* @return {Boolean}
*/
instance isSuperOf(_object)
{
return _object.getClass().getSuperclass().getName() == this._className();
}
/**
* Returns whether the _object parameter is of this class type.
* @param {Object} _object
* @return {Boolean}
*/
instance isInstance(_object)
{
var name = _object.getClass().getName();
if(this._className() == name || this._superClassName() == name || (this._interfaces().indexOf(name)>-1) || (this._mixins().indexOf(name)>-1))
{
return true;
}
return false;
}
/**
* Returns whether this class is implementing the _class parameter.
* @param {jsx.lang.Class} _object
* @return {Boolean}
*/
instance isImplementing(_class)
{
var name = _class.getName();
return (this._interfaces().indexOf(name)>-1);
}
/**
* Returns whether this class is mixing in the _class parameter.
* @param {jsx.lang.Class} _object
* @return {Boolean}
*/
instance isMixingIn(_class)
{
var name = _class.getName();
return (this._mixins().indexOf(name)>-1);
}
/**
* Returns the warnings for this class.
* @return {String}
*/
instance getWarnings()
{
return this._warnings();
}
/**
* Returns the name of this class.
* @return {String}
*/
instance toString()
{
return this._className();
}
/**
* Returns whether this object is equal to the specified _object.
* @param {Object} _object
* @return {Boolean}
*/
instance equals(_object)
{
if (this === _object)
{
return true;
}
if(!_object._className()){return false;}
return this._className() == _object._className();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -