Skip to content

Commit

Permalink
Initial work on syntax refactoring. Sorry for the huge commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
mstade committed Mar 10, 2011
1 parent 2e6f822 commit a46ecc8
Show file tree
Hide file tree
Showing 100 changed files with 892 additions and 2,761 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,6 +4,7 @@
.FlexUnitSettings
.project
.DS_Store
bin-debug/
*bin/
fussy.iml
fussy.ipr
Expand Down
57 changes: 1 addition & 56 deletions README.md
@@ -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!
69 changes: 36 additions & 33 deletions pom.xml
Expand Up @@ -2,62 +2,65 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>uk.co.ziazoo</groupId>
<artifactId>fussy</artifactId>
<version>0.2</version>

<groupId>se.stade</groupId>
<artifactId>daffodil</artifactId>
<version>0.1</version>
<packaging>swc</packaging>
<name>Fussy query language</name>

<name>Daffodil</name>

<properties>
<flexversion>3.5.0.12683</flexversion>
<mojoversion>3.5.0</mojoversion>
<flexversion>4.1.0.16076</flexversion>
<mojoversion>3.8</mojoversion>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>${mojoversion}</version>
<extensions>true</extensions>
<configuration>
<keepAs3Metadatas>
<!-- can i just keep these for tests? -->
<keepAs3Metadata>Inject</keepAs3Metadata>
<keepAs3Metadata>Fussy</keepAs3Metadata>
</keepAs3Metadatas>
</configuration>
<dependencies>
<dependency>
<groupId>com.adobe.flex</groupId>
<artifactId>compiler</artifactId>
<version>${flexversion}</version>
<type>pom</type>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

<dependencies>

<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>flex-framework</artifactId>
<version>${flexversion}</version>
<type>pom</type>
</dependency>

<dependency>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-unittest-support</artifactId>
<version>${mojoversion}</version>
<type>swc</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.adobe.flexunit</groupId>
<artifactId>flexunit</artifactId>
<version>4.0-rc-1</version>
<type>swc</type>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>${mojoversion}</version>
<extensions>true</extensions>

<dependencies>
<dependency>
<groupId>com.adobe.flex</groupId>
<artifactId>compiler</artifactId>
<version>${flexversion}</version>
<type>pom</type>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
31 changes: 31 additions & 0 deletions src/se/stade/daffodil/Reflect.as
@@ -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();
}
}
}
7 changes: 7 additions & 0 deletions src/se/stade/daffodil/Reflection.as
@@ -0,0 +1,7 @@
package se.stade.daffodil
{
public interface Reflection
{
function matches(input:*):Boolean;
}
}
7 changes: 7 additions & 0 deletions src/se/stade/daffodil/Reflector.as
@@ -0,0 +1,7 @@
package se.stade.daffodil
{
public interface Reflector
{
function find(reflection:Reflection):Array;
}
}
12 changes: 12 additions & 0 deletions src/se/stade/daffodil/TypeMember.as
@@ -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>;
}
}
65 changes: 65 additions & 0 deletions src/se/stade/daffodil/XMLAbstractReflection.as
@@ -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);
}
}
}
25 changes: 25 additions & 0 deletions src/se/stade/daffodil/XMLConstantReflection.as
@@ -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;
}
}
}
20 changes: 20 additions & 0 deletions src/se/stade/daffodil/XMLDescriptionCache.as
@@ -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];
}
}
}

0 comments on commit a46ecc8

Please sign in to comment.