1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
|
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="2" MadCap:lastHeight="120" MadCap:lastWidth="624" MadCap:disableMasterStylesheet="true" MadCap:tocPath="Community|Working With Source Code|Sharpen" MadCap:InPreviewMode="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" MadCap:PathToHelpSystem="../../../../" MadCap:HelpSystemFileName="index.xml" MadCap:SearchType="Stem">
<head><title>Sharpen Annotations</title>
<script type="text/javascript">/* <![CDATA[ */
window.onload = function(){
var pathToFlash = $('html').attr('MadCap:PathToHelpSystem') + 'Content/Resources/Code/ZeroClipboard.swf';
ZeroClipboard.setMoviePath(pathToFlash);
function bindToClipBord(element,content){
var clip = new ZeroClipboard.Client();
clip.setText(content);
clip.glue(element);
};
if(location.protocol==='file:'){
$('.copylink-marker').remove();
} else{
$('.copylink-marker').each(function(){
var text = $(this).parent().parent().children('.prettyprint').html();
$(this).hover(function(){
bindToClipBord(this,text);
},
function(){});
});
}
prettyPrint();
};
/* ]]> */</script>
<link href="../../../SkinSupport/MadCap.css" rel="stylesheet" />
<link href="../../../Resources/Stylesheets/OnlineStyle.css" rel="stylesheet" />
<script src="../../../SkinSupport/MadCapAll.js">
</script>
<script src="../../../Resources/Code/prettify.js">
</script>
<script src="../../../Resources/Code/lang-vb.js">
</script>
<script src="../../../Resources/Code/jquery.min.js">
</script>
<script src="../../../Resources/Code/ZeroClipboard.js">
</script>
</head>
<body>
<p class="MCWebHelpFramesetLink" style="display: none;"><a href="../../../../index_CSH.html#community/working_with_source/sharpen/sharpen_annotations.htm" style="">Open topic with navigation</a>
</p>
<div class="MCBreadcrumbsBox"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="../../../community.htm">Community</a><span class="MCBreadcrumbsDivider"> > </span><a class="MCBreadcrumbsLink" href="../../working_with_source_code.htm">Working With Source Code</a><span class="MCBreadcrumbsDivider"> > </span><a class="MCBreadcrumbsLink" href="../sharpen.htm">Sharpen</a><span class="MCBreadcrumbsDivider"> > </span><span class="MCBreadcrumbs">Sharpen Annotations</span>
</div>
<p>
<script type="text/javascript">/*<![CDATA[*/document.write('<a href="' + location.href +'">');
document.write("Direct Link");
document.write('</a>');/*]]>*/</script>
</p>
<p>
</p>
<h1>Sharpen Annotations</h1>
<p><span class="MCTextPopup"><a href="javascript:void(0);" class="MCTextPopupSpot" onclick="FMCTextPopup( event, this ); return false;">Sharpen<img style="border: none;margin-left: 5px;" src="../../../SkinSupport/ExpandingClosed.gif" MadCap:altsrc="../../../SkinSupport/ExpandingOpen.gif" class="MCExpandingIcon" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../../SkinSupport/ExpandingOpen.gif' ); }" /></a><span class="MCTextPopupBody" style="display: none; ">Sharpen is a tool to translate Java source code to C# source code</span></span> 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.</p>
<p>The following table shows existing annotations, their
meaning and examples.</p>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td valign="top">
<p><b>Annotation</b>
</p>
</td>
<td valign="top">
<p><b>Meaning</b>
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>@sharpen.enum</p>
</td>
<td valign="top">
<p>Mark java class to be processed as a .NET enum</p>
</td>
</tr>
<tr>
<td valign="top">
<p>@sharpen.rename</p>
</td>
<td valign="top">
<p>Specifies a different name for the converted type, takes a
single name argument. For example:</p>
<p>@sharpen.rename Db4oFactory</p>
</td>
</tr>
<tr>
<td valign="top">
<p>@sharpen.private</p>
</td>
<td valign="top">
<p>Specifies that the element must be declared private in the
converted file, though it can be not private in the java source:</p>
<pre class="monospace" xml:space="preserve">/*
* @sharpen.private
*/
</pre>
<p>public List4 _first;</p>
</td>
</tr>
<tr>
<td valign="top">
<p>@sharpen.internal</p>
</td>
<td valign="top">
<p>Specifies that the element must be declared internal in
the converted file:</p>
<pre class="monospace" xml:space="preserve">/**
* @sharpen.internal
*/</pre>
<p>public abstract int size();</p>
</td>
</tr>
<tr>
<td valign="top">@sharpen.protected</td>
<td valign="top">
<p>Specifies that the element must be declared protected in
the converted file:</p>
<pre class="monospace" xml:space="preserve">/**
* @sharpen.protected
*/</pre>
<p>public abstract int size();</p>
</td>
</tr>
<tr>
<td valign="top">@sharpen.new</td>
<td valign="top">Adds the C#-'new' modifier to the translated code.</td>
</tr>
<tr>
<td valign="top">
<p>@sharpen.event</p>
</td>
<td valign="top">
<p>Links an event to its arguments. For example:</p>
<p>Java:</p>
<pre class="monospace">/**
* @sharpen.event com.db4o.events.QueryEventArgs
*/
public Event4 queryStarted();</pre>
<p>is converted to:</p>
<pre class="monospace">public delegate void QueryEventHandler(
object sender,
Db4objects.Db4o.Events.QueryEventArgs args);
.......
event Db4objects.Db4o.Events.QueryEventHandler QueryStarted;</pre>
</td>
</tr>
<tr>
<td valign="top">
<p>@sharpen.event.add</p>
</td>
<td valign="top">
<p>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> </p>
</td>
</tr>
<tr>
<td valign="top">
<p>@sharpen.event.onAdd</p>
</td>
<td valign="top">
<p>Valid for event declaration only (SHARPEN_EVENT). Configures the method to be invoked whenever a new event handler is subscribed to the event. </p>
</td>
</tr>
<tr>
<td valign="top">
<p>@sharpen.if</p>
</td>
<td valign="top">
<p>Add #if <expression>#endif declaration:</p>
<p>@sharpen.if <expression></p>
</td>
</tr>
<tr>
<td valign="top">
<p>@sharpen.property</p>
</td>
<td valign="top">
<p>Convert a java method as a property:</p>
<pre class="monospace" xml:space="preserve">/**
* @sharpen.property
*/</pre>
<p>public abstract int size();</p>
</td>
</tr>
<tr>
<td valign="top">
<p>@sharpen.indexer</p>
</td>
<td valign="top">
<p>Marks an element as an indexer property</p>
</td>
</tr>
<tr>
<td valign="top">
<p>@sharpen.ignore</p>
</td>
<td valign="top">
<p>Skip the element while converting</p>
</td>
</tr>
<tr>
<td valign="top">
<p>@sharpen.ignore.extends</p>
</td>
<td valign="top">
<p>Ignore the extends clause in Java class definition</p>
</td>
</tr>
<tr>
<td valign="top">
<p>@sharpen.ignore.implements</p>
</td>
<td valign="top">
<p>Ignore the implements clause in Java class definition</p>
</td>
</tr>
<tr>
<td valign="top">
<p>@sharpen.extends</p>
</td>
<td valign="top">
<p>Adds an extends clause to the converted class definition.
For example:</p>
<p>Java:</p>
<pre class="monospace" xml:space="preserve">/**
* @sharpen.extends System.Collections.IList
*/
public interface ObjectSet {...</pre>
<p>converts to</p>
<pre class="monospace">public interface IObjectSet : System.Collections.IList</pre>
</td>
</tr>
<tr>
<td valign="top">
<p>@sharpen.partial</p>
</td>
<td valign="top">
<p>Marks the converted class as partial</p>
</td>
</tr>
<tr>
<td valign="top">
<p>@sharpen.remove</p>
</td>
<td valign="top">
<p>Marks a method invocation that should be removed</p>
</td>
</tr>
<tr>
<td valign="top">@sharpen.remove.first</td>
<td valign="top">
<p valign="top">Removes the first line of the method/constructor when converting to C#:</p>
<pre valign="top" class="monospace" xml:space="preserve">/**
* @sharpen.remove.first
*/
public void doSomething(){
System.out.println("Java");
NextMethod();
}
</pre>
<p valign="top">converts to:</p>
<pre valign="top" class="monospace" xml:space="preserve">public void DoSomething(){
NextMethod();
}</pre>
</td>
</tr>
<tr>
<td valign="top">
<p>@sharpen.struct</p>
</td>
<td valign="top">
<p>Marks class to be converted as c# struct</p>
</td>
</tr>
<tr>
<td valign="top">@sharpen.unwrap</td>
<td valign="top">
<p valign="top">When a method is marked with this annotation <br />all method calls are removed. This is useful for removing conversion methods when their aren't required in C#.</p>
<pre valign="top" class="monospace" xml:space="preserve">/*
* @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
}</pre>
<p valign="top">Is converted to:</p>
<pre valign="top" class="monospace" xml:space="preserve">
public IEnumerable ToIterable(object[] array){
return Arrays.AsList(array);
}
public void doSomething(object[] objs){
Iterable iterable = objs;
// do something with the iterable
}</pre>
</td>
</tr>
<tr>
<td valign="top">@sharpen.attribute</td>
<td valign="top">
<p valign="top">Adds an attribute to the converted code:</p>
<pre valign="top" class="monospace" xml:space="preserve">/*
* @sharpen.attribute TheAttribute
*/
public void doSomething(){}</pre>
<p valign="top">Will be converted to:</p>
<pre valign="top" class="monospace" xml:space="preserve">[TheAttribute]
public void DoSomething(){}</pre>
</td>
</tr>
<tr>
<td valign="top">@sharpen.macro</td>
<td valign="top">Add a replace-pattern macro to your code.</td>
</tr>
</table>
<script type="text/javascript" src="../../../SkinSupport/MadCapBodyEnd.js">
</script>
</body>
</html>
|