[hg] main-silver: #235720: more and more logging and sanity checks

  • From: Svata Dedic < >
  • To:
  • Subject: [hg] main-silver: #235720: more and more logging and sanity checks
  • Date: Sat, 14 Sep 2013 09:48:56 -0700

changeset 2f943192023c in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/2f943192023c
description:
        #235720: more and more logging and sanity checks

diffstat:

 editor.fold/src/org/netbeans/modules/editor/fold/FoldChildren.java           
      |  44 ++++++++++
 
editor.fold/src/org/netbeans/modules/editor/fold/FoldHierarchyTransactionImpl.java
 |   2 +-
 editor.fold/src/org/netbeans/modules/editor/fold/FoldOperationImpl.java      
      |  21 ++++
 3 files changed, 66 insertions(+), 1 deletions(-)

diffs (125 lines):

diff --git 
a/editor.fold/src/org/netbeans/modules/editor/fold/FoldChildren.java 
b/editor.fold/src/org/netbeans/modules/editor/fold/FoldChildren.java
--- a/editor.fold/src/org/netbeans/modules/editor/fold/FoldChildren.java
+++ b/editor.fold/src/org/netbeans/modules/editor/fold/FoldChildren.java
@@ -44,6 +44,9 @@
 
 package org.netbeans.modules.editor.fold;
 
+import java.util.Arrays;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 import org.netbeans.api.editor.fold.Fold;
 import org.netbeans.modules.editor.fold.ApiPackageAccessor;
 import org.netbeans.lib.editor.util.GapList;
@@ -59,6 +62,7 @@
  */
 
 public final class FoldChildren extends GapList {
+    private static final Logger LOG = 
Logger.getLogger(FoldChildren.class.getName()); 
 
     /**
      * Initial size of the index gap.
@@ -170,6 +174,20 @@
      * @param fold fold that will own the newly created fold children.
      */
     public FoldChildren extractToChildren(int index, int length, Fold fold) {
+        // sanity check:
+        int ps = parent.getStartOffset();
+        int pe = parent.getEndOffset();
+        int fs = fold.getStartOffset();
+        int fe = fold.getEndOffset();
+        
+        if (fs < ps || fe > pe) {
+            LOG.log(Level.WARNING, "Illegal attempt to change hierarchy. 
Parent fold: {0}, fold to be inserted: {1}, extract from {2}, len {3}", new 
Object[] {
+                parent, fold, index, length
+            });
+            LOG.log(Level.WARNING, "Dumping hierarchy: " + 
parent.getHierarchy(), new Throwable());
+        }
+        
+        
         FoldChildren foldChildren = new FoldChildren(fold);
         if (length == 1) {
             Fold insertFold = getFold(index);
@@ -217,6 +235,17 @@
     }
 
     private void insertImpl(int index, Fold fold) {
+        int ps = parent.getStartOffset();
+        int pe = parent.getEndOffset();
+        int fs = fold.getStartOffset();
+        int fe = fold.getEndOffset();
+        if (fs < ps || fe > pe) {
+            LOG.log(Level.WARNING, "Illegal attempt to insert fold. Parent 
fold: {0}, fold to be inserted: {1}, " +
+                    "at index {2}", new Object[] {
+                parent, fold, index
+            });
+            LOG.log(Level.WARNING, "Dumping hierarchy: " + 
parent.getHierarchy(), new Throwable());
+        }
         indexGapLength--;
         indexGapIndex++;
         ApiPackageAccessor api = ApiPackageAccessor.get();
@@ -226,6 +255,21 @@
     }
     
     private void insertImpl(int index, Fold[] folds) {
+        // sanity check
+        if (folds.length > 0) {
+            int ps = parent.getStartOffset();
+            int pe = parent.getEndOffset();
+            int fs = folds[0].getStartOffset();
+            int fe = folds[folds.length - 1].getEndOffset();
+            if (fs < ps || fe > pe) {
+                LOG.log(Level.WARNING, "Illegal attempt to insert fold. 
Parent fold: {0}, folds to be inserted: {1}, " +
+                        "at index {2}", new Object[] {
+                    parent, Arrays.asList(folds), index
+                });
+                LOG.log(Level.WARNING, "Dumping hierarchy: " + 
parent.getHierarchy(), new Throwable());
+            }
+        }
+
         ApiPackageAccessor api = ApiPackageAccessor.get();
         int foldsLength = folds.length;
         indexGapLength -= foldsLength;
diff --git 
a/editor.fold/src/org/netbeans/modules/editor/fold/FoldHierarchyTransactionImpl.java
 
b/editor.fold/src/org/netbeans/modules/editor/fold/FoldHierarchyTransactionImpl.java
--- 
a/editor.fold/src/org/netbeans/modules/editor/fold/FoldHierarchyTransactionImpl.java
+++ 
b/editor.fold/src/org/netbeans/modules/editor/fold/FoldHierarchyTransactionImpl.java
@@ -864,7 +864,7 @@
                     Fold realPrev = ix > 0 ? realPF.getFold(ix - 1) : null;
                     Fold realNext = ix < realPF.getFoldCount() - 1 ? 
realPF.getFold(ix + 1) : null;
                     if ((realPrev != null && realPrev.getEndOffset() > 
fold.getStartOffset()) ||
-                        (realNext != null && realNext.getStartOffset() < 
fold.getStartOffset())) {
+                        (realNext != null && realNext.getStartOffset() < 
fold.getEndOffset())) {
                         LOG.warning("Invalid next/prev offsets: fold = " + 
fold + ", prev = " + realPrev + ", next = " + realNext);
                         LOG.warning("debug info: " + sbDebug.toString());
                     }
diff --git 
a/editor.fold/src/org/netbeans/modules/editor/fold/FoldOperationImpl.java 
b/editor.fold/src/org/netbeans/modules/editor/fold/FoldOperationImpl.java
--- a/editor.fold/src/org/netbeans/modules/editor/fold/FoldOperationImpl.java
+++ b/editor.fold/src/org/netbeans/modules/editor/fold/FoldOperationImpl.java
@@ -752,6 +752,27 @@
             if (desc == null) {
                 desc = info.getTemplate().getDescription();
             }
+            // sanity check
+            Fold p = f.getParent();
+            if (p != null) {
+                int index = p.getFoldIndex(f);
+                if (index != -1) {
+                    if (index > 0) {
+                        Fold prev = p.getFold(index - 1);
+                        if (prev.getEndOffset() > f.getStartOffset()) {
+                            LOG.warning("Wrong fold nesting after update, 
hierarchy: " + execution);
+                            LOG.warning("FoldInfo: " + info + ", fold: " + f 
+ " origStart-End" + soffs + "-" + eoffs);
+                        }
+                    }
+                    if (index < p.getFoldCount() - 1) {
+                        Fold next = p.getFold(index + 1);
+                        if (next.getStartOffset() < f.getEndOffset()) {
+                            LOG.warning("Wrong fold nesting after update, 
hierarchy: " + execution);
+                            LOG.warning("FoldInfo: " + info + ", fold: " + f 
+ " origStart-End" + soffs + "-" + eoffs);
+                        }
+                    }
+                }
+            }
             if (!f.getDescription().equals(desc)) {
                 acc.foldSetDescription(f, desc);
                 acc.foldStateChangeDescriptionChanged(getFSCH(f));

[hg] main-silver: #235720: more and more logging and sanity checks

Svata Dedic 09/14/2013

Project Features

About this Project

Editor was started in November 2009, is owned by Martin Ryzl, and has 147 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close