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

Prevented class loading avalanche on UI thread when CDT is installed but

is not actively used.
This commit is contained in:
Sergey Prigogin 2012-04-28 23:19:40 -07:00
parent c8e3a663f0
commit b136bb95d0
3 changed files with 38 additions and 8 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009, 2012 Alena Laskavaia * 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
@ -16,6 +16,7 @@ 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.CodanBuilder;
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.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;
@ -55,7 +56,7 @@ public class Startup implements IStartup {
IWorkbenchWindow active = workbench.getActiveWorkbenchWindow(); IWorkbenchWindow active = workbench.getActiveWorkbenchWindow();
final IWorkbenchPage page = active.getActivePage(); final IWorkbenchPage page = active.getActivePage();
IPartListener2 partListener = new IPartListener2() { IPartListener2 partListener = new IPartListener2() {
CodanCReconciler reconciler = new CodanCReconciler(); CodanCReconciler reconciler;
@Override @Override
public void partActivated(IWorkbenchPartReference partRef) { public void partActivated(IWorkbenchPartReference partRef) {
@ -68,8 +69,16 @@ public class Startup implements IStartup {
@Override @Override
public void partOpened(IWorkbenchPartReference partRef) { public void partOpened(IWorkbenchPartReference partRef) {
IWorkbenchPart part = partRef.getPart(false); IWorkbenchPart part = partRef.getPart(false);
if (part instanceof CEditor) { // We need to be very careful since this code may be executed in
// an invironement where CDT is installed, but is not actively used.
// By checking for ICEditor first we avoid loading CEditor class if
// the part is not a C/C++ editor. Loading of CEditor class can be very
// expensive since it triggers loading of many other classes.
if (part instanceof ICEditor && part instanceof CEditor) {
CEditor editor = (CEditor) part; CEditor editor = (CEditor) part;
if (reconciler == null) {
reconciler = new CodanCReconciler();
}
reconciler.install(editor); reconciler.install(editor);
IResource resource = (IResource) editor.getEditorInput().getAdapter(IResource.class); IResource resource = (IResource) editor.getEditorInput().getAdapter(IResource.class);
if (resource != null) { if (resource != null) {
@ -103,7 +112,7 @@ public class Startup implements IStartup {
@Override @Override
public void partClosed(IWorkbenchPartReference partRef) { public void partClosed(IWorkbenchPartReference partRef) {
IWorkbenchPart part = partRef.getPart(false); IWorkbenchPart part = partRef.getPart(false);
if (part instanceof CEditor) { if (reconciler != null && part instanceof ICEditor && part instanceof CEditor) {
reconciler.uninstall((CEditor) part); reconciler.uninstall((CEditor) part);
} }
} }
@ -116,11 +125,11 @@ public class Startup implements IStartup {
public void partInputChanged(IWorkbenchPartReference partRef) { public void partInputChanged(IWorkbenchPartReference partRef) {
} }
}; };
page.addPartListener(partListener); page.addPartListener(partListener);
// Check current open editors. // Check current open editors.
IEditorReference[] editorReferences = page.getEditorReferences(); IEditorReference[] editorReferences = page.getEditorReferences();
for (int i = 0; i < editorReferences.length; i++) { for (IEditorReference ref : editorReferences) {
IEditorReference ref = editorReferences[i];
partListener.partOpened(ref); partListener.partOpened(ref);
} }
} }

View file

@ -188,6 +188,7 @@ import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.ICEditor;
import org.eclipse.cdt.ui.IWorkingCopyManager; import org.eclipse.cdt.ui.IWorkingCopyManager;
import org.eclipse.cdt.ui.PreferenceConstants; import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.actions.GenerateActionGroup; import org.eclipse.cdt.ui.actions.GenerateActionGroup;
@ -241,9 +242,9 @@ import org.eclipse.cdt.internal.ui.viewsupport.SelectionListenerWithASTManager;
/** /**
* C/C++ source editor. * C/C++ source editor.
*/ */
public class CEditor extends TextEditor implements ISelectionChangedListener, ICReconcilingListener { public class CEditor extends TextEditor implements ICEditor, ISelectionChangedListener, ICReconcilingListener {
/** Marker used for synchronization from Problems View to the editor on double-click. */ /** Marker used for synchronization from Problems View to the editor on double-click. */
private IMarker fSyncProblemsViewMarker = null; private IMarker fSyncProblemsViewMarker;
/** /**
* A slightly modified implementation of IGotomarker compared to AbstractDecoratedTextEditor. * A slightly modified implementation of IGotomarker compared to AbstractDecoratedTextEditor.

View file

@ -0,0 +1,20 @@
/*******************************************************************************
* Copyright (c) 2010 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.ui;
import org.eclipse.ui.texteditor.ITextEditor;
/**
* Marker interface that distinguishes C/C++ editor from other text editors.
* @since 5.4
*/
public interface ICEditor extends ITextEditor {
}