Skip to content

Commit

Permalink
Add @throws from Javadoc to Java model from DOM
Browse files Browse the repository at this point in the history
  • Loading branch information
mickaelistria committed Dec 17, 2024
1 parent 7ca73a2 commit 2fa5a64
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
import org.eclipse.jdt.internal.compiler.parser.RecoveryScanner;
import org.eclipse.jdt.internal.compiler.parser.Scanner;
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens;
import org.eclipse.jdt.internal.core.Annotation;
import org.eclipse.jdt.internal.core.CompilationUnit;
import org.eclipse.jdt.internal.core.TypeParameter;
import org.eclipse.jdt.internal.core.ModuleDescriptionInfo.ModuleReferenceInfo;
import org.eclipse.jdt.internal.core.ModuleDescriptionInfo.PackageExportInfo;
import org.eclipse.jdt.internal.core.ModuleDescriptionInfo.ServiceInfo;
Expand Down Expand Up @@ -522,8 +525,20 @@ public boolean visit(MethodDeclaration method) {
if (this.infos.peek() instanceof SourceTypeElementInfo parentInfo) {
parentInfo.addCategories(newElement, getCategories(method));
}
LinkedHashSet<Type> exceptions = new LinkedHashSet<>();
if (method.getJavadoc() != null) {
((List<TagElement>)method.getJavadoc().tags()).stream()
.filter(tag -> TagElement.TAG_THROWS.equals(tag.getTagName()))
.map(tag -> tag.fragments().get(0))
.filter(Type.class::isInstance)
.map(Type.class::cast)
.forEach(exceptions::add);
}
if (method.getAST().apiLevel() >= AST.JLS8) {
info.setExceptionTypeNames(((List<Type>)method.thrownExceptionTypes()).stream().map(Type::toString).map(String::toCharArray).toArray(char[][]::new));
exceptions.addAll(method.thrownExceptionTypes());
}
if (!exceptions.isEmpty()) {
info.setExceptionTypeNames(exceptions.stream().map(Type::toString).map(String::toCharArray).toArray(char[][]::new));
}
setSourceRange(info, method);
boolean isDeprecated = isNodeDeprecated(method);
Expand Down

0 comments on commit 2fa5a64

Please sign in to comment.