Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 254701
Collapse All | Expand All

(-)a/editor.bracesmatching/src/org/netbeans/modules/editor/bracesmatching/BracesMatchHighlighting.java (-1 / +16 lines)
 Lines 67-72    Link Here 
67
import org.netbeans.api.editor.mimelookup.MimeLookup;
67
import org.netbeans.api.editor.mimelookup.MimeLookup;
68
import org.netbeans.api.editor.settings.FontColorSettings;
68
import org.netbeans.api.editor.settings.FontColorSettings;
69
import org.netbeans.spi.editor.highlighting.HighlightsLayerFactory;
69
import org.netbeans.spi.editor.highlighting.HighlightsLayerFactory;
70
import org.netbeans.spi.editor.highlighting.ReleasableHighlightsContainer;
70
import org.netbeans.spi.editor.highlighting.ZOrder;
71
import org.netbeans.spi.editor.highlighting.ZOrder;
71
72
72
/**
73
/**
 Lines 74-80    Link Here 
74
 * @author Vita Stejskal
75
 * @author Vita Stejskal
75
 */
76
 */
76
public class BracesMatchHighlighting extends AbstractHighlightsContainer 
77
public class BracesMatchHighlighting extends AbstractHighlightsContainer 
77
    implements ChangeListener, PropertyChangeListener, HighlightsChangeListener, DocumentListener 
78
    implements ReleasableHighlightsContainer, ChangeListener, PropertyChangeListener, HighlightsChangeListener, DocumentListener 
78
{
79
{
79
    private static final Logger LOG = Logger.getLogger(BracesMatchHighlighting.class.getName());
80
    private static final Logger LOG = Logger.getLogger(BracesMatchHighlighting.class.getName());
80
    
81
    
 Lines 95-100    Link Here 
95
    private final AttributeSet bracesMismatchColoring;
96
    private final AttributeSet bracesMismatchColoring;
96
    private final AttributeSet bracesMatchMulticharColoring;
97
    private final AttributeSet bracesMatchMulticharColoring;
97
    private final AttributeSet bracesMismatchMulticharColoring;
98
    private final AttributeSet bracesMismatchMulticharColoring;
99
    
100
    private boolean released;
98
101
99
    public BracesMatchHighlighting(JTextComponent component, Document document) {
102
    public BracesMatchHighlighting(JTextComponent component, Document document) {
100
        this.document = document;
103
        this.document = document;
 Lines 220-225    Link Here 
220
    // ------------------------------------------------
223
    // ------------------------------------------------
221
    
224
    
222
    private void refresh() {
225
    private void refresh() {
226
        if (released) {
227
            return; // No longer notify the matcher since it would leak to memory leak of MasterMatcher.lastResult
228
        }
229
223
        Caret c = this.caret;
230
        Caret c = this.caret;
224
        if (c == null) {
231
        if (c == null) {
225
            bag.clear();
232
            bag.clear();
 Lines 247-252    Link Here 
247
        }
254
        }
248
        return mimeType;
255
        return mimeType;
249
    }
256
    }
257
258
    @Override
259
    public void released() {
260
        released = true;
261
//        component.removePropertyChangeListener(this);
262
//        bag.removeHighlightsChangeListener(this);
263
//        document.removeDocumentListener(this);
264
    }
250
    
265
    
251
    public static final class Factory implements HighlightsLayerFactory {
266
    public static final class Factory implements HighlightsLayerFactory {
252
        public HighlightsLayer[] createLayers(Context context) {
267
        public HighlightsLayer[] createLayers(Context context) {
(-)a/editor.bracesmatching/src/org/netbeans/modules/editor/bracesmatching/MasterMatcher.java (+21 lines)
 Lines 31-36    Link Here 
31
package org.netbeans.modules.editor.bracesmatching;
31
package org.netbeans.modules.editor.bracesmatching;
32
32
33
import java.awt.Color;
33
import java.awt.Color;
34
import java.beans.PropertyChangeEvent;
35
import java.beans.PropertyChangeListener;
34
import java.util.ArrayList;
36
import java.util.ArrayList;
35
import java.util.Arrays;
37
import java.util.Arrays;
36
import java.util.Collection;
38
import java.util.Collection;
 Lines 254-259    Link Here 
254
    
256
    
255
    private MasterMatcher(JTextComponent component) {
257
    private MasterMatcher(JTextComponent component) {
256
        this.component = component;
258
        this.component = component;
259
        component.addPropertyChangeListener(new PropertyChangeListener() {
260
            @Override
261
            public void propertyChange(PropertyChangeEvent evt) {
262
                if ("document".equals(evt.getPropertyName())) {
263
                    synchronized (LOCK) {
264
                        // Cancel any pending task and clear the lastResult
265
                        if (task != null) {
266
                            task.cancel();
267
                            task = null;
268
                        }
269
                        if (lastResult != null) {
270
                            System.err.println("thisMatcher=" + this + "\n    lastResult=" + lastResult);
271
                            lastResult.cancel();
272
                            lastResult = null; // Prevent memory leak upon document change
273
                        }
274
                    }
275
                }
276
            }
277
        });
257
    }
278
    }
258
279
259
    private Object getAllowedDirection() {
280
    private Object getAllowedDirection() {
(-)a/editor.lib2/apichanges.xml (+13 lines)
 Lines 107-112    Link Here 
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
    <changes>
109
    <changes>
110
        <change id="releasable-highlights-container">
111
            <summary>ReleasableHighlightsContainer added</summary>
112
            <version major="2" minor="4"/>
113
            <date day="27" month="8" year="2015"/>
114
            <author login="mmetelka"/>
115
            <compatibility binary="compatible" semantic="compatible" source="compatible" addition="yes" deprecation="no" deletion="no"/>
116
            <description>
117
                <p>
118
                    Allows highlights containers to be notified that they are no longer being used by highlighting manager.
119
                </p>
120
            </description>
121
            <issue number="254701"/>
122
        </change>
110
        <change id="editor-document-split">
123
        <change id="editor-document-split">
111
            <summary>Document handling split</summary>
124
            <summary>Document handling split</summary>
112
            <version major="2" minor="0"/>
125
            <version major="2" minor="0"/>
(-)a/editor.lib2/manifest.mf (-1 / +1 lines)
 Lines 1-6    Link Here 
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.editor.lib2/1
2
OpenIDE-Module: org.netbeans.modules.editor.lib2/1
3
OpenIDE-Module-Implementation-Version: 43
3
OpenIDE-Module-Implementation-Version: 44
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/lib2/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/lib2/Bundle.properties
5
OpenIDE-Module-Layer: org/netbeans/modules/editor/lib2/resources/layer.xml
5
OpenIDE-Module-Layer: org/netbeans/modules/editor/lib2/resources/layer.xml
6
OpenIDE-Module-Needs: org.netbeans.modules.editor.actions
6
OpenIDE-Module-Needs: org.netbeans.modules.editor.actions
(-)a/editor.lib2/nbproject/project.properties (-1 / +1 lines)
 Lines 43-49    Link Here 
43
is.autoload=true
43
is.autoload=true
44
javac.source=1.7
44
javac.source=1.7
45
javac.compilerargs=-Xlint:unchecked
45
javac.compilerargs=-Xlint:unchecked
46
spec.version.base=2.3.0
46
spec.version.base=2.4.0
47
47
48
javadoc.arch=${basedir}/arch.xml
48
javadoc.arch=${basedir}/arch.xml
49
javadoc.apichanges=${basedir}/apichanges.xml
49
javadoc.apichanges=${basedir}/apichanges.xml
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/highlighting/DirectMergeContainer.java (-1 / +11 lines)
 Lines 56-61    Link Here 
56
import org.netbeans.spi.editor.highlighting.HighlightsChangeListener;
56
import org.netbeans.spi.editor.highlighting.HighlightsChangeListener;
57
import org.netbeans.spi.editor.highlighting.HighlightsContainer;
57
import org.netbeans.spi.editor.highlighting.HighlightsContainer;
58
import org.netbeans.spi.editor.highlighting.HighlightsSequence;
58
import org.netbeans.spi.editor.highlighting.HighlightsSequence;
59
import org.netbeans.spi.editor.highlighting.ReleasableHighlightsContainer;
59
import org.openide.util.WeakListeners;
60
import org.openide.util.WeakListeners;
60
61
61
/**
62
/**
 Lines 67-73    Link Here 
67
 *
68
 *
68
 * @author Miloslav Metelka
69
 * @author Miloslav Metelka
69
 */
70
 */
70
public final class DirectMergeContainer implements HighlightsContainer, HighlightsChangeListener {
71
public final class DirectMergeContainer implements HighlightsContainer, HighlightsChangeListener, ReleasableHighlightsContainer {
71
    
72
    
72
    // -J-Dorg.netbeans.modules.editor.lib2.highlighting.DirectMergeContainer.level=FINE
73
    // -J-Dorg.netbeans.modules.editor.lib2.highlighting.DirectMergeContainer.level=FINE
73
    private static final Logger LOG = Logger.getLogger(DirectMergeContainer.class.getName());
74
    private static final Logger LOG = Logger.getLogger(DirectMergeContainer.class.getName());
 Lines 166-171    Link Here 
166
        }
167
        }
167
        return sb.toString();
168
        return sb.toString();
168
    }
169
    }
170
171
    @Override
172
    public void released() {
173
        for (HighlightsContainer layer : layers) {
174
            if (layer instanceof ReleasableHighlightsContainer) {
175
                ((ReleasableHighlightsContainer) layer).released();
176
            }
177
        }
178
    }
169
    
179
    
170
    static final class HlSequence implements HighlightsSequenceEx {
180
    static final class HlSequence implements HighlightsSequenceEx {
171
181
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/highlighting/HighlightingManager.java (+22 lines)
 Lines 69-74    Link Here 
69
import org.netbeans.spi.editor.highlighting.HighlightsContainer;
69
import org.netbeans.spi.editor.highlighting.HighlightsContainer;
70
import org.netbeans.spi.editor.highlighting.HighlightsLayer;
70
import org.netbeans.spi.editor.highlighting.HighlightsLayer;
71
import org.netbeans.spi.editor.highlighting.HighlightsLayerFactory;
71
import org.netbeans.spi.editor.highlighting.HighlightsLayerFactory;
72
import org.netbeans.spi.editor.highlighting.ReleasableHighlightsContainer;
72
import org.openide.ErrorManager;
73
import org.openide.ErrorManager;
73
import org.openide.util.Lookup;
74
import org.openide.util.Lookup;
74
import org.openide.util.LookupEvent;
75
import org.openide.util.LookupEvent;
 Lines 382-387    Link Here 
382
            if (inRebuildAllLayers) {
383
            if (inRebuildAllLayers) {
383
                return;
384
                return;
384
            }
385
            }
386
            DirectMergeContainer origTopHighlights;
387
            DirectMergeContainer origBottomHighlights;
385
            inRebuildAllLayers = true;
388
            inRebuildAllLayers = true;
386
            try {
389
            try {
387
                Document doc = pane.getDocument();
390
                Document doc = pane.getDocument();
 Lines 418-424    Link Here 
418
                    sortedLayers = sl;
421
                    sortedLayers = sl;
419
                }
422
                }
420
                // Filter layers by pane's filter - retains order
423
                // Filter layers by pane's filter - retains order
424
                List<? extends HighlightsLayer> origSortedLayers = sortedLayers;
421
                sortedLayers = paneFilter.filterLayers(sortedLayers);
425
                sortedLayers = paneFilter.filterLayers(sortedLayers);
426
                if (origSortedLayers.size() != sortedLayers.size()) { // Release filtered out layers
427
                    origSortedLayers = new ArrayList<>(origSortedLayers);
428
                    origSortedLayers.removeAll(sortedLayers);
429
                    for (HighlightsLayer layer : origSortedLayers) {
430
                        HighlightsContainer container = HighlightingSpiPackageAccessor.get().getHighlightsLayerAccessor(layer).getContainer();
431
                        if (container instanceof ReleasableHighlightsContainer) {
432
                            ((ReleasableHighlightsContainer)container).released();
433
                        }
434
                    }
435
                }
422
436
423
                int topStartIndex = 0;
437
                int topStartIndex = 0;
424
                for (int i = 0; i < sortedLayers.size(); i++) {
438
                for (int i = 0; i < sortedLayers.size(); i++) {
 Lines 454-459    Link Here 
454
                    topContainers = Collections.emptyList();
468
                    topContainers = Collections.emptyList();
455
                }
469
                }
456
470
471
                origBottomHighlights = bottomHighlights;
472
                origTopHighlights = topHighlights;
457
                bottomHighlights = new DirectMergeContainer(bottomContainers.toArray(
473
                bottomHighlights = new DirectMergeContainer(bottomContainers.toArray(
458
                        new HighlightsContainer[bottomContainers.size()]));
474
                        new HighlightsContainer[bottomContainers.size()]));
459
                topHighlights = new DirectMergeContainer(topContainers.toArray(
475
                topHighlights = new DirectMergeContainer(topContainers.toArray(
 Lines 461-466    Link Here 
461
            } finally {
477
            } finally {
462
                inRebuildAllLayers = false;
478
                inRebuildAllLayers = false;
463
            }
479
            }
480
            if (origBottomHighlights != null) {
481
                origBottomHighlights.released();
482
            }
483
            if (origTopHighlights != null) {
484
                origTopHighlights.released();
485
            }
464
            fireChangeListeners();
486
            fireChangeListeners();
465
        }
487
        }
466
        
488
        
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/view/DocumentViewOp.java (+1 lines)
 Lines 610-615    Link Here 
610
        viewHierarchyImpl.setDocumentView(null);
610
        viewHierarchyImpl.setDocumentView(null);
611
        uninstallFromViewport();
611
        uninstallFromViewport();
612
        textComponent.removePropertyChangeListener(this);
612
        textComponent.removePropertyChangeListener(this);
613
        viewUpdates.released();
613
        viewUpdates = null;
614
        viewUpdates = null;
614
    }
615
    }
615
    
616
    
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/view/EditorViewFactory.java (-5 / +37 lines)
 Lines 96-104    Link Here 
96
        return viewFactoryFactories;
96
        return viewFactoryFactories;
97
    }
97
    }
98
    
98
    
99
    private final DocumentView docView;
99
    private DocumentView docView;
100
    
100
    
101
    private final JTextComponent component;
101
    private JTextComponent component;
102
102
103
    private ViewBuilder viewBuilder;
103
    private ViewBuilder viewBuilder;
104
104
 Lines 115-121    Link Here 
115
    /**
115
    /**
116
     * Text component for which this view factory was constructed.
116
     * Text component for which this view factory was constructed.
117
     *
117
     *
118
     * @return non-null text component.
118
     * @return text component or null if this view factory is released.
119
     */
119
     */
120
    protected final JTextComponent textComponent() {
120
    protected final JTextComponent textComponent() {
121
        return component;
121
        return component;
 Lines 127-136    Link Here 
127
     * it may differ from <code>document()</code> result at certain points
127
     * it may differ from <code>document()</code> result at certain points
128
     * and it could lead to incorrect behavior.
128
     * and it could lead to incorrect behavior.
129
     *
129
     *
130
     * @return non-null document for which the view hierarchy was constructed.
130
     * @return document for which the view hierarchy was constructed
131
     *   or null if this view factory is released.
131
     */
132
     */
132
    protected final Document document() {
133
    protected final Document document() {
133
        return docView.getDocument();
134
        return (docView != null) ? docView.getDocument() : null;
134
    }
135
    }
135
136
136
    /**
137
    /**
 Lines 295-300    Link Here 
295
        this.viewBuilder = viewBuilder;
296
        this.viewBuilder = viewBuilder;
296
    }
297
    }
297
298
299
    public final boolean isReleased() {
300
        return (docView == null);
301
    }
302
303
    /**
304
     * Notification that this factory is no longer being used so it should
305
     * release its resources - for example detach all listeners.
306
     * <br/>
307
     * It's called upon document view receives setParent(null) which typically signals
308
     * that a new document view will be created for the particular editor pane.
309
     */
310
    protected void released() {
311
    }
312
    
313
    void releaseAll() {
314
        released(); // Is allowed to use docView and component info before subsequent clearing
315
        this.docView = null;
316
        this.component = null;
317
        // this.viewBuilder should be null-ed in try..finally manner
318
    }
319
    
320
    /**
321
     * Used by highlights view factory. If there would be a high demand for this method
322
     * it might become public although the view factories are used at times when
323
     * the document view is not in a "stable" state so the factories would have to be careful.
324
     * @return 
325
     */
326
    DocumentView documentView() {
327
        return docView;
328
    }
329
    
298
    @Override
330
    @Override
299
    public String toString() {
331
    public String toString() {
300
        ViewBuilder vb = viewBuilder;
332
        ViewBuilder vb = viewBuilder;
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/view/HighlightsViewFactory.java (-4 / +7 lines)
 Lines 108-115    Link Here 
108
    private static final int RTL_CHAR_TYPE = 2;
108
    private static final int RTL_CHAR_TYPE = 2;
109
    private static final int TAB_CHAR_TYPE = 3;
109
    private static final int TAB_CHAR_TYPE = 3;
110
    
110
    
111
    private final DocumentView docView;
112
113
    private final HighlightingManager highlightingManager;
111
    private final HighlightingManager highlightingManager;
114
112
115
    private HighlightsContainer highlightsContainer;
113
    private HighlightsContainer highlightsContainer;
 Lines 154-164    Link Here 
154
    
152
    
155
    public HighlightsViewFactory(View documentView) {
153
    public HighlightsViewFactory(View documentView) {
156
        super(documentView);
154
        super(documentView);
157
        this.docView = (DocumentView) documentView;
158
        highlightingManager = HighlightingManager.getInstance(textComponent());
155
        highlightingManager = HighlightingManager.getInstance(textComponent());
159
        highlightingManager.addChangeListener(new ChangeListener() {
156
        highlightingManager.addChangeListener(new ChangeListener() {
160
            @Override
157
            @Override
161
            public void stateChanged(ChangeEvent e) { // Layers in highlighting manager changed
158
            public void stateChanged(ChangeEvent e) { // Layers in highlighting manager changed
159
                if (isReleased()) {
160
                    return;
161
                }
162
                notifyStaleCreation();
162
                notifyStaleCreation();
163
                updateHighlightsContainer();
163
                updateHighlightsContainer();
164
                fireEvent(EditorViewFactoryChange.createList(0, document().getLength() + 1,
164
                fireEvent(EditorViewFactoryChange.createList(0, document().getLength() + 1,
 Lines 260-266    Link Here 
260
                    TextLayout origTextLayout = origHView.getTextLayout();
260
                    TextLayout origTextLayout = origHView.getTextLayout();
261
                    if (origTextLayout != null) {
261
                    if (origTextLayout != null) {
262
                        if (ViewHierarchyImpl.CHECK_LOG.isLoggable(Level.FINE)) {
262
                        if (ViewHierarchyImpl.CHECK_LOG.isLoggable(Level.FINE)) {
263
                            String origText = docView.getTextLayoutVerifier().get(origTextLayout);
263
                            String origText = documentView().getTextLayoutVerifier().get(origTextLayout);
264
                            if (origText != null) {
264
                            if (origText != null) {
265
                                CharSequence text = docText.subSequence(startOffset, startOffset + length);
265
                                CharSequence text = docText.subSequence(startOffset, startOffset + length);
266
                                if (!CharSequenceUtilities.textEquals(text, origText)) {
266
                                if (!CharSequenceUtilities.textEquals(text, origText)) {
 Lines 360-365    Link Here 
360
360
361
    @Override
361
    @Override
362
    public void highlightChanged(final HighlightsChangeEvent evt) {
362
    public void highlightChanged(final HighlightsChangeEvent evt) {
363
        if (isReleased()) {
364
            return;
365
        }
363
        // Since still many highlighting layers fire changes without document lock acquired
366
        // Since still many highlighting layers fire changes without document lock acquired
364
        // do an extra read lock so that view hierarchy surely operates under document lock
367
        // do an extra read lock so that view hierarchy surely operates under document lock
365
        document().render(new Runnable() {
368
        document().render(new Runnable() {
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/view/ViewUpdates.java (+8 lines)
 Lines 168-173    Link Here 
168
                    new Object[] { docView.getTextComponent(), Arrays.asList(viewFactories) });
168
                    new Object[] { docView.getTextComponent(), Arrays.asList(viewFactories) });
169
        }
169
        }
170
    }
170
    }
171
    
172
    void released() {
173
        if (viewFactories != null) {
174
            for (EditorViewFactory viewFactory : viewFactories) {
175
                viewFactory.releaseAll();
176
            }
177
        }
178
    }
171
179
172
    /**
180
    /**
173
     * Start view building process (it must be followed by finishBuildViews() in try-finally).
181
     * Start view building process (it must be followed by finishBuildViews() in try-finally).
(-)a/editor.lib2/src/org/netbeans/spi/editor/highlighting/ReleasableHighlightsContainer.java (+59 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2015 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2015 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.editor.highlighting;
43
44
/**
45
 * Highlights container that wishes to free its resources once the highlighting manager
46
 * stops using it.
47
 *
48
 * @author Miloslav Metelka
49
 * @since 2.4
50
 */
51
public interface ReleasableHighlightsContainer extends HighlightsContainer {
52
    
53
    /**
54
     * Called once the highlighting manager rebuilds its layers so this
55
     * layer is no longer being used.
56
     */
57
    void released();
58
    
59
}
(-)a/editor.lib2/test/unit/src/org/netbeans/modules/editor/lib2/highlighting/HighlightingManagerTest.java (-1 / +40 lines)
 Lines 70-76    Link Here 
70
import org.netbeans.spi.editor.highlighting.HighlightsLayer;
70
import org.netbeans.spi.editor.highlighting.HighlightsLayer;
71
import org.netbeans.spi.editor.highlighting.HighlightsLayerFactory;
71
import org.netbeans.spi.editor.highlighting.HighlightsLayerFactory;
72
import org.netbeans.spi.editor.highlighting.HighlightsSequence;
72
import org.netbeans.spi.editor.highlighting.HighlightsSequence;
73
import org.netbeans.spi.editor.highlighting.ReleasableHighlightsContainer;
73
import org.netbeans.spi.editor.highlighting.ZOrder;
74
import org.netbeans.spi.editor.highlighting.ZOrder;
75
import org.netbeans.spi.editor.highlighting.support.AbstractHighlightsContainer;
74
import org.openide.util.Lookup;
76
import org.openide.util.Lookup;
75
77
76
/**
78
/**
 Lines 351-357    Link Here 
351
        bagB.addHighlight(15, 25, attribsB);
353
        bagB.addHighlight(15, 25, attribsB);
352
        bagC.addHighlight(50, 60, attribsC);
354
        bagC.addHighlight(50, 60, attribsC);
353
        bagD.addHighlight(55, 65, attribsD);
355
        bagD.addHighlight(55, 65, attribsD);
354
356
        
355
        SingletonLayerFactory layerA = new SingletonLayerFactory("layerA", ZOrder.DEFAULT_RACK, true, bagA);
357
        SingletonLayerFactory layerA = new SingletonLayerFactory("layerA", ZOrder.DEFAULT_RACK, true, bagA);
356
        SingletonLayerFactory layerB = new SingletonLayerFactory("layerB", ZOrder.DEFAULT_RACK.forPosition(1), false, bagB);
358
        SingletonLayerFactory layerB = new SingletonLayerFactory("layerB", ZOrder.DEFAULT_RACK.forPosition(1), false, bagB);
357
        SingletonLayerFactory layerC = new SingletonLayerFactory("layerC", ZOrder.DEFAULT_RACK.forPosition(2), true, bagC);
359
        SingletonLayerFactory layerC = new SingletonLayerFactory("layerC", ZOrder.DEFAULT_RACK.forPosition(2), true, bagC);
 Lines 634-639    Link Here 
634
            assertFalse("There should be no highlights", fixed.moveNext());
636
            assertFalse("There should be no highlights", fixed.moveNext());
635
        }
637
        }
636
    }
638
    }
639
640
    public void testReleaseLayers() {
641
        final String mimeType = "text/plain";
642
        TestReleaseHighlightsContainer releasableContainer = new TestReleaseHighlightsContainer();
643
        SingletonLayerFactory releasableLayer = new SingletonLayerFactory(
644
                "releasableLayer", ZOrder.DEFAULT_RACK.forPosition(1), true, releasableContainer);
645
646
        MemoryMimeDataProvider.reset(null);
647
        MemoryMimeDataProvider.addInstances(mimeType, releasableLayer);
648
649
        JEditorPane pane = new JEditorPane(mimeType, "Hello");
650
        HighlightingManager hm = HighlightingManager.getInstance(pane); // Ensure layers get created
651
        hm.getHighlights(HighlightsLayerFilter.IDENTITY);
652
        pane.setEditorKit(new SimpleKit(mimeType));
653
        // Do not check against concrete release count since there are e.g. mime lookup rebuild notifications
654
        // that lead to HM.rebuildAllLayers() which increases the releaseCount too.
655
        assertTrue("Highlights container releasing not performed after pane.setEditorKit()", releasableContainer.releaseCount > 0);
656
    }
637
    
657
    
638
    // test getting independent HCs for different JEditorPanes with the same mime type
658
    // test getting independent HCs for different JEditorPanes with the same mime type
639
    
659
    
 Lines 870-873    Link Here 
870
            return filteredLayers;
890
            return filteredLayers;
871
        }
891
        }
872
    };
892
    };
893
    
894
    private static final class TestReleaseHighlightsContainer extends AbstractHighlightsContainer
895
            implements ReleasableHighlightsContainer
896
    {
897
        
898
        public int releaseCount;
899
        
900
        @Override
901
        public HighlightsSequence getHighlights(int startOffset, int endOffset) {
902
            return HighlightsSequence.EMPTY;
903
        }
904
905
        @Override
906
        public void released() {
907
            releaseCount++;
908
        }
909
        
910
    }
911
    
873
}
912
}

Return to bug 254701
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo