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

Generification and other code cleanup.

Change-Id: Ifb35a80ec8cf563c5635078db947768d1a7aa6ff
This commit is contained in:
Sergey Prigogin 2016-10-06 16:24:34 -07:00
parent c8d528587e
commit 33f0522906
8 changed files with 48 additions and 62 deletions

View file

@ -12,14 +12,13 @@ package org.eclipse.cdt.managedbuilder.ui.tests;
import java.util.List; import java.util.List;
import junit.framework.TestCase;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.managedbuilder.core.IProjectType; import org.eclipse.cdt.managedbuilder.core.IProjectType;
import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPageManager; import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPageManager;
import org.eclipse.cdt.ui.wizards.CDTMainWizardPage; import org.eclipse.cdt.ui.wizards.CDTMainWizardPage;
import org.eclipse.cdt.ui.wizards.CDTProjectWizard; import org.eclipse.cdt.ui.wizards.CDTProjectWizard;
import org.eclipse.cdt.ui.wizards.CWizardHandler; import org.eclipse.cdt.ui.wizards.CWizardHandler;
import org.eclipse.cdt.ui.wizards.EntryDescriptor;
import org.eclipse.cdt.ui.wizards.IWizardItemsListListener; import org.eclipse.cdt.ui.wizards.IWizardItemsListListener;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.wizard.WizardPage; import org.eclipse.jface.wizard.WizardPage;
@ -27,12 +26,13 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI; import org.eclipse.ui.PlatformUI;
import junit.framework.TestCase;
/** /**
* Tests for the get/setSelectedProjectType() of CProjectPlatformPage. * Tests for the get/setSelectedProjectType() of CProjectPlatformPage.
* @author Elias Volanakis * @author Elias Volanakis
*/ */
public class TestCProjectPlatformPage extends TestCase implements IWizardItemsListListener { public class TestCProjectPlatformPage extends TestCase implements IWizardItemsListListener {
//TODO: migrate to the new UI functionality //TODO: migrate to the new UI functionality
private CDTProjectWizard wizard; private CDTProjectWizard wizard;
private TestPage page; private TestPage page;
@ -141,7 +141,7 @@ public class TestCProjectPlatformPage extends TestCase implements IWizardItemsLi
} }
@Override @Override
public List filterItems(List items) { public List<EntryDescriptor> filterItems(List<EntryDescriptor> items) {
return items; return items;
} }
} }
@ -149,11 +149,12 @@ public class TestCProjectPlatformPage extends TestCase implements IWizardItemsLi
// methods of IToolChainListListener // methods of IToolChainListListener
@Override @Override
public boolean isCurrent() { return currentState; } public boolean isCurrent() { return currentState; }
@Override @Override
public void toolChainListChanged(int count) {} public void toolChainListChanged(int count) {}
@Override @Override
public List filterItems(List items) { public List<EntryDescriptor> filterItems(List<EntryDescriptor> items) {
return items; return items;
} }
} }

View file

@ -15,14 +15,14 @@ package org.eclipse.cdt.managedbuilder.ui.tests;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.cdt.managedbuilder.ui.tests.util.TestToolchain; import org.eclipse.cdt.managedbuilder.ui.tests.util.TestToolchain;
import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPageManager; import org.eclipse.cdt.managedbuilder.ui.wizards.MBSCustomPageManager;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/** /**
* This class is responsible for testing the functionality of the custom page manager (MBSCustomPageManager) * This class is responsible for testing the functionality of the custom page manager (MBSCustomPageManager)
* that manages custom wizard pages that are provided by ISVs to supplement the pages in the New Project wizards * that manages custom wizard pages that are provided by ISVs to supplement the pages in the New Project wizards
@ -36,9 +36,7 @@ import org.eclipse.core.runtime.NullProgressMonitor;
* change around what options (i.e. nature, project type, toolchain) a hypothetical user would set, and then * change around what options (i.e. nature, project type, toolchain) a hypothetical user would set, and then
* check to see if the proper pages are displayed in the proper order. * check to see if the proper pages are displayed in the proper order.
*/ */
public class TestCustomPageManager extends TestCase public class TestCustomPageManager extends TestCase {
{
private static final String alwaysPresentPageName = "org.eclipse.cdt.managedbuilder.ui.tests.wizardPages.AlwaysPresentWizardPage"; private static final String alwaysPresentPageName = "org.eclipse.cdt.managedbuilder.ui.tests.wizardPages.AlwaysPresentWizardPage";
private static final String natureAPageName = "org.eclipse.cdt.managedbuilder.ui.tests.wizardPages.NatureAWizardPage"; private static final String natureAPageName = "org.eclipse.cdt.managedbuilder.ui.tests.wizardPages.NatureAWizardPage";
private static final String natureBPageName = "org.eclipse.cdt.managedbuilder.ui.tests.wizardPages.NatureBWizardPage"; private static final String natureBPageName = "org.eclipse.cdt.managedbuilder.ui.tests.wizardPages.NatureBWizardPage";
@ -70,7 +68,7 @@ public class TestCustomPageManager extends TestCase
MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PROJECT_TYPE, "X"); MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PROJECT_TYPE, "X");
// set the toolchain to "Y" // set the toolchain to "Y"
List toolchainSet = new ArrayList(); List<TestToolchain> toolchainSet = new ArrayList<TestToolchain>();
TestToolchain toolchain = new TestToolchain(); TestToolchain toolchain = new TestToolchain();
toolchain.setID("Y"); toolchain.setID("Y");
toolchainSet.add(toolchain); toolchainSet.add(toolchain);
@ -146,7 +144,7 @@ public class TestCustomPageManager extends TestCase
MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PROJECT_TYPE, "X"); MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PROJECT_TYPE, "X");
// set the toolchain to "Y" // set the toolchain to "Y"
List toolchainSet = new ArrayList(); List<TestToolchain> toolchainSet = new ArrayList<TestToolchain>();
TestToolchain toolchain = new TestToolchain(); TestToolchain toolchain = new TestToolchain();
toolchain.setID("Y"); toolchain.setID("Y");
toolchainSet.add(toolchain); toolchainSet.add(toolchain);
@ -233,7 +231,7 @@ public class TestCustomPageManager extends TestCase
MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PROJECT_TYPE, "X"); MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PROJECT_TYPE, "X");
// set the toolchain to "Y" // set the toolchain to "Y"
List toolchainSet = new ArrayList(); List<TestToolchain> toolchainSet = new ArrayList<TestToolchain>();
TestToolchain toolchain = new TestToolchain(); TestToolchain toolchain = new TestToolchain();
toolchain.setID("Y"); toolchain.setID("Y");
toolchainSet.add(toolchain); toolchainSet.add(toolchain);
@ -320,7 +318,7 @@ public class TestCustomPageManager extends TestCase
MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PROJECT_TYPE, "X"); MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PROJECT_TYPE, "X");
// set the toolchain to "C" // set the toolchain to "C"
List toolchainSet = new ArrayList(); List<TestToolchain> toolchainSet = new ArrayList<TestToolchain>();
TestToolchain toolchain = new TestToolchain(); TestToolchain toolchain = new TestToolchain();
toolchain.setID("C"); toolchain.setID("C");
toolchainSet.add(toolchain); toolchainSet.add(toolchain);
@ -408,7 +406,7 @@ public class TestCustomPageManager extends TestCase
MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PROJECT_TYPE, "X"); MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PROJECT_TYPE, "X");
// set the toolchain to "C" // set the toolchain to "C"
List toolchainSet = new ArrayList(); List<TestToolchain> toolchainSet = new ArrayList<TestToolchain>();
TestToolchain toolchain = new TestToolchain(); TestToolchain toolchain = new TestToolchain();
toolchain.setID("C_2.0.0"); toolchain.setID("C_2.0.0");
toolchainSet.add(toolchain); toolchainSet.add(toolchain);
@ -510,7 +508,7 @@ public class TestCustomPageManager extends TestCase
MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PROJECT_TYPE, "D"); MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PROJECT_TYPE, "D");
// set the toolchain to "Y" // set the toolchain to "Y"
List toolchainSet = new ArrayList(); List<TestToolchain> toolchainSet = new ArrayList<TestToolchain>();
TestToolchain toolchain = new TestToolchain(); TestToolchain toolchain = new TestToolchain();
toolchain.setID("Y"); toolchain.setID("Y");
toolchainSet.add(toolchain); toolchainSet.add(toolchain);
@ -600,7 +598,7 @@ public class TestCustomPageManager extends TestCase
MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PROJECT_TYPE, "E"); MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PROJECT_TYPE, "E");
// set the toolchain to "Y" // set the toolchain to "Y"
List toolchainSet = new ArrayList(); List<TestToolchain> toolchainSet = new ArrayList<TestToolchain>();
TestToolchain toolchain = new TestToolchain(); TestToolchain toolchain = new TestToolchain();
toolchain.setID("Y"); toolchain.setID("Y");
toolchainSet.add(toolchain); toolchainSet.add(toolchain);
@ -682,13 +680,12 @@ public class TestCustomPageManager extends TestCase
/** /**
* Set the toolchain to "F". Only pages with no contraints or toolchains set to "F" should show up. * Set the toolchain to "F". Only pages with no contraints or toolchains set to "F" should show up.
*/ */
public void testToolchainF() public void testToolchainF() {
{
// set the project type to be "X" // set the project type to be "X"
MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PROJECT_TYPE, "X"); MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PROJECT_TYPE, "X");
// set the toolchain to "F" // set the toolchain to "F"
List toolchainSet = new ArrayList(); List<TestToolchain> toolchainSet = new ArrayList<TestToolchain>();
TestToolchain toolchain = new TestToolchain(); TestToolchain toolchain = new TestToolchain();
toolchain.setID("F"); toolchain.setID("F");
toolchainSet.add(toolchain); toolchainSet.add(toolchain);
@ -776,7 +773,7 @@ public class TestCustomPageManager extends TestCase
MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PROJECT_TYPE, "D"); MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PROJECT_TYPE, "D");
// set the toolchain to "C" // set the toolchain to "C"
List toolchainSet = new ArrayList(); List<TestToolchain> toolchainSet = new ArrayList<TestToolchain>();
TestToolchain toolchain = new TestToolchain(); TestToolchain toolchain = new TestToolchain();
toolchain.setID("C"); toolchain.setID("C");
toolchainSet.add(toolchain); toolchainSet.add(toolchain);

View file

@ -51,7 +51,6 @@ import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
* @noinstantiate This class is not intended to be instantiated by clients. * @noinstantiate This class is not intended to be instantiated by clients.
*/ */
public class ConvertToMakeWizardPage extends ConvertProjectWizardPage { public class ConvertToMakeWizardPage extends ConvertProjectWizardPage {
private static final String WZ_TITLE = "WizardMakeProjectConversion.title"; //$NON-NLS-1$ private static final String WZ_TITLE = "WizardMakeProjectConversion.title"; //$NON-NLS-1$
private static final String WZ_DESC = "WizardMakeProjectConversion.description"; //$NON-NLS-1$ private static final String WZ_DESC = "WizardMakeProjectConversion.description"; //$NON-NLS-1$
@ -147,12 +146,10 @@ public class ConvertToMakeWizardPage extends ConvertProjectWizardPage {
gd.horizontalSpan = 2; gd.horizontalSpan = 2;
show_sup.setLayoutData(gd); show_sup.setLayoutData(gd);
final IWizardItemsListListener filter = new IWizardItemsListListener() { final IWizardItemsListListener filter = new IWizardItemsListListener() {
// Show only category // Show only category
@Override @Override
public List<EntryDescriptor> filterItems( public List<EntryDescriptor> filterItems(List<EntryDescriptor> items) {
List<? extends EntryDescriptor> items) { List<EntryDescriptor> results = new ArrayList<>();
List<EntryDescriptor> results = new ArrayList<EntryDescriptor>();
for (EntryDescriptor entry : items) { for (EntryDescriptor entry : items) {
if (entry.isCategory()) { if (entry.isCategory()) {

View file

@ -183,7 +183,7 @@ public class CoreModel {
public boolean isObject(IFile file) { public boolean isObject(IFile file) {
ICElement celement = create(file); ICElement celement = create(file);
if (celement instanceof IBinary) { if (celement instanceof IBinary) {
return ((IBinary)celement).isObject(); return ((IBinary) celement).isObject();
} }
return false; return false;
} }
@ -194,7 +194,7 @@ public class CoreModel {
public boolean isExecutable(IFile file) { public boolean isExecutable(IFile file) {
ICElement celement = create(file); ICElement celement = create(file);
if (celement instanceof IBinary) { if (celement instanceof IBinary) {
return ((IBinary)celement).isExecutable(); return ((IBinary) celement).isExecutable();
} }
return false; return false;
} }
@ -204,7 +204,7 @@ public class CoreModel {
*/ */
public boolean isBinary(IFile file) { public boolean isBinary(IFile file) {
ICElement celement = create(file); ICElement celement = create(file);
return (celement instanceof IBinary); return celement instanceof IBinary;
} }
/** /**
@ -212,7 +212,7 @@ public class CoreModel {
*/ */
public boolean isArchive(IFile file) { public boolean isArchive(IFile file) {
ICElement celement = create(file); ICElement celement = create(file);
return(celement instanceof IArchive); return celement instanceof IArchive;
} }
/** /**
@ -494,7 +494,6 @@ public class CoreModel {
return new LibraryEntry(resourcePath, null, baseRef, libraryPath, null, null, null, false); return new LibraryEntry(resourcePath, null, baseRef, libraryPath, null, null, null, false);
} }
/** /**
* Creates and returns a new entry of kind {@code CDT_LIBRARY} * Creates and returns a new entry of kind {@code CDT_LIBRARY}
* for the archive or folder identified by the given absolute path. * for the archive or folder identified by the given absolute path.
@ -665,7 +664,7 @@ public class CoreModel {
* @param includePath * @param includePath
* the path of the include * the path of the include
* @param isSystemInclude * @param isSystemInclude
* wheter this include path should be consider the system * whether this include path should be consider the system
* include path * include path
* @param exclusionPatterns * @param exclusionPatterns
* exclusion patterns in the resource if a container * exclusion patterns in the resource if a container
@ -1328,7 +1327,7 @@ public class CoreModel {
} }
/** /**
* this method is a full equivalent to {@code createProjectDescription(project, loadIfExists, false)}. * This method is a full equivalent to {@code createProjectDescription(project, loadIfExists, false)}.
* *
* @see #createProjectDescription(IProject, boolean, boolean) * @see #createProjectDescription(IProject, boolean, boolean)
*/ */
@ -1337,7 +1336,7 @@ public class CoreModel {
} }
/** /**
* the method creates and returns a writable project description * Creates and returns a writable project description
* *
* @param project project for which the project description is requested * @param project project for which the project description is requested
* @param loadIfExists if true the method first tries to load and return the project description * @param loadIfExists if true the method first tries to load and return the project description
@ -1356,7 +1355,7 @@ public class CoreModel {
} }
/** /**
* returns the project description associated with this project or null if the project does not contain the * Returns the project description associated with this project or null if the project does not contain the
* CDT data associated with it. * CDT data associated with it.
* *
* this is a convenience method fully equivalent to getProjectDescription(project, true) * this is a convenience method fully equivalent to getProjectDescription(project, true)
@ -1374,7 +1373,7 @@ public class CoreModel {
} }
/** /**
* this method is called to save/apply the project description * This method is called to save/apply the project description
* the method should be called to apply changes made to the project description * the method should be called to apply changes made to the project description
* returned by the {@link #getProjectDescription(IProject, boolean)} or {@link #createProjectDescription(IProject, boolean)} * returned by the {@link #getProjectDescription(IProject, boolean)} or {@link #createProjectDescription(IProject, boolean)}
* *
@ -1407,7 +1406,7 @@ public class CoreModel {
* All set* calls to the read-only description result in the {@link WriteAccessException} * All set* calls to the read-only description result in the {@link WriteAccessException}
* *
* When the writable description is requested, the description copy is created. * When the writable description is requested, the description copy is created.
* Changes to this description will not be reflected/used by the core and Build System untill the * Changes to this description will not be reflected/used by the core and Build System until the
* {@link #setProjectDescription(IProject, ICProjectDescription)} is called * {@link #setProjectDescription(IProject, ICProjectDescription)} is called
* *
* Each getProjectDescription(project, true) returns a new copy of the project description * Each getProjectDescription(project, true) returns a new copy of the project description
@ -1465,7 +1464,7 @@ public class CoreModel {
if (descriptionManager != null) if (descriptionManager != null)
return descriptionManager; return descriptionManager;
// Initialization of the CoreModel hasn't finished yet. // The method was called while initialization of the CoreModel hasn't finished yet.
return CProjectDescriptionManager.getInstance(); return CProjectDescriptionManager.getInstance();
} }
} }

View file

@ -18,8 +18,7 @@ import java.lang.reflect.Method;
/** /**
* This class contains several convenience methods * This class contains several convenience methods mainly for debugging purposes.
* mainly for debugging purposes.
* *
* @noextend This interface is not intended to be extended by clients. * @noextend This interface is not intended to be extended by clients.
* @noinstantiate This class is not intended to be instantiated by clients. * @noinstantiate This class is not intended to be instantiated by clients.
@ -93,7 +92,7 @@ public class DebugUtil {
System.out.println("Object: " + obj); System.out.println("Object: " + obj);
BeanInfo info = Introspector.getBeanInfo(obj.getClass()); BeanInfo info = Introspector.getBeanInfo(obj.getClass());
for(PropertyDescriptor propertyDescriptor : info.getPropertyDescriptors()) { for (PropertyDescriptor propertyDescriptor : info.getPropertyDescriptors()) {
Method getter = propertyDescriptor.getReadMethod(); Method getter = propertyDescriptor.getReadMethod();
try { try {
System.out.println(" " + getter.getName() + "=" + getter.invoke(obj, new Object[0])); System.out.println(" " + getter.getName() + "=" + getter.invoke(obj, new Object[0]));

View file

@ -517,8 +517,7 @@ public class CDTMainWizardPage extends WizardNewProjectCreationPage implements I
} }
@Override @Override
@SuppressWarnings({ "unchecked", "rawtypes" }) public List<EntryDescriptor> filterItems(List<EntryDescriptor> items) {
public List filterItems(List items) {
return items; return items;
} }
} }

View file

@ -20,29 +20,25 @@ import java.util.List;
*/ */
public interface IWizardItemsListListener { public interface IWizardItemsListListener {
/** /**
* Called by ICNewWizard instance when * Called by ICNewWizard instance when user has changed tool chains selection.
* user has changed tool chains selection
* *
* @param count - number of selected toolchains. * @param count - number of selected toolchains.
*/ */
void toolChainListChanged(int count); void toolChainListChanged(int count);
/** /**
* @return true if this page is visible * @return true if this page is visible
*/ */
boolean isCurrent(); boolean isCurrent();
/** /**
* Ability to filter items which would be shown * Ability to filter items which would be shown in the left pane of Main Wizard Page.
* in the left pane of Main Wizard Page. * Standard implementation: returns unchanged list. When filtering, please note that
* Standard implementation: return unchanged list. * the items have hierarchical relations with others, so removing some item(s) can
* When filtering, please note : * break a tree.
* - Each item has {@link}EntryDescriptor type *
* - Items have hierarchical relations with others,
* so removing some item(s) can break a tree.
*
* @param items - list of EntryDescriptor objects * @param items - list of EntryDescriptor objects
* @return - list with filtered items * @return - list with filtered items
*/ */
List<EntryDescriptor> filterItems(List<? extends EntryDescriptor> items); List<EntryDescriptor> filterItems(List<EntryDescriptor> items);
} }

View file

@ -61,15 +61,13 @@ public class UpcProjectWizard extends CDTCommonProjectWizard {
@Override @Override
public void addPages() { public void addPages() {
fMainPage = new CDTMainWizardPage(PAGE_NAME) { fMainPage = new CDTMainWizardPage(PAGE_NAME) {
@Override @Override
@SuppressWarnings("unchecked") public List<EntryDescriptor> filterItems(List<EntryDescriptor> items) {
public List filterItems(List items) {
// filter out all non-UPC project types // filter out all non-UPC project types
if (items != null) { if (items != null) {
Iterator iter = items.iterator(); Iterator<EntryDescriptor> iter = items.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
EntryDescriptor entryDescriptor = (EntryDescriptor) iter.next(); EntryDescriptor entryDescriptor = iter.next();
if(!ALL_TYPES.contains(entryDescriptor.getId())) if(!ALL_TYPES.contains(entryDescriptor.getId()))
iter.remove(); iter.remove();
} }