diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/doxygen/DoxygenCCommentAutoEditStrategyTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/doxygen/DoxygenCCommentAutoEditStrategyTest.java
index 54f82adec39..be1fbaa6e22 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/doxygen/DoxygenCCommentAutoEditStrategyTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/doctools/doxygen/DoxygenCCommentAutoEditStrategyTest.java
@@ -23,9 +23,9 @@ import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.cdt.ui.CUIPlugin;
@@ -689,12 +689,12 @@ public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
DoxygenMultilineAutoEditStrategy ds= new DoxygenMultilineAutoEditStrategy() {
@Override
- public IASTTranslationUnit getAST() {
+ public ITranslationUnit getTranslationUnitForActiveEditor() {
final IFile file= fCProject.getProject().getFile("testContent.cpp");
try {
TestSourceReader.createFile(fCProject.getProject(), "testContent.cpp", doc.get());
String id = CoreModel.getRegistedContentTypeId(file.getProject(), file.getName());
- return new TranslationUnit(fCProject, file, id).getAST();
+ return new TranslationUnit(fCProject, file, id);
} catch(CoreException ce) {
assertTrue("Could not get test content AST", false);
return null;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/text/doctools/DefaultMultilineCommentAutoEditStrategy.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/text/doctools/DefaultMultilineCommentAutoEditStrategy.java
index dab42551134..1a59361a09e 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/text/doctools/DefaultMultilineCommentAutoEditStrategy.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/text/doctools/DefaultMultilineCommentAutoEditStrategy.java
@@ -32,12 +32,14 @@ import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.core.dom.ast.IASTNodeSelector;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin;
@@ -148,27 +150,44 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg
// as we are auto-closing, the comment becomes eligible for auto-doc'ing
IASTDeclaration dec= null;
- IASTTranslationUnit ast= getAST();
-
- if (ast != null) {
- dec= findFollowingDeclaration(ast, offset);
- if (dec == null) {
- IASTNodeSelector ans= ast.getNodeSelector(ast.getFilePath());
- IASTNode node= ans.findEnclosingNode(offset, 0);
- if (node instanceof IASTDeclaration) {
- dec= (IASTDeclaration) node;
- }
+ IIndex index = null;
+ ITranslationUnit unit = getTranslationUnitForActiveEditor();
+ if (unit != null) {
+ index = CCorePlugin.getIndexManager().getIndex(unit.getCProject());
+ try {
+ index.acquireReadLock();
+ } catch (InterruptedException e) {
+ index = null;
}
}
-
- if (dec != null) {
- ITypedRegion partition= TextUtilities.getPartition(doc, ICPartitions.C_PARTITIONING /* this! */, offset, false);
- StringBuilder content= customizeAfterNewLineForDeclaration(doc, dec, partition);
- buf.append(indent(content, indentation + MULTILINE_MID, lineDelim));
+ try {
+ IASTTranslationUnit ast = getAST(unit, index);
+
+ if (ast != null) {
+ dec= findFollowingDeclaration(ast, offset);
+ if (dec == null) {
+ IASTNodeSelector ans= ast.getNodeSelector(ast.getFilePath());
+ IASTNode node= ans.findEnclosingNode(offset, 0);
+ if (node instanceof IASTDeclaration) {
+ dec= (IASTDeclaration) node;
+ }
+ }
+ }
+
+ if (dec != null) {
+ ITypedRegion partition= TextUtilities.getPartition(doc, ICPartitions.C_PARTITIONING /* this! */, offset, false);
+ StringBuilder content= customizeAfterNewLineForDeclaration(doc, dec, partition);
+ buf.append(indent(content, indentation + MULTILINE_MID, lineDelim));
+ }
+ } finally {
+ if (index != null) {
+ index.releaseReadLock();
+ }
}
-
} catch(BadLocationException ble) {
- ble.printStackTrace();
+ CUIPlugin.log(ble);
+ } catch(CoreException e) {
+ CUIPlugin.log(e);
}
}
@@ -241,14 +260,22 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg
}
/**
- * @return the AST unit for the active editor, or null
if there is no active editor, or
- * the AST could not be obtained.
+ * @return the AST unit for the active editor, not based on an index, or null
if there
+ * is no active editor, or the AST could not be obtained.
*/
public IASTTranslationUnit getAST() {
- final ITranslationUnit unit= getTranslationUnit();
+ return getAST(getTranslationUnitForActiveEditor(), null);
+ }
+
+ /**
+ * @return the AST for the given translation unit, based on the given index, or null
if
+ * the translation unit is null
, or the AST could not be obtained.
+ * @since 5.10
+ */
+ public IASTTranslationUnit getAST(ITranslationUnit unit, IIndex index) {
try {
if (unit != null) {
- IASTTranslationUnit ast= unit.getAST(null, ITranslationUnit.AST_SKIP_ALL_HEADERS);
+ IASTTranslationUnit ast= unit.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS);
return ast;
}
} catch (CModelException e) {
@@ -297,10 +324,9 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg
/**
* @return the ITranslationUnit for the active editor, or null if no active
* editor could be found.
+ * @deprecated use getTranslationUnitForActiveEditor() instead
*/
- /*
- * Cloned from JDT
- */
+ @Deprecated
protected static ITranslationUnit getTranslationUnit() {
IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null)
@@ -322,6 +348,14 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg
return unit;
}
+ /**
+ * Same as above, but nonstatic so derived classes can override it.
+ * @since 5.10
+ */
+ protected ITranslationUnit getTranslationUnitForActiveEditor() {
+ return getTranslationUnit();
+ }
+
/**
* Returns a new buffer with the specified indent string inserted at the beginning
* of each line in the specified input buffer