forked from sammyt/fussy
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial work on syntax refactoring. Sorry for the huge commit.
- Loading branch information
Showing
100 changed files
with
892 additions
and
2,761 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
.FlexUnitSettings | ||
.project | ||
.DS_Store | ||
bin-debug/ | ||
*bin/ | ||
fussy.iml | ||
fussy.ipr | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1 @@ | ||
# fussy is an actionscript reflection query language # | ||
|
||
Fussy allows you to query your actionscript types using a simple DSL | ||
|
||
### Why ### | ||
Because I didn't need a full OO representation of my types, I just needed to know some specific things about them | ||
|
||
### How ### | ||
Fussy allows you to perform the business logic of you reflection (find me such-and-such) with a query language, then only parses into strictly typed objects those facets of the type that satisfy your query | ||
|
||
### Code ### | ||
|
||
Want to know somethings about some types? Create a Fussy. | ||
|
||
<pre> | ||
var fussy:Fussy = new Fussy() | ||
</pre> | ||
|
||
Explain what you want to know by creating a query | ||
|
||
<pre> | ||
var query:IQuery = fussy.query().findMethods().withTypeSignature(int, String); | ||
</pre> | ||
|
||
This will find any methods that have a signiture of int, string e.g. public function setAgeAndName(age:int, name:String):void; or public function addToCart(prodId:int, name:String):void; | ||
|
||
Now to use the query | ||
|
||
<pre> | ||
var methods:Array = query.forType(Person); | ||
</pre> | ||
|
||
Result is strongly typed into Method objects | ||
|
||
<pre> | ||
for each(var method:Method in methods) | ||
{ | ||
trace(method.name); | ||
trace(method.parameters.length); | ||
method.invoke(myPerson, [1, "Bacon"]); | ||
} | ||
</pre> | ||
|
||
### And some more... ### | ||
|
||
Take from [dawns](http://github.com/sammyt/dawn) code base | ||
|
||
<pre> | ||
var query:QueryBuilder = fussy.query(); | ||
|
||
query.findMethods().withMetadata("Inject").withArguments(); | ||
query.findProperties().withMetadata("Inject"); | ||
query.findMethods().withMetadata("Provider").noCompulsoryArguments(); | ||
query.findMethods().withMetadata("Execute").withArgsLengthOf(1); | ||
query.getTypeQuery(); | ||
</pre> | ||
Entirely based on the excellent work of Sam Williams in his [Fussy](https://github.com/sammyt/fussy) library, check it out! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package se.stade.daffodil | ||
{ | ||
import se.stade.daffodil.methods.MethodReflection; | ||
import se.stade.daffodil.properties.ConstantReflection; | ||
import se.stade.daffodil.properties.PropertyReflection; | ||
|
||
public class Reflect | ||
{ | ||
private static var cache:XMLDescriptionCache = new XMLDescriptionCache(); | ||
|
||
public static function on(target:Object):Reflector | ||
{ | ||
return new XMLReflector(cache, target); | ||
} | ||
|
||
public static function get methods():MethodReflection | ||
{ | ||
return new XMLMethodReflection(); | ||
} | ||
|
||
public static function get properties():PropertyReflection | ||
{ | ||
return new XMLPropertyReflection(); | ||
} | ||
|
||
public static function get constants():ConstantReflection | ||
{ | ||
return new XMLConstantReflection(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package se.stade.daffodil | ||
{ | ||
public interface Reflection | ||
{ | ||
function matches(input:*):Boolean; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package se.stade.daffodil | ||
{ | ||
public interface Reflector | ||
{ | ||
function find(reflection:Reflection):Array; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package se.stade.daffodil | ||
{ | ||
import se.stade.daffodil.metadata.Metadata; | ||
|
||
public interface TypeMember | ||
{ | ||
function get name():String; | ||
function get type():String; | ||
|
||
function get metadata():Vector.<Metadata>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package se.stade.daffodil | ||
{ | ||
import flash.utils.getQualifiedClassName; | ||
|
||
internal class XMLAbstractReflection | ||
{ | ||
protected static function createNameMatcher(name:String):Function | ||
{ | ||
return function(input:XML):Boolean | ||
{ | ||
return input.@name == name; | ||
} | ||
} | ||
|
||
protected static function createMetadataMatcher(name:String):Function | ||
{ | ||
return function(input:XML):Boolean | ||
{ | ||
for each (var metadata:XML in input.metadata) | ||
{ | ||
if (metadata.@name == name) | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
|
||
protected static function createReturnTypeMatcher(type:Class, isMethod:Boolean):Function | ||
{ | ||
var qName:String = getQualifiedClassName(type); | ||
|
||
if (isMethod) return function(input:XML):Boolean | ||
{ | ||
return input.@returnType == qName; | ||
} | ||
else return function(input:XML):Boolean | ||
{ | ||
return input.@type == qName; | ||
} | ||
} | ||
|
||
public final function XMLAbstractReflection() | ||
{ | ||
nameMatches = signatureMatches = metadataMatches = returnTypeMatches = function(input:XML):Boolean | ||
{ | ||
return true; | ||
}; | ||
} | ||
|
||
protected var nameMatches:Function; | ||
protected var metadataMatches:Function; | ||
protected var signatureMatches:Function; | ||
protected var returnTypeMatches:Function; | ||
|
||
public final function matches(input:*):Boolean | ||
{ | ||
return input is XML && | ||
nameMatches(input) && | ||
metadataMatches(input) && | ||
signatureMatches(input) && | ||
returnTypeMatches(input); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package se.stade.daffodil | ||
{ | ||
import se.stade.daffodil.properties.ConstantReflection; | ||
|
||
internal final class XMLConstantReflection extends XMLAbstractReflection implements ConstantReflection | ||
{ | ||
public function named(name:String):ConstantReflection | ||
{ | ||
nameMatches = createNameMatcher(name); | ||
return this; | ||
} | ||
|
||
public function ofType(type:Class):ConstantReflection | ||
{ | ||
returnTypeMatches = createReturnTypeMatcher(type, false); | ||
return this; | ||
} | ||
|
||
public function withMetadata(name:String):ConstantReflection | ||
{ | ||
metadataMatches = createMetadataMatcher(name); | ||
return this; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package se.stade.daffodil | ||
{ | ||
import flash.utils.Dictionary; | ||
import flash.utils.describeType; | ||
|
||
internal final class XMLDescriptionCache | ||
{ | ||
private var descriptions:Dictionary = new Dictionary(true); | ||
|
||
public function retrieve(key:*):XML | ||
{ | ||
if (key in descriptions == false) | ||
{ | ||
descriptions[key] = describeType(key); | ||
} | ||
|
||
return descriptions[key]; | ||
} | ||
} | ||
} |
Oops, something went wrong.