• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Caught: groovy.lang.MissingPropertyException while excuting my DSL

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
package stack

/**
* Created by IntelliJ IDEA.
* User: aninath
* Date: 9/20/11
* Time: 3:40 PM
* To change this template use File | Settings | File Templates.
*/
class EmployeeDSL {

Employee root

List propchain = []

EmployeeDSL( Employee root ) {
this.root = root
}

def propertyMissing( String name ) {
// if name is 'add' and we have a chain of names
if( name == 'add' && propchain ) {
println("inside if--> "+name)
// add a new employee
root.empList << new EmployeeData( firstName:propchain.take( 1 ).join( ' ' ), lastName:propchain.drop( 1 ).join( ' ' ) )
// and reset the chain of names
propchain = []
}
else {
// add this name to the chain of names
println("inside else--> "+name)

propchain << name
this
}
}

static void main(args) {
Employee emp = new Employee( [] )

new EmployeeDSL( emp ).with {
anish.nath.add
//tim.yates.add
"4"."nath".add // this is the pont where exception throws
}

emp.empList.each {
println it.firstName
println it.lastName
}

}

}


class Employee {
List<EmployeeData> empList = []

Employee( List<EmployeeData> list ) {
empList = list
}
}
// #@groovy.transform.Canonical
class EmployeeData {
String firstName
String lastName
}



Exception in thread "main" groovy.lang.MissingPropertyException: No such property: nath for class: java.lang.String
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
at org.codehaus.groovy.runtime.callsite.GetEffectivePojoPropertySite.getProperty(GetEffectivePojoPropertySite.java:63)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:227)
at stack.EmployeeDSL$_main_closure1.doCall(EmployeeDSL.groovy:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:883)
at groovy.lang.Closure.call(Closure.java:410)
at groovy.lang.Closure.call(Closure.java:423)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.with(DefaultGroovyMethods.java:194)
at org.codehaus.groovy.runtime.dgm$876.invoke(Unknown Source)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoMetaMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:308)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:64)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at stack.EmployeeDSL.main(EmployeeDSL.groovy:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Process finished with exit code 1


new EmployeeDSL( emp ).with {
anish.nath.add
//tim.yates.add
"4"."nath".add // this is the pont where exception throws if i comment this line my programe will be fine can any one suggest what code i have to change
}
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic