From 4c3a5dd6695667662d861aed6e7d2d517de7e9de Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sun, 29 Apr 2012 19:12:28 -0700 Subject: [PATCH] Moved execution of checkers from CodanBuilder to CodanRunner. --- .../internal/model/CxxCodanReconciler.java | 12 +- .../.settings/.api_filters | 11 ++ .../cdt/codan/core/CodanCorePlugin.java | 4 +- .../cdt/codan/core/model/CodanSeverity.java | 3 +- .../cdt/codan/core/model/Messages.java | 31 +++++ .../cdt/codan/core/model/Messages.properties | 14 ++ .../param/FileScopeProblemPreference.java | 18 +-- .../cdt/codan/core/param/Messages.java | 29 ++++ .../cdt/codan/core/param/Messages.properties | 12 ++ .../codan/internal/core/CodanApplication.java | 9 +- .../cdt/codan/internal/core/CodanBuilder.java | 96 +------------ .../cdt/codan/internal/core/CodanRunner.java | 130 ++++++++++++++++++ .../codan/{ => internal}/core/Messages.java | 22 +-- .../{ => internal}/core/Messages.properties | 7 +- .../internal/core/model/ProblemProfile.java | 10 +- .../cdt/codan/internal/ui/cxx/Startup.java | 11 +- .../ui/preferences/CodanPreferencePage.java | 34 ++--- .../preferences/FieldEditorOverlayPage.java | 12 +- 18 files changed, 289 insertions(+), 176 deletions(-) create mode 100644 codan/org.eclipse.cdt.codan.core/.settings/.api_filters create mode 100644 codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/Messages.java create mode 100644 codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/Messages.properties create mode 100644 codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/Messages.java create mode 100644 codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/Messages.properties create mode 100644 codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanRunner.java rename codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/{ => internal}/core/Messages.java (70%) rename codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/{ => internal}/core/Messages.properties (84%) diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/CxxCodanReconciler.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/CxxCodanReconciler.java index 5c48524a448..3fd01ca1fe0 100644 --- a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/CxxCodanReconciler.java +++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/CxxCodanReconciler.java @@ -1,17 +1,17 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Alena Laskavaia + * Copyright (c) 2009, 2012 Alena Laskavaia * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Alena Laskavaia - initial API and implementation + * Alena Laskavaia - initial API and implementation + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.codan.core.cxx.internal.model; -import org.eclipse.cdt.codan.core.CodanRuntime; -import org.eclipse.cdt.codan.internal.core.CodanBuilder; +import org.eclipse.cdt.codan.internal.core.CodanRunner; import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CProjectNature; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; @@ -22,10 +22,8 @@ import org.eclipse.core.runtime.IProgressMonitor; /** * @author Alena - * */ public class CxxCodanReconciler { - private CodanBuilder builder = (CodanBuilder) CodanRuntime.getInstance().getBuilder(); public void reconciledAst(IASTTranslationUnit ast, IResource resource, IProgressMonitor monitor) { if (ast == null) @@ -35,7 +33,7 @@ public class CxxCodanReconciler { return; try { if (project.hasNature(CProjectNature.C_NATURE_ID) || project.hasNature(CCProjectNature.CC_NATURE_ID)) { - builder.runInEditor(ast, resource, monitor); + CodanRunner.runInEditor(ast, resource, monitor); } } catch (CoreException e) { // ignore diff --git a/codan/org.eclipse.cdt.codan.core/.settings/.api_filters b/codan/org.eclipse.cdt.codan.core/.settings/.api_filters new file mode 100644 index 00000000000..2133a51480f --- /dev/null +++ b/codan/org.eclipse.cdt.codan.core/.settings/.api_filters @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java index befb24ac5cb..70a583c6c10 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanCorePlugin.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.codan.core; -import org.eclipse.cdt.codan.internal.core.CodeAnlysisNature; +import org.eclipse.cdt.codan.internal.core.CodeAnalysisNature; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Status; @@ -28,7 +28,7 @@ public class CodanCorePlugin extends Plugin { * The nature used to run Codan builder. * @noreference This constant is not intended to be referenced by clients. */ - public static final String NATURE_ID = CodeAnlysisNature.NATURE_ID; + public static final String NATURE_ID = CodeAnalysisNature.NATURE_ID; // The shared instance private static CodanCorePlugin plugin; diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanSeverity.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanSeverity.java index d92db707347..5ff0852ab7c 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanSeverity.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanSeverity.java @@ -11,11 +11,9 @@ *******************************************************************************/ package org.eclipse.cdt.codan.core.model; -import org.eclipse.cdt.codan.core.Messages; import org.eclipse.core.resources.IMarker; /** - * * Represents Severity of the codan problem. It is directly mapped to markers * severity. * @@ -33,6 +31,7 @@ public enum CodanSeverity { * Error severity */ Error(IMarker.SEVERITY_ERROR); + private int value; private CodanSeverity(int value) { diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/Messages.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/Messages.java new file mode 100644 index 00000000000..bc9a63ffb7e --- /dev/null +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/Messages.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2009, 2012 Alena Laskavaia and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + * IBM Corporation + *******************************************************************************/ +package org.eclipse.cdt.codan.core.model; + +import org.eclipse.osgi.util.NLS; + +/** + * Core Messages + */ +class Messages extends NLS { + public static String CodanSeverity_Error; + public static String CodanSeverity_Info; + public static String CodanSeverity_Warning; + + static { + NLS.initializeMessages(Messages.class.getName(), Messages.class); + } + + // Do not instantiate + private Messages() { + } +} diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/Messages.properties b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/Messages.properties new file mode 100644 index 00000000000..192e094fd00 --- /dev/null +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/Messages.properties @@ -0,0 +1,14 @@ +############################################################################### +# Copyright (c) 2010, 2012 Alena Laskavaia and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Alena Laskavaia - initial API and implementation +# IBM Corporation +############################################################################### +CodanSeverity_Error=Error +CodanSeverity_Info=Info +CodanSeverity_Warning=Warning diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/FileScopeProblemPreference.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/FileScopeProblemPreference.java index 277b3aa4e93..dcff77ca15f 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/FileScopeProblemPreference.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/FileScopeProblemPreference.java @@ -1,16 +1,21 @@ /******************************************************************************* - * Copyright (c) 2009,2010 QNX Software Systems + * Copyright (c) 2009, 2010 QNX Software Systems * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX Software Systems (Alena Laskavaia) - initial API and implementation + * QNX Software Systems (Alena Laskavaia) - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.codan.core.param; -import org.eclipse.cdt.codan.core.Messages; +import java.io.IOException; +import java.io.StreamTokenizer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import org.eclipse.cdt.codan.internal.core.CharOperation; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; @@ -20,12 +25,6 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; -import java.io.IOException; -import java.io.StreamTokenizer; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - /** * Custom preference for resource scope * @@ -45,6 +44,7 @@ public class FileScopeProblemPreference extends AbstractProblemPreference { * Inclusion attribute */ public static final String INCLUSION = "inclusion"; //$NON-NLS-1$ + private IResource resource; private IPath[] inclusion = new IPath[0]; private IPath[] exclusion = new IPath[0]; diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/Messages.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/Messages.java new file mode 100644 index 00000000000..4591d288546 --- /dev/null +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/Messages.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2009, 2012 Alena Laskavaia and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + * IBM Corporation + *******************************************************************************/ +package org.eclipse.cdt.codan.core.param; + +import org.eclipse.osgi.util.NLS; + +/** + * Core Messages + */ +class Messages extends NLS { + public static String FileScopeProblemPreference_Label; + + static { + NLS.initializeMessages(Messages.class.getName(), Messages.class); + } + + // Do not instantiate + private Messages() { + } +} diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/Messages.properties b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/Messages.properties new file mode 100644 index 00000000000..04c64faf740 --- /dev/null +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/Messages.properties @@ -0,0 +1,12 @@ +############################################################################### +# Copyright (c) 2010, 2012 Alena Laskavaia and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Alena Laskavaia - initial API and implementation +# IBM Corporation +############################################################################### +FileScopeProblemPreference_Label=Exclusion and Inclusion diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanApplication.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanApplication.java index 0d2f0de74e3..62f3f18fa9c 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanApplication.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanApplication.java @@ -14,7 +14,6 @@ import java.util.ArrayList; import java.util.Collection; import org.eclipse.cdt.codan.core.CodanRuntime; -import org.eclipse.cdt.codan.core.Messages; import org.eclipse.cdt.codan.core.model.AbstractProblemReporter; import org.eclipse.cdt.codan.core.model.ICodanProblemMarker; import org.eclipse.core.resources.IProject; @@ -28,14 +27,14 @@ import org.eclipse.osgi.util.NLS; /** * Application to support headless build - * + * * @noextend This class is not intended to be extended by clients. * @noinstantiate This class is not intended to be instantiated by clients. */ public class CodanApplication implements IApplication { private Collection projects = new ArrayList(); - private boolean verbose = false; - private boolean all = false; + private boolean verbose; + private boolean all; @Override public Object start(IApplicationContext context) throws Exception { @@ -99,7 +98,7 @@ public class CodanApplication implements IApplication { } /** - * + * */ private void help() { System.out.println(Messages.CodanApplication_Usage); diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java index 0d88a03d63c..56619b9b50b 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java @@ -13,14 +13,8 @@ package org.eclipse.cdt.codan.internal.core; import java.util.Map; -import org.eclipse.cdt.codan.core.CodanCorePlugin; -import org.eclipse.cdt.codan.core.Messages; import org.eclipse.cdt.codan.core.model.CheckerLaunchMode; -import org.eclipse.cdt.codan.core.model.IChecker; -import org.eclipse.cdt.codan.core.model.ICheckerInvocationContext; import org.eclipse.cdt.codan.core.model.ICodanBuilder; -import org.eclipse.cdt.codan.core.model.IRunnableInEditorChecker; -import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceDelta; @@ -28,8 +22,6 @@ import org.eclipse.core.resources.IResourceDeltaVisitor; import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.SubProgressMonitor; /** * Implementation of {@link ICodanBuilder} @@ -86,7 +78,7 @@ public class CodanBuilder extends IncrementalProjectBuilder implements ICodanBui @Override public void processResource(IResource resource, IProgressMonitor monitor) { - processResource(resource, monitor, null, CheckerLaunchMode.RUN_ON_FULL_BUILD); + CodanRunner.processResource(resource, monitor, CheckerLaunchMode.RUN_ON_FULL_BUILD); } /** @@ -99,84 +91,13 @@ public class CodanBuilder extends IncrementalProjectBuilder implements ICodanBui */ @Override public void processResource(IResource resource, IProgressMonitor monitor, CheckerLaunchMode mode) { - processResource(resource, monitor, null, mode); + CodanRunner.processResource(resource, monitor, mode); } private void processResourceDelta(IResource resource, IProgressMonitor monitor) { processResource(resource, monitor, CheckerLaunchMode.RUN_ON_INC_BUILD); } - protected void processResource(IResource resource, IProgressMonitor monitor, Object model, - CheckerLaunchMode checkerLaunchMode) { - CheckersRegistry chegistry = CheckersRegistry.getInstance(); - int checkers = chegistry.getCheckersSize(); - int memsize = 0; - if (resource instanceof IContainer) { - try { - IResource[] members = ((IContainer) resource).members(); - memsize = members.length; - } catch (CoreException e) { - CodanCorePlugin.log(e); - } - } - int tick = 1000; - // System.err.println("processing " + resource); - monitor.beginTask(Messages.CodanBuilder_Code_Analysis_On + resource, checkers + memsize * tick); - try { - CheckersTimeStats.getInstance().checkerStart(CheckersTimeStats.ALL); - ICheckerInvocationContext context = new CheckerInvocationContext(resource); - try { - for (IChecker checker : chegistry) { - try { - if (monitor.isCanceled()) - return; - if (chegistry.isCheckerEnabled(checker, resource, checkerLaunchMode)) { - synchronized (checker) { - try { - checker.before(resource); - CheckersTimeStats.getInstance().checkerStart(checker.getClass().getName()); - if (checkerLaunchMode == CheckerLaunchMode.RUN_AS_YOU_TYPE) { - ((IRunnableInEditorChecker) checker).processModel(model, context); - } else { - checker.processResource(resource, context); - } - } finally { - CheckersTimeStats.getInstance().checkerStop(checker.getClass().getName()); - checker.after(resource); - } - } - } - monitor.worked(1); - } catch (OperationCanceledException e) { - return; - } catch (Throwable e) { - CodanCorePlugin.log(e); - } - } - } finally { - context.dispose(); - CheckersTimeStats.getInstance().checkerStop(CheckersTimeStats.ALL); - //CheckersTimeStats.getInstance().printStats(); - } - if (resource instanceof IContainer - && (checkerLaunchMode == CheckerLaunchMode.RUN_ON_FULL_BUILD || checkerLaunchMode == CheckerLaunchMode.RUN_ON_DEMAND)) { - try { - IResource[] members = ((IContainer) resource).members(); - for (int i = 0; i < members.length; i++) { - if (monitor.isCanceled()) - return; - IResource member = members[i]; - processResource(member, new SubProgressMonitor(monitor, tick)); - } - } catch (CoreException e) { - CodanCorePlugin.log(e); - } - } - } finally { - monitor.done(); - } - } - protected void fullBuild(final IProgressMonitor monitor) throws CoreException { processResource(getProject(), monitor); } @@ -185,17 +106,4 @@ public class CodanBuilder extends IncrementalProjectBuilder implements ICodanBui // The visitor does the work. delta.accept(new CodanDeltaVisitor(monitor)); } - - /** - * Run all checkers that support "check as you type" mode - * - * @param model - model of given resource such as ast - * @param resource - resource to process - * @param monitor - progress monitor - */ - public void runInEditor(Object model, IResource resource, IProgressMonitor monitor) { - if (model == null) - return; - processResource(resource, monitor, model, CheckerLaunchMode.RUN_AS_YOU_TYPE); - } } diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanRunner.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanRunner.java new file mode 100644 index 00000000000..9b5dc9549be --- /dev/null +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanRunner.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2009, 2012 Alena Laskavaia + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + * Sergey Prigogin (Google) + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.core; + +import org.eclipse.cdt.codan.core.CodanCorePlugin; +import org.eclipse.cdt.codan.core.model.CheckerLaunchMode; +import org.eclipse.cdt.codan.core.model.IChecker; +import org.eclipse.cdt.codan.core.model.ICheckerInvocationContext; +import org.eclipse.cdt.codan.core.model.IRunnableInEditorChecker; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.osgi.util.NLS; + +/** + * Collection of methods for running checkers. + */ +public class CodanRunner { + /** Do not instantiate. All methods are static */ + private CodanRunner() {} + + + /** + * Runs all checkers that support "run as you type" mode. + * + * @param model - the model of given resource such as AST + * @param resource - the resource to process + * @param monitor - the progress monitor + */ + public static void runInEditor(Object model, IResource resource, IProgressMonitor monitor) { + CodanRunner.processResource(resource, monitor, model, CheckerLaunchMode.RUN_AS_YOU_TYPE); + } + + /** + * Runs all checkers on a given resource. + * + * @param resource - the resource to run the checkers on, either IFile or IContainer + * @param monitor - the progress monitor + * @param checkerLaunchMode - the checker launch mode. + */ + public static void processResource(IResource resource, IProgressMonitor monitor, + CheckerLaunchMode checkerLaunchMode) { + processResource(resource, monitor, null, checkerLaunchMode); + } + + private static void processResource(IResource resource, IProgressMonitor monitor, Object model, + CheckerLaunchMode checkerLaunchMode) { + CheckersRegistry chegistry = CheckersRegistry.getInstance(); + int checkers = chegistry.getCheckersSize(); + int memsize = 0; + if (resource instanceof IContainer) { + try { + IResource[] members = ((IContainer) resource).members(); + memsize = members.length; + } catch (CoreException e) { + CodanCorePlugin.log(e); + } + } + int tick = 1000; + // System.err.println("processing " + resource); + monitor.beginTask(NLS.bind(Messages.CodanRunner_Code_Analysis_On, resource.getFullPath().toString()), + checkers + memsize * tick); + try { + CheckersTimeStats.getInstance().checkerStart(CheckersTimeStats.ALL); + ICheckerInvocationContext context = new CheckerInvocationContext(resource); + try { + for (IChecker checker : chegistry) { + try { + if (monitor.isCanceled()) + return; + if (chegistry.isCheckerEnabled(checker, resource, checkerLaunchMode)) { + synchronized (checker) { + try { + checker.before(resource); + CheckersTimeStats.getInstance().checkerStart(checker.getClass().getName()); + if (checkerLaunchMode == CheckerLaunchMode.RUN_AS_YOU_TYPE) { + ((IRunnableInEditorChecker) checker).processModel(model, context); + } else { + checker.processResource(resource, context); + } + } finally { + CheckersTimeStats.getInstance().checkerStop(checker.getClass().getName()); + checker.after(resource); + } + } + } + monitor.worked(1); + } catch (OperationCanceledException e) { + return; + } catch (Throwable e) { + CodanCorePlugin.log(e); + } + } + } finally { + context.dispose(); + CheckersTimeStats.getInstance().checkerStop(CheckersTimeStats.ALL); + //CheckersTimeStats.getInstance().printStats(); + } + + if (resource instanceof IContainer + && (checkerLaunchMode == CheckerLaunchMode.RUN_ON_FULL_BUILD || checkerLaunchMode == CheckerLaunchMode.RUN_ON_DEMAND)) { + try { + IResource[] members = ((IContainer) resource).members(); + for (int i = 0; i < members.length; i++) { + if (monitor.isCanceled()) + return; + IResource member = members[i]; + processResource(member, new SubProgressMonitor(monitor, tick), null, checkerLaunchMode); + } + } catch (CoreException e) { + CodanCorePlugin.log(e); + } + } + } finally { + monitor.done(); + } + } +} diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/Messages.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/Messages.java similarity index 70% rename from codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/Messages.java rename to codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/Messages.java index 2e46b4f5dc6..755e06d2cca 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/Messages.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/Messages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 Alena Laskavaia and others. + * Copyright (c) 2009, 2012 Alena Laskavaia and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,15 +8,16 @@ * Contributors: * Alena Laskavaia - initial API and implementation * IBM Corporation + * Sergey Prigogin (Google) *******************************************************************************/ -package org.eclipse.cdt.codan.core; +package org.eclipse.cdt.codan.internal.core; import org.eclipse.osgi.util.NLS; /** * Core Messages */ -public class Messages extends NLS { +class Messages extends NLS { public static String CodanApplication_all_option; public static String CodanApplication_Error_ProjectDoesNotExists; public static String CodanApplication_LogRunProject; @@ -24,20 +25,7 @@ public class Messages extends NLS { public static String CodanApplication_Options; public static String CodanApplication_Usage; public static String CodanApplication_verbose_option; - public static String CodanBuilder_Code_Analysis_On; - /** - * @since 2.0 - */ - public static String CodanSeverity_Error; - /** - * @since 2.0 - */ - public static String CodanSeverity_Info; - /** - * @since 2.0 - */ - public static String CodanSeverity_Warning; - public static String FileScopeProblemPreference_Label; + public static String CodanRunner_Code_Analysis_On; static { NLS.initializeMessages(Messages.class.getName(), Messages.class); diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/Messages.properties b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/Messages.properties similarity index 84% rename from codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/Messages.properties rename to codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/Messages.properties index cc76a9dd941..5b81389a957 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/Messages.properties +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/Messages.properties @@ -8,6 +8,7 @@ # Contributors: # Alena Laskavaia - initial API and implementation # IBM Corporation +# Sergey Prigogin (Google) ############################################################################### CodanApplication_Error_ProjectDoesNotExists=Error: project {0} does not exist CodanApplication_LogRunProject=Running code analysis on project @@ -16,8 +17,4 @@ CodanApplication_Usage=Usage: [options] ... CodanApplication_Options=Options: CodanApplication_all_option= -all - run on all projects in workspace CodanApplication_verbose_option= -verbose - print verbose build information -CodanBuilder_Code_Analysis_On=Code analysis on -CodanSeverity_Error=Error -CodanSeverity_Info=Info -CodanSeverity_Warning=Warning -FileScopeProblemPreference_Label=Exclusion and Inclusion +CodanRunner_Code_Analysis_On=Code analysis on {0} diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/ProblemProfile.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/ProblemProfile.java index e1e63830d69..bec13249e65 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/ProblemProfile.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/ProblemProfile.java @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.cdt.codan.internal.core.model; +import java.util.ArrayList; +import java.util.Collection; + import org.eclipse.cdt.codan.core.model.IProblem; import org.eclipse.cdt.codan.core.model.IProblemCategory; import org.eclipse.cdt.codan.core.model.IProblemProfile; @@ -19,15 +22,13 @@ import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.ListenerList; import org.eclipse.core.runtime.SafeRunner; -import java.util.ArrayList; -import java.util.Collection; - /** * @author Alena */ public class ProblemProfile implements IProblemProfile, Cloneable { private CodanProblemCategory rootCategory; private Object resource; + private ListenerList preferenceChangeListeners; /** * @param resource @@ -106,7 +107,6 @@ public class ProblemProfile implements IProblemProfile, Cloneable { public IProblemCategory getParentCategory() { return getRoot(); } - private ListenerList preferenceChangeListeners; @Override public void addProfileChangeListener(IProblemProfileChangeListener listener) { @@ -120,7 +120,7 @@ public class ProblemProfile implements IProblemProfile, Cloneable { if (preferenceChangeListeners == null) return; preferenceChangeListeners.remove(listener); - if (preferenceChangeListeners.size() == 0) + if (preferenceChangeListeners.isEmpty()) preferenceChangeListeners = null; } diff --git a/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/Startup.java b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/Startup.java index 5755b01010e..f89c7024440 100644 --- a/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/Startup.java +++ b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/Startup.java @@ -12,15 +12,13 @@ *******************************************************************************/ package org.eclipse.cdt.codan.internal.ui.cxx; -import org.eclipse.cdt.codan.core.CodanRuntime; import org.eclipse.cdt.codan.core.model.CheckerLaunchMode; -import org.eclipse.cdt.codan.internal.core.CodanBuilder; +import org.eclipse.cdt.codan.internal.core.CodanRunner; import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.ui.ICEditor; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.osgi.util.NLS; @@ -38,8 +36,6 @@ import org.eclipse.ui.PlatformUI; * @author Alena Laskavaia */ public class Startup implements IStartup { - private static final IProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor(); - @Override public void earlyStartup() { registerListeners(); @@ -86,13 +82,12 @@ public class Startup implements IStartup { } } } - + private void processResource(final IResource resource) { Job job = new Job(NLS.bind(Messages.Startup_AnalyzingFile, resource.getName())) { @Override protected IStatus run(IProgressMonitor monitor) { - CodanBuilder builder = (CodanBuilder) CodanRuntime.getInstance().getBuilder(); - builder.processResource(resource, NULL_PROGRESS_MONITOR, CheckerLaunchMode.RUN_ON_FILE_OPEN); + CodanRunner.processResource(resource, monitor, CheckerLaunchMode.RUN_ON_FILE_OPEN); return Status.OK_STATUS; } }; diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java index b8ba26fedc9..60f6ddfeb1d 100644 --- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java +++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java @@ -11,6 +11,9 @@ *******************************************************************************/ package org.eclipse.cdt.codan.internal.ui.preferences; +import java.util.ArrayList; +import java.util.Iterator; + import org.eclipse.cdt.codan.core.CodanCorePlugin; import org.eclipse.cdt.codan.core.CodanRuntime; import org.eclipse.cdt.codan.core.model.ICheckersRegistry; @@ -41,17 +44,15 @@ import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.preferences.ScopedPreferenceStore; -import java.util.ArrayList; -import java.util.Iterator; - /** - * This class represents a preference page that is contributed to the Preferences dialog. By - * subclassing {@code FieldEditorPreferencePage}, we can use built-in field support in JFace to - * create a page that is both small and knows how to save, restore and apply its values. + * This class represents a preference page that is contributed to the Preferences dialog. + * By subclassing {@code FieldEditorPreferencePage}, we can use built-in field support in + * JFace to create a page that is both small and knows how to save, restore and apply its + * values. *

- * This page is used to modify preferences only. They are stored in the preference store that - * belongs to the main plug-in class. That way, preferences can be accessed directly via the - * preference store. + * This page is used to modify preferences only. They are stored in the preference store that + * belongs to the main plug-in class. That way, preferences can be accessed directly via + * the preference store. *

*/ public class CodanPreferencePage extends FieldEditorOverlayPage implements IWorkbenchPreferencePage { @@ -89,8 +90,10 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements IWork } /** - * Creates the field editors. Field editors are abstractions of the common GUI blocks needed to - * manipulate various types of preferences. Each field editor knows how to save and restore + * Creates the field editors. Field editors are abstractions of the common + * GUI blocks needed to + * manipulate various types of preferences. Each field editor knows how to + * save and restore * its own value. */ @Override @@ -156,13 +159,13 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements IWork } private void saveWidgetValues() { - String id = (!hasSelectedProblems()) ? EMPTY_STRING : selectedProblems.get(0).getId(); + String id = !hasSelectedProblems() ? EMPTY_STRING : selectedProblems.get(0).getId(); getDialogSettings().put(getWidgetId(), id); } private void restoreWidgetValues() { String id = getDialogSettings().get(getWidgetId()); - if (id != null && id.length() > 0 && checkedTreeEditor != null) { + if (id != null && !id.isEmpty() && checkedTreeEditor != null) { IProblem problem = profile.findProblem(id); if (problem != null) { checkedTreeEditor.getTreeViewer().setSelection(new StructuredSelection(problem), true); @@ -194,12 +197,11 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements IWork return; } IProblem[] selected = selectedProblems.toArray(new IProblem[selectedProblems.size()]); - CustomizeProblemDialog dialog = - new CustomizeProblemDialog(getShell(), selected, (IResource) getElement()); + CustomizeProblemDialog dialog = new CustomizeProblemDialog(getShell(), selected, (IResource) getElement()); dialog.open(); checkedTreeEditor.getTreeViewer().refresh(true); } - + private boolean hasSelectedProblems() { return selectedProblems != null && !selectedProblems.isEmpty(); } diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FieldEditorOverlayPage.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FieldEditorOverlayPage.java index d498be65f88..39b860b7167 100644 --- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FieldEditorOverlayPage.java +++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FieldEditorOverlayPage.java @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.cdt.codan.internal.ui.preferences; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.cdt.codan.core.CodanCorePlugin; import org.eclipse.cdt.codan.core.PreferenceConstants; import org.eclipse.cdt.codan.internal.ui.CodanUIActivator; @@ -40,9 +43,6 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.ui.IWorkbenchPropertyPage; import org.eclipse.ui.preferences.ScopedPreferenceStore; -import java.util.ArrayList; -import java.util.List; - /** * @author Berthold Daum */ @@ -269,7 +269,7 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage i return super.getPreferenceStore(); } - /* + /** * Enables or disables the field editors and buttons of this page */ private void updateFieldEditors() { @@ -293,8 +293,8 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage i } /** - * We override the performOk method. In case of property pages we copy the - * values in the overlay store into the property values of the selected + * We override the performOk method. In case of property pages we copy + * the values in the overlay store into the property values of the selected * project. We also save the state of the radio buttons. * * @see org.eclipse.jface.preference.IPreferencePage#performOk()