private JavaClass _getJavaClass(String fileName, Reader reader) throws Exception {

    int pos = fileName.indexOf("src/");

    if (pos == -1) {
      pos = fileName.indexOf("test/");
    }

    if (pos == -1) {
      throw new RuntimeException(fileName);
    }

    pos = fileName.indexOf("/", pos);

    String srcFile = fileName.substring(pos + 1, fileName.length());
    String className = StringUtil.replace(srcFile.substring(0, srcFile.length() - 5), "/", ".");

    JavaDocBuilder builder = new JavaDocBuilder();

    if (reader == null) {
      File file = new File(fileName);

      if (!file.exists()) {
        return null;
      }

      builder.addSource(file);
    } else {
      builder.addSource(reader);
    }

    return builder.getClassByName(className);
  }
  private JavaClass _getJavaClass(String parentDir, String srcFile) throws IOException {

    String className = StringUtil.replace(srcFile.substring(0, srcFile.length() - 5), "/", ".");

    JavaDocBuilder builder = new JavaDocBuilder();

    builder.addSource(new File(parentDir + "/" + srcFile));

    return builder.getClassByName(className);
  }
  private JavaClass _getJavaClass(String fileName, Reader reader) throws Exception {

    String className = _getClassName(fileName);

    JavaDocBuilder javadocBuilder = new JavaDocBuilder();

    if (reader == null) {
      File file = new File(fileName);

      if (!file.exists()) {
        return null;
      }

      javadocBuilder.addSource(file);
    } else {
      javadocBuilder.addSource(reader);
    }

    return javadocBuilder.getClassByName(className);
  }
Exemple #4
0
  @BeforeClass
  public static void generateClasses() throws ClassNotFoundException, IOException {

    File outputDirectory = generate("/schema/title/title.json", "com.example");
    File generatedJavaFile = new File(outputDirectory, "com/example/Title.java");

    compile(outputDirectory);

    JavaDocBuilder javaDocBuilder = new JavaDocBuilder();
    javaDocBuilder.addSource(generatedJavaFile);

    classWithTitle = javaDocBuilder.getClassByName("com.example.Title");
  }