001/*license*\
002   Codelet
003
004   Copyright (c) 2014, Jeff Epstein (aliteralmind __DASH__ github __AT__ yahoo __DOT__ com)
005
006   This software is dual-licensed under the:
007   - Lesser General Public License (LGPL) version 3.0 or, at your option, any later version;
008   - Apache Software License (ASL) version 2.0.
009
010   Either license may be applied at your discretion. More information may be found at
011   - http://en.wikipedia.org/wiki/Multi-licensing.
012
013   The text of both licenses is available in the root directory of this project, under the names "LICENSE_lgpl-3.0.txt" and "LICENSE_asl-2.0.txt". The latest copies may be downloaded at:
014   - LGPL 3.0: https://www.gnu.org/licenses/lgpl-3.0.txt
015   - ASL 2.0: http://www.apache.org/licenses/LICENSE-2.0.txt
016\*license*/
017package  com.github.aliteralmind.codelet.examples.non_xbn;
018   import  com.github.xbn.io.RTIOException;
019   import  java.io.File;
020   import  java.io.IOException;
021   import  java.util.Iterator;
022   import  java.util.regex.Pattern;
023   import  org.apache.commons.io.FileUtils;
024/**
025   <p>Prints the start and end line-numbers for all JavaDoc blocks in a Java source-code file. The one and only parameter is the path to the file. This assumes that the JavaDoc open-comment (slash-asterisk-asterisk) is the first non-whitespace on its line. The end comment (asterisk-slash) may be anywhere on the line.</p>
026
027   <p><code>java com.github.codelet.examples.non_xbn.PrintJDBlocksStartStopLineNumsXmpl xbnjava\xbn\examples\<!--escape-u is illegal-->util\PrintJDBlocksStartStopLineNumsXmpl.java</code></p>
028
029   <p>Self-answered question on stackoverflow.com
030   <br/> &nbsp; &nbsp; <code><a href="http://stackoverflow.com/questions/21312336/how-to-detect-each-javadoc-block-start-and-end-line-in-a-source-code-file">http://stackoverflow.com/questions/21312336/how-to-detect-each-javadoc-block-start-and-end-line-in-a-source-code-file</a></code></p>
031
032 * @see  com.github.xbn.examples.text.line.FindJavaDocBlocksAndSLCmtsXmpl
033 * @since  0.1.0
034 * @author  Copyright (C) 2014, Jeff Epstein ({@code aliteralmind __DASH__ github __AT__ yahoo __DOT__ com}), dual-licensed under the LGPL (version 3.0 or later) or the ASL (version 2.0). See source code for details. <a href="http://codelet.aliteralmind.com">{@code http://codelet.aliteralmind.com}</a>, <a href="https://github.com/aliteralmind/codelet">{@code https://github.com/aliteralmind/codelet}</a>
035 **/
036public class PrintJDBlocksStartStopLineNumsXmpl  {
037   /**
038      <p>The main function.</p>
039    */
040   public static final void main(String[] as_1RqdJavaSourcePath)  {
041
042      //Read command-line parameter
043         String sJPath = null;
044         try  {
045            sJPath = as_1RqdJavaSourcePath[0];
046         }  catch(ArrayIndexOutOfBoundsException aibx)  {
047            throw  new NullPointerException("Missing one-and-only required parameter: Path to java source-code file.");
048         }
049         System.out.println("Java source: " + sJPath);
050
051      //Establish line-iterator
052         Iterator<String> lineItr = null;
053         try  {
054            lineItr = FileUtils.lineIterator(new File(sJPath)); //Throws npx if null
055         }  catch(IOException iox)  {
056            throw  new RTIOException("PrintJDBlocksStartStopLinesXmpl", iox);
057         }
058         Pattern pTrmdJDBlockStart = Pattern.compile("^[\\t ]*/\\*\\*");
059
060      String sDD = "..";
061      int lineNum = 1;
062      boolean bInJDBlock = false;
063      while(lineItr.hasNext())  {
064         String sLn = lineItr.next();
065         if(!bInJDBlock)  {
066            if(pTrmdJDBlockStart.matcher(sLn).matches())  {
067               bInJDBlock = true;
068               System.out.print(lineNum + sDD);
069            }
070         }  else if(sLn.indexOf("*/") != -1)  {
071            bInJDBlock = false;
072            System.out.println(lineNum);
073         }
074         lineNum++;
075      }
076      if(bInJDBlock)  {
077         throw  new IllegalStateException("Reach end of file. JavaDoc not closed.");
078      }
079   }
080   /**
081      <p>Another one</p>
082    */
083   private static final void oneMoreForGoodMeasure()  {
084   }
085}