public static CompilationUnit parse(final File file, final String encoding) throws ParseException, IOException { return parse(file,encoding,true); }
public CGFile(InputStream in) throws ParseException { cu = JavaParser.parse(in); // parse }
/** * Parses the Java code contained in the {@link InputStream} and returns a * {@link CompilationUnit} that represents it. * * @param in * {@link InputStream} containing Java source code * @return CompilationUnit representing the Java source code * @throws ParseException * if the source code has parser errors */ public static CompilationUnit parse(final InputStream in) throws ParseException { return parse(in, null,true); }
public static CompilationUnit parse(final InputStream in, final String encoding) throws ParseException { return parse(in,encoding,true); }
/** * Parses the Java code contained in a {@link File} and returns a * {@link CompilationUnit} that represents it. * * @param file * {@link File} containing Java source code * @return CompilationUnit representing the Java source code * @throws ParseException * if the source code has parser errors * @throws IOException */ public static CompilationUnit parse(final File file) throws ParseException, IOException { return parse(file, null,true); }
private void parseCompilationUnit(InputStream input) { try { compilationUnit = JavaParser.parse(input, "UTF-8"); } catch (ParseException pe) { throw new IllegalArgumentException(pe); } }
/** * Parses the Java code contained in a {@link File} and returns a * {@link CompilationUnit} that represents it. * * @param file * {@link File} containing Java source code * @param encoding * encoding of the source code * @return CompilationUnit representing the Java source code * @throws ParseException * if the source code has parser errors * @throws IOException */ public static CompilationUnit parse(final File file, final String encoding, boolean considerComments) throws ParseException, IOException { final FileInputStream in = new FileInputStream(file); try { return parse(in, encoding, considerComments); } finally { in.close(); } }
CU(String source) throws ParseException { this.compilationUnit = JavaParser.parse(new ByteArrayInputStream(source.getBytes())); this.source = source; this.sb = new TextArea(source); this.types = new ArrayList<TypeSource>(); }
public String getMethodBody(ExecutableElement element) { if (cu == null) { try { cu = JavaParser.parse(inputStream); } catch (ParseException e) { return null; } finally { try { inputStream.close(); } catch (IOException e) {} } } MethodVisitor methodVisitor = new MethodVisitor(); methodVisitor.visit(cu, element); return methodVisitor.getMethodBody(); }
/** * This method will add methods, fields and import statement to existing java file * * @throws IOException * @throws ParseException */ public void insertCode() throws IOException, ParseException { CompilationUnit cuResult = JavaParser.parse(baseFile); if (cuResult.getImports() != null) { List<ImportDeclaration> importsFromBaseFile = cuResult.getImports(); for (ImportDeclaration eachImport : importsFromExtendedFile) { if (!importAlreadyPresent(importsFromBaseFile, eachImport)) { importsFromBaseFile.add(eachImport); } } cuResult.setImports(importsFromBaseFile); } String code = cuResult.toString(); BufferedWriter b = new BufferedWriter(new FileWriter(baseFile)); b.write(code); b.close(); }
try { in = new FileInputStream(file); cu = JavaParser.parse(in); } catch (ParseException | FileNotFoundException e) { throw new SampleCodeParserException(e);
final String classText = text + "\n" + "public class Dummy{}"; final StringReader reader = new StringReader(classText); final CompilationUnit compilationUnit = JavaParser.parse(reader, true); final List<TypeDeclaration> typeDeclarations = compilationUnit .getTypes();
private void initialize() throws IOException, ParseException { CompilationUnit cu = JavaParser.parse(file); if (cu.getImports() != null) { imports = cu.getImports(); } initializeFieldDetails(cu); initializeMethodDetails(cu); }
public CompilationUnit assertCompilationUnit() { if (cu == null) { try { Resource content = sourcePath.getResource(path).getObject(); InputStream in = content.getInputStream(); cu = JavaParser.parse(in); } catch (Exception e) { throw AbstractTestCase.failure(e); } } return cu; }
public CompilationUnit assertCompilationUnit() { if (cu == null) { try { Resource content = sourcePath.getResource(path).getObject(); InputStream in = content.getInputStream(); cu = JavaParser.parse(in); } catch (Exception e) { throw AbstractTestCase.failure(e); } } return cu; }