Skip to content

Commit

Permalink
initial support for bean properties
Browse files Browse the repository at this point in the history
  • Loading branch information
bamboo committed Jan 17, 2009
1 parent 7e88f8a commit 0bbd450
Show file tree
Hide file tree
Showing 16 changed files with 314 additions and 20 deletions.
48 changes: 34 additions & 14 deletions boojay/TODO
@@ -1,30 +1,50 @@
Debugging ometa.calculator Release
==================================
ROADMAP
=======

* external callables
** automatically insert default parameterless ctor

******** Acknowledgement Release **************

* bean properties
** 'get(arg)' is the indexer (default member)
* monolipse wizard: new boojay project
* code completion for java library types
* monolipse: windows version should not require anything other than update site
* ensure pattern matching works with bean properties
* refactor all primitive dependent information into a PrimitiveInfo() tuple with things like
* array store opcode
* array load opcode
* type descriptor
* move boojay to separate google project (http://code.google.com/p/boojay/)
* update monolipse site


********* Resolution Release ***************

** resident test runner
** internal macros work again
** support for referencing jar files and class file directories
* external callables
** automatically insert default parameterless ctor
* monolipse integration
** "Run As JUnit Tests"
* events


********** Pursuance Release ***************

* monolipse integration
** wizard: new boojay project
** wizard: new boojay source folder
** resident incremental compiler
*** builder just sends delta information to the compiler
which maintains the dependency tree and it's able to recompile
required files on demand
** deferred namespace implementation on top of a directory or jar file
** meta-programming by invoking the boojay compiler on temporary files generated from code literals

* ant tasks

* refactor all primitive dependent information into a PrimitiveInfo() tuple with things like
* array store opcode
* array load opcode
* type descriptor

* GetHashCode
* events
* properties
* duck typing


*********** Psalm Release ****************

...
76 changes: 76 additions & 0 deletions boojay/src/Boojay.Compilation.Tests/BeanPropertyFinderTest.boo
@@ -0,0 +1,76 @@
namespace Boojay.Compilation.Tests

import NUnit.Framework

import Boo.Lang.Compiler.TypeSystem
import Boojay.Compilation.TypeSystem

[TestFixture]
class BeanPropertyFinderTest:

[Test] def SimpleProperty():
p = expectingSingleBeanPropertyWithNameAndTypeOn(ClassWithSimpleProperty, "name", string)
Assert.AreEqual("getName", p.GetGetMethod().Name)
Assert.AreEqual("setName", p.GetSetMethod().Name)

[Test] def ReadOnlyProperty():
p = expectingSingleBeanPropertyWithNameAndTypeOn(ClassWithReadOnlyProperty, "value", int)
assert p.GetSetMethod() is null
Assert.AreEqual("getValue", p.GetGetMethod().Name)

[Test] def WriteOnlyProperty():
p = expectingSingleBeanPropertyWithNameAndTypeOn(ClassWithWriteOnlyProperty, "value", object)
assert p.GetGetMethod() is null
Assert.AreEqual("setValue", p.GetSetMethod().Name)

[Test] def IndexedProperty():
pass

[Test] def OverloadedIndexedProperty():
pass

[Test] def ConflictingSetters():
properties = beanPropertiesFor(ClassWithConflictingSetters)
assert 0 == len(properties), join(properties, ", ")

class ClassWithSimpleProperty:
def getName() as string:
pass
def setName(value as string):
pass

class ClassWithReadOnlyProperty:
def getValue():
return 0

class ClassWithWriteOnlyProperty:
def setValue(value):
pass

class ClassWithConflictingSetters:
def setValue(value as int):
pass
def setValue(vaue as string):
pass

def expectingSingleBeanPropertyWithNameAndTypeOn(type as System.Type, expectedName as string, expectedType as System.Type):
p = expectingSingleBeanPropertyFor(type)
assertPropertyNameAndType p, expectedName, expectedType
return p

def expectingSingleBeanPropertyFor(type as System.Type):
properties = beanPropertiesFor(type)
assert 1 == len(properties), join(properties, ", ")
return properties[0]

def assertPropertyNameAndType(p as IProperty, expectedName as string, expectedType as System.Type):
Assert.AreEqual(expectedName, p.Name)
Assert.AreSame(bindingFor(expectedType), p.Type)

typeSystem = JavaTypeSystem()

def beanPropertiesFor(type as System.Type):
return array(BeanPropertyFinder(bindingFor(type).GetMembers()).findAll())

def bindingFor(type as System.Type):
return typeSystem.Map(type)
Expand Up @@ -4,7 +4,7 @@ import NUnit.Framework
import Boo.Lang.Compiler
import Boo.Lang.Compiler.Ast
import Boo.Lang.Compiler.TypeSystem
import Boojay.Compilation.Steps
import Boojay.Compilation.TypeSystem

class GenericFoo[of T]:
def Bar(value as T):
Expand Down
Expand Up @@ -189,6 +189,10 @@ partial class IntegrationTest:
def Assert_1():
runTestCase("tests/integration/macros/Assert-1.boo")

[Test]
def BeanProperties():
runTestCase("tests/integration/properties/BeanProperties.boo")

[Test]
def ForItemInArray():
runTestCase("tests/integration/statements/ForItemInArray.boo")
Expand Down
25 changes: 25 additions & 0 deletions boojay/src/Boojay.Compilation.Tests/JavaTypeSystemTest.boo
@@ -0,0 +1,25 @@
namespace Boojay.Compilation.Tests

import NUnit.Framework

import Boo.Lang.Compiler.TypeSystem
import Boojay.Compilation.TypeSystem

[TestFixture]
class JavaTypeSystemTest:

class Bean:
def getName() as string:
pass
def setName(value as string):
pass

typeSystem = JavaTypeSystem()

[Test] def BeanProperties():

members = typeSystem.Map(Bean).GetMembers()
System.Array.Sort(members, { l as IEntity, r as IEntity | l.Name.CompareTo(r.Name) })

Assert.AreEqual("constructor, getName, name, setName", join(member.Name for member in members, ", "))

9 changes: 9 additions & 0 deletions boojay/src/Boojay.Compilation/Steps/BoojayEmitter.boo
Expand Up @@ -12,6 +12,8 @@ import Boo.Lang.PatternMatching
import org.objectweb.asm
import org.objectweb.asm.Type

import Boojay.Compilation.TypeSystem

class BoojayEmitter(AbstractVisitorCompilerStep):

_classWriter as ClassWriter
Expand Down Expand Up @@ -481,7 +483,9 @@ class BoojayEmitter(AbstractVisitorCompilerStep):
def emitRegularMethodInvocation(method as IMethod, node as MethodInvocationExpression):
emit node.Target
emit node.Arguments
emitInvokeMethodInstructionFor method

def emitInvokeMethodInstructionFor(method as IMethod):
if method.IsStatic:
INVOKESTATIC method
elif method.DeclaringType.IsInterface:
Expand Down Expand Up @@ -759,6 +763,11 @@ class BoojayEmitter(AbstractVisitorCompilerStep):
emit memberRef.Target
emitRValue()
PUTFIELD field
case p = IProperty(IsStatic: false):
emit memberRef.Target
emitRValue()
emitInvokeMethodInstructionFor p.GetSetMethod()

case reference = ReferenceExpression():
emitRValue()
match bindingFor(reference):
Expand Down
2 changes: 1 addition & 1 deletion boojay/src/Boojay.Compilation/Steps/Globals.boo
Expand Up @@ -30,7 +30,7 @@ def isJavaLangObject(type as IType):
def definitionFor(m as IMethodBase):
if m.DeclaringType.ConstructedInfo is null:
return m
return GenericMethodDefinitionFinder(m).find()
return Boojay.Compilation.TypeSystem.GenericMethodDefinitionFinder(m).find()

def typeOf(e as Expression) as IType:
match e:
Expand Down
Expand Up @@ -4,4 +4,4 @@ import Boo.Lang.Compiler.Steps

class InitializeJavaTypeSystem(InitializeTypeSystemServices):
override def CreateTypeSystemServices():
return JavaTypeSystem(_context)
return Boojay.Compilation.TypeSystem.JavaTypeSystem(_context)
2 changes: 2 additions & 0 deletions boojay/src/Boojay.Compilation/Steps/InjectCasts.boo
Expand Up @@ -5,6 +5,8 @@ import Boo.Lang.Compiler.TypeSystem
import Boo.Lang.Compiler.Steps
import Boo.Lang.PatternMatching

import Boojay.Compilation.TypeSystem

class InjectCasts(AbstractTransformerCompilerStep):

_currentReturnType as IType
Expand Down
2 changes: 2 additions & 0 deletions boojay/src/Boojay.Compilation/Steps/NormalizeIterations.boo
Expand Up @@ -5,6 +5,8 @@ import Boo.Lang.Compiler.Ast
import Boo.Lang.Compiler.TypeSystem
import Boo.Lang.Compiler.Steps

import Boojay.Compilation.TypeSystem

class NormalizeIterations(AbstractVisitorCompilerStep):

_RuntimeServices_GetEnumerable as IMethod
Expand Down
@@ -1,6 +1,5 @@
namespace Boojay.Compilation.Steps


import Boo.Lang.PatternMatching
import Boo.Lang.Compiler.Ast
import Boo.Lang.Compiler.TypeSystem
Expand Down
13 changes: 13 additions & 0 deletions boojay/src/Boojay.Compilation/TypeSystem/BeanAwareType.boo
@@ -0,0 +1,13 @@
namespace Boojay.Compilation.TypeSystem

import Boo.Lang.Compiler.TypeSystem

class BeanAwareType(ExternalType):

def constructor(typeSystem as TypeSystemServices, type as System.Type):
super(typeSystem, type)

override def CreateMembers():
originalMembers = super()
beanProperties = BeanPropertyFinder(originalMembers).findAll()
return array(IEntity, cat(originalMembers, beanProperties))

0 comments on commit 0bbd450

Please sign in to comment.