From d550905a0dff40d4b7ffe504dab604660e198fbb Mon Sep 17 00:00:00 2001
From: Markus Schorn
Date: Thu, 29 Oct 2009 09:02:48 +0000
Subject: [PATCH] Restoring non-API methods of ITranslationUnit, providing
public methods for accessing shared working copies, bug 293617.
---
.../cdt/core/model/ITranslationUnit.java | 35 ++++++++++++----
.../internal/core/model/TranslationUnit.java | 15 +++++++
.../ui/BaseCElementContentProvider.java | 6 +--
.../internal/ui/editor/CDocumentProvider.java | 6 +--
.../ui/editor/WorkingCopyManager.java | 41 ++++++++++++++++---
.../cdt/internal/ui/util/EditorUtility.java | 4 +-
.../src/org/eclipse/cdt/ui/CUIPlugin.java | 11 ++---
.../eclipse/cdt/ui/IWorkingCopyManager.java | 34 +++++++++++++--
8 files changed, 118 insertions(+), 34 deletions(-)
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java
index 37a0c7d825f..ddc48a6884b 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java
@@ -389,15 +389,6 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
*/
boolean isWorkingCopy();
- /**
- * parse()
- * returns a map of all new elements and their element info
- * @deprecated this is currently only used by the core tests. It should
- * be removed from the interface.
- */
- @Deprecated
- Map,?> parse();
-
/**
* Return the language for this translation unit.
*/
@@ -467,4 +458,30 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
* Return the completion node using the given index and parsing style at the given offset.
*/
public IASTCompletionNode getCompletionNode(IIndex index, int style, int offset) throws CoreException;
+
+
+ /**
+ * @deprecated use {@link #getSharedWorkingCopy(IProgressMonitor, IProblemRequestor)}, instead.
+ * @noreference This method is not intended to be referenced by clients.
+ */
+ @Deprecated IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor, IBufferFactory factory) throws CModelException;
+ /**
+ * @deprecated use {@link #getSharedWorkingCopy(IProgressMonitor, IProblemRequestor)}, instead.
+ * @noreference This method is not intended to be referenced by clients.
+ */
+ @Deprecated IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor, IBufferFactory factory, IProblemRequestor requestor) throws CModelException;
+ /**
+ * @deprecated use {@link #findSharedWorkingCopy()}, instead.
+ * @noreference This method is not intended to be referenced by clients.
+ */
+ @Deprecated IWorkingCopy findSharedWorkingCopy(IBufferFactory bufferFactory);
+ /**
+ * @deprecated use {@link #getWorkingCopy(IProgressMonitor)}, instead.
+ * @noreference This method is not intended to be referenced by clients.
+ */
+ @Deprecated IWorkingCopy getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory) throws CModelException;
+ /**
+ * @deprecated don't use this method.
+ */
+ @Deprecated Map,?> parse();
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java
index 8be182029ae..cffd0bb123b 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java
@@ -1110,4 +1110,19 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
public int getIndex() {
return 0;
}
+
+ @Deprecated
+ public IWorkingCopy findSharedWorkingCopy(IBufferFactory bufferFactory) {
+ return CModelManager.getDefault().findSharedWorkingCopy(bufferFactory, this);
+ }
+
+ @Deprecated
+ public IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor, IBufferFactory factory, IProblemRequestor requestor) throws CModelException {
+ return CModelManager.getDefault().getSharedWorkingCopy(factory, this, requestor, monitor);
+ }
+
+ @Deprecated
+ public IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor, IBufferFactory factory) throws CModelException {
+ return CModelManager.getDefault().getSharedWorkingCopy(factory, this, null, monitor);
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java
index 95c97490550..685a21da19a 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/BaseCElementContentProvider.java
@@ -45,12 +45,10 @@ import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
+import org.eclipse.cdt.ui.CDTUITools;
import org.eclipse.cdt.ui.CElementGrouping;
-import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.IncludesGrouping;
import org.eclipse.cdt.ui.NamespacesGrouping;
-
-import org.eclipse.cdt.internal.core.model.CModelManager;
/**
* A base content provider for C elements. It provides access to the
@@ -210,7 +208,7 @@ public class BaseCElementContentProvider implements ITreeContentProvider {
// if it is not already a working copy
if (!(element instanceof IWorkingCopy)){
// if it has a valid working copy
- IWorkingCopy copy = CModelManager.getDefault().findSharedWorkingCopy(CUIPlugin.getDefault().getBufferFactory(), tu);
+ IWorkingCopy copy = CDTUITools.getWorkingCopyManager().findSharedWorkingCopy(tu);
if (copy != null) {
tu = copy;
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java
index bf50c41c9a6..545f53efbbd 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CDocumentProvider.java
@@ -77,12 +77,11 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.IPersistableProblem;
import org.eclipse.cdt.core.parser.IProblem;
+import org.eclipse.cdt.ui.CDTUITools;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.text.ICPartitions;
-import org.eclipse.cdt.internal.core.model.CModelManager;
-import org.eclipse.cdt.internal.core.model.IBufferFactory;
import org.eclipse.cdt.internal.core.model.TranslationUnit;
import org.eclipse.cdt.internal.ui.text.IProblemRequestorExtension;
@@ -861,8 +860,7 @@ public class CDocumentProvider extends TextFileDocumentProvider {
setUpSynchronization(tuInfo);
IProblemRequestor requestor= tuInfo.fModel instanceof IProblemRequestor ? (IProblemRequestor) tuInfo.fModel : null;
- IBufferFactory factory = CUIPlugin.getDefault().getBufferFactory();
- tuInfo.fCopy = CModelManager.getDefault().getSharedWorkingCopy(factory, original, requestor, getProgressMonitor());
+ tuInfo.fCopy = CDTUITools.getWorkingCopyManager().getSharedWorkingCopy(original, requestor, getProgressMonitor());
if (tuInfo.fModel == null) {
IPath location = original.getLocation();
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/WorkingCopyManager.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/WorkingCopyManager.java
index 6a1e7c808fb..02623ac8e1f 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/WorkingCopyManager.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/WorkingCopyManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2009 IBM Corporation 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,19 +8,26 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-
package org.eclipse.cdt.internal.ui.editor;
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.ui.IEditorInput;
+
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.IProblemRequestor;
+import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.ui.IWorkingCopyManager;
import org.eclipse.cdt.ui.IWorkingCopyManagerExtension;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.ui.IEditorInput;
+
+import org.eclipse.cdt.internal.core.model.CModelManager;
+import org.eclipse.cdt.internal.core.model.IBufferFactory;
/**
@@ -32,6 +39,7 @@ public class WorkingCopyManager implements IWorkingCopyManager, IWorkingCopyMana
private CDocumentProvider fDocumentProvider;
private Map fMap;
private boolean fIsShuttingDown;
+ private IBufferFactory fBufferFactory;
/**
* Creates a new working copy manager that co-operates with the given
@@ -103,4 +111,27 @@ public class WorkingCopyManager implements IWorkingCopyManager, IWorkingCopyMana
if (fMap.isEmpty())
fMap= null;
}
+
+ public IBufferFactory getBufferFactory() {
+ if (fBufferFactory == null) {
+ synchronized (this) {
+ if (fBufferFactory == null)
+ fBufferFactory= new CustomBufferFactory();
+ }
+ }
+ return fBufferFactory;
+ }
+
+ public IWorkingCopy findSharedWorkingCopy(ITranslationUnit tu) {
+ return CModelManager.getDefault().findSharedWorkingCopy(getBufferFactory(), tu);
+ }
+
+ public IWorkingCopy[] getSharedWorkingCopies() {
+ return CModelManager.getDefault().getSharedWorkingCopies(getBufferFactory());
+ }
+
+ public IWorkingCopy getSharedWorkingCopy(ITranslationUnit original, IProblemRequestor requestor,
+ IProgressMonitor progressMonitor) throws CModelException {
+ return CModelManager.getDefault().getSharedWorkingCopy(getBufferFactory(), original, requestor, progressMonitor);
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java
index eb671f974fc..2f4a8ee2f46 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java
@@ -87,9 +87,9 @@ 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.core.resources.FileStorage;
+import org.eclipse.cdt.ui.CDTUITools;
import org.eclipse.cdt.ui.CUIPlugin;
-import org.eclipse.cdt.internal.core.model.CModelManager;
import org.eclipse.cdt.internal.core.resources.ResourceLookup;
import org.eclipse.cdt.internal.ui.ICStatusConstants;
@@ -542,7 +542,7 @@ public class EditorUtility {
if (cu.isWorkingCopy())
return cu;
- return CModelManager.getDefault().findSharedWorkingCopy(CUIPlugin.getDefault().getBufferFactory(), cu);
+ return CDTUITools.getWorkingCopyManager().findSharedWorkingCopy(cu);
}
/**
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java
index beb3af96bb8..b157c97fcb4 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java
@@ -73,7 +73,6 @@ import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.model.IWorkingCopyProvider;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTRewriteAnalyzer;
-import org.eclipse.cdt.internal.core.model.CModelManager;
import org.eclipse.cdt.internal.core.model.IBufferFactory;
import org.eclipse.cdt.internal.corext.template.c.CContextType;
import org.eclipse.cdt.internal.corext.template.c.CodeTemplateContextType;
@@ -88,7 +87,6 @@ import org.eclipse.cdt.internal.ui.ResourceAdapterFactory;
import org.eclipse.cdt.internal.ui.buildconsole.BuildConsoleManager;
import org.eclipse.cdt.internal.ui.editor.ASTProvider;
import org.eclipse.cdt.internal.ui.editor.CDocumentProvider;
-import org.eclipse.cdt.internal.ui.editor.CustomBufferFactory;
import org.eclipse.cdt.internal.ui.editor.WorkingCopyManager;
import org.eclipse.cdt.internal.ui.refactoring.CTextFileChangeFactory;
import org.eclipse.cdt.internal.ui.text.CTextTools;
@@ -246,15 +244,15 @@ public class CUIPlugin extends AbstractUIPlugin {
/**
* @noreference This method is not intended to be referenced by clients.
+ * @deprecated use {@link CDTUITools#getWorkingCopyManager()}, instead.
*/
+ @Deprecated
public synchronized IBufferFactory getBufferFactory() {
- if (fBufferFactory == null)
- fBufferFactory= new CustomBufferFactory();
- return fBufferFactory;
+ return ((WorkingCopyManager) getWorkingCopyManager()).getBufferFactory();
}
public static IWorkingCopy[] getSharedWorkingCopies() {
- return CModelManager.getDefault().getSharedWorkingCopies(getDefault().getBufferFactory());
+ return getDefault().getWorkingCopyManager().getSharedWorkingCopies();
}
public static String getResourceString(String key) {
@@ -384,7 +382,6 @@ public class CUIPlugin extends AbstractUIPlugin {
private CoreModel fCoreModel;
private CDocumentProvider fDocumentProvider;
- private IBufferFactory fBufferFactory;
private WorkingCopyManager fWorkingCopyManager;
private CTextTools fTextTools;
private ProblemMarkerManager fProblemMarkerManager;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IWorkingCopyManager.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IWorkingCopyManager.java
index a68b55ec762..cbb0074ec13 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IWorkingCopyManager.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/IWorkingCopyManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2009 IBM Corporation 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
@@ -10,10 +10,15 @@
*******************************************************************************/
package org.eclipse.cdt.ui;
-import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.ui.IEditorInput;
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.IProblemRequestor;
+import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.core.model.IWorkingCopy;
+
/**
* Interface for accessing working copies of ITranslationUnit
* objects. The original translation unit is only given indirectly by means
@@ -31,7 +36,7 @@ import org.eclipse.ui.IEditorInput;
*
* @noimplement This interface is not intended to be implemented by clients.
*
- * @see CUIPlugin#getWorkingCopyManager
+ * @see CDTUITools#getWorkingCopyManager
*/
public interface IWorkingCopyManager {
@@ -73,4 +78,27 @@ public interface IWorkingCopyManager {
* by this manager are destroyed.
*/
void shutdown();
+
+ /**
+ * Returns a shared working copy for the given translation unit. If necessary, a new
+ * working copy will be created.
+ * @param tu a translation unit
+ * @param requestor call back interface for reporting problems, may be null
.
+ * @param monitor a monitor to report progress
+ * @since 5.2
+ */
+ IWorkingCopy getSharedWorkingCopy(ITranslationUnit tu, IProblemRequestor requestor, IProgressMonitor monitor) throws CModelException;
+
+ /**
+ * Returns all shared working copies, currently available.
+ * @since 5.2
+ */
+ IWorkingCopy[] getSharedWorkingCopies();
+
+ /**
+ * Returns the shared working copy for the given translation unit, if it exists, or null
, otherwise.
+ * @since 5.2
+ */
+ IWorkingCopy findSharedWorkingCopy(ITranslationUnit tu);
+
}