1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 06:02:11 +02:00

Don't run checkers on UI thread.

This commit is contained in:
Sergey Prigogin 2012-04-28 17:59:34 -07:00
parent 5a643e5e57
commit c554c4e707
4 changed files with 70 additions and 12 deletions

View file

@ -66,7 +66,7 @@ public class Activator extends AbstractUIPlugin {
* @param e the exception to be logged
*/
public static void log(Throwable e) {
log(new Status(IStatus.ERROR, PLUGIN_ID, 1, "Internal Error", e)); //$NON-NLS-1$
log(new Status(IStatus.ERROR, PLUGIN_ID, 1, Messages.Activatior_Error, e));
}
/**

View file

@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2012 Google, Inc 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:
* Sergey Prigogin (Google) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.codan.internal.ui.cxx;
import org.eclipse.osgi.util.NLS;
class Messages extends NLS {
public static String Activatior_Error;
public static String Startup_AnalyzingFile;
static {
// Initialize resource bundle
NLS.initializeMessages(Messages.class.getName(), Messages.class);
}
private Messages() {
}
}

View file

@ -0,0 +1,12 @@
###############################################################################
# Copyright (c) 2012 Google, Inc 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:
# Sergey Prigogin (Google) - initial API and implementation
###############################################################################
Activatior_InternalError=Error
Startup_AnalyzingFile=Analizing ''{0}''

View file

@ -1,12 +1,14 @@
/*******************************************************************************
* 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
* Alex Ruiz (Google)
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.codan.internal.ui.cxx;
@ -16,7 +18,11 @@ import org.eclipse.cdt.codan.internal.core.CodanBuilder;
import org.eclipse.cdt.internal.ui.editor.CEditor;
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;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IPartListener2;
import org.eclipse.ui.IStartup;
@ -33,11 +39,7 @@ import org.eclipse.ui.PlatformUI;
public class Startup implements IStartup {
private static final IProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor();
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IStartup#earlyStartup()
*/
@Override
public void earlyStartup() {
registerListeners();
}
@ -48,18 +50,22 @@ public class Startup implements IStartup {
private void registerListeners() {
final IWorkbench workbench = PlatformUI.getWorkbench();
workbench.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
IWorkbenchWindow active = workbench.getActiveWorkbenchWindow();
final IWorkbenchPage page = active.getActivePage();
IPartListener2 partListener = new IPartListener2() {
CodanCReconciler reconciler = new CodanCReconciler();
@Override
public void partActivated(IWorkbenchPartReference partRef) {
}
@Override
public void partDeactivated(IWorkbenchPartReference partRef) {
}
@Override
public void partOpened(IWorkbenchPartReference partRef) {
IWorkbenchPart part = partRef.getPart(false);
if (part instanceof CEditor) {
@ -72,17 +78,29 @@ public class Startup implements IStartup {
}
}
private void processResource(IResource resource) {
CodanBuilder builder = (CodanBuilder) CodanRuntime.getInstance().getBuilder();
builder.processResource(resource, NULL_PROGRESS_MONITOR, CheckerLaunchMode.RUN_ON_FILE_OPEN);
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);
return Status.OK_STATUS;
}
};
job.setRule(resource);
job.setSystem(true);
job.schedule();
}
@Override
public void partHidden(IWorkbenchPartReference partRef) {
}
@Override
public void partVisible(IWorkbenchPartReference partRef) {
}
@Override
public void partClosed(IWorkbenchPartReference partRef) {
IWorkbenchPart part = partRef.getPart(false);
if (part instanceof CEditor) {
@ -90,14 +108,16 @@ public class Startup implements IStartup {
}
}
@Override
public void partBroughtToTop(IWorkbenchPartReference partRef) {
}
@Override
public void partInputChanged(IWorkbenchPartReference partRef) {
}
};
page.addPartListener(partListener);
// check current open editors
// Check current open editors.
IEditorReference[] editorReferences = page.getEditorReferences();
for (int i = 0; i < editorReferences.length; i++) {
IEditorReference ref = editorReferences[i];