diff options
Diffstat (limited to 'org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java')
-rw-r--r-- | org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java | 74 |
1 files changed, 28 insertions, 46 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 2b1bd31b999..45e6e9cccb5 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); } |