use of com.github.javaparser.ASTParser in project javaparser by javaparser.
the class JavaParser method parseAnnotation.
/**
* Parses the Java annotation contained in a {@link String} and returns a
* {@link AnnotationExpr} that represents it.
*
* @param annotation
* {@link String} containing Java annotation
* @return AnnotationExpr representing the Java annotation
* @throws ParseException
* if the source code has parser errors
*/
public static AnnotationExpr parseAnnotation(final String annotation) {
StringReader sr = new StringReader(annotation);
AnnotationExpr ae = new ASTParser(sr).Annotation();
sr.close();
return ae;
}
use of com.github.javaparser.ASTParser in project javaparser by javaparser.
the class JavaParser method parseImport.
/**
* Parses the Java import contained in a {@link String} and returns a
* {@link ImportDeclaration} that represents it.
*
* @param importDeclaration
* {@link String} containing Java import code
* @return ImportDeclaration representing the Java import declaration
* @throws ParseException
* if the source code has parser errors
*/
public static ImportDeclaration parseImport(final String importDeclaration) {
StringReader sr = new StringReader(importDeclaration);
ImportDeclaration id = new ASTParser(sr).ImportDeclaration();
sr.close();
return id;
}
use of com.github.javaparser.ASTParser in project javaparser by javaparser.
the class JavaParser method parseBodyDeclaration.
/**
* Parses the Java body declaration(e.g fields or methods) contained in a
* {@link String} and returns a {@link BodyDeclaration} that represents it.
*
* @param body
* {@link String} containing Java body declaration
* @return BodyDeclaration representing the Java annotation
* @throws ParseException
* if the source code has parser errors
*/
public static BodyDeclaration parseBodyDeclaration(final String body) {
StringReader sr = new StringReader(body);
BodyDeclaration bd = new ASTParser(sr).AnnotationBodyDeclaration();
sr.close();
return bd;
}
Aggregations