Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

As3Vanilla - added caching and Enum support #8

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ bin
dist

# IDE crud.
.iml
.project
.idea
.DS_Store
Expand Down
43 changes: 38 additions & 5 deletions README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -209,22 +209,55 @@ trace(result.phoneNumbers); // [object PhoneNumber],[object PhoneNumber]
trace((result.phoneNumbers[0] as PhoneNumber).type) // "home".
```

Enum support
------------
Java style Enum support is implemented using the IEnum interface, which marks a class for being processed as an Enum.

An As3 example enum:

```actionscript
public class LocaleEnum implements IEnum {

public static var DA:LocaleEnum = new LocaleEnum("DA");
public static var EN:LocaleEnum = new LocaleEnum("EN");

private var localeName:String;

function LocaleEnum(localeName:String) {
this.localeName = localeName;
}
}
```

```actionscript
// The Target Model Class Definition.
class app.model {
public class Locale {
public var supportedLocale : LocaleEnum;
}
}

var source : Object = { supportedLocale:"DA" };
var result : Locale = extract(source, Locale);

trace(getQualifiedClassName(result.supportedLocale)); // LocaleEnum


```



Dependencies
------------
`as3commons-reflect` is used for all reflection; in order to use as3-vanilla you will need to download and add
the following SWCs to your project's libs folder.

* [ascommons-reflect-1.4.1](http://projects.yoolab.org/maven/content/repositories/releases/org/as3commons/as3commons-reflect/1.4.1/as3commons-reflect-1.4.1.swc)
* [as3commons-lang-0.3.4](http://projects.yoolab.org/maven/content/repositories/releases/org/as3commons/as3commons-lang/0.3.4/as3commons-lang-0.3.4.swc)
* [as3commons-logging-2.0](http://projects.yoolab.org/maven/content/repositories/releases/org/as3commons/as3commons-logging/2.0/as3commons-logging-2.0.swc)

* [ascommons-reflect-1.6.4](https://as3-commons.googlecode.com/files/as3commons-reflect-1.6.4.swc)
* [as3commons-lang-0.3.7](https://as3-commons.googlecode.com/files/as3commons-lang-0.3.7.swc)

Future Features / Wish List
---------------------------
* The user should be able to define mapping rules without having to use Metadata.
* Caching of the InjectionMap (assuming Class definitions won't change at run time).
* Java style mutators (eg: `setFoo()`) could be mapped automatically.
* By using `as3commons-bytecode` we could perform ByteCode reflection to retrieve the names of parameters; this would
would remove the need for constructor marshalling metadata.
Expand Down
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FLEX_HOME = ${env.FLEX_HOME}

# Versioning
project.name = as3-vanilla
project.version = 0.1.3
project.version = 0.1.4
project.versionedname = ${project.name}-${project.version}

# Folder layout
Expand Down
4 changes: 2 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<property file="build.properties" />

<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
<taskdef resource="flexUnitTasks.tasks" classpath="${lib.dir}/flexUnitTasks-4.0.0.jar" />
<taskdef resource="flexUnitTasks.tasks" classpath="${lib.dir}/flexunitTasks-4.1.0.jar"/>

<target name="init">
<target name="init">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix tabbing here (2 tabs, not 1).

<delete dir="${bin.dir}" />
<delete dir="${report.dir}" />
<mkdir dir="${bin.dir}" />
Expand Down
Binary file removed libs/as3commons-lang-0.3.4.swc
Binary file not shown.
Binary file added libs/as3commons-lang-0.3.7.swc
Binary file not shown.
Binary file removed libs/as3commons-logging-2.0.swc
Binary file not shown.
Binary file removed libs/as3commons-reflect-1.4.1.swc
Binary file not shown.
Binary file added libs/as3commons-reflect-1.6.4.swc
Binary file not shown.
Binary file not shown.
Binary file removed libs/flexunit-4.0.0.swc
Binary file not shown.
Binary file added libs/flexunit-4.1.0-as3.swc
Binary file not shown.
Binary file removed libs/flexunit-cilistener-4.0.0.swc
Binary file not shown.
Binary file added libs/flexunit-cilistener-4.1.0.swc
Binary file not shown.
Binary file added libs/hamcrest-as3-1.2.0-flex.swc
Binary file not shown.
Binary file added libs/mockolate-0.12.4-as3.swc
Binary file not shown.
8 changes: 8 additions & 0 deletions src/org/osflash/vanilla/IEnum.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.osflash.vanilla
{

public interface IEnum
{

}
}
47 changes: 29 additions & 18 deletions src/org/osflash/vanilla/InjectionDetail.as
Original file line number Diff line number Diff line change
@@ -1,45 +1,56 @@
package org.osflash.vanilla
{
internal class InjectionDetail

public class InjectionDetail
{
private var _fieldName : String;
private var _type : Class;
private var _required : Boolean;
private var _arrayTypeHint : Class;

public function InjectionDetail(fieldName : String, type : Class, required : Boolean, arrayTypeHint : Class) {
public function InjectionDetail(fieldName : String, type : Class, required : Boolean, arrayTypeHint : Class)
{
_fieldName = fieldName;
_type = type;
_required = required;
_arrayTypeHint = arrayTypeHint;
}

public function get name() : String {
return _fieldName;
}


private var _fieldName : String;
private var _required : Boolean;

private var _type : Class;

public function get type() : Class
{
return _type;
}



private var _arrayTypeHint : Class;

public function get arrayTypeHint() : Class
{
return _arrayTypeHint;
}


public function get name() : String
{
return _fieldName;
}


public function get isRequired() : Boolean
{
return _required;
}


public function toString() : String
{
var result : String = _fieldName + "<" + type + ">";
if (arrayTypeHint) {
if (arrayTypeHint)
{
result += "->" + arrayTypeHint;
}
return result;
}

public function get arrayTypeHint() : Class
{
return _arrayTypeHint;
}
}
}
61 changes: 38 additions & 23 deletions src/org/osflash/vanilla/InjectionMap.as
Original file line number Diff line number Diff line change
@@ -1,72 +1,87 @@
package org.osflash.vanilla
{
internal class InjectionMap

public class InjectionMap
{
private static function getNames(object : Object) : Array
{
const result : Array = [];
for (var name : String in object)
{
result.push(name);
}
return result;
}


private var _constructorFields : Array = [];
private var _fields : Object = {};
private var _methods : Object = {};


public function addConstructorField(injectionDetails : InjectionDetail) : void
{
_constructorFields.push(injectionDetails);
}


public function getConstructorFields() : Array
{
return _constructorFields;
}


public function addField(fieldName : String, injectionDetails : InjectionDetail) : void
{
_fields[fieldName] = injectionDetails;
}



public function getFieldNames() : Array
{
const result : Array = [];
for (var fieldName : String in _fields) {
result.push(fieldName);
}
return result;
return getNames(_fields);
}

public function getField(fieldName : String) : InjectionDetail {


public function getField(fieldName : String) : InjectionDetail
{
return _fields[fieldName];
}


public function addMethod(methodName : String, injectionDetails : InjectionDetail) : void
{
_methods[methodName] ||= [];
(_methods[methodName] as Array).push(injectionDetails);
}

}


public function getMethodsNames() : Array
{
const result : Array = [];
for (var methodName : String in _methods) {
result.push(methodName);
}
return result;
return getNames(_methods);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need getMethodNames and getNames? Oh I see, you're removing the duplication between these methods - fair enough.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey John, as a maintainer of public repo, you can get a free copy of the
IntelliJ. Maybe you qualify. It is a great IDE

Matej Šimunić

On 6 July 2014 23:27, John Reeves [email protected] wrote:

In src/org/osflash/vanilla/InjectionMap.as:

    public function getMethodsNames() : Array
    {
  •       const result : Array = [];
    
  •       for (var methodName : String in _methods) {
    
  •           result.push(methodName);
    
  •       }
    
  •       return result;
    
  •       return getNames(_methods);
    

Why do we need getMethodNames and getNames?


Reply to this email directly or view it on GitHub
https://github.com/jonnyreeves/as3-vanilla/pull/8/files#r14577706.

}



public function getMethod(methodName : String) : Array
{
return _methods[methodName];
}



public function toString() : String
{
var result : String = "[FieldMap ";
result += "ctor:{" + _constructorFields +"}, ";

result += "ctor:{" + _constructorFields + "}, ";
result += "fields:{" + _fields + "}, ";

result += "methods:{";
for (var methodName : String in _methods) {
for (var methodName : String in _methods)
{
result += methodName + "(" + getMethod(methodName) + "),";
}
result += "}";

result += "]";
return result;
}
Expand Down
7 changes: 5 additions & 2 deletions src/org/osflash/vanilla/MarshallingError.as
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.osflash.vanilla
{

public class MarshallingError extends Error
{
public static const TYPE_MISMATCH : uint = 150000;
public static const MISSING_REQUIRED_FIELD : uint = 150001;

public function MarshallingError(message : String, id : uint) {


public function MarshallingError(message : String, id : uint)
{
super(message, id);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/org/osflash/vanilla/VANILLA_INSTANCE.as
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.osflash.vanilla
{

/**
* Global, singleton instance used by the extract() convenience method.
* Global, singleton instance used by the extract() convenience method.
*/
internal var VANILLA_INSTANCE : Vanilla = new Vanilla();
}
Loading