コード例 #1
0
  public static void save(File fSource, File fDest, AnalysisConsumer acAnalysisResults)
      throws IOException {
    Reader r = new FileReader(fSource);
    IndentAwareWriter iaw =
        new IndentAwareWriter(new OutputStreamWriter(new FileOutputStream(fDest)));

    try {
      new Injector(r, iaw, new FileSaveConsumer(iaw, acAnalysisResults)).parseFile();
      iaw.flush();
      iaw.close();
    } catch (InjectorParseException ipe) {
      ipe.printStackTrace();
    }
  }
コード例 #2
0
  public void onAttributeHeader(JavaAttribute ja) throws java.io.IOException {
    if (!m_fWroteDocComment) {
      // Feature without comment
      if ((m_iFeatures.hasNext())
          && (getCurrentFeature().getCommentID()
              == m_cComments
                  + 1)) { // ' + 1 ' because the number in m_cComments refers to the last doccomment
                          // that was actually written
        // Might need element-type/key-type spec (i.e., if it is a collection or map)
        if (ja.getType() != null) {
          try {
            Class clClass = ja.getFile().findType(ja.getType());

            if (clClass != null) {
              // Not a simple type --> check whether collection or map
              if (java.util.Collection.class.isAssignableFrom(clClass)
                  || java.util.Map.class.isAssignableFrom(clClass)) {
                // Yup! So we have to generate a comment for it!
                if (m_iawOutput != null) {
                  int nIndent = m_iawOutput.getCurrentIndent();

                  getCurrentFeature().indentComment(nIndent);

                  String sDocComment = getCurrentFeature().getDocComment();

                  if (sDocComment != null) {
                    m_iawOutput.write(sDocComment + "\n");

                    for (; nIndent > 0; nIndent--) {
                      m_iawOutput.write(" ");
                    }
                  }
                }

                m_adCurrentFeature = null; // Mark feature as handled...
                m_cComments++;
              }
            }
          } catch (InjectorParseException ipe) {
            System.err.println("Exception while saving attribute:");
            ipe.printStackTrace();

            throw new IOException(ipe.getMessage());
          }
        }
      }
    }
  }