14
14
package org .eclipse .jst .jsp .core .internal .contentmodel ;
15
15
16
16
import java .util .ArrayList ;
17
+ import java .util .Collections ;
17
18
import java .util .HashMap ;
18
19
import java .util .Iterator ;
19
20
import java .util .List ;
20
21
import java .util .Map ;
21
- import java .util .Map .Entry ;
22
22
23
23
import org .eclipse .core .filebuffers .FileBuffers ;
24
24
import org .eclipse .core .filebuffers .IDocumentSetupParticipant ;
@@ -56,7 +56,6 @@ public class TaglibController implements IDocumentSetupParticipant, IDocumentSet
56
56
57
57
class DocumentInfo implements ITaglibIndexListener {
58
58
IStructuredDocument document ;
59
- ITextFileBuffer textFileBuffer ;
60
59
IPath location ;
61
60
LocationKind locationKind ;
62
61
TLDCMDocumentManager tldDocumentManager ;
@@ -128,20 +127,19 @@ public void bufferCreated(IFileBuffer buffer) {
128
127
info = _instance .fDocumentMap .get (document );
129
128
}
130
129
if (info != null ) {
131
- // remember the buffer now
132
- info .textFileBuffer = (ITextFileBuffer ) buffer ;
130
+ _instance .fTextFileBufferMap .put (buffer , info );
133
131
}
134
132
else {
135
133
info = new DocumentInfo ();
136
134
info .document = (IStructuredDocument ) document ;
137
- info .textFileBuffer = (ITextFileBuffer ) buffer ;
138
135
info .location = buffer .getLocation ();
139
136
info .locationKind = LocationKind .NORMALIZE ;
140
137
info .tldDocumentManager = new TLDCMDocumentManager ();
141
138
info .tldDocumentManager .setSourceParser ((XMLSourceParser ) info .document .getParser ());
142
139
synchronized (_instance .fDocumentMap ) {
143
140
_instance .fDocumentMap .put (document , info );
144
141
}
142
+ _instance .fTextFileBufferMap .put (buffer , info );
145
143
if (document instanceof BasicStructuredDocument && document .getLength () > 0 ) {
146
144
((BasicStructuredDocument ) document ).reparse (this );
147
145
}
@@ -156,31 +154,21 @@ public void bufferCreated(IFileBuffer buffer) {
156
154
* @see org.eclipse.core.filebuffers.IFileBufferListener#bufferDisposed(org.eclipse.core.filebuffers.IFileBuffer)
157
155
*/
158
156
public void bufferDisposed (IFileBuffer buffer ) {
157
+ DocumentInfo info ;
158
+
159
159
if (buffer instanceof ITextFileBuffer ) {
160
160
IDocument document = ((ITextFileBuffer ) buffer ).getDocument ();
161
161
synchronized (_instance .fJSPdocuments ) {
162
162
if (!_instance .fJSPdocuments .remove (document ))
163
163
return ;
164
164
}
165
165
}
166
-
167
- synchronized (fDocumentMap ) {
168
- Iterator <Entry <IDocument , DocumentInfo >> infos = fDocumentMap .entrySet ().iterator ();
169
- while (infos .hasNext ()) {
170
- Entry <IDocument , DocumentInfo > entry = infos .next ();
171
- /**
172
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=222137
173
- *
174
- * Might be null if setup() has been called but
175
- * bufferCreated() has not, yet.
176
- */
177
- DocumentInfo info = entry .getValue ();
178
- if (info .textFileBuffer != null && info .textFileBuffer .equals (buffer )) {
179
- info .tldDocumentManager .clearCache ();
180
- TaglibIndex .removeTaglibIndexListener (info );
181
- infos .remove ();
182
- break ;
183
- }
166
+ info = _instance .fTextFileBufferMap .remove (buffer );
167
+ if (info != null ) {
168
+ info .tldDocumentManager .clearCache ();
169
+ TaglibIndex .removeTaglibIndexListener (info );
170
+ synchronized (fDocumentMap ) {
171
+ fDocumentMap .remove (info .document );
184
172
}
185
173
}
186
174
}
@@ -310,7 +298,7 @@ public synchronized static void startup() {
310
298
IFileBufferListener fBufferListener ;
311
299
312
300
Map <IDocument , DocumentInfo > fDocumentMap ;
313
-
301
+ Map < IFileBuffer , DocumentInfo > fTextFileBufferMap ;
314
302
List <IDocument > fJSPdocuments ;
315
303
316
304
/*
@@ -322,6 +310,7 @@ public TaglibController() {
322
310
fBufferListener = new FileBufferListener ();
323
311
fJSPdocuments = new ArrayList <>(1 );
324
312
fDocumentMap = new HashMap <>(1 );
313
+ fTextFileBufferMap = Collections .synchronizedMap (new HashMap <>(1 ));
325
314
}
326
315
327
316
@@ -359,7 +348,6 @@ public void setup(IDocument document, IPath location, LocationKind locationKind)
359
348
360
349
DocumentInfo info = new DocumentInfo ();
361
350
info .document = (IStructuredDocument ) document ;
362
- info .textFileBuffer = null ; // will be supplied later
363
351
info .location = location ;
364
352
info .locationKind = locationKind ;
365
353
info .tldDocumentManager = new TLDCMDocumentManager ();
0 commit comments