mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 04:16:19 +00:00
Merge branch 'master' of git@github.com:rzwitserloot/lombok
This commit is contained in:
commit
55dd52942e
16 files changed
+150
-25
No files matched your search
@@ -74,11 +74,15 @@
|
||||
<antcall target="-integrateSnippet">
|
||||
<param name="transformationName" value="Data" />
|
||||
</antcall>
|
||||
<antcall target="-integrateSnippet">
|
||||
<param name="transformationName" value="Cleanup" />
|
||||
</antcall>
|
||||
<mkdir dir="dist" />
|
||||
<tar destfile="dist/website.tar">
|
||||
<tarfileset dir="build/website" />
|
||||
<tarfileset dir="doc/api" prefix="api" />
|
||||
</tar>
|
||||
<echo>If you want to publish the website to the web, run the website/publish script.</echo>
|
||||
</target>
|
||||
|
||||
<target name="-integrateSnippet">
|
||||
|
||||
@@ -78,5 +78,5 @@ import java.lang.annotation.Target;
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface Cleanup {
|
||||
/** The name of the method that cleans up the resource. By default, 'close'. The method must not have any parameters. */
|
||||
String cleanupMethod() default "close";
|
||||
String value() default "close";
|
||||
}
|
||||
@@ -51,7 +51,7 @@ import org.mangosdk.spi.ProviderFor;
|
||||
@ProviderFor(EclipseAnnotationHandler.class)
|
||||
public class HandleCleanup implements EclipseAnnotationHandler<Cleanup> {
|
||||
public boolean handle(AnnotationValues<Cleanup> annotation, Annotation ast, Node annotationNode) {
|
||||
String cleanupName = annotation.getInstance().cleanupMethod();
|
||||
String cleanupName = annotation.getInstance().value();
|
||||
if ( cleanupName.length() == 0 ) {
|
||||
annotationNode.addError("cleanupName cannot be the empty string.");
|
||||
return true;
|
||||
@@ -146,7 +146,7 @@ public class HandleCleanup implements EclipseAnnotationHandler<Cleanup> {
|
||||
unsafeClose.receiver = receiver;
|
||||
long nameSourcePosition = (long)ast.sourceStart << 32 | ast.sourceEnd;
|
||||
if ( ast.memberValuePairs() != null ) for ( MemberValuePair pair : ast.memberValuePairs() ) {
|
||||
if ( pair.name != null && new String(pair.name).equals("cleanupMethod") ) {
|
||||
if ( pair.name != null && new String(pair.name).equals("value") ) {
|
||||
nameSourcePosition = (long)pair.value.sourceStart << 32 | pair.value.sourceEnd;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ import com.sun.tools.javac.util.Name;
|
||||
@ProviderFor(JavacAnnotationHandler.class)
|
||||
public class HandleCleanup implements JavacAnnotationHandler<Cleanup> {
|
||||
@Override public boolean handle(AnnotationValues<Cleanup> annotation, JCAnnotation ast, Node annotationNode) {
|
||||
String cleanupName = annotation.getInstance().cleanupMethod();
|
||||
String cleanupName = annotation.getInstance().value();
|
||||
if ( cleanupName.length() == 0 ) {
|
||||
annotationNode.addError("cleanupName cannot be the empty string.");
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import java.io.*;
|
||||
|
||||
public class CleanupExample {
|
||||
public static void main(String[] args) throws IOException {
|
||||
InputStream in = new FileInputStream(args[0]);
|
||||
try {
|
||||
OutputStream out = new FileOutputStream(args[1]);
|
||||
try {
|
||||
byte[] b = new byte[10000];
|
||||
while (true) {
|
||||
int r = in.read(b);
|
||||
if (r == -1) break;
|
||||
out.write(b, 0, r);
|
||||
}
|
||||
} finally {
|
||||
out.close();
|
||||
}
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import lombok.Cleanup;
|
||||
import java.io.*;
|
||||
|
||||
public class CleanupExample {
|
||||
public static void main(String[] args) throws IOException {
|
||||
@Cleanup InputStream in = new FileInputStream(args[0]);
|
||||
@Cleanup OutputStream out = new FileOutputStream(args[1]);
|
||||
byte[] b = new byte[10000];
|
||||
while (true) {
|
||||
int r = in.read(b);
|
||||
if (r == -1) break;
|
||||
out.write(b, 0, r);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 43 B |
@@ -0,0 +1,63 @@
|
||||
<!DOCTYPE html>
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<link rel="stylesheet" type="text/css" href="../logi/reset.css" />
|
||||
<link rel="stylesheet" type="text/css" href="features.css" />
|
||||
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
|
||||
<meta name="description" content="Spice up your java" />
|
||||
<title>@Cleanup</title>
|
||||
<!--[if lt IE 7]><script type="text/javascript" src="logi/iepngfix_tilebg.js"></script><![endif]-->
|
||||
</head><body><div id="pepper">
|
||||
<div class="minimumHeight"></div>
|
||||
<div class="meat">
|
||||
<div class="header"><a href="../index.html">Project Lombok</a></div>
|
||||
<h1>@Cleanup</h1>
|
||||
<div class="byline">Automatic resource management: Call your <code>close()</code> methods safely with no hassle.</div>
|
||||
<div class="overview">
|
||||
<h3>Overview</h3>
|
||||
<p>
|
||||
You can use <code>@Cleanup</code> to ensure a given resource is automatically cleaned up before the code execution path exits your
|
||||
current scope. You do this by annotating any local variable declaration with the <code>@Cleanup</code> annotation like so:<br />
|
||||
<code>@Cleanup InputStream in = new FileInputStream("some/file");</code><br />
|
||||
As a result, at the end of the scope you're in, <code>in.close()</code> is called. This call is guaranteed to run by way of a
|
||||
try/finally construct. Look at the example below to see how this works.
|
||||
</p><p>
|
||||
If the type of object you'd like to cleanup does not have a <code>close()</code> method, but some other no-argument method, you can
|
||||
specify the name of this method like so:<br />
|
||||
<code>@Cleanup("dispose") org.eclipse.swt.widgets.CoolBar bar = new CoolBar(parent, 0);</code><br />
|
||||
By default, the cleanup method is presumed to be <code>close()</code>. A cleanup method that takes argument cannot be called via
|
||||
<code>@Cleanup</code>.
|
||||
</p>
|
||||
</div>
|
||||
<div class="snippets">
|
||||
<div class="pre">
|
||||
<h3>With Lombok</h3>
|
||||
<div class="snippet">@HTML_PRE@</div>
|
||||
</div>
|
||||
<div class="sep"></div>
|
||||
<div class="post">
|
||||
<h3>Vanilla Java</h3>
|
||||
<div class="snippet">@HTML_POST@</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style="clear: left;"></div>
|
||||
<div class="overview">
|
||||
<h3>Small print</h3><div class="smallprint">
|
||||
<p>
|
||||
If your code throws an exception, and the cleanup method call that is then triggered also throws an exception, then the original exception
|
||||
is hidden by the exception thrown by the cleanup call. You should <em>not</em> rely on this 'feature'. Preferably, lombok would like to generate
|
||||
code so that, if the main body has thrown an exception, any exception thrown by the close call is silently swallowed (but if the main body
|
||||
exited in any other way, exceptions by the close call will not be swallowed). The authors of lombok do not currently know of a feasible way
|
||||
to implement this scheme, but if java updates allow it, or we find a way, we'll fix it.
|
||||
</p><p>
|
||||
You do still need to handle any exception that the cleanup method can generate!
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<a href="index.html">Back to features</a> | <a href="Data.html">Previous feature (@Data)</a> | <a href="Synchronized.html">Next feature (@Synchronized)</a><br />
|
||||
<span class="copyright">Copyright © 2009 Reinier Zwitserloot and Roel Spilker, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT licence</a>.</span>
|
||||
</div>
|
||||
<div style="clear: both;"></div>
|
||||
</div>
|
||||
</div></body></html>
|
||||
@@ -8,10 +8,12 @@
|
||||
<title>@Data</title>
|
||||
<!--[if lt IE 7]><script type="text/javascript" src="logi/iepngfix_tilebg.js"></script><![endif]-->
|
||||
</head><body><div id="pepper">
|
||||
<div class="minimumHeight"></div>
|
||||
<div class="meat">
|
||||
<div class="minimumHeight"></div>
|
||||
<div class="header"><a href="../index.html">Project Lombok</a></div>
|
||||
<h1>@Data</h1>
|
||||
<div class="byline">'struct' for java: Automatically generate <code>toString</code>, <code>hashCode</code>, <code>equals</code>, a constructor, and getters and setters
|
||||
from just the fields in your class.</div>
|
||||
<div class="overview">
|
||||
<h3>Overview</h3>
|
||||
<p>
|
||||
@@ -71,10 +73,10 @@
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<footer>
|
||||
<div class="footer">
|
||||
<a href="index.html">Back to features</a> | <a href="GetterSetter.html">Previous feature (@Getter / @Setter)</a> | <a href="Cleanup.html">Next feature (@Cleanup)</a><br />
|
||||
<span class="copyright">Copyright © 2009 Reinier Zwitserloot and Roel Spilker, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT licence</a>.</span>
|
||||
</footer>
|
||||
</div>
|
||||
<div style="clear: both;"></div>
|
||||
</div>
|
||||
</div></body></html>
|
||||
@@ -8,10 +8,11 @@
|
||||
<title>@Getter and @Setter</title>
|
||||
<!--[if lt IE 7]><script type="text/javascript" src="logi/iepngfix_tilebg.js"></script><![endif]-->
|
||||
</head><body><div id="pepper">
|
||||
<div class="minimumHeight"></div>
|
||||
<div class="meat">
|
||||
<div class="minimumHeight"></div>
|
||||
<div class="header"><a href="../index.html">Project Lombok</a></div>
|
||||
<h1>@Getter and @Setter</h1>
|
||||
<div class="byline">Never write <code>public int getFoo() {return foo;}</code> again.</div>
|
||||
<div class="overview">
|
||||
<h3>Overview</h3>
|
||||
<p>
|
||||
@@ -51,10 +52,10 @@
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<footer>
|
||||
<div class="footer">
|
||||
<a href="index.html">Back to features</a> | <span class="disabled">Previous feature</span> | <a href="Data.html">Next feature (@Data)</a><br />
|
||||
<span class="copyright">Copyright © 2009 Reinier Zwitserloot and Roel Spilker, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT licence</a>.</span>
|
||||
</footer>
|
||||
</div>
|
||||
<div style="clear: both;"></div>
|
||||
</div>
|
||||
</div></body></html>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 43 B |
@@ -12,6 +12,10 @@ body {
|
||||
background-position: 50px 20px;
|
||||
}
|
||||
|
||||
* html #pepper {
|
||||
background: none;
|
||||
}
|
||||
|
||||
.meat {
|
||||
padding: 0px 48px;
|
||||
}
|
||||
@@ -22,20 +26,33 @@ body {
|
||||
left: 30px;
|
||||
}
|
||||
|
||||
.meat .minimumHeight {
|
||||
.minimumHeight {
|
||||
height: 700px;
|
||||
width: 5px;
|
||||
width: 1px;
|
||||
float: right;
|
||||
}
|
||||
|
||||
* html .minimumHeight {
|
||||
height: 0px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
padding: 8px 0 10px 0;
|
||||
font-size: 20px;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.byline {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
font-style: italic;
|
||||
font-size: 1.3em;
|
||||
}
|
||||
|
||||
.index {
|
||||
font-size: 1.2em;
|
||||
margin: 64px 0px 32px 64px;
|
||||
margin: 48px 0px 32px 64px;
|
||||
}
|
||||
|
||||
.index dt {
|
||||
@@ -101,7 +118,7 @@ h1 {
|
||||
display: none;
|
||||
}
|
||||
|
||||
footer {
|
||||
.footer {
|
||||
clear: left;
|
||||
margin: 0 auto 0 auto;
|
||||
padding: 16px 0 16px 0;
|
||||
@@ -109,11 +126,11 @@ footer {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
footer .disabled {
|
||||
.footer .disabled {
|
||||
color: #aaa;
|
||||
}
|
||||
|
||||
footer .copyright {
|
||||
.footer .copyright {
|
||||
color: #555;
|
||||
font-size: 11px;
|
||||
font-style: italic;
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
|
||||
<meta name="description" content="Spice up your java" />
|
||||
<title>Lombok feature overview</title>
|
||||
<!--[if lt IE 7]><script type="text/javascript" src="logi/iepngfix_tilebg.js"></script><![endif]-->
|
||||
<!--[if lt IE 7]><script type="text/javascript" src="../logi/iepngfix_tilebg.js"></script><![endif]-->
|
||||
</head><body><div id="pepper">
|
||||
<div class="minimumHeight"></div>
|
||||
<div class="meat">
|
||||
<div class="minimumHeight"></div>
|
||||
<div class="header"><a href="../index.html">Project Lombok</a></div>
|
||||
<h1>Lombok features</h1>
|
||||
<div class="index overview">
|
||||
@@ -27,9 +27,9 @@
|
||||
<dd>To boldly throw checked exceptions where no one has thrown them before!</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<footer>
|
||||
<div class="footer">
|
||||
<span class="copyright">Copyright © 2009 Reinier Zwitserloot and Roel Spilker, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT licence</a>.</span>
|
||||
</footer>
|
||||
</div>
|
||||
<div style="clear: both;"></div>
|
||||
</div>
|
||||
</div></body></html>
|
||||
+3
-2
@@ -8,7 +8,8 @@ body {
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 8px 0 16px 0;
|
||||
padding: 8px 0 10px 0;
|
||||
font-size: 20px;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
@@ -120,7 +121,7 @@ code {
|
||||
background-color: #888;
|
||||
}
|
||||
|
||||
footer {
|
||||
.footer {
|
||||
margin-top: 8px;
|
||||
display: block;
|
||||
color: #555;
|
||||
|
||||
+2
-2
@@ -48,8 +48,8 @@
|
||||
<div class="endBar">
|
||||
<a href="slideshow.html">I don't want to see a video - show me a slideshow instead!</a>
|
||||
</div>
|
||||
<footer>
|
||||
<div class="footer">
|
||||
Copyright © 2009 Reinier Zwitserloot and Roel Spilker, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT licence</a>.
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
</body></html>
|
||||
@@ -13,7 +13,7 @@ IEPNGFix.data = IEPNGFix.data || {};
|
||||
|
||||
// This must be a path to a blank image, relative to the HTML document(s).
|
||||
// In production use I suggest '/images/blankImg' or similar. That's all!
|
||||
IEPNGFix.blankImg = 'logi-img/clear.gif';
|
||||
IEPNGFix.blankImg = 'clear.gif';
|
||||
|
||||
|
||||
IEPNGFix.fix = function(elm, src, t) {
|
||||
|
||||
Reference in new issue
Block a user