コード例 #1
0
ファイル: SharedUtils.java プロジェクト: ELTE-Soft/txtUML
  public static CompilationUnit[] parseICompilationUnitStream(
      Stream<ICompilationUnit> stream, IJavaProject javaProject)
      throws IOException, JavaModelException {

    // Sneaky.<JavaModelException> Throw();
    // Sneaky.<IOException> Throw();
    return stream
        .map(ICompilationUnit::getResource)
        .map(IResource::getLocationURI)
        .map(File::new)
        .map(Sneaky.unchecked(f -> SharedUtils.parseJavaSource(f, javaProject)))
        .filter(Objects::nonNull)
        .toArray(CompilationUnit[]::new);
  }
コード例 #2
0
ファイル: SharedUtils.java プロジェクト: ELTE-Soft/txtUML
  /**
   * Parses the specified Java source file located in the given Java project.
   *
   * @param sourceFile The specified Java source file.
   * @param project The given Java project.
   * @return The parsed compilation unit.
   * @throws IOException Thrown when I/O error occurs during reading the file.
   * @throws JavaModelException
   */
  public static CompilationUnit parseJavaSource(File sourceFile, IJavaProject project)
      throws IOException, JavaModelException {
    ASTParser parser = ASTParser.newParser(AST.JLS8);
    char[] content = SharedUtils.getFileContents(sourceFile);

    parser.setSource(content);
    parser.setProject(project);

    parser.setResolveBindings(true);
    parser.setBindingsRecovery(true);
    parser.setUnitName(sourceFile.getName());
    parser.setKind(ASTParser.K_COMPILATION_UNIT);

    CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(null);
    return compilationUnit;
  }