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.
Related
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.
We are working on plugin for ReSharper and we want to make our plugin extensible. Seems, we should use ShellComponent attribute to do it but we can not find any examples. Could anybody enplane how to define custom extension point and how to manage extension. Example of code of extension point and extension implementation would be very helpful.
Thanks.
If you're looking to write a plugin that can extend ReSharper, you need to tell ReSharper about the classes in your plugin, by marking them with the [ShellComponent] or [SoutionComponent] attributes. These attributes have different lifetimes - a shell component lasts the lifetime of ReSharper itself, and a solution component is created when a solution is opened and disposed when the solution is closed.
To make ReSharper do something useful with your components, they typically have to implement an interface, such as ICodeCompletionItemsProvider, and sometimes have to use a different attribute, such as [CodeCleanupModule] (which itself derives from ShellComponentAttribute). There are many extension points in ReSharper, and the one that's appropriate for you depends on what you're trying to do - refactoring, unit test provider, code cleanup, code completion items, etc. The devguide provides a good introduction to the more common extension points.
But if you want to make your own plugin extensible, then your component needs to work with a kind of provider pattern, by deferring work to multiple provider instances. For example, code cleanup works by deferring to multiple code cleanup modules, each responsible for cleaning up a different aspect of your code (whitespace, ordering, etc). To do this, your component should take in a collection of providers in the constructor. ReSharper's component model will automatically create a collection of these types and pass them to. More specifically, you should have a constructor that takes an IEnumerable<T> or IViewable<T>, where T is the interface of the provider you're going to define and call. The IEnumerable<T> will give you a simple collection of providers, but IViewable<T> represents an observable collection, and allows you to subscribe to notifications of new providers being made available from the component model.
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
I want to be able to dynamically create a new class that has all of the methods of another class. In particular, I want to make my own kind of remoting proxy.
class ApiProxy extends haxe.remoting.Proxy { }
The new class ApiProxy would have all of the same method names and signatures as Api, and would be compile time checked. Only every invocation is done over the wire, instead of handled locally.
I think that remoting.Proxy is a magic internal class - is this true? Do regular users have the ability to define a class that is as powerfully static as this? I've never seen this done in Java and I'm impressed with it's capabilities in Haxe.
How would I implement my own class like remoting.Proxy?
you can achieve this with macros
take a look at this post to get the idea:
http://haxe.1354130.n2.nabble.com/Macros-Are-Awesome-tc5945711.html
You can write, save to filesystem and register a new Class inside of a Macro, based on type information that was passed to the function.
haxe.remoting.Proxy is indeed "magic", it is described that way in the source comments:
http://code.google.com/p/haxe/source/browse/trunk/std/haxe/remoting/Proxy.hx?r=3592
You can't replicate with "normal" haxe code. Adding/modifying functionality to haxe.remoting.Proxy for your own class will be difficult, but maybe not impossible.
Check the tutorial for the "equivalent" api implementing code:
http://haxe.org/doc/remoting/proxy
However, something like this is probably possible with macros:
http://haxe.org/manual/macros
Working with macros is challenging right now. There is little in the way of documentation or examples, and the macro feature is still under development. However, it lets you have a some control over the compiler during the compilation process, which can be amazingly useful at times.
good luck!
as part of our application i need to build component that will output code in php and asp
that have the same functionality ( and maybe latter jsp ) .
how can i design this kind of component to be generic as possible ?
You need to be able to create a parse tree out of all input languages.
For each output language, you will need to create a set of tree transforming grammar.
You may also require a runtime library to help translate routines that are not available in your output language.
I would personally go with the Strategy Pattern. You could have a master code maker class and instantiate it with a strategy.
PHPCodeStrategy
ASPCodeStrategy
Then each would have a method called execute maybe. Bu then you could add further strategies down the line and extend your application.
Andrew