History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: MGROOVY-102
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Jason Dillon
Reporter: Luke Daley
Votes: 1
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
GMaven

Getters/Setters should be generated for properties.

Created: 15/Dec/07 05:25 PM   Updated: 01/Apr/08 05:30 AM
Component/s: stub generation
Affects Version/s: 1.0-beta-3
Fix Version/s: 1.0-rc-1

Time Tracking:
Not Specified

Issue Links:
Duplicate
 


 Description  « Hide
Consider the following ...
public interface ExampleInterface {
    public void setExampleProperty(Object exampleProperty);
}

And the following groovy class ...

class ExampleClass implements ExampleInterface {
    def exampleProperty
}

This should work and does if you aren't using the joint compile stuff.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Luke Daley - 08/Jan/08 04:46 PM
This also begs the question of what to do with the groovy doc :S

// MyClass.groovy

class MyClass {

/**

  • Some documentation here
    */
    def var = null

}

// Generated stub ...

public class MyClass extends Object {

/**

  • Some documentation here
    */
    public Object getVar() { throw new Error(); }

    public void setVar(Object var) { throw new Error(); }
    }

I think attaching the documentation to the getter makes sense. But what if the groovy class defines it's own getter with groovydoc comments?


Jason Dillon - 19/Jan/08 12:25 PM
Is the expected behavior for public Groovy fields to generate the get/set methods and omit the field? Or include the field... I can't recall...

Jason Dillon - 19/Jan/08 12:27 PM
As for custom set/get bits, I think when generating the get/set methods we can check if there is already one defined and omit. And when we run across custom set/get methods we can replace the javadoc for the method.

Jason Dillon - 19/Jan/08 02:01 PM - edited
Ugh, this has the unfortunate side-effect of causing mojo parameter injection to properties to fail

This fails:

/**
 * @parameter expression="${project}"
 */
def project

This works:

/**
 * @parameter expression="${project}"
*/
private def project

Luke Daley - 20/Jan/08 05:10 PM
class MyGroovyClass {
    def p
}

should become

public class MyGroovyClass {
    private Object p
    public void setP(Object p) { throw new Error(); }
    public Object getP() { throw new Error(); }
}

The property is private.


Jason Dillon - 20/Jan/08 05:30 PM
Kay... though I still have a problem with the javadoc... for the property. The field will get the javadoc which it comes with, then I can either omit them for the get/set or make stupid ones.

For now I'm gonna omit, leaving the javadoc only for the field, since that should be compatible with the Mojo muck.


Jason Dillon - 25/Jan/08 04:10 PM
I believe this is fixed now, new snaps deploying shortly.