-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement @ThrowsException annotation #135
base: master
Are you sure you want to change the base?
Conversation
@lnsun Can you have a pass through these changes? |
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) | ||
public @interface ThrowsException { | ||
Class<? extends Throwable> value() default Throwable.class; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to make this an array, since a method could throw multiple different exceptions.
@@ -300,6 +303,13 @@ public static ControlFlowGraph build( | |||
/** Does this node terminate the execution? (e.g., "System.exit()") */ | |||
protected boolean terminatesExecution = false; | |||
|
|||
/** | |||
* Provided this node terminates the execution, does the execution exit immediately? e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about "Indicate whether this node terminates the execution of current method and exits the program immediately"
AnnotationUtils.getElementValueClassName(throwAnno, "value", false) | ||
.toString(); | ||
if (cls == null) { // thrown type is Throwable by default | ||
thrown = elements.getTypeElement("java.lang.Throwable").asType(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default is already decleared in the annotation as Throwable
, is this line accessible in any way?
// get type of thrown exception | ||
String cls = | ||
AnnotationUtils.getElementValueClassName(throwAnno, "value", false) | ||
.toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If value
is changing to array, maybe this part needs to be updated
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) | ||
public @interface ThrowsException { | ||
Class<? extends RuntimeException> value() default RuntimeException.class; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About the choice of the type of value
, I think there are the following questions:
- Whether Error should be included.
- Should the checked exceptions be included? Although uncaught checked exceptions are always declared in the
throws
clause in the method signature, it cannot express the behavior of "unconditionally throws such exception", which can be supplemented by@ThrowsException
annotation.
…into throw-exception-annotation
This PR implements @ThrowsException annotation and fixes issue #2076