Advertisement
Guest User

XBN-Java:Insert Example Code: The basics

a guest
Apr 16th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.71 KB | None | 0 0
  1. ------------------------------------------------
  2. Original JavaDoc with unfilled "IXC blocks" (Insert Example Code):
  3. ------------------------------------------------
  4.    package com.github.xbn.examples.insertexample.adder;
  5.    /**
  6.       <P>Adds an array of zero or more numbers. This class would normally have a license block and at-author tag--they're eliminated for brevity.</P>
  7.  
  8.       <H3>Example</H3>
  9.  
  10.    [([EXAMPLE-CODE-START:com.github.xbn.examples.insertexample.adder.AdderDemo#main()
  11.    <PRE>[[source:getAllSourceLines_tabTo3Spcs_escForHtml_withIndent("   ")]]</PRE>
  12.  
  13.       <P><B>Output:</B></P>
  14.  
  15.    <PRE>   [C:\java_code\]java %fqclassname%
  16.    [[output:getAllOutputLinesWithIndent("   ")]]</PRE>
  17.    :EXAMPLE-CODE-END])]
  18.     **/
  19.    public class Adder_withIxcBlock01  {
  20.       private final int sum;
  21.  
  22.       public Adder_withIxcBlock01(int... numbers_to_add)  {
  23.          int sum2 = 0;
  24.          for(int i : numbers_to_add)  {
  25.             sum2 += i;
  26.          }
  27.          sum = sum2;
  28.       }
  29.  
  30.       public int getSum()  {
  31.          return  sum;
  32.       }
  33.    }
  34.  
  35. ------------------------------------------------
  36. It has three gaps:
  37.  
  38.    - [[source:getAllSourceLines_tabTo3Spcs_escForHtml_withIndent("   ")]]
  39.    - %fqclassname%
  40.    - [[output:getAllOutputLinesWithIndent("   ")]]
  41.  
  42. The function after the colon is the "output line processor". These are basic ones already created. You can also create your own, such as at the bottom of this document.
  43.  
  44. Example code to insert:
  45. ------------------------------------------------
  46.    package com.github.xbn.examples.insertexample.adder;
  47.       import com.github.xbn.examples.insertexample.adder.Adder;
  48.    /**
  49.       <P>Demonstration of {@code com.github.xbn.examples.insertexample.adder.}{@link #com.github.xbn.examples.insertexample.adder.Adder Adder}.</P>
  50.     **/
  51.    public class AdderDemo  {
  52.       public static final void main(String[] ignored)  {
  53.          Adder adder = new Adder();
  54.          System.out.println(adder.getSum());
  55.  
  56.          adder = new Adder(5, -7, 20, 27);
  57.          System.out.println(adder.getSum());
  58.       }
  59.    }
  60.  
  61. ------------------------------------------------
  62. Resulting JavaDoc:
  63. ------------------------------------------------
  64.  
  65.    package com.github.xbn.examples.insertexample.adder;
  66.    /**
  67.       <P>Adds an array of zero or more numbers. This class would normally have a license block and at-author tag--they're eliminated for brevity.</P>
  68.  
  69.       <H3>Example</H3>
  70.  
  71.    <PRE>   package  com.github.xbn.examples.insertexample.adder;
  72.       import  com.github.xbn.examples.insertexample.adder.Adder;
  73.       /&#42;&#42;
  74.        &nbsp; &nbsp; &nbsp;&lt;P&gt;Demonstration of {@code com.github.xbn.examples.insertexample.adder.}{@link #com.github.xbn.examples.insertexample.adder.Adder Adder}.&lt;/P&gt;
  75.         &nbsp; &nbsp;&#42;&#42;/
  76.       public class AdderDemo  {
  77.          public static final void main(String[] ignored)  {
  78.             Adder adder = new Adder();
  79.             System.out.println(adder.getSum());
  80.  
  81.             adder = new Adder(5, -7, 20, 27);
  82.             System.out.println(adder.getSum());
  83.          }
  84.       }</PRE>
  85.  
  86.       <P><B>Output:</B></P>
  87.  
  88.    <PRE>   [C:\java_code\]java com.github.xbn.examples.insertexample.adder.AdderDemo
  89.       0
  90.       45</PRE>
  91.     **/
  92.    public class Adder_withIxcBlock01  {
  93.       private final int sum;
  94.  
  95.       public Adder_withIxcBlock01(int... numbers_to_add)  {
  96.          int sum2 = 0;
  97.          for(int i : numbers_to_add)  {
  98.             sum2 += i;
  99.          }
  100.          sum = sum2;
  101.       }
  102.  
  103.       public int getSum()  {
  104.          return  sum;
  105.       }
  106.    }
  107. ------------------------------------------------
  108. A custom output processor, which would be referenced in the IXC-block with
  109.  
  110.    <PRE>[[source:getSource_AdderDemo("   ")]]</PRE>
  111.  
  112. ------------------------------------------------
  113.       Adder adder = new Adder();
  114.       System.out.println(adder.getSum());
  115.  
  116.  
  117.    static final String getSource_AdderDemo(int start_lineNum, Iterator<String> xmplSrc_lineItr, String base_dir, Class<?> xmpl_class, String indent, String rplc_tabWith)  {
  118.  
  119.       String adderFqName = "com.github.xbn.examples.insertexample.adder.Adder";
  120.  
  121.       //Line alterers in order
  122.       //   Final two parameters are debugging: on=System.out, off=null
  123.  
  124.          TextLineAlterer[] lineAlterers = new TextLineAlterer[] {
  125.             //Indent tab to 3 spaces:
  126.             NewAlterLineFor.regexReplacement(Pattern.compile("\t"), rplc_tabWith, ReplacesWhat.ALL, null, null),
  127.             NewAlterLineFor.regexReplacement(Pattern.compile("^"), indent, ReplacesWhat.FIRST, null, null),
  128.             NewAlterLineFor.escapeHtml(),
  129.  
  130.             //JavaDoc links for *first occurance* of function/class/object names:
  131.             NewSrcOutLineAltererFor.firstFuncNameToJDLinkLineReplacer(adderFqName, "Adder", "", null, null)};
  132.             NewSrcOutLineAltererFor.firstFuncNameToJDLinkLineReplacer(adderFqName, "getSum", "", null, null)};
  133.  
  134.       ExpirableTextLineAlterList alterTxtLnList = new ExpirableTextLineAlterList(
  135.          MultiAlterType.CUMULATIVE, lineAlterers);
  136.       //alterTxtLnList.setDebug(System.out, true);
  137.  
  138.       Iterator<LineObject<String>> lineItr = NewTextLineModeForIxc.exampleCodeElimLicenseBlkAuthorTag
  139.             (null,     //debug_licenseStart (on=System.out, off=null)
  140.              null,     //debug_licenseEnd
  141.              null,     //debug_authorLine
  142.              null).    //debug_mode
  143.          activeLineIterator(xmplSrc_lineItr);
  144.  
  145.       //For each line returned by the text-line-mode iterator
  146.       //(which suppresses the license block and @author tag line),
  147.       //change them with the alteres in lineAlterers
  148.       return  (new AllTextLineAlterer(alterTxtLnList)).getAlteredLineObjects(start_lineNum, lineItr);
  149.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement