This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 222161
Collapse All | Expand All

(-)a/php.editor/src/org/netbeans/modules/php/editor/nav/OccurrencesFinderImpl.java (-23 / +43 lines)
Lines 49-54 Link Here
49
import java.util.Map;
49
import java.util.Map;
50
import java.util.Set;
50
import java.util.Set;
51
import java.util.TreeSet;
51
import java.util.TreeSet;
52
import java.util.concurrent.CountDownLatch;
53
import java.util.logging.Level;
54
import java.util.logging.Logger;
52
import java.util.prefs.Preferences;
55
import java.util.prefs.Preferences;
53
import org.netbeans.api.lexer.Token;
56
import org.netbeans.api.lexer.Token;
54
import org.netbeans.api.lexer.TokenHierarchy;
57
import org.netbeans.api.lexer.TokenHierarchy;
Lines 70-75 Link Here
70
import org.netbeans.modules.php.editor.model.OccurencesSupport;
73
import org.netbeans.modules.php.editor.model.OccurencesSupport;
71
import org.netbeans.modules.php.editor.options.MarkOccurencesSettings;
74
import org.netbeans.modules.php.editor.options.MarkOccurencesSettings;
72
import org.netbeans.modules.php.editor.parser.PHPParseResult;
75
import org.netbeans.modules.php.editor.parser.PHPParseResult;
76
import org.openide.util.RequestProcessor;
73
77
74
/**
78
/**
75
 *
79
 *
Lines 78-86 Link Here
78
 * @author Radek Matous
82
 * @author Radek Matous
79
 */
83
 */
80
public class OccurrencesFinderImpl extends OccurrencesFinder {
84
public class OccurrencesFinderImpl extends OccurrencesFinder {
85
    private static final RequestProcessor RP = new RequestProcessor(OccurrencesFinderImpl.class);
86
    private static final Logger LOGGER = Logger.getLogger(OccurrencesFinderImpl.class.getName());
81
    private Map<OffsetRange, ColoringAttributes> range2Attribs;
87
    private Map<OffsetRange, ColoringAttributes> range2Attribs;
82
    private int caretPosition;
88
    private int caretPosition;
83
    private volatile boolean cancelled;
89
    private volatile boolean cancelled;
90
    private CountDownLatch latch = new CountDownLatch(1);
84
91
85
    @Override
92
    @Override
86
    public void setCaretPosition(int position) {
93
    public void setCaretPosition(int position) {
Lines 89-94 Link Here
89
96
90
    @Override
97
    @Override
91
    public Map<OffsetRange, ColoringAttributes> getOccurrences() {
98
    public Map<OffsetRange, ColoringAttributes> getOccurrences() {
99
        try {
100
            latch.await();
101
        } catch (InterruptedException ex) {
102
            LOGGER.log(Level.FINE, null, ex);
103
        }
92
        return range2Attribs;
104
        return range2Attribs;
93
    }
105
    }
94
106
Lines 98-129 Link Here
98
    }
110
    }
99
111
100
    @Override
112
    @Override
101
    public void run(Result result, SchedulerEvent event) {
113
    public void run(final Result result, SchedulerEvent event) {
102
        //remove the last occurrences - the CSL caches the last found occurences for us
114
        latch = new CountDownLatch(1);
103
        range2Attribs = null;
115
        RP.post(new Runnable() {
104
116
105
        if (cancelled) {
117
            @Override
106
            cancelled = false;
118
            public void run() {
107
            return;
119
                //remove the last occurrences - the CSL caches the last found occurences for us
108
        }
120
                range2Attribs = null;
109
121
110
        Preferences node = MarkOccurencesSettings.getCurrentNode();
122
                if (cancelled) {
111
        Map<OffsetRange, ColoringAttributes> localRange2Attribs = new HashMap<OffsetRange, ColoringAttributes>();
123
                    cancelled = false;
112
        if (node.getBoolean(MarkOccurencesSettings.ON_OFF, true)) {
124
                    return;
113
            for (OffsetRange r : compute((ParserResult) result, caretPosition)) {
125
                }
114
                localRange2Attribs.put(r, ColoringAttributes.MARK_OCCURRENCES);
126
127
                Preferences node = MarkOccurencesSettings.getCurrentNode();
128
                Map<OffsetRange, ColoringAttributes> localRange2Attribs = new HashMap<OffsetRange, ColoringAttributes>();
129
                if (node.getBoolean(MarkOccurencesSettings.ON_OFF, true)) {
130
                    for (OffsetRange r : compute((ParserResult) result, caretPosition)) {
131
                        localRange2Attribs.put(r, ColoringAttributes.MARK_OCCURRENCES);
132
                    }
133
                }
134
135
                if (cancelled) {
136
                    cancelled = false;
137
                    return;
138
                }
139
140
                if (!node.getBoolean(MarkOccurencesSettings.KEEP_MARKS, true) || localRange2Attribs.size() > 0) {
141
                    //store the occurrences if not empty, return null in getOccurrences() otherwise
142
                    range2Attribs = localRange2Attribs;
143
                }
144
                latch.countDown();
115
            }
145
            }
116
        }
146
        });
117
118
        if (cancelled) {
119
            cancelled = false;
120
            return;
121
        }
122
123
        if (!node.getBoolean(MarkOccurencesSettings.KEEP_MARKS, true) || localRange2Attribs.size() > 0) {
124
            //store the occurrences if not empty, return null in getOccurrences() otherwise
125
            range2Attribs = localRange2Attribs;
126
        }
127
    }
147
    }
128
148
129
    static Collection<OffsetRange> compute(final ParserResult parameter, final int offset) {
149
    static Collection<OffsetRange> compute(final ParserResult parameter, final int offset) {

Return to bug 222161