1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-06 17:26:01 +02:00

cosmetics: generics

This commit is contained in:
Andrew Gvozdev 2010-01-28 21:20:52 +00:00
parent f766cfa76c
commit a62de2fbe6
10 changed files with 53 additions and 46 deletions

View file

@ -17,6 +17,8 @@ import org.eclipse.cdt.core.settings.model.ICSettingEntry;
* A storage where stored data is organized by "kind". * A storage where stored data is organized by "kind".
* In most cases kind is one of {@link ICLanguageSettingEntry}, i.e. include path, macro etc. * In most cases kind is one of {@link ICLanguageSettingEntry}, i.e. include path, macro etc.
* *
* @param <T> - stored type
*
* @see ICSettingEntry#INCLUDE_PATH * @see ICSettingEntry#INCLUDE_PATH
* @see ICSettingEntry#INCLUDE_FILE * @see ICSettingEntry#INCLUDE_FILE
* @see ICSettingEntry#MACRO * @see ICSettingEntry#MACRO
@ -27,7 +29,7 @@ import org.eclipse.cdt.core.settings.model.ICSettingEntry;
* @see ICSettingEntry#SOURCE_PATH * @see ICSettingEntry#SOURCE_PATH
* *
*/ */
public class KindBasedStore<TypeStored> implements Cloneable { public class KindBasedStore<T> implements Cloneable {
private static final int INDEX_INCLUDE_PATH = 0; private static final int INDEX_INCLUDE_PATH = 0;
private static final int INDEX_INCLUDE_FILE = 1; private static final int INDEX_INCLUDE_FILE = 1;
private static final int INDEX_MACRO = 2; private static final int INDEX_MACRO = 2;
@ -149,19 +151,19 @@ public class KindBasedStore<TypeStored> implements Cloneable {
throw new IllegalArgumentException(UtilMessages.getString("KindBasedStore.1")); //$NON-NLS-1$ throw new IllegalArgumentException(UtilMessages.getString("KindBasedStore.1")); //$NON-NLS-1$
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public TypeStored get(int kind){ public T get(int kind){
return (TypeStored) fEntryStorage[kindToIndex(kind)]; return (T) fEntryStorage[kindToIndex(kind)];
} }
@SuppressWarnings("unchecked") public T put(int kind, T object){
public TypeStored put(int kind, TypeStored object){
int index = kindToIndex(kind); int index = kindToIndex(kind);
TypeStored old = (TypeStored) fEntryStorage[index]; @SuppressWarnings("unchecked")
T old = (T) fEntryStorage[index];
fEntryStorage[index] = object; fEntryStorage[index] = object;
return old; return old;
} }
private class KindBasedInfo implements IKindBasedInfo { private class KindBasedInfo implements IKindBasedInfo<T> {
int fIdex; int fIdex;
int fKind; int fKind;
@ -175,31 +177,35 @@ public class KindBasedStore<TypeStored> implements Cloneable {
} }
} }
public Object getInfo() { public T getInfo() {
return fEntryStorage[fIdex]; @SuppressWarnings("unchecked")
T info = (T)fEntryStorage[fIdex];
return info;
} }
public int getKind() { public int getKind() {
return fKind; return fKind;
} }
public Object setInfo(Object newInfo) { public T setInfo(T newInfo) {
Object old = fEntryStorage[fIdex]; @SuppressWarnings("unchecked")
T old = (T)fEntryStorage[fIdex];
fEntryStorage[fIdex] = newInfo; fEntryStorage[fIdex] = newInfo;
return old; return old;
} }
} }
public IKindBasedInfo[] getContents(){ public IKindBasedInfo<T>[] getContents(){
IKindBasedInfo infos[] = new IKindBasedInfo[fEntryStorage.length]; @SuppressWarnings("unchecked")
IKindBasedInfo<T> infos[] = new IKindBasedInfo[fEntryStorage.length];
for(int i = 0; i < fEntryStorage.length; i++){ for(int i = 0; i < fEntryStorage.length; i++){
infos[i] = new KindBasedInfo(i, false); infos[i] = new KindBasedInfo(i, false);
} }
return infos; return infos;
} }
public IKindBasedInfo getInfo(int kind){ public IKindBasedInfo<T> getInfo(int kind){
return new KindBasedInfo(kind, true); return new KindBasedInfo(kind, true);
} }
@ -213,7 +219,7 @@ public class KindBasedStore<TypeStored> implements Cloneable {
public Object clone() { public Object clone() {
try { try {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
KindBasedStore<TypeStored> clone = (KindBasedStore<TypeStored>)super.clone(); KindBasedStore<T> clone = (KindBasedStore<T>)super.clone();
clone.fEntryStorage = fEntryStorage.clone(); clone.fEntryStorage = fEntryStorage.clone();
return clone; return clone;
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {

View file

@ -15,15 +15,15 @@ import java.util.List;
public class PathEntryResolveInfo { public class PathEntryResolveInfo {
private PathEntryResolveInfoElement[] fElements; private PathEntryResolveInfoElement[] fElements;
public PathEntryResolveInfo(List list){ public PathEntryResolveInfo(List<PathEntryResolveInfoElement> list){
if(list != null){ if(list != null){
fElements = (PathEntryResolveInfoElement[])list.toArray(new PathEntryResolveInfoElement[list.size()]); fElements = list.toArray(new PathEntryResolveInfoElement[list.size()]);
} else { } else {
fElements = new PathEntryResolveInfoElement[0]; fElements = new PathEntryResolveInfoElement[0];
} }
} }
public PathEntryResolveInfoElement[] getElements(){ public PathEntryResolveInfoElement[] getElements(){
return (PathEntryResolveInfoElement[])fElements.clone(); return fElements.clone();
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007 Intel Corporation and others. * Copyright (c) 2007, 2010 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -26,7 +26,7 @@ public class PathEntryResolveInfoElement {
fResolvedEntries = new IPathEntry[0]; fResolvedEntries = new IPathEntry[0];
} }
public PathEntryResolveInfoElement(IPathEntry rawEntry, List resolvedList){ public PathEntryResolveInfoElement(IPathEntry rawEntry, List<IPathEntry> resolvedList){
fRawEntry = rawEntry; fRawEntry = rawEntry;
if(resolvedList != null){ if(resolvedList != null){
fResolvedEntries = new IPathEntry[resolvedList.size()]; fResolvedEntries = new IPathEntry[resolvedList.size()];
@ -41,6 +41,6 @@ public class PathEntryResolveInfoElement {
public IPathEntry[] getResolvedEntries(){ public IPathEntry[] getResolvedEntries(){
if(fResolvedEntries == null) if(fResolvedEntries == null)
return new IPathEntry[0]; return new IPathEntry[0];
return (IPathEntry[])fResolvedEntries.clone(); return fResolvedEntries.clone();
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007 Intel Corporation and others. * Copyright (c) 2007, 2010 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -44,8 +44,8 @@ public class CExternalSettingSerializer {
if(tmp != null) if(tmp != null)
exts = CDataUtil.stringToArray(tmp, SEPARATOR); exts = CDataUtil.stringToArray(tmp, SEPARATOR);
List entriesList = LanguageSettingEntriesSerializer.loadEntriesList(element, KindBasedStore.ORED_LANG_ENTRY_KINDS); List<ICSettingEntry> entriesList = LanguageSettingEntriesSerializer.loadEntriesList(element, KindBasedStore.ORED_LANG_ENTRY_KINDS);
ICSettingEntry[] entries = (ICSettingEntry[])entriesList.toArray(new ICSettingEntry[entriesList.size()]); ICSettingEntry[] entries = entriesList.toArray(new ICSettingEntry[entriesList.size()]);
return new CExternalSetting(langIds, cTypeIds, exts, entries); return new CExternalSetting(langIds, cTypeIds, exts, entries);
} }

View file

@ -98,7 +98,7 @@ public class CProjectConverterDesciptor {
if(supportedIds != null){ if(supportedIds != null){
IProjectDescription eDes = project.getDescription(); IProjectDescription eDes = project.getDescription();
String natures[] = eDes.getNatureIds(); String natures[] = eDes.getNatureIds();
Set natureSet = new HashSet(Arrays.asList(natures)); Set<String> natureSet = new HashSet<String>(Arrays.asList(natures));
natureSet.removeAll(Arrays.asList(supportedIds)); natureSet.removeAll(Arrays.asList(supportedIds));
if(natureSet.size() == natures.length) if(natureSet.size() == natures.length)
return false; return false;

View file

@ -40,7 +40,7 @@ public class CfgProxyCache implements IProxyCache {
if(proxy != null) if(proxy != null)
fProxyMap.put(proxy.getId(),proxy); fProxyMap.put(proxy.getId(),proxy);
else if(oldValue != null){ else if(oldValue != null){
fProxyMap.remove((CDataProxy)oldValue); fProxyMap.remove(oldValue);
} }
} }
@ -82,6 +82,7 @@ public class CfgProxyCache implements IProxyCache {
removeCachedProxy(proxy); removeCachedProxy(proxy);
} }
@SuppressWarnings("unchecked")
public Map<String, CDataProxy> getCachedProxiesMap() { public Map<String, CDataProxy> getCachedProxiesMap() {
return (Map<String, CDataProxy>)fProxyMap.clone(); return (Map<String, CDataProxy>)fProxyMap.clone();
} }

View file

@ -21,12 +21,12 @@ public class ConfigBasedPathEntryContainer implements IPathEntryContainer {
public static final IPath CONTAINER_PATH = new Path("org.eclipse.cdt.core.CFG_BASED_CONTAINER"); //$NON-NLS-1$ public static final IPath CONTAINER_PATH = new Path("org.eclipse.cdt.core.CFG_BASED_CONTAINER"); //$NON-NLS-1$
private IPathEntry[] fEntries; private IPathEntry[] fEntries;
public ConfigBasedPathEntryContainer(List list){ public ConfigBasedPathEntryContainer(List<IPathEntry> list){
this.fEntries = (IPathEntry[])list.toArray(new IPathEntry[list.size()]); this.fEntries = list.toArray(new IPathEntry[list.size()]);
} }
public ConfigBasedPathEntryContainer(IPathEntry entries[]){ public ConfigBasedPathEntryContainer(IPathEntry entries[]){
this.fEntries = (IPathEntry[])entries.clone(); this.fEntries = entries.clone();
} }
public String getDescription() { public String getDescription() {
@ -38,7 +38,7 @@ public class ConfigBasedPathEntryContainer implements IPathEntryContainer {
} }
public IPathEntry[] getPathEntries() { public IPathEntry[] getPathEntries() {
return (IPathEntry[])fEntries.clone(); return fEntries.clone();
} }
} }

View file

@ -18,7 +18,7 @@ import org.eclipse.cdt.core.settings.model.util.KindBasedStore;
class EntriesNamesContainer { class EntriesNamesContainer {
// private String fLanguageSettingsId; // private String fLanguageSettingsId;
private KindBasedStore fRemovedEntryNamesStore = new KindBasedStore(); private KindBasedStore<Set<String>> fRemovedEntryNamesStore = new KindBasedStore<Set<String>>();
// EntriesNamesContainer(ICLanguageSetting setting) { // EntriesNamesContainer(ICLanguageSetting setting) {
// fLanguageSettingsId = setting.getId(); // fLanguageSettingsId = setting.getId();
@ -30,11 +30,11 @@ class EntriesNamesContainer {
public EntriesNamesContainer(EntriesNamesContainer base) { public EntriesNamesContainer(EntriesNamesContainer base) {
// fLanguageSettingsId = base.fLanguageSettingsId; // fLanguageSettingsId = base.fLanguageSettingsId;
IKindBasedInfo infos[] = base.fRemovedEntryNamesStore.getContents(); IKindBasedInfo<Set<String>> infos[] = base.fRemovedEntryNamesStore.getContents();
for(int i = 0; i < infos.length; i++){ for(int i = 0; i < infos.length; i++){
Set set = (Set)infos[i].getInfo(); Set<String> set = infos[i].getInfo();
if(set != null) if(set != null)
fRemovedEntryNamesStore.put(infos[i].getKind(), new HashSet(set)); fRemovedEntryNamesStore.put(infos[i].getKind(), new HashSet<String>(set));
} }
} }
@ -42,10 +42,10 @@ class EntriesNamesContainer {
// return fLanguageSettingsId; // return fLanguageSettingsId;
//o } //o }
private Set getRemovedNamesSet(int kind, boolean create){ private Set<String> getRemovedNamesSet(int kind, boolean create){
Set set = (Set)fRemovedEntryNamesStore.get(kind); Set<String> set = fRemovedEntryNamesStore.get(kind);
if(set == null && create){ if(set == null && create){
set = new HashSet(); set = new HashSet<String>();
fRemovedEntryNamesStore.put(kind, set); fRemovedEntryNamesStore.put(kind, set);
} }
return set; return set;
@ -60,7 +60,7 @@ class EntriesNamesContainer {
} }
public boolean contains(int kind, String name){ public boolean contains(int kind, String name){
Set set = getRemovedNamesSet(kind, false); Set<String> set = getRemovedNamesSet(kind, false);
if(set != null) if(set != null)
return set.contains(name); return set.contains(name);
return false; return false;
@ -71,7 +71,7 @@ class EntriesNamesContainer {
} }
public boolean remove(int kind, String name){ public boolean remove(int kind, String name){
Set set = getRemovedNamesSet(kind, false); Set<String> set = getRemovedNamesSet(kind, false);
if(set != null) if(set != null)
return set.remove(name); return set.remove(name);
return false; return false;
@ -81,13 +81,13 @@ class EntriesNamesContainer {
if(names == null || names.length == 0) { if(names == null || names.length == 0) {
clear(kind); clear(kind);
} else { } else {
Set set = getRemovedNamesSet(kind, true); Set<String> set = getRemovedNamesSet(kind, true);
set.clear(); set.clear();
add(set, names); add(set, names);
} }
} }
private static void add(Set set, String names[]){ private static void add(Set<String> set, String names[]){
for(int i = 0; i < names.length; i++){ for(int i = 0; i < names.length; i++){
set.add(names[i]); set.add(names[i]);
} }
@ -97,7 +97,7 @@ class EntriesNamesContainer {
if(names == null || names.length == 0) { if(names == null || names.length == 0) {
return; return;
} else { } else {
Set set = getRemovedNamesSet(kind, true); Set<String> set = getRemovedNamesSet(kind, true);
add(set, names); add(set, names);
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007 Intel Corporation and others. * Copyright (c) 2007, 2010 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -17,7 +17,7 @@ import org.eclipse.cdt.core.settings.model.extension.CDataObject;
public interface IProxyCache { public interface IProxyCache {
CDataProxy[] getCachedProxies(); CDataProxy[] getCachedProxies();
Map getCachedProxiesMap(); Map<String, CDataProxy> getCachedProxiesMap();
CDataProxy getCachedProxy(String id); CDataProxy getCachedProxy(String id);

View file

@ -255,7 +255,7 @@ public class PathEntryConfigurationDataProvider extends
ICProject cproject = manager.create(project); ICProject cproject = manager.create(project);
IPathEntry[] curRawEntries = PathEntryManager.getDefault().getRawPathEntries(cproject); IPathEntry[] curRawEntries = PathEntryManager.getDefault().getRawPathEntries(cproject);
List list = new ArrayList(); List<IPathEntry> list = new ArrayList<IPathEntry>();
list.addAll(Arrays.asList(entries)); list.addAll(Arrays.asList(entries));
for(int i = 0; i < curRawEntries.length; i++){ for(int i = 0; i < curRawEntries.length; i++){
if(curRawEntries[i].getEntryKind() == IPathEntry.CDT_CONTAINER){ if(curRawEntries[i].getEntryKind() == IPathEntry.CDT_CONTAINER){
@ -263,7 +263,7 @@ public class PathEntryConfigurationDataProvider extends
} }
} }
IPathEntry[] newEntries = (IPathEntry[])list.toArray(new IPathEntry[list.size()]); IPathEntry[] newEntries = list.toArray(new IPathEntry[list.size()]);
PathEntryManager.getDefault().setRawPathEntries(cproject, newEntries, new NullProgressMonitor()); PathEntryManager.getDefault().setRawPathEntries(cproject, newEntries, new NullProgressMonitor());
return createData(des, base, false, false); return createData(des, base, false, false);
} }