Is there a Groovy equivilent to Python Docstrings? - groovy

In Python, when commenting a function, you can do it in a way that makes it easier for documentation to be automatically generated. They refer to it as a docstring.
Now that I've made an abstract class in Groovy that I'd like to pass around, is there a standard way I should comment it as well? Are there any Groovy tools to generate basic documentation from code comments?

Documenting Groovy with Groovydoc is a nice starting point:
"Groovydoc was introduced in 2007 to provide for Groovy what Javadoc provides for Java. Groovydoc is used to generate the API documentation for the Groovy and Java classes that compose the Groovy language."

Related

Is there a way to attach a Javadoc doc comment to a Groovy script?

For a Groovy or Java class or method, I would generally include any API-level documentation in a doc comment (aka Javadoc comment), rather than a regular comment. What is the analogous way of adding such comments about a Groovy script?
I personally don't care so much about whether the Javadoc tool picks up the documentation. However, documentation about the purpose of a Groovy script seems conceptually analogous to a doc comment on a class; therefore, I would intuitively expect them to be in a doc comment. If my intuition is wrong and doc tags are not the standard way of commenting the intent of a Groovy script, what is the preferred method to document the purpose of a script?
The syntax section of the Groovy language specification defines the elements that a Groovydoc comment can be associated with:
[Groovydoc] comments are associated with:
type definitions (classes, interfaces, enums, annotations),
fields and properties definitions
methods definitions
Although the compiler will not complain about Groovydoc comments not being associated with the above language elements, you should prepend those constructs with the comment right before it.
A script has no class type definition to put the Groovydoc comment before.
There is an open issue requesting this functionality in the Groovy issue tracker at GROOVY-8877:
Groovydoc doesn't offer any direct way to document Groovy scripts. It will process comments on classes in a Groovy script, but not any sort of file-level or top-level comment.
In summary, script-level Groovydoc comments are not currently supported in a Groovy script file.

Location of Documentation for Groovy Process.waitFor()

I am trying to find the javadoc style documentation for Groovy's Process.waitFor() method.
I am currently using the method, so I know it exists.
It is shown in example code on the codehaus website: http://groovy.codehaus.org/Process+Management
Yet, it is not referenced in the Groovy documentation for Process:
http://groovy.codehaus.org/groovy-jdk/java/lang/Process.html
I would think this would be easy to Google for, but so far no luck.
The waitFor method is in Java's Process class

How to define a method in Groovy-Eclipse DSL

I'm developing a language by taking advantages of groovy-eclipse plugin. I can define a property successfully. However, I can not do same even for a simple method. Probably I'm missing some very simple thing at the center of all...
Can't I define a method that delegates to a simple closure?
What does type property define in a method pointcut?
Following is only contribution block in my groovy dsl file;
currentType(currentType("com.galaksiya.World")){
method name : 'sayHello',
provider : 'Galaksiya',
doc : 'This is a simple salutor.',
delegate: {-> println 'Hello World'}
}
Is it a simple defect or do I need to change my perspective?
OK. I think I see that what is wrong. Concerns are separated. Groovy-Eclipse DSL enables you to manage features like code completion and howers, docs... But it doesn't provide any capability about implementation.
You should design and implement your languages artifacts using meta programming features of groovy (like expandos, dynamic closures etc.) separately from your dsl.

What is the difference between a Groovy object and a Java object with regards to functionality in Groovy code?

First of all, excuse me if I say something obvious because I did not research the answer to this question, it's just something that came to mind and couldn't find an answer to with a quick google search (I also don't know Groovy well).
I'm reading Groovy in action (1st ed) and in section 7.6 it states that "If you want a usual Java class to be recognized as a Groovy class, you only have to implement the GroovyObject interface. For convenience, you can also subclass the abstract class GroovyObjectSupport, which provides default implementations."
So I'm trying out some Java/Groovy (trying to find ways to make coding in Java faster/easier), and I'm instantiating this object Person, which is a Java object and the Person class does not have anything to do with Groovy (i.e. doesn't implement GroovyObject or anything). Person has a protected field, name, with getters/setters. I am able to access this like so in a groovy test case (extends GroovyTestCase), which btw is in a different package and should not be accessible like this:
Person person = new Person('joe')
println "Name: ${person.name}"
Isn't that using the meta info which a Groovy object would have i.e. Groovy would intercept, get the "name" part of "person.name" and call the getName() method or something like that? But person is a Java object... i.e. it shouldn't have that logic available.
I have not implemented GroovyObject or extended GroovyObjectSupport, yet it seems like this Java object has Groovy features I can use.
My question is, what can I assume from Java objects used in Groovy? There is obviously something being done behind the scenes to augment Java defined classes with some Groovy features... but, which features?
So, I guess my question boils down to: "What is done to Java classes when used within a Groovy context?"
Any info regarding the subject would be appreciated, thanks :)
Groovy indeed enhances your Java classes. The problem is when you want to use these enhanced Java classes from Java. Then you need to go for the GroovyObject and GroovyObjectSupport strategy.
About what you can expect, you can check the groovy docs:
the groovy-jdk shows the Groovy enhancements to the JDK
the groovy-api shows the stuff specific from the Groovy library
Also the eclipse plugin works great in autocompleting your Java classes from Groovy.
Java objects are enhanced through Groovy's Meta Object Protocol (MOP), which intercepts and makes its own dispatch to methods and attributes. That is why you can intercept stuff and that's how new methods are added to Java's final classes.
The Groovy's MOP uses cached strategy and reflector classes to achieve a good performance.
You can also read Groovy objects via ObjectInputStream by overriding the resolveClass method and changing the class loader.
See http://www.feiteira.org/2013/04/reading-groovy-objects-from-java.html

How can I get IntelliJ IDEA to recognize the GPars DSL?

According to the GPars User Guide, IntelliJ IDEA is supposed to be able to recognize the GPars DSL right out of the box as soon as the GPars jar is added to the project. Since Groovy 1.8, GPars is now included in the Groovy distribution, but adding that facet to the IDEA project doesn't seem to help.
Does anyone know how I can activate the DSL support? It would be really nice to have the DSL keywords recognized instead of having little underlines everywhere.
Note: I'm using IntelliJ IDEA Ultimate v11.1
It seems GPars jar from Groovy distribution doesn't contain gdsl script which teaches IDEA to work with GPars dsl.
The simplest thing you could do is to add this gdsl file in your project
http://git.codehaus.org/gitweb.cgi?p=gpars.git;a=blob;f=src/main/groovy/groovyx/gpars/Definitions.gdsl;h=49f6993221645e3d887e6bf99c3c0fc46afef69e;hb=b0155a809a5c9adf9de816f18121d5a60d4b455d

Resources