There are many ways how to define extension methods for existing types in Groovy, e.g. meta-class, categories, extension modules etc. I'd like to know, which of them are compatible with static compilation via #CompileStatic. I know that it is possible to put a pre-built extension module jar into the classpath providing an extension method for e.g. String and then write a #CompileStatic Groovy class which uses the extension methods from the extension module. However, I'd like to have a solution where I can define extension methods in the same project so that I don't have to build the extension module in advance. Is this possible in Groovy?
Answer from tim_yates in the comments: Most probably not possible, see here.
Related
If I open a Kotlin project and try to create my own template for JUnit Test Classes I get the generated template generated as a Java file instead of as a Kotlin file.
Is there any way to make this generation to happen as a Kotlin file?
I attached some images to easily show the issue I am facing.
The question marks on one of the images have to do because I don't know what that default parse function does. I tried to change it to #parse("File Header.kt") but that does not work.
The issue was I was trying to add kotlin code to the template.
All I had to do is create the template using Java code and it automatically gets generated in Java.
However, if anyone know a way to specifically use this feature using your own kotlin code instead of generated one, please let me know.
Is there a workaround to make this possible in Kotlin?
open object ClientFetcherHelper
I would like to be able to mock the object in java test class using Mockito.
I now there are multiple ways of mocking final classes or static methods, but I do not want to add more external library dependencies to a big project.
Or how could I mock the methods inside an object ?
I was looking into Objective-C protocols and delegates and was trying to implement a custom one in Xamarin.iOS. I was following the example in the Xamarin documentation for "Binding Protocols"
[BaseType (typeof(NSObject))]
[Model][Protocol]
public interface INITableViewCellDelegate {
}
for some reason I cannot find the BaseType attribute. I cannot reference it. My current list of namespaces for the project are:
using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.CoreGraphics;
using MonoTouch.ObjCRuntime;
I'm expecting that it should be under System or MonoTouch.ObjCRuntime. Can anyone shed some light? I've checked other questions on StackOverflow involving binding protocols and many examples show the same MonoTouch usings.
Thank you
Make sure you are using an iOS Binding Project
[BaseType] attributes are only used in projects of type "iOS Binding Project" and are not available at runtime.
So make sure you're doing an "iOS Binding Project" that'll be processed by the btouch tools and will generate bindings for your native library.
I had this same problem because I just blindly added the files that Sharpie creates to my project without thinking.
When you create a new iOS binding library, it creates two files: ApiDefinition.cs and Structs.cs. These are empty except for a namespace that matches the project name.
When Sharpie is run it creates two files: ApiDefinitions.cs and StructsAndEnums.cs. These are the pure definitions and do not exist in a namespace. Do not add these files to your project. Instead;
Copy all the contents of ApiDefinitions.cs and paste it in the empty namespace in ApiDefinition.cs.
Copy all the contents of StructsAndEnums.cs and paste it into the empty namespace in Structs.cs.
Hopefully it should now build.
Is there a way to generate an XSD document automatically from the binding.xml used by JIBx? This is mainly to allow offline validation of the XML documents will be unmarshalled eventually.
I checked the JIBx homepage, it mentioned a tool called Schema Generator:
http://jibx.sourceforge.net/jibxtools/schema-example.html
but looks like the jibx-genschema.jar file is no longer part of the package anymore, as such I was wondering if there is any alternative
Thanks!
Here is the link to the original package.
http://mirrors.ibiblio.org/pub/mirrors/maven2/org/codehaus/xfire/jibx/genschema/jibx-genschema.jar
Schema generator main class is org.jibx.binding.Compile. It is available in jibx-bind.jar.
This jar can be added to your project with maven dependency org.jibx:jibx-bind:1.2.3 (for example).
The SchemaGen tool has been included in the jibx-tools.jar file for some time. See the JiBX Binding Generator page for instructions on running tools in the jar, just substitute the target class org.jibx.schema.generator.SchemaGen to run the schema generator.
I am using a UI component from J2ME Polish. I found a simple bug in the code, and want to quickly fix it but cannot find any build scripts in the download package, although source-code is included.
The problem cannot be solved by extending the class as it involves members with private access.
How should I go about fixing it? Should I simply compile the class in question with Javac or should try to locate build script in their repository?
There is no binary code for J2MEPolish UI library, because these classes are also preprocessed during your application compilation. This is why there is also no build script for J2MEPolish UI part - the resulting binary, if it compiles, would not make any sense :)
If you are using this UI class directly (there is no Polish magic involved) I would suggest to copy it into your own project, make the changes there and you should be just fine.
But there is a small issue. I'm not 100% sure, but Polish build process should be as follows: first your classes are preprocessed and then Polish classes will be preprocessed. If the UI component, that you copied into your project, will stay in the same java package, it could happen that your changes will be overwritten by buggy Polish implementation. You can check it by running the application or looking at the final java code in build directory.
If the overwriting problem happens, then you have two options - move UI class in your project into different package (I'm 99% sure this should be fine if you use it directly) or you need to modify Polish build process, so that it would preprocess Polish classes first and you could overwrite changes done by it.
/JaanusSiim
I know this question has been answered and accepted but an easier method would be to used their built in property (for any one coming here via the magic search engines)
polish.client.source=/projecthome/j2me-polish-source
which is simply a copy of their sources packaged with the installer. You can copy this into your own source tree and thus have version history of your changes.
While JaanusSiim's method might work I would not recommend it as it becomes confusing having de.enough.** packages in your own source tree I normally create a src for my personal source and a src-j2mepolish for their source files this was it is VERY explicit what I have added to the standard versions.