EADS-3523 PLSQL Folding doesn't separate different Comment block into individual folds
authorchrislovsund@netbeans.org
Mon, 18 Mar 2013 15:49:13 +0100
changeset 3629a549f0d1c97
parent 361 263576d44506
child 363 3bf19a69e02b
EADS-3523 PLSQL Folding doesn't separate different Comment block into individual folds
- check for \n\n
- add TASK_DELAY to 1000
PLSQL/Folding/src/org/netbeans/modules/plsql/fold/NewPlsqlFoldManager.java
PLSQL/Lexer/src/org/netbeans/modules/plsql/lexer/PlsqlBlockFactory.java
     1.1 --- a/PLSQL/Folding/src/org/netbeans/modules/plsql/fold/NewPlsqlFoldManager.java	Fri Mar 15 14:17:14 2013 +0100
     1.2 +++ b/PLSQL/Folding/src/org/netbeans/modules/plsql/fold/NewPlsqlFoldManager.java	Mon Mar 18 15:49:13 2013 +0100
     1.3 @@ -72,7 +72,7 @@
     1.4  
     1.5     private static final Logger LOG = Logger.getLogger(NewPlsqlFoldManager.class.getName());
     1.6     private static final RequestProcessor RP = new RequestProcessor(NewPlsqlFoldManager.class.getName(), 1, false, false);
     1.7 -   private static final int TASK_DELAY = 300;
     1.8 +   private static final int TASK_DELAY = 1000;
     1.9     private final RequestProcessor.Task task = RP.create(this);
    1.10     private FoldOperation operation;
    1.11     private Document doc;
     2.1 --- a/PLSQL/Lexer/src/org/netbeans/modules/plsql/lexer/PlsqlBlockFactory.java	Fri Mar 15 14:17:14 2013 +0100
     2.2 +++ b/PLSQL/Lexer/src/org/netbeans/modules/plsql/lexer/PlsqlBlockFactory.java	Mon Mar 18 15:49:13 2013 +0100
     2.3 @@ -51,6 +51,8 @@
     2.4  import java.util.Map;
     2.5  import java.util.Observable;
     2.6  import java.util.StringTokenizer;
     2.7 +import java.util.logging.Level;
     2.8 +import java.util.logging.Logger;
     2.9  import javax.swing.SwingUtilities;
    2.10  import javax.swing.event.DocumentEvent;
    2.11  import javax.swing.event.DocumentListener;
    2.12 @@ -65,10 +67,12 @@
    2.13  
    2.14  /**
    2.15   * Class that will maintain code blocks of the file.
    2.16 + *
    2.17   * @author YaDhLK
    2.18   */
    2.19  public class PlsqlBlockFactory extends Observable implements DocumentListener {
    2.20  
    2.21 +    private static final Logger LOG = Logger.getLogger(PlsqlBlockFactory.class.getName());
    2.22      private List<PlsqlBlock> blockHierarchy;
    2.23      private List<PlsqlBlock> customFoldBlocks;
    2.24      private List<PlsqlBlock> newBlocks;
    2.25 @@ -104,6 +108,7 @@
    2.26  
    2.27      /**
    2.28       * Method used to reparse the whole document
    2.29 +     *
    2.30       * @param doc
    2.31       */
    2.32      public void reParse(Document doc) {
    2.33 @@ -126,6 +131,7 @@
    2.34  
    2.35      /**
    2.36       * Return new blocks that were recognized by the latest change
    2.37 +     *
    2.38       * @return
    2.39       */
    2.40      public List<PlsqlBlock> getNewBlocks() {
    2.41 @@ -134,6 +140,7 @@
    2.42  
    2.43      /**
    2.44       * Return the blocks who's offsets have changed
    2.45 +     *
    2.46       * @return
    2.47       */
    2.48      public List<PlsqlBlock> getChangedBlocks() {
    2.49 @@ -142,6 +149,7 @@
    2.50  
    2.51      /**
    2.52       * Return the custom fold blocks that are there
    2.53 +     *
    2.54       * @return
    2.55       */
    2.56      public List<PlsqlBlock> getCustomFolds() {
    2.57 @@ -150,6 +158,7 @@
    2.58  
    2.59      /**
    2.60       * Return block hierarchy
    2.61 +     *
    2.62       * @return
    2.63       */
    2.64      public List<PlsqlBlock> getBlockHierarchy() {
    2.65 @@ -158,6 +167,7 @@
    2.66  
    2.67      /**
    2.68       * Method that will return the blocks that are removed
    2.69 +     *
    2.70       * @return
    2.71       */
    2.72      public List<PlsqlBlock> getRemovedBlocks() {
    2.73 @@ -166,6 +176,7 @@
    2.74  
    2.75      /**
    2.76       * Check whether there are childrean of this fold here, if so add them
    2.77 +     *
    2.78       * @param block
    2.79       * @param immediateBlockHier
    2.80       */
    2.81 @@ -187,6 +198,7 @@
    2.82  
    2.83      /**
    2.84       * Method that will look for custom start or end token based on the given type
    2.85 +     *
    2.86       * @param customEndToken
    2.87       * @param ts
    2.88       * @param immediateBlockHier
    2.89 @@ -265,6 +277,7 @@
    2.90  
    2.91      /**
    2.92       * Method that will check for a Java Source block
    2.93 +     *
    2.94       * @param tempToken
    2.95       * @param ts
    2.96       * @param immediateBlockHier
    2.97 @@ -285,7 +298,7 @@
    2.98              String image = tmp.text().toString();
    2.99              PlsqlTokenId tokenID = tmp.id();
   2.100  
   2.101 -            if ((tmp != null) && (!image.equals("/")) && (tmp.offset(tokenHierarchy) > endParse)) {
   2.102 +            if ((!image.equals("/")) && (tmp.offset(tokenHierarchy) > endParse)) {
   2.103                  break;
   2.104              }
   2.105  
   2.106 @@ -309,6 +322,7 @@
   2.107  
   2.108      /**
   2.109       * Check whether this current token is the only token in this line
   2.110 +     *
   2.111       * @param ts
   2.112       * @param offset
   2.113       * @return
   2.114 @@ -358,26 +372,24 @@
   2.115  
   2.116      /**
   2.117       * Method that will check for statement blocks other than the CURSOR and VIEW
   2.118 +     *
   2.119       * @param tempToken
   2.120       * @param ts
   2.121       * @param immediateBlockHier
   2.122       * @return
   2.123       */
   2.124      private PlsqlBlock checkStatementBlock(Token<PlsqlTokenId> current, TokenSequence<PlsqlTokenId> ts, List<PlsqlBlock> parentBlocks) {
   2.125 -        Token<PlsqlTokenId> stmtBegin = null;
   2.126 -        Token<PlsqlTokenId> token = null;
   2.127          List<PlsqlBlock> lstChild = new ArrayList<PlsqlBlock>();
   2.128          PlsqlBlock block = null;
   2.129 -        boolean moveNext = false;
   2.130  
   2.131          //Check whether the beginning is in a SQL Plus command
   2.132          if (sqlPlusLine(ts)) {
   2.133              return null;
   2.134          }
   2.135  
   2.136 -        moveNext = ts.moveNext();
   2.137 -        token = ts.token();
   2.138 -        stmtBegin = current;
   2.139 +        boolean moveNext = ts.moveNext();
   2.140 +        Token<PlsqlTokenId> token = ts.token();
   2.141 +        Token<PlsqlTokenId> stmtBegin = current;
   2.142          boolean getName = true;
   2.143          Token<PlsqlTokenId> customStartToken = null;
   2.144          String name = current.text().toString();
   2.145 @@ -425,9 +437,6 @@
   2.146                      customStartToken = token;
   2.147                  } else if (image.toUpperCase(Locale.ENGLISH).contains("<END-FOLD>")) {
   2.148                      if (customStartToken != null) {
   2.149 -                        String fname = customStartToken.text().toString();
   2.150 -                        int index = fname.toUpperCase(Locale.ENGLISH).indexOf("<FOLD>");
   2.151 -                        fname = fname.substring(index + 7).trim();
   2.152                          if (ts.moveNext()) {
   2.153                              token = ts.token();
   2.154                              PlsqlBlock custom = new PlsqlBlock(customStartToken.offset(tokenHierarchy),
   2.155 @@ -473,6 +482,7 @@
   2.156  
   2.157      /**
   2.158       * Check whether the given token offset is included in any existing block
   2.159 +     *
   2.160       * @param token
   2.161       * @param immediateBlockHier
   2.162       * @param parent
   2.163 @@ -499,6 +509,7 @@
   2.164  
   2.165      /**
   2.166       * Method that will look for trigger blocks
   2.167 +     *
   2.168       * @param tempToken
   2.169       * @param ts
   2.170       * @param parentBlocks
   2.171 @@ -678,6 +689,7 @@
   2.172  
   2.173      /**
   2.174       * Method that will check the prefix of the given block and change the block values accordingly
   2.175 +     *
   2.176       * @param startOffset
   2.177       * @param ts
   2.178       * @param begin
   2.179 @@ -712,6 +724,7 @@
   2.180  
   2.181      /**
   2.182       * Check whether there is a block existing with the given offset as the start offset
   2.183 +     *
   2.184       * @param blockHierarchy
   2.185       * @param offset
   2.186       * @return
   2.187 @@ -765,6 +778,7 @@
   2.188  
   2.189      /**
   2.190       * Method that will remove the begin block of this declare block if there
   2.191 +     *
   2.192       * @param declareBlock
   2.193       */
   2.194      private void removeChildBegin(PlsqlBlock declareBlock) {
   2.195 @@ -781,6 +795,7 @@
   2.196  
   2.197      /**
   2.198       * Change offsets of the blocks below the area
   2.199 +     *
   2.200       * @param blockHier
   2.201       * @param endParse
   2.202       * @param length
   2.203 @@ -848,6 +863,7 @@
   2.204  
   2.205      /**
   2.206       * Method that will check whether there are DEFINE statements in the affected area
   2.207 +     *
   2.208       * @param doc
   2.209       * @param startOffset
   2.210       * @param endOffset
   2.211 @@ -866,6 +882,7 @@
   2.212  
   2.213      /**
   2.214       * Method that will make CURSOR blocks
   2.215 +     *
   2.216       * @param tempToken
   2.217       * @param ts
   2.218       * @param parentBlocks
   2.219 @@ -1011,6 +1028,7 @@
   2.220  
   2.221      /**
   2.222       * Check whether we have caught a begin of a declare block
   2.223 +     *
   2.224       * @param ts
   2.225       * @param immediate
   2.226       * @return
   2.227 @@ -1053,6 +1071,7 @@
   2.228  
   2.229      /**
   2.230       * Check whether the given block is already there in block hierarchy
   2.231 +     *
   2.232       * @param block
   2.233       * @param childList
   2.234       * @return
   2.235 @@ -1240,10 +1259,10 @@
   2.236      }
   2.237  
   2.238      private synchronized void doUpdate(final Document document, final List<EventProperties> docList) {
   2.239 +        LOG.log(Level.FINE, "doUpdate", new Object[]{document, docList});
   2.240  
   2.241          //make sure that the updates are run in the Swing thread
   2.242          SwingUtilities.invokeLater(new Runnable() {
   2.243 -
   2.244              @Override
   2.245              public void run() {
   2.246                  setChanged();
   2.247 @@ -1267,23 +1286,26 @@
   2.248  
   2.249      /**
   2.250       * Event fired on insert
   2.251 +     *
   2.252       * @param e
   2.253       */
   2.254      @Override
   2.255      public void insertUpdate(DocumentEvent e) {
   2.256 +        LOG.log(Level.FINER, "insertUpdate", e);
   2.257          if (isSaveInProgress()) {
   2.258              return;
   2.259          }
   2.260 -
   2.261          addUpdateEvent(e, DocumentEvent.EventType.INSERT);
   2.262      }
   2.263  
   2.264      /**
   2.265       * Event fired in remove
   2.266 +     *
   2.267       * @param e
   2.268       */
   2.269      @Override
   2.270      public void removeUpdate(DocumentEvent e) {
   2.271 +        LOG.log(Level.FINER, "removeUpdate", e);
   2.272          if (isSaveInProgress()) {
   2.273              return;
   2.274          }
   2.275 @@ -1292,6 +1314,7 @@
   2.276  
   2.277      /**
   2.278       * triggered when opening a different document
   2.279 +     *
   2.280       * @param e
   2.281       */
   2.282      @Override
   2.283 @@ -1302,6 +1325,7 @@
   2.284  
   2.285      /**
   2.286       * Update block hierarchy on a document event
   2.287 +     *
   2.288       * @param e
   2.289       * @param action
   2.290       */
   2.291 @@ -1333,6 +1357,7 @@
   2.292  
   2.293      /**
   2.294       * Method that will return the block within the start & end parse
   2.295 +     *
   2.296       * @param start
   2.297       * @param end
   2.298       * @return
   2.299 @@ -1359,6 +1384,7 @@
   2.300  
   2.301      /**
   2.302       * Get the line offset of the beginning of this block end line
   2.303 +     *
   2.304       * @param doc
   2.305       * @param parent
   2.306       * @return
   2.307 @@ -1431,6 +1457,7 @@
   2.308  
   2.309      /**
   2.310       * Get the line offset of the second line of this block start
   2.311 +     *
   2.312       * @param doc
   2.313       * @param parent
   2.314       * @return
   2.315 @@ -1479,8 +1506,8 @@
   2.316      }
   2.317  
   2.318      /**
   2.319 -     * Method that will evaluate the given block and
   2.320 -     * decide whether the name has to be changed
   2.321 +     * Method that will evaluate the given block and decide whether the name has to be changed
   2.322 +     *
   2.323       * @param block
   2.324       */
   2.325      private void evaluateBlock(PlsqlBlock block) {
   2.326 @@ -1498,6 +1525,7 @@
   2.327  
   2.328      /**
   2.329       * Remove given block from the hierarchy
   2.330 +     *
   2.331       * @param blockHier
   2.332       * @param block
   2.333       */
   2.334 @@ -1529,7 +1557,9 @@
   2.335      }
   2.336  
   2.337      /**
   2.338 -     * Add child blocks enclosed by the change area to the remove list (do not update the parse area here, done only in REMOVE)
   2.339 +     * Add child blocks enclosed by the change area to the remove list (do not update the parse area here, done only in
   2.340 +     * REMOVE)
   2.341 +     *
   2.342       * @param doc
   2.343       * @param plsqlBlocks
   2.344       * @param toBeRemoved
   2.345 @@ -1553,8 +1583,8 @@
   2.346      }
   2.347  
   2.348      /**
   2.349 -     * Add child blocks affected by the change area to the remove list
   2.350 -     * and update the parse area
   2.351 +     * Add child blocks affected by the change area to the remove list and update the parse area
   2.352 +     *
   2.353       * @param doc
   2.354       * @param plsqlBlocks
   2.355       * @param toBeRemoved
   2.356 @@ -1623,6 +1653,7 @@
   2.357  
   2.358      /**
   2.359       * Remove custom fold blocks that are there within the parse area
   2.360 +     *
   2.361       * @param customFoldBlocks
   2.362       * @param startParse
   2.363       * @param endParse
   2.364 @@ -1647,6 +1678,7 @@
   2.365  
   2.366      /**
   2.367       * If given block exists in the hier delete
   2.368 +     *
   2.369       * @param child
   2.370       * @param parentBlocks
   2.371       */
   2.372 @@ -1693,6 +1725,7 @@
   2.373       * Update block hierarchy based on the document event and the action
   2.374       */
   2.375      private synchronized void updateBlocks(Document doc, List<EventProperties> docList) {
   2.376 +        LOG.log(Level.FINE, "updateBlocks", new Object[]{doc, docList});
   2.377          clear();
   2.378          try {
   2.379              ((AbstractDocument) doc).readLock();
   2.380 @@ -1710,6 +1743,7 @@
   2.381  
   2.382              for (int x = 0; x < docList.size(); x++) {
   2.383                  event = docList.get(x);
   2.384 +                LOG.log(Level.FINE, "event={0}, ", new Object[]{event});
   2.385                  int offset = event.offset;
   2.386                  int length = event.length;
   2.387                  DocumentEvent.EventType action = event.mode;
   2.388 @@ -1868,6 +1902,7 @@
   2.389  
   2.390      /**
   2.391       * Get block which is immediately before the given offset
   2.392 +     *
   2.393       * @param blocks
   2.394       * @param block
   2.395       * @param offset
   2.396 @@ -1895,6 +1930,7 @@
   2.397  
   2.398      /**
   2.399       * Get fold which is immediately after the given offset
   2.400 +     *
   2.401       * @param blocks
   2.402       * @param block
   2.403       * @param offset
   2.404 @@ -1922,6 +1958,7 @@
   2.405  
   2.406      /**
   2.407       * Method that will generate blocks of the given offset range
   2.408 +     *
   2.409       * @param startOffset
   2.410       * @param endOffset
   2.411       */
   2.412 @@ -1930,6 +1967,9 @@
   2.413          tokenHierarchy = TokenHierarchy.get(doc);
   2.414          @SuppressWarnings("unchecked")
   2.415          TokenSequence<PlsqlTokenId> ts = tokenHierarchy.tokenSequence(PlsqlTokenId.language());
   2.416 +        if (ts == null) {
   2.417 +            return;
   2.418 +        }
   2.419  
   2.420          PlsqlBlock parent = getParentBlock(blockHierarchy, startParse, endParse);
   2.421          if (parent != null) {
   2.422 @@ -1938,201 +1978,177 @@
   2.423              immediateBlockHier = blockHierarchy;
   2.424          }
   2.425  
   2.426 -        if (ts != null) {
   2.427 -            //move offset
   2.428 -            ts.move(startParse);
   2.429 -            Token<PlsqlTokenId> tempToken = null;
   2.430 -            Token<PlsqlTokenId> customStartToken = null;
   2.431 -            Token<PlsqlTokenId> customEndToken = null;
   2.432 -
   2.433 -            //Go through all the available tokens
   2.434 -            while (ts.moveNext()) {
   2.435 -                tempToken = ts.token();
   2.436 -                PlsqlTokenId tokenID = tempToken.id();
   2.437 -                String image = tempToken.text().toString();
   2.438 -
   2.439 -                //Check end offset and break (exception for colun which will mark end of some blocks)
   2.440 -                if ((tempToken != null) && (!image.equals(";")) && (tempToken.offset(tokenHierarchy) > endParse)) {
   2.441 -                    break;
   2.442 -                }
   2.443 -
   2.444 -                if (tokenID == PlsqlTokenId.KEYWORD) {
   2.445 -                    if (image.equalsIgnoreCase("VIEW")) {
   2.446 +        LOG.log(Level.FINE, "generateBlocks, doc.getLength()={0}, ts.tokenCount()={1}",
   2.447 +                new Object[]{doc.getLength(), ts.tokenCount()});
   2.448 +        //move offset
   2.449 +        ts.move(startParse);
   2.450 +        Token<PlsqlTokenId> tempToken;
   2.451 +        Token<PlsqlTokenId> customStartToken = null;
   2.452 +        Token<PlsqlTokenId> customEndToken = null;
   2.453 +
   2.454 +        //Go through all the available tokens
   2.455 +        while (ts.moveNext()) {
   2.456 +            tempToken = ts.token();
   2.457 +            PlsqlTokenId tokenID = tempToken.id();
   2.458 +            String image = tempToken.text().toString();
   2.459 +
   2.460 +            LOG.log(Level.FINE, "tempToken.id()={0}, tempToken.text()={1}",
   2.461 +                    new Object[]{tempToken.id(), tempToken.text()});
   2.462 +
   2.463 +            //Check end offset and break (exception for colun which will mark end of some blocks)
   2.464 +            if ((!image.equals(";")) && (tempToken.offset(tokenHierarchy) > endParse)) {
   2.465 +                break;
   2.466 +            }
   2.467 +
   2.468 +            if (tokenID == PlsqlTokenId.KEYWORD) {
   2.469 +                if (image.equalsIgnoreCase("VIEW")) {
   2.470 +                    int offset = ts.offset();
   2.471 +                    PlsqlBlock block = checkView(tempToken, ts, immediateBlockHier);
   2.472 +                    if (block == null) {
   2.473 +                        //pass from the immediate next token to get inner blocks
   2.474 +                        ts.move(offset);
   2.475 +                        ts.moveNext();
   2.476 +                    } else {
   2.477 +                        checkAndAddNew(block, parent, immediateBlockHier);
   2.478 +                    }
   2.479 +                } else if (image.equalsIgnoreCase("FUNCTION")) {
   2.480 +                    int offset = ts.offset();
   2.481 +                    PlsqlBlock block = checkMethod(tempToken, ts, PlsqlBlockType.FUNCTION_IMPL, immediateBlockHier);
   2.482 +                    if (block == null) {
   2.483 +                        //pass from the immediate next token to get inner blocks
   2.484 +                        ts.move(offset);
   2.485 +                        ts.moveNext();
   2.486 +                    } else {
   2.487 +                        checkAndAddNew(block, parent, immediateBlockHier);
   2.488 +                    }
   2.489 +                } else if (image.equalsIgnoreCase("PROCEDURE")) {
   2.490 +                    int offset = ts.offset();
   2.491 +                    PlsqlBlock block = checkMethod(tempToken, ts, PlsqlBlockType.PROCEDURE_IMPL, immediateBlockHier);
   2.492 +                    if (block == null) {
   2.493 +                        //pass from the immediate next token to get inner blocks
   2.494 +                        ts.move(offset);
   2.495 +                        ts.moveNext();
   2.496 +                    } else {
   2.497 +                        checkAndAddNew(block, parent, immediateBlockHier);
   2.498 +                    }
   2.499 +                } else if (image.equalsIgnoreCase("PACKAGE")) {
   2.500 +                    int offset = ts.offset();
   2.501 +                    PlsqlBlock block = checkPackage(tempToken, ts, immediateBlockHier);
   2.502 +                    if (block == null) {
   2.503 +                        //pass from the immediate next token to get inner blocks
   2.504 +                        ts.move(offset);
   2.505 +                        ts.moveNext();
   2.506 +                    } else {
   2.507 +                        checkAndAddNew(block, parent, immediateBlockHier);
   2.508 +                    }
   2.509 +                } else if (image.equalsIgnoreCase("CURSOR")) {
   2.510 +                    int offset = ts.offset();
   2.511 +                    PlsqlBlock block = checkCursor(tempToken, ts, immediateBlockHier);
   2.512 +                    if (block == null) {
   2.513 +                        //pass from the immediate next token to get inner blocks
   2.514 +                        ts.move(offset);
   2.515 +                        ts.moveNext();
   2.516 +                    } else {
   2.517 +                        checkAndAddNew(block, parent, immediateBlockHier);
   2.518 +                    }
   2.519 +                } else if (image.equalsIgnoreCase("TRIGGER")) {
   2.520 +                    int offset = ts.offset();
   2.521 +                    PlsqlBlock block = checkTrigger(tempToken, ts, immediateBlockHier);
   2.522 +                    if (block == null) {
   2.523 +                        //pass from the immediate next token to get inner blocks
   2.524 +                        ts.move(offset);
   2.525 +                        ts.moveNext();
   2.526 +                    } else {
   2.527 +                        checkAndAddNew(block, parent, immediateBlockHier);
   2.528 +                    }
   2.529 +                } else if (image.equalsIgnoreCase("COMMENT")) {
   2.530 +                    int offset = ts.offset();
   2.531 +                    PlsqlBlock block = checkTblColComment(tempToken, ts, immediateBlockHier);
   2.532 +                    if (block == null) {
   2.533 +                        //pass from the immediate next token to get inner blocks
   2.534 +                        ts.move(offset);
   2.535 +                        ts.moveNext();
   2.536 +                    } else {
   2.537 +                        checkAndAddNew(block, parent, immediateBlockHier);
   2.538 +                    }
   2.539 +                } else if (image.equalsIgnoreCase("DECLARE")) {
   2.540 +                    PlsqlBlock block = checkDeclareBlock(tempToken, ts, immediateBlockHier);
   2.541 +                    if (block != null) {//If inner check seems to have failed need to continue this one
   2.542 +                        checkAndAddNew(block, parent, immediateBlockHier);
   2.543 +                    }
   2.544 +                } else if (image.equalsIgnoreCase("BEGIN")) {
   2.545 +                    if (!isDeclare(ts, immediateBlockHier)) {//We need to check whether the declare is isolated by a CURSOR block
   2.546 +
   2.547                          int offset = ts.offset();
   2.548 -                        PlsqlBlock block = null;
   2.549 -                        block = checkView(tempToken, ts, immediateBlockHier);
   2.550 -                        if (block == null) {
   2.551 -                            //pass from the immediate next token to get inner blocks
   2.552 +                        PlsqlBlock block = checkBeginBlock(tempToken, ts, immediateBlockHier);
   2.553 +                        if (block == null) {//If inner check seems to have failed need to continue this one
   2.554 +
   2.555                              ts.move(offset);
   2.556                              ts.moveNext();
   2.557                          } else {
   2.558                              checkAndAddNew(block, parent, immediateBlockHier);
   2.559                          }
   2.560 -                    } else if (image.equalsIgnoreCase("FUNCTION")) {
   2.561 -                        int offset = ts.offset();
   2.562 -                        PlsqlBlock block = null;
   2.563 -                        block = checkMethod(tempToken, ts, PlsqlBlockType.FUNCTION_IMPL, immediateBlockHier);
   2.564 -                        if (block == null) {
   2.565 -                            //pass from the immediate next token to get inner blocks
   2.566 +                    }
   2.567 +                } else if (image.equalsIgnoreCase("IF")
   2.568 +                        || image.equalsIgnoreCase("ELSIF")) {
   2.569 +                    if (!isNotBlockStart(tempToken, ts)) {
   2.570 +                        int offset = tempToken.offset(tokenHierarchy);
   2.571 +                        List children = checkIfBlock(tempToken, ts, immediateBlockHier);
   2.572 +                        if (children == null || children.isEmpty()) {//If inner check seems to have failed need to continue this one
   2.573 +
   2.574                              ts.move(offset);
   2.575                              ts.moveNext();
   2.576                          } else {
   2.577 -                            checkAndAddNew(block, parent, immediateBlockHier);
   2.578 +                            for (int i = 0; i < children.size(); i++) {
   2.579 +                                PlsqlBlock child = (PlsqlBlock) children.get(i);
   2.580 +                                checkAndAddNew(child, parent, immediateBlockHier);
   2.581 +                            }
   2.582                          }
   2.583 -                    } else if (image.equalsIgnoreCase("PROCEDURE")) {
   2.584 -                        int offset = ts.offset();
   2.585 -                        PlsqlBlock block = null;
   2.586 -                        block = checkMethod(tempToken, ts, PlsqlBlockType.PROCEDURE_IMPL, immediateBlockHier);
   2.587 -                        if (block == null) {
   2.588 -                            //pass from the immediate next token to get inner blocks
   2.589 +                    }
   2.590 +                } else if (image.equalsIgnoreCase("ELSE")) {
   2.591 +                    if (!isNotBlockStart(tempToken, ts)) {
   2.592 +                        int offset = tempToken.offset(tokenHierarchy);
   2.593 +                        List children = checkIfBlock(tempToken, ts, immediateBlockHier);
   2.594 +                        if (children == null || children.isEmpty()) {
   2.595 +                            children = checkCaseBlock(tempToken, ts, immediateBlockHier, false);
   2.596 +                        }
   2.597 +
   2.598 +                        if (children == null || children.isEmpty()) {//If inner check seems to have failed need to continue this one
   2.599 +
   2.600                              ts.move(offset);
   2.601                              ts.moveNext();
   2.602                          } else {
   2.603 -                            checkAndAddNew(block, parent, immediateBlockHier);
   2.604 +                            for (int i = 0; i < children.size(); i++) {
   2.605 +                                PlsqlBlock child = (PlsqlBlock) children.get(i);
   2.606 +                                checkAndAddNew(child, parent, immediateBlockHier);
   2.607 +                            }
   2.608                          }
   2.609 -                    } else if (image.equalsIgnoreCase("PACKAGE")) {
   2.610 -                        int offset = ts.offset();
   2.611 -                        PlsqlBlock block = null;
   2.612 -                        block = checkPackage(tempToken, ts, immediateBlockHier);
   2.613 -                        if (block == null) {
   2.614 -                            //pass from the immediate next token to get inner blocks
   2.615 +                    }
   2.616 +                } else if (image.equalsIgnoreCase("CASE")
   2.617 +                        || image.equalsIgnoreCase("WHEN")) {
   2.618 +                    if (!isNotBlockStart(tempToken, ts)) {
   2.619 +                        int offset = tempToken.offset(tokenHierarchy);
   2.620 +                        List children = checkCaseBlock(tempToken, ts, immediateBlockHier, false);
   2.621 +                        if (children == null || children.isEmpty()) {//If inner check seems to have failed need to continue this one
   2.622 +
   2.623                              ts.move(offset);
   2.624                              ts.moveNext();
   2.625                          } else {
   2.626 -                            checkAndAddNew(block, parent, immediateBlockHier);
   2.627 -                        }
   2.628 -                    } else if (image.equalsIgnoreCase("CURSOR")) {
   2.629 -                        int offset = ts.offset();
   2.630 -                        PlsqlBlock block = null;
   2.631 -                        block = checkCursor(tempToken, ts, immediateBlockHier);
   2.632 -                        if (block == null) {
   2.633 -                            //pass from the immediate next token to get inner blocks
   2.634 -                            ts.move(offset);
   2.635 -                            ts.moveNext();
   2.636 -                        } else {
   2.637 -                            checkAndAddNew(block, parent, immediateBlockHier);
   2.638 -                        }
   2.639 -                    } else if (image.equalsIgnoreCase("TRIGGER")) {
   2.640 -                        int offset = ts.offset();
   2.641 -                        PlsqlBlock block = null;
   2.642 -                        block = checkTrigger(tempToken, ts, immediateBlockHier);
   2.643 -                        if (block == null) {
   2.644 -                            //pass from the immediate next token to get inner blocks
   2.645 -                            ts.move(offset);
   2.646 -                            ts.moveNext();
   2.647 -                        } else {
   2.648 -                            checkAndAddNew(block, parent, immediateBlockHier);
   2.649 -                        }
   2.650 -                    } else if (image.equalsIgnoreCase("COMMENT")) {
   2.651 -                        int offset = ts.offset();
   2.652 -                        PlsqlBlock block = null;
   2.653 -                        block = checkTblColComment(tempToken, ts, immediateBlockHier);
   2.654 -                        if (block == null) {
   2.655 -                            //pass from the immediate next token to get inner blocks
   2.656 -                            ts.move(offset);
   2.657 -                            ts.moveNext();
   2.658 -                        } else {
   2.659 -                            checkAndAddNew(block, parent, immediateBlockHier);
   2.660 -                        }
   2.661 -                    } else if (image.equalsIgnoreCase("DECLARE")) {
   2.662 -                        PlsqlBlock block = checkDeclareBlock(tempToken, ts, immediateBlockHier);
   2.663 -                        if (block != null) {//If inner check seems to have failed need to continue this one
   2.664 -                            checkAndAddNew(block, parent, immediateBlockHier);
   2.665 -                        }
   2.666 -                    } else if (image.equalsIgnoreCase("BEGIN")) {
   2.667 -                        if (!isDeclare(ts, immediateBlockHier)) {//We need to check whether the declare is isolated by a CURSOR block
   2.668 -
   2.669 -                            int offset = ts.offset();
   2.670 -                            PlsqlBlock block = checkBeginBlock(tempToken, ts, immediateBlockHier);
   2.671 -                            if (block == null) {//If inner check seems to have failed need to continue this one
   2.672 -
   2.673 -                                ts.move(offset);
   2.674 -                                ts.moveNext();
   2.675 -                            } else {
   2.676 -                                checkAndAddNew(block, parent, immediateBlockHier);
   2.677 +                            for (int i = 0; i < children.size(); i++) {
   2.678 +                                PlsqlBlock child = (PlsqlBlock) children.get(i);
   2.679 +                                checkAndAddNew(child, parent, immediateBlockHier);
   2.680                              }
   2.681                          }
   2.682 -                    } else if (image.equalsIgnoreCase("IF")
   2.683 -                            || image.equalsIgnoreCase("ELSIF")) {
   2.684 -                        if (!isNotBlockStart(tempToken, ts)) {
   2.685 -                            int offset = tempToken.offset(tokenHierarchy);
   2.686 -                            List children = checkIfBlock(tempToken, ts, immediateBlockHier);
   2.687 -                            if (children == null || children.isEmpty()) {//If inner check seems to have failed need to continue this one
   2.688 -
   2.689 -                                ts.move(offset);
   2.690 -                                ts.moveNext();
   2.691 -                            } else {
   2.692 -                                for (int i = 0; i < children.size(); i++) {
   2.693 -                                    PlsqlBlock child = (PlsqlBlock) children.get(i);
   2.694 -                                    checkAndAddNew(child, parent, immediateBlockHier);
   2.695 -                                }
   2.696 -                            }
   2.697 -                        }
   2.698 -                    } else if (image.equalsIgnoreCase("ELSE")) {
   2.699 -                        if (!isNotBlockStart(tempToken, ts)) {
   2.700 -                            int offset = tempToken.offset(tokenHierarchy);
   2.701 -                            List children = checkIfBlock(tempToken, ts, immediateBlockHier);
   2.702 -                            if (children == null || children.isEmpty()) {
   2.703 -                                children = checkCaseBlock(tempToken, ts, immediateBlockHier, false);
   2.704 -                            }
   2.705 -
   2.706 -                            if (children == null || children.isEmpty()) {//If inner check seems to have failed need to continue this one
   2.707 -
   2.708 -                                ts.move(offset);
   2.709 -                                ts.moveNext();
   2.710 -                            } else {
   2.711 -                                for (int i = 0; i < children.size(); i++) {
   2.712 -                                    PlsqlBlock child = (PlsqlBlock) children.get(i);
   2.713 -                                    checkAndAddNew(child, parent, immediateBlockHier);
   2.714 -                                }
   2.715 -                            }
   2.716 -                        }
   2.717 -                    } else if (image.equalsIgnoreCase("CASE")
   2.718 -                            || image.equalsIgnoreCase("WHEN")) {
   2.719 -                        if (!isNotBlockStart(tempToken, ts)) {
   2.720 -                            int offset = tempToken.offset(tokenHierarchy);
   2.721 -                            List children = checkCaseBlock(tempToken, ts, immediateBlockHier, false);
   2.722 -                            if (children == null || children.isEmpty()) {//If inner check seems to have failed need to continue this one
   2.723 -
   2.724 -                                ts.move(offset);
   2.725 -                                ts.moveNext();
   2.726 -                            } else {
   2.727 -                                for (int i = 0; i < children.size(); i++) {
   2.728 -                                    PlsqlBlock child = (PlsqlBlock) children.get(i);
   2.729 -                                    checkAndAddNew(child, parent, immediateBlockHier);
   2.730 -                                }
   2.731 -                            }
   2.732 -                        }
   2.733 -                    } else if (image.equalsIgnoreCase("LOOP")
   2.734 -                            || image.equalsIgnoreCase("WHILE")
   2.735 -                            || image.equalsIgnoreCase("FOR")) {
   2.736 -                        if (!isNotBlockStart(tempToken, ts)) {
   2.737 -                            int offset = tempToken.offset(tokenHierarchy);
   2.738 -                            if (!unsuccessBlocks.contains(offset)) {
   2.739 -                                PlsqlBlock child = checkLoopBlock(tempToken, ts, immediateBlockHier);
   2.740 -                                if (child == null) {//If inner check seems to have failed need to continue this one
   2.741 -                                    unsuccessBlocks.add(offset);
   2.742 -                                    ts.move(offset);
   2.743 -                                    ts.moveNext();
   2.744 -                                } else {
   2.745 -                                    checkAndAddNew(child, parent, immediateBlockHier);
   2.746 -                                }
   2.747 -                            }
   2.748 -                        }
   2.749 -                    } else if (image.equalsIgnoreCase("TABLE")
   2.750 -                            || image.equalsIgnoreCase("INDEX")
   2.751 -                            || image.equalsIgnoreCase("SELECT")
   2.752 -                            || image.equalsIgnoreCase("UPDATE")
   2.753 -                            || image.equalsIgnoreCase("DELETE")
   2.754 -                            || image.equalsIgnoreCase("INSERT")
   2.755 -                            || image.equalsIgnoreCase("MERGE")
   2.756 -                            || image.equalsIgnoreCase("DROP")
   2.757 -                            || image.equalsIgnoreCase("SEQUENCE")) {
   2.758 -                        if (!isNotBlockStart(tempToken, ts)) {
   2.759 -                            int offset = tempToken.offset(tokenHierarchy);
   2.760 -                            PlsqlBlock child = checkStatementBlock(tempToken, ts, immediateBlockHier);
   2.761 +                    }
   2.762 +                } else if (image.equalsIgnoreCase("LOOP")
   2.763 +                        || image.equalsIgnoreCase("WHILE")
   2.764 +                        || image.equalsIgnoreCase("FOR")) {
   2.765 +                    if (!isNotBlockStart(tempToken, ts)) {
   2.766 +                        int offset = tempToken.offset(tokenHierarchy);
   2.767 +                        if (!unsuccessBlocks.contains(offset)) {
   2.768 +                            PlsqlBlock child = checkLoopBlock(tempToken, ts, immediateBlockHier);
   2.769                              if (child == null) {//If inner check seems to have failed need to continue this one
   2.770 -
   2.771 +                                unsuccessBlocks.add(offset);
   2.772                                  ts.move(offset);
   2.773                                  ts.moveNext();
   2.774                              } else {
   2.775 @@ -2140,78 +2156,100 @@
   2.776                              }
   2.777                          }
   2.778                      }
   2.779 -                } else if (tokenID == PlsqlTokenId.JAVA_SOUCE) {
   2.780 -                    int offset = ts.offset();
   2.781 -                    PlsqlBlock block = null;
   2.782 -                    block = checkJavaSource(tempToken, ts);
   2.783 -                    if (block == null) {
   2.784 -                        //pass from the immediate next token to get inner blocks
   2.785 -                        ts.move(offset);
   2.786 -                        ts.moveNext();
   2.787 -                    } else {
   2.788 -                        checkAndAddNew(block, parent, immediateBlockHier);
   2.789 -                    }
   2.790 -                } else if (tokenID == PlsqlTokenId.LINE_COMMENT) {
   2.791 -                    //only single comment line
   2.792 -                    if (image.toUpperCase(Locale.ENGLISH).contains("<FOLD>")) {
   2.793 -                        customStartToken = tempToken;
   2.794 -                    } else if (image.toUpperCase(Locale.ENGLISH).contains("<END-FOLD>")) {
   2.795 -                        if (customStartToken != null) {
   2.796 -                            String name = customStartToken.text().toString();
   2.797 -                            int index = name.toUpperCase(Locale.ENGLISH).indexOf("<FOLD>");
   2.798 -                            name = name.substring(index + 7).trim();
   2.799 -                            if (ts.moveNext()) {
   2.800 -                                tempToken = ts.token();
   2.801 -                                PlsqlBlock custom = new PlsqlBlock(customStartToken.offset(tokenHierarchy),
   2.802 -                                        tempToken.offset(tokenHierarchy), name, "", PlsqlBlockType.CUSTOM_FOLD);
   2.803 -                                customFoldBlocks.add(custom);
   2.804 -                            }
   2.805 -                            customStartToken = null;
   2.806 +                } else if (image.equalsIgnoreCase("TABLE")
   2.807 +                        || image.equalsIgnoreCase("INDEX")
   2.808 +                        || image.equalsIgnoreCase("SELECT")
   2.809 +                        || image.equalsIgnoreCase("UPDATE")
   2.810 +                        || image.equalsIgnoreCase("DELETE")
   2.811 +                        || image.equalsIgnoreCase("INSERT")
   2.812 +                        || image.equalsIgnoreCase("MERGE")
   2.813 +                        || image.equalsIgnoreCase("DROP")
   2.814 +                        || image.equalsIgnoreCase("SEQUENCE")) {
   2.815 +                    if (!isNotBlockStart(tempToken, ts)) {
   2.816 +                        int offset = tempToken.offset(tokenHierarchy);
   2.817 +                        PlsqlBlock child = checkStatementBlock(tempToken, ts, immediateBlockHier);
   2.818 +                        if (child == null) {//If inner check seems to have failed need to continue this one
   2.819 +
   2.820 +                            ts.move(offset);
   2.821 +                            ts.moveNext();
   2.822                          } else {
   2.823 -                            customEndToken = tempToken;
   2.824 -                        }
   2.825 -                    } else {
   2.826 -                        PlsqlBlock block = checkComment(tempToken, ts);
   2.827 -                        if (block != null) {
   2.828 -                            checkAndAddNew(block, parent, immediateBlockHier);
   2.829 +                            checkAndAddNew(child, parent, immediateBlockHier);
   2.830                          }
   2.831                      }
   2.832 -                } else if (tokenID == PlsqlTokenId.BLOCK_COMMENT) {
   2.833 -                    int start = tempToken.offset(tokenHierarchy);
   2.834 -                    PlsqlBlock block = new PlsqlBlock(start,
   2.835 -                            start + tempToken.length(), "BLOCK COMMENT", "", PlsqlBlockType.COMMENT);
   2.836 +                }
   2.837 +            } else if (tokenID == PlsqlTokenId.JAVA_SOUCE) {
   2.838 +                int offset = ts.offset();
   2.839 +                PlsqlBlock block = null;
   2.840 +                block = checkJavaSource(tempToken, ts);
   2.841 +                if (block == null) {
   2.842 +                    //pass from the immediate next token to get inner blocks
   2.843 +                    ts.move(offset);
   2.844 +                    ts.moveNext();
   2.845 +                } else {
   2.846 +                    checkAndAddNew(block, parent, immediateBlockHier);
   2.847 +                }
   2.848 +            } else if (tokenID == PlsqlTokenId.LINE_COMMENT) {
   2.849 +                //only single comment line
   2.850 +                if (image.toUpperCase(Locale.ENGLISH).contains("<FOLD>")) {
   2.851 +                    customStartToken = tempToken;
   2.852 +                } else if (image.toUpperCase(Locale.ENGLISH).contains("<END-FOLD>")) {
   2.853 +                    if (customStartToken != null) {
   2.854 +                        String name = customStartToken.text().toString();
   2.855 +                        int index = name.toUpperCase(Locale.ENGLISH).indexOf("<FOLD>");
   2.856 +                        name = name.substring(index + 7).trim();
   2.857 +                        if (ts.moveNext()) {
   2.858 +                            tempToken = ts.token();
   2.859 +                            PlsqlBlock custom = new PlsqlBlock(customStartToken.offset(tokenHierarchy),
   2.860 +                                    tempToken.offset(tokenHierarchy), name, "", PlsqlBlockType.CUSTOM_FOLD);
   2.861 +                            customFoldBlocks.add(custom);
   2.862 +                        }
   2.863 +                        customStartToken = null;
   2.864 +                    } else {
   2.865 +                        customEndToken = tempToken;
   2.866 +                    }
   2.867 +                } else {
   2.868 +                    PlsqlBlock block = checkComment(tempToken, ts);
   2.869                      if (block != null) {
   2.870                          checkAndAddNew(block, parent, immediateBlockHier);
   2.871                      }
   2.872 -                } else if ((tokenID == PlsqlTokenId.OPERATOR) && (image.equals(";"))) {
   2.873 -                    PlsqlBlock block = checkEnd(tempToken, ts);
   2.874 -                    //check whether this is the parent can happen in a remove
   2.875 -                    if (block != null && (block.getType() != PlsqlBlockType.FUNCTION_IMPL && block.getType() != PlsqlBlockType.PROCEDURE_IMPL)) {
   2.876 -                        if (!isEqual(parent, block)) {
   2.877 -                            if ((block != null) && (checkExisting(block, immediateBlockHier) == false)) {
   2.878 -                                addImmediateChildren(block, immediateBlockHier);
   2.879 -                                immediateBlockHier.add(block);
   2.880 -                                newBlocks.add(block);
   2.881 -                                if (parent != null) {
   2.882 -                                    block.setParent(parent);
   2.883 -                                }
   2.884 +                }
   2.885 +            } else if (tokenID == PlsqlTokenId.BLOCK_COMMENT) {
   2.886 +                int start = tempToken.offset(tokenHierarchy);
   2.887 +                PlsqlBlock block = new PlsqlBlock(start,
   2.888 +                        start + tempToken.length(), "BLOCK COMMENT", "", PlsqlBlockType.COMMENT);
   2.889 +                if (block != null) {
   2.890 +                    checkAndAddNew(block, parent, immediateBlockHier);
   2.891 +                }
   2.892 +            } else if ((tokenID == PlsqlTokenId.OPERATOR) && (image.equals(";"))) {
   2.893 +                PlsqlBlock block = checkEnd(tempToken, ts);
   2.894 +                //check whether this is the parent can happen in a remove
   2.895 +                if (block != null && (block.getType() != PlsqlBlockType.FUNCTION_IMPL && block.getType() != PlsqlBlockType.PROCEDURE_IMPL)) {
   2.896 +                    if (!isEqual(parent, block)) {
   2.897 +                        if ((block != null) && (checkExisting(block, immediateBlockHier) == false)) {
   2.898 +                            addImmediateChildren(block, immediateBlockHier);
   2.899 +                            immediateBlockHier.add(block);
   2.900 +                            newBlocks.add(block);
   2.901 +                            if (parent != null) {
   2.902 +                                block.setParent(parent);
   2.903                              }
   2.904                          }
   2.905                      }
   2.906                  }
   2.907 -            }   //we have come to the end now, check whether we have unmatched custom tokens
   2.908 -
   2.909 -            if (customEndToken != null) {
   2.910 -                checkCustom(customEndToken, ts, immediateBlockHier, parent, "END");
   2.911 -            } else if (customStartToken != null) {
   2.912 -                checkCustom(customStartToken, ts, immediateBlockHier, parent, "START");
   2.913              }
   2.914 +        }   //we have come to the end now, check whether we have unmatched custom tokens
   2.915 +
   2.916 +        if (customEndToken != null) {
   2.917 +            checkCustom(customEndToken, ts, immediateBlockHier, parent, "END");
   2.918 +        } else if (customStartToken != null) {
   2.919 +            checkCustom(customStartToken, ts, immediateBlockHier, parent, "START");
   2.920          }
   2.921      }
   2.922  
   2.923      private void checkAndAddNew(PlsqlBlock block, PlsqlBlock parent, List<PlsqlBlock> immediateBlockHier) {
   2.924 +            LOG.log(Level.FINE, "checkAndAddNew, block.getName()={0}, block.getType()={1}", new Object[]{block.getName(), block.getType()});
   2.925          if (checkExisting(block, immediateBlockHier) == false && !isEqual(parent, block)) {
   2.926              immediateBlockHier.add(block);
   2.927 +            LOG.log(Level.FINE, "newBlocks.add({0})", new Object[]{block.getName(), block.getType()});
   2.928              newBlocks.add(block);
   2.929              if (parent != null) {
   2.930                  block.setParent(parent);
   2.931 @@ -2221,6 +2259,7 @@
   2.932  
   2.933      /**
   2.934       * Check whether current ';' is the end of a function/procedure/view/package
   2.935 +     *
   2.936       * @param tempToken
   2.937       * @param ts
   2.938       */
   2.939 @@ -2335,6 +2374,7 @@
   2.940  
   2.941      /**
   2.942       * Check whether there is a function/procedure in this block
   2.943 +     *
   2.944       * @param ts
   2.945       * @param methodName
   2.946       * @return
   2.947 @@ -2382,8 +2422,8 @@
   2.948      }
   2.949  
   2.950      /**
   2.951 -     * Check whether there is a function/procedure in this block
   2.952 -     * Method name is not there in the 'END;'
   2.953 +     * Check whether there is a function/procedure in this block Method name is not there in the 'END;'
   2.954 +     *
   2.955       * @param ts
   2.956       * @return
   2.957       */
   2.958 @@ -2436,11 +2476,13 @@
   2.959  
   2.960      /**
   2.961       * Check whether this is a block comment, single line or multi lined comment
   2.962 +     *
   2.963       * @param current
   2.964       * @param ts
   2.965       * @return
   2.966       */
   2.967      private PlsqlBlock checkComment(Token<PlsqlTokenId> current, TokenSequence<PlsqlTokenId> ts) {
   2.968 +        LOG.log(Level.FINE, "checkComment, ts.index()={0} current={1} ", new Object[]{ts.index(), current});
   2.969          //If the line don't start with the comment ignore
   2.970          String prefix = getPreceedingText(current.offset(tokenHierarchy), ts);
   2.971          if (!prefix.trim().equals("")) {
   2.972 @@ -2448,13 +2490,10 @@
   2.973          }
   2.974  
   2.975          Token<PlsqlTokenId> commentBegin = current;
   2.976 -        Token<PlsqlTokenId> tmp = current;
   2.977          Token<PlsqlTokenId> commentEnd = current;
   2.978 -        PlsqlBlock block = null;
   2.979          String text = commentBegin.text().toString();
   2.980 -        int offset = ts.offset();
   2.981 -        boolean moveNext = getNextNonWhitespace(ts, false);
   2.982 -        tmp = ts.token();
   2.983 +        boolean moveNext = getNextNonWhitespaceForComments(ts);
   2.984 +        Token<PlsqlTokenId> tmp = ts.token();
   2.985          boolean takeDesc = true;
   2.986          String desc = getCommentDescription(text);
   2.987          if (!desc.equals("COMMENT...")) {
   2.988 @@ -2476,26 +2515,24 @@
   2.989                          takeDesc = false;
   2.990                      }
   2.991                  }
   2.992 -                moveNext = getNextNonWhitespace(ts, false);
   2.993 +                moveNext = getNextNonWhitespaceForComments(ts);
   2.994                  tmp = ts.token();
   2.995              }
   2.996          }
   2.997  
   2.998 -        offset = commentEnd.offset(tokenHierarchy);
   2.999 -        ts.move(offset);
  2.1000 +        ts.move(commentEnd.offset(tokenHierarchy));
  2.1001          ts.moveNext();
  2.1002  
  2.1003          //Calculate end offset
  2.1004          int endOffset = commentEnd.offset(tokenHierarchy) + commentEnd.length();
  2.1005  
  2.1006 -        block = new PlsqlBlock(commentBegin.offset(tokenHierarchy),
  2.1007 +        return new PlsqlBlock(commentBegin.offset(tokenHierarchy),
  2.1008                  endOffset, desc, "", PlsqlBlockType.COMMENT);
  2.1009 -
  2.1010 -        return block;
  2.1011      }
  2.1012  
  2.1013      /**
  2.1014       * Method that will give the description of the comment fold
  2.1015 +     *
  2.1016       * @param text
  2.1017       * @return
  2.1018       */
  2.1019 @@ -2537,6 +2574,7 @@
  2.1020  
  2.1021      /**
  2.1022       * Check whether this is the start of a PROCEDURE/FUNCTION block
  2.1023 +     *
  2.1024       * @param methodToken
  2.1025       * @param ts
  2.1026       * @param type
  2.1027 @@ -2869,6 +2907,7 @@
  2.1028  
  2.1029      /**
  2.1030       * Check whether this is the start of a PACKAGE block
  2.1031 +     *
  2.1032       * @param tempToken
  2.1033       * @param ts
  2.1034       * @return
  2.1035 @@ -3095,6 +3134,7 @@
  2.1036  
  2.1037      /**
  2.1038       * Method that will check declare end blocks
  2.1039 +     *
  2.1040       * @param current
  2.1041       * @param ts
  2.1042       * @param parentBlocks
  2.1043 @@ -3360,6 +3400,7 @@
  2.1044  
  2.1045      /**
  2.1046       * Method that will check begin end blocks
  2.1047 +     *
  2.1048       * @param current
  2.1049       * @param ts
  2.1050       * @param parentBlocks
  2.1051 @@ -3583,6 +3624,7 @@
  2.1052  
  2.1053      /**
  2.1054       * Method to check table & column comments
  2.1055 +     *
  2.1056       * @param current
  2.1057       * @param ts
  2.1058       * @param parentBlocks
  2.1059 @@ -3791,6 +3833,7 @@
  2.1060  
  2.1061      /**
  2.1062       * Get Return next non whitespace token
  2.1063 +     *
  2.1064       * @param ts
  2.1065       * @param ignoreComment: if true will ignore comments also
  2.1066       * @return
  2.1067 @@ -3819,7 +3862,29 @@
  2.1068      }
  2.1069  
  2.1070      /**
  2.1071 +     * Get Return next non whitespace token
  2.1072 +     *
  2.1073 +     * @param ts
  2.1074 +     * @return
  2.1075 +     */
  2.1076 +    private boolean getNextNonWhitespaceForComments(TokenSequence<PlsqlTokenId> ts) {
  2.1077 +        boolean moveNext = ts.moveNext();
  2.1078 +        Token<PlsqlTokenId> tmp = ts.token();
  2.1079 +        LOG.log(Level.FINE, "getNextNonWhitespaceForComments, tmp.id()={0}, tmp.text()={1}", new Object[]{tmp.id(), tmp.text().toString()});
  2.1080 +        while (moveNext) {
  2.1081 +            if (tmp.id() == PlsqlTokenId.WHITESPACE && "\n".equals(tmp.text())) {
  2.1082 +                moveNext = ts.moveNext();
  2.1083 +                tmp = ts.token();
  2.1084 +            } else {
  2.1085 +                break;
  2.1086 +            }
  2.1087 +        }
  2.1088 +        return moveNext;
  2.1089 +    }
  2.1090 +
  2.1091 +    /**
  2.1092       * Return previous non whitespace token
  2.1093 +     *
  2.1094       * @param ts
  2.1095       * @param ignoreComment
  2.1096       * @return
  2.1097 @@ -3847,6 +3912,7 @@
  2.1098  
  2.1099      /**
  2.1100       * Check whether this is the start of a VIEW block
  2.1101 +     *
  2.1102       * @param viewToken
  2.1103       * @param ts
  2.1104       * @param parentBlocks
  2.1105 @@ -4005,6 +4071,7 @@
  2.1106  
  2.1107      /**
  2.1108       * Get the name defined by &Name
  2.1109 +     *
  2.1110       * @param inputName
  2.1111       * @return
  2.1112       */
  2.1113 @@ -4024,6 +4091,7 @@
  2.1114  
  2.1115      /**
  2.1116       * Check &Name is in map as a key
  2.1117 +     *
  2.1118       * @param inputName
  2.1119       * @return
  2.1120       */
  2.1121 @@ -4039,6 +4107,7 @@
  2.1122  
  2.1123      /**
  2.1124       * Check &Name is in map as a value
  2.1125 +     *
  2.1126       * @param inputName
  2.1127       * @return
  2.1128       */
  2.1129 @@ -4049,6 +4118,7 @@
  2.1130  
  2.1131      /**
  2.1132       * Get the key of &Name
  2.1133 +     *
  2.1134       * @param inputName
  2.1135       * @return
  2.1136       */
  2.1137 @@ -4067,6 +4137,7 @@
  2.1138  
  2.1139      /**
  2.1140       * Method that will parse the document and initialize the aliases
  2.1141 +     *
  2.1142       * @param doc
  2.1143       */
  2.1144      private void getAliases(Document doc) {
  2.1145 @@ -4136,6 +4207,7 @@
  2.1146  
  2.1147      /**
  2.1148       * Replace exStr in the given text with newStr
  2.1149 +     *
  2.1150       * @param plsqlString
  2.1151       * @param exStr
  2.1152       * @param newStr
  2.1153 @@ -4152,6 +4224,7 @@
  2.1154  
  2.1155      /**
  2.1156       * Check whether the given offsets are in the same line
  2.1157 +     *
  2.1158       * @param doc
  2.1159       * @param offset1
  2.1160       * @param offset2
  2.1161 @@ -4219,6 +4292,7 @@
  2.1162  
  2.1163      /**
  2.1164       * Method that will check if blocks
  2.1165 +     *
  2.1166       * @param current
  2.1167       * @param ts
  2.1168       * @param parentBlocks
  2.1169 @@ -4451,6 +4525,7 @@
  2.1170  
  2.1171      /**
  2.1172       * Method that will check case blocks
  2.1173 +     *
  2.1174       * @param current
  2.1175       * @param ts
  2.1176       * @param parentBlocks
  2.1177 @@ -4645,9 +4720,6 @@
  2.1178                      customStartToken = token;
  2.1179                  } else if (image.toUpperCase(Locale.ENGLISH).contains("<END-FOLD>")) {
  2.1180                      if (customStartToken != null) {
  2.1181 -                        String fname = customStartToken.text().toString();
  2.1182 -                        int index = fname.toUpperCase(Locale.ENGLISH).indexOf("<FOLD>");
  2.1183 -                        fname = fname.substring(index + 7).trim();
  2.1184                          if (ts.moveNext()) {
  2.1185                              token = ts.token();
  2.1186                              PlsqlBlock custom = new PlsqlBlock(customStartToken.offset(tokenHierarchy),
  2.1187 @@ -4668,10 +4740,8 @@
  2.1188                  int start = token.offset(tokenHierarchy);
  2.1189                  PlsqlBlock child = new PlsqlBlock(start,
  2.1190                          start + token.length(), "BLOCK COMMENT", "", PlsqlBlockType.COMMENT);
  2.1191 -                if (child != null) {
  2.1192 -                    if (checkExisting(child, lstChild) == false) {
  2.1193 -                        lstChild.add(child);
  2.1194 -                    }
  2.1195 +                if (checkExisting(child, lstChild) == false) {
  2.1196 +                    lstChild.add(child);
  2.1197                  }
  2.1198              } else if (!isThen) {
  2.1199                  name = name + image;
  2.1200 @@ -4687,6 +4757,7 @@
  2.1201  
  2.1202      /**
  2.1203       * Method that will return the prefix of the given block
  2.1204 +     *
  2.1205       * @param startOffset
  2.1206       * @param ts
  2.1207       * @return
  2.1208 @@ -4716,6 +4787,7 @@
  2.1209  
  2.1210      /**
  2.1211       * Method that will check loop blocks
  2.1212 +     *
  2.1213       * @param current
  2.1214       * @param ts
  2.1215       * @param parentBlocks
  2.1216 @@ -4854,9 +4926,6 @@
  2.1217                      customStartToken = token;
  2.1218                  } else if (image.toUpperCase(Locale.ENGLISH).contains("<END-FOLD>")) {
  2.1219                      if (customStartToken != null) {
  2.1220 -                        String fname = customStartToken.text().toString();
  2.1221 -                        int index = fname.toUpperCase(Locale.ENGLISH).indexOf("<FOLD>");
  2.1222 -                        fname = fname.substring(index + 7).trim();
  2.1223                          if (ts.moveNext()) {
  2.1224                              token = ts.token();
  2.1225                              PlsqlBlock custom = new PlsqlBlock(customStartToken.offset(tokenHierarchy),
  2.1226 @@ -4900,8 +4969,8 @@
  2.1227      }
  2.1228  
  2.1229      /**
  2.1230 -     * Method that will add the given child blocks to the block and
  2.1231 -     * remove from parent blocks if existing there
  2.1232 +     * Method that will add the given child blocks to the block and remove from parent blocks if existing there
  2.1233 +     *
  2.1234       * @param block
  2.1235       * @param lstChild
  2.1236       * @param parentBlocks