EADS-3506 java.lang.IllegalStateException The manager has been already released SEVERE
authorchrislovsund@netbeans.org
Mon, 11 Mar 2013 23:04:52 +0100
changeset 356e96211b127ae
parent 355 a540b65e3395
child 357 f09db8d26a8b
EADS-3506 java.lang.IllegalStateException The manager has been already released SEVERE
cleanup of code
Still getting: "Adding a fold that is identical with another previously added fold from the same FoldManager is not allowed." even though just adding new blocks, leaving XXX: comments for possible fix later
PLSQL/Folding/src/org/netbeans/modules/plsql/fold/NewPlsqlFoldManager.java
PLSQL/Folding/src/org/netbeans/modules/plsql/fold/PlsqlFoldManagerFactory.java
     1.1 --- a/PLSQL/Folding/src/org/netbeans/modules/plsql/fold/NewPlsqlFoldManager.java	Mon Mar 11 15:26:32 2013 +0100
     1.2 +++ b/PLSQL/Folding/src/org/netbeans/modules/plsql/fold/NewPlsqlFoldManager.java	Mon Mar 11 23:04:52 2013 +0100
     1.3 @@ -42,8 +42,6 @@
     1.4  package org.netbeans.modules.plsql.fold;
     1.5  
     1.6  import java.util.ArrayList;
     1.7 -import java.util.Collections;
     1.8 -import java.util.Comparator;
     1.9  import java.util.HashMap;
    1.10  import java.util.List;
    1.11  import java.util.Map;
    1.12 @@ -51,7 +49,6 @@
    1.13  import java.util.Observer;
    1.14  import java.util.logging.Level;
    1.15  import java.util.logging.Logger;
    1.16 -import java.util.regex.Pattern;
    1.17  import javax.swing.event.DocumentEvent;
    1.18  import javax.swing.text.BadLocationException;
    1.19  import javax.swing.text.Document;
    1.20 @@ -77,19 +74,19 @@
    1.21  public class NewPlsqlFoldManager implements FoldManager, Runnable, Observer {
    1.22  
    1.23     private static final Logger LOG = Logger.getLogger(NewPlsqlFoldManager.class.getName());
    1.24 -//   public static final FoldType CUSTOM_FOLD_TYPE = new FoldType("custom-fold"); // NOI18N
    1.25     private FoldOperation operation;
    1.26     private Document doc;
    1.27 +   // XXX replace with Map to be able to test if mark already exist before adding new fold.
    1.28 +//   private Map<Integer, FoldMarkInfo> markArray = new HashMap<Integer, FoldMarkInfo>();
    1.29     private org.netbeans.editor.GapObjectArray markArray = new org.netbeans.editor.GapObjectArray();
    1.30     private int minUpdateMarkOffset = Integer.MAX_VALUE;
    1.31     private int maxUpdateMarkOffset = -1;
    1.32     private List<Fold> removedFoldList;
    1.33     private Map<String, Boolean> customFoldId = new HashMap<String, Boolean>();
    1.34 -   private static final RequestProcessor RP = new RequestProcessor(NewPlsqlFoldManager.class.getName(),
    1.35 -           1, false, false);
    1.36 +   private static final RequestProcessor RP = new RequestProcessor(NewPlsqlFoldManager.class.getName(), 1, false, false);
    1.37     private final RequestProcessor.Task task = RP.create(this);
    1.38 -//   private NewPlsqlFoldManager observer;
    1.39     private boolean initial = true;
    1.40 +   private PlsqlBlockFactory blockFactory;
    1.41  
    1.42     @Override
    1.43     public void init(FoldOperation operation) {
    1.44 @@ -106,31 +103,22 @@
    1.45     @Override
    1.46     public void initFolds(FoldHierarchyTransaction transaction) {
    1.47        doc = getOperation().getHierarchy().getComponent().getDocument();
    1.48 -      final PlsqlBlockFactory blockFactory = getBlockFactory();
    1.49 +      blockFactory = getBlockFactory();
    1.50        if (blockFactory != null) {
    1.51 -//         if (observer != null) {
    1.52 -//            blockFactory.deleteObserver(observer);
    1.53 -//         }
    1.54           blockFactory.addObserver(this);
    1.55 -//         observer = this;
    1.56        }
    1.57        task.schedule(300);
    1.58     }
    1.59  
    1.60 -   //XXX: seems NewPlsqlFoldManager needs to listen to PlsqlBlockFactory changes, instead of directly to document through FoldManager interface 
    1.61     @Override
    1.62     public void insertUpdate(DocumentEvent evt, FoldHierarchyTransaction transaction) {
    1.63        processRemovedFolds(transaction);
    1.64 -//      myRemoveFolds(transaction);
    1.65 -//      task.schedule(300);
    1.66     }
    1.67  
    1.68     @Override
    1.69     public void removeUpdate(DocumentEvent evt, FoldHierarchyTransaction transaction) {
    1.70        processRemovedFolds(transaction);
    1.71 -//      myRemoveFolds(transaction);
    1.72        removeAffectedMarks(evt, transaction);
    1.73 -//      task.schedule(300);
    1.74     }
    1.75  
    1.76     @Override
    1.77 @@ -174,7 +162,6 @@
    1.78        ((BaseDocument) doc).readLock();
    1.79        try {
    1.80  
    1.81 -         final PlsqlBlockFactory blockFactory = getBlockFactory();
    1.82           if (blockFactory != null) {
    1.83              FoldHierarchy hierarchy = getOperation().getHierarchy();
    1.84              hierarchy.lock();
    1.85 @@ -187,25 +174,18 @@
    1.86                 }
    1.87                 if (LOG.isLoggable(Level.FINE)) {
    1.88                    LOG.log(Level.FINE, "Updating: {0}", System.identityHashCode(this));
    1.89 +                  LOG.log(Level.FINE, "blockFactory.getBlockHierarchy().size(): {0}", blockFactory.getBlockHierarchy().size());
    1.90 +                  LOG.log(Level.FINE, "blockFactory.getNewBlocks().size(): {0}", blockFactory.getNewBlocks().size());
    1.91 +                  LOG.log(Level.FINE, "blockFactory.getRemovedBlocks().size(): {0}", blockFactory.getRemovedBlocks().size());
    1.92                 }
    1.93                 FoldHierarchyTransaction transaction = getOperation().openTransaction();
    1.94                 try {
    1.95 -                  //Initialize document hierarchy
    1.96 -                  blockFactory.initHierarchy(doc);
    1.97                    //Add new blocks to the hierarchy
    1.98 -                  List<PlsqlBlock> blocks = blockFactory.getBlockHierarchy();
    1.99 -//                  List<PlsqlBlock> blocks = blockFactory.getNewBlocks();
   1.100 -//                  if (initial) {
   1.101 -//                     blocks = blockFactory.getBlockHierarchy();
   1.102 -//                     initial = false;
   1.103 -//                  }
   1.104 -//                  List<PlsqlBlock> removedBlocks = blockFactory.getRemovedBlocks();
   1.105 -
   1.106 -//                  final Fold root = hierarchy.getRootFold();
   1.107 -//                  final List<FoldInfo> collapsedFolds = new ArrayList<FoldInfo>();
   1.108 -//                  getCollapsedFolds(root, collapsedFolds);
   1.109 -//                  addFolds(newBlocks, transaction, collapsedFolds);
   1.110 -//                  addFolds(blockFactory.getCustomFolds(), transaction, collapsedFolds);
   1.111 +                  List<PlsqlBlock> blocks = blockFactory.getNewBlocks();
   1.112 +                  if (initial) {
   1.113 +                     blocks = blockFactory.getBlockHierarchy();
   1.114 +                     initial = false;
   1.115 +                  }
   1.116  
   1.117                    updateFolds(blocks, transaction);
   1.118                    //Add custom fold blocks
   1.119 @@ -277,23 +257,27 @@
   1.120  
   1.121     private FoldMarkInfo getMark(int index) {
   1.122        return (FoldMarkInfo) markArray.getItem(index);
   1.123 +//      return markArray.get(index);
   1.124     }
   1.125  
   1.126     private int getMarkCount() {
   1.127        return markArray.getItemCount();
   1.128 +//      return markArray.size();
   1.129     }
   1.130  
   1.131     private void removeMark(int index) {
   1.132 -      if (LOG.isLoggable(Level.FINE)) {
   1.133 -         LOG.log(Level.FINE, "Removing mark from ind={0}: {1}", new Object[]{index, getMark(index)}); // NOI18N
   1.134 +      if (LOG.isLoggable(Level.FINER)) {
   1.135 +         LOG.log(Level.FINER, "Removing mark from ind={0}: {1}", new Object[]{index, getMark(index)}); // NOI18N
   1.136        }
   1.137        markArray.remove(index, 1);
   1.138 +//      markArray.remove(index);
   1.139     }
   1.140  
   1.141     private void insertMark(int index, FoldMarkInfo mark) {
   1.142 +//      markArray.put(index, mark);
   1.143        markArray.insertItem(index, mark);
   1.144 -      if (LOG.isLoggable(Level.FINE)) {
   1.145 -         LOG.log(Level.FINE, "Inserted mark at ind={0}: {1}", new Object[]{index, mark}); // NOI18N
   1.146 +      if (LOG.isLoggable(Level.FINER)) {
   1.147 +         LOG.log(Level.FINER, "Inserted mark at ind={0}: {1}", new Object[]{index, mark}); // NOI18N
   1.148        }
   1.149     }
   1.150  
   1.151 @@ -326,28 +310,15 @@
   1.152  
   1.153     private List<FoldMarkInfo> getMarkList(List<PlsqlBlock> blocks) {
   1.154        List<FoldMarkInfo> markList = new ArrayList<FoldMarkInfo>();
   1.155 -//      for (PlsqlBlock block : blocks) {
   1.156 -//         Token token = blocks.token();
   1.157 -//         List<FoldMarkInfo> info;
   1.158        try {
   1.159 -         scanToken(markList, blocks);
   1.160 +         scanBlocks(markList, blocks);
   1.161        } catch (BadLocationException e) {
   1.162           LOG.log(Level.WARNING, null, e);
   1.163 -//            info = null;
   1.164        }
   1.165 -
   1.166 -//         if (info != null) {
   1.167 -//            if (markList == null) {
   1.168 -//               markList = new ArrayList<FoldMarkInfo>();
   1.169 -//            }
   1.170 -//            markList.addAll(info);
   1.171 -//         }
   1.172 -//      }
   1.173 -
   1.174        return markList;
   1.175     }
   1.176  
   1.177 -   private void processTokenList(List<PlsqlBlock> blocks, FoldHierarchyTransaction transaction) {
   1.178 +   private void processBlocks(List<PlsqlBlock> blocks, FoldHierarchyTransaction transaction) {
   1.179        List<FoldMarkInfo> markList = getMarkList(blocks);
   1.180        int markListSize;
   1.181        if (markList != null && ((markListSize = markList.size()) > 0)) {
   1.182 @@ -382,8 +353,8 @@
   1.183                    arrayMark.release(false, transaction);
   1.184                 }
   1.185                 removeMark(arrayMarkIndex);
   1.186 -               if (LOG.isLoggable(Level.FINE)) {
   1.187 -                  LOG.log(Level.FINE, "Removed dup mark from ind={0}: {1}", new Object[]{arrayMarkIndex, arrayMark}); // NOI18N
   1.188 +               if (LOG.isLoggable(Level.FINER)) {
   1.189 +                  LOG.log(Level.FINER, "Removed dup mark from ind={0}: {1}", new Object[]{arrayMarkIndex, arrayMark}); // NOI18N
   1.190                 }
   1.191                 if (arrayMarkIndex < getMarkCount()) {
   1.192                    arrayMark = getMark(arrayMarkIndex);
   1.193 @@ -395,8 +366,8 @@
   1.194              }
   1.195              // Insert the listmark
   1.196              insertMark(arrayMarkIndex, listMark);
   1.197 -            if (LOG.isLoggable(Level.FINE)) {
   1.198 -               LOG.log(Level.FINE, "Inserted mark at ind={0}: {1}", new Object[]{arrayMarkIndex, listMark}); // NOI18N
   1.199 +            if (LOG.isLoggable(Level.FINER)) {
   1.200 +               LOG.log(Level.FINER, "Inserted mark at ind={0}: {1}", new Object[]{arrayMarkIndex, listMark}); // NOI18N
   1.201              }
   1.202              arrayMarkIndex++;
   1.203           }
   1.204 @@ -406,7 +377,7 @@
   1.205     private void updateFolds(List<PlsqlBlock> blocks, FoldHierarchyTransaction transaction) {
   1.206  
   1.207        if (blocks != null && !blocks.isEmpty()) {
   1.208 -         processTokenList(blocks, transaction);
   1.209 +         processBlocks(blocks, transaction);
   1.210        }
   1.211  
   1.212        if (maxUpdateMarkOffset == -1) { // no updates
   1.213 @@ -518,40 +489,8 @@
   1.214           sb.append(' ');
   1.215        }
   1.216     }
   1.217 -   private static Pattern pattern = Pattern.compile(
   1.218 -           "(<\\s*editor-fold"
   1.219 -           + // id="x"[opt] defaultstate="y"[opt] desc="z"[opt] defaultstate="a"[opt]
   1.220 -           // id must be first, the rest of attributes in random order
   1.221 -           "(?:(?:\\s+id=\"(\\S*)\")?(?:\\s+defaultstate=\"(\\S*?)\")?(?:\\s+desc=\"([\\S \\t]*?)\")?(?:\\s+defaultstate=\"(\\S*?)\")?)"
   1.222 -           + "\\s*>)|(?:</\\s*editor-fold\\s*>)"); // NOI18N
   1.223  
   1.224 -   private void scanToken(List<FoldMarkInfo> list, List<PlsqlBlock> blocks) throws BadLocationException {
   1.225 -      // ignore any token that is not comment
   1.226 -//      if (token.id().primaryCategory() != null && token.id().primaryCategory().startsWith("comment")) { //NOI18N
   1.227 -//         Matcher matcher = pattern.matcher(token.text());
   1.228 -//         if (matcher.find()) {
   1.229 -//            if (matcher.group(1) != null) { // fold's start mark found
   1.230 -//               boolean state;
   1.231 -//               if (matcher.group(3) != null) {
   1.232 -//                  state = "collapsed".equals(matcher.group(3)); // remember the defaultstate // NOI18N
   1.233 -//               } else {
   1.234 -//                  state = "collapsed".equals(matcher.group(5));
   1.235 -//               }
   1.236 -//
   1.237 -//               if (matcher.group(2) != null) { // fold's id exists
   1.238 -//                  Boolean collapsed = (Boolean) customFoldId.get(matcher.group(2));
   1.239 -//                  if (collapsed != null) {
   1.240 -//                     state = collapsed.booleanValue(); // fold's state is already known from the past
   1.241 -//                  } else {
   1.242 -//                     customFoldId.put(matcher.group(2), Boolean.valueOf(state));
   1.243 -//                  }
   1.244 -//               }
   1.245 -//               return new FoldMarkInfo(true, token.offset(null), matcher.end(0), matcher.group(2), state, matcher.group(4)); // NOI18N
   1.246 -//            } else { // fold's end mark found
   1.247 -//               return new FoldMarkInfo(false, token.offset(null), matcher.end(0), null, false, null);
   1.248 -//            }
   1.249 -//         }
   1.250 -//      }
   1.251 +   private void scanBlocks(List<FoldMarkInfo> list, List<PlsqlBlock> blocks) throws BadLocationException {
   1.252        for (PlsqlBlock block : blocks) {
   1.253  
   1.254           FoldType foldType = null;
   1.255 @@ -626,36 +565,14 @@
   1.256                 foldType = PlsqlFoldTypes.JAVASOURCE;
   1.257                 description = block.getPrefix() + "JAVA SOURCE";
   1.258              }
   1.259 -            final int length = block.getPrefix().length() + block.getName().length();
   1.260 -//         List<FoldMarkInfo> list = new ArrayList<FoldMarkInfo>();
   1.261              //XXX: find out what offsets are needed (check CustomFoldManager when .php is run):
   1.262 -            list.add(new FoldMarkInfo(foldType, true, block.getStartOffset(), length, block.getName(), false, description));
   1.263 +            final FoldMarkInfo foldMarkInfo = new FoldMarkInfo(foldType, true, block.getStartOffset(), 0, block.getName(), isCollapsed(foldType), description);
   1.264 +            // XXX: check if mark exist
   1.265 +            list.add(foldMarkInfo);
   1.266              list.add(new FoldMarkInfo(foldType, false, block.getEndOffset(), 0, null, false, null));
   1.267 -            scanToken(list, block.getChildBlocks());
   1.268 -//         return list;
   1.269 +            scanBlocks(list, block.getChildBlocks());
   1.270           }
   1.271        }
   1.272 -//      return null;
   1.273 -   }
   1.274 -
   1.275 -   private boolean myRemoveFolds(FoldHierarchyTransaction transaction) {
   1.276 -      final PlsqlBlockFactory blockFactory = getBlockFactory();
   1.277 -      if (blockFactory == null) {
   1.278 -         return true;
   1.279 -      }
   1.280 -      final FoldHierarchy fh = getOperation().getHierarchy();
   1.281 -      //Get folds from Block maker
   1.282 -      final Fold root = fh.getRootFold();
   1.283 -      final List<PlsqlBlock> oldBlocks = blockFactory.getRemovedBlocks();
   1.284 -      //Remove non existing blocks
   1.285 -      final int childCount = root.getFoldCount();
   1.286 -      if (!oldBlocks.isEmpty()) {
   1.287 -         for (int i = (childCount - 1); i >= 0; i--) {
   1.288 -            final Fold child = root.getFold(i);
   1.289 -            removeWithChildren(child, oldBlocks, transaction);
   1.290 -         }
   1.291 -      }
   1.292 -      return false;
   1.293     }
   1.294  
   1.295     private final class FoldMarkInfo {
   1.296 @@ -841,6 +758,7 @@
   1.297                 int startGuardedLength = getLength();
   1.298                 int endGuardedLength = pairMark.getLength();
   1.299                 int endOffset = pairMark.getOffset() + endGuardedLength;
   1.300 +               // XXX: check if Fold exist before adding
   1.301                 fold = getOperation().addToHierarchy(
   1.302                         foldType, getDescription(), collapsed,
   1.303                         startOffset, endOffset,
   1.304 @@ -896,161 +814,6 @@
   1.305           return sb.toString();
   1.306        }
   1.307     }
   1.308 -//   @Override
   1.309 -//   public void initFolds(final FoldHierarchyTransaction foldHierarchyTransaction) {
   1.310 -//      final Document doc = getDocument();
   1.311 -//      if (!(doc instanceof BaseDocument)) {
   1.312 -//         return;
   1.313 -//      }
   1.314 -//
   1.315 -//      final PlsqlBlockFactory blockFactory = getBlockFactory();
   1.316 -//      if (blockFactory != null) {
   1.317 -//         try {
   1.318 -//
   1.319 -//            //Initialize document hierarchy
   1.320 -//            blockFactory.initHierarchy(doc);
   1.321 -//            //Add new blocks to the hierarchy
   1.322 -//            List<PlsqlBlock> newBlocks;
   1.323 -//            if (initial) {
   1.324 -//               newBlocks = blockFactory.getBlockHierarchy();
   1.325 -//               initial = false;
   1.326 -//            } else {
   1.327 -//               newBlocks = blockFactory.getNewBlocks();
   1.328 -//            }
   1.329 -//            addFolds(newBlocks, foldHierarchyTransaction, null);
   1.330 -//            //Add custom fold blocks
   1.331 -//            addFolds(blockFactory.getCustomFolds(), foldHierarchyTransaction, null);
   1.332 -//         } catch (BadLocationException ex) {
   1.333 -//            Exceptions.printStackTrace(ex);
   1.334 -//         }
   1.335 -//      }
   1.336 -//   }
   1.337 -//
   1.338 -
   1.339 -   /**
   1.340 -    * Add folds to the folder hierarchy (initial)
   1.341 -    *
   1.342 -    * @param blockHier
   1.343 -    * @param fhTransaction
   1.344 -    */
   1.345 -   private void addFolds(final List<PlsqlBlock> blockHier, final FoldHierarchyTransaction fhTransaction, final List<FoldInfo> collapsedFolds) {
   1.346 -      final int count = blockHier.size();
   1.347 -      for (int i = 0; i < count; i++) {
   1.348 -         try {
   1.349 -            final PlsqlBlock temp = blockHier.get(i);
   1.350 -            FoldType foldType = null;
   1.351 -            final PlsqlBlockType type = temp.getType();
   1.352 -            String description = "";
   1.353 -
   1.354 -            if (!(type == PlsqlBlockType.COMMENT && doc.getText(temp.getStartOffset(), temp.getEndOffset() - temp.getStartOffset()).indexOf("\n") == -1)) { // check for single line comments
   1.355 -               if (type == PlsqlBlockType.VIEW) {
   1.356 -                  foldType = PlsqlFoldTypes.VIEW;
   1.357 -                  description = temp.getPrefix() + "VIEW " + temp.getName();
   1.358 -               } else if (type == PlsqlBlockType.TABLE_COMMENT) {
   1.359 -                  foldType = PlsqlFoldTypes.TABLECOMMENT;
   1.360 -                  description = "COMMENT ON TABLE " + temp.getName();
   1.361 -               } else if (type == PlsqlBlockType.COLUMN_COMMENT) {
   1.362 -                  foldType = PlsqlFoldTypes.COLUMNCOMMENT;
   1.363 -                  description = "COLUMN COMMENTS ON TABLE " + temp.getName();
   1.364 -               } else if (type == PlsqlBlockType.COMMENT) {
   1.365 -                  foldType = PlsqlFoldTypes.COMMENT;
   1.366 -                  description = temp.getName();
   1.367 -               } else if (type == PlsqlBlockType.PACKAGE) {
   1.368 -                  foldType = PlsqlFoldTypes.PACKAGE;
   1.369 -                  description = temp.getPrefix() + "PACKAGE " + temp.getName();
   1.370 -               } else if (type == PlsqlBlockType.PACKAGE_BODY) {
   1.371 -                  foldType = PlsqlFoldTypes.PACKAGEBODY;
   1.372 -                  description = temp.getPrefix() + "PACKAGE BODY " + temp.getName();
   1.373 -               } else if (type == PlsqlBlockType.PROCEDURE_IMPL) {
   1.374 -                  foldType = PlsqlFoldTypes.PROCEDUREIMPL;
   1.375 -                  description = temp.getPrefix() + "PROCEDURE IMPLEMENTATION " + temp.getName();
   1.376 -               } else if (type == PlsqlBlockType.FUNCTION_IMPL) {
   1.377 -                  foldType = PlsqlFoldTypes.FUNCTIONIMPL;
   1.378 -                  description = temp.getPrefix() + "FUNCTION IMPLEMENTATION " + temp.getName();
   1.379 -               } else if (type == PlsqlBlockType.PROCEDURE_DEF) {
   1.380 -                  foldType = PlsqlFoldTypes.PROCEDUREDEF;
   1.381 -                  description = "PROCEDURE DEFINITION " + temp.getName();
   1.382 -               } else if (type == PlsqlBlockType.FUNCTION_DEF) {
   1.383 -                  foldType = PlsqlFoldTypes.FUNCTIONDEF;
   1.384 -                  description = "FUNCTION DEFINITION " + temp.getName();
   1.385 -               } else if (type == PlsqlBlockType.DECLARE_END) {
   1.386 -                  foldType = PlsqlFoldTypes.DECLAREEND;
   1.387 -                  description = "DECLARE BLOCK";
   1.388 -               } else if (type == PlsqlBlockType.BEGIN_END) {
   1.389 -                  foldType = PlsqlFoldTypes.BEGINEND;
   1.390 -                  description = "BEGIN BLOCK";
   1.391 -               } else if (type == PlsqlBlockType.TRIGGER) {
   1.392 -                  foldType = PlsqlFoldTypes.TRIGGER;
   1.393 -                  description = temp.getPrefix() + "TRIGGER " + temp.getName();
   1.394 -               } else if (type == PlsqlBlockType.IF) {
   1.395 -                  foldType = PlsqlFoldTypes.IF;
   1.396 -                  description = temp.getName();
   1.397 -               } else if (type == PlsqlBlockType.CASE) {
   1.398 -                  foldType = PlsqlFoldTypes.CASE;
   1.399 -                  description = temp.getName();
   1.400 -               } else if (type == PlsqlBlockType.WHILE_LOOP) {
   1.401 -                  foldType = PlsqlFoldTypes.WHILELOOP;
   1.402 -                  description = "WHILE " + temp.getName();
   1.403 -               } else if (type == PlsqlBlockType.FOR_LOOP) {
   1.404 -                  foldType = PlsqlFoldTypes.FORLOOP;
   1.405 -                  description = "FOR " + temp.getName();
   1.406 -               } else if (type == PlsqlBlockType.LOOP) {
   1.407 -                  foldType = PlsqlFoldTypes.LOOP;
   1.408 -                  description = "LOOP ";
   1.409 -               } else if (type == PlsqlBlockType.CUSTOM_FOLD) {
   1.410 -                  foldType = PlsqlFoldTypes.CUSTOM;
   1.411 -                  description = temp.getName();
   1.412 -               } else if (type == PlsqlBlockType.STATEMENT) {
   1.413 -                  foldType = PlsqlFoldTypes.STATEMENT;
   1.414 -                  description = temp.getPrefix() + temp.getName();
   1.415 -               } else if (type == PlsqlBlockType.CURSOR) {
   1.416 -                  foldType = PlsqlFoldTypes.CURSOR;
   1.417 -                  description = "CURSOR " + temp.getName();
   1.418 -               } else if (type == PlsqlBlockType.JAVA_SOURCE) {
   1.419 -                  foldType = PlsqlFoldTypes.JAVASOURCE;
   1.420 -                  description = temp.getPrefix() + "JAVA SOURCE";
   1.421 -               }
   1.422 -
   1.423 -               if (doc.getEndPosition().getOffset() >= temp.getEndOffset()) {
   1.424 -                  operation.addToHierarchy(foldType, description, isCollapsed(temp, foldType, collapsedFolds),
   1.425 -                          temp.getStartOffset(), temp.getEndOffset(), 0, 0, null, fhTransaction);
   1.426 -
   1.427 -                  //check for any child folds and add them also
   1.428 -                  addFolds(temp.getChildBlocks(), fhTransaction, collapsedFolds);
   1.429 -               }
   1.430 -            }
   1.431 -         } catch (BadLocationException ex) {
   1.432 -            LOG.log(Level.FINE, "BadLocationException thrown in addFolds", ex);
   1.433 -         }
   1.434 -      }
   1.435 -   }
   1.436 -
   1.437 -   private void getBlockMap(final Map<String, PlsqlBlock> blockMap, final List<PlsqlBlock> blockHierarchy) {
   1.438 -      for (int i = 0; i < blockHierarchy.size(); i++) {
   1.439 -         final PlsqlBlock temp = blockHierarchy.get(i);
   1.440 -         blockMap.put(temp.getStartOffset() + "_" + temp.getEndOffset(), temp);
   1.441 -
   1.442 -         getBlockMap(blockMap, temp.getChildBlocks());
   1.443 -      }
   1.444 -   }
   1.445 -
   1.446 -   /**
   1.447 -    * Method that will add collapsed folds (FoldInfo objects) in the fold hierarchy to the given list
   1.448 -    *
   1.449 -    * @param parent
   1.450 -    * @param foldInfoLst
   1.451 -    */
   1.452 -   private void getCollapsedFolds(final Fold parent, final List<FoldInfo> foldInfoLst) {
   1.453 -      if (parent.isCollapsed()) {
   1.454 -         final FoldInfo tempInfo = new FoldInfo(parent.getStartOffset(), parent.getEndOffset(), parent.getType());
   1.455 -         foldInfoLst.add(tempInfo);
   1.456 -      }
   1.457 -      final int count = parent.getFoldCount();
   1.458 -      for (int i = 0; i < count; i++) {
   1.459 -         final Fold temp = parent.getFold(i);
   1.460 -         getCollapsedFolds(temp, foldInfoLst);
   1.461 -      }
   1.462 -   }
   1.463  
   1.464     /**
   1.465      * Method that will select and return the corresponding fold to parent from oldRoot fold hierarchy
   1.466 @@ -1059,344 +822,11 @@
   1.467      * @param foldInfoLst
   1.468      * @return
   1.469      */
   1.470 -   private boolean isCollapsed(final PlsqlBlock block, final FoldType foldType, final List<FoldInfo> foldInfoLst) {
   1.471 -      if (foldInfoLst == null) {
   1.472 -         if (OptionsUtilities.isPlSqlExpandFolds()) {
   1.473 -            return false;
   1.474 -         } else {
   1.475 -            return foldType == PlsqlFoldTypes.COMMENT;
   1.476 -         }
   1.477 -      }
   1.478 -      final int size = foldInfoLst.size();
   1.479 -      for (int i = 0; i < size; i++) {
   1.480 -         final FoldInfo temp = foldInfoLst.get(i);
   1.481 -
   1.482 -         if ((temp.foldType == foldType)
   1.483 -                 && (temp.startOffset == block.getPreviousStart())
   1.484 -                 && (temp.endOffset == block.getPreviousEnd())) {
   1.485 -            return true;
   1.486 -         }
   1.487 -      }
   1.488 -
   1.489 -      return false;
   1.490 -   }
   1.491 -
   1.492 -//   /**
   1.493 -//    * Method that will update the folds based on the changes to the document
   1.494 -//    *
   1.495 -//    * @param fhTran
   1.496 -//    */
   1.497 -//   private synchronized void updateFolds(final FoldHierarchyTransaction fhTran) {
   1.498 -//      try {
   1.499 -//         final PlsqlBlockFactory blockFactory = getBlockFactory();
   1.500 -//         if (blockFactory == null) {
   1.501 -//            return;
   1.502 -//         }
   1.503 -//
   1.504 -//         final FoldHierarchy fh = getOperation().getHierarchy();
   1.505 -//         try {
   1.506 -//            //lock the hierarchy
   1.507 -//            fh.lock();
   1.508 -//
   1.509 -//            final Fold root = fh.getRootFold();
   1.510 -//            final List<FoldInfo> collapsedFolds = new ArrayList<FoldInfo>();
   1.511 -//            getCollapsedFolds(root, collapsedFolds);
   1.512 -//
   1.513 -//            //Get folds from Block maker
   1.514 -//            final List<PlsqlBlock> oldBlocks = blockFactory.getRemovedBlocks();
   1.515 -//
   1.516 -//            //Remove non existing blocks
   1.517 -//            final int childCount = root.getFoldCount();
   1.518 -//            if (!oldBlocks.isEmpty()) {
   1.519 -//               for (int i = (childCount - 1); i >= 0; i--) {
   1.520 -//                  final Fold child = root.getFold(i);
   1.521 -//                  removeWithChildren(child, oldBlocks, fhTran);
   1.522 -//               }
   1.523 -//            }
   1.524 -//
   1.525 -//            //Add new blocks to the hierarchy
   1.526 -//            final List<PlsqlBlock> newBlocks = blockFactory.getNewBlocks();
   1.527 -//            addFolds(newBlocks, fhTran, collapsedFolds);
   1.528 -//            //Add custom folds
   1.529 -//            addFolds(blockFactory.getCustomFolds(), fhTran, collapsedFolds);
   1.530 -//
   1.531 -//            if (blockFactory.isAliasesChanged()) {
   1.532 -//               final Map<String, PlsqlBlock> blockMap = new HashMap<String, PlsqlBlock>();
   1.533 -//               getBlockMap(blockMap, blockFactory.getBlockHierarchy());
   1.534 -//               final int rootChildren = root.getFoldCount();
   1.535 -//               for (int i = (rootChildren - 1); i >= 0; i--) {
   1.536 -//                  final Fold child = root.getFold(i);
   1.537 -//                  changeDescriptions(child, blockMap, fhTran);
   1.538 -//               }
   1.539 -//            }
   1.540 -//
   1.541 -//            //compareFoldHierarchies(root, collapsedFolds, fhTran);
   1.542 -//         } finally {
   1.543 -//            fh.unlock();
   1.544 -//         }
   1.545 -//      } catch (Exception e) {
   1.546 -//         ErrorManager.getDefault().notify(e);
   1.547 -//      }
   1.548 -//   }
   1.549 -//
   1.550 -//   /**
   1.551 -//    * Method that will change the fold descriptions if changed
   1.552 -//    *
   1.553 -//    * @param parent
   1.554 -//    * @param blockMap
   1.555 -//    * @param fhTran
   1.556 -//    */
   1.557 -//   private void changeDescriptions(final Fold parent, final Map<String, PlsqlBlock> blockMap, final FoldHierarchyTransaction fhTran) throws BadLocationException {
   1.558 -//      final PlsqlBlock block = getCorrespondingBlock(parent, blockMap);
   1.559 -//
   1.560 -//      //check whether block name is an alias
   1.561 -//      if ((block != null) && (!block.getAlias().equals(""))) {  //Aliases wont be there for COMMENT & DECLARE
   1.562 -//         final String description = getFoldDescription(block);
   1.563 -//         //check whether description is different
   1.564 -//         if (!parent.getDescription().equals(description)) {
   1.565 -//            operation.removeFromHierarchy(parent, fhTran);
   1.566 -//            operation.addToHierarchy(parent.getType(), description, parent.isCollapsed(),
   1.567 -//                    block.getStartOffset(), block.getEndOffset(), 0, 0, null, fhTran);
   1.568 -//         }
   1.569 -//      }
   1.570 -//
   1.571 -//      final int childCount = parent.getFoldCount();
   1.572 -//      for (int i = (childCount - 1); i >= 0; i--) {
   1.573 -//         final Fold child = parent.getFold(i);
   1.574 -//         //Ignore types that cannot have the name as an alias
   1.575 -//         if ((child.getType() != PlsqlFoldTypes.BEGINEND)
   1.576 -//                 && (child.getType() != PlsqlFoldTypes.COMMENT)
   1.577 -//                 && (child.getType() != PlsqlFoldTypes.DECLAREEND)
   1.578 -//                 && (child.getType() != PlsqlFoldTypes.IF)
   1.579 -//                 && (child.getType() != PlsqlFoldTypes.CUSTOM)
   1.580 -//                 && (child.getType() != PlsqlFoldTypes.FORLOOP)
   1.581 -//                 && (child.getType() != PlsqlFoldTypes.LOOP)
   1.582 -//                 && (child.getType() != PlsqlFoldTypes.WHILELOOP)) {
   1.583 -//
   1.584 -//            changeDescriptions(child, blockMap, fhTran);
   1.585 -//         }
   1.586 -//      }
   1.587 -//   }
   1.588 -//
   1.589 -   /**
   1.590 -    * Get the matching block to the fold. Consider the type, start & end offset
   1.591 -    *
   1.592 -    * @param fold
   1.593 -    * @param blockMap
   1.594 -    * @return
   1.595 -    */
   1.596 -   private PlsqlBlock getCorrespondingBlock(final Fold fold, final Map<String, PlsqlBlock> blockMap) {
   1.597 -
   1.598 -      final PlsqlBlock temp = blockMap.get(fold.getStartOffset() + "_" + fold.getEndOffset());
   1.599 -      if (temp != null && isCorrespondingType(temp.getType(), fold.getType())) {
   1.600 -         return temp;
   1.601 -      }
   1.602 -
   1.603 -      return null;
   1.604 -   }
   1.605 -
   1.606 -   /**
   1.607 -    * Method that will check whether the block type and the fold type are matching
   1.608 -    *
   1.609 -    * @param blockType
   1.610 -    * @param foldType
   1.611 -    * @return
   1.612 -    */
   1.613 -   private boolean isCorrespondingType(final PlsqlBlockType blockType, final FoldType foldType) {
   1.614 -      switch (blockType) {
   1.615 -         case VIEW:
   1.616 -            return foldType == PlsqlFoldTypes.VIEW;
   1.617 -         case TABLE_COMMENT:
   1.618 -            return foldType == PlsqlFoldTypes.TABLECOMMENT;
   1.619 -         case COLUMN_COMMENT:
   1.620 -            return foldType == PlsqlFoldTypes.COLUMNCOMMENT;
   1.621 -         case COMMENT:
   1.622 -            return foldType == PlsqlFoldTypes.COMMENT;
   1.623 -         case PACKAGE:
   1.624 -            return foldType == PlsqlFoldTypes.PACKAGE;
   1.625 -         case PACKAGE_BODY:
   1.626 -            return foldType == PlsqlFoldTypes.PACKAGEBODY;
   1.627 -         case PROCEDURE_IMPL:
   1.628 -            return foldType == PlsqlFoldTypes.PROCEDUREIMPL;
   1.629 -         case FUNCTION_IMPL:
   1.630 -            return foldType == PlsqlFoldTypes.FUNCTIONIMPL;
   1.631 -         case PROCEDURE_DEF:
   1.632 -            return foldType == PlsqlFoldTypes.PROCEDUREDEF;
   1.633 -         case FUNCTION_DEF:
   1.634 -            return foldType == PlsqlFoldTypes.FUNCTIONDEF;
   1.635 -         case DECLARE_END:
   1.636 -            return foldType == PlsqlFoldTypes.DECLAREEND;
   1.637 -         case BEGIN_END:
   1.638 -            return foldType == PlsqlFoldTypes.BEGINEND;
   1.639 -         case TRIGGER:
   1.640 -            return foldType == PlsqlFoldTypes.TRIGGER;
   1.641 -         case IF:
   1.642 -            return foldType == PlsqlFoldTypes.IF;
   1.643 -         case CASE:
   1.644 -            return foldType == PlsqlFoldTypes.CASE;
   1.645 -         case WHILE_LOOP:
   1.646 -            return foldType == PlsqlFoldTypes.WHILELOOP;
   1.647 -         case FOR_LOOP:
   1.648 -            return foldType == PlsqlFoldTypes.FORLOOP;
   1.649 -         case LOOP:
   1.650 -            return foldType == PlsqlFoldTypes.LOOP;
   1.651 -         case CUSTOM_FOLD:
   1.652 -            return foldType == PlsqlFoldTypes.CUSTOM;
   1.653 -         case STATEMENT:
   1.654 -            return foldType == PlsqlFoldTypes.STATEMENT;
   1.655 -         case CURSOR:
   1.656 -            return foldType == PlsqlFoldTypes.CURSOR;
   1.657 -         case JAVA_SOURCE:
   1.658 -            return foldType == PlsqlFoldTypes.JAVASOURCE;
   1.659 -         default:
   1.660 -            return false;
   1.661 -      }
   1.662 -   }
   1.663 -
   1.664 -   /**
   1.665 -    * Method that will return the fold description given the Plsql block Used when changing the descriptions only.
   1.666 -    *
   1.667 -    * @param block
   1.668 -    * @return
   1.669 -    */
   1.670 -   private String getFoldDescription(final PlsqlBlock block) {
   1.671 -      switch (block.getType()) {
   1.672 -         case VIEW:
   1.673 -            return block.getPrefix() + "VIEW " + block.getName();
   1.674 -         case TABLE_COMMENT:
   1.675 -            return "COMMENT ON TABLE " + block.getName();
   1.676 -         case COLUMN_COMMENT:
   1.677 -            return "COLUMN COMMENTS ON TABLE " + block.getName();
   1.678 -         case COMMENT:
   1.679 -            return block.getName();
   1.680 -         case PACKAGE:
   1.681 -            return block.getPrefix() + "PACKAGE " + block.getName();
   1.682 -         case PACKAGE_BODY:
   1.683 -            return block.getPrefix() + "PACKAGE BODY " + block.getName();
   1.684 -         case PROCEDURE_IMPL:
   1.685 -            return block.getPrefix() + "PROCEDURE IMPLEMENTATION " + block.getName();
   1.686 -         case FUNCTION_IMPL:
   1.687 -            return block.getPrefix() + "FUNCTION IMPLEMENTATION " + block.getName();
   1.688 -         case PROCEDURE_DEF:
   1.689 -            return "PROCEDURE DEFINITION " + block.getName();
   1.690 -         case FUNCTION_DEF:
   1.691 -            return "FUNCTION DEFINITION " + block.getName();
   1.692 -         case DECLARE_END:
   1.693 -            return "DECLARE BLOCK";
   1.694 -         case BEGIN_END:
   1.695 -            return "BEGIN BLOCK";
   1.696 -         case TRIGGER:
   1.697 -            return block.getPrefix() + "TRIGGER " + block.getName();
   1.698 -         case IF:
   1.699 -            return block.getName();
   1.700 -         case CASE:
   1.701 -            return block.getName();
   1.702 -         case WHILE_LOOP:
   1.703 -            return "WHILE " + block.getName();
   1.704 -         case FOR_LOOP:
   1.705 -            return "FOR " + block.getName();
   1.706 -         case LOOP:
   1.707 -            return "LOOP ";
   1.708 -         case CUSTOM_FOLD:
   1.709 -            return block.getName();
   1.710 -         case STATEMENT:
   1.711 -            return block.getPrefix() + block.getName();
   1.712 -         case CURSOR:
   1.713 -            return "CURSOR " + block.getName();
   1.714 -         case JAVA_SOURCE:
   1.715 -            return block.getPrefix() + "JAVA SOURCE";
   1.716 -         default:
   1.717 -            return "";
   1.718 -      }
   1.719 -   }
   1.720 -
   1.721 -   /**
   1.722 -    * Remove fold with its children
   1.723 -    *
   1.724 -    * @param fold
   1.725 -    * @param blockHier
   1.726 -    * @param fhTran
   1.727 -    * @return true if removed all the children
   1.728 -    */
   1.729 -   private void removeWithChildren(final Fold fold, final List<PlsqlBlock> blockHier, final FoldHierarchyTransaction fhTran) {
   1.730 -
   1.731 -      final int childCount = fold.getFoldCount();
   1.732 -      for (int i = (childCount - 1); i >= 0; i--) {
   1.733 -         final Fold child = fold.getFold(i);
   1.734 -         removeWithChildren(child, blockHier, fhTran);
   1.735 -      }
   1.736 -
   1.737 -      //If a custom fold remove
   1.738 -      if (fold.getType() == PlsqlFoldTypes.CUSTOM || checkExists(fold, blockHier)) {
   1.739 -         operation.removeFromHierarchy(fold, fhTran);
   1.740 -      }
   1.741 -   }
   1.742 -
   1.743 -   /**
   1.744 -    * Method that will check whether given fold exists in block hier
   1.745 -    *
   1.746 -    * @param fold
   1.747 -    * @param blockHier
   1.748 -    * @return
   1.749 -    */
   1.750 -   private boolean checkExists(final Fold fold, final List<PlsqlBlock> blockHier) {
   1.751 -      final Comparator<PlsqlBlock> comparator = new Comparator<PlsqlBlock>() {
   1.752 -         @Override
   1.753 -         public int compare(final PlsqlBlock o1, final PlsqlBlock o2) {
   1.754 -            Integer o1pos, o2pos;
   1.755 -            if (o1.getStartOffset() > -1 && o2.getStartOffset() > -1) {
   1.756 -               o1pos = Integer.valueOf(o1.getStartOffset());
   1.757 -               o2pos = Integer.valueOf(o2.getStartOffset());
   1.758 -            } else {
   1.759 -               o1pos = Integer.valueOf(o1.getEndOffset());
   1.760 -               o2pos = Integer.valueOf(o2.getEndOffset());
   1.761 -            }
   1.762 -            return o1pos.compareTo(o2pos);
   1.763 -         }
   1.764 -      };
   1.765 -      return checkExists(fold, blockHier, comparator);
   1.766 -   }
   1.767 -
   1.768 -   /**
   1.769 -    * Method that will check whether given fold exists in block hier
   1.770 -    *
   1.771 -    * @param fold
   1.772 -    * @param blockHier
   1.773 -    * @param comparator
   1.774 -    * @return
   1.775 -    */
   1.776 -   private boolean checkExists(final Fold fold, final List<PlsqlBlock> blockHier, final Comparator<PlsqlBlock> comparator) {
   1.777 -      final int size = blockHier.size();
   1.778 -      Collections.sort(blockHier, comparator);
   1.779 -      if (size == 0) {
   1.780 +   private boolean isCollapsed(final FoldType foldType) {
   1.781 +      if (OptionsUtilities.isPlSqlExpandFolds()) {
   1.782           return false;
   1.783        }
   1.784 -      //make sure that the fold isn't before the first block or after the last block in the hierarchy.
   1.785 -      if (fold.getStartOffset() > blockHier.get(size - 1).getEndOffset()
   1.786 -              || fold.getEndOffset() < blockHier.get(0).getStartOffset()) {
   1.787 -         return false;
   1.788 -      }
   1.789 -      for (int i = 0; i < size; i++) {
   1.790 -         final PlsqlBlock tmp = blockHier.get(i);
   1.791 -         if (tmp.getStartOffset() <= fold.getStartOffset() && tmp.getEndOffset() >= fold.getEndOffset()) {
   1.792 -            return true;
   1.793 -         }
   1.794 -         if (tmp.getPreviousStart() <= fold.getStartOffset() && tmp.getPreviousEnd() >= fold.getEndOffset()) {
   1.795 -            return true;
   1.796 -         }
   1.797 -         if ((tmp.getEndOffset() == fold.getEndOffset() || fold.getEndOffset() == tmp.getPreviousEnd()
   1.798 -                 || tmp.getStartOffset() == fold.getStartOffset() || tmp.getPreviousStart() == fold.getStartOffset())
   1.799 -                 && (isCorrespondingType(tmp.getType(), fold.getType()))
   1.800 -                 && (getFoldDescription(tmp).equals(fold.getDescription()))) {
   1.801 -            return true;
   1.802 -         }
   1.803 -
   1.804 -         if (checkExists(fold, tmp.getChildBlocks(), comparator)) {
   1.805 -            return true;
   1.806 -         }
   1.807 -      }
   1.808 -
   1.809 -      return false;
   1.810 +      return foldType == PlsqlFoldTypes.COMMENT;
   1.811     }
   1.812  
   1.813     /**
   1.814 @@ -1411,33 +841,4 @@
   1.815        }
   1.816        return null;
   1.817     }
   1.818 -//
   1.819 -//   /**
   1.820 -//    * Document event has occurred
   1.821 -//    *
   1.822 -//    * @param o
   1.823 -//    * @param arg
   1.824 -//    */
   1.825 -//   public void update(final Observable o, final Object arg) {
   1.826 -//      final FoldHierarchyTransaction fhTran = getOperation().openTransaction();
   1.827 -//      updateFolds(fhTran);
   1.828 -//      // allready commited at this time
   1.829 -//      //fhTran.commit();
   1.830 -//   }
   1.831 -
   1.832 -   /**
   1.833 -    * Private class that holds some fold info This is used to collapse folds after a change
   1.834 -    */
   1.835 -   private class FoldInfo {
   1.836 -
   1.837 -      public FoldType foldType;
   1.838 -      public int startOffset;
   1.839 -      public int endOffset;
   1.840 -
   1.841 -      private FoldInfo(final int start, final int end, final FoldType type) {
   1.842 -         this.startOffset = start;
   1.843 -         this.endOffset = end;
   1.844 -         this.foldType = type;
   1.845 -      }
   1.846 -   }
   1.847  }
     2.1 --- a/PLSQL/Folding/src/org/netbeans/modules/plsql/fold/PlsqlFoldManagerFactory.java	Mon Mar 11 15:26:32 2013 +0100
     2.2 +++ b/PLSQL/Folding/src/org/netbeans/modules/plsql/fold/PlsqlFoldManagerFactory.java	Mon Mar 11 23:04:52 2013 +0100
     2.3 @@ -52,12 +52,12 @@
     2.4  
     2.5     @Override
     2.6     public FoldManager createFoldManager() {
     2.7 -      if (System.getProperty("plsql.fold.manager").equals("new")) {
     2.8 -         return new NewPlsqlFoldManager();
     2.9 -      }
    2.10        if (System.getProperty("plsql.fold.manager").equals("custom")) {
    2.11           return new CustomFoldManager();
    2.12        }
    2.13 -      return new PlsqlFoldManager();
    2.14 +      if (System.getProperty("plsql.fold.manager").equals("old")) {
    2.15 +         return new PlsqlFoldManager();
    2.16 +      }
    2.17 +      return new NewPlsqlFoldManager();
    2.18     }
    2.19  }