1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 21:05:37 +02:00

Avoid ClassCastException in Codan Run job

Occasionally Run Code Analysis actions get text selection
instead of structured selection so it is failing and logging
CCE. Avoid this by non accepting other selections.

Change-Id: Ia3583755547e5251a057290e506184656ebf2d5a
Signed-off-by: Alena Laskavaia <elaskavaia.cdt@gmail.com>
Reviewed-on: https://git.eclipse.org/r/37306
Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
Alena Laskavaia 2014-11-28 15:30:48 -05:00 committed by Elena Laskavaia
parent 8667f5a5ae
commit 0f49ec2015

View file

@ -38,35 +38,36 @@ public class RunCodeAnalysis implements IObjectActionDelegate {
@Override @Override
public void run(IAction action) { public void run(IAction action) {
Job job = new Job(CodanUIMessages.Job_TitleRunningAnalysis) { if (sel instanceof IStructuredSelection) {
@SuppressWarnings("unchecked") final IStructuredSelection ss = (IStructuredSelection) sel;
@Override Job job = new Job(CodanUIMessages.Job_TitleRunningAnalysis) {
protected IStatus run(final IProgressMonitor monitor) { @Override
IStructuredSelection ss = (IStructuredSelection) sel; protected IStatus run(final IProgressMonitor monitor) {
int count = ss.size(); int count = ss.size();
monitor.beginTask(getName(), count * 100); monitor.beginTask(getName(), count * 100);
if (monitor.isCanceled())
return Status.CANCEL_STATUS;
for (Iterator iterator = ss.iterator(); iterator.hasNext();) {
Object o = iterator.next();
if (o instanceof IAdaptable) {
o = ((IAdaptable) o).getAdapter(IResource.class);
}
if (o instanceof IResource) {
IResource res = (IResource) o;
SubProgressMonitor subMon = new SubProgressMonitor(monitor, 100);
CodanRuntime.getInstance().getBuilder().processResource(res, subMon, CheckerLaunchMode.RUN_ON_DEMAND);
if (subMon.isCanceled())
return Status.CANCEL_STATUS;
}
if (monitor.isCanceled()) if (monitor.isCanceled())
return Status.CANCEL_STATUS; return Status.CANCEL_STATUS;
for (Iterator iterator = ss.iterator(); iterator.hasNext();) {
Object o = iterator.next();
if (o instanceof IAdaptable) {
o = ((IAdaptable) o).getAdapter(IResource.class);
}
if (o instanceof IResource) {
IResource res = (IResource) o;
SubProgressMonitor subMon = new SubProgressMonitor(monitor, 100);
CodanRuntime.getInstance().getBuilder().processResource(res, subMon, CheckerLaunchMode.RUN_ON_DEMAND);
if (subMon.isCanceled())
return Status.CANCEL_STATUS;
}
if (monitor.isCanceled())
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
} }
return Status.OK_STATUS; };
} job.setUser(true);
}; job.schedule();
job.setUser(true); }
job.schedule();
} }
@Override @Override