diff options
Diffstat (limited to 'org.eclipse.text/src')
33 files changed, 503 insertions, 484 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 ba2fe5ac7d2..b9c734a50ba 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, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2015 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; @@ -98,19 +98,19 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, /** The registered document partitioning listeners */ private ListenerList fDocumentPartitioningListeners; /** All positions managed by the document ordered by their start positions. */ - private Map fPositions; + private Map<String, List<Position>> fPositions; /** - * All positions managed by the document ordered by there end positions. + * All positions managed by the document ordered by their end positions. * @since 3.4 */ - private Map fEndPositions; + private Map<String, List<Position>> fEndPositions; /** All registered document position updaters */ - private List fPositionUpdaters; + private List<IPositionUpdater> fPositionUpdaters; /** * The list of post notification changes * @since 2.0 */ - private List fPostNotificationChanges; + private List<RegisteredReplace> fPostNotificationChanges; /** * The reentrance count for post notification changes. * @since 2.0 @@ -140,7 +140,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, * The registered document partitioners. * @since 3.0 */ - private Map fDocumentPartitioners; + private Map<String, IDocumentPartitioner> fDocumentPartitioners; /** * The partitioning changed event. * @since 3.0 @@ -160,7 +160,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, * The registered document rewrite session listeners. * @since 3.1 */ - private List fDocumentRewriteSessionListeners; + private List<IDocumentRewriteSessionListener> fDocumentRewriteSessionListeners; /** * The current modification stamp. * @since 3.1 @@ -211,13 +211,31 @@ 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; + } + }; + } + + /** * Returns the document's document listeners. * * @return the document's document listeners */ - protected List getDocumentListeners() { - return Arrays.asList(fDocumentListeners.getListeners()); + protected List<IDocumentListener> getDocumentListeners() { + return asList(fDocumentListeners.getListeners()); } /** @@ -225,8 +243,8 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, * * @return the document's partitioning listeners */ - protected List getDocumentPartitioningListeners() { - return Arrays.asList(fDocumentPartitioningListeners.getListeners()); + protected List<IDocumentPartitioningListener> getDocumentPartitioningListeners() { + return asList(fDocumentPartitioningListeners.getListeners()); } /** @@ -234,7 +252,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, * * @return the document's positions */ - protected Map getDocumentManagedPositions() { + protected Map<String, List<Position>> getDocumentManagedPositions() { return fPositions; } @@ -279,13 +297,13 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, */ protected void completeInitialization() { - fPositions= new HashMap(); - fEndPositions= new HashMap(); - fPositionUpdaters= new ArrayList(); + fPositions= new HashMap<>(); + fEndPositions= new HashMap<>(); + fPositionUpdaters= new ArrayList<>(); fDocumentListeners= new ListenerList(ListenerList.IDENTITY); fPrenotifiedDocumentListeners= new ListenerList(ListenerList.IDENTITY); fDocumentPartitioningListeners= new ListenerList(ListenerList.IDENTITY); - fDocumentRewriteSessionListeners= new ArrayList(); + fDocumentRewriteSessionListeners= new ArrayList<>(); addPositionCategory(DEFAULT_CATEGORY); addPositionUpdater(new DefaultPositionUpdater(DEFAULT_CATEGORY)); @@ -339,12 +357,12 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, if (category == null) throw new BadPositionCategoryException(); - List list= (List) fPositions.get(category); + List<Position> list= fPositions.get(category); if (list == null) throw new BadPositionCategoryException(); list.add(computeIndexInPositionList(list, position.offset), position); - List endPositions= (List) fEndPositions.get(category); + List<Position> endPositions= fEndPositions.get(category); if (endPositions == null) throw new BadPositionCategoryException(); endPositions.add(computeIndexInPositionList(endPositions, position.offset + position.length - 1, false), position); @@ -365,8 +383,8 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, return; if (!containsPositionCategory(category)) { - fPositions.put(category, new ArrayList()); - fEndPositions.put(category, new ArrayList()); + fPositions.put(category, new ArrayList<>()); + fEndPositions.put(category, new ArrayList<>()); } } @@ -381,7 +399,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, if (category == null) return false; - List list= (List) fPositions.get(category); + List<Position> list= fPositions.get(category); if (list == null) return false; @@ -391,12 +409,12 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, int index= computeIndexInPositionList(list, offset); if (index < size) { - Position p= (Position) list.get(index); + Position p= list.get(index); while (p != null && p.offset == offset) { if (p.length == length) return true; ++ index; - p= (index < size) ? (Position) list.get(index) : null; + p= (index < size) ? list.get(index) : null; } } @@ -424,7 +442,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, * @deprecated As of 3.4, replaced by {@link #computeIndexInPositionList(List, int, boolean)} */ @Deprecated - protected int computeIndexInPositionList(List positions, int offset) { + protected int computeIndexInPositionList(List<Position> positions, int offset) { return computeIndexInPositionList(positions, offset, true); } @@ -439,7 +457,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, * @return the computed index * @since 3.4 */ - protected int computeIndexInPositionList(List positions, int offset, boolean orderedByOffset) { + protected int computeIndexInPositionList(List<Position> positions, int offset, boolean orderedByOffset) { if (positions.size() == 0) return 0; @@ -452,7 +470,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, mid= (left + right) / 2; - p= (Position) positions.get(mid); + p= positions.get(mid); int pOffset= getOffset(orderedByOffset, p); if (offset < pOffset) { if (left == mid) @@ -471,7 +489,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, } int pos= left; - p= (Position) positions.get(pos); + p= positions.get(pos); int pPosition= getOffset(orderedByOffset, p); if (offset > pPosition) { // append to the end @@ -482,7 +500,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, --pos; if (pos < 0) break; - p= (Position) positions.get(pos); + p= positions.get(pos); pPosition= getOffset(orderedByOffset, p); } while (offset == pPosition); ++pos; @@ -508,7 +526,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, if (0 > offset || offset > getLength()) throw new BadLocationException(); - List c= (List) fPositions.get(category); + List<Position> c= fPositions.get(category); if (c == null) throw new BadPositionCategoryException(); @@ -607,9 +625,9 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, flushPostNotificationChanges(); if (fDocumentPartitioners != null) { - Iterator e= fDocumentPartitioners.values().iterator(); + Iterator<IDocumentPartitioner> e= fDocumentPartitioners.values().iterator(); while (e.hasNext()) { - IDocumentPartitioner p= (IDocumentPartitioner) e.next(); + IDocumentPartitioner p= e.next(); if (p instanceof IDocumentPartitionerExtension3) { IDocumentPartitionerExtension3 extension= (IDocumentPartitionerExtension3) p; if (extension.getActiveRewriteSession() != null) @@ -653,10 +671,10 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, if (fDocumentPartitioners != null) { fDocumentPartitioningChangedEvent= new DocumentPartitioningChangedEvent(this); - Iterator e= fDocumentPartitioners.keySet().iterator(); + Iterator<String> e= fDocumentPartitioners.keySet().iterator(); while (e.hasNext()) { - String partitioning= (String) e.next(); - IDocumentPartitioner partitioner= (IDocumentPartitioner) fDocumentPartitioners.get(partitioning); + String partitioning= e.next(); + IDocumentPartitioner partitioner= fDocumentPartitioners.get(partitioning); if (partitioner instanceof IDocumentPartitionerExtension3) { IDocumentPartitionerExtension3 extension= (IDocumentPartitionerExtension3) partitioner; @@ -927,7 +945,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, if (category == null) throw new BadPositionCategoryException(); - List c= (List) fPositions.get(category); + List<Position> c= fPositions.get(category); if (c == null) throw new BadPositionCategoryException(); @@ -939,9 +957,9 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, @Override public String[] getPositionCategories() { String[] categories= new String[fPositions.size()]; - Iterator keys= fPositions.keySet().iterator(); + Iterator<String> keys= fPositions.keySet().iterator(); for (int i= 0; i < categories.length; i++) - categories[i]= (String) keys.next(); + categories[i]= keys.next(); return categories; } @@ -988,12 +1006,12 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, if (category == null) throw new BadPositionCategoryException(); - List c= (List) fPositions.get(category); + List<Position> c= fPositions.get(category); if (c == null) throw new BadPositionCategoryException(); removeFromPositionsList(c, position, true); - List endPositions= (List) fEndPositions.get(category); + List<Position> endPositions= fEndPositions.get(category); if (endPositions == null) throw new BadPositionCategoryException(); removeFromPositionsList(endPositions, position, false); @@ -1007,7 +1025,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, * @param orderedByOffset true if <code>positions</code> is ordered by offset, false if ordered by end position * @since 3.4 */ - private void removeFromPositionsList(List positions, Position position, boolean orderedByOffset) { + private void removeFromPositionsList(List<Position> positions, Position position, boolean orderedByOffset) { int size= positions.size(); //Assume position is somewhere near it was before @@ -1150,10 +1168,10 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, * the positions */ protected void updatePositions(DocumentEvent event) { - List list= new ArrayList(fPositionUpdaters); - Iterator e= list.iterator(); + List<IPositionUpdater> list= new ArrayList<>(fPositionUpdaters); + Iterator<IPositionUpdater> e= list.iterator(); while (e.hasNext()) { - IPositionUpdater u= (IPositionUpdater) e.next(); + IPositionUpdater u= e.next(); u.update(event); } } @@ -1211,12 +1229,12 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, return; while (fPostNotificationChanges != null) { - List changes= fPostNotificationChanges; + List<RegisteredReplace> changes= fPostNotificationChanges; fPostNotificationChanges= null; - Iterator e= changes.iterator(); + Iterator<RegisteredReplace> e= changes.iterator(); while (e.hasNext()) { - RegisteredReplace replace= (RegisteredReplace) e.next(); + RegisteredReplace replace= e.next(); replace.fReplace.perform(this, replace.fOwner); } } @@ -1236,7 +1254,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, public void registerPostNotificationReplace(IDocumentListener owner, IDocumentExtension.IReplace replace) { if (fAcceptPostNotificationReplaces) { if (fPostNotificationChanges == null) - fPostNotificationChanges= new ArrayList(1); + fPostNotificationChanges= new ArrayList<>(1); fPostNotificationChanges.add(new RegisteredReplace(owner, replace)); } } @@ -1352,7 +1370,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, @Override public IDocumentPartitioner getDocumentPartitioner(String partitioning) { - return fDocumentPartitioners != null ? (IDocumentPartitioner) fDocumentPartitioners.get(partitioning) : null; + return fDocumentPartitioners != null ? fDocumentPartitioners.get(partitioning) : null; } @Override @@ -1407,7 +1425,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, } } else { if (fDocumentPartitioners == null) - fDocumentPartitioners= new HashMap(); + fDocumentPartitioners= new HashMap<>(); fDocumentPartitioners.put(partitioning, partitioner); } DocumentPartitioningChangedEvent event= new DocumentPartitioningChangedEvent(this); @@ -1428,11 +1446,11 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, */ protected void fireRewriteSessionChanged(DocumentRewriteSessionEvent event) { if (fDocumentRewriteSessionListeners.size() > 0) { - List list= new ArrayList(fDocumentRewriteSessionListeners); - Iterator e= list.iterator(); + List<IDocumentRewriteSessionListener> list= new ArrayList<>(fDocumentRewriteSessionListeners); + Iterator<IDocumentRewriteSessionListener> e= list.iterator(); while (e.hasNext()) { try { - IDocumentRewriteSessionListener l= (IDocumentRewriteSessionListener)e.next(); + IDocumentRewriteSessionListener l= e.next(); l.documentRewriteSessionChanged(event); } catch (Exception ex) { log(ex); @@ -1483,7 +1501,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, */ protected final void startRewriteSessionOnPartitioners(DocumentRewriteSession session) { if (fDocumentPartitioners != null) { - Iterator e= fDocumentPartitioners.values().iterator(); + Iterator<IDocumentPartitioner> e= fDocumentPartitioners.values().iterator(); while (e.hasNext()) { Object partitioner= e.next(); if (partitioner instanceof IDocumentPartitionerExtension3) { @@ -1527,10 +1545,10 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, protected final void stopRewriteSessionOnPartitioners(DocumentRewriteSession session) { if (fDocumentPartitioners != null) { DocumentPartitioningChangedEvent event= new DocumentPartitioningChangedEvent(this); - Iterator e= fDocumentPartitioners.keySet().iterator(); + Iterator<String> e= fDocumentPartitioners.keySet().iterator(); while (e.hasNext()) { - String partitioning= (String) e.next(); - IDocumentPartitioner partitioner= (IDocumentPartitioner) fDocumentPartitioners.get(partitioning); + String partitioning= e.next(); + IDocumentPartitioner partitioner= fDocumentPartitioners.get(partitioning); if (partitioner instanceof IDocumentPartitionerExtension3) { IDocumentPartitionerExtension3 extension= (IDocumentPartitionerExtension3) partitioner; extension.stopRewriteSession(session); @@ -1597,7 +1615,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, */ public Position[] getPositions(String category, int offset, int length, boolean canStartBefore, boolean canEndAfter) throws BadPositionCategoryException { if (canStartBefore && canEndAfter || (!canStartBefore && !canEndAfter)) { - List documentPositions; + List<Position> documentPositions; if (canStartBefore && canEndAfter) { if (offset < getLength() / 2) { documentPositions= getStartingPositions(category, 0, offset + length); @@ -1608,12 +1626,12 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, documentPositions= getStartingPositions(category, offset, length); } - ArrayList list= new ArrayList(documentPositions.size()); + ArrayList<Position> list= new ArrayList<>(documentPositions.size()); Position region= new Position(offset, length); - for (Iterator iterator= documentPositions.iterator(); iterator.hasNext();) { - Position position= (Position) iterator.next(); + for (Iterator<Position> iterator= documentPositions.iterator(); iterator.hasNext();) { + Position position= iterator.next(); if (isWithinRegion(region, position, canStartBefore, canEndAfter)) { list.add(position); } @@ -1623,14 +1641,14 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, list.toArray(positions); return positions; } else if (canStartBefore) { - List list= getEndingPositions(category, offset, length); + List<Position> list= getEndingPositions(category, offset, length); Position[] positions= new Position[list.size()]; list.toArray(positions); return positions; } else { Assert.isLegal(canEndAfter && !canStartBefore); - List list= getStartingPositions(category, offset, length); + List<Position> list= getStartingPositions(category, offset, length); Position[] positions= new Position[list.size()]; list.toArray(positions); return positions; @@ -1664,8 +1682,8 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, * @throws BadPositionCategoryException if category is undefined in this document * @since 3.4 */ - private List getStartingPositions(String category, int offset, int length) throws BadPositionCategoryException { - List positions= (List) fPositions.get(category); + private List<Position> getStartingPositions(String category, int offset, int length) throws BadPositionCategoryException { + List<Position> positions= fPositions.get(category); if (positions == null) throw new BadPositionCategoryException(); @@ -1686,8 +1704,8 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension, * @throws BadPositionCategoryException if category is undefined in this document * @since 3.4 */ - private List getEndingPositions(String category, int offset, int length) throws BadPositionCategoryException { - List positions= (List) fEndPositions.get(category); + private List<Position> getEndingPositions(String category, int offset, int length) throws BadPositionCategoryException { + List<Position> positions= fEndPositions.get(category); if (positions == null) throw new BadPositionCategoryException(); diff --git a/org.eclipse.text/src/org/eclipse/jface/text/AbstractLineTracker.java b/org.eclipse.text/src/org/eclipse/jface/text/AbstractLineTracker.java index ba4f3ac17a3..8cf30f89628 100644 --- a/org.eclipse.text/src/org/eclipse/jface/text/AbstractLineTracker.java +++ b/org.eclipse.text/src/org/eclipse/jface/text/AbstractLineTracker.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2015 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 @@ -88,7 +88,7 @@ public abstract class AbstractLineTracker implements ILineTracker, ILineTrackerE * * @since 3.1 */ - private List fPendingRequests; + private List<Request> fPendingRequests; /** * The implementation that this tracker delegates to. * @@ -233,7 +233,7 @@ public abstract class AbstractLineTracker implements ILineTracker, ILineTrackerE if (fActiveRewriteSession != null) throw new IllegalStateException(); fActiveRewriteSession= session; - fPendingRequests= new ArrayList(20); + fPendingRequests= new ArrayList<>(20); } @Override @@ -266,13 +266,13 @@ public abstract class AbstractLineTracker implements ILineTracker, ILineTrackerE if (DEBUG) System.out.println("AbstractLineTracker: Flushing rewrite session: " + fActiveRewriteSession); //$NON-NLS-1$ - Iterator e= fPendingRequests.iterator(); + Iterator<Request> e= fPendingRequests.iterator(); fPendingRequests= null; fActiveRewriteSession= null; while (e.hasNext()) { - Request request= (Request) e.next(); + Request request= e.next(); if (request.isReplaceRequest()) replace(request.offset, request.length, request.text); else diff --git a/org.eclipse.text/src/org/eclipse/jface/text/DocumentPartitioningChangedEvent.java b/org.eclipse.text/src/org/eclipse/jface/text/DocumentPartitioningChangedEvent.java index 1fc4a8db300..af7e0a05d58 100644 --- a/org.eclipse.text/src/org/eclipse/jface/text/DocumentPartitioningChangedEvent.java +++ b/org.eclipse.text/src/org/eclipse/jface/text/DocumentPartitioningChangedEvent.java @@ -27,7 +27,7 @@ public class DocumentPartitioningChangedEvent { /** The document whose partitionings changed */ private final IDocument fDocument; /** The map of partitionings to changed regions. */ - private final Map fMap= new HashMap(); + private final Map<String, Region> fMap= new HashMap<>(); /** @@ -57,7 +57,7 @@ public class DocumentPartitioningChangedEvent { * @return the changed region of the given partitioning or <code>null</code> */ public IRegion getChangedRegion(String partitioning) { - return (IRegion) fMap.get(partitioning); + return fMap.get(partitioning); } /** @@ -105,9 +105,9 @@ public class DocumentPartitioningChangedEvent { int offset= -1; int endOffset= -1; - Iterator e= fMap.values().iterator(); + Iterator<Region> e= fMap.values().iterator(); while (e.hasNext()) { - IRegion r= (IRegion) e.next(); + IRegion r= e.next(); if (offset < 0 || r.getOffset() < offset) offset= r.getOffset(); diff --git a/org.eclipse.text/src/org/eclipse/jface/text/ListLineTracker.java b/org.eclipse.text/src/org/eclipse/jface/text/ListLineTracker.java index 11fcf70c977..299e9c647d6 100644 --- a/org.eclipse.text/src/org/eclipse/jface/text/ListLineTracker.java +++ b/org.eclipse.text/src/org/eclipse/jface/text/ListLineTracker.java @@ -34,7 +34,7 @@ import org.eclipse.jface.text.AbstractLineTracker.DelimiterInfo; abstract class ListLineTracker implements ILineTracker { /** The line information */ - private final List fLines= new ArrayList(); + private final List<Line> fLines= new ArrayList<>(); /** The length of the tracked text */ private int fTextLength; @@ -64,7 +64,7 @@ abstract class ListLineTracker implements ILineTracker { mid= (left + right) / 2; - line= (Line) fLines.get(mid); + line= fLines.get(mid); if (offset < line.offset) { if (left == mid) right= left; @@ -80,7 +80,7 @@ abstract class ListLineTracker implements ILineTracker { } } - line= (Line) fLines.get(left); + line= fLines.get(left); if (line.offset > offset) --left; return left; @@ -102,7 +102,7 @@ abstract class ListLineTracker implements ILineTracker { int target= offset + length; - Line l= (Line) fLines.get(startLine); + Line l= fLines.get(startLine); if (l.delimiter == null) return 1; @@ -126,7 +126,7 @@ abstract class ListLineTracker implements ILineTracker { if (lines == 0 || lines == line) return 0; - Line l= (Line) fLines.get(line); + Line l= fLines.get(line); return l.length; } @@ -141,7 +141,7 @@ abstract class ListLineTracker implements ILineTracker { if (lastLine < 0) return 0; - Line l= (Line) fLines.get(lastLine); + Line l= fLines.get(lastLine); return (l.delimiter != null ? lastLine + 1 : lastLine); } @@ -157,7 +157,7 @@ abstract class ListLineTracker implements ILineTracker { int size= fLines.size(); if (size == 0) return new Region(0, 0); - Line l= (Line) fLines.get(size - 1); + Line l= fLines.get(size - 1); return (l.delimiter != null ? new Line(fTextLength, 0) : new Line(fTextLength - l.length, l.length)); } @@ -175,11 +175,11 @@ abstract class ListLineTracker implements ILineTracker { return new Line(0, 0); if (line == lines) { - Line l= (Line) fLines.get(line - 1); + Line l= fLines.get(line - 1); return new Line(l.offset + l.length, 0); } - Line l= (Line) fLines.get(line); + Line l= fLines.get(line); return (l.delimiter != null ? new Line(l.offset, l.length - l.delimiter.length()) : l); } @@ -194,13 +194,13 @@ abstract class ListLineTracker implements ILineTracker { return 0; if (line == lines) { - Line l= (Line) fLines.get(line - 1); + Line l= fLines.get(line - 1); if (l.delimiter != null) return l.offset + l.length; throw new BadLocationException(); } - Line l= (Line) fLines.get(line); + Line l= fLines.get(line); return l.offset; } @@ -211,7 +211,7 @@ abstract class ListLineTracker implements ILineTracker { if (lines == 0) return 1; - Line l= (Line) fLines.get(lines - 1); + Line l= fLines.get(lines - 1); return (l.delimiter != null ? lines + 1 : lines); } @@ -253,7 +253,7 @@ abstract class ListLineTracker implements ILineTracker { if (line == lines) return null; - Line l= (Line) fLines.get(line); + Line l= fLines.get(line); return l.delimiter; } @@ -300,7 +300,7 @@ abstract class ListLineTracker implements ILineTracker { if (start < text.length()) { if (insertPosition + count < fLines.size()) { // there is a line below the current - Line l= (Line) fLines.get(insertPosition + count); + Line l= fLines.get(insertPosition + count); int delta= text.length() - start; l.offset-= delta; l.length+= delta; @@ -333,7 +333,7 @@ abstract class ListLineTracker implements ILineTracker { * * @return the internal list of lines. */ - final List getLines() { + final List<Line> getLines() { return fLines; } } diff --git a/org.eclipse.text/src/org/eclipse/jface/text/SequentialRewriteTextStore.java b/org.eclipse.text/src/org/eclipse/jface/text/SequentialRewriteTextStore.java index 3c26c5de467..5d1de092ed2 100644 --- a/org.eclipse.text/src/org/eclipse/jface/text/SequentialRewriteTextStore.java +++ b/org.eclipse.text/src/org/eclipse/jface/text/SequentialRewriteTextStore.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2015 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 @@ -45,7 +45,7 @@ public class SequentialRewriteTextStore implements ITextStore { } /** The list of buffered replacements. */ - private LinkedList fReplaceList; + private LinkedList<Replace> fReplaceList; /** The source text store */ private ITextStore fSource; /** A flag to enforce sequential access. */ @@ -58,7 +58,7 @@ public class SequentialRewriteTextStore implements ITextStore { * @param source the source text store */ public SequentialRewriteTextStore(ITextStore source) { - fReplaceList= new LinkedList(); + fReplaceList= new LinkedList<>(); fSource= source; } @@ -81,15 +81,15 @@ public class SequentialRewriteTextStore implements ITextStore { fReplaceList.add(new Replace(offset, offset, length, text)); } else { - Replace firstReplace= (Replace) fReplaceList.getFirst(); - Replace lastReplace= (Replace) fReplaceList.getLast(); + Replace firstReplace= fReplaceList.getFirst(); + Replace lastReplace= fReplaceList.getLast(); // backward if (offset + length <= firstReplace.newOffset) { int delta= text.length() - length; if (delta != 0) { - for (Iterator i= fReplaceList.iterator(); i.hasNext(); ) { - Replace replace= (Replace) i.next(); + for (Iterator<Replace> i= fReplaceList.iterator(); i.hasNext(); ) { + Replace replace= i.next(); replace.newOffset += delta; } } @@ -124,8 +124,8 @@ public class SequentialRewriteTextStore implements ITextStore { return fSource.get(offset, length); - Replace firstReplace= (Replace) fReplaceList.getFirst(); - Replace lastReplace= (Replace) fReplaceList.getLast(); + Replace firstReplace= fReplaceList.getFirst(); + Replace lastReplace= fReplaceList.getLast(); // before if (offset + length <= firstReplace.newOffset) { @@ -142,8 +142,8 @@ public class SequentialRewriteTextStore implements ITextStore { } else { int delta= 0; - for (Iterator i= fReplaceList.iterator(); i.hasNext(); ) { - Replace replace= (Replace) i.next(); + for (Iterator<Replace> i= fReplaceList.iterator(); i.hasNext(); ) { + Replace replace= i.next(); if (offset + length < replace.newOffset) { return fSource.get(offset - delta, length); @@ -182,8 +182,8 @@ public class SequentialRewriteTextStore implements ITextStore { if (fReplaceList.isEmpty()) return fSource.get(offset); - Replace firstReplace= (Replace) fReplaceList.getFirst(); - Replace lastReplace= (Replace) fReplaceList.getLast(); + Replace firstReplace= fReplaceList.getFirst(); + Replace lastReplace= fReplaceList.getLast(); // before if (offset < firstReplace.newOffset) { @@ -200,8 +200,8 @@ public class SequentialRewriteTextStore implements ITextStore { } else { int delta= 0; - for (Iterator i= fReplaceList.iterator(); i.hasNext(); ) { - Replace replace= (Replace) i.next(); + for (Iterator<Replace> i= fReplaceList.iterator(); i.hasNext(); ) { + Replace replace= i.next(); if (offset < replace.newOffset) return fSource.get(offset - delta); @@ -221,7 +221,7 @@ public class SequentialRewriteTextStore implements ITextStore { if (fReplaceList.isEmpty()) return fSource.getLength(); - Replace lastReplace= (Replace) fReplaceList.getLast(); + Replace lastReplace= fReplaceList.getLast(); return fSource.getLength() + getDelta(lastReplace); } @@ -244,8 +244,8 @@ public class SequentialRewriteTextStore implements ITextStore { StringBuffer buffer= new StringBuffer(); int delta= 0; - for (Iterator i= fReplaceList.iterator(); i.hasNext(); ) { - Replace replace= (Replace) i.next(); + for (Iterator<Replace> i= fReplaceList.iterator(); i.hasNext(); ) { + Replace replace= i.next(); int offset= buffer.length() - delta; buffer.append(fSource.get(offset, replace.offset - offset)); diff --git a/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java b/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java index 64fcf4c94c7..df2e9ad5029 100644 --- a/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java +++ b/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2014 IBM Corporation and others. + * Copyright (c) 2000, 2015 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 @@ -182,13 +182,13 @@ public class TextUtilities { * @return returns the merged document event * @throws BadLocationException might be thrown if document is not in the correct state with respect to document events */ - public static DocumentEvent mergeUnprocessedDocumentEvents(IDocument unprocessedDocument, List documentEvents) throws BadLocationException { + public static DocumentEvent mergeUnprocessedDocumentEvents(IDocument unprocessedDocument, List<? extends DocumentEvent> documentEvents) throws BadLocationException { if (documentEvents.size() == 0) return null; - final Iterator iterator= documentEvents.iterator(); - final DocumentEvent firstEvent= (DocumentEvent) iterator.next(); + final Iterator<? extends DocumentEvent> iterator= documentEvents.iterator(); + final DocumentEvent firstEvent= iterator.next(); // current merged event final IDocument document= unprocessedDocument; @@ -200,7 +200,7 @@ public class TextUtilities { final int delta= text.length() - length; - final DocumentEvent event= (DocumentEvent) iterator.next(); + final DocumentEvent event= iterator.next(); final int eventOffset= event.getOffset(); final int eventLength= event.getLength(); final String eventText= event.getText() == null ? "" : event.getText(); //$NON-NLS-1$ @@ -247,13 +247,13 @@ public class TextUtilities { * @return returns the merged document event * @throws BadLocationException might be thrown if document is not in the correct state with respect to document events */ - public static DocumentEvent mergeProcessedDocumentEvents(List documentEvents) throws BadLocationException { + public static DocumentEvent mergeProcessedDocumentEvents(List<? extends DocumentEvent> documentEvents) throws BadLocationException { if (documentEvents.size() == 0) return null; - final ListIterator iterator= documentEvents.listIterator(documentEvents.size()); - final DocumentEvent firstEvent= (DocumentEvent) iterator.previous(); + final ListIterator<? extends DocumentEvent> iterator= documentEvents.listIterator(documentEvents.size()); + final DocumentEvent firstEvent= iterator.previous(); // current merged event final IDocument document= firstEvent.getDocument(); @@ -265,7 +265,7 @@ public class TextUtilities { final int delta= length - textLength; - final DocumentEvent event= (DocumentEvent) iterator.previous(); + final DocumentEvent event= iterator.previous(); final int eventOffset= event.getOffset(); final int eventLength= event.getLength(); final int eventTextLength= event.getText() == null ? 0 : event.getText().length(); @@ -303,11 +303,10 @@ public class TextUtilities { * the given document is no longer connected to any document partitioner. * * @param document the document - * @return the map containing the removed partitioners (key type: {@link String}, value type: - * {@link IDocumentPartitioner}) + * @return the map containing the removed partitioners */ - public static Map removeDocumentPartitioners(IDocument document) { - Map partitioners= new HashMap(); + public static Map<String, IDocumentPartitioner> removeDocumentPartitioners(IDocument document) { + Map<String, IDocumentPartitioner> partitioners= new HashMap<>(); if (document instanceof IDocumentExtension3) { IDocumentExtension3 extension3= (IDocumentExtension3) document; String[] partitionings= extension3.getPartitionings(); @@ -335,23 +334,22 @@ public class TextUtilities { * their partitioning name. This method cleans the given map. * * @param document the document - * @param partitioners the map containing the partitioners to be connected (key type: {@link String}, value type: - * {@link IDocumentPartitioner}) + * @param partitioners the map containing the partitioners to be connected * @since 3.0 */ - public static void addDocumentPartitioners(IDocument document, Map partitioners) { + public static void addDocumentPartitioners(IDocument document, Map<String, ? extends IDocumentPartitioner> partitioners) { if (document instanceof IDocumentExtension3) { IDocumentExtension3 extension3= (IDocumentExtension3) document; - Iterator e= partitioners.keySet().iterator(); + Iterator<String> e= partitioners.keySet().iterator(); while (e.hasNext()) { - String partitioning= (String) e.next(); - IDocumentPartitioner partitioner= (IDocumentPartitioner) partitioners.get(partitioning); + String partitioning= e.next(); + IDocumentPartitioner partitioner= partitioners.get(partitioning); partitioner.connect(document); extension3.setDocumentPartitioner(partitioning, partitioner); } partitioners.clear(); } else { - IDocumentPartitioner partitioner= (IDocumentPartitioner) partitioners.get(IDocumentExtension3.DEFAULT_PARTITIONING); + IDocumentPartitioner partitioner= partitioners.get(IDocumentExtension3.DEFAULT_PARTITIONING); partitioner.connect(document); document.setDocumentPartitioner(partitioner); } @@ -451,7 +449,7 @@ public class TextUtilities { IDocumentExtension3 extension3= (IDocumentExtension3) document; String[] partitionings= extension3.getPartitionings(); if (partitionings != null) { - Set categories= new HashSet(); + Set<String> categories= new HashSet<>(); for (int i= 0; i < partitionings.length; i++) { IDocumentPartitioner p= extension3.getDocumentPartitioner(partitionings[i]); if (p instanceof IDocumentPartitionerExtension2) { diff --git a/org.eclipse.text/src/org/eclipse/jface/text/TreeLineTracker.java b/org.eclipse.text/src/org/eclipse/jface/text/TreeLineTracker.java index faede932120..9c2acf1bb5b 100755 --- a/org.eclipse.text/src/org/eclipse/jface/text/TreeLineTracker.java +++ b/org.eclipse.text/src/org/eclipse/jface/text/TreeLineTracker.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2010 IBM Corporation and others. + * Copyright (c) 2005, 2015 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 @@ -170,12 +170,12 @@ abstract class TreeLineTracker implements ILineTracker { * @param tracker the list line tracker */ TreeLineTracker(ListLineTracker tracker) { - final List lines= tracker.getLines(); + final List<Line> lines= tracker.getLines(); final int n= lines.size(); if (n == 0) return; - Line line= (Line) lines.get(0); + Line line= lines.get(0); String delim= line.delimiter; if (delim == null) delim= NO_DELIM; @@ -184,7 +184,7 @@ abstract class TreeLineTracker implements ILineTracker { Node node= fRoot; for (int i= 1; i < n; i++) { - line= (Line) lines.get(i); + line= lines.get(i); delim= line.delimiter; if (delim == null) delim= NO_DELIM; @@ -1229,7 +1229,7 @@ abstract class TreeLineTracker implements ILineTracker { int width= WIDTH * leaves; String empty= "."; //$NON-NLS-1$ - List roots= new LinkedList(); + List<Node> roots= new LinkedList<>(); roots.add(fRoot); StringBuffer buf= new StringBuffer((width + 1) * depth); int indents= leaves; @@ -1240,11 +1240,11 @@ abstract class TreeLineTracker implements ILineTracker { indents /= 2; int spaces= Math.max(0, indents * WIDTH - WIDTH / 2); // print nodes - for (ListIterator it= roots.listIterator(); it.hasNext();) { + for (ListIterator<Node> it= roots.listIterator(); it.hasNext();) { // pad before buf.append(space, 0, spaces); - Node node= (Node) it.next(); + Node node= it.next(); String box; // replace the node with its children if (node == null) { diff --git a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeManager.java b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeManager.java index d91f4a119ed..8334798e9ac 100644 --- a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeManager.java +++ b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeManager.java @@ -55,7 +55,7 @@ class LinkedModeManager { } /** Global map from documents to managers. */ - private static Map fgManagers= new HashMap(); + private static Map<IDocument, LinkedModeManager> fgManagers= new HashMap<>(); /** * Returns whether there exists a <code>LinkedModeManager</code> on <code>document</code>. @@ -94,17 +94,17 @@ class LinkedModeManager { if (documents == null || documents.length == 0) return null; - Set mgrs= new HashSet(); + Set<LinkedModeManager> mgrs= new HashSet<>(); LinkedModeManager mgr= null; for (int i= 0; i < documents.length; i++) { - mgr= (LinkedModeManager) fgManagers.get(documents[i]); + mgr= fgManagers.get(documents[i]); if (mgr != null) mgrs.add(mgr); } if (mgrs.size() > 1) if (force) { - for (Iterator it= mgrs.iterator(); it.hasNext(); ) { - LinkedModeManager m= (LinkedModeManager) it.next(); + for (Iterator<LinkedModeManager> it= mgrs.iterator(); it.hasNext(); ) { + LinkedModeManager m= it.next(); m.closeAllEnvironments(); } } else { @@ -126,13 +126,13 @@ class LinkedModeManager { * @param document the document whose <code>LinkedModeManager</code> should be canceled */ public static void cancelManager(IDocument document) { - LinkedModeManager mgr= (LinkedModeManager) fgManagers.get(document); + LinkedModeManager mgr= fgManagers.get(document); if (mgr != null) mgr.closeAllEnvironments(); } /** The hierarchy of environments managed by this manager. */ - private Stack fEnvironments= new Stack(); + private Stack<LinkedModeModel> fEnvironments= new Stack<>(); private Listener fListener= new Listener(); /** @@ -146,7 +146,7 @@ class LinkedModeManager { return; while (!fEnvironments.isEmpty()) { - LinkedModeModel env= (LinkedModeModel) fEnvironments.pop(); + LinkedModeModel env= fEnvironments.pop(); if (env == model) break; env.exit(ILinkedModeListener.NONE); @@ -159,7 +159,7 @@ class LinkedModeManager { private void closeAllEnvironments() { while (!fEnvironments.isEmpty()) { - LinkedModeModel env= (LinkedModeModel) fEnvironments.pop(); + LinkedModeModel env= fEnvironments.pop(); env.exit(ILinkedModeListener.NONE); } @@ -167,8 +167,8 @@ class LinkedModeManager { } private void removeManager() { - for (Iterator it= fgManagers.keySet().iterator(); it.hasNext();) { - IDocument doc= (IDocument) it.next(); + for (Iterator<IDocument> it= fgManagers.keySet().iterator(); it.hasNext();) { + IDocument doc= it.next(); if (fgManagers.get(doc) == this) it.remove(); } @@ -195,7 +195,7 @@ class LinkedModeManager { return true; } - LinkedModeModel top= (LinkedModeModel) fEnvironments.peek(); + LinkedModeModel top= fEnvironments.peek(); if (model.canNestInto(top)) { model.addLinkingListener(fListener); fEnvironments.push(model); @@ -223,6 +223,6 @@ class LinkedModeManager { public LinkedModeModel getTopEnvironment() { if (fEnvironments.isEmpty()) return null; - return (LinkedModeModel) fEnvironments.peek(); + return fEnvironments.peek(); } } diff --git a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeModel.java b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeModel.java index d6ad8897ef9..0a19721ca1b 100644 --- a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeModel.java +++ b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedModeModel.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2015 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 @@ -28,10 +28,10 @@ import org.eclipse.jface.text.BadPositionCategoryException; import org.eclipse.jface.text.DocumentEvent; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocumentExtension; +import org.eclipse.jface.text.IDocumentExtension.IReplace; import org.eclipse.jface.text.IDocumentListener; import org.eclipse.jface.text.IPositionUpdater; import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.IDocumentExtension.IReplace; /** @@ -182,8 +182,8 @@ public class LinkedModeModel { if (fParentEnvironment != null && fParentEnvironment.isChanging()) return; - for (Iterator it= fGroups.iterator(); it.hasNext(); ) { - LinkedPositionGroup group= (LinkedPositionGroup) it.next(); + for (Iterator<LinkedPositionGroup> it= fGroups.iterator(); it.hasNext(); ) { + LinkedPositionGroup group= it.next(); if (!group.isLegalEvent(event)) { fExit= true; return; @@ -209,11 +209,11 @@ public class LinkedModeModel { return; // collect all results - Map result= null; - for (Iterator it= fGroups.iterator(); it.hasNext();) { - LinkedPositionGroup group= (LinkedPositionGroup) it.next(); + Map<IDocument, TextEdit> result= null; + for (Iterator<LinkedPositionGroup> it= fGroups.iterator(); it.hasNext();) { + LinkedPositionGroup group= it.next(); - Map map= group.handleEvent(event); + Map<IDocument, TextEdit> map= group.handleEvent(event); if (result != null && map != null) { // exit if more than one position was changed LinkedModeModel.this.exit(ILinkedModeListener.EXTERNAL_MODIFICATION); @@ -225,9 +225,9 @@ public class LinkedModeModel { if (result != null) { // edit all documents - for (Iterator it2= result.keySet().iterator(); it2.hasNext(); ) { - IDocument doc= (IDocument) it2.next(); - TextEdit edit= (TextEdit) result.get(doc); + for (Iterator<IDocument> it2= result.keySet().iterator(); it2.hasNext(); ) { + IDocument doc= it2.next(); + TextEdit edit= result.get(doc); Replace replace= new Replace(edit); // apply the edition, either as post notification replace @@ -249,9 +249,9 @@ public class LinkedModeModel { } /** The set of linked position groups. */ - private final List fGroups= new ArrayList(); + private final List<LinkedPositionGroup> fGroups= new ArrayList<>(); /** The set of documents spanned by this group. */ - private final Set fDocuments= new HashSet(); + private final Set<IDocument> fDocuments= new HashSet<>(); /** The position updater for linked positions. */ private final IPositionUpdater fUpdater= new InclusivePositionUpdater(getCategory()); /** The document listener on the documents affected by this model. */ @@ -272,14 +272,14 @@ public class LinkedModeModel { /** <code>true</code> when this model is changing documents. */ private boolean fIsChanging= false; /** The linked listeners. */ - private final List fListeners= new ArrayList(); + private final List<ILinkedModeListener> fListeners= new ArrayList<>(); /** Flag telling whether we have exited: */ private boolean fIsActive= true; /** * The sequence of document positions as we are going to iterate through * them. */ - private List fPositionSequence= new ArrayList(); + private List<LinkedPosition> fPositionSequence= new ArrayList<>(); /** * Whether we are in the process of editing documents (set by <code>Replace</code>, @@ -301,8 +301,8 @@ public class LinkedModeModel { * model's groups */ private void enforceDisjoint(LinkedPositionGroup group) throws BadLocationException { - for (Iterator it= fGroups.iterator(); it.hasNext(); ) { - LinkedPositionGroup g= (LinkedPositionGroup) it.next(); + for (Iterator<LinkedPositionGroup> it= fGroups.iterator(); it.hasNext(); ) { + LinkedPositionGroup g= it.next(); g.enforceDisjoint(group); } } @@ -319,8 +319,8 @@ public class LinkedModeModel { fIsActive= false; - for (Iterator it= fDocuments.iterator(); it.hasNext(); ) { - IDocument doc= (IDocument) it.next(); + for (Iterator<IDocument> it= fDocuments.iterator(); it.hasNext(); ) { + IDocument doc= it.next(); try { doc.removePositionCategory(getCategory()); } catch (BadPositionCategoryException e) { @@ -334,10 +334,10 @@ public class LinkedModeModel { fDocuments.clear(); fGroups.clear(); - List listeners= new ArrayList(fListeners); + List<ILinkedModeListener> listeners= new ArrayList<>(fListeners); fListeners.clear(); - for (Iterator it= listeners.iterator(); it.hasNext(); ) { - ILinkedModeListener listener= (ILinkedModeListener) it.next(); + for (Iterator<ILinkedModeListener> it= listeners.iterator(); it.hasNext(); ) { + ILinkedModeListener listener= it.next(); listener.left(this, flags); } @@ -507,8 +507,8 @@ public class LinkedModeModel { // register positions try { - for (Iterator it= fGroups.iterator(); it.hasNext(); ) { - LinkedPositionGroup group= (LinkedPositionGroup) it.next(); + for (Iterator<LinkedPositionGroup> it= fGroups.iterator(); it.hasNext(); ) { + LinkedPositionGroup group= it.next(); group.register(this); } return true; @@ -525,8 +525,8 @@ public class LinkedModeModel { */ private void enforceNotEmpty() { boolean hasPosition= false; - for (Iterator it= fGroups.iterator(); it.hasNext(); ) - if (!((LinkedPositionGroup) it.next()).isEmpty()) { + for (Iterator<LinkedPositionGroup> it= fGroups.iterator(); it.hasNext(); ) + if (!it.next().isEmpty()) { hasPosition= true; break; } @@ -540,12 +540,12 @@ public class LinkedModeModel { * @return the set of documents affected by this model */ private IDocument[] getDocuments() { - Set docs= new HashSet(); - for (Iterator it= fGroups.iterator(); it.hasNext(); ) { - LinkedPositionGroup group= (LinkedPositionGroup) it.next(); + Set<IDocument> docs= new HashSet<>(); + for (Iterator<LinkedPositionGroup> it= fGroups.iterator(); it.hasNext(); ) { + LinkedPositionGroup group= it.next(); docs.addAll(Arrays.asList(group.getDocuments())); } - return (IDocument[]) docs.toArray(new IDocument[docs.size()]); + return docs.toArray(new IDocument[docs.size()]); } /** @@ -557,8 +557,8 @@ public class LinkedModeModel { * @return <code>true</code> if the receiver can be nested into <code>parent</code>, <code>false</code> otherwise */ boolean canNestInto(LinkedModeModel parent) { - for (Iterator it= fGroups.iterator(); it.hasNext(); ) { - LinkedPositionGroup group= (LinkedPositionGroup) it.next(); + for (Iterator<LinkedPositionGroup> it= fGroups.iterator(); it.hasNext(); ) { + LinkedPositionGroup group= it.next(); if (!enforceNestability(group, parent)) { fParentPosition= null; return false; @@ -584,8 +584,8 @@ public class LinkedModeModel { Assert.isNotNull(group); try { - for (Iterator it= model.fGroups.iterator(); it.hasNext(); ) { - LinkedPositionGroup pg= (LinkedPositionGroup) it.next(); + for (Iterator<LinkedPositionGroup> it= model.fGroups.iterator(); it.hasNext(); ) { + LinkedPositionGroup pg= it.next(); LinkedPosition pos; pos= pg.adopt(group); if (pos != null && fParentPosition != null && fParentPosition != pos) @@ -628,7 +628,7 @@ public class LinkedModeModel { * @return the positions in this model that have a tab stop, in the * order they were added */ - public List getTabStopSequence() { + public List<LinkedPosition> getTabStopSequence() { return fPositionSequence; } @@ -670,8 +670,8 @@ public class LinkedModeModel { */ public LinkedPosition findPosition(LinkedPosition toFind) { LinkedPosition position= null; - for (Iterator it= fGroups.iterator(); it.hasNext(); ) { - LinkedPositionGroup group= (LinkedPositionGroup) it.next(); + for (Iterator<LinkedPositionGroup> it= fGroups.iterator(); it.hasNext(); ) { + LinkedPositionGroup group= it.next(); position= group.getPosition(toFind); if (position != null) break; @@ -708,9 +708,9 @@ public class LinkedModeModel { * Suspends this model. */ private void suspend() { - List l= new ArrayList(fListeners); - for (Iterator it= l.iterator(); it.hasNext(); ) { - ILinkedModeListener listener= (ILinkedModeListener) it.next(); + List<ILinkedModeListener> l= new ArrayList<>(fListeners); + for (Iterator<ILinkedModeListener> it= l.iterator(); it.hasNext(); ) { + ILinkedModeListener listener= it.next(); listener.suspend(this); } } @@ -722,9 +722,9 @@ public class LinkedModeModel { * @param flags <code>NONE</code> or <code>SELECT</code> */ private void resume(int flags) { - List l= new ArrayList(fListeners); - for (Iterator it= l.iterator(); it.hasNext(); ) { - ILinkedModeListener listener= (ILinkedModeListener) it.next(); + List<ILinkedModeListener> l= new ArrayList<>(fListeners); + for (Iterator<ILinkedModeListener> it= l.iterator(); it.hasNext(); ) { + ILinkedModeListener listener= it.next(); listener.resume(this, flags); } } @@ -739,8 +739,8 @@ public class LinkedModeModel { * model, <code>false</code> otherwise */ public boolean anyPositionContains(int offset) { - for (Iterator it= fGroups.iterator(); it.hasNext(); ) { - LinkedPositionGroup group= (LinkedPositionGroup) it.next(); + for (Iterator<LinkedPositionGroup> it= fGroups.iterator(); it.hasNext(); ) { + LinkedPositionGroup group= it.next(); if (group.contains(offset)) // take the first hit - exclusion is guaranteed by enforcing // disjointness when adding positions @@ -767,8 +767,8 @@ public class LinkedModeModel { * or <code>null</code> if no group contains <code>position</code> */ public LinkedPositionGroup getGroupForPosition(Position position) { - for (Iterator it= fGroups.iterator(); it.hasNext(); ) { - LinkedPositionGroup group= (LinkedPositionGroup) it.next(); + for (Iterator<LinkedPositionGroup> it= fGroups.iterator(); it.hasNext(); ) { + LinkedPositionGroup group= it.next(); if (group.contains(position)) return group; } diff --git a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedPositionGroup.java b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedPositionGroup.java index 9c8450d316a..49f39fd2d77 100644 --- a/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedPositionGroup.java +++ b/org.eclipse.text/src/org/eclipse/jface/text/link/LinkedPositionGroup.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2014 IBM Corporation and others. + * Copyright (c) 2000, 2015 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 @@ -62,7 +62,7 @@ public class LinkedPositionGroup { /* members */ /** The linked positions of this group. */ - private final List fPositions= new LinkedList(); + private final List<LinkedPosition> fPositions= new LinkedList<>(); /** Whether we are sealed or not. */ private boolean fIsSealed= false; /** @@ -137,7 +137,7 @@ public class LinkedPositionGroup { */ private void checkContent(LinkedPosition position) throws BadLocationException { if (fPositions.size() > 0) { - LinkedPosition groupPosition= (LinkedPosition) fPositions.get(0); + LinkedPosition groupPosition= fPositions.get(0); String groupContent= groupPosition.getContent(); String positionContent= position.getContent(); if (!fMustEnforceEqualContents && !groupContent.equals(positionContent)) { @@ -153,8 +153,8 @@ public class LinkedPositionGroup { * @throws BadLocationException if the disjointness check fails */ private void enforceDisjoint(LinkedPosition position) throws BadLocationException { - for (Iterator it= fPositions.iterator(); it.hasNext(); ) { - LinkedPosition p= (LinkedPosition) it.next(); + for (Iterator<LinkedPosition> it= fPositions.iterator(); it.hasNext(); ) { + LinkedPosition p= it.next(); if (p.overlapsWith(position)) throw new BadLocationException(); } @@ -168,8 +168,8 @@ public class LinkedPositionGroup { */ void enforceDisjoint(LinkedPositionGroup group) throws BadLocationException { Assert.isNotNull(group); - for (Iterator it= group.fPositions.iterator(); it.hasNext(); ) { - LinkedPosition p= (LinkedPosition) it.next(); + for (Iterator<LinkedPosition> it= group.fPositions.iterator(); it.hasNext(); ) { + LinkedPosition p= it.next(); enforceDisjoint(p); } } @@ -186,8 +186,8 @@ public class LinkedPositionGroup { fLastPosition= null; fLastRegion= null; - for (Iterator it= fPositions.iterator(); it.hasNext(); ) { - LinkedPosition pos= (LinkedPosition) it.next(); + for (Iterator<LinkedPosition> it= fPositions.iterator(); it.hasNext(); ) { + LinkedPosition pos= it.next(); if (overlapsOrTouches(pos, event)) { if (fLastPosition != null) { fLastPosition= null; @@ -226,11 +226,11 @@ public class LinkedPositionGroup { * @return a map of edits, grouped by edited document, or <code>null</code> * if there are no edits */ - Map handleEvent(DocumentEvent event) { + Map<IDocument, TextEdit> handleEvent(DocumentEvent event) { if (fLastPosition != null) { - Map map= new HashMap(); + Map<IDocument, List<ReplaceEdit>> map= new HashMap<>(); int relativeOffset= event.getOffset() - fLastRegion.getOffset(); @@ -250,14 +250,14 @@ public class LinkedPositionGroup { if (text == null) text= ""; //$NON-NLS-1$ - for (Iterator it= fPositions.iterator(); it.hasNext(); ) { - LinkedPosition p= (LinkedPosition) it.next(); + for (Iterator<LinkedPosition> it= fPositions.iterator(); it.hasNext(); ) { + LinkedPosition p= it.next(); if (p == fLastPosition || p.isDeleted()) continue; // don't re-update the origin of the change - List edits= (List) map.get(p.getDocument()); + List<ReplaceEdit> edits= map.get(p.getDocument()); if (edits == null) { - edits= new ArrayList(); + edits= new ArrayList<>(); map.put(p.getDocument(), edits); } @@ -274,14 +274,15 @@ public class LinkedPositionGroup { fMustEnforceEqualContents= false; try { - for (Iterator it= map.keySet().iterator(); it.hasNext();) { - IDocument d= (IDocument) it.next(); + Map<IDocument, TextEdit> result= new HashMap<>(); + for (Iterator<IDocument> it= map.keySet().iterator(); it.hasNext();) { + IDocument d= it.next(); TextEdit edit= new MultiTextEdit(0, d.getLength()); - edit.addChildren((TextEdit[]) ((List) map.get(d)).toArray(new TextEdit[0])); - map.put(d, edit); + edit.addChildren(map.get(d).toArray(new TextEdit[0])); + result.put(d, edit); } - return map; + return result; } catch (MalformedTreeException x) { // may happen during undo, as LinkedModeModel does not know // that the changes technically originate from a parent environment @@ -305,23 +306,23 @@ public class LinkedPositionGroup { fIsSealed= true; if (fHasCustomIteration == false && fPositions.size() > 0) { - ((LinkedPosition) fPositions.get(0)).setSequenceNumber(0); + fPositions.get(0).setSequenceNumber(0); } } IDocument[] getDocuments() { IDocument[] docs= new IDocument[fPositions.size()]; int i= 0; - for (Iterator it= fPositions.iterator(); it.hasNext(); i++) { - LinkedPosition pos= (LinkedPosition) it.next(); + for (Iterator<LinkedPosition> it= fPositions.iterator(); it.hasNext(); i++) { + LinkedPosition pos= it.next(); docs[i]= pos.getDocument(); } return docs; } void register(LinkedModeModel model) throws BadLocationException { - for (Iterator it= fPositions.iterator(); it.hasNext(); ) { - LinkedPosition pos= (LinkedPosition) it.next(); + for (Iterator<LinkedPosition> it= fPositions.iterator(); it.hasNext(); ) { + LinkedPosition pos= it.next(); model.register(pos); } } @@ -338,11 +339,11 @@ public class LinkedPositionGroup { */ LinkedPosition adopt(LinkedPositionGroup group) throws BadLocationException { LinkedPosition found= null; - for (Iterator it= group.fPositions.iterator(); it.hasNext(); ) { - LinkedPosition pos= (LinkedPosition) it.next(); + for (Iterator<LinkedPosition> it= group.fPositions.iterator(); it.hasNext(); ) { + LinkedPosition pos= it.next(); LinkedPosition localFound= null; - for (Iterator it2= fPositions.iterator(); it2.hasNext(); ) { - LinkedPosition myPos= (LinkedPosition) it2.next(); + for (Iterator<LinkedPosition> it2= fPositions.iterator(); it2.hasNext(); ) { + LinkedPosition myPos= it2.next(); if (myPos.includes(pos)) { if (found == null) found= myPos; @@ -366,8 +367,8 @@ public class LinkedPositionGroup { * @return the closest position to <code>toFind</code>. */ LinkedPosition getPosition(LinkedPosition toFind) { - for (Iterator it= fPositions.iterator(); it.hasNext(); ) { - LinkedPosition p= (LinkedPosition) it.next(); + for (Iterator<LinkedPosition> it= fPositions.iterator(); it.hasNext(); ) { + LinkedPosition p= it.next(); if (p.includes(toFind)) return p; } @@ -382,8 +383,8 @@ public class LinkedPositionGroup { * @return <code>true</code> if offset is contained by this group */ boolean contains(int offset) { - for (Iterator it= fPositions.iterator(); it.hasNext(); ) { - LinkedPosition pos= (LinkedPosition) it.next(); + for (Iterator<LinkedPosition> it= fPositions.iterator(); it.hasNext(); ) { + LinkedPosition pos= it.next(); if (pos.includes(offset)) { return true; } @@ -420,7 +421,7 @@ public class LinkedPositionGroup { * @return the positions of this group in no particular order */ public LinkedPosition[] getPositions() { - return (LinkedPosition[]) fPositions.toArray(new LinkedPosition[0]); + return fPositions.toArray(new LinkedPosition[0]); } /** @@ -430,8 +431,8 @@ public class LinkedPositionGroup { * @return <code>true</code> if the receiver contains <code>position</code> */ boolean contains(Position position) { - for (Iterator it= fPositions.iterator(); it.hasNext(); ) { - LinkedPosition p= (LinkedPosition) it.next(); + for (Iterator<LinkedPosition> it= fPositions.iterator(); it.hasNext(); ) { + LinkedPosition p= it.next(); if (position.equals(p)) return true; } diff --git a/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationMap.java b/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationMap.java index 490083414c3..e43af5b7739 100644 --- a/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationMap.java +++ b/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationMap.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2015 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 @@ -18,6 +18,8 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; +import org.eclipse.jface.text.Position; + /** * Internal implementation of {@link org.eclipse.jface.text.source.IAnnotationMap}. @@ -38,7 +40,7 @@ class AnnotationMap implements IAnnotationMap { private final Object fInternalLockObject= new Object(); /** The map holding the annotations */ - private Map fInternalMap; + private Map<Annotation, Position> fInternalMap; /** * Creates a new annotation map with the given capacity. @@ -46,7 +48,7 @@ class AnnotationMap implements IAnnotationMap { * @param capacity the capacity */ public AnnotationMap(int capacity) { - fInternalMap= new HashMap(capacity); + fInternalMap= new HashMap<>(capacity); } @Override @@ -62,16 +64,16 @@ class AnnotationMap implements IAnnotationMap { } @Override - public Iterator valuesIterator() { + public Iterator<Position> valuesIterator() { synchronized (getLockObject()) { - return new ArrayList(fInternalMap.values()).iterator(); + return new ArrayList<>(fInternalMap.values()).iterator(); } } @Override - public Iterator keySetIterator() { + public Iterator<Annotation> keySetIterator() { synchronized (getLockObject()) { - return new ArrayList(fInternalMap.keySet()).iterator(); + return new ArrayList<>(fInternalMap.keySet()).iterator(); } } @@ -83,14 +85,14 @@ class AnnotationMap implements IAnnotationMap { } @Override - public Object put(Object annotation, Object position) { + public Position put(Annotation annotation, Position position) { synchronized (getLockObject()) { return fInternalMap.put(annotation, position); } } @Override - public Object get(Object annotation) { + public Position get(Object annotation) { synchronized (getLockObject()) { return fInternalMap.get(annotation); } @@ -104,7 +106,7 @@ class AnnotationMap implements IAnnotationMap { } @Override - public Object remove(Object annotation) { + public Position remove(Object annotation) { synchronized (getLockObject()) { return fInternalMap.remove(annotation); } @@ -132,28 +134,28 @@ class AnnotationMap implements IAnnotationMap { } @Override - public void putAll(Map map) { + public void putAll(Map<? extends Annotation, ? extends Position> map) { synchronized (getLockObject()) { fInternalMap.putAll(map); } } @Override - public Set entrySet() { + public Set<Entry<Annotation, Position>> entrySet() { synchronized (getLockObject()) { return fInternalMap.entrySet(); } } @Override - public Set keySet() { + public Set<Annotation> keySet() { synchronized (getLockObject()) { return fInternalMap.keySet(); } } @Override - public Collection values() { + public Collection<Position> values() { synchronized (getLockObject()) { return fInternalMap.values(); } diff --git a/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java b/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java index 3631aee4f0d..d3ae54c0c69 100644 --- a/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java +++ b/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModel.java @@ -18,6 +18,7 @@ import java.util.IdentityHashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.NoSuchElementException; import org.eclipse.core.runtime.Assert; @@ -49,13 +50,13 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens * @since 3.4 * @see AnnotationModel.RegionIterator#RegionIterator(Iterator, IAnnotationModel, int, int, boolean, boolean) */ - private static final class RegionIterator implements Iterator { + private static final class RegionIterator implements Iterator<Annotation> { - private final Iterator fParentIterator; + private final Iterator<Annotation> fParentIterator; private final boolean fCanEndAfter; private final boolean fCanStartBefore; private final IAnnotationModel fModel; - private Object fNext; + private Annotation fNext; private Position fRegion; /** @@ -74,7 +75,7 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens * @param canEndAfter include annotations ending after region * @see IAnnotationModelExtension2 */ - public RegionIterator(Iterator parentIterator, IAnnotationModel model, int offset, int length, boolean canStartBefore, boolean canEndAfter) { + public RegionIterator(Iterator<Annotation> parentIterator, IAnnotationModel model, int offset, int length, boolean canStartBefore, boolean canEndAfter) { fParentIterator= parentIterator; fModel= model; fRegion= new Position(offset, length); @@ -89,11 +90,11 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens } @Override - public Object next() { + public Annotation next() { if (!hasNext()) throw new NoSuchElementException(); - Object result= fNext; + Annotation result= fNext; fNext= findNext(); return result; } @@ -103,9 +104,9 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens throw new UnsupportedOperationException(); } - private Object findNext() { + private Annotation findNext() { while (fParentIterator.hasNext()) { - Annotation next= (Annotation) fParentIterator.next(); + Annotation next= fParentIterator.next(); Position position= fModel.getPosition(next); if (position != null) { int offset= position.getOffset(); @@ -134,18 +135,18 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens * * @since 3.4 */ - private static final class AnnotationsInterator implements Iterator { + private static final class AnnotationsInterator implements Iterator<Annotation> { - private Object fNext; + private Annotation fNext; private final Position[] fPositions; private int fIndex; - private final Map fMap; + private final Map<Position, Annotation> fMap; /** * @param positions positions to iterate over * @param map a map to map positions to annotations */ - public AnnotationsInterator(Position[] positions, Map map) { + public AnnotationsInterator(Position[] positions, Map<Position, Annotation> map) { fPositions= positions; fIndex= 0; fMap= map; @@ -158,8 +159,8 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens } @Override - public Object next() { - Object result= fNext; + public Annotation next() { + Annotation result= fNext; fNext= findNext(); return result; } @@ -169,7 +170,7 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens throw new UnsupportedOperationException(); } - private Object findNext() { + private Annotation findNext() { while (fIndex < fPositions.length) { Position position= fPositions[fIndex]; fIndex++; @@ -183,22 +184,23 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens /** * A single iterator builds its behavior based on a sequence of iterators. - * + * + * @param <E> the type of elements returned by this iterator * @since 3.1 */ - private static class MetaIterator implements Iterator { + private static class MetaIterator<E> implements Iterator<E> { /** The iterator over a list of iterators. */ - private Iterator fSuperIterator; + private Iterator<? extends Iterator<? extends E>> fSuperIterator; /** The current iterator. */ - private Iterator fCurrent; + private Iterator<? extends E> fCurrent; /** The current element. */ - private Object fCurrentElement; + private E fCurrentElement; - public MetaIterator(Iterator iterator) { + public MetaIterator(Iterator<? extends Iterator<? extends E>> iterator) { fSuperIterator= iterator; - fCurrent= (Iterator) fSuperIterator.next(); // there is at least one. + fCurrent= fSuperIterator.next(); // there is at least one. } @Override @@ -215,18 +217,18 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens fCurrentElement= fCurrent.next(); return true; } else if (fSuperIterator.hasNext()) { - fCurrent= (Iterator) fSuperIterator.next(); + fCurrent= fSuperIterator.next(); return hasNext(); } else return false; } @Override - public Object next() { + public E next() { if (!hasNext()) throw new NoSuchElementException(); - Object element= fCurrentElement; + E element= fCurrentElement; fCurrentElement= null; return element; } @@ -256,14 +258,14 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens * @deprecated since 3.0 use <code>getAnnotationMap</code> instead */ @Deprecated - protected Map fAnnotations; + protected Map<Annotation, Position> fAnnotations; /** * The map which maps {@link Position} to {@link Annotation}. * @since 3.4 **/ - private IdentityHashMap fPositions; + private IdentityHashMap<Position, Annotation> fPositions; /** The list of annotation model listeners */ - protected ArrayList fAnnotationModelListeners; + protected ArrayList<IAnnotationModelListener> fAnnotationModelListeners; /** The document connected with this model */ protected IDocument fDocument; /** The number of open connections to the same document */ @@ -276,7 +278,7 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens * The model's attachment. * @since 3.0 */ - private Map fAttachments= new HashMap(); + private Map<Object, IAnnotationModel> fAttachments= new HashMap<>(); /** * The annotation model listener on attached sub-models. * @since 3.0 @@ -299,8 +301,8 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens */ public AnnotationModel() { fAnnotations= new AnnotationMap(10); - fPositions= new IdentityHashMap(10); - fAnnotationModelListeners= new ArrayList(2); + fPositions= new IdentityHashMap<>(10); + fAnnotationModelListeners= new ArrayList<>(2); fDocumentListener= new IDocumentListener() { @@ -363,7 +365,7 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens } @Override - public void replaceAnnotations(Annotation[] annotationsToRemove, Map annotationsToAdd) { + public void replaceAnnotations(Annotation[] annotationsToRemove, Map<? extends Annotation, ? extends Position> annotationsToAdd) { try { replaceAnnotations(annotationsToRemove, annotationsToAdd, true); } catch (BadLocationException x) { @@ -382,7 +384,7 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens * invalid position * @since 3.0 */ - protected void replaceAnnotations(Annotation[] annotationsToRemove, Map annotationsToAdd, boolean fireModelChanged) throws BadLocationException { + protected void replaceAnnotations(Annotation[] annotationsToRemove, Map<? extends Annotation, ? extends Position> annotationsToAdd, boolean fireModelChanged) throws BadLocationException { if (annotationsToRemove != null) { for (int i= 0, length= annotationsToRemove.length; i < length; i++) @@ -390,11 +392,11 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens } if (annotationsToAdd != null) { - Iterator iter= annotationsToAdd.entrySet().iterator(); + Iterator<? extends Entry<? extends Annotation, ? extends Position>> iter= annotationsToAdd.entrySet().iterator(); while (iter.hasNext()) { - Map.Entry mapEntry= (Map.Entry) iter.next(); - Annotation annotation= (Annotation) mapEntry.getKey(); - Position position= (Position) mapEntry.getValue(); + Map.Entry<? extends Annotation, ? extends Position> mapEntry= iter.next(); + Annotation annotation= mapEntry.getKey(); + Position position= mapEntry.getValue(); addAnnotation(annotation, position, false); } } @@ -476,10 +478,10 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens if (fDocument == null) { fDocument= document; - Iterator e= getAnnotationMap().valuesIterator(); + Iterator<Position> e= getAnnotationMap().valuesIterator(); while (e.hasNext()) try { - addPosition(document, (Position) e.next()); + addPosition(document, e.next()); } catch (BadLocationException x) { // ignore invalid position } @@ -491,8 +493,8 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens connected(); } - for (Iterator it= fAttachments.keySet().iterator(); it.hasNext();) { - IAnnotationModel model= (IAnnotationModel) fAttachments.get(it.next()); + for (Iterator<Object> it= fAttachments.keySet().iterator(); it.hasNext();) { + IAnnotationModel model= fAttachments.get(it.next()); model.connect(document); } } @@ -516,8 +518,8 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens Assert.isTrue(fDocument == document); - for (Iterator it= fAttachments.keySet().iterator(); it.hasNext();) { - IAnnotationModel model= (IAnnotationModel) fAttachments.get(it.next()); + for (Iterator<Object> it= fAttachments.keySet().iterator(); it.hasNext();) { + IAnnotationModel model= fAttachments.get(it.next()); model.disconnect(document); } @@ -527,9 +529,9 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens disconnected(); document.removeDocumentListener(fDocumentListener); - Iterator e= getAnnotationMap().valuesIterator(); + Iterator<Position> e= getAnnotationMap().valuesIterator(); while (e.hasNext()) { - Position p= (Position) e.next(); + Position p= e.next(); removePosition(document, p); } fDocument= null; @@ -579,10 +581,10 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens if (event.isEmpty()) return; - ArrayList v= new ArrayList(fAnnotationModelListeners); - Iterator e= v.iterator(); + ArrayList<IAnnotationModelListener> v= new ArrayList<>(fAnnotationModelListeners); + Iterator<IAnnotationModelListener> e= v.iterator(); while (e.hasNext()) { - IAnnotationModelListener l= (IAnnotationModelListener) e.next(); + IAnnotationModelListener l= e.next(); if (l instanceof IAnnotationModelListenerExtension) ((IAnnotationModelListenerExtension) l).modelChanged(event); else if (l != null) @@ -600,11 +602,11 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens * @param fireModelChanged indicates whether to notify all model listeners * @param modelInitiated indicates whether this changes has been initiated by this model */ - protected void removeAnnotations(List annotations, boolean fireModelChanged, boolean modelInitiated) { + protected void removeAnnotations(List<? extends Annotation> annotations, boolean fireModelChanged, boolean modelInitiated) { if (annotations.size() > 0) { - Iterator e= annotations.iterator(); + Iterator<? extends Annotation> e= annotations.iterator(); while (e.hasNext()) - removeAnnotation((Annotation) e.next(), false); + removeAnnotation(e.next(), false); if (fireModelChanged) fireModelChanged(); @@ -634,11 +636,11 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens if (fDocumentChanged) { fDocumentChanged= false; - ArrayList deleted= new ArrayList(); - Iterator e= getAnnotationMap().keySetIterator(); + ArrayList<Annotation> deleted= new ArrayList<>(); + Iterator<Annotation> e= getAnnotationMap().keySetIterator(); while (e.hasNext()) { - Annotation a= (Annotation) e.next(); - Position p= (Position) fAnnotations.get(a); + Annotation a= e.next(); + Position p= fAnnotations.get(a); if (p == null || p.isDeleted()) deleted.add(a); } @@ -660,7 +662,7 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens } @Override - public Iterator getAnnotationIterator() { + public Iterator<Annotation> getAnnotationIterator() { return getAnnotationIterator(true, true); } @@ -670,24 +672,24 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens * @since 3.4 */ @Override - public Iterator getAnnotationIterator(int offset, int length, boolean canStartBefore, boolean canEndAfter) { - Iterator regionIterator= getRegionAnnotationIterator(offset, length, canStartBefore, canEndAfter); + public Iterator<Annotation> getAnnotationIterator(int offset, int length, boolean canStartBefore, boolean canEndAfter) { + Iterator<Annotation> regionIterator= getRegionAnnotationIterator(offset, length, canStartBefore, canEndAfter); if (fAttachments.isEmpty()) return regionIterator; - List iterators= new ArrayList(fAttachments.size() + 1); + List<Iterator<Annotation>> iterators= new ArrayList<>(fAttachments.size() + 1); iterators.add(regionIterator); - Iterator it= fAttachments.keySet().iterator(); + Iterator<Object> it= fAttachments.keySet().iterator(); while (it.hasNext()) { - IAnnotationModel attachment= (IAnnotationModel) fAttachments.get(it.next()); + IAnnotationModel attachment= fAttachments.get(it.next()); if (attachment instanceof IAnnotationModelExtension2) iterators.add(((IAnnotationModelExtension2) attachment).getAnnotationIterator(offset, length, canStartBefore, canEndAfter)); else iterators.add(new RegionIterator(attachment.getAnnotationIterator(), attachment, offset, length, canStartBefore, canEndAfter)); } - return new MetaIterator(iterators.iterator()); + return new MetaIterator<>(iterators.iterator()); } /** @@ -701,7 +703,7 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens * @see IAnnotationModelExtension2#getAnnotationIterator(int, int, boolean, boolean) * @since 3.4 */ - private Iterator getRegionAnnotationIterator(int offset, int length, boolean canStartBefore, boolean canEndAfter) { + private Iterator<Annotation> getRegionAnnotationIterator(int offset, int length, boolean canStartBefore, boolean canEndAfter) { if (!(fDocument instanceof AbstractDocument)) return new RegionIterator(getAnnotationIterator(true), this, offset, length, canStartBefore, canEndAfter); @@ -713,7 +715,7 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens return new AnnotationsInterator(positions, fPositions); } catch (BadPositionCategoryException e) { // can happen if e.g. the document doesn't contain such a category, or when removed in a different thread - return Collections.EMPTY_LIST.iterator(); + return Collections.<Annotation>emptyList().iterator(); } } @@ -728,18 +730,18 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens * @return all annotations managed by this model * @since 3.0 */ - private Iterator getAnnotationIterator(boolean cleanup, boolean recurse) { - Iterator iter= getAnnotationIterator(cleanup); + private Iterator<Annotation> getAnnotationIterator(boolean cleanup, boolean recurse) { + Iterator<Annotation> iter= getAnnotationIterator(cleanup); if (!recurse || fAttachments.isEmpty()) return iter; - List iterators= new ArrayList(fAttachments.size() + 1); + List<Iterator<Annotation>> iterators= new ArrayList<>(fAttachments.size() + 1); iterators.add(iter); - Iterator it= fAttachments.keySet().iterator(); + Iterator<Object> it= fAttachments.keySet().iterator(); while (it.hasNext()) - iterators.add(((IAnnotationModel) fAttachments.get(it.next())).getAnnotationIterator()); + iterators.add(fAttachments.get(it.next()).getAnnotationIterator()); - return new MetaIterator(iterators.iterator()); + return new MetaIterator<>(iterators.iterator()); } /** @@ -750,7 +752,7 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens * @param cleanup indicates whether annotations with deleted associated positions are removed * @return all annotations managed by this model */ - protected Iterator getAnnotationIterator(boolean cleanup) { + protected Iterator<Annotation> getAnnotationIterator(boolean cleanup) { if (cleanup) cleanup(true); @@ -759,13 +761,13 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens @Override public Position getPosition(Annotation annotation) { - Position position= (Position) fAnnotations.get(annotation); + Position position= fAnnotations.get(annotation); if (position != null) return position; - Iterator it= fAttachments.values().iterator(); + Iterator<IAnnotationModel> it= fAttachments.values().iterator(); while (position == null && it.hasNext()) - position= ((IAnnotationModel) it.next()).getPosition(annotation); + position= it.next().getPosition(annotation); return position; } @@ -783,10 +785,10 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens protected void removeAllAnnotations(boolean fireModelChanged) { if (fDocument != null) { - Iterator e= getAnnotationMap().keySetIterator(); + Iterator<Annotation> e= getAnnotationMap().keySetIterator(); while (e.hasNext()) { - Annotation a= (Annotation) e.next(); - Position p= (Position) fAnnotations.get(a); + Annotation a= e.next(); + Position p= fAnnotations.get(a); removePosition(fDocument, p); // p.delete(); synchronized (getLockObject()) { @@ -818,7 +820,7 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens if (fAnnotations.containsKey(annotation)) { Position p= null; - p= (Position) fAnnotations.get(annotation); + p= fAnnotations.get(annotation); if (fDocument != null) { removePosition(fDocument, p); // p.delete(); @@ -860,7 +862,7 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens if (position == null) { removeAnnotation(annotation, fireModelChanged); } else { - Position p= (Position) fAnnotations.get(annotation); + Position p= fAnnotations.get(annotation); if (p != null) { if (position.getOffset() != p.getOffset() || position.getLength() != p.getLength()) { @@ -936,7 +938,7 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens */ @Override public IAnnotationModel getAnnotationModel(Object key) { - return (IAnnotationModel) fAttachments.get(key); + return fAttachments.get(key); } /* @@ -945,7 +947,7 @@ public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtens */ @Override public IAnnotationModel removeAnnotationModel(Object key) { - IAnnotationModel ret= (IAnnotationModel) fAttachments.remove(key); + IAnnotationModel ret= fAttachments.remove(key); if (ret != null) { for (int i= 0; i < fOpenConnections; i++) ret.disconnect(fDocument); diff --git a/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModelEvent.java b/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModelEvent.java index 5c78b1fcbc1..5858b07498f 100644 --- a/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModelEvent.java +++ b/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModelEvent.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2015 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 @@ -39,17 +39,17 @@ public class AnnotationModelEvent { * The added annotations. * @since 3.0 */ - private Set fAddedAnnotations= new HashSet(); + private Set<Annotation> fAddedAnnotations= new HashSet<>(); /** * The removed annotations. * @since 3.0 */ - private Map fRemovedAnnotations= new HashMap(); + private Map<Annotation, Position> fRemovedAnnotations= new HashMap<>(); /** * The changed annotations. * @since 3.0 */ - private Set fChangedAnnotations= new HashSet(); + private Set<Annotation> fChangedAnnotations= new HashSet<>(); /** * Indicates that this event does not contain detailed information. * @since 3.0 @@ -165,7 +165,7 @@ public class AnnotationModelEvent { * @since 3.0 */ public Position getPositionOfRemovedAnnotation(Annotation annotation) { - return (Position) fRemovedAnnotations.get(annotation); + return fRemovedAnnotations.get(annotation); } /** diff --git a/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationMap.java b/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationMap.java index 4c73d8045d7..b7f979fae22 100644 --- a/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationMap.java +++ b/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationMap.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2015 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 @@ -17,6 +17,7 @@ import java.util.Map; import java.util.Set; import org.eclipse.jface.text.ISynchronizable; +import org.eclipse.jface.text.Position; /** @@ -36,21 +37,21 @@ import org.eclipse.jface.text.ISynchronizable; * @see org.eclipse.jface.text.source.IAnnotationModel * @since 3.0 */ -public interface IAnnotationMap extends Map, ISynchronizable { +public interface IAnnotationMap extends Map<Annotation, Position>, ISynchronizable { /** * Returns an iterator for a copy of this annotation map's values. * * @return an iterator for a copy of this map's values */ - Iterator valuesIterator(); + Iterator<Position> valuesIterator(); /** * Returns an iterator for a copy of this map's key set. * * @return an iterator for a copy of this map's key set */ - Iterator keySetIterator(); + Iterator<Annotation> keySetIterator(); /** * {@inheritDoc} @@ -58,7 +59,7 @@ public interface IAnnotationMap extends Map, ISynchronizable { * The returned set is not synchronized on this annotation map's lock object. */ @Override - Set entrySet(); + Set<Entry<Annotation, Position>> entrySet(); /** * {@inheritDoc} @@ -66,7 +67,7 @@ public interface IAnnotationMap extends Map, ISynchronizable { * The returned set is not synchronized on this annotation map's lock object. */ @Override - Set keySet(); + Set<Annotation> keySet(); /** * {@inheritDoc} @@ -74,5 +75,5 @@ public interface IAnnotationMap extends Map, ISynchronizable { * The returned collection is not synchronized on this annotation map's lock object. */ @Override - Collection values(); + Collection<Position> values(); } diff --git a/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModel.java b/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModel.java index 5a813ea187a..2ba27b63048 100644 --- a/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModel.java +++ b/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModel.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2015 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 @@ -131,9 +131,9 @@ public interface IAnnotationModel { /** * Returns all annotations managed by this model. * - * @return all annotations managed by this model (element type: {@link Annotation}) + * @return all annotations managed by this model */ - Iterator getAnnotationIterator(); + Iterator<Annotation> getAnnotationIterator(); /** * Returns the position associated with the given annotation. diff --git a/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModelExtension.java b/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModelExtension.java index 6ea5fabd359..e7db30991d4 100644 --- a/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModelExtension.java +++ b/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModelExtension.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2015 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 @@ -75,7 +75,7 @@ public interface IAnnotationModelExtension { * @throws ClassCastException if one of the map key or values has a wrong * type */ - void replaceAnnotations(Annotation[] annotationsToRemove, Map annotationsToAdd) throws ClassCastException; + void replaceAnnotations(Annotation[] annotationsToRemove, Map<? extends Annotation, ? extends Position> annotationsToAdd) throws ClassCastException; /** * Modifies the position associated with the given annotation to equal the diff --git a/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModelExtension2.java b/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModelExtension2.java index 745b479d5db..7533db23214 100644 --- a/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModelExtension2.java +++ b/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationModelExtension2.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 IBM Corporation and others. + * Copyright (c) 2007, 2015 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 @@ -31,7 +31,7 @@ public interface IAnnotationModelExtension2 { * which start before the region if they end at or after the region's start * @param canEndAfter if <code>true</code> then annotations are included * which end after the region if they start at or before the region's end - * @return all annotations inside the region managed by this model (element type: {@link Annotation}) + * @return all annotations inside the region managed by this model */ - Iterator getAnnotationIterator(int offset, int length, boolean canStartBefore, boolean canEndAfter); + Iterator<Annotation> getAnnotationIterator(int offset, int length, boolean canStartBefore, boolean canEndAfter); } diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContext.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContext.java index 6dc5d1abc25..e6a54921d2c 100644 --- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContext.java +++ b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContext.java @@ -29,7 +29,7 @@ public abstract class TemplateContext { /** The context type of this context */ private final TemplateContextType fContextType; /** Additional variables. */ - private final Map fVariables= new HashMap(); + private final Map<String, String> fVariables= new HashMap<>(); /** A flag to indicate that the context should not be modified. */ private boolean fReadOnly; @@ -87,7 +87,7 @@ public abstract class TemplateContext { * @return returns the value of the variable, <code>null</code> if the variable was not defined */ public String getVariable(String name) { - return (String) fVariables.get(name); + return fVariables.get(name); } /** diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContextType.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContextType.java index 756df860730..b856c04a240 100644 --- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContextType.java +++ b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContextType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2015 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 @@ -48,7 +48,7 @@ public class TemplateContextType { private /* final */ String fId= null; /** Variable resolvers used by this content type. */ - private final Map/*<String, TemplateVariableResolver>*/ fResolvers= new HashMap(); + private final Map<String, TemplateVariableResolver> fResolvers= new HashMap<>(); /** The name of the context type. */ private String fName= null; @@ -172,9 +172,9 @@ public class TemplateContextType { /** * Returns an iterator for the variables known to the context type. * - * @return an iterator over the variables in this context type (element type: {@link TemplateVariableResolver}) + * @return an iterator over the variables in this context type */ - public Iterator resolvers() { + public Iterator<TemplateVariableResolver> resolvers() { return Collections.unmodifiableMap(fResolvers).values().iterator(); } @@ -185,7 +185,7 @@ public class TemplateContextType { * @return a resolver for the given type, or <code>null</code> if none is registered */ protected TemplateVariableResolver getResolver(String type) { - return (TemplateVariableResolver) fResolvers.get(type); + return fResolvers.get(type); } /** @@ -229,8 +229,8 @@ public class TemplateContextType { Assert.isNotNull(context); TemplateVariable[] variables= buffer.getVariables(); - List positions= variablesToPositions(variables); - List edits= new ArrayList(5); + List<RangeMarker> positions= variablesToPositions(variables); + List<ReplaceEdit> edits= new ArrayList<>(5); // iterate over all variables and try to resolve them for (int i= 0; i != variables.length; i++) { @@ -249,8 +249,8 @@ public class TemplateContextType { IDocument document= new Document(buffer.getString()); MultiTextEdit edit= new MultiTextEdit(0, document.getLength()); - edit.addChildren((TextEdit[]) positions.toArray(new TextEdit[positions.size()])); - edit.addChildren((TextEdit[]) edits.toArray(new TextEdit[edits.size()])); + edit.addChildren(positions.toArray(new TextEdit[positions.size()])); + edit.addChildren(edits.toArray(new TextEdit[edits.size()])); edit.apply(document, TextEdit.UPDATE_REGIONS); positionsToVariables(positions, variables); @@ -267,14 +267,14 @@ public class TemplateContextType { */ public void resolve(TemplateVariable variable, TemplateContext context) { String type= variable.getType(); - TemplateVariableResolver resolver= (TemplateVariableResolver) fResolvers.get(type); + TemplateVariableResolver resolver= fResolvers.get(type); if (resolver == null) resolver= new TemplateVariableResolver(type, ""); //$NON-NLS-1$ resolver.resolve(variable, context); } - private static List variablesToPositions(TemplateVariable[] variables) { - List positions= new ArrayList(5); + private static List<RangeMarker> variablesToPositions(TemplateVariable[] variables) { + List<RangeMarker> positions= new ArrayList<>(5); for (int i= 0; i != variables.length; i++) { int[] offsets= variables[i].getOffsets(); for (int j= 0; j != offsets.length; j++) @@ -284,15 +284,15 @@ public class TemplateContextType { return positions; } - private static void positionsToVariables(List positions, TemplateVariable[] variables) { - Iterator iterator= positions.iterator(); + private static void positionsToVariables(List<RangeMarker> positions, TemplateVariable[] variables) { + Iterator<RangeMarker> iterator= positions.iterator(); for (int i= 0; i != variables.length; i++) { TemplateVariable variable= variables[i]; int[] offsets= new int[variable.getOffsets().length]; for (int j= 0; j != offsets.length; j++) - offsets[j]= ((TextEdit) iterator.next()).getOffset(); + offsets[j]= iterator.next().getOffset(); variable.setOffsets(offsets); } diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateTranslator.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateTranslator.java index 9cf79156f27..0b74d8481a1 100644 --- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateTranslator.java +++ b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateTranslator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2015 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 @@ -108,7 +108,7 @@ public class TemplateTranslator { * @since 3.3 */ private final class VariableDescription { - final List fOffsets= new ArrayList(5); + final List<Integer> fOffsets= new ArrayList<>(5); final String fName; TemplateVariableType fType; @@ -186,7 +186,7 @@ public class TemplateTranslator { fErrorMessage= null; final StringBuffer buffer= new StringBuffer(string.length()); final Matcher matcher= ESCAPE_PATTERN.matcher(string); - final Map variables= new LinkedHashMap(); + final Map<String, VariableDescription> variables= new LinkedHashMap<>(); int complete= 0; while (matcher.find()) { @@ -227,7 +227,7 @@ public class TemplateTranslator { return new TemplateVariableType(typeName); final Matcher matcher= PARAM_PATTERN.matcher(paramString); - List params= new ArrayList(5); + List<String> params= new ArrayList<>(5); while (matcher.find()) { String argument= matcher.group(); if (argument.charAt(0) == '\'') { @@ -238,7 +238,7 @@ public class TemplateTranslator { params.add(argument); } - return new TemplateVariableType(typeName, (String[]) params.toArray(new String[params.size()])); + return new TemplateVariableType(typeName, params.toArray(new String[params.size()])); } private void fail(String message) throws TemplateException { @@ -258,8 +258,8 @@ public class TemplateTranslator { * @throws TemplateException if merging the type fails * @since 3.3 */ - private void updateOrCreateVariable(Map variables, String name, TemplateVariableType type, int offset) throws TemplateException { - VariableDescription varDesc= (VariableDescription) variables.get(name); + private void updateOrCreateVariable(Map<String, VariableDescription> variables, String name, TemplateVariableType type, int offset) throws TemplateException { + VariableDescription varDesc= variables.get(name); if (varDesc == null) { varDesc= new VariableDescription(name, type); variables.put(name, varDesc); @@ -276,16 +276,16 @@ public class TemplateTranslator { * @return the corresponding variables * @since 3.3 */ - private TemplateVariable[] createVariables(Map variables) { + private TemplateVariable[] createVariables(Map<String, VariableDescription> variables) { TemplateVariable[] result= new TemplateVariable[variables.size()]; int idx= 0; - for (Iterator it= variables.values().iterator(); it.hasNext(); idx++) { - VariableDescription desc= (VariableDescription) it.next(); + for (Iterator<VariableDescription> it= variables.values().iterator(); it.hasNext(); idx++) { + VariableDescription desc= it.next(); TemplateVariableType type= desc.fType == null ? new TemplateVariableType(desc.fName) : desc.fType; int[] offsets= new int[desc.fOffsets.size()]; int i= 0; - for (Iterator intIt= desc.fOffsets.iterator(); intIt.hasNext(); i++) { - Integer offset= (Integer) intIt.next(); + for (Iterator<Integer> intIt= desc.fOffsets.iterator(); intIt.hasNext(); i++) { + Integer offset= intIt.next(); offsets[i]= offset.intValue(); } fCurrentType= type; diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateVariableType.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateVariableType.java index e3b705f1354..eaffa9a7db1 100644 --- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateVariableType.java +++ b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateVariableType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 IBM Corporation and others. + * Copyright (c) 2006, 2015 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 @@ -30,7 +30,7 @@ public final class TemplateVariableType { /** The name of the type. */ private final String fName; /** The parameter list. */ - private final List fParams; + private final List<String> fParams; TemplateVariableType(String name) { this(name, new String[0]); @@ -40,7 +40,7 @@ public final class TemplateVariableType { Assert.isLegal(name != null); Assert.isLegal(params != null); fName= name; - fParams= Collections.unmodifiableList(new ArrayList(Arrays.asList(params))); + fParams= Collections.unmodifiableList(new ArrayList<>(Arrays.asList(params))); } /** @@ -53,11 +53,11 @@ public final class TemplateVariableType { } /** - * Returns the unmodifiable and possibly empty list of parameters (element type: {@link String}) + * Returns the unmodifiable and possibly empty list of parameters * * @return the list of parameters */ - public List getParams() { + public List<String> getParams() { return fParams; } diff --git a/org.eclipse.text/src/org/eclipse/text/edits/CopySourceEdit.java b/org.eclipse.text/src/org/eclipse/text/edits/CopySourceEdit.java index d6c513c18d6..03daeb57d60 100644 --- a/org.eclipse.text/src/org/eclipse/text/edits/CopySourceEdit.java +++ b/org.eclipse.text/src/org/eclipse/text/edits/CopySourceEdit.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2015 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 @@ -45,7 +45,7 @@ public final class CopySourceEdit extends TextEdit { private static class PartialCopier extends TextEditVisitor { TextEdit fResult; - List fParents= new ArrayList(); + List<TextEdit> fParents= new ArrayList<>(); TextEdit fCurrentParent; public static TextEdit perform(TextEdit source) { @@ -64,7 +64,7 @@ public final class CopySourceEdit extends TextEdit { } @Override public void postVisit(TextEdit edit) { - fCurrentParent= (TextEdit)fParents.remove(fParents.size() - 1); + fCurrentParent= fParents.remove(fParents.size() - 1); } @Override public boolean visitNode(TextEdit edit) { @@ -220,22 +220,22 @@ public final class CopySourceEdit extends TextEdit { //---- consistency check ---------------------------------------------------- @Override - int traverseConsistencyCheck(TextEditProcessor processor, IDocument document, List sourceEdits) { + int traverseConsistencyCheck(TextEditProcessor processor, IDocument document, List<List<TextEdit>> sourceEdits) { int result= super.traverseConsistencyCheck(processor, document, sourceEdits); // Since source computation takes place in a recursive fashion (see // performSourceComputation) we only do something if we don't have a // computed source already. if (fSourceContent == null) { if (sourceEdits.size() <= result) { - List list= new ArrayList(); + List<TextEdit> list= new ArrayList<>(); list.add(this); for (int i= sourceEdits.size(); i < result; i++) sourceEdits.add(null); sourceEdits.add(list); } else { - List list= (List)sourceEdits.get(result); + List<TextEdit> list= sourceEdits.get(result); if (list == null) { - list= new ArrayList(); + list= new ArrayList<>(); sourceEdits.add(result, list); } list.add(this); diff --git a/org.eclipse.text/src/org/eclipse/text/edits/CopyTargetEdit.java b/org.eclipse.text/src/org/eclipse/text/edits/CopyTargetEdit.java index 1c6569e3bdb..4eed83d5416 100644 --- a/org.eclipse.text/src/org/eclipse/text/edits/CopyTargetEdit.java +++ b/org.eclipse.text/src/org/eclipse/text/edits/CopyTargetEdit.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2015 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 @@ -132,7 +132,7 @@ public final class CopyTargetEdit extends TextEdit { * @see TextEdit#traverseConsistencyCheck */ @Override - int traverseConsistencyCheck(TextEditProcessor processor, IDocument document, List sourceEdits) { + int traverseConsistencyCheck(TextEditProcessor processor, IDocument document, List<List<TextEdit>> sourceEdits) { return super.traverseConsistencyCheck(processor, document, sourceEdits) + 1; } diff --git a/org.eclipse.text/src/org/eclipse/text/edits/MoveSourceEdit.java b/org.eclipse.text/src/org/eclipse/text/edits/MoveSourceEdit.java index 25f56b4010e..f297f2c0fd7 100644 --- a/org.eclipse.text/src/org/eclipse/text/edits/MoveSourceEdit.java +++ b/org.eclipse.text/src/org/eclipse/text/edits/MoveSourceEdit.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2015 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 @@ -183,22 +183,22 @@ public final class MoveSourceEdit extends TextEdit { //---- consistency check ---------------------------------------------------------------- @Override - int traverseConsistencyCheck(TextEditProcessor processor, IDocument document, List sourceEdits) { + int traverseConsistencyCheck(TextEditProcessor processor, IDocument document, List<List<TextEdit>> sourceEdits) { int result= super.traverseConsistencyCheck(processor, document, sourceEdits); // Since source computation takes place in a recursive fashion (see // performSourceComputation) we only do something if we don't have a // computed source already. if (fSourceContent == null) { if (sourceEdits.size() <= result) { - List list= new ArrayList(); + List<TextEdit> list= new ArrayList<>(); list.add(this); for (int i= sourceEdits.size(); i < result; i++) sourceEdits.add(null); sourceEdits.add(list); } else { - List list= (List)sourceEdits.get(result); + List<TextEdit> list= sourceEdits.get(result); if (list == null) { - list= new ArrayList(); + list= new ArrayList<>(); sourceEdits.add(result, list); } list.add(this); @@ -292,9 +292,9 @@ public final class MoveSourceEdit extends TextEdit { private void applyTransformation(IDocument document, int style) throws MalformedTreeException { if ((style & TextEdit.UPDATE_REGIONS) != 0 && fSourceRoot != null) { - Map editMap= new HashMap(); + Map<TextEdit, TextEdit> editMap= new HashMap<>(); TextEdit newEdit= createEdit(editMap); - List replaces= new ArrayList(Arrays.asList(fModifier.getModifications(document.get()))); + List<ReplaceEdit> replaces= new ArrayList<>(Arrays.asList(fModifier.getModifications(document.get()))); insertEdits(newEdit, replaces); try { newEdit.apply(document, style); @@ -316,14 +316,14 @@ public final class MoveSourceEdit extends TextEdit { } } - private TextEdit createEdit(Map editMap) { + private TextEdit createEdit(Map<TextEdit, TextEdit> editMap) { MultiTextEdit result= new MultiTextEdit(0, fSourceRoot.getLength()); editMap.put(result, fSourceRoot); createEdit(fSourceRoot, result, editMap); return result; } - private static void createEdit(TextEdit source, TextEdit target, Map editMap) { + private static void createEdit(TextEdit source, TextEdit target, Map<TextEdit, TextEdit> editMap) { TextEdit[] children= source.getChildren(); for (int i= 0; i < children.length; i++) { TextEdit child= children[i]; @@ -338,13 +338,13 @@ public final class MoveSourceEdit extends TextEdit { } } - private void insertEdits(TextEdit root, List edits) { + private void insertEdits(TextEdit root, List<ReplaceEdit> edits) { while(edits.size() > 0) { - ReplaceEdit edit= (ReplaceEdit)edits.remove(0); + ReplaceEdit edit= edits.remove(0); insert(root, edit, edits); } } - private static void insert(TextEdit parent, ReplaceEdit edit, List edits) { + private static void insert(TextEdit parent, ReplaceEdit edit, List<ReplaceEdit> edits) { if (!parent.hasChildren()) { parent.addChild(edit); return; @@ -419,10 +419,10 @@ public final class MoveSourceEdit extends TextEdit { return result; } - private static void restorePositions(Map editMap) { - for (Iterator iter= editMap.keySet().iterator(); iter.hasNext();) { - TextEdit marker= (TextEdit)iter.next(); - TextEdit edit= (TextEdit)editMap.get(marker); + private static void restorePositions(Map<TextEdit, TextEdit> editMap) { + for (Iterator<TextEdit> iter= editMap.keySet().iterator(); iter.hasNext();) { + TextEdit marker= iter.next(); + TextEdit edit= editMap.get(marker); if (marker.isDeleted()) { edit.markAsDeleted(); } else { diff --git a/org.eclipse.text/src/org/eclipse/text/edits/MoveTargetEdit.java b/org.eclipse.text/src/org/eclipse/text/edits/MoveTargetEdit.java index 1815ca28545..3efb0064ad2 100644 --- a/org.eclipse.text/src/org/eclipse/text/edits/MoveTargetEdit.java +++ b/org.eclipse.text/src/org/eclipse/text/edits/MoveTargetEdit.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2015 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 @@ -133,7 +133,7 @@ public final class MoveTargetEdit extends TextEdit { * @see TextEdit#traverseConsistencyCheck */ @Override - int traverseConsistencyCheck(TextEditProcessor processor, IDocument document, List sourceEdits) { + int traverseConsistencyCheck(TextEditProcessor processor, IDocument document, List<List<TextEdit>> sourceEdits) { return super.traverseConsistencyCheck(processor, document, sourceEdits) + 1; } @@ -163,7 +163,7 @@ public final class MoveTargetEdit extends TextEdit { if (sourceRoot != null) { sourceRoot.internalMoveTree(getOffset()); TextEdit[] sourceChildren= sourceRoot.removeChildren(); - List children= new ArrayList(sourceChildren.length); + List<TextEdit> children= new ArrayList<>(sourceChildren.length); for (int i= 0; i < sourceChildren.length; i++) { TextEdit child= sourceChildren[i]; child.internalSetParent(this); diff --git a/org.eclipse.text/src/org/eclipse/text/edits/MultiTextEdit.java b/org.eclipse.text/src/org/eclipse/text/edits/MultiTextEdit.java index c1dcb81f555..9ace8e96880 100644 --- a/org.eclipse.text/src/org/eclipse/text/edits/MultiTextEdit.java +++ b/org.eclipse.text/src/org/eclipse/text/edits/MultiTextEdit.java @@ -98,11 +98,11 @@ public class MultiTextEdit extends TextEdit { if (fDefined) return super.getOffset(); - List/*<TextEdit>*/ children= internalGetChildren(); + List<TextEdit> children= internalGetChildren(); if (children == null || children.size() == 0) return 0; // the children are already sorted - return ((TextEdit)children.get(0)).getOffset(); + return children.get(0).getOffset(); } @Override @@ -110,12 +110,12 @@ public class MultiTextEdit extends TextEdit { if (fDefined) return super.getLength(); - List/*<TextEdit>*/ children= internalGetChildren(); + List<TextEdit> children= internalGetChildren(); if (children == null || children.size() == 0) return 0; // the children are already sorted - TextEdit first= (TextEdit)children.get(0); - TextEdit last= (TextEdit)children.get(children.size() - 1); + TextEdit first= children.get(0); + TextEdit last= children.get(children.size() - 1); return last.getOffset() - first.getOffset() + last.getLength(); } diff --git a/org.eclipse.text/src/org/eclipse/text/edits/TextEdit.java b/org.eclipse.text/src/org/eclipse/text/edits/TextEdit.java index b3aba990a9c..4806d620d8e 100644 --- a/org.eclipse.text/src/org/eclipse/text/edits/TextEdit.java +++ b/org.eclipse.text/src/org/eclipse/text/edits/TextEdit.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2015 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 @@ -98,12 +98,9 @@ public abstract class TextEdit { */ public static final int UPDATE_REGIONS= 1 << 1; - private static class InsertionComparator implements Comparator { + private static class InsertionComparator implements Comparator<TextEdit> { @Override - public int compare(Object o1, Object o2) throws MalformedTreeException { - TextEdit edit1= (TextEdit)o1; - TextEdit edit2= (TextEdit)o2; - + public int compare(TextEdit edit1, TextEdit edit2) throws MalformedTreeException { int offset1= edit1.getOffset(); int length1= edit1.getLength(); @@ -134,7 +131,7 @@ public abstract class TextEdit { private int fLength; private TextEdit fParent; - private List fChildren; + private List<TextEdit> fChildren; int fDelta; @@ -365,7 +362,7 @@ public abstract class TextEdit { public final TextEdit removeChild(int index) { if (fChildren == null) throw new IndexOutOfBoundsException("Index: " + index + " Size: 0"); //$NON-NLS-1$//$NON-NLS-2$ - TextEdit result= (TextEdit)fChildren.remove(index); + TextEdit result= fChildren.remove(index); result.internalSetParent(null); if (fChildren.isEmpty()) fChildren= null; @@ -405,7 +402,7 @@ public abstract class TextEdit { int size= fChildren.size(); TextEdit[] result= new TextEdit[size]; for (int i= 0; i < size; i++) { - result[i]= (TextEdit)fChildren.get(i); + result[i]= fChildren.get(i); result[i].internalSetParent(null); } fChildren= null; @@ -432,7 +429,7 @@ public abstract class TextEdit { public final TextEdit[] getChildren() { if (fChildren == null) return EMPTY_ARRAY; - return (TextEdit[])fChildren.toArray(new TextEdit[fChildren.size()]); + return fChildren.toArray(new TextEdit[fChildren.size()]); } /** @@ -566,8 +563,8 @@ public abstract class TextEdit { private void toStringWithChildren(StringBuffer buffer, int indent) { internalToString(buffer, indent); if (fChildren != null) { - for (Iterator iterator= fChildren.iterator(); iterator.hasNext();) { - TextEdit child= (TextEdit) iterator.next(); + for (Iterator<TextEdit> iterator= fChildren.iterator(); iterator.hasNext();) { + TextEdit child= iterator.next(); buffer.append('\n'); child.toStringWithChildren(buffer, indent + 1); } @@ -676,9 +673,9 @@ public abstract class TextEdit { protected final void acceptChildren(TextEditVisitor visitor) { if (fChildren == null) return; - Iterator iterator= fChildren.iterator(); + Iterator<TextEdit> iterator= fChildren.iterator(); while (iterator.hasNext()) { - TextEdit curr= (TextEdit) iterator.next(); + TextEdit curr= iterator.next(); curr.accept(visitor); } } @@ -762,11 +759,11 @@ public abstract class TextEdit { fLength= length; } - List internalGetChildren() { + List<TextEdit> internalGetChildren() { return fChildren; } - void internalSetChildren(List children) { + void internalSetChildren(List<TextEdit> children) { fChildren= children; } @@ -777,7 +774,7 @@ public abstract class TextEdit { if (!covers(child)) throw new MalformedTreeException(this, child, TextEditMessages.getString("TextEdit.range_outside")); //$NON-NLS-1$ if (fChildren == null) { - fChildren= new ArrayList(2); + fChildren= new ArrayList<>(2); } int index= computeInsertionIndex(child); fChildren.add(index, child); @@ -789,7 +786,7 @@ public abstract class TextEdit { if (size == 0) return 0; int lastIndex= size - 1; - TextEdit last= (TextEdit)fChildren.get(lastIndex); + TextEdit last= fChildren.get(lastIndex); if (last.getExclusiveEnd() <= edit.getOffset()) return size; try { @@ -862,11 +859,11 @@ public abstract class TextEdit { * * @return the number of indirect move or copy target edit children */ - int traverseConsistencyCheck(TextEditProcessor processor, IDocument document, List sourceEdits) { + int traverseConsistencyCheck(TextEditProcessor processor, IDocument document, List<List<TextEdit>> sourceEdits) { int result= 0; if (fChildren != null) { for (int i= fChildren.size() - 1; i >= 0; i--) { - TextEdit child= (TextEdit)fChildren.get(i); + TextEdit child= fChildren.get(i); result= Math.max(result, child.traverseConsistencyCheck(processor, document, sourceEdits)); } } @@ -907,7 +904,7 @@ public abstract class TextEdit { int delta= 0; if (fChildren != null) { for (int i= fChildren.size() - 1; i >= 0; i--) { - TextEdit child= (TextEdit)fChildren.get(i); + TextEdit child= fChildren.get(i); delta+= child.traverseDocumentUpdating(processor, document); childDocumentUpdated(); } @@ -942,8 +939,8 @@ public abstract class TextEdit { performRegionUpdating(accumulatedDelta, delete); if (fChildren != null) { boolean childDelete= delete || deleteChildren(); - for (Iterator iter= fChildren.iterator(); iter.hasNext();) { - TextEdit child= (TextEdit)iter.next(); + for (Iterator<TextEdit> iter= fChildren.iterator(); iter.hasNext();) { + TextEdit child= iter.next(); accumulatedDelta= child.traverseRegionUpdating(processor, document, accumulatedDelta, childDelete); childRegionUpdated(); } @@ -978,8 +975,8 @@ public abstract class TextEdit { void internalMoveTree(int delta) { adjustOffset(delta); if (fChildren != null) { - for (Iterator iter= fChildren.iterator(); iter.hasNext();) { - ((TextEdit)iter.next()).internalMoveTree(delta); + for (Iterator<TextEdit> iter= fChildren.iterator(); iter.hasNext();) { + iter.next().internalMoveTree(delta); } } } @@ -987,8 +984,8 @@ public abstract class TextEdit { void deleteTree() { markAsDeleted(); if (fChildren != null) { - for (Iterator iter= fChildren.iterator(); iter.hasNext();) { - TextEdit child= (TextEdit)iter.next(); + for (Iterator<TextEdit> iter= fChildren.iterator(); iter.hasNext();) { + TextEdit child= iter.next(); child.deleteTree(); } } diff --git a/org.eclipse.text/src/org/eclipse/text/edits/TextEditCopier.java b/org.eclipse.text/src/org/eclipse/text/edits/TextEditCopier.java index 002b7fe79ed..eea20c07749 100644 --- a/org.eclipse.text/src/org/eclipse/text/edits/TextEditCopier.java +++ b/org.eclipse.text/src/org/eclipse/text/edits/TextEditCopier.java @@ -29,7 +29,7 @@ import org.eclipse.core.runtime.Assert; public final class TextEditCopier { private TextEdit fEdit; - private Map fCopies; + private Map<TextEdit, TextEdit> fCopies; /** * Constructs a new <code>TextEditCopier</code> for the @@ -44,7 +44,7 @@ public final class TextEditCopier { super(); Assert.isNotNull(edit); fEdit= edit; - fCopies= new HashMap(); + fCopies= new HashMap<>(); } /** @@ -55,8 +55,8 @@ public final class TextEditCopier { public TextEdit perform() { TextEdit result= doCopy(fEdit); if (result != null) { - for (Iterator iter= fCopies.keySet().iterator(); iter.hasNext();) { - TextEdit edit= (TextEdit)iter.next(); + for (Iterator<TextEdit> iter= fCopies.keySet().iterator(); iter.hasNext();) { + TextEdit edit= iter.next(); edit.postProcessCopy(this); } } @@ -73,18 +73,18 @@ public final class TextEditCopier { */ public TextEdit getCopy(TextEdit original) { Assert.isNotNull(original); - return (TextEdit)fCopies.get(original); + return fCopies.get(original); } //---- helper methods -------------------------------------------- private TextEdit doCopy(TextEdit edit) { TextEdit result= edit.doCopy(); - List children= edit.internalGetChildren(); + List<TextEdit> children= edit.internalGetChildren(); if (children != null) { - List newChildren= new ArrayList(children.size()); - for (Iterator iter= children.iterator(); iter.hasNext();) { - TextEdit childCopy= doCopy((TextEdit)iter.next()); + List<TextEdit> newChildren= new ArrayList<>(children.size()); + for (Iterator<TextEdit> iter= children.iterator(); iter.hasNext();) { + TextEdit childCopy= doCopy(iter.next()); childCopy.internalSetParent(result); newChildren.add(childCopy); } diff --git a/org.eclipse.text/src/org/eclipse/text/edits/TextEditGroup.java b/org.eclipse.text/src/org/eclipse/text/edits/TextEditGroup.java index 4ad9cae9ca3..1442dbe00ae 100644 --- a/org.eclipse.text/src/org/eclipse/text/edits/TextEditGroup.java +++ b/org.eclipse.text/src/org/eclipse/text/edits/TextEditGroup.java @@ -34,7 +34,7 @@ import org.eclipse.jface.text.IRegion; public class TextEditGroup { private String fDescription; - private List fEdits; + private List<TextEdit> fEdits; /** * Creates a new text edit group with the given name. @@ -46,7 +46,7 @@ public class TextEditGroup { super(); Assert.isNotNull(name); fDescription= name; - fEdits= new ArrayList(3); + fEdits= new ArrayList<>(3); } /** @@ -61,7 +61,7 @@ public class TextEditGroup { Assert.isNotNull(name); Assert.isNotNull(edit); fDescription= name; - fEdits= new ArrayList(1); + fEdits= new ArrayList<>(1); fEdits.add(edit); } @@ -78,7 +78,7 @@ public class TextEditGroup { Assert.isNotNull(name); Assert.isNotNull(edits); fDescription= name; - fEdits= new ArrayList(Arrays.asList(edits)); + fEdits= new ArrayList<>(Arrays.asList(edits)); } /** @@ -140,7 +140,7 @@ public class TextEditGroup { * @return the managed text edits */ public TextEdit[] getTextEdits() { - return (TextEdit[]) fEdits.toArray(new TextEdit[fEdits.size()]); + return fEdits.toArray(new TextEdit[fEdits.size()]); } /** @@ -156,9 +156,9 @@ public class TextEditGroup { if (size == 0) { return null; } else if (size == 1) { - return ((TextEdit)fEdits.get(0)).getRegion(); + return fEdits.get(0).getRegion(); } else { - return TextEdit.getCoverage((TextEdit[])fEdits.toArray(new TextEdit[fEdits.size()])); + return TextEdit.getCoverage(fEdits.toArray(new TextEdit[fEdits.size()])); } } } diff --git a/org.eclipse.text/src/org/eclipse/text/edits/TextEditProcessor.java b/org.eclipse.text/src/org/eclipse/text/edits/TextEditProcessor.java index 77e29af6a44..73c7e6dd01f 100644 --- a/org.eclipse.text/src/org/eclipse/text/edits/TextEditProcessor.java +++ b/org.eclipse.text/src/org/eclipse/text/edits/TextEditProcessor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2015 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 @@ -40,7 +40,7 @@ public class TextEditProcessor { private boolean fChecked; private MalformedTreeException fException; - private List fSourceEdits; + private List<List<TextEdit>> fSourceEdits; /** * Constructs a new edit processor for the given @@ -69,7 +69,7 @@ public class TextEditProcessor { fStyle= style; if (secondary) { fChecked= true; - fSourceEdits= new ArrayList(); + fSourceEdits= new ArrayList<>(); } } @@ -172,7 +172,7 @@ public class TextEditProcessor { //---- checking -------------------------------------------------------------------- void checkIntegrityDo() throws MalformedTreeException { - fSourceEdits= new ArrayList(); + fSourceEdits= new ArrayList<>(); fRoot.traverseConsistencyCheck(this, fDocument, fSourceEdits); if (fRoot.getExclusiveEnd() > fDocument.getLength()) throw new MalformedTreeException(null, fRoot, TextEditMessages.getString("TextEditProcessor.invalid_length")); //$NON-NLS-1$ @@ -202,11 +202,11 @@ public class TextEditProcessor { } private void computeSources() { - for (Iterator iter= fSourceEdits.iterator(); iter.hasNext();) { - List list= (List)iter.next(); + for (Iterator<List<TextEdit>> iter= fSourceEdits.iterator(); iter.hasNext();) { + List<TextEdit> list= iter.next(); if (list != null) { - for (Iterator edits= list.iterator(); edits.hasNext();) { - TextEdit edit= (TextEdit)edits.next(); + for (Iterator<TextEdit> edits= list.iterator(); edits.hasNext();) { + TextEdit edit= edits.next(); edit.traverseSourceComputation(this, fDocument); } } diff --git a/org.eclipse.text/src/org/eclipse/text/edits/UndoEdit.java b/org.eclipse.text/src/org/eclipse/text/edits/UndoEdit.java index 57601327cab..663a9c4c328 100644 --- a/org.eclipse.text/src/org/eclipse/text/edits/UndoEdit.java +++ b/org.eclipse.text/src/org/eclipse/text/edits/UndoEdit.java @@ -85,9 +85,9 @@ public final class UndoEdit extends TextEdit { } void add(ReplaceEdit edit) { - List children= internalGetChildren(); + List<TextEdit> children= internalGetChildren(); if (children == null) { - children= new ArrayList(2); + children= new ArrayList<>(2); internalSetChildren(children); } children.add(edit); 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 7f15f60f664..4ead31215b1 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, 2009 IBM Corporation and others. + * Copyright (c) 2006, 2015 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 @@ -422,7 +422,7 @@ public class DocumentUndoManager implements IDocumentUndoManager { private static class UndoableCompoundTextChange extends UndoableTextChange { /** The list of individual changes */ - private List fChanges= new ArrayList(); + private List<UndoableTextChange> fChanges= new ArrayList<>(); /** * Creates a new compound text change. @@ -449,11 +449,11 @@ public class DocumentUndoManager implements IDocumentUndoManager { if (size > 0) { UndoableTextChange c; - c= (UndoableTextChange) fChanges.get(0); + c= fChanges.get(0); fDocumentUndoManager.fireDocumentUndo(c.fStart, c.fPreservedText, c.fText, uiInfo, DocumentUndoEvent.ABOUT_TO_UNDO, true); for (int i= size - 1; i >= 0; --i) { - c= (UndoableTextChange) fChanges.get(i); + c= fChanges.get(i); c.undoTextChange(); } fDocumentUndoManager.resetProcessChangeState(); @@ -470,11 +470,11 @@ public class DocumentUndoManager implements IDocumentUndoManager { if (size > 0) { UndoableTextChange c; - c= (UndoableTextChange) fChanges.get(size - 1); + c= fChanges.get(size - 1); fDocumentUndoManager.fireDocumentUndo(c.fStart, c.fText, c.fPreservedText, uiInfo, DocumentUndoEvent.ABOUT_TO_REDO, true); for (int i= 0; i <= size - 1; ++i) { - c= (UndoableTextChange) fChanges.get(i); + c= fChanges.get(i); c.redoTextChange(); } fDocumentUndoManager.resetProcessChangeState(); @@ -532,7 +532,7 @@ public class DocumentUndoManager implements IDocumentUndoManager { if (fStart > -1) return super.getUndoModificationStamp(); else if (fChanges.size() > 0) - return ((UndoableTextChange) fChanges.get(0)) + return fChanges.get(0) .getUndoModificationStamp(); return fUndoModificationStamp; @@ -543,7 +543,7 @@ public class DocumentUndoManager implements IDocumentUndoManager { if (fStart > -1) return super.getRedoModificationStamp(); else if (fChanges.size() > 0) - return ((UndoableTextChange) fChanges.get(fChanges.size() - 1)) + return fChanges.get(fChanges.size() - 1) .getRedoModificationStamp(); return fRedoModificationStamp; @@ -738,7 +738,7 @@ public class DocumentUndoManager implements IDocumentUndoManager { private ListenerList fDocumentUndoListeners; /** The list of clients connected. */ - private List fConnected; + private List<Object> fConnected; /** * @@ -752,7 +752,7 @@ public class DocumentUndoManager implements IDocumentUndoManager { fDocument= document; fHistory= OperationHistoryFactory.getOperationHistory(); fUndoContext= new ObjectUndoContext(fDocument); - fConnected= new ArrayList(); + fConnected= new ArrayList<>(); fDocumentUndoListeners= new ListenerList(ListenerList.IDENTITY); } diff --git a/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManagerRegistry.java b/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManagerRegistry.java index 5a1cf42cc36..5879f4d58b6 100644 --- a/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManagerRegistry.java +++ b/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManagerRegistry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2015 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 @@ -44,7 +44,7 @@ public final class DocumentUndoManagerRegistry { private IDocumentUndoManager undoManager; } - private static Map fgFactory= new HashMap(); + private static Map<IDocument, Record> fgFactory= new HashMap<>(); private DocumentUndoManagerRegistry() { // Do not instantiate @@ -62,7 +62,7 @@ public final class DocumentUndoManagerRegistry { */ public static synchronized void connect(IDocument document) { Assert.isNotNull(document); - Record record= (Record)fgFactory.get(document); + Record record= fgFactory.get(document); if (record == null) { record= new Record(document); fgFactory.put(document, record); @@ -77,7 +77,7 @@ public final class DocumentUndoManagerRegistry { */ public static synchronized void disconnect(IDocument document) { Assert.isNotNull(document); - Record record= (Record)fgFactory.get(document); + Record record= fgFactory.get(document); record.count--; if (record.count == 0) fgFactory.remove(document); @@ -99,7 +99,7 @@ public final class DocumentUndoManagerRegistry { */ public static synchronized IDocumentUndoManager getDocumentUndoManager(IDocument document) { Assert.isNotNull(document); - Record record= (Record)fgFactory.get(document); + Record record= fgFactory.get(document); if (record == null) return null; return record.undoManager; |