diff options
author | Nathan Ridge | 2015-03-16 04:10:52 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2015-03-24 06:00:09 +0000 |
commit | dc57ba11a41818c1efced32fef57eae6a3486d42 (patch) | |
tree | c9146d75fa3317cdc734623882ab1332fd459c9a | |
parent | ab6c210d1d50a2cb56f76536bc9dcc6b240880c9 (diff) | |
download | org.eclipse.cdt-dc57ba11a41818c1efced32fef57eae6a3486d42.tar.gz org.eclipse.cdt-dc57ba11a41818c1efced32fef57eae6a3486d42.tar.xz org.eclipse.cdt-dc57ba11a41818c1efced32fef57eae6a3486d42.zip |
Bug 416247 - Use an index-based AST when generating doxygen comments
Change-Id: Ic379ba7f51ab8379d32969856f189dacb8cb32fc
Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
2 files changed, 61 insertions, 27 deletions
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 <code>null</code> 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 <code>null</code> 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 <code>null</code> if + * the translation unit is <code>null</code>, 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) @@ -323,6 +349,14 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg } /** + * 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 * @param buffer |