-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParser.java
More file actions
23 lines (19 loc) · 1006 Bytes
/
Copy pathParser.java
File metadata and controls
23 lines (19 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package de.uni_passau.fim.se2.sa.readability.utils;
import com.github.javaparser.*;
import com.github.javaparser.ast.body.BodyDeclaration;
public class Parser {
/**
* Parses the code of a java snippet .jsnp file using the JavaParser library such that it can accept JavaParser visitors.
*
* @param codeSnippet The code of the respective .jsnp as a String
* @return The parsed code snippet ready to accept JavaParser visitors.
* @throws ParseException if the code snippet could not be parsed by the JavaParser library.
*/
public static BodyDeclaration<?> parseJavaSnippet(String codeSnippet) throws ParseException {
ParseResult<BodyDeclaration<?>> parseResult = new JavaParser().parse(ParseStart.CLASS_BODY, new StringProvider(codeSnippet));
if (!parseResult.isSuccessful() || parseResult.getResult().isEmpty()) {
throw new ParseException("Could not parse " + codeSnippet);
}
return parseResult.getResult().get();
}
}