mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 22:16:11 +00:00
@StandardException feature working draft
* move feature under experimental * replace ProviderFor with Provides * add doc material (to be completed) * add author
This commit is contained in:
1 parent
63ea3db6b7
commit
af16ba23cd
9 files changed
+74
-13
No files matched your search
@@ -2,6 +2,7 @@ Lombok contributors in alphabetical order:
|
||||
|
||||
Adam Juraszek <juriad@gmail.com>
|
||||
Aleksandr Zhelezniak <lekan1992@gmail.com>
|
||||
Amine Touzani <ttzn.dev@gmail.com>
|
||||
Andre Brait <andrebrait@gmail.com>
|
||||
Bulgakov Alexander <buls@yandex.ru>
|
||||
Caleb Brinkman <floralvikings@gmail.com>
|
||||
|
||||
@@ -23,16 +23,16 @@ package lombok.eclipse.handlers;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.ConfigurationKeys;
|
||||
import lombok.StandardException;
|
||||
import lombok.experimental.StandardException;
|
||||
import lombok.core.AST.Kind;
|
||||
import lombok.core.AnnotationValues;
|
||||
import lombok.eclipse.Eclipse;
|
||||
import lombok.eclipse.EclipseAnnotationHandler;
|
||||
import lombok.eclipse.EclipseNode;
|
||||
import lombok.eclipse.handlers.EclipseHandlerUtil.*;
|
||||
import lombok.spi.Provides;
|
||||
import org.eclipse.jdt.internal.compiler.ast.*;
|
||||
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
|
||||
import org.mangosdk.spi.ProviderFor;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
@@ -42,7 +42,7 @@ import static lombok.eclipse.Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG;
|
||||
import static lombok.eclipse.Eclipse.pos;
|
||||
import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
|
||||
|
||||
@ProviderFor(EclipseAnnotationHandler.class)
|
||||
@Provides
|
||||
public class HandleStandardException extends EclipseAnnotationHandler<StandardException> {
|
||||
private static final String NAME = StandardException.class.getSimpleName();
|
||||
|
||||
@@ -175,12 +175,10 @@ public class HandleStandardException extends EclipseAnnotationHandler<StandardEx
|
||||
|
||||
@SuppressWarnings("deprecation") public static ConstructorDeclaration createConstructor(
|
||||
AccessLevel level, EclipseNode type, Collection<SuperParameter> parameters, EclipseNode sourceNode) {
|
||||
|
||||
ASTNode source = sourceNode.get();
|
||||
TypeDeclaration typeDeclaration = ((TypeDeclaration) type.get());
|
||||
|
||||
boolean isEnum = (((TypeDeclaration) type.get()).modifiers & ClassFileConstants.AccEnum) != 0;
|
||||
|
||||
if (isEnum) level = AccessLevel.PRIVATE;
|
||||
|
||||
boolean addConstructorProperties;
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package lombok;
|
||||
package lombok.experimental;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -30,7 +30,7 @@ import com.sun.tools.javac.util.ListBuffer;
|
||||
import com.sun.tools.javac.util.Name;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.ConfigurationKeys;
|
||||
import lombok.StandardException;
|
||||
import lombok.experimental.StandardException;
|
||||
import lombok.core.AST.Kind;
|
||||
import lombok.core.AnnotationValues;
|
||||
import lombok.delombok.LombokOptionsFactory;
|
||||
@@ -39,13 +39,13 @@ import lombok.javac.JavacAnnotationHandler;
|
||||
import lombok.javac.JavacNode;
|
||||
import lombok.javac.JavacTreeMaker;
|
||||
import lombok.javac.handlers.JavacHandlerUtil.*;
|
||||
import org.mangosdk.spi.ProviderFor;
|
||||
import lombok.spi.Provides;
|
||||
|
||||
import static lombok.core.handlers.HandlerUtil.handleFlagUsage;
|
||||
import static lombok.javac.Javac.CTC_VOID;
|
||||
import static lombok.javac.handlers.JavacHandlerUtil.*;
|
||||
|
||||
@ProviderFor(JavacAnnotationHandler.class)
|
||||
@Provides
|
||||
public class HandleStandardException extends JavacAnnotationHandler<StandardException> {
|
||||
private static final String NAME = StandardException.class.getSimpleName();
|
||||
|
||||
@@ -161,7 +161,6 @@ public class HandleStandardException extends JavacAnnotationHandler<StandardExce
|
||||
if (isEnum) level = AccessLevel.PRIVATE;
|
||||
|
||||
boolean addConstructorProperties;
|
||||
|
||||
if (fieldsToParam.isEmpty()) {
|
||||
addConstructorProperties = false;
|
||||
} else {
|
||||
@@ -194,7 +193,7 @@ public class HandleStandardException extends JavacAnnotationHandler<StandardExce
|
||||
}
|
||||
return recursiveSetGeneratedBy(maker.MethodDef(mods, typeNode.toName("<init>"),
|
||||
null, List.<JCTypeParameter>nil(), params.toList(), List.<JCExpression>nil(),
|
||||
maker.Block(0L, statements.toList()), null), source.get(), typeNode.getContext());
|
||||
maker.Block(0L, statements.toList()), null), source);
|
||||
}
|
||||
|
||||
public static boolean isLocalType(JavacNode type) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
@lombok.StandardException class EmptyException extends Exception {
|
||||
import lombok.experimental.StandardException;
|
||||
|
||||
@StandardException class EmptyException extends Exception {
|
||||
}
|
||||
@lombok.StandardException class NoArgsException extends Exception {
|
||||
@StandardException class NoArgsException extends Exception {
|
||||
public NoArgsException() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<#import "../_features.html" as f>
|
||||
|
||||
<@f.scaffold title="@StandardException"
|
||||
logline="TODO">
|
||||
<@f.history>
|
||||
<p>
|
||||
<code>@StandardException</code> was introduced as an experimental feature in lombok v1.18.21.
|
||||
</p>
|
||||
</@f.history>
|
||||
|
||||
<@f.overview>
|
||||
<p>
|
||||
This annotation is intended to be used on subclasses of <code>java.util.Throwable</code>. For each of the four constructors in <code>Throwable</code>, it will generate a corresponding constructor in the target class, that simply forwards its argument to its super-counterpart.
|
||||
</p><p>
|
||||
If any of those constructors is manually overriden, it is simply skipped. This allows applying special treatment such as annotations.
|
||||
</p>
|
||||
</@f.overview>
|
||||
|
||||
<@f.snippets name="StandardException" />
|
||||
|
||||
<@f.confKeys>
|
||||
<dt>
|
||||
<code>lombok.standardException.addConstructorProperties</code> = [<code>true</code> | <code>false</code>] (default: <code>false</code>)
|
||||
</dt><dt>
|
||||
<code>lombok.standardException.flagUsage</code> = [<code>warning</code> | <code>error</code>] (default: not set)
|
||||
</dt><dd>
|
||||
Lombok will flag any usage of <code>@StandardException</code> as a warning or error if configured.
|
||||
</dd>
|
||||
</@f.confKeys>
|
||||
|
||||
<@f.smallPrint>
|
||||
<p>
|
||||
Although such situation is unlikely to occur, this annotation can technically be applied to any class for which all four expected constructors are defined in a superclass.
|
||||
</p>
|
||||
</@f.smallPrint>
|
||||
</@f.scaffold>
|
||||
@@ -75,6 +75,10 @@
|
||||
<@main.feature title="@Jacksonized" href="Jacksonized">
|
||||
Bob, meet Jackson. Lets make sure you become fast friends.
|
||||
</@main.feature>
|
||||
|
||||
<@main.feature title="@StandardException" href="StandardException">
|
||||
TODO
|
||||
</@main.feature>
|
||||
</div>
|
||||
|
||||
<@f.confKeys>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
public class ExampleException extends Exception {
|
||||
public ExampleException() {
|
||||
}
|
||||
|
||||
public ExampleException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ExampleException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public ExampleException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import lombok.experimental.StandardException;
|
||||
|
||||
@StandardException
|
||||
public class ExampleException extends Exception {
|
||||
}
|
||||
Reference in new issue
Block a user