1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-29 11:55:40 +02:00

formatting, null pointer warnings, loops to enhanced - no functionality changes

This commit is contained in:
Andrew Gvozdev 2009-08-12 14:31:28 +00:00
parent 5ea5e92667
commit 9bbb8450e9

View file

@ -171,24 +171,22 @@ public class MBSWizardHandler extends CWizardHandler {
String[] langIDs = wz.getLanguageIDs(); String[] langIDs = wz.getLanguageIDs();
if(langIDs.length > 0) { if(langIDs.length > 0) {
List<Template> lstTemplates = new ArrayList<Template>(); List<Template> lstTemplates = new ArrayList<Template>();
for(int i = 0; i < langIDs.length; ++i) { for (String id : langIDs) {
lstTemplates.addAll(Arrays.asList(TemplateEngineUI.getDefault(). lstTemplates.addAll(Arrays.asList(TemplateEngineUI.getDefault().
getTemplates(projectTypeId, null, langIDs[i]))); getTemplates(projectTypeId, null, id)));
} }
templates = lstTemplates.toArray(new Template[lstTemplates.size()]); templates = lstTemplates.toArray(new Template[lstTemplates.size()]);
} }
} }
if(null == templates) { if(null == templates) {
templates = templates = TemplateEngineUI.getDefault().getTemplates(projectTypeId);
TemplateEngineUI.getDefault().
getTemplates(projectTypeId);
} }
if((null == templates) || (templates.length == 0)) if((null == templates) || (templates.length == 0))
break; break;
for(int i = 0; i < templates.length; i++){ for (Template t : templates) {
if(templates[i].getTemplateId().equals(templateId)){ if(t.getTemplateId().equals(templateId)){
template = templates[i]; template = t;
break; break;
} }
} }
@ -211,8 +209,7 @@ public class MBSWizardHandler extends CWizardHandler {
if(template != null){ if(template != null){
Map<String, String> valueStore = template.getValueStore(); Map<String, String> valueStore = template.getValueStore();
// valueStore.clear(); // valueStore.clear();
for(int i=0; i < templatePages.length; i++) { for (IWizardPage page : templatePages) {
IWizardPage page = templatePages[i];
if (page instanceof UIWizardPage) if (page instanceof UIWizardPage)
valueStore.putAll(((UIWizardPage)page).getPageData()); valueStore.putAll(((UIWizardPage)page).getPageData());
if (page instanceof IWizardDataPage) if (page instanceof IWizardDataPage)
@ -280,8 +277,8 @@ public class MBSWizardHandler extends CWizardHandler {
if (template == null || template.getTemplateInfo() == null) if (template == null || template.getTemplateInfo() == null)
return true; return true;
String[] ss = template.getTemplateInfo().getToolChainIds(); String[] toolChainIds = template.getTemplateInfo().getToolChainIds();
if (ss == null || ss.length == 0) if (toolChainIds == null || toolChainIds.length == 0)
return true; return true;
Object ob = tcs.get(tcId); Object ob = tcs.get(tcId);
@ -294,9 +291,9 @@ public class MBSWizardHandler extends CWizardHandler {
IToolChain sup = ((IToolChain)ob).getSuperClass(); IToolChain sup = ((IToolChain)ob).getSuperClass();
String id2 = sup == null ? null : sup.getId(); String id2 = sup == null ? null : sup.getId();
for (int i=0; i<ss.length; i++) { for (String id : toolChainIds) {
if ((ss[i] != null && ss[i].equals(id1)) || if ((id != null && id.equals(id1)) ||
(ss[i] != null && ss[i].equals(id2))) (id != null && id.equals(id2)))
return true; return true;
} }
return false; return false;
@ -365,19 +362,20 @@ public class MBSWizardHandler extends CWizardHandler {
return baseName; return baseName;
} }
@Override
public void handleSelection() { public void handleSelection() {
List<String> preferred = CDTPrefUtil.getPreferredTCs(); List<String> preferred = CDTPrefUtil.getPreferredTCs();
if (table == null) { if (table == null) {
table = new Table(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER); table = new Table(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
table.getAccessible().addAccessibleListener( table.getAccessible().addAccessibleListener(
new AccessibleAdapter() { new AccessibleAdapter() {
public void getName(AccessibleEvent e) { @Override
if (e.result == null) public void getName(AccessibleEvent e) {
e.result = head; if (e.result == null)
} e.result = head;
} }
); });
table.setToolTipText(tooltip); table.setToolTipText(tooltip);
if (entryInfo != null) { if (entryInfo != null) {
int counter = 0; int counter = 0;
@ -402,9 +400,11 @@ public class MBSWizardHandler extends CWizardHandler {
if (counter > 0) table.select(position); if (counter > 0) table.select(position);
} }
table.addSelectionListener(new SelectionAdapter() { table.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
handleToolChainSelection(); handleToolChainSelection();
}}); }
});
} }
updatePreferred(preferred); updatePreferred(preferred);
loadCustomPages(); loadCustomPages();
@ -441,8 +441,8 @@ public class MBSWizardHandler extends CWizardHandler {
if (customPages == null) if (customPages == null)
customPages = new IWizardPage[0]; customPages = new IWizardPage[0];
for (int k = 0; k < customPages.length; k++) for (IWizardPage customPage : customPages)
customPages[k].setWizard(wz); customPage.setWizard(wz);
} }
setCustomPagesFilter(wz); setCustomPagesFilter(wz);
} }
@ -455,7 +455,8 @@ public class MBSWizardHandler extends CWizardHandler {
MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.NATURE, natures[0]); MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.NATURE, natures[0]);
else { else {
TreeSet<String> x = new TreeSet<String>(); TreeSet<String> x = new TreeSet<String>();
for (int i=0; i<natures.length; i++) x.add(natures[i]); for (String nature : natures)
x.add(nature);
MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.NATURE, x); MBSCustomPageManager.addPageProperty(MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.NATURE, x);
} }
// Project type can be obtained either from Handler (for old-style projects), // Project type can be obtained either from Handler (for old-style projects),
@ -469,20 +470,22 @@ public class MBSWizardHandler extends CWizardHandler {
); );
IToolChain[] tcs = getSelectedToolChains(); IToolChain[] tcs = getSelectedToolChains();
int n = (tcs == null) ? 0 : tcs.length;
ArrayList<IToolChain> x = new ArrayList<IToolChain>(); ArrayList<IToolChain> x = new ArrayList<IToolChain>();
TreeSet<String> y = new TreeSet<String>(); TreeSet<String> y = new TreeSet<String>();
for (int i=0; i<n; i++) { if (tcs!=null) {
if (tcs[i] == null) // --- NO TOOLCHAIN --- int n = tcs.length;
continue; // has no custom pages. for (int i=0; i<n; i++) {
x.add(tcs[i]); if (tcs[i] == null) // --- NO TOOLCHAIN ---
continue; // has no custom pages.
x.add(tcs[i]);
IConfiguration cfg = tcs[i].getParent(); IConfiguration cfg = tcs[i].getParent();
if (cfg == null) if (cfg == null)
continue; continue;
IProjectType pt = cfg.getProjectType(); IProjectType pt = cfg.getProjectType();
if (pt != null) if (pt != null)
y.add(pt.getId()); y.add(pt.getId());
}
} }
MBSCustomPageManager.addPageProperty( MBSCustomPageManager.addPageProperty(
MBSCustomPageManager.PAGE_ID, MBSCustomPageManager.PAGE_ID,
@ -503,6 +506,7 @@ public class MBSWizardHandler extends CWizardHandler {
} }
} }
@Override
public void handleUnSelection() { public void handleUnSelection() {
if (table != null) { if (table != null) {
table.setVisible(false); table.setVisible(false);
@ -524,6 +528,7 @@ public class MBSWizardHandler extends CWizardHandler {
full_tcs.put(tc.getUniqueRealName(), tc); full_tcs.put(tc.getUniqueRealName(), tc);
} }
@Override
public void createProject(IProject project, boolean defaults, boolean onFinish, IProgressMonitor monitor) throws CoreException { public void createProject(IProject project, boolean defaults, boolean onFinish, IProgressMonitor monitor) throws CoreException {
try { try {
monitor.beginTask("", 100); //$NON-NLS-1$ monitor.beginTask("", 100); //$NON-NLS-1$
@ -536,61 +541,63 @@ public class MBSWizardHandler extends CWizardHandler {
} }
} }
@Override
public void convertProject(IProject proj, IProgressMonitor monitor) throws CoreException { public void convertProject(IProject proj, IProgressMonitor monitor) throws CoreException {
setProjectDescription(proj, true, true, monitor); setProjectDescription(proj, true, true, monitor);
} }
private void setProjectDescription(IProject project, boolean defaults, boolean onFinish, IProgressMonitor monitor) throws CoreException { private void setProjectDescription(IProject project, boolean defaults, boolean onFinish, IProgressMonitor monitor) throws CoreException {
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
ICProjectDescription des = mngr.createProjectDescription(project, false, !onFinish); ICProjectDescription des = mngr.createProjectDescription(project, false, !onFinish);
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project); ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
monitor.worked(10); monitor.worked(10);
cfgs = getCfgItems(false); cfgs = getCfgItems(false);
if (cfgs == null || cfgs.length == 0) if (cfgs == null || cfgs.length == 0)
cfgs = CDTConfigWizardPage.getDefaultCfgs(this); cfgs = CDTConfigWizardPage.getDefaultCfgs(this);
if (cfgs == null || cfgs.length == 0 || cfgs[0].getConfiguration() == null) { if (cfgs == null || cfgs.length == 0 || cfgs[0].getConfiguration() == null) {
throw new CoreException(new Status(IStatus.ERROR, throw new CoreException(new Status(IStatus.ERROR,
ManagedBuilderUIPlugin.getUniqueIdentifier(), ManagedBuilderUIPlugin.getUniqueIdentifier(),
Messages.getString("CWizardHandler.6"))); //$NON-NLS-1$ Messages.getString("CWizardHandler.6"))); //$NON-NLS-1$
} }
Configuration cf = (Configuration)cfgs[0].getConfiguration(); Configuration cf = (Configuration)cfgs[0].getConfiguration();
ManagedProject mProj = new ManagedProject(project, cf.getProjectType()); ManagedProject mProj = new ManagedProject(project, cf.getProjectType());
info.setManagedProject(mProj); info.setManagedProject(mProj);
monitor.worked(10); monitor.worked(10);
cfgs = CfgHolder.unique(cfgs); cfgs = CfgHolder.unique(cfgs);
cfgs = CfgHolder.reorder(cfgs); cfgs = CfgHolder.reorder(cfgs);
ICConfigurationDescription cfgDebug = null; ICConfigurationDescription cfgDebug = null;
ICConfigurationDescription cfgFirst = null; ICConfigurationDescription cfgFirst = null;
int work = 50/cfgs.length; int work = 50/cfgs.length;
for(int i = 0; i < cfgs.length; i++){ for (CfgHolder cfg : cfgs) {
cf = (Configuration)cfgs[i].getConfiguration(); cf = (Configuration)cfg.getConfiguration();
String id = ManagedBuildManager.calculateChildId(cf.getId(), null); String id = ManagedBuildManager.calculateChildId(cf.getId(), null);
Configuration config = new Configuration(mProj, cf, id, false, true); Configuration config = new Configuration(mProj, cf, id, false, true);
CConfigurationData data = config.getConfigurationData(); CConfigurationData data = config.getConfigurationData();
ICConfigurationDescription cfgDes = des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data); ICConfigurationDescription cfgDes = des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
config.setConfigurationDescription(cfgDes); config.setConfigurationDescription(cfgDes);
config.exportArtifactInfo(); config.exportArtifactInfo();
IBuilder bld = config.getEditableBuilder(); IBuilder bld = config.getEditableBuilder();
if (bld != null) { bld.setManagedBuildOn(true); } if (bld != null) { bld.setManagedBuildOn(true); }
config.setName(cfgs[i].getName()); config.setName(cfg.getName());
config.setArtifactName(mProj.getDefaultArtifactName()); config.setArtifactName(mProj.getDefaultArtifactName());
IBuildProperty b = config.getBuildProperties().getProperty(PROPERTY); IBuildProperty b = config.getBuildProperties().getProperty(PROPERTY);
if (cfgDebug == null && b != null && b.getValue() != null && PROP_VAL.equals(b.getValue().getId())) if (cfgDebug == null && b != null && b.getValue() != null && PROP_VAL.equals(b.getValue().getId()))
cfgDebug = cfgDes; cfgDebug = cfgDes;
if (cfgFirst == null) // select at least first configuration if (cfgFirst == null) // select at least first configuration
cfgFirst = cfgDes; cfgFirst = cfgDes;
monitor.worked(work); monitor.worked(work);
} }
mngr.setProjectDescription(project, des); mngr.setProjectDescription(project, des);
} }
@Override
protected void doTemplatesPostProcess(IProject prj) { protected void doTemplatesPostProcess(IProject prj) {
if(entryInfo == null) if(entryInfo == null)
return; return;
@ -600,15 +607,15 @@ public class MBSWizardHandler extends CWizardHandler {
return; return;
List<IConfiguration> configs = new ArrayList<IConfiguration>(); List<IConfiguration> configs = new ArrayList<IConfiguration>();
for(int i = 0; i < cfgs.length; i++){ for (CfgHolder cfg : cfgs) {
configs.add((IConfiguration)cfgs[i].getConfiguration()); configs.add((IConfiguration)cfg.getConfiguration());
} }
template.getTemplateInfo().setConfigurations(configs); template.getTemplateInfo().setConfigurations(configs);
IStatus[] statuses = template.executeTemplateProcesses(null, false); IStatus[] statuses = template.executeTemplateProcesses(null, false);
if (statuses.length == 1 && statuses[0].getException() instanceof ProcessFailureException) { if (statuses.length == 1 && statuses[0].getException() instanceof ProcessFailureException) {
TemplateEngineUIUtil.showError(statuses[0].getMessage(), statuses[0].getException()); TemplateEngineUIUtil.showError(statuses[0].getMessage(), statuses[0].getException());
} }
} }
protected CDTConfigWizardPage getConfigPage() { protected CDTConfigWizardPage getConfigPage() {
@ -618,6 +625,7 @@ public class MBSWizardHandler extends CWizardHandler {
return fConfigPage; return fConfigPage;
} }
@Override
public IWizardPage getSpecificPage() { public IWizardPage getSpecificPage() {
return entryInfo.getNextPage(getStartingPage(), getConfigPage()); return entryInfo.getNextPage(getStartingPage(), getConfigPage());
} }
@ -627,19 +635,19 @@ public class MBSWizardHandler extends CWizardHandler {
* @ * @
*/ */
@Override
public void updatePreferred(List<String> prefs) { public void updatePreferred(List<String> prefs) {
preferredTCs.clear(); preferredTCs.clear();
int x = table.getItemCount(); int x = table.getItemCount();
for (int i=0; i<x; i++) { for (int i=0; i<x; i++) {
TableItem ti = table.getItem(i); TableItem ti = table.getItem(i);
IToolChain tc = (IToolChain)ti.getData(); IToolChain tc = (IToolChain)ti.getData();
String id = (tc == null) ? CDTPrefUtil.NULL : tc.getId(); if (tc!=null && prefs.contains(tc.getId())) {
if (prefs.contains(id)) {
ti.setImage(IMG1); ti.setImage(IMG1);
preferredTCs.add(tc.getName()); preferredTCs.add(tc.getName());
} } else {
else
ti.setImage(IMG0); ti.setImage(IMG0);
}
} }
} }
@ -647,28 +655,34 @@ public class MBSWizardHandler extends CWizardHandler {
return preferredTCs; return preferredTCs;
} }
@Override
public String getHeader() { return head; } public String getHeader() { return head; }
public boolean isDummy() { return false; } public boolean isDummy() { return false; }
@Override
public boolean supportsPreferred() { return true; } public boolean supportsPreferred() { return true; }
@Override
public boolean isChanged() { public boolean isChanged() {
if (savedToolChains == null) if (savedToolChains == null)
return true; return true;
IToolChain[] tcs = getSelectedToolChains(); IToolChain[] tcs = getSelectedToolChains();
if (savedToolChains.length != tcs.length) if (savedToolChains.length != tcs.length)
return true; return true;
for (int i=0; i<savedToolChains.length; i++) { for (IToolChain savedToolChain : savedToolChains) {
boolean found = false; boolean found = false;
for (int j=0; j<tcs.length; j++) { for (IToolChain tc : tcs) {
if (savedToolChains[i] == tcs[j]) { if (savedToolChain == tc) {
found = true; break; found = true;
break;
} }
} }
if (!found) return true; if (!found)
return true;
} }
return false; return false;
} }
@Override
public void saveState() { public void saveState() {
savedToolChains = getSelectedToolChains(); savedToolChains = getSelectedToolChains();
} }
@ -704,6 +718,7 @@ public class MBSWizardHandler extends CWizardHandler {
getConfigPage(); // ensure that page is created getConfigPage(); // ensure that page is created
return fConfigPage.getCfgItems(defaults); return fConfigPage.getCfgItems(defaults);
} }
@Override
public String getErrorMessage() { public String getErrorMessage() {
TableItem[] tis = table.getSelection(); TableItem[] tis = table.getSelection();
if (tis == null || tis.length == 0) if (tis == null || tis.length == 0)
@ -711,12 +726,13 @@ public class MBSWizardHandler extends CWizardHandler {
return null; return null;
} }
@Override
protected void doCustom(IProject newProject) { protected void doCustom(IProject newProject) {
IRunnableWithProgress[] operations = MBSCustomPageManager.getOperations(); IRunnableWithProgress[] operations = MBSCustomPageManager.getOperations();
if(operations != null) if(operations != null)
for(int k = 0; k < operations.length; k++) for (IRunnableWithProgress op: operations)
try { try {
wizard.getContainer().run(false, true, operations[k]); wizard.getContainer().run(false, true, op);
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
ManagedBuilderUIPlugin.log(e); ManagedBuilderUIPlugin.log(e);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -724,6 +740,7 @@ public class MBSWizardHandler extends CWizardHandler {
} }
} }
@Override
public void postProcess(IProject newProject, boolean created) { public void postProcess(IProject newProject, boolean created) {
deleteExtraConfigs(newProject); deleteExtraConfigs(newProject);
// calls are required only if the project was // calls are required only if the project was
@ -750,16 +767,17 @@ public class MBSWizardHandler extends CWizardHandler {
if (all == null) return; if (all == null) return;
CfgHolder[] req = getCfgItems(false); CfgHolder[] req = getCfgItems(false);
boolean modified = false; boolean modified = false;
for (int i=0; i<all.length; i++) { for (ICConfigurationDescription cfgDes : all) {
boolean found = false; boolean found = false;
for (int j=0; j<req.length; j++) { for (CfgHolder cfgh : req) {
if (all[i].getName().equals(req[j].getName())) { if (cfgDes.getName().equals(cfgh.getName())) {
found = true; break; found = true;
break;
} }
} }
if (!found) { if (!found) {
modified = true; modified = true;
prjd.removeConfiguration(all[i]); prjd.removeConfiguration(cfgDes);
} }
} }
if (modified) try { if (modified) try {
@ -767,11 +785,13 @@ public class MBSWizardHandler extends CWizardHandler {
} catch (CoreException e) {} } catch (CoreException e) {}
} }
@Override
public boolean isApplicable(EntryDescriptor data) { public boolean isApplicable(EntryDescriptor data) {
EntryInfo info = new EntryInfo(data, full_tcs, wizard); EntryInfo info = new EntryInfo(data, full_tcs, wizard);
return info.isValid() && (info.getToolChainsCount() > 0); return info.isValid() && (info.getToolChainsCount() > 0);
} }
@Override
public void initialize(EntryDescriptor data) throws CoreException { public void initialize(EntryDescriptor data) throws CoreException {
EntryInfo info = new EntryInfo(data, full_tcs, wizard); EntryInfo info = new EntryInfo(data, full_tcs, wizard);
if(!info.isValid()) if(!info.isValid())
@ -783,6 +803,7 @@ public class MBSWizardHandler extends CWizardHandler {
/** /**
* Clones itself. * Clones itself.
*/ */
@Override
public Object clone() { public Object clone() {
MBSWizardHandler clone = (MBSWizardHandler)super.clone(); MBSWizardHandler clone = (MBSWizardHandler)super.clone();
if (clone != null) { if (clone != null) {
@ -797,6 +818,7 @@ public class MBSWizardHandler extends CWizardHandler {
return clone; return clone;
} }
@Override
public boolean canFinish() { public boolean canFinish() {
if(entryInfo == null) if(entryInfo == null)
return false; return false;