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 237308dfd68..5755b01010e 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 @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * 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.internal.core.CodanBuilder; 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; @@ -55,7 +56,7 @@ public class Startup implements IStartup { IWorkbenchWindow active = workbench.getActiveWorkbenchWindow(); final IWorkbenchPage page = active.getActivePage(); IPartListener2 partListener = new IPartListener2() { - CodanCReconciler reconciler = new CodanCReconciler(); + CodanCReconciler reconciler; @Override public void partActivated(IWorkbenchPartReference partRef) { @@ -68,8 +69,16 @@ public class Startup implements IStartup { @Override public void partOpened(IWorkbenchPartReference partRef) { 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; + if (reconciler == null) { + reconciler = new CodanCReconciler(); + } reconciler.install(editor); IResource resource = (IResource) editor.getEditorInput().getAdapter(IResource.class); if (resource != null) { @@ -103,7 +112,7 @@ public class Startup implements IStartup { @Override public void partClosed(IWorkbenchPartReference partRef) { IWorkbenchPart part = partRef.getPart(false); - if (part instanceof CEditor) { + if (reconciler != null && part instanceof ICEditor && part instanceof CEditor) { reconciler.uninstall((CEditor) part); } } @@ -116,11 +125,11 @@ public class Startup implements IStartup { public void partInputChanged(IWorkbenchPartReference partRef) { } }; + page.addPartListener(partListener); // Check current open editors. IEditorReference[] editorReferences = page.getEditorReferences(); - for (int i = 0; i < editorReferences.length; i++) { - IEditorReference ref = editorReferences[i]; + for (IEditorReference ref : editorReferences) { partListener.partOpened(ref); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java index cd4398c3813..4057e70b58c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java @@ -188,6 +188,7 @@ import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.ICEditor; import org.eclipse.cdt.ui.IWorkingCopyManager; import org.eclipse.cdt.ui.PreferenceConstants; import org.eclipse.cdt.ui.actions.GenerateActionGroup; @@ -241,9 +242,9 @@ import org.eclipse.cdt.internal.ui.viewsupport.SelectionListenerWithASTManager; /** * 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. */ - private IMarker fSyncProblemsViewMarker = null; + private IMarker fSyncProblemsViewMarker; /** * A slightly modified implementation of IGotomarker compared to AbstractDecoratedTextEditor. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/ICEditor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/ICEditor.java new file mode 100644 index 00000000000..ddda03cdc2e --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/ICEditor.java @@ -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 { +}