1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-13 03:05:39 +02:00

Generics.

This commit is contained in:
Sergey Prigogin 2010-12-02 20:42:38 +00:00
parent 9792e732c4
commit f3b4634427
2 changed files with 226 additions and 242 deletions

View file

@ -18,7 +18,6 @@ import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetDecoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator;
import java.util.List; import java.util.List;
import javax.xml.transform.OutputKeys; import javax.xml.transform.OutputKeys;
@ -68,8 +67,7 @@ public class CDebugUtils {
if (handler != null) { if (handler != null) {
try { try {
result = (Boolean)handler.handleStatus(status, source); result = (Boolean)handler.handleStatus(status, source);
} } catch (CoreException e) {
catch( CoreException e ) {
} }
} }
return result.booleanValue(); return result.booleanValue();
@ -80,8 +78,7 @@ public class CDebugUtils {
if (handler != null) { if (handler != null) {
try { try {
handler.handleStatus(status, source); handler.handleStatus(status, source);
} } catch (CoreException e) {
catch( CoreException e ) {
} }
} }
} }
@ -91,8 +88,7 @@ public class CDebugUtils {
if (handler != null) { if (handler != null) {
try { try {
handler.handleStatus(status, source); handler.handleStatus(status, source);
} } catch (CoreException e) {
catch( CoreException e ) {
} }
} }
} }
@ -134,8 +130,7 @@ public class CDebugUtils {
public static char bytesToChar(byte[] bytes) { public static char bytesToChar(byte[] bytes) {
try { try {
return (char)Short.parseShort(new String(bytes), 16); return (char)Short.parseShort(new String(bytes), 16);
} } catch (RuntimeException e) {
catch( RuntimeException e ) {
} }
return 0; return 0;
} }
@ -183,8 +178,7 @@ public class CDebugUtils {
copy[2 * i] = bytes[bytes.length - 2 * i - 2]; copy[2 * i] = bytes[bytes.length - 2 * i - 2];
copy[2 * i + 1] = bytes[bytes.length - 2 * i - 1]; copy[2 * i + 1] = bytes[bytes.length - 2 * i - 1];
} }
} } else {
else {
System.arraycopy(bytes, 0, copy, 0, copy.length); System.arraycopy(bytes, 0, copy, 0, copy.length);
} }
return new String(copy); return new String(copy);
@ -194,8 +188,7 @@ public class CDebugUtils {
StringBuffer sb = new StringBuffer(length); StringBuffer sb = new StringBuffer(length);
if (text.length() > length) { if (text.length() > length) {
sb.append(text.substring(0, length)); sb.append(text.substring(0, length));
} } else {
else {
char[] prefix = new char[length - text.length()]; char[] prefix = new char[length - text.length()];
Arrays.fill(prefix, ch); Arrays.fill(prefix, ch);
sb.append(prefix); sb.append(prefix);
@ -206,11 +199,9 @@ public class CDebugUtils {
public static boolean isReferencedProject(IProject parent, IProject project) { public static boolean isReferencedProject(IProject parent, IProject project) {
if (parent != null && parent.exists()) { if (parent != null && parent.exists()) {
List projects = CDebugUtils.getReferencedProjects( project ); List<IProject> projects = CDebugUtils.getReferencedProjects(project);
Iterator it = projects.iterator(); for (IProject proj : projects) {
while( it.hasNext() ) { if (proj.exists() && (proj.equals(project)))
IProject prj = (IProject)it.next();
if ( prj.exists() && (prj.equals( project )) )
return true; return true;
} }
} }
@ -251,8 +242,7 @@ public class CDebugUtils {
if (value instanceof CFloatingPointValue) { if (value instanceof CFloatingPointValue) {
try { try {
return ((CFloatingPointValue)value).getFloatingPointValue(); return ((CFloatingPointValue)value).getFloatingPointValue();
} } catch (CDIException e) {
catch( CDIException e ) {
} }
} }
return null; return null;
@ -288,14 +278,13 @@ public class CDebugUtils {
return false; return false;
} }
public static List getReferencedProjects( IProject project ) { public static List<IProject> getReferencedProjects(IProject project) {
ArrayList list = new ArrayList( 10 ); ArrayList<IProject> list = new ArrayList<IProject>(10);
if (project != null && project.exists() && project.isOpen()) { if (project != null && project.exists() && project.isOpen()) {
IProject[] refs = new IProject[0]; IProject[] refs = new IProject[0];
try { try {
refs = project.getReferencedProjects(); refs = project.getReferencedProjects();
} } catch (CoreException e) {
catch( CoreException e ) {
} }
for (int i = 0; i < refs.length; ++i) { for (int i = 0; i < refs.length; ++i) {
if (!project.equals(refs[i]) && refs[i] != null && refs[i].exists() && refs[i].isOpen()) { if (!project.equals(refs[i]) && refs[i] != null && refs[i].exists() && refs[i].isOpen()) {
@ -307,13 +296,12 @@ public class CDebugUtils {
return list; return list;
} }
private static void getReferencedProjects( IProject root, IProject project, List list ) { private static void getReferencedProjects(IProject root, IProject project, List<IProject> list) {
if (project != null && project.exists() && project.isOpen()) { if (project != null && project.exists() && project.isOpen()) {
IProject[] refs = new IProject[0]; IProject[] refs = new IProject[0];
try { try {
refs = project.getReferencedProjects(); refs = project.getReferencedProjects();
} } catch (CoreException e) {
catch( CoreException e ) {
} }
for (int i = 0; i < refs.length; ++i) { for (int i = 0; i < refs.length; ++i) {
if (!list.contains(refs[i]) && refs[i] != null && !refs[i].equals(root) && refs[i].exists() && refs[i].isOpen()) { if (!list.contains(refs[i]) && refs[i] != null && !refs[i].equals(root) && refs[i].exists() && refs[i].isOpen()) {
@ -339,7 +327,8 @@ public class CDebugUtils {
} }
// this allow to create new breakpoint without implemention one the interfaces above and still see a label // this allow to create new breakpoint without implemention one the interfaces above and still see a label
Object message = breakpoint.getMarker().getAttribute(IMarker.MESSAGE); Object message = breakpoint.getMarker().getAttribute(IMarker.MESSAGE);
if (message!=null) return message.toString(); if (message != null)
return message.toString();
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
@ -411,8 +400,7 @@ public class CDebugUtils {
try { try {
label.append(' '); label.append(' ');
label.append(MessageFormat.format(DebugCoreMessages.getString("CDebugUtils.1"), new String[]{ breakpoint.getAddress() })); //$NON-NLS-1$ label.append(MessageFormat.format(DebugCoreMessages.getString("CDebugUtils.1"), new String[]{ breakpoint.getAddress() })); //$NON-NLS-1$
} } catch (NumberFormatException e) {
catch( NumberFormatException e ) {
} }
return label; return label;
} }
@ -500,7 +488,6 @@ public class CDebugUtils {
} }
} }
return label; return label;
} }
private static boolean isEmpty(String string) { private static boolean isEmpty(String string) {
@ -511,8 +498,7 @@ public class CDebugUtils {
public static CharsetDecoder getCharsetDecoder() { public static CharsetDecoder getCharsetDecoder() {
String charsetName = CDebugCorePlugin.getDefault().getPluginPreferences().getString(ICDebugConstants.PREF_CHARSET); String charsetName = CDebugCorePlugin.getDefault().getPluginPreferences().getString(ICDebugConstants.PREF_CHARSET);
if (fDecoder == null || !fDecoder.charset().name().equals(charsetName)) if (fDecoder == null || !fDecoder.charset().name().equals(charsetName)) {
{
Charset charset = Charset.forName(charsetName); Charset charset = Charset.forName(charsetName);
fDecoder = charset.newDecoder(); fDecoder = charset.newDecoder();
} }
@ -647,8 +633,7 @@ public class CDebugUtils {
IFile projFile = null; IFile projFile = null;
try { try {
projFile = cproject.getProject().getFile(CDebugUtils.getProgramPath(config)); projFile = cproject.getProject().getFile(CDebugUtils.getProgramPath(config));
} } catch (IllegalArgumentException exc) {
catch (IllegalArgumentException exc) {
// thrown if relative path that resolves to a root file (e.g., "..\somefile") // thrown if relative path that resolves to a root file (e.g., "..\somefile")
} }
if (projFile != null && projFile.exists()) { if (projFile != null && projFile.exists()) {

View file

@ -13,7 +13,6 @@ package org.eclipse.cdt.debug.ui.sourcelookup;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import org.eclipse.cdt.debug.core.CDebugUtils; import org.eclipse.cdt.debug.core.CDebugUtils;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
@ -41,8 +40,7 @@ public class DefaultSourceLocator extends CSourceLookupDirector {
Element rootElement = DebugPlugin.parseDocument(memento); Element rootElement = DebugPlugin.parseDocument(memento);
if (rootElement.getNodeName().equalsIgnoreCase(OldDefaultSourceLocator.ELEMENT_NAME)) { if (rootElement.getNodeName().equalsIgnoreCase(OldDefaultSourceLocator.ELEMENT_NAME)) {
initializeFromOldMemento(memento, configuration); initializeFromOldMemento(memento, configuration);
} } else {
else {
super.initializeFromMemento(memento, configuration); super.initializeFromMemento(memento, configuration);
} }
} }
@ -59,12 +57,11 @@ public class DefaultSourceLocator extends CSourceLookupDirector {
// Check if the old source locator includes all referenced projects. // Check if the old source locator includes all referenced projects.
// If so, DefaultSpourceContainer should be used. // If so, DefaultSpourceContainer should be used.
IProject project = csl.getProject(); IProject project = csl.getProject();
List list = CDebugUtils.getReferencedProjects( project ); List<IProject> list = CDebugUtils.getReferencedProjects(project);
HashSet names = new HashSet( list.size() + 1 ); HashSet<String> names = new HashSet<String>(list.size() + 1);
names.add(project.getName()); names.add(project.getName());
Iterator it = list.iterator(); for (IProject proj : list) {
while( it.hasNext() ) { names.add(proj.getName());
names.add( ((IProject)it.next()).getName() );
} }
boolean includesDefault = true; boolean includesDefault = true;
for (int i = 0; i < locations.length; ++i) { for (int i = 0; i < locations.length; ++i) {
@ -77,20 +74,22 @@ public class DefaultSourceLocator extends CSourceLookupDirector {
} }
// Generate an array of new source containers including DefaultSourceContainer // Generate an array of new source containers including DefaultSourceContainer
ArrayList locs = new ArrayList( locations.length ); ArrayList<ICSourceLocation> locs = new ArrayList<ICSourceLocation>(locations.length);
for (int i = 0; i < locations.length; ++i) { for (int i = 0; i < locations.length; ++i) {
if ( !includesDefault || !( locations[i] instanceof IProjectSourceLocation && names.contains( ((IProjectSourceLocation)locations[i]).getProject().getName() ) ) ) if (!includesDefault || !(locations[i] instanceof IProjectSourceLocation &&
names.contains(((IProjectSourceLocation)locations[i]).getProject().getName()))) {
locs.add(locations[i]); locs.add(locations[i]);
} }
}
ISourceContainer[] containers = SourceUtils.convertSourceLocations( (ICSourceLocation[])locs.toArray( new ICSourceLocation[locs.size()] ) ); ISourceContainer[] containers = SourceUtils.convertSourceLocations(locs.toArray(new ICSourceLocation[locs.size()]));
ArrayList cons = new ArrayList( Arrays.asList( containers ) ); ArrayList<ISourceContainer> cons = new ArrayList<ISourceContainer>(Arrays.asList(containers));
if (includesDefault) { if (includesDefault) {
DefaultSourceContainer defaultContainer = new DefaultSourceContainer(); DefaultSourceContainer defaultContainer = new DefaultSourceContainer();
defaultContainer.init(this); defaultContainer.init(this);
cons.add(0, defaultContainer); cons.add(0, defaultContainer);
} }
setSourceContainers( (ISourceContainer[])cons.toArray( new ISourceContainer[cons.size()] ) ); setSourceContainers(cons.toArray(new ISourceContainer[cons.size()]));
initializeParticipants(); initializeParticipants();
} }
} }