Is CamelGroovyMethods used as a groovy category? - dynamic

Apache Camel comes with some relatively nice Groovy extensions so that you, for instance, can use closures with the Java DSL for defining routes.
Most, if not all, of the additional methods providing these extensions seem to be located in the class CamelGroovyMethods with static methods like
public static ProcessorDefinition<?> process(ProcessorDefinition<?> self,
Closure<?> processorLogic){/* implementation */}
How is the actual extension of the Camel java classes realised? Is CamelGroovyMethods used as a category somewhere, and if so, where is use(CamelGroovyMethods) called?

Just a guess, but as they are called extension methods they have probably been defined as such. Look in the jar, you should find a file called org.codehaus.groovy.runtime.ExtensionModule in META-INF/services. Have a look at Creating an extension module. I've used this technique myself and it works great except if you want to provide custom constructors, that requires an alternate mechanism.
...
Yep, found it ExtensionModule file in GitHub. They even provided the dsld file to assist with code completion in Eclipse.

Related

How to use "org.eclipse.ui.internalTweaklets"

No usage information of this extension point is found in Google
Although it is internal, I still want to know how to use it
This extension point is a way for internal Eclipse code to define classes to make small changes (tweaks) to various operations.
The format of the extension point is:
<extension
point="org.eclipse.ui.internalTweaklets">
<tweaklet
definition="org.eclipse.ui.internal.tweaklets.TitlePathUpdater"
id="org.eclipse.ui.cocoa.titlePathUpdaterTweaklet"
implementation="org.eclipse.ui.internal.cocoa.CocoaTitlePathUpdater"
name="Cocoa Title Path Updater">
</tweaklet>
</extension>
On my Eclipse on macOS this the only use of this extension point.
definition is the name of an existing abstract class in Eclipse. Only classes which support tweaklets can be specified, this is not a general mechanism to change anything.
implementation is a class extending the abstract class that is being provided by the plug-in.
id and name don't appear to be used.
The particular extension point I have shown is only used on macOS and is used to set the call the NSWindow.representedFile API when the main window title is set.

How to organize Kotlin extension methods

Let's say I have a few extension methods for "MyClass".
My question is, what's the best practice to organize/store these methods?
Should they be simply put into a "MyClassExtensions" Kotlin file?
I have tried to encapsulate these methods within a class, but after importing the class I couldn't seem to figure out how to use/access the extension methods.
Edit:
For clarification, I was not asking for help what to call a file that contains extension methods. I was asking about best practices/approaches to store/organize such methods. Ie. should they be simply put into kotlin files, or should they be encapsulated in a class. I am coming from a Java background, so I'm used to store stuff in classes.
As far as I am concerned, you should put them into a utility file, as you did in Java code base before.
But mention, you no longer need to put them into a class. Top-level functions are the best choice.
You can refer to the kotlin standard library or some open source projects like anko, those would be good examples.
In my case, I put extensions of one class into a file which have the same name of the original file in another package, and use
#JvmMultifileClass
to reduce the number of generated class files.

Does kotlin support making a class implementing an interface outside of its definition file?

I see kotlin.List and kotlin.MutableList is implemented by java.util.ArrayList. But where did kotlin put this trick? Compiler or somewhere in stdlib?
If kotlin supports making a class implementing an interface outside of its definition file like the ArrayList case, it will be fascinated.
No, it is not supported.
You are right, that is only a compiler trick. There are lots of magic applied to the collections to make them right. Fortunately it is not available to the devs. Special paragraph in the docs: https://kotlinlang.org/docs/reference/java-interop.html#mapped-types

Header files without implementation

I'm working on a open source project, which consist on a framework for iOS devices, and one of the methods is not working as I expected. I tried to search for the implementation of the method, but all I found was a a header file and the method declaration; I didn't find the implementation anywhere. Neither did I find the .m file corresponding to that class.
So I have some questions:
How can a class exist without it's implementation and still its methods perform certain operations?
What is the purpose of writing this kind of classes.
In this kind of situations where should be the methods implemented?
Note
The open source project is FastPdfKit and the method is wholeTextForPage:
Well, those methods are somewhere, so it's not that they don't exist, you just can't see them.
Try for example to open UITableView.h, you can see the methods definition, but not the implementation. The implementation is hidden in the library, but you can't see it.
In a nutshell, developers do this to hide the details of the implementation of a class to other users. You just receive a header that tells you which methods you can use, and how, but the details about how are they implemented are hidden for you.
For example, Apple doesn't want you to see how they implemented UITableView, but they want you to know how you can use it.
Here you can find a tutorial about how to create a library for Objective-C:
Creating Static Libraries for Objective-C

Has Freemarker something similar to toolbox.xml-file of Velocity?

I have a Struts 1 application which works with Velocity as a template language. I shall replace Velocity with Freemarker, and am looking for something similar to 'toolbox.xml'-File from VelocityViewServlet. (there you can map names to Java Classes and, using these names it is possible to access methods and variables of various Java class in the Velocity template).
Does someone know, what is possible with Freemarker instead? So far I have found only information about the form beans...would be glad if someone can help....
For the utility functions and macros that are View-related (not Model-related), the standard practice is to implement them in FreeMarker and put them into one or more templates and #import (or #include) them. It's also possible to pull in TemplateDirectiveModel-s and TemplateMethodModelEx-es (these are similar to macros and function, but they are implemented in Java) into the template that you will #import/#inlcude as <#assign foo = 'com.example.Foo'?new()>.
As of calling plain static Java methods, you may use the ObjectWrapper's getStaticModels() (assuming it's a BeansWrapper subclass) and then get the required methods as TemplateMethodModelEx-es with staticModels.get("com.example.MyStatics"). Now that you have them, you can put them into the data-model (Velocity context) in the Controller, or pick methods from them in an #import-ed template, etc. Of course, you can also put POJO objects into the data-model so you can call their non-static methods.
The third method, which is not much different from putting things into the data-model is using "shared variables", which are variables (possibly including TemplateMethodModelEx-es and TemplateDirectiveModel-s) defined on the Configuration level.