mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +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:
parent
8667f5a5ae
commit
0f49ec2015
1 changed files with 27 additions and 26 deletions
|
@ -38,35 +38,36 @@ public class RunCodeAnalysis implements IObjectActionDelegate {
|
|||
|
||||
@Override
|
||||
public void run(IAction action) {
|
||||
Job job = new Job(CodanUIMessages.Job_TitleRunningAnalysis) {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected IStatus run(final IProgressMonitor monitor) {
|
||||
IStructuredSelection ss = (IStructuredSelection) sel;
|
||||
int count = ss.size();
|
||||
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 (sel instanceof IStructuredSelection) {
|
||||
final IStructuredSelection ss = (IStructuredSelection) sel;
|
||||
Job job = new Job(CodanUIMessages.Job_TitleRunningAnalysis) {
|
||||
@Override
|
||||
protected IStatus run(final IProgressMonitor monitor) {
|
||||
int count = ss.size();
|
||||
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())
|
||||
return Status.CANCEL_STATUS;
|
||||
}
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
};
|
||||
job.setUser(true);
|
||||
job.schedule();
|
||||
};
|
||||
job.setUser(true);
|
||||
job.schedule();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Reference in a new issue