Lines 194-199
Link Here
|
194 |
|
194 |
|
195 |
/** the document for this manager or null if the manager is not in memory */ |
195 |
/** the document for this manager or null if the manager is not in memory */ |
196 |
transient private StyledDocument doc; |
196 |
transient private StyledDocument doc; |
|
|
197 |
/** document that this thread should use */ |
198 |
private static ThreadLocal DOCUMENT = new ThreadLocal (); |
197 |
|
199 |
|
198 |
|
200 |
|
199 |
static final long serialVersionUID =-4374030124265110801L; |
201 |
static final long serialVersionUID =-4374030124265110801L; |
Lines 273-278
Link Here
|
273 |
doc = null; |
275 |
doc = null; |
274 |
} |
276 |
} |
275 |
|
277 |
|
|
|
278 |
/** Gets the document this object should work on. |
279 |
* @return docoument or null |
280 |
*/ |
281 |
private StyledDocument getDoc () { |
282 |
Object d = DOCUMENT.get (); |
283 |
if (d instanceof StyledDocument) { |
284 |
return (StyledDocument)d; |
285 |
} |
286 |
if (d == this) { |
287 |
return null; |
288 |
} |
289 |
return this.doc; |
290 |
} |
291 |
|
276 |
/** Puts/gets positions to/from memory. It also provides full |
292 |
/** Puts/gets positions to/from memory. It also provides full |
277 |
* pass sweep of the data structure (inlined in the code). |
293 |
* pass sweep of the data structure (inlined in the code). |
278 |
* @param toMemory puts positions to memory if <code>true</code>, |
294 |
* @param toMemory puts positions to memory if <code>true</code>, |
Lines 363-372
Link Here
|
363 |
pos.kind.toMemory(pos.insertAfter)); |
379 |
pos.kind.toMemory(pos.insertAfter)); |
364 |
} |
380 |
} |
365 |
*/ |
381 |
*/ |
366 |
// [pnejedly] needed to prevent doc variable modification while adding position, #40766 |
382 |
kind = (Kind)new DocumentRenderer(DocumentRenderer.ADD_POSITION, pos).renderToObject(); |
367 |
synchronized(support.docStateLock) { |
|
|
368 |
kind = (Kind)new DocumentRenderer(DocumentRenderer.ADD_POSITION, pos).renderToObject(); |
369 |
} |
370 |
checkQueue(); |
383 |
checkQueue(); |
371 |
|
384 |
|
372 |
return kind; |
385 |
return kind; |
Lines 510-516
Link Here
|
510 |
"Illegal PositionKind: " + pos + "[offset=" // NOI18N |
523 |
"Illegal PositionKind: " + pos + "[offset=" // NOI18N |
511 |
+ offset + ",line=" // NOI18N |
524 |
+ offset + ",line=" // NOI18N |
512 |
+ line + ",column=" + column + "] in " // NOI18N |
525 |
+ line + ",column=" + column + "] in " // NOI18N |
513 |
+ doc + " used by " + support + "." // NOI18N |
526 |
+ getDoc () + " used by " + support + "." // NOI18N |
514 |
); |
527 |
); |
515 |
} |
528 |
} |
516 |
|
529 |
|
Lines 563-569
Link Here
|
563 |
"Illegal OutKind[offset=" // NOI18N |
576 |
"Illegal OutKind[offset=" // NOI18N |
564 |
+ offset + ",line=" // NOI18N |
577 |
+ offset + ",line=" // NOI18N |
565 |
+ line + ",column=" + column + "] in " // NOI18N |
578 |
+ line + ",column=" + column + "] in " // NOI18N |
566 |
+ doc + " used by " + support + "." // NOI18N |
579 |
+ getDoc () + " used by " + support + "." // NOI18N |
567 |
); |
580 |
); |
568 |
} |
581 |
} |
569 |
|
582 |
|
Lines 602-608
Link Here
|
602 |
"Illegal OutKind[offset=" // NOI18N |
615 |
"Illegal OutKind[offset=" // NOI18N |
603 |
+ offset + ",line=" // NOI18N |
616 |
+ offset + ",line=" // NOI18N |
604 |
+ line + ",column=" + column + "] in " // NOI18N |
617 |
+ line + ",column=" + column + "] in " // NOI18N |
605 |
+ doc + " used by " + support + "." // NOI18N |
618 |
+ getDoc () + " used by " + support + "." // NOI18N |
606 |
); |
619 |
); |
607 |
} |
620 |
} |
608 |
|
621 |
|
Lines 624-630
Link Here
|
624 |
if(offset < 0) { |
637 |
if(offset < 0) { |
625 |
throw new IndexOutOfBoundsException( |
638 |
throw new IndexOutOfBoundsException( |
626 |
"Illegal OffsetKind[offset=" // NOI18N |
639 |
"Illegal OffsetKind[offset=" // NOI18N |
627 |
+ offset + "] in " + doc + " used by " // NOI18N |
640 |
+ offset + "] in " + getDoc () + " used by " // NOI18N |
628 |
+ support + "." // NOI18N |
641 |
+ support + "." // NOI18N |
629 |
); |
642 |
); |
630 |
} |
643 |
} |
Lines 658-664
Link Here
|
658 |
if(offset < 0) { |
671 |
if(offset < 0) { |
659 |
throw new IOException( |
672 |
throw new IOException( |
660 |
"Illegal OffsetKind[offset=" // NOI18N |
673 |
"Illegal OffsetKind[offset=" // NOI18N |
661 |
+ offset + "] in " + doc + " used by " // NOI18N |
674 |
+ offset + "] in " + getDoc () + " used by " // NOI18N |
662 |
+ support + "." // NOI18N |
675 |
+ support + "." // NOI18N |
663 |
); |
676 |
); |
664 |
} |
677 |
} |
Lines 683-689
Link Here
|
683 |
throw new IndexOutOfBoundsException( |
696 |
throw new IndexOutOfBoundsException( |
684 |
"Illegal LineKind[line=" // NOI18N |
697 |
"Illegal LineKind[line=" // NOI18N |
685 |
+ line + ",column=" + column + "] in " // NOI18N |
698 |
+ line + ",column=" + column + "] in " // NOI18N |
686 |
+ doc + " used by " + support + "." // NOI18N |
699 |
+ getDoc () + " used by " + support + "." // NOI18N |
687 |
); |
700 |
); |
688 |
} |
701 |
} |
689 |
|
702 |
|
Lines 739-745
Link Here
|
739 |
throw new IOException( |
752 |
throw new IOException( |
740 |
"Illegal LineKind[line=" // NOI18N |
753 |
"Illegal LineKind[line=" // NOI18N |
741 |
+ line + ",column=" + column + "] in " // NOI18N |
754 |
+ line + ",column=" + column + "] in " // NOI18N |
742 |
+ doc + " used by " + support + "." // NOI18N |
755 |
+ getDoc () + " used by " + support + "." // NOI18N |
743 |
); |
756 |
); |
744 |
} |
757 |
} |
745 |
|
758 |
|
Lines 864-873
Link Here
|
864 |
} |
877 |
} |
865 |
|
878 |
|
866 |
void render() { |
879 |
void render() { |
867 |
if (doc != null) { |
880 |
StyledDocument d = getDoc (); |
868 |
doc.render(this); |
881 |
Object prev = DOCUMENT.get (); |
869 |
} else { |
882 |
try { |
870 |
this.run(); |
883 |
if (d != null) { |
|
|
884 |
DOCUMENT.set (d); |
885 |
d.render(this); |
886 |
} else { |
887 |
DOCUMENT.set (Manager.this); |
888 |
this.run(); |
889 |
} |
890 |
} finally { |
891 |
DOCUMENT.set (prev); |
871 |
} |
892 |
} |
872 |
} |
893 |
} |
873 |
|
894 |
|
Lines 925-931
Link Here
|
925 |
try { |
946 |
try { |
926 |
int line = argKind.getLine(); |
947 |
int line = argKind.getLine(); |
927 |
int col = argKind.getColumn(); |
948 |
int col = argKind.getColumn(); |
928 |
Element lineRoot = NbDocument.findLineRootElement(doc); |
949 |
Element lineRoot = NbDocument.findLineRootElement(getDoc ()); |
929 |
if (line < lineRoot.getElementCount()) { |
950 |
if (line < lineRoot.getElementCount()) { |
930 |
Element lineElem = lineRoot.getElement(line); |
951 |
Element lineElem = lineRoot.getElement(line); |
931 |
int lineStartOffset = lineElem.getStartOffset(); |
952 |
int lineStartOffset = lineElem.getStartOffset(); |
Lines 942-961
Link Here
|
942 |
} |
963 |
} |
943 |
|
964 |
|
944 |
try { |
965 |
try { |
945 |
p = NbDocument.createPosition (doc, offset, |
966 |
p = NbDocument.createPosition (getDoc (), offset, |
946 |
argInsertAfter ? Position.Bias.Forward : Position.Bias.Backward); |
967 |
argInsertAfter ? Position.Bias.Forward : Position.Bias.Backward); |
947 |
} catch (BadLocationException e) { |
968 |
} catch (BadLocationException e) { |
948 |
p = doc.getEndPosition (); |
969 |
p = getDoc ().getEndPosition (); |
949 |
} |
970 |
} |
950 |
retObject = (PositionKind)new PositionKind (p); |
971 |
retObject = (PositionKind)new PositionKind (p); |
951 |
break; } |
972 |
break; } |
952 |
|
973 |
|
953 |
case POSITION_KIND_GET_LINE: { |
974 |
case POSITION_KIND_GET_LINE: { |
954 |
retInt = NbDocument.findLineNumber(doc, argKind.getOffset()); |
975 |
retInt = NbDocument.findLineNumber(getDoc (), argKind.getOffset()); |
955 |
break; } |
976 |
break; } |
956 |
|
977 |
|
957 |
case POSITION_KIND_GET_COLUMN: { |
978 |
case POSITION_KIND_GET_COLUMN: { |
958 |
retInt = NbDocument.findLineColumn(doc, argKind.getOffset()); |
979 |
retInt = NbDocument.findLineColumn(getDoc (), argKind.getOffset()); |
959 |
break; } |
980 |
break; } |
960 |
|
981 |
|
961 |
case POSITION_KIND_WRITE: |
982 |
case POSITION_KIND_WRITE: |
Lines 980-992
Link Here
|
980 |
case LINE_KIND_TO_MEMORY: { |
1001 |
case LINE_KIND_TO_MEMORY: { |
981 |
// try to find the right position |
1002 |
// try to find the right position |
982 |
try { |
1003 |
try { |
983 |
retObject = NbDocument.createPosition (doc, |
1004 |
retObject = NbDocument.createPosition (getDoc (), |
984 |
NbDocument.findLineOffset (doc, argLine) + argColumn, |
1005 |
NbDocument.findLineOffset (getDoc (), argLine) + argColumn, |
985 |
argInsertAfter ? Position.Bias.Forward : Position.Bias.Backward); |
1006 |
argInsertAfter ? Position.Bias.Forward : Position.Bias.Backward); |
986 |
} catch (BadLocationException e) { |
1007 |
} catch (BadLocationException e) { |
987 |
retObject = doc.getEndPosition (); |
1008 |
retObject = getDoc ().getEndPosition (); |
988 |
} catch (IndexOutOfBoundsException e) { |
1009 |
} catch (IndexOutOfBoundsException e) { |
989 |
retObject = doc.getEndPosition(); |
1010 |
retObject = getDoc ().getEndPosition(); |
990 |
} |
1011 |
} |
991 |
break; } |
1012 |
break; } |
992 |
|
1013 |
|
Lines 1024-1030
Link Here
|
1024 |
support.howToReproduceDeadlock40766(false); |
1045 |
support.howToReproduceDeadlock40766(false); |
1025 |
head.next = new ChainItem(argPos, queue, head.next); |
1046 |
head.next = new ChainItem(argPos, queue, head.next); |
1026 |
|
1047 |
|
1027 |
retObject = (doc == null ? |
1048 |
retObject = (getDoc () == null ? |
1028 |
argPos.kind : |
1049 |
argPos.kind : |
1029 |
argPos.kind.toMemory(argPos.insertAfter)); |
1050 |
argPos.kind.toMemory(argPos.insertAfter)); |
1030 |
} |
1051 |
} |