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

Moved execution of checkers from CodanBuilder to CodanRunner.

This commit is contained in:
Sergey Prigogin 2012-04-29 19:12:28 -07:00
parent d40474476a
commit 4c3a5dd669
18 changed files with 289 additions and 176 deletions

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * 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; package org.eclipse.cdt.codan.core.cxx.internal.model;
import org.eclipse.cdt.codan.core.CodanRuntime; import org.eclipse.cdt.codan.internal.core.CodanRunner;
import org.eclipse.cdt.codan.internal.core.CodanBuilder;
import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CProjectNature; import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
@ -22,10 +22,8 @@ import org.eclipse.core.runtime.IProgressMonitor;
/** /**
* @author Alena * @author Alena
*
*/ */
public class CxxCodanReconciler { public class CxxCodanReconciler {
private CodanBuilder builder = (CodanBuilder) CodanRuntime.getInstance().getBuilder();
public void reconciledAst(IASTTranslationUnit ast, IResource resource, IProgressMonitor monitor) { public void reconciledAst(IASTTranslationUnit ast, IResource resource, IProgressMonitor monitor) {
if (ast == null) if (ast == null)
@ -35,7 +33,7 @@ public class CxxCodanReconciler {
return; return;
try { try {
if (project.hasNature(CProjectNature.C_NATURE_ID) || project.hasNature(CCProjectNature.CC_NATURE_ID)) { 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) { } catch (CoreException e) {
// ignore // ignore

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.cdt.codan.core" version="2">
<resource path="META-INF/MANIFEST.MF" type="org.eclipse.cdt.codan.core.Messages">
<filter id="305324134">
<message_arguments>
<message_argument value="org.eclipse.cdt.codan.core.Messages"/>
<message_argument value="org.eclipse.cdt.codan.core_2.1.0"/>
</message_arguments>
</filter>
</resource>
</component>

View file

@ -10,7 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.codan.core; 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.IStatus;
import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
@ -28,7 +28,7 @@ public class CodanCorePlugin extends Plugin {
* The nature used to run Codan builder. * The nature used to run Codan builder.
* @noreference This constant is not intended to be referenced by clients. * @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 // The shared instance
private static CodanCorePlugin plugin; private static CodanCorePlugin plugin;

View file

@ -11,11 +11,9 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.codan.core.model; package org.eclipse.cdt.codan.core.model;
import org.eclipse.cdt.codan.core.Messages;
import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IMarker;
/** /**
*
* Represents Severity of the codan problem. It is directly mapped to markers * Represents Severity of the codan problem. It is directly mapped to markers
* severity. * severity.
* *
@ -33,6 +31,7 @@ public enum CodanSeverity {
* Error severity * Error severity
*/ */
Error(IMarker.SEVERITY_ERROR); Error(IMarker.SEVERITY_ERROR);
private int value; private int value;
private CodanSeverity(int value) { private CodanSeverity(int value) {

View file

@ -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() {
}
}

View file

@ -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

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * 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; 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.cdt.codan.internal.core.CharOperation;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; 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.IPath;
import org.eclipse.core.runtime.Path; 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 * Custom preference for resource scope
* *
@ -45,6 +44,7 @@ public class FileScopeProblemPreference extends AbstractProblemPreference {
* Inclusion attribute * Inclusion attribute
*/ */
public static final String INCLUSION = "inclusion"; //$NON-NLS-1$ public static final String INCLUSION = "inclusion"; //$NON-NLS-1$
private IResource resource; private IResource resource;
private IPath[] inclusion = new IPath[0]; private IPath[] inclusion = new IPath[0];
private IPath[] exclusion = new IPath[0]; private IPath[] exclusion = new IPath[0];

View file

@ -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() {
}
}

View file

@ -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

View file

@ -14,7 +14,6 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import org.eclipse.cdt.codan.core.CodanRuntime; 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.AbstractProblemReporter;
import org.eclipse.cdt.codan.core.model.ICodanProblemMarker; import org.eclipse.cdt.codan.core.model.ICodanProblemMarker;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
@ -34,8 +33,8 @@ import org.eclipse.osgi.util.NLS;
*/ */
public class CodanApplication implements IApplication { public class CodanApplication implements IApplication {
private Collection<String> projects = new ArrayList<String>(); private Collection<String> projects = new ArrayList<String>();
private boolean verbose = false; private boolean verbose;
private boolean all = false; private boolean all;
@Override @Override
public Object start(IApplicationContext context) throws Exception { public Object start(IApplicationContext context) throws Exception {

View file

@ -13,14 +13,8 @@ package org.eclipse.cdt.codan.internal.core;
import java.util.Map; 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.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.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.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta; 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.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.SubProgressMonitor;
/** /**
* Implementation of {@link ICodanBuilder} * Implementation of {@link ICodanBuilder}
@ -86,7 +78,7 @@ public class CodanBuilder extends IncrementalProjectBuilder implements ICodanBui
@Override @Override
public void processResource(IResource resource, IProgressMonitor monitor) { 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 @Override
public void processResource(IResource resource, IProgressMonitor monitor, CheckerLaunchMode mode) { 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) { private void processResourceDelta(IResource resource, IProgressMonitor monitor) {
processResource(resource, monitor, CheckerLaunchMode.RUN_ON_INC_BUILD); 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 { protected void fullBuild(final IProgressMonitor monitor) throws CoreException {
processResource(getProject(), monitor); processResource(getProject(), monitor);
} }
@ -185,17 +106,4 @@ public class CodanBuilder extends IncrementalProjectBuilder implements ICodanBui
// The visitor does the work. // The visitor does the work.
delta.accept(new CodanDeltaVisitor(monitor)); 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);
}
} }

View file

@ -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();
}
}
}

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -8,15 +8,16 @@
* Contributors: * Contributors:
* Alena Laskavaia - initial API and implementation * Alena Laskavaia - initial API and implementation
* IBM Corporation * IBM Corporation
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.codan.core; package org.eclipse.cdt.codan.internal.core;
import org.eclipse.osgi.util.NLS; import org.eclipse.osgi.util.NLS;
/** /**
* Core Messages * Core Messages
*/ */
public class Messages extends NLS { class Messages extends NLS {
public static String CodanApplication_all_option; public static String CodanApplication_all_option;
public static String CodanApplication_Error_ProjectDoesNotExists; public static String CodanApplication_Error_ProjectDoesNotExists;
public static String CodanApplication_LogRunProject; public static String CodanApplication_LogRunProject;
@ -24,20 +25,7 @@ public class Messages extends NLS {
public static String CodanApplication_Options; public static String CodanApplication_Options;
public static String CodanApplication_Usage; public static String CodanApplication_Usage;
public static String CodanApplication_verbose_option; public static String CodanApplication_verbose_option;
public static String CodanBuilder_Code_Analysis_On; public static String CodanRunner_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;
static { static {
NLS.initializeMessages(Messages.class.getName(), Messages.class); NLS.initializeMessages(Messages.class.getName(), Messages.class);

View file

@ -8,6 +8,7 @@
# Contributors: # Contributors:
# Alena Laskavaia - initial API and implementation # Alena Laskavaia - initial API and implementation
# IBM Corporation # IBM Corporation
# Sergey Prigogin (Google)
############################################################################### ###############################################################################
CodanApplication_Error_ProjectDoesNotExists=Error: project {0} does not exist CodanApplication_Error_ProjectDoesNotExists=Error: project {0} does not exist
CodanApplication_LogRunProject=Running code analysis on project CodanApplication_LogRunProject=Running code analysis on project
@ -16,8 +17,4 @@ CodanApplication_Usage=Usage: [options] <project1> <project2> ...
CodanApplication_Options=Options: CodanApplication_Options=Options:
CodanApplication_all_option= -all - run on all projects in workspace CodanApplication_all_option= -all - run on all projects in workspace
CodanApplication_verbose_option= -verbose - print verbose build information CodanApplication_verbose_option= -verbose - print verbose build information
CodanBuilder_Code_Analysis_On=Code analysis on CodanRunner_Code_Analysis_On=Code analysis on {0}
CodanSeverity_Error=Error
CodanSeverity_Info=Info
CodanSeverity_Warning=Warning
FileScopeProblemPreference_Label=Exclusion and Inclusion

View file

@ -10,6 +10,9 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.codan.internal.core.model; 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.IProblem;
import org.eclipse.cdt.codan.core.model.IProblemCategory; import org.eclipse.cdt.codan.core.model.IProblemCategory;
import org.eclipse.cdt.codan.core.model.IProblemProfile; 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.ListenerList;
import org.eclipse.core.runtime.SafeRunner; import org.eclipse.core.runtime.SafeRunner;
import java.util.ArrayList;
import java.util.Collection;
/** /**
* @author Alena * @author Alena
*/ */
public class ProblemProfile implements IProblemProfile, Cloneable { public class ProblemProfile implements IProblemProfile, Cloneable {
private CodanProblemCategory rootCategory; private CodanProblemCategory rootCategory;
private Object resource; private Object resource;
private ListenerList preferenceChangeListeners;
/** /**
* @param resource * @param resource
@ -106,7 +107,6 @@ public class ProblemProfile implements IProblemProfile, Cloneable {
public IProblemCategory getParentCategory() { public IProblemCategory getParentCategory() {
return getRoot(); return getRoot();
} }
private ListenerList preferenceChangeListeners;
@Override @Override
public void addProfileChangeListener(IProblemProfileChangeListener listener) { public void addProfileChangeListener(IProblemProfileChangeListener listener) {
@ -120,7 +120,7 @@ public class ProblemProfile implements IProblemProfile, Cloneable {
if (preferenceChangeListeners == null) if (preferenceChangeListeners == null)
return; return;
preferenceChangeListeners.remove(listener); preferenceChangeListeners.remove(listener);
if (preferenceChangeListeners.size() == 0) if (preferenceChangeListeners.isEmpty())
preferenceChangeListeners = null; preferenceChangeListeners = null;
} }

View file

@ -12,15 +12,13 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.codan.internal.ui.cxx; 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.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.internal.ui.editor.CEditor;
import org.eclipse.cdt.ui.ICEditor; import org.eclipse.cdt.ui.ICEditor;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.osgi.util.NLS; import org.eclipse.osgi.util.NLS;
@ -38,8 +36,6 @@ import org.eclipse.ui.PlatformUI;
* @author Alena Laskavaia * @author Alena Laskavaia
*/ */
public class Startup implements IStartup { public class Startup implements IStartup {
private static final IProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor();
@Override @Override
public void earlyStartup() { public void earlyStartup() {
registerListeners(); registerListeners();
@ -91,8 +87,7 @@ public class Startup implements IStartup {
Job job = new Job(NLS.bind(Messages.Startup_AnalyzingFile, resource.getName())) { Job job = new Job(NLS.bind(Messages.Startup_AnalyzingFile, resource.getName())) {
@Override @Override
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {
CodanBuilder builder = (CodanBuilder) CodanRuntime.getInstance().getBuilder(); CodanRunner.processResource(resource, monitor, CheckerLaunchMode.RUN_ON_FILE_OPEN);
builder.processResource(resource, NULL_PROGRESS_MONITOR, CheckerLaunchMode.RUN_ON_FILE_OPEN);
return Status.OK_STATUS; return Status.OK_STATUS;
} }
}; };

View file

@ -11,6 +11,9 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.codan.internal.ui.preferences; 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.CodanCorePlugin;
import org.eclipse.cdt.codan.core.CodanRuntime; import org.eclipse.cdt.codan.core.CodanRuntime;
import org.eclipse.cdt.codan.core.model.ICheckersRegistry; 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.IWorkbenchPreferencePage;
import org.eclipse.ui.preferences.ScopedPreferenceStore; 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 * This class represents a preference page that is contributed to the Preferences dialog.
* subclassing {@code FieldEditorPreferencePage}, we can use built-in field support in JFace to * By subclassing {@code FieldEditorPreferencePage}, we can use built-in field support in
* create a page that is both small and knows how to save, restore and apply its values. * JFace to create a page that is both small and knows how to save, restore and apply its
* values.
* <p> * <p>
* This page is used to modify preferences only. They are stored in the preference store that * 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 * belongs to the main plug-in class. That way, preferences can be accessed directly via
* preference store. * the preference store.
* </p> * </p>
*/ */
public class CodanPreferencePage extends FieldEditorOverlayPage implements IWorkbenchPreferencePage { 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 * Creates the field editors. Field editors are abstractions of the common
* manipulate various types of preferences. Each field editor knows how to save and restore * GUI blocks needed to
* manipulate various types of preferences. Each field editor knows how to
* save and restore
* its own value. * its own value.
*/ */
@Override @Override
@ -156,13 +159,13 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements IWork
} }
private void saveWidgetValues() { 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); getDialogSettings().put(getWidgetId(), id);
} }
private void restoreWidgetValues() { private void restoreWidgetValues() {
String id = getDialogSettings().get(getWidgetId()); 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); IProblem problem = profile.findProblem(id);
if (problem != null) { if (problem != null) {
checkedTreeEditor.getTreeViewer().setSelection(new StructuredSelection(problem), true); checkedTreeEditor.getTreeViewer().setSelection(new StructuredSelection(problem), true);
@ -194,8 +197,7 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements IWork
return; return;
} }
IProblem[] selected = selectedProblems.toArray(new IProblem[selectedProblems.size()]); IProblem[] selected = selectedProblems.toArray(new IProblem[selectedProblems.size()]);
CustomizeProblemDialog dialog = CustomizeProblemDialog dialog = new CustomizeProblemDialog(getShell(), selected, (IResource) getElement());
new CustomizeProblemDialog(getShell(), selected, (IResource) getElement());
dialog.open(); dialog.open();
checkedTreeEditor.getTreeViewer().refresh(true); checkedTreeEditor.getTreeViewer().refresh(true);
} }

View file

@ -10,6 +10,9 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.codan.internal.ui.preferences; 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.CodanCorePlugin;
import org.eclipse.cdt.codan.core.PreferenceConstants; import org.eclipse.cdt.codan.core.PreferenceConstants;
import org.eclipse.cdt.codan.internal.ui.CodanUIActivator; 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.IWorkbenchPropertyPage;
import org.eclipse.ui.preferences.ScopedPreferenceStore; import org.eclipse.ui.preferences.ScopedPreferenceStore;
import java.util.ArrayList;
import java.util.List;
/** /**
* @author Berthold Daum * @author Berthold Daum
*/ */
@ -269,7 +269,7 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage i
return super.getPreferenceStore(); return super.getPreferenceStore();
} }
/* /**
* Enables or disables the field editors and buttons of this page * Enables or disables the field editors and buttons of this page
*/ */
private void updateFieldEditors() { 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 * We override the performOk method. In case of property pages we copy
* values in the overlay store into the property values of the selected * the values in the overlay store into the property values of the selected
* project. We also save the state of the radio buttons. * project. We also save the state of the radio buttons.
* *
* @see org.eclipse.jface.preference.IPreferencePage#performOk() * @see org.eclipse.jface.preference.IPreferencePage#performOk()