aboutsummaryrefslogtreecommitdiffstats
path: root/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithThrowable.java
diff options
context:
space:
mode:
Diffstat (limited to 'javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithThrowable.java')
-rw-r--r--javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithThrowable.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithThrowable.java b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithThrowable.java
new file mode 100644
index 000000000..beee9e727
--- /dev/null
+++ b/javaparser-symbol-solver-testing/src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/nodeTypes/NodeWithThrowable.java
@@ -0,0 +1,57 @@
+package com.github.javaparser.ast.nodeTypes;
+
+import java.util.List;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
+import com.github.javaparser.ast.type.ReferenceType;
+
+public interface NodeWithThrowable<T> {
+ T setThrows(List<ReferenceType> throws_);
+
+ List<ReferenceType> getThrows();
+
+ /**
+ * Adds this type to the throws clause
+ *
+ * @param throwType the exception type
+ * @return this
+ */
+ @SuppressWarnings("unchecked")
+ default T addThrows(ReferenceType throwType) {
+ getThrows().add(throwType);
+ throwType.setParentNode((Node) this);
+ return (T) this;
+ }
+
+ /**
+ * Adds this class to the throws clause
+ *
+ * @param clazz the exception class
+ * @return this
+ */
+ default T addThrows(Class<? extends Throwable> clazz) {
+ ((Node) this).tryAddImportToParentCompilationUnit(clazz);
+ return addThrows(new ClassOrInterfaceType(clazz.getSimpleName()));
+ }
+
+ /**
+ * Check whether this elements throws this exception class
+ *
+ * @param clazz the class of the exception
+ * @return true if found in throws clause, false if not
+ */
+ public default boolean isThrows(Class<? extends Throwable> clazz) {
+ return isThrows(clazz.getSimpleName());
+ }
+
+ /**
+ * Check whether this elements throws this exception class
+ *
+ * @param throwableName the class of the exception
+ * @return true if found in throws clause, false if not
+ */
+ public default boolean isThrows(String throwableName) {
+ return getThrows().stream().anyMatch(t -> t.toString().equals(throwableName));
+ }
+}