Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Keller2016-01-20 11:31:26 -0500
committerMarkus Keller2016-01-20 11:31:26 -0500
commit0bea9726df0c7a51257165226de61c26c7798c58 (patch)
treefb4279ef99b308b6686d12680d57db0d5a0f3925 /org.eclipse.text
parentb45e6c163c5f101d2bdb8248593972e2a6cc6eb5 (diff)
downloadeclipse.platform.text-0bea9726df0c7a51257165226de61c26c7798c58.tar.gz
eclipse.platform.text-0bea9726df0c7a51257165226de61c26c7798c58.tar.xz
eclipse.platform.text-0bea9726df0c7a51257165226de61c26c7798c58.zip
Fixes for bug 483340: ListenerList should be parameterized
Diffstat (limited to 'org.eclipse.text')
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java74
-rw-r--r--org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java11
2 files changed, 33 insertions, 52 deletions
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java b/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java
index 2b1bd31b9..45e6e9ccc 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -12,8 +12,8 @@
package org.eclipse.jface.text;
-import java.util.AbstractList;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -92,11 +92,11 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension,
/** The document's line tracker */
private ILineTracker fTracker;
/** The registered document listeners */
- private ListenerList fDocumentListeners;
+ private ListenerList<IDocumentListener> fDocumentListeners;
/** The registered pre-notified document listeners */
- private ListenerList fPrenotifiedDocumentListeners;
+ private ListenerList<IDocumentListener> fPrenotifiedDocumentListeners;
/** The registered document partitioning listeners */
- private ListenerList fDocumentPartitioningListeners;
+ private ListenerList<IDocumentPartitioningListener> fDocumentPartitioningListeners;
/** All positions managed by the document ordered by their start positions. */
private Map<String, List<Position>> fPositions;
/**
@@ -211,21 +211,11 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension,
return fTracker;
}
- private static <T> List<T> asList(Object[] listeners) {
- // Workaround for Bug 483340: ListenerList should be parameterized
- // Use Arrays.asList(..) once that bug is fixed.
- return new AbstractList<T>() {
- @SuppressWarnings("unchecked")
- @Override
- public T get(int index) {
- return (T) listeners[index];
- }
-
- @Override
- public int size() {
- return listeners.length;
- }
- };
+ private static <T> List<T> asList(ListenerList<T> listenerList) {
+ List<?> list= Arrays.asList(listenerList.getListeners());
+ @SuppressWarnings("unchecked")
+ List<T> castList= (List<T>) list;
+ return castList;
}
@@ -235,7 +225,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension,
* @return the document's document listeners
*/
protected List<IDocumentListener> getDocumentListeners() {
- return asList(fDocumentListeners.getListeners());
+ return asList(fDocumentListeners);
}
/**
@@ -244,7 +234,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension,
* @return the document's partitioning listeners
*/
protected List<IDocumentPartitioningListener> getDocumentPartitioningListeners() {
- return asList(fDocumentPartitioningListeners.getListeners());
+ return asList(fDocumentPartitioningListeners);
}
/**
@@ -300,9 +290,9 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension,
fPositions= new HashMap<>();
fEndPositions= new HashMap<>();
fPositionUpdaters= new ArrayList<>();
- fDocumentListeners= new ListenerList(ListenerList.IDENTITY);
- fPrenotifiedDocumentListeners= new ListenerList(ListenerList.IDENTITY);
- fDocumentPartitioningListeners= new ListenerList(ListenerList.IDENTITY);
+ fDocumentListeners= new ListenerList<>(ListenerList.IDENTITY);
+ fPrenotifiedDocumentListeners= new ListenerList<>(ListenerList.IDENTITY);
+ fDocumentPartitioningListeners= new ListenerList<>(ListenerList.IDENTITY);
fDocumentRewriteSessionListeners= new ArrayList<>();
addPositionCategory(DEFAULT_CATEGORY);
@@ -544,9 +534,9 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension,
if (fDocumentPartitioningListeners == null)
return;
- Object[] listeners= fDocumentPartitioningListeners.getListeners();
- for (int i= 0; i < listeners.length; i++)
- ((IDocumentPartitioningListener)listeners[i]).documentPartitioningChanged(this);
+ for (IDocumentPartitioningListener listener : fDocumentPartitioningListeners) {
+ listener.documentPartitioningChanged(this);
+ }
}
/**
@@ -566,9 +556,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension,
if (fDocumentPartitioningListeners == null)
return;
- Object[] listeners= fDocumentPartitioningListeners.getListeners();
- for (int i= 0; i < listeners.length; i++) {
- IDocumentPartitioningListener l= (IDocumentPartitioningListener)listeners[i];
+ for (IDocumentPartitioningListener l : fDocumentPartitioningListeners) {
try {
if (l instanceof IDocumentPartitioningListenerExtension)
((IDocumentPartitioningListenerExtension)l).documentPartitioningChanged(this, region);
@@ -593,9 +581,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension,
if (fDocumentPartitioningListeners == null)
return;
- Object[] listeners= fDocumentPartitioningListeners.getListeners();
- for (int i= 0; i < listeners.length; i++) {
- IDocumentPartitioningListener l= (IDocumentPartitioningListener)listeners[i];
+ for (IDocumentPartitioningListener l : fDocumentPartitioningListeners) {
try {
if (l instanceof IDocumentPartitioningListenerExtension2) {
IDocumentPartitioningListenerExtension2 extension2= (IDocumentPartitioningListenerExtension2)l;
@@ -641,19 +627,17 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension,
}
}
- Object[] listeners= fPrenotifiedDocumentListeners.getListeners();
- for (int i= 0; i < listeners.length; i++) {
+ for (IDocumentListener listener : fPrenotifiedDocumentListeners) {
try {
- ((IDocumentListener)listeners[i]).documentAboutToBeChanged(event);
+ listener.documentAboutToBeChanged(event);
} catch (Exception ex) {
log(ex);
}
}
- listeners= fDocumentListeners.getListeners();
- for (int i= 0; i < listeners.length; i++) {
+ for (IDocumentListener listener : fDocumentListeners) {
try {
- ((IDocumentListener)listeners[i]).documentAboutToBeChanged(event);
+ listener.documentAboutToBeChanged(event);
} catch (Exception ex) {
log(ex);
}
@@ -746,19 +730,17 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension,
if (p != null && !p.isEmpty())
fireDocumentPartitioningChanged(p);
- Object[] listeners= fPrenotifiedDocumentListeners.getListeners();
- for (int i= 0; i < listeners.length; i++) {
+ for (IDocumentListener listener : fPrenotifiedDocumentListeners) {
try {
- ((IDocumentListener)listeners[i]).documentChanged(event);
+ listener.documentChanged(event);
} catch (Exception ex) {
log(ex);
}
}
- listeners= fDocumentListeners.getListeners();
- for (int i= 0; i < listeners.length; i++) {
+ for (IDocumentListener listener : fDocumentListeners) {
try {
- ((IDocumentListener)listeners[i]).documentChanged(event);
+ listener.documentChanged(event);
} catch (Exception ex) {
log(ex);
}
diff --git a/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java b/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java
index 4ead31215..aef594799 100644
--- a/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java
+++ b/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2015 IBM Corporation and others.
+ * Copyright (c) 2006, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -735,7 +735,7 @@ public class DocumentUndoManager implements IDocumentUndoManager {
private boolean fOverwriting= false;
/** The registered document listeners. */
- private ListenerList fDocumentUndoListeners;
+ private ListenerList<IDocumentUndoListener> fDocumentUndoListeners;
/** The list of clients connected. */
private List<Object> fConnected;
@@ -753,7 +753,7 @@ public class DocumentUndoManager implements IDocumentUndoManager {
fHistory= OperationHistoryFactory.getOperationHistory();
fUndoContext= new ObjectUndoContext(fDocument);
fConnected= new ArrayList<>();
- fDocumentUndoListeners= new ListenerList(ListenerList.IDENTITY);
+ fDocumentUndoListeners= new ListenerList<>(ListenerList.IDENTITY);
}
@Override
@@ -873,9 +873,8 @@ public class DocumentUndoManager implements IDocumentUndoManager {
void fireDocumentUndo(int offset, String text, String preservedText, Object source, int eventType, boolean isCompound) {
eventType= isCompound ? eventType | DocumentUndoEvent.COMPOUND : eventType;
DocumentUndoEvent event= new DocumentUndoEvent(fDocument, offset, text, preservedText, eventType, source);
- Object[] listeners= fDocumentUndoListeners.getListeners();
- for (int i= 0; i < listeners.length; i++) {
- ((IDocumentUndoListener)listeners[i]).documentUndoNotification(event);
+ for (IDocumentUndoListener listener : fDocumentUndoListeners) {
+ listener.documentUndoNotification(event);
}
}

Back to the top