Skip to content
Draft

WIP #3686

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions bundles/org.eclipse.core.filebuffers/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.core.filebuffers; singleton:=true
Bundle-Version: 3.8.500.qualifier
Bundle-Version: 3.8.600.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package:
org.eclipse.core.filebuffers,
org.eclipse.core.filebuffers.manipulation,
org.eclipse.core.internal.filebuffers;x-internal:=true
Require-Bundle:
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
org.eclipse.core.resources;bundle-version="[3.5.0,4.0.0)";resolution:=optional,
org.eclipse.text;bundle-version="[3.5.0,4.0.0)",
org.eclipse.core.filesystem;bundle-version="[1.2.0,2.0.0)"
org.eclipse.core.runtime;bundle-version="[3.34.0,4.0.0)",
org.eclipse.core.resources;bundle-version="[3.23.0,4.0.0)";resolution:=optional,
org.eclipse.text;bundle-version="[3.15.0,4.0.0)",
org.eclipse.core.filesystem;bundle-version="[1.11.0,2.0.0)"
Bundle-RequiredExecutionEnvironment: JavaSE-17
Automatic-Module-Name: org.eclipse.core.filebuffers
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,7 @@ public long getModificationStamp() {

@Override
public void replace(int offset, int length, String text) throws BadLocationException {
Object lockObject= getLockObject();
if (lockObject == null) {
super.replace(offset, length, text);
return;
}
synchronized (lockObject) {
super.replace(offset, length, text);
}
super.replace(offset, length, text);
}

@Override
Expand All @@ -267,21 +260,19 @@ public void replace(int offset, int length, String text, long modificationStamp)
super.replace(offset, length, text, modificationStamp);
return;
}
synchronized (lockObject) {
super.replace(offset, length, text, modificationStamp);
try {
stopListenerNotification();
synchronized (lockObject) {
super.replace(offset, length, text, modificationStamp);
}
} finally {
resumeListenerNotification();
}
}

@Override
public void set(String text) {
Object lockObject= getLockObject();
if (lockObject == null) {
super.set(text);
return;
}
synchronized (lockObject) {
super.set(text);
}
super.set(text);
}

@Override
Expand All @@ -291,11 +282,22 @@ public void set(String text, long modificationStamp) {
super.set(text, modificationStamp);
return;
}
synchronized (lockObject) {
super.set(text, modificationStamp);
try {
stopListenerNotification();
synchronized (lockObject) {
super.set(text, modificationStamp);
}
} finally {
resumeListenerNotification();
}
}

@Override
protected void doFireDocumentChanged2(DocumentEvent event) {
// TODO this code could use a job to dispatch updates to listeners asynchronously
super.doFireDocumentChanged2(event);
}

@Override
public void addPosition(String category, Position position) throws BadLocationException, BadPositionCategoryException {
Object lockObject= getLockObject();
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.eclipse.text/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.text
Bundle-Version: 3.14.600.qualifier
Bundle-Version: 3.15.0.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.PatternSyntaxException;

import org.eclipse.core.runtime.Assert;
Expand Down Expand Up @@ -115,17 +118,17 @@ static private class RegisteredReplace {
* The list of post notification changes
* @since 2.0
*/
private List<RegisteredReplace> fPostNotificationChanges;
private volatile List<RegisteredReplace> fPostNotificationChanges;
/**
* The reentrance count for post notification changes.
* @since 2.0
*/
private int fReentranceCount= 0;
private volatile int fReentranceCount;
/**
* Indicates whether post notification change processing has been stopped.
* @since 2.0
*/
private int fStoppedCount= 0;
private volatile int fStoppedCount;
/**
* Indicates whether the registration of post notification changes should be ignored.
* @since 2.1
Expand All @@ -135,22 +138,22 @@ static private class RegisteredReplace {
* Indicates whether the notification of listeners has been stopped.
* @since 2.1
*/
private int fStoppedListenerNotification= 0;
private final AtomicInteger fStoppedListenerNotification;
/**
* The document event to be sent after listener notification has been resumed.
* @since 2.1
* The document event list to be sent after listener notification has been resumed.
* @since 3.15
*/
private DocumentEvent fDeferredDocumentEvent;
private final List<DocumentEvent> fDeferredDocumentEvents;
/**
* The registered document partitioners.
* @since 3.0
*/
private Map<String, IDocumentPartitioner> fDocumentPartitioners;
/**
* The partitioning changed event.
* @since 3.0
* @since 3.15.0
*/
private DocumentPartitioningChangedEvent fDocumentPartitioningChangedEvent;
private final AtomicReference<DocumentPartitioningChangedEvent> fDocumentPartitioningChangedEvent;
/**
* The find/replace document adapter.
* @since 3.0
Expand All @@ -175,7 +178,7 @@ static private class RegisteredReplace {
* Keeps track of next modification stamp.
* @since 3.1.1
*/
private long fNextModificationStamp= IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP;
private final AtomicLong fNextModificationStamp= new AtomicLong(IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP);
/**
* This document's default line delimiter.
* @since 3.1
Expand All @@ -191,6 +194,9 @@ static private class RegisteredReplace {
*/
protected AbstractDocument() {
fModificationStamp= getNextModificationStamp();
fStoppedListenerNotification = new AtomicInteger();
fDeferredDocumentEvents = new CopyOnWriteArrayList<>();
fDocumentPartitioningChangedEvent = new AtomicReference<>();
}


Expand Down Expand Up @@ -437,7 +443,7 @@ public boolean containsPositionCategory(String category) {
* @see IDocument#computeIndexInCategory(String, int)
* @deprecated As of 3.4, replaced by {@link #computeIndexInPositionList(List, int, boolean)}
*/
@Deprecated
@Deprecated(forRemoval = true, since= "3.15.0")
protected int computeIndexInPositionList(List<? extends Position> positions, int offset) {
return computeIndexInPositionList(positions, offset, true);
}
Expand Down Expand Up @@ -542,7 +548,7 @@ public int computeIndexInCategory(String category, int offset) throws BadLocatio
*
* @deprecated as of 2.0. Use <code>fireDocumentPartitioningChanged(IRegion)</code> instead.
*/
@Deprecated
@Deprecated(forRemoval = true, since= "3.15.0")
protected void fireDocumentPartitioningChanged() {
if (fDocumentPartitioningListeners == null) {
return;
Expand All @@ -565,7 +571,7 @@ protected void fireDocumentPartitioningChanged() {
* <code>fireDocumentPartitioningChanged(DocumentPartitioningChangedEvent)</code>
* instead.
*/
@Deprecated
@Deprecated(forRemoval = true, since= "3.15.0")
protected void fireDocumentPartitioningChanged(IRegion region) {
if (fDocumentPartitioningListeners == null) {
return;
Expand Down Expand Up @@ -670,7 +676,7 @@ protected void fireDocumentAboutToBeChanged(DocumentEvent event) {
protected void updateDocumentStructures(DocumentEvent event) {

if (fDocumentPartitioners != null) {
fDocumentPartitioningChangedEvent= new DocumentPartitioningChangedEvent(this);
DocumentPartitioningChangedEvent newValue= new DocumentPartitioningChangedEvent(this);
for (Entry<String, IDocumentPartitioner> entry : fDocumentPartitioners.entrySet()) {

String partitioning= entry.getKey();
Expand All @@ -685,14 +691,15 @@ protected void updateDocumentStructures(DocumentEvent event) {
if (partitioner instanceof IDocumentPartitionerExtension extension) {
IRegion r= extension.documentChanged2(event);
if (r != null) {
fDocumentPartitioningChangedEvent.setPartitionChange(partitioning, r.getOffset(), r.getLength());
newValue.setPartitionChange(partitioning, r.getOffset(), r.getLength());
}
} else {
if (partitioner.documentChanged(event)) {
fDocumentPartitioningChangedEvent.setPartitionChange(partitioning, 0, event.getDocument().getLength());
newValue.setPartitionChange(partitioning, 0, event.getDocument().getLength());
}
}
}
fDocumentPartitioningChangedEvent.set(newValue);
}

if (!fPositions.isEmpty()) {
Expand All @@ -709,8 +716,9 @@ protected void updateDocumentStructures(DocumentEvent event) {
* @param event the event to be sent out.
*/
protected void doFireDocumentChanged(DocumentEvent event) {
boolean changed= fDocumentPartitioningChangedEvent != null && !fDocumentPartitioningChangedEvent.isEmpty();
IRegion change= changed ? fDocumentPartitioningChangedEvent.getCoverage() : null;
DocumentPartitioningChangedEvent changedEvent= fDocumentPartitioningChangedEvent.get();
boolean changed= changedEvent != null && !changedEvent.isEmpty();
IRegion change= changed ? changedEvent.getCoverage() : null;
doFireDocumentChanged(event, changed, change);
}

Expand All @@ -725,7 +733,7 @@ protected void doFireDocumentChanged(DocumentEvent event) {
* @since 2.0
* @deprecated as of 3.0. Use <code>doFireDocumentChanged2(DocumentEvent)</code> instead; this method will be removed.
*/
@Deprecated
@Deprecated(forRemoval = true, since= "3.15.0")
protected void doFireDocumentChanged(DocumentEvent event, boolean firePartitionChange, IRegion partitionChange) {
doFireDocumentChanged2(event);
}
Expand All @@ -743,8 +751,7 @@ protected void doFireDocumentChanged(DocumentEvent event, boolean firePartitionC
*/
protected void doFireDocumentChanged2(DocumentEvent event) {

DocumentPartitioningChangedEvent p= fDocumentPartitioningChangedEvent;
fDocumentPartitioningChangedEvent= null;
DocumentPartitioningChangedEvent p= fDocumentPartitioningChangedEvent.getAndSet(null);
if (p != null && !p.isEmpty()) {
fireDocumentPartitioningChanged(p);
}
Expand Down Expand Up @@ -786,10 +793,10 @@ protected void doFireDocumentChanged2(DocumentEvent event) {
protected void fireDocumentChanged(DocumentEvent event) {
updateDocumentStructures(event);

if (fStoppedListenerNotification == 0) {
if (fStoppedListenerNotification.get() == 0) {
doFireDocumentChanged(event);
} else {
fDeferredDocumentEvent= event;
fDeferredDocumentEvents.add(event);
}
}

Expand Down Expand Up @@ -1099,13 +1106,13 @@ public void removePositionUpdater(IPositionUpdater updater) {
}

private long getNextModificationStamp() {
if (fNextModificationStamp == Long.MAX_VALUE || fNextModificationStamp == IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP) {
fNextModificationStamp= 0;
} else {
fNextModificationStamp= fNextModificationStamp + 1;
}

return fNextModificationStamp;
return fNextModificationStamp.getAndUpdate(current -> {
if (current == Long.MAX_VALUE || current == IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP) {
return 0;
} else {
return current + 1;
}
});
}

@Override
Expand All @@ -1126,7 +1133,7 @@ public void replace(int pos, int length, String text, long modificationStamp) th
getTracker().replace(pos, length, text);

fModificationStamp= modificationStamp;
fNextModificationStamp= Math.max(fModificationStamp, fNextModificationStamp);
fNextModificationStamp.getAndAccumulate(fModificationStamp, Math::max);
e.fModificationStamp= fModificationStamp;

fireDocumentChanged(e);
Expand Down Expand Up @@ -1167,7 +1174,7 @@ public void set(String text, long modificationStamp) {
getTracker().set(text);

fModificationStamp= modificationStamp;
fNextModificationStamp= Math.max(fModificationStamp, fNextModificationStamp);
fNextModificationStamp.getAndAccumulate(fModificationStamp, Math::max);
e.fModificationStamp= fModificationStamp;

fireDocumentChanged(e);
Expand All @@ -1192,7 +1199,7 @@ protected void updatePositions(DocumentEvent event) {
*
* @deprecated as of 3.0 search is provided by {@link FindReplaceDocumentAdapter}
*/
@Deprecated
@Deprecated(forRemoval = true, since= "3.15.0")
@Override
public int search(int startPosition, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord) throws BadLocationException {
try {
Expand Down Expand Up @@ -1295,7 +1302,7 @@ public void resumePostNotificationProcessing() {
* {@link IDocumentExtension4#startRewriteSession(DocumentRewriteSessionType)}
* instead.
*/
@Deprecated
@Deprecated(forRemoval = true, since= "3.15.0")
@Override
public void startSequentialRewrite(boolean normalized) {
}
Expand All @@ -1306,22 +1313,21 @@ public void startSequentialRewrite(boolean normalized) {
* @since 2.0
* @deprecated As of 3.1, replaced by {@link IDocumentExtension4#stopRewriteSession(DocumentRewriteSession)}
*/
@Deprecated
@Deprecated(forRemoval = true, since= "3.15.0")
@Override
public void stopSequentialRewrite() {
}

@Override
public void resumeListenerNotification() {
-- fStoppedListenerNotification;
if (fStoppedListenerNotification == 0) {
if (fStoppedListenerNotification.decrementAndGet() == 0) {
resumeDocumentListenerNotification();
}
}

@Override
public void stopListenerNotification() {
++ fStoppedListenerNotification;
fStoppedListenerNotification.incrementAndGet();
}

/**
Expand All @@ -1331,17 +1337,20 @@ public void stopListenerNotification() {
* @since 2.1
*/
private void resumeDocumentListenerNotification() {
if (fDeferredDocumentEvent != null) {
DocumentEvent event= fDeferredDocumentEvent;
fDeferredDocumentEvent= null;
doFireDocumentChanged(event);
while (!fDeferredDocumentEvents.isEmpty()) {
if (fStoppedListenerNotification.get() == 0) {
try {
DocumentEvent event= fDeferredDocumentEvents.remove(0);
doFireDocumentChanged(event);
} catch (IndexOutOfBoundsException ex) {
log(ex);
}
} else {
break;
}
}
}

/*
* @see org.eclipse.jface.text.IDocumentExtension3#computeZeroLengthPartitioning(java.lang.String, int, int)
* @since 3.0
*/
@Override
public ITypedRegion[] computePartitioning(String partitioning, int offset, int length, boolean includeZeroLengthPartitions) throws BadLocationException, BadPartitioningException {
if ((0 > offset) || (0 > length) || (offset + length > getLength())) {
Expand Down
Loading