EADS-3671 - Comment line folding have problems in PL/SQL
authorchrislovsund@netbeans.org
Thu, 02 May 2013 17:20:19 +0200
changeset 390305b6f0a2e87
parent 389 d3b44ff8d4dc
child 391 e19b67ac4799
EADS-3671 - Comment line folding have problems in PL/SQL
only add "--" on next row when located in header comment block
PLSQL/Formatter/src/org/netbeans/modules/plsql/format/PlsqlTypedBreakInterceptor.java
     1.1 --- a/PLSQL/Formatter/src/org/netbeans/modules/plsql/format/PlsqlTypedBreakInterceptor.java	Thu May 02 15:45:24 2013 +0200
     1.2 +++ b/PLSQL/Formatter/src/org/netbeans/modules/plsql/format/PlsqlTypedBreakInterceptor.java	Thu May 02 17:20:19 2013 +0200
     1.3 @@ -31,11 +31,10 @@
     1.4           return;
     1.5        }
     1.6        BaseDocument doc = (BaseDocument) context.getDocument();
     1.7 -
     1.8        int insertPos = context.getCaretOffset();
     1.9        int lineStartPos = Utilities.getRowStart(doc, insertPos);
    1.10        String word = Utilities.getWord(doc, lineStartPos);
    1.11 -      if (word.equals("--")) {
    1.12 +      if (word.equals("--") && isHeaderComment(doc, insertPos)) {
    1.13           context.setText("\n--  ", 0, 5);
    1.14        } else if (word.equals("--------------------")) {
    1.15           context.setText("\n-------------------- ", 0, 22);
    1.16 @@ -52,6 +51,17 @@
    1.17        LOG.log(Level.FINER, "cancelled, context: {0}", context);
    1.18     }
    1.19  
    1.20 +   private boolean isHeaderComment(BaseDocument doc, int insertPos) throws BadLocationException {
    1.21 +      for (int i = 0; i < Utilities.getLineOffset(doc, insertPos); i++) {
    1.22 +         int rowStartFromLineOffset = Utilities.getRowStartFromLineOffset(doc, i);
    1.23 +         String word = Utilities.getWord(doc, rowStartFromLineOffset);
    1.24 +         if (!word.startsWith("--")) {
    1.25 +            return false;
    1.26 +         }
    1.27 +      }
    1.28 +      return true;
    1.29 +   }
    1.30 +
    1.31     @MimeRegistration(mimeType = PlsqlDataLoader.REQUIRED_MIME, service = TypedBreakInterceptor.Factory.class)
    1.32     public static class PlsqlFactory implements TypedBreakInterceptor.Factory {
    1.33