1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +02:00

Bug 567966 - CDT code clean up: type safety warnings

Generalize the type of elements and resolve type safety warnings

Change-Id: I5cb8d06a80207a7df8240f499936cdc49d49964c
Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
This commit is contained in:
Alexander Fedorov 2020-10-20 19:54:40 +03:00
parent 6ca0bb78bb
commit 87dff3db99
2 changed files with 35 additions and 34 deletions

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.debug.ui; singleton:=true
Bundle-Version: 8.4.0.qualifier
Bundle-Version: 8.4.100.qualifier
Bundle-Activator: org.eclipse.cdt.debug.ui.CDebugUIPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2018 IBM Corporation and others.
* Copyright (c) 2005, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@ -10,6 +10,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
* Alexander Fedorov (ArSysOp) - Bug 567966
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.dialogfields;
@ -45,15 +46,16 @@ import org.eclipse.swt.widgets.Table;
/**
* A list with a button bar.
* Typical buttons are 'Add', 'Remove', 'Up' and 'Down'.
* List model is independend of widget creation.
* List model is independent of widget creation.
* DialogFields controls are: Label, List and Composite containing buttons.
*/
public class ListDialogField extends DialogField {
//FIXME: Mostly duplicates org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField
public class ListDialogField<T> extends DialogField {
protected TableViewer fTable;
protected ILabelProvider fLabelProvider;
protected ListViewerAdapter fListViewerAdapter;
protected List fElements;
protected List<T> fElements;
protected ViewerComparator fViewerComparator;
protected String[] fButtonLabels;
@ -90,7 +92,7 @@ public class ListDialogField extends DialogField {
fListViewerAdapter = new ListViewerAdapter();
fParentElement = this;
fElements = new ArrayList(10);
fElements = new ArrayList<>(10);
fButtonLabels = buttonLabels;
if (fButtonLabels != null) {
@ -442,8 +444,8 @@ public class ListDialogField extends DialogField {
/**
* Sets the elements shown in the list.
*/
public void setElements(List elements) {
fElements = new ArrayList(elements);
public void setElements(List<? extends T> elements) {
fElements = new ArrayList<>(elements);
if (fTable != null) {
fTable.refresh();
}
@ -454,8 +456,8 @@ public class ListDialogField extends DialogField {
* Gets the elements shown in the list.
* The list returned is a copy, so it can be modified by the user.
*/
public List getElements() {
return new ArrayList(fElements);
public List<? extends Object> getElements() {
return new ArrayList<>(fElements);
}
/**
@ -468,7 +470,7 @@ public class ListDialogField extends DialogField {
/**
* Replace an element.
*/
public void replaceElement(Object oldElement, Object newElement) throws IllegalArgumentException {
public void replaceElement(T oldElement, T newElement) throws IllegalArgumentException {
int idx = fElements.indexOf(oldElement);
if (idx != -1) {
if (oldElement.equals(newElement) || fElements.contains(newElement)) {
@ -476,7 +478,7 @@ public class ListDialogField extends DialogField {
}
fElements.set(idx, newElement);
if (fTable != null) {
List selected = getSelectedElements();
List<T> selected = getSelectedElements();
if (selected.remove(oldElement)) {
selected.add(newElement);
}
@ -492,7 +494,7 @@ public class ListDialogField extends DialogField {
/**
* Adds an element at the end of the list.
*/
public void addElement(Object element) {
public void addElement(T element) {
if (fElements.contains(element)) {
return;
}
@ -506,15 +508,15 @@ public class ListDialogField extends DialogField {
/**
* Adds elements at the end of the list.
*/
public void addElements(List elements) {
public void addElements(List<? extends T> elements) {
int nElements = elements.size();
if (nElements > 0) {
// filter duplicated
ArrayList elementsToAdd = new ArrayList(nElements);
ArrayList<T> elementsToAdd = new ArrayList<>(nElements);
for (int i = 0; i < nElements; i++) {
Object elem = elements.get(i);
T elem = elements.get(i);
if (!fElements.contains(elem)) {
elementsToAdd.add(elem);
}
@ -530,7 +532,7 @@ public class ListDialogField extends DialogField {
/**
* Adds an element at a position.
*/
public void insertElementAt(Object element, int index) {
public void insertElementAt(T element, int index) {
if (fElements.contains(element)) {
return;
}
@ -572,7 +574,7 @@ public class ListDialogField extends DialogField {
/**
* Removes elements from the list.
*/
public void removeElements(List elements) {
public void removeElements(List<? extends Object> elements) {
if (elements.size() > 0) {
fElements.removeAll(elements);
if (fTable != null) {
@ -634,12 +636,12 @@ public class ListDialogField extends DialogField {
// ------- list maintenance
private List moveUp(List elements, List move) {
private List<T> moveUp(List<? extends T> elements, List<? extends T> move) {
int nElements = elements.size();
List res = new ArrayList(nElements);
Object floating = null;
List<T> res = new ArrayList<>(nElements);
T floating = null;
for (int i = 0; i < nElements; i++) {
Object curr = elements.get(i);
T curr = elements.get(i);
if (move.contains(curr)) {
res.add(curr);
} else {
@ -655,22 +657,22 @@ public class ListDialogField extends DialogField {
return res;
}
private void moveUp(List toMoveUp) {
private void moveUp(List<? extends T> toMoveUp) {
if (toMoveUp.size() > 0) {
setElements(moveUp(fElements, toMoveUp));
fTable.reveal(toMoveUp.get(0));
}
}
private void moveDown(List toMoveDown) {
private void moveDown(List<? extends T> toMoveDown) {
if (toMoveDown.size() > 0) {
setElements(reverse(moveUp(reverse(fElements), toMoveDown)));
fTable.reveal(toMoveDown.get(toMoveDown.size() - 1));
}
}
private List reverse(List p) {
List reverse = new ArrayList(p.size());
private List<T> reverse(List<? extends T> p) {
List<T> reverse = new ArrayList<>(p.size());
for (int i = p.size() - 1; i >= 0; i--) {
reverse.add(p.get(i));
}
@ -717,17 +719,16 @@ public class ListDialogField extends DialogField {
/**
* Returns the selected elements.
*/
public List getSelectedElements() {
List result = new ArrayList();
public List<T> getSelectedElements() {
List<T> result = new ArrayList<>();
if (fTable != null) {
ISelection selection = fTable.getSelection();
if (selection instanceof IStructuredSelection) {
Iterator iter = ((IStructuredSelection) selection).iterator();
IStructuredSelection selection = fTable.getStructuredSelection();
@SuppressWarnings("unchecked")
Iterator<T> iter = selection.iterator();
while (iter.hasNext()) {
result.add(iter.next());
}
}
}
return result;
}