mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-20 15:35:24 +02:00
Bug 416247 - Use an index-based AST when generating doxygen comments
Change-Id: Ic379ba7f51ab8379d32969856f189dacb8cb32fc Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
parent
ab6c210d1d
commit
dc57ba11a4
2 changed files with 61 additions and 27 deletions
|
@ -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;
|
||||
|
|
|
@ -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,7 +150,18 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg
|
|||
|
||||
// as we are auto-closing, the comment becomes eligible for auto-doc'ing
|
||||
IASTDeclaration dec= null;
|
||||
IASTTranslationUnit ast= getAST();
|
||||
IIndex index = null;
|
||||
ITranslationUnit unit = getTranslationUnitForActiveEditor();
|
||||
if (unit != null) {
|
||||
index = CCorePlugin.getIndexManager().getIndex(unit.getCProject());
|
||||
try {
|
||||
index.acquireReadLock();
|
||||
} catch (InterruptedException e) {
|
||||
index = null;
|
||||
}
|
||||
}
|
||||
try {
|
||||
IASTTranslationUnit ast = getAST(unit, index);
|
||||
|
||||
if (ast != null) {
|
||||
dec= findFollowingDeclaration(ast, offset);
|
||||
|
@ -166,9 +179,15 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg
|
|||
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)
|
||||
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue