Sharpen annotations decorate java source code and are used
to notify sharpener about how the code should be processed and converted. Annotations
can be used to specify how a code element should be converted (for example
class to enum), to skip conversion of some code elements, to rename classes, to
change visibility etc.
The following table shows existing annotations, their meaning and examples.
Annotation |
Meaning |
@sharpen.enum |
Mark java class to be processed as a .NET enum |
@sharpen.rename |
Specifies a different name for the converted type, takes a single name argument. For example: @sharpen.rename Db4oFactory |
@sharpen.private |
Specifies that the element must be declared private in the converted file, though it can be not private in the java source: /* * @sharpen.private */ public List4 _first; |
@sharpen.internal |
Specifies that the element must be declared internal in the converted file: /** * @sharpen.internal */ public abstract int size(); |
@sharpen.protected |
Specifies that the element must be declared protected in the converted file: /** * @sharpen.protected */ public abstract int size(); |
@sharpen.new | Adds the C#-'new' modifier to the translated code. |
@sharpen.event |
Links an event to its arguments. For example: Java: /** * @sharpen.event com.db4o.events.QueryEventArgs */ public Event4 queryStarted(); is converted to: public delegate void QueryEventHandler( object sender, Db4objects.Db4o.Events.QueryEventArgs args); ....... event Db4objects.Db4o.Events.QueryEventHandler QueryStarted; |
@sharpen.event.add |
Marks the method as an event subscription method. Invocations to the method in the form <target>.method(<argument>) will be replaced by the c# event subscription idiom: <target> += <argument> |
@sharpen.event.onAdd |
Valid for event declaration only (SHARPEN_EVENT). Configures the method to be invoked whenever a new event handler is subscribed to the event. |
@sharpen.if |
Add #if <expression>#endif declaration: @sharpen.if <expression> |
@sharpen.property |
Convert a java method as a property: /** * @sharpen.property */ public abstract int size(); |
@sharpen.indexer |
Marks an element as an indexer property |
@sharpen.ignore |
Skip the element while converting |
@sharpen.ignore.extends |
Ignore the extends clause in Java class definition |
@sharpen.ignore.implements |
Ignore the implements clause in Java class definition |
@sharpen.extends |
Adds an extends clause to the converted class definition. For example: Java: /** * @sharpen.extends System.Collections.IList */ public interface ObjectSet {... converts to public interface IObjectSet : System.Collections.IList |
@sharpen.partial |
Marks the converted class as partial |
@sharpen.remove |
Marks a method invocation that should be removed |
@sharpen.remove.first |
Removes the first line of the method/constructor when converting to C#: /** * @sharpen.remove.first */ public void doSomething(){ System.out.println("Java"); NextMethod(); } converts to: public void DoSomething(){ NextMethod(); } |
@sharpen.struct |
Marks class to be converted as c# struct |
@sharpen.unwrap |
When a method is marked with this annotation /* * @sharpen.unwrap */ public Iterable toIterable(Object[] array){ return Arrays.asList(array); } public void doSomething(Object[] objs){ Iterable iterable = toIterable(objs); // do something with the iterable } Is converted to: public IEnumerable ToIterable(object[] array){ return Arrays.AsList(array); } public void doSomething(object[] objs){ Iterable iterable = objs; // do something with the iterable } |
@sharpen.attribute |
Adds an attribute to the converted code: /* * @sharpen.attribute TheAttribute */ public void doSomething(){} Will be converted to: [TheAttribute] public void DoSomething(){} |
@sharpen.macro | Add a replace-pattern macro to your code. |