mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Extends fix for 180168 (using shared AST) to search.
Extends fix for 183973 (plain C in C++-project) to content-assist, hyperlink-detector, search and source-hover.
This commit is contained in:
parent
6c578aa80c
commit
c8dce15ce0
18 changed files with 223 additions and 131 deletions
|
@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||||
|
@ -157,7 +158,7 @@ public class ASTCacheTests extends BaseTestCase {
|
||||||
final int[] counter= {0};
|
final int[] counter= {0};
|
||||||
cache.setActiveElement(fTU1);
|
cache.setActiveElement(fTU1);
|
||||||
IStatus status= cache.runOnAST(fTU1, false, null, new ASTRunnable() {
|
IStatus status= cache.runOnAST(fTU1, false, null, new ASTRunnable() {
|
||||||
public IStatus runOnAST(IASTTranslationUnit ast) throws CoreException {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException {
|
||||||
assertNull(ast);
|
assertNull(ast);
|
||||||
counter[0]++;
|
counter[0]++;
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
|
@ -168,7 +169,7 @@ public class ASTCacheTests extends BaseTestCase {
|
||||||
IProgressMonitor npm= new NullProgressMonitor();
|
IProgressMonitor npm= new NullProgressMonitor();
|
||||||
npm.setCanceled(true);
|
npm.setCanceled(true);
|
||||||
status= cache.runOnAST(fTU1, true, npm, new ASTRunnable() {
|
status= cache.runOnAST(fTU1, true, npm, new ASTRunnable() {
|
||||||
public IStatus runOnAST(IASTTranslationUnit ast) throws CoreException {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException {
|
||||||
assertNull(ast);
|
assertNull(ast);
|
||||||
counter[0]++;
|
counter[0]++;
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
|
@ -178,7 +179,7 @@ public class ASTCacheTests extends BaseTestCase {
|
||||||
|
|
||||||
npm.setCanceled(false);
|
npm.setCanceled(false);
|
||||||
status= cache.runOnAST(fTU1, true, npm, new ASTRunnable() {
|
status= cache.runOnAST(fTU1, true, npm, new ASTRunnable() {
|
||||||
public IStatus runOnAST(IASTTranslationUnit ast) throws CoreException {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException {
|
||||||
assertNotNull(ast);
|
assertNotNull(ast);
|
||||||
counter[0]++;
|
counter[0]++;
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
|
@ -203,7 +204,7 @@ public class ASTCacheTests extends BaseTestCase {
|
||||||
}
|
}
|
||||||
reconciler1.fStopped= true;
|
reconciler1.fStopped= true;
|
||||||
IStatus status= cache.runOnAST(fTU1, true, null, new ASTRunnable() {
|
IStatus status= cache.runOnAST(fTU1, true, null, new ASTRunnable() {
|
||||||
public IStatus runOnAST(IASTTranslationUnit ast) throws CoreException {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException {
|
||||||
assertNotNull(ast);
|
assertNotNull(ast);
|
||||||
assertTrue(cache.isActiveElement(fTU1));
|
assertTrue(cache.isActiveElement(fTU1));
|
||||||
assertFalse(cache.isReconciling(fTU1));
|
assertFalse(cache.isReconciling(fTU1));
|
||||||
|
@ -225,7 +226,7 @@ public class ASTCacheTests extends BaseTestCase {
|
||||||
reconciler2.fStopped= true;
|
reconciler2.fStopped= true;
|
||||||
|
|
||||||
status= cache.runOnAST(fTU2, true, null, new ASTRunnable() {
|
status= cache.runOnAST(fTU2, true, null, new ASTRunnable() {
|
||||||
public IStatus runOnAST(IASTTranslationUnit ast) throws CoreException {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException {
|
||||||
assertNotNull(ast);
|
assertNotNull(ast);
|
||||||
assertTrue(cache.isActiveElement(fTU2));
|
assertTrue(cache.isActiveElement(fTU2));
|
||||||
assertFalse(cache.isReconciling(fTU2));
|
assertFalse(cache.isReconciling(fTU2));
|
||||||
|
@ -256,7 +257,7 @@ public class ASTCacheTests extends BaseTestCase {
|
||||||
cache.setActiveElement(fTU1);
|
cache.setActiveElement(fTU1);
|
||||||
Thread.sleep(50);
|
Thread.sleep(50);
|
||||||
waitForAST(cache, fTU1, new ASTRunnable() {
|
waitForAST(cache, fTU1, new ASTRunnable() {
|
||||||
public IStatus runOnAST(IASTTranslationUnit ast) {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
||||||
assertNotNull(ast);
|
assertNotNull(ast);
|
||||||
assertEquals("void foo1() {}", ast.getDeclarations()[0].getRawSignature());
|
assertEquals("void foo1() {}", ast.getDeclarations()[0].getRawSignature());
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
|
@ -264,7 +265,7 @@ public class ASTCacheTests extends BaseTestCase {
|
||||||
});
|
});
|
||||||
|
|
||||||
waitForAST(cache, fTU2, new ASTRunnable() {
|
waitForAST(cache, fTU2, new ASTRunnable() {
|
||||||
public IStatus runOnAST(IASTTranslationUnit ast) {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
||||||
assertNotNull(ast);
|
assertNotNull(ast);
|
||||||
assertEquals("void foo2() {}", ast.getDeclarations()[0].getRawSignature());
|
assertEquals("void foo2() {}", ast.getDeclarations()[0].getRawSignature());
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
|
@ -275,7 +276,7 @@ public class ASTCacheTests extends BaseTestCase {
|
||||||
cache.setActiveElement(fTU2);
|
cache.setActiveElement(fTU2);
|
||||||
Thread.sleep(50);
|
Thread.sleep(50);
|
||||||
waitForAST(cache, fTU2, new ASTRunnable() {
|
waitForAST(cache, fTU2, new ASTRunnable() {
|
||||||
public IStatus runOnAST(IASTTranslationUnit ast) {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
||||||
assertNotNull(ast);
|
assertNotNull(ast);
|
||||||
assertEquals("void foo2() {}", ast.getDeclarations()[0].getRawSignature());
|
assertEquals("void foo2() {}", ast.getDeclarations()[0].getRawSignature());
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
|
@ -283,7 +284,7 @@ public class ASTCacheTests extends BaseTestCase {
|
||||||
});
|
});
|
||||||
|
|
||||||
waitForAST(cache, fTU1, new ASTRunnable() {
|
waitForAST(cache, fTU1, new ASTRunnable() {
|
||||||
public IStatus runOnAST(IASTTranslationUnit ast) {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
||||||
assertNotNull(ast);
|
assertNotNull(ast);
|
||||||
assertEquals("void foo1() {}", ast.getDeclarations()[0].getRawSignature());
|
assertEquals("void foo1() {}", ast.getDeclarations()[0].getRawSignature());
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
|
|
|
@ -14,6 +14,7 @@ import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.index.IIndexManager;
|
import org.eclipse.cdt.core.index.IIndexManager;
|
||||||
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
@ -50,10 +51,11 @@ public class ASTCache {
|
||||||
/**
|
/**
|
||||||
* Do something with the given AST.
|
* Do something with the given AST.
|
||||||
*
|
*
|
||||||
|
* @param lang the language with which the AST has been created.
|
||||||
* @param ast the translation unit AST, may be <code>null</code>
|
* @param ast the translation unit AST, may be <code>null</code>
|
||||||
* @return a status object
|
* @return a status object
|
||||||
*/
|
*/
|
||||||
IStatus runOnAST(IASTTranslationUnit ast) throws CoreException;
|
IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int fParseMode;
|
private final int fParseMode;
|
||||||
|
@ -205,7 +207,8 @@ public class ASTCache {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IASTTranslationUnit ast= getAST(tUnit, index, wait, monitor);
|
IASTTranslationUnit ast= getAST(tUnit, index, wait, monitor);
|
||||||
return astRunnable.runOnAST(ast);
|
ILanguage lang= (tUnit instanceof TranslationUnit) ? ((TranslationUnit) tUnit).getLanguageOfContext() : tUnit.getLanguage();
|
||||||
|
return astRunnable.runOnAST(lang, ast);
|
||||||
}
|
}
|
||||||
catch (CoreException e) {
|
catch (CoreException e) {
|
||||||
return e.getStatus();
|
return e.getStatus();
|
||||||
|
|
|
@ -83,6 +83,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
||||||
protected IProblemRequestor problemRequestor;
|
protected IProblemRequestor problemRequestor;
|
||||||
|
|
||||||
SourceManipulationInfo sourceManipulationInfo = null;
|
SourceManipulationInfo sourceManipulationInfo = null;
|
||||||
|
private ILanguage fLanguageOfContext;
|
||||||
|
|
||||||
public TranslationUnit(ICElement parent, IFile file, String idType) {
|
public TranslationUnit(ICElement parent, IFile file, String idType) {
|
||||||
super(parent, file, ICElement.C_UNIT);
|
super(parent, file, ICElement.C_UNIT);
|
||||||
|
@ -754,9 +755,41 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
||||||
codeReaderFactory= new IndexBasedCodeReaderFactory(getCProject(), index, codeReaderFactory);
|
codeReaderFactory= new IndexBasedCodeReaderFactory(getCProject(), index, codeReaderFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ITranslationUnit configureWith = getSourceContextTU(index, style);
|
||||||
|
|
||||||
|
IScannerInfo scanInfo= configureWith.getScannerInfo( (style & AST_SKIP_IF_NO_BUILD_INFO) == 0);
|
||||||
|
if (scanInfo == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeReader reader;
|
||||||
|
reader = getCodeReader();
|
||||||
|
|
||||||
|
if (reader != null) {
|
||||||
|
ILanguage language= configureWith.getLanguage();
|
||||||
|
fLanguageOfContext= language;
|
||||||
|
if (language != null) {
|
||||||
|
if (language instanceof AbstractLanguage) {
|
||||||
|
int options= 0;
|
||||||
|
if ((style & AST_SKIP_FUNCTION_BODIES) != 0) {
|
||||||
|
options |= AbstractLanguage.OPTION_SKIP_FUNCTION_BODIES;
|
||||||
|
}
|
||||||
|
if ((style & AST_CREATE_COMMENT_NODES) != 0) {
|
||||||
|
options |= AbstractLanguage.OPTION_ADD_COMMENTS;
|
||||||
|
}
|
||||||
|
return ((AbstractLanguage)language).getASTTranslationUnit(reader, scanInfo, codeReaderFactory, index, options, ParserUtil.getParserLogService());
|
||||||
|
}
|
||||||
|
return language.getASTTranslationUnit(reader, scanInfo, codeReaderFactory, index, ParserUtil.getParserLogService());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ITranslationUnit getSourceContextTU(IIndex index, int style) {
|
||||||
ITranslationUnit configureWith= this;
|
ITranslationUnit configureWith= this;
|
||||||
try {
|
if (index != null && (style & AST_CONFIGURE_USING_SOURCE_CONTEXT) != 0) {
|
||||||
if (index != null && (style & AST_CONFIGURE_USING_SOURCE_CONTEXT) != 0) {
|
try {
|
||||||
|
fLanguageOfContext= null;
|
||||||
IIndexFile context= null;
|
IIndexFile context= null;
|
||||||
IIndexFile indexFile= index.getFile(IndexLocationFactory.getIFL(this));
|
IIndexFile indexFile= index.getFile(IndexLocationFactory.getIFL(this));
|
||||||
if (indexFile != null) {
|
if (indexFile != null) {
|
||||||
|
@ -773,36 +806,11 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
catch (CoreException e) {
|
||||||
catch (CoreException e) {
|
CCorePlugin.log(e);
|
||||||
CCorePlugin.log(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
IScannerInfo scanInfo= configureWith.getScannerInfo( (style & AST_SKIP_IF_NO_BUILD_INFO) == 0);
|
|
||||||
if (scanInfo == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
CodeReader reader;
|
|
||||||
reader = getCodeReader();
|
|
||||||
|
|
||||||
if (reader != null) {
|
|
||||||
ILanguage language= configureWith.getLanguage();
|
|
||||||
if (language != null) {
|
|
||||||
if (language instanceof AbstractLanguage) {
|
|
||||||
int options= 0;
|
|
||||||
if ((style & AST_SKIP_FUNCTION_BODIES) != 0) {
|
|
||||||
options |= AbstractLanguage.OPTION_SKIP_FUNCTION_BODIES;
|
|
||||||
}
|
|
||||||
if ((style & AST_CREATE_COMMENT_NODES) != 0) {
|
|
||||||
options |= AbstractLanguage.OPTION_ADD_COMMENTS;
|
|
||||||
}
|
|
||||||
return ((AbstractLanguage)language).getASTTranslationUnit(reader, scanInfo, codeReaderFactory, index, options, ParserUtil.getParserLogService());
|
|
||||||
}
|
|
||||||
return language.getASTTranslationUnit(reader, scanInfo, codeReaderFactory, index, ParserUtil.getParserLogService());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return configureWith;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IIndexFile getParsedInContext(IIndexFile indexFile)
|
private IIndexFile getParsedInContext(IIndexFile indexFile)
|
||||||
|
@ -829,7 +837,9 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
||||||
codeReaderFactory = SavedCodeReaderFactory.getInstance();
|
codeReaderFactory = SavedCodeReaderFactory.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
IScannerInfo scanInfo = getScannerInfo( (style & ITranslationUnit.AST_SKIP_IF_NO_BUILD_INFO) == 0);
|
ITranslationUnit configureWith= getSourceContextTU(index, style);
|
||||||
|
|
||||||
|
IScannerInfo scanInfo = configureWith.getScannerInfo( (style & ITranslationUnit.AST_SKIP_IF_NO_BUILD_INFO) == 0);
|
||||||
if (scanInfo == null) {
|
if (scanInfo == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -837,7 +847,8 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
||||||
CodeReader reader;
|
CodeReader reader;
|
||||||
reader = getCodeReader();
|
reader = getCodeReader();
|
||||||
|
|
||||||
ILanguage language= getLanguage();
|
ILanguage language= configureWith.getLanguage();
|
||||||
|
fLanguageOfContext= language;
|
||||||
if (language != null) {
|
if (language != null) {
|
||||||
return language.getCompletionNode(reader, scanInfo, codeReaderFactory, index, ParserUtil.getParserLogService(), offset);
|
return language.getCompletionNode(reader, scanInfo, codeReaderFactory, index, ParserUtil.getParserLogService(), offset);
|
||||||
}
|
}
|
||||||
|
@ -882,4 +893,13 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the language of the context this file was parsed in. Works only after using
|
||||||
|
* {@link #getAST(IIndex, int)} with the flag {@link ITranslationUnit#AST_CONFIGURE_USING_SOURCE_CONTEXT}.
|
||||||
|
*/
|
||||||
|
public ILanguage getLanguageOfContext() throws CoreException {
|
||||||
|
final ILanguage result= fLanguageOfContext;
|
||||||
|
return result != null ? result : getLanguage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.jface.action.IAction;
|
import org.eclipse.jface.action.IAction;
|
||||||
import org.eclipse.jface.text.ITextSelection;
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
import org.eclipse.jface.text.TextSelection;
|
import org.eclipse.jface.text.TextSelection;
|
||||||
|
@ -47,12 +48,15 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.testplugin.FileManager;
|
import org.eclipse.cdt.core.testplugin.FileManager;
|
||||||
import org.eclipse.cdt.ui.tests.BaseUITestCase;
|
import org.eclipse.cdt.ui.tests.BaseUITestCase;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable;
|
||||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.editor.ASTProvider;
|
||||||
import org.eclipse.cdt.internal.ui.editor.ICEditorActionDefinitionIds;
|
import org.eclipse.cdt.internal.ui.editor.ICEditorActionDefinitionIds;
|
||||||
import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction;
|
import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction;
|
||||||
|
|
||||||
|
@ -210,16 +214,21 @@ public class BaseSelectionTestsIndexer extends BaseUITestCase {
|
||||||
// the action above should highlight the declaration, so now retrieve it and use that selection to get the IASTName selected on the TU
|
// the action above should highlight the declaration, so now retrieve it and use that selection to get the IASTName selected on the TU
|
||||||
ISelection sel = ((AbstractTextEditor)part).getSelectionProvider().getSelection();
|
ISelection sel = ((AbstractTextEditor)part).getSelectionProvider().getSelection();
|
||||||
|
|
||||||
|
final IASTName[] result= {null};
|
||||||
if (sel instanceof ITextSelection) {
|
if (sel instanceof ITextSelection) {
|
||||||
ITextSelection textSel = (ITextSelection)sel;
|
final ITextSelection textSel = (ITextSelection)sel;
|
||||||
ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(file);
|
ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(file);
|
||||||
IASTTranslationUnit ast = tu.getAST();
|
IStatus ok= ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_YES, monitor, new ASTRunnable() {
|
||||||
IASTName[] names = tu.getLanguage().getSelectedNames(ast, textSel.getOffset(), textSel.getLength());
|
public IStatus runOnAST(ILanguage language, IASTTranslationUnit ast) throws CoreException {
|
||||||
|
IASTName[] names = language.getSelectedNames(ast, textSel.getOffset(), textSel.getLength());
|
||||||
if (names == null || names.length == 0)
|
if (names != null && names.length > 0)
|
||||||
return null;
|
result[0]= names[0];
|
||||||
|
|
||||||
return names[0];
|
return Status.OK_STATUS;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assertTrue(ok.isOK());
|
||||||
|
return result[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,10 @@ import org.eclipse.core.resources.IWorkspace;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.jface.text.ITextSelection;
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
import org.eclipse.jface.text.TextSelection;
|
import org.eclipse.jface.text.TextSelection;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
|
@ -47,14 +49,17 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||||
import org.eclipse.cdt.core.testplugin.FileManager;
|
import org.eclipse.cdt.core.testplugin.FileManager;
|
||||||
import org.eclipse.cdt.ui.tests.BaseUITestCase;
|
import org.eclipse.cdt.ui.tests.BaseUITestCase;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||||
|
import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable;
|
||||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.editor.ASTProvider;
|
||||||
import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction;
|
import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -241,17 +246,21 @@ public class CPPSelectionTestsNoIndexer extends BaseUITestCase {
|
||||||
// the action above should highlight the declaration, so now retrieve it and use that selection to get the IASTName selected on the TU
|
// the action above should highlight the declaration, so now retrieve it and use that selection to get the IASTName selected on the TU
|
||||||
ISelection sel = ((AbstractTextEditor)part).getSelectionProvider().getSelection();
|
ISelection sel = ((AbstractTextEditor)part).getSelectionProvider().getSelection();
|
||||||
|
|
||||||
if (sel instanceof TextSelection) {
|
final IASTName[] result= {null};
|
||||||
ITextSelection textSel = (ITextSelection)sel;
|
if (sel instanceof ITextSelection) {
|
||||||
|
final ITextSelection textSel = (ITextSelection)sel;
|
||||||
ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(file);
|
ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(file);
|
||||||
IASTTranslationUnit ast = tu.getAST();
|
IStatus ok= ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_YES, monitor, new ASTRunnable() {
|
||||||
IASTName[] names = tu.getLanguage().getSelectedNames(ast, textSel.getOffset(), textSel.getLength());
|
public IStatus runOnAST(ILanguage language, IASTTranslationUnit ast) throws CoreException {
|
||||||
|
IASTName[] names = language.getSelectedNames(ast, textSel.getOffset(), textSel.getLength());
|
||||||
if (names.length == 0) {
|
if (names != null && names.length > 0)
|
||||||
assertFalse(true);
|
result[0]= names[0];
|
||||||
} else {
|
|
||||||
return names[0];
|
return Status.OK_STATUS;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
assertTrue(ok.isOK());
|
||||||
|
return result[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,10 @@ import org.eclipse.core.resources.IWorkspace;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.jface.text.ITextSelection;
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
import org.eclipse.jface.text.TextSelection;
|
import org.eclipse.jface.text.TextSelection;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
|
@ -44,14 +46,17 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||||
import org.eclipse.cdt.core.testplugin.FileManager;
|
import org.eclipse.cdt.core.testplugin.FileManager;
|
||||||
import org.eclipse.cdt.ui.tests.BaseUITestCase;
|
import org.eclipse.cdt.ui.tests.BaseUITestCase;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||||
|
import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable;
|
||||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.editor.ASTProvider;
|
||||||
import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction;
|
import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -266,16 +271,21 @@ public class CSelectionTestsNoIndexer extends BaseUITestCase {
|
||||||
// the action above should highlight the declaration, so now retrieve it and use that selection to get the IASTName selected on the TU
|
// the action above should highlight the declaration, so now retrieve it and use that selection to get the IASTName selected on the TU
|
||||||
ISelection sel = ((AbstractTextEditor)part).getSelectionProvider().getSelection();
|
ISelection sel = ((AbstractTextEditor)part).getSelectionProvider().getSelection();
|
||||||
|
|
||||||
if (sel instanceof TextSelection) {
|
final IASTName[] result= {null};
|
||||||
ITextSelection textSel = (ITextSelection)sel;
|
if (sel instanceof ITextSelection) {
|
||||||
|
final ITextSelection textSel = (ITextSelection)sel;
|
||||||
ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(file);
|
ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(file);
|
||||||
IASTTranslationUnit ast = tu.getAST();
|
IStatus ok= ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_YES, monitor, new ASTRunnable() {
|
||||||
IASTName[] names = tu.getLanguage().getSelectedNames(ast, textSel.getOffset(), textSel.getLength());
|
public IStatus runOnAST(ILanguage language, IASTTranslationUnit ast) throws CoreException {
|
||||||
|
IASTName[] names = language.getSelectedNames(ast, textSel.getOffset(), textSel.getLength());
|
||||||
if (names == null || names.length == 0)
|
if (names != null && names.length > 0)
|
||||||
return null;
|
result[0]= names[0];
|
||||||
|
|
||||||
return names[0];
|
return Status.OK_STATUS;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assertTrue(ok.isOK());
|
||||||
|
return result[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.index.IIndexManager;
|
import org.eclipse.cdt.core.index.IIndexManager;
|
||||||
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
|
@ -86,29 +87,27 @@ public class CElementHyperlinkDetector implements IHyperlinkDetector {
|
||||||
|
|
||||||
final IHyperlink[] result= {null};
|
final IHyperlink[] result= {null};
|
||||||
try {
|
try {
|
||||||
ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_YES, null, new ASTRunnable() {
|
IStatus status= ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_YES, null, new ASTRunnable() {
|
||||||
public IStatus runOnAST(IASTTranslationUnit ast) {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
||||||
try {
|
IASTName[] selectedNames=
|
||||||
IASTName[] selectedNames =
|
lang.getSelectedNames(ast, selection.getOffset(), selection.getLength());
|
||||||
workingCopy.getLanguage().getSelectedNames(ast, selection.getOffset(), selection.getLength());
|
|
||||||
|
|
||||||
IRegion linkRegion;
|
IRegion linkRegion;
|
||||||
if(selectedNames.length > 0 && selectedNames[0] != null) { // found a name
|
if(selectedNames.length > 0 && selectedNames[0] != null) { // found a name
|
||||||
linkRegion = new Region(selection.getOffset(), selection.getLength());
|
linkRegion = new Region(selection.getOffset(), selection.getLength());
|
||||||
}
|
}
|
||||||
else { // check if we are in an include statement
|
else { // check if we are in an include statement
|
||||||
linkRegion = matchIncludeStatement(ast, selection);
|
linkRegion = matchIncludeStatement(ast, selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(linkRegion != null)
|
if(linkRegion != null)
|
||||||
result[0]= new CElementHyperlink(linkRegion, openAction);
|
result[0]= new CElementHyperlink(linkRegion, openAction);
|
||||||
}
|
|
||||||
catch (CoreException e) {
|
|
||||||
return e.getStatus();
|
|
||||||
}
|
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (!status.isOK()) {
|
||||||
|
CUIPlugin.getDefault().log(status);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
index.releaseReadLock();
|
index.releaseReadLock();
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfndefStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
|
@ -106,7 +107,7 @@ public class InactiveCodeHighlighting implements ICReconcilingListener, ITextInp
|
||||||
if (fTranslationUnit != null) {
|
if (fTranslationUnit != null) {
|
||||||
final ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider();
|
final ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider();
|
||||||
result= astProvider.runOnAST(fTranslationUnit, ASTProvider.WAIT_YES, monitor, new ASTCache.ASTRunnable() {
|
result= astProvider.runOnAST(fTranslationUnit, ASTProvider.WAIT_YES, monitor, new ASTCache.ASTRunnable() {
|
||||||
public IStatus runOnAST(IASTTranslationUnit ast) {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
||||||
reconciled(ast, true, monitor);
|
reconciled(ast, true, monitor);
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.model.ASTCache;
|
import org.eclipse.cdt.internal.core.model.ASTCache;
|
||||||
|
@ -559,7 +560,7 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
|
||||||
final Job me= this;
|
final Job me= this;
|
||||||
ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider();
|
ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider();
|
||||||
IStatus status= astProvider.runOnAST(element, ASTProvider.WAIT_YES, monitor, new ASTCache.ASTRunnable() {
|
IStatus status= astProvider.runOnAST(element, ASTProvider.WAIT_YES, monitor, new ASTCache.ASTRunnable() {
|
||||||
public IStatus runOnAST(IASTTranslationUnit ast) {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
||||||
reconciled(ast, true, monitor);
|
reconciled(ast, true, monitor);
|
||||||
synchronized (fJobLock) {
|
synchronized (fJobLock) {
|
||||||
// allow the job to be gc'ed
|
// allow the job to be gc'ed
|
||||||
|
|
|
@ -50,6 +50,7 @@ import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.index.IIndexName;
|
import org.eclipse.cdt.core.index.IIndexName;
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
@ -102,7 +103,7 @@ public class ToggleSourceAndHeaderAction extends TextEditorAction {
|
||||||
{
|
{
|
||||||
shouldVisitDeclarators= true;
|
shouldVisitDeclarators= true;
|
||||||
}
|
}
|
||||||
public IStatus runOnAST(IASTTranslationUnit ast) {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
||||||
fIndex= ast.getIndex();
|
fIndex= ast.getIndex();
|
||||||
fFilePath= Path.fromOSString(ast.getFilePath());
|
fFilePath= Path.fromOSString(ast.getFilePath());
|
||||||
fMap= new HashMap();
|
fMap= new HashMap();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006 QNX Software Systems and others.
|
* Copyright (c) 2006, 2007 QNX Software Systems and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -18,15 +18,12 @@ import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.OperationCanceledException;
|
import org.eclipse.core.runtime.OperationCanceledException;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ILanguage;
|
|
||||||
import org.eclipse.cdt.core.model.ISourceRange;
|
|
||||||
import org.eclipse.cdt.core.model.ISourceReference;
|
import org.eclipse.cdt.core.model.ISourceReference;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
|
||||||
|
import org.eclipse.cdt.internal.ui.viewsupport.IndexUI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
|
@ -43,15 +40,11 @@ public class PDOMSearchElementQuery extends PDOMSearchQuery {
|
||||||
|
|
||||||
public IStatus runWithIndex(IIndex index, IProgressMonitor monitor) throws OperationCanceledException {
|
public IStatus runWithIndex(IIndex index, IProgressMonitor monitor) throws OperationCanceledException {
|
||||||
try {
|
try {
|
||||||
ISourceRange range = element.getSourceRange();
|
if (element instanceof ICElement) {
|
||||||
ITranslationUnit tu = element.getTranslationUnit();
|
IBinding binding= IndexUI.elementToBinding(index, (ICElement) element);
|
||||||
IASTTranslationUnit ast= tu.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS);
|
if (binding != null) {
|
||||||
ILanguage language = tu.getLanguage();
|
createMatches(index, binding);
|
||||||
IASTName[] names = language.getSelectedNames(ast, range.getIdStartPos(), range.getIdLength());
|
}
|
||||||
|
|
||||||
for (int i = 0; i < names.length; ++i) {
|
|
||||||
IBinding binding = names[i].resolveBinding();
|
|
||||||
createMatches(index, binding);
|
|
||||||
}
|
}
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006 QNX Software Systems and others.
|
* Copyright (c) 2006, 2007 QNX Software Systems and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -26,6 +26,10 @@ import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ILanguage;
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.editor.ASTProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
*
|
*
|
||||||
|
@ -41,25 +45,23 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery {
|
||||||
this.selection = selection;
|
this.selection = selection;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IStatus runWithIndex(IIndex index, IProgressMonitor monitor) {
|
protected IStatus runWithIndex(final IIndex index, IProgressMonitor monitor) {
|
||||||
try {
|
return ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_YES, monitor, new ASTRunnable() {
|
||||||
IASTTranslationUnit ast= tu.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS);
|
public IStatus runOnAST(ILanguage language, IASTTranslationUnit ast) throws CoreException {
|
||||||
ILanguage language = tu.getLanguage();
|
IASTName[] names = language.getSelectedNames(ast, selection.getOffset(), selection.getLength());
|
||||||
IASTName[] names = language.getSelectedNames(ast, selection.getOffset(), selection.getLength());
|
if (names != null) {
|
||||||
|
for (int i = 0; i < names.length; ++i) {
|
||||||
for (int i = 0; i < names.length; ++i) {
|
IBinding binding = names[i].resolveBinding();
|
||||||
IBinding binding = names[i].resolveBinding();
|
if (binding != null)
|
||||||
if (binding != null)
|
createMatches(index, binding);
|
||||||
createMatches(index, binding);
|
}
|
||||||
|
}
|
||||||
|
return Status.OK_STATUS;
|
||||||
}
|
}
|
||||||
return Status.OK_STATUS;
|
});
|
||||||
} catch (CoreException e) {
|
|
||||||
return e.getStatus();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return super.getLabel() + " " + selection.getText(); //$NON-NLS-1$
|
return super.getLabel() + " " + selection.getText(); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.index.IIndexManager;
|
import org.eclipse.cdt.core.index.IIndexManager;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.core.model.ISourceRange;
|
import org.eclipse.cdt.core.model.ISourceRange;
|
||||||
import org.eclipse.cdt.core.model.ISourceReference;
|
import org.eclipse.cdt.core.model.ISourceReference;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
@ -107,11 +108,11 @@ public class OpenDeclarationsAction extends SelectionParseAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IStatus runOnAST(IASTTranslationUnit ast) throws CoreException {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException {
|
||||||
int selectionStart = selNode.getOffset();
|
int selectionStart = selNode.getOffset();
|
||||||
int selectionLength = selNode.getLength();
|
int selectionLength = selNode.getLength();
|
||||||
|
|
||||||
IASTName[] selectedNames = fWorkingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength);
|
IASTName[] selectedNames = lang.getSelectedNames(ast, selectionStart, selectionLength);
|
||||||
|
|
||||||
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
|
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
|
|
|
@ -40,8 +40,8 @@ import org.eclipse.cdt.internal.ui.editor.CEditorMessages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open Definition Action (Ctrl+F3).
|
* Open Definition Action (Ctrl+F3).
|
||||||
*
|
*
|
||||||
* @author dsteffle
|
* @deprecated use {@link OpenDeclarationsAction}.
|
||||||
*/
|
*/
|
||||||
public class OpenDefinitionAction extends SelectionParseAction {
|
public class OpenDefinitionAction extends SelectionParseAction {
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.core.model.ISourceRange;
|
import org.eclipse.cdt.core.model.ISourceRange;
|
||||||
import org.eclipse.cdt.core.model.ISourceReference;
|
import org.eclipse.cdt.core.model.ISourceReference;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
@ -117,11 +118,11 @@ public class CSourceHover extends AbstractCEditorTextHover implements ITextHover
|
||||||
/*
|
/*
|
||||||
* @see org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable#runOnAST(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit)
|
* @see org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable#runOnAST(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit)
|
||||||
*/
|
*/
|
||||||
public IStatus runOnAST(IASTTranslationUnit ast) {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
||||||
if (ast != null) {
|
if (ast != null) {
|
||||||
try {
|
try {
|
||||||
IASTName[] names;
|
IASTName[] names;
|
||||||
names = fTU.getLanguage().getSelectedNames(ast, fTextRegion.getOffset(), fTextRegion.getLength());
|
names = lang.getSelectedNames(ast, fTextRegion.getOffset(), fTextRegion.getLength());
|
||||||
if (names != null && names.length >= 1) {
|
if (names != null && names.length >= 1) {
|
||||||
for (int i = 0; i < names.length; i++) {
|
for (int i = 0; i < names.length; i++) {
|
||||||
IASTName name= names[i];
|
IASTName name= names[i];
|
||||||
|
|
|
@ -128,7 +128,7 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int flags = ITranslationUnit.AST_SKIP_ALL_HEADERS;
|
int flags = ITranslationUnit.AST_SKIP_ALL_HEADERS | ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT;
|
||||||
if (fIndex == null) {
|
if (fIndex == null) {
|
||||||
flags = 0;
|
flags = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.IElementChangedListener;
|
import org.eclipse.cdt.core.model.IElementChangedListener;
|
||||||
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.core.model.IMember;
|
import org.eclipse.cdt.core.model.IMember;
|
||||||
import org.eclipse.cdt.core.model.IParent;
|
import org.eclipse.cdt.core.model.IParent;
|
||||||
import org.eclipse.cdt.core.model.ISourceRange;
|
import org.eclipse.cdt.core.model.ISourceRange;
|
||||||
|
@ -1038,7 +1039,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
if (ast == null) {
|
if (ast == null) {
|
||||||
final ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider();
|
final ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider();
|
||||||
IStatus status= astProvider.runOnAST(getInputElement(), ASTProvider.WAIT_ACTIVE_ONLY, null, new ASTCache.ASTRunnable() {
|
IStatus status= astProvider.runOnAST(getInputElement(), ASTProvider.WAIT_ACTIVE_ONLY, null, new ASTCache.ASTRunnable() {
|
||||||
public IStatus runOnAST(IASTTranslationUnit ast) {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
||||||
if (ast != null) {
|
if (ast != null) {
|
||||||
ctx.fAST= ast;
|
ctx.fAST= ast;
|
||||||
fInitialReconcilePending= false;
|
fInitialReconcilePending= false;
|
||||||
|
|
|
@ -36,9 +36,17 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IField;
|
||||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
import org.eclipse.cdt.core.index.IIndexFile;
|
import org.eclipse.cdt.core.index.IIndexFile;
|
||||||
|
@ -50,6 +58,7 @@ import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.CoreModelUtil;
|
import org.eclipse.cdt.core.model.CoreModelUtil;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.core.model.ISourceRange;
|
import org.eclipse.cdt.core.model.ISourceRange;
|
||||||
import org.eclipse.cdt.core.model.ISourceReference;
|
import org.eclipse.cdt.core.model.ISourceReference;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
@ -97,17 +106,48 @@ public class IndexUI {
|
||||||
return binding instanceof IEnumeration;
|
return binding instanceof IEnumeration;
|
||||||
case ICElement.C_NAMESPACE:
|
case ICElement.C_NAMESPACE:
|
||||||
return binding instanceof ICPPNamespace;
|
return binding instanceof ICPPNamespace;
|
||||||
|
case ICElement.C_STRUCT_DECLARATION:
|
||||||
case ICElement.C_STRUCT:
|
case ICElement.C_STRUCT:
|
||||||
return binding instanceof ICompositeType &&
|
return binding instanceof ICompositeType &&
|
||||||
((ICompositeType) binding).getKey() == ICompositeType.k_struct;
|
((ICompositeType) binding).getKey() == ICompositeType.k_struct;
|
||||||
case ICElement.C_CLASS:
|
case ICElement.C_CLASS:
|
||||||
|
case ICElement.C_CLASS_DECLARATION:
|
||||||
return binding instanceof ICPPClassType &&
|
return binding instanceof ICPPClassType &&
|
||||||
((ICompositeType) binding).getKey() == ICPPClassType.k_class;
|
((ICompositeType) binding).getKey() == ICPPClassType.k_class;
|
||||||
case ICElement.C_UNION:
|
case ICElement.C_UNION:
|
||||||
|
case ICElement.C_UNION_DECLARATION:
|
||||||
return binding instanceof ICompositeType &&
|
return binding instanceof ICompositeType &&
|
||||||
((ICompositeType) binding).getKey() == ICompositeType.k_union;
|
((ICompositeType) binding).getKey() == ICompositeType.k_union;
|
||||||
case ICElement.C_TYPEDEF:
|
case ICElement.C_TYPEDEF:
|
||||||
return binding instanceof ITypedef;
|
return binding instanceof ITypedef;
|
||||||
|
case ICElement.C_METHOD:
|
||||||
|
case ICElement.C_METHOD_DECLARATION:
|
||||||
|
return binding instanceof ICPPMethod;
|
||||||
|
case ICElement.C_FIELD:
|
||||||
|
return binding instanceof IField;
|
||||||
|
case ICElement.C_FUNCTION:
|
||||||
|
case ICElement.C_FUNCTION_DECLARATION:
|
||||||
|
return binding instanceof ICPPFunction && !(binding instanceof ICPPMethod);
|
||||||
|
case ICElement.C_VARIABLE:
|
||||||
|
case ICElement.C_VARIABLE_DECLARATION:
|
||||||
|
return binding instanceof IVariable;
|
||||||
|
case ICElement.C_ENUMERATOR:
|
||||||
|
return binding instanceof IEnumerator;
|
||||||
|
case ICElement.C_TEMPLATE_CLASS:
|
||||||
|
case ICElement.C_TEMPLATE_CLASS_DECLARATION:
|
||||||
|
case ICElement.C_TEMPLATE_STRUCT:
|
||||||
|
case ICElement.C_TEMPLATE_STRUCT_DECLARATION:
|
||||||
|
case ICElement.C_TEMPLATE_UNION:
|
||||||
|
case ICElement.C_TEMPLATE_UNION_DECLARATION:
|
||||||
|
return binding instanceof ICPPClassTemplate;
|
||||||
|
case ICElement.C_TEMPLATE_FUNCTION:
|
||||||
|
case ICElement.C_TEMPLATE_FUNCTION_DECLARATION:
|
||||||
|
return binding instanceof ICPPFunctionTemplate && !(binding instanceof ICPPMethod);
|
||||||
|
case ICElement.C_TEMPLATE_METHOD_DECLARATION:
|
||||||
|
case ICElement.C_TEMPLATE_METHOD:
|
||||||
|
return binding instanceof ICPPFunctionTemplate && binding instanceof ICPPMethod;
|
||||||
|
case ICElement.C_TEMPLATE_VARIABLE:
|
||||||
|
return binding instanceof ICPPTemplateParameter;
|
||||||
}
|
}
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
// index bindings don't throw the DOMException.
|
// index bindings don't throw the DOMException.
|
||||||
|
@ -258,7 +298,7 @@ public class IndexUI {
|
||||||
|
|
||||||
final IASTName[] result= {null};
|
final IASTName[] result= {null};
|
||||||
ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_YES, null, new ASTRunnable() {
|
ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_YES, null, new ASTRunnable() {
|
||||||
public IStatus runOnAST(IASTTranslationUnit ast) {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
||||||
FindNameForSelectionVisitor finder= new FindNameForSelectionVisitor(ast.getFilePath(), selectionStart, selectionLength);
|
FindNameForSelectionVisitor finder= new FindNameForSelectionVisitor(ast.getFilePath(), selectionStart, selectionLength);
|
||||||
ast.accept(finder);
|
ast.accept(finder);
|
||||||
result[0]= finder.getSelectedName();
|
result[0]= finder.getSelectedName();
|
||||||
|
|
Loading…
Add table
Reference in a new issue