|
Project Information
Links
|
Eclipse JDT extension to visually collapse (fold) anonymous inner classes to concise lambda expressions (closures) in Java Editor. Moved to https://github.com/elucash/lambda4jdtWhile it is not difficult to write anonymous inner classes using completion and/or templates in java editor, reading of such structures can be really hurting. Read also http://code.google.com/p/guava-libraries/wiki/FunctionalExplained#Caveats Unlike real language change proposals (CICE or BGGA),
Lambda4jdt uses hacked jface projection infrastructure to visually hide uninteresting parts of specified anonymous class declaration. In attempt to modify collapsed text of closure expression will be expanded back to anonymous inner class (I have tried to add limited in place editing but it is not working properly yet or ever will). It can be collapsed again manually (using (-) icon in editor ruler column) or by resetting folding structure. Appearance of collapsed function expressions uses parents in argumeny lists and curly braces for multi liners. Also folding engine collapses anonymous inner class declaration to clause statement (like custom control methods in BGGA). Such folding only take place when function method body consist of more than one expression and appears to be single parameter of higher order method invocation, which is followed by statement terminator (semicolon). In particular it is triggered by char '(' before inner class and by sequence ');' after declaration. Executor e =...
e.execute {
doSomething();
}
// for one line it is folded like simple lambda expression
final int i = 1;//you still need final to access i in function
h.invoke(111, () doSomethingWithIn(i));
Nested closure constructs are supported to some degree interface Provider<T> {
T get(Object context);
}
//Consider such code
public Provider<Provider<Provider<String>>> myProvider() {
return new Provider<Provider<Provider<String>>>() {
public Provider<Provider<String>> get(Object c) {
return new Provider<Provider<String>>() {
public Provider<String> get(Object c) {
return new Provider<String>() {
public String get(Object c) {
return "MyFavoriteStringFactory" + c;
}
};
}
};
}
};
}
//....
// Which may be collapsed to..
public Provider<Provider<Provider<String>>> myProvider() {
return (c) (c) (c) "MyFavoriteStringFactory" + c;
}Lambda4jdt is in early development phase and some bugs are known. Preferences block can be added later. Lambda4jdt is experimental proof-of-concept project not intended for broad use, but rather a toy to play with and evaluate use of closures in Java (as we wont see closures support in java language for a long time). Sometimes inappropriately partially hidden text chunks can occur when some modification by quick fix, refactoring or toggle comment (and such) overlaps with collapsed code in a unexpected manner. Quirks can be defeated by resetting folding structure or reopening editor. Solution targets an Eclipse Indigo 3.7.2 Dont forget to switch you folding provider. Install plugins and then goto Preferences->Java->Editor->Folding, select folding to use "Lambda4jdt Folding". Any newly opened Java editor will pickup lambda4jdt
|


