diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/ASTCacheTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/ASTCacheTests.java index 3c546708c52..8b0e483be46 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/ASTCacheTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/ASTCacheTests.java @@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.model.CoreModel; 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.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.util.BaseTestCase; @@ -157,7 +158,7 @@ public class ASTCacheTests extends BaseTestCase { final int[] counter= {0}; cache.setActiveElement(fTU1); 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); counter[0]++; return Status.OK_STATUS; @@ -168,7 +169,7 @@ public class ASTCacheTests extends BaseTestCase { IProgressMonitor npm= new NullProgressMonitor(); npm.setCanceled(true); 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); counter[0]++; return Status.OK_STATUS; @@ -178,7 +179,7 @@ public class ASTCacheTests extends BaseTestCase { npm.setCanceled(false); 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); counter[0]++; return Status.OK_STATUS; @@ -203,7 +204,7 @@ public class ASTCacheTests extends BaseTestCase { } reconciler1.fStopped= true; 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); assertTrue(cache.isActiveElement(fTU1)); assertFalse(cache.isReconciling(fTU1)); @@ -225,7 +226,7 @@ public class ASTCacheTests extends BaseTestCase { reconciler2.fStopped= true; 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); assertTrue(cache.isActiveElement(fTU2)); assertFalse(cache.isReconciling(fTU2)); @@ -256,7 +257,7 @@ public class ASTCacheTests extends BaseTestCase { cache.setActiveElement(fTU1); Thread.sleep(50); waitForAST(cache, fTU1, new ASTRunnable() { - public IStatus runOnAST(IASTTranslationUnit ast) { + public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) { assertNotNull(ast); assertEquals("void foo1() {}", ast.getDeclarations()[0].getRawSignature()); return Status.OK_STATUS; @@ -264,7 +265,7 @@ public class ASTCacheTests extends BaseTestCase { }); waitForAST(cache, fTU2, new ASTRunnable() { - public IStatus runOnAST(IASTTranslationUnit ast) { + public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) { assertNotNull(ast); assertEquals("void foo2() {}", ast.getDeclarations()[0].getRawSignature()); return Status.OK_STATUS; @@ -275,7 +276,7 @@ public class ASTCacheTests extends BaseTestCase { cache.setActiveElement(fTU2); Thread.sleep(50); waitForAST(cache, fTU2, new ASTRunnable() { - public IStatus runOnAST(IASTTranslationUnit ast) { + public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) { assertNotNull(ast); assertEquals("void foo2() {}", ast.getDeclarations()[0].getRawSignature()); return Status.OK_STATUS; @@ -283,7 +284,7 @@ public class ASTCacheTests extends BaseTestCase { }); waitForAST(cache, fTU1, new ASTRunnable() { - public IStatus runOnAST(IASTTranslationUnit ast) { + public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) { assertNotNull(ast); assertEquals("void foo1() {}", ast.getDeclarations()[0].getRawSignature()); return Status.OK_STATUS; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTCache.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTCache.java index fc8544a440a..5724c8de734 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTCache.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTCache.java @@ -14,6 +14,7 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexManager; +import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -50,10 +51,11 @@ public class ASTCache { /** * 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 null * @return a status object */ - IStatus runOnAST(IASTTranslationUnit ast) throws CoreException; + IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException; } private final int fParseMode; @@ -205,7 +207,8 @@ public class ASTCache { try { 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) { return e.getStatus(); 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 6120ff3e77e..ee7ca550bce 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 @@ -83,6 +83,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit { protected IProblemRequestor problemRequestor; SourceManipulationInfo sourceManipulationInfo = null; + private ILanguage fLanguageOfContext; public TranslationUnit(ICElement parent, IFile file, String idType) { super(parent, file, ICElement.C_UNIT); @@ -754,9 +755,41 @@ public class TranslationUnit extends Openable implements ITranslationUnit { 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; - 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 indexFile= index.getFile(IndexLocationFactory.getIFL(this)); if (indexFile != null) { @@ -773,36 +806,11 @@ public class TranslationUnit extends Openable implements ITranslationUnit { } } } - } - catch (CoreException 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()); + catch (CoreException e) { + CCorePlugin.log(e); } } - return null; + return configureWith; } private IIndexFile getParsedInContext(IIndexFile indexFile) @@ -829,7 +837,9 @@ public class TranslationUnit extends Openable implements ITranslationUnit { 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) { return null; } @@ -837,7 +847,8 @@ public class TranslationUnit extends Openable implements ITranslationUnit { CodeReader reader; reader = getCodeReader(); - ILanguage language= getLanguage(); + ILanguage language= configureWith.getLanguage(); + fLanguageOfContext= language; if (language != null) { return language.getCompletionNode(reader, scanInfo, codeReaderFactory, index, ParserUtil.getParserLogService(), offset); } @@ -882,4 +893,13 @@ public class TranslationUnit extends Openable implements ITranslationUnit { } 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(); + } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/BaseSelectionTestsIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/BaseSelectionTestsIndexer.java index e632b3bce65..af9d0e082fb 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/BaseSelectionTestsIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/BaseSelectionTestsIndexer.java @@ -25,6 +25,7 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.action.IAction; import org.eclipse.jface.text.ITextSelection; 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.model.CoreModel; 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.testplugin.FileManager; 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.ui.editor.ASTProvider; import org.eclipse.cdt.internal.ui.editor.ICEditorActionDefinitionIds; 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 ISelection sel = ((AbstractTextEditor)part).getSelectionProvider().getSelection(); + final IASTName[] result= {null}; if (sel instanceof ITextSelection) { - ITextSelection textSel = (ITextSelection)sel; + final ITextSelection textSel = (ITextSelection)sel; ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(file); - IASTTranslationUnit ast = tu.getAST(); - IASTName[] names = tu.getLanguage().getSelectedNames(ast, textSel.getOffset(), textSel.getLength()); - - if (names == null || names.length == 0) - return null; - - return names[0]; + IStatus ok= ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_YES, monitor, new ASTRunnable() { + public IStatus runOnAST(ILanguage language, IASTTranslationUnit ast) throws CoreException { + IASTName[] names = language.getSelectedNames(ast, textSel.getOffset(), textSel.getLength()); + if (names != null && names.length > 0) + result[0]= names[0]; + + return Status.OK_STATUS; + } + }); + assertTrue(ok.isOK()); + return result[0]; } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsNoIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsNoIndexer.java index 116c34331f9..9a51b68c9b0 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsNoIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsNoIndexer.java @@ -28,8 +28,10 @@ import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.TextSelection; 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.model.CoreModel; 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.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.FileManager; import org.eclipse.cdt.ui.tests.BaseUITestCase; 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.ui.editor.ASTProvider; 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 ISelection sel = ((AbstractTextEditor)part).getSelectionProvider().getSelection(); - if (sel instanceof TextSelection) { - ITextSelection textSel = (ITextSelection)sel; + final IASTName[] result= {null}; + if (sel instanceof ITextSelection) { + final ITextSelection textSel = (ITextSelection)sel; ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(file); - IASTTranslationUnit ast = tu.getAST(); - IASTName[] names = tu.getLanguage().getSelectedNames(ast, textSel.getOffset(), textSel.getLength()); - - if (names.length == 0) { - assertFalse(true); - } else { - return names[0]; - } + IStatus ok= ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_YES, monitor, new ASTRunnable() { + public IStatus runOnAST(ILanguage language, IASTTranslationUnit ast) throws CoreException { + IASTName[] names = language.getSelectedNames(ast, textSel.getOffset(), textSel.getLength()); + if (names != null && names.length > 0) + result[0]= names[0]; + + return Status.OK_STATUS; + } + }); + assertTrue(ok.isOK()); + return result[0]; } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsNoIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsNoIndexer.java index 2348d32ab2c..50d07896b79 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsNoIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsNoIndexer.java @@ -26,8 +26,10 @@ import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.TextSelection; 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.model.CoreModel; 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.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.FileManager; import org.eclipse.cdt.ui.tests.BaseUITestCase; 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.ui.editor.ASTProvider; 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 ISelection sel = ((AbstractTextEditor)part).getSelectionProvider().getSelection(); - if (sel instanceof TextSelection) { - ITextSelection textSel = (ITextSelection)sel; + final IASTName[] result= {null}; + if (sel instanceof ITextSelection) { + final ITextSelection textSel = (ITextSelection)sel; ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(file); - IASTTranslationUnit ast = tu.getAST(); - IASTName[] names = tu.getLanguage().getSelectedNames(ast, textSel.getOffset(), textSel.getLength()); - - if (names == null || names.length == 0) - return null; - - return names[0]; + IStatus ok= ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_YES, monitor, new ASTRunnable() { + public IStatus runOnAST(ILanguage language, IASTTranslationUnit ast) throws CoreException { + IASTName[] names = language.getSelectedNames(ast, textSel.getOffset(), textSel.getLength()); + if (names != null && names.length > 0) + result[0]= names[0]; + + return Status.OK_STATUS; + } + }); + assertTrue(ok.isOK()); + return result[0]; } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CElementHyperlinkDetector.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CElementHyperlinkDetector.java index cb0d7d132a8..8cb89d255b1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CElementHyperlinkDetector.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CElementHyperlinkDetector.java @@ -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.index.IIndex; 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.ui.CUIPlugin; @@ -86,29 +87,27 @@ public class CElementHyperlinkDetector implements IHyperlinkDetector { final IHyperlink[] result= {null}; try { - ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_YES, null, new ASTRunnable() { - public IStatus runOnAST(IASTTranslationUnit ast) { - try { - IASTName[] selectedNames = - workingCopy.getLanguage().getSelectedNames(ast, selection.getOffset(), selection.getLength()); + IStatus status= ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_YES, null, new ASTRunnable() { + public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) { + IASTName[] selectedNames= + lang.getSelectedNames(ast, selection.getOffset(), selection.getLength()); - IRegion linkRegion; - if(selectedNames.length > 0 && selectedNames[0] != null) { // found a name - linkRegion = new Region(selection.getOffset(), selection.getLength()); - } - else { // check if we are in an include statement - linkRegion = matchIncludeStatement(ast, selection); - } + IRegion linkRegion; + if(selectedNames.length > 0 && selectedNames[0] != null) { // found a name + linkRegion = new Region(selection.getOffset(), selection.getLength()); + } + else { // check if we are in an include statement + linkRegion = matchIncludeStatement(ast, selection); + } - if(linkRegion != null) - result[0]= new CElementHyperlink(linkRegion, openAction); - } - catch (CoreException e) { - return e.getStatus(); - } + if(linkRegion != null) + result[0]= new CElementHyperlink(linkRegion, openAction); return Status.OK_STATUS; } }); + if (!status.isOK()) { + CUIPlugin.getDefault().log(status); + } } finally { index.releaseReadLock(); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/InactiveCodeHighlighting.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/InactiveCodeHighlighting.java index a1fa2c85d74..08b6f560c6d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/InactiveCodeHighlighting.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/InactiveCodeHighlighting.java @@ -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.IASTTranslationUnit; 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.ui.CUIPlugin; @@ -106,7 +107,7 @@ public class InactiveCodeHighlighting implements ICReconcilingListener, ITextInp if (fTranslationUnit != null) { final ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider(); 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); return Status.OK_STATUS; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightingReconciler.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightingReconciler.java index cf569232ffa..29c84c4f2b3 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightingReconciler.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightingReconciler.java @@ -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.ICPPASTNamespaceDefinition; import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.internal.core.model.ASTCache; @@ -559,7 +560,7 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener { final Job me= this; ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider(); 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); synchronized (fJobLock) { // allow the job to be gc'ed diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ToggleSourceAndHeaderAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ToggleSourceAndHeaderAction.java index d2a3590bc38..0b0d0eb4bcc 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ToggleSourceAndHeaderAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ToggleSourceAndHeaderAction.java @@ -50,6 +50,7 @@ import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexName; import org.eclipse.cdt.core.model.CModelException; 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.IWorkingCopy; import org.eclipse.cdt.ui.CUIPlugin; @@ -102,7 +103,7 @@ public class ToggleSourceAndHeaderAction extends TextEditorAction { { shouldVisitDeclarators= true; } - public IStatus runOnAST(IASTTranslationUnit ast) { + public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) { fIndex= ast.getIndex(); fFilePath= Path.fromOSString(ast.getFilePath()); fMap= new HashMap(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchElementQuery.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchElementQuery.java index 169cbb50b77..585bb8224a0 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchElementQuery.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchElementQuery.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * 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.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.index.IIndex; 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.ITranslationUnit; + +import org.eclipse.cdt.internal.ui.viewsupport.IndexUI; /** * @author Doug Schaefer @@ -43,15 +40,11 @@ public class PDOMSearchElementQuery extends PDOMSearchQuery { public IStatus runWithIndex(IIndex index, IProgressMonitor monitor) throws OperationCanceledException { try { - ISourceRange range = element.getSourceRange(); - ITranslationUnit tu = element.getTranslationUnit(); - IASTTranslationUnit ast= tu.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS); - ILanguage language = tu.getLanguage(); - 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); + if (element instanceof ICElement) { + IBinding binding= IndexUI.elementToBinding(index, (ICElement) element); + if (binding != null) { + createMatches(index, binding); + } } return Status.OK_STATUS; } catch (CoreException e) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java index bb5cde05dab..c375c34a209 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * 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.ITranslationUnit; +import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable; + +import org.eclipse.cdt.internal.ui.editor.ASTProvider; + /** * @author Doug Schaefer * @@ -41,25 +45,23 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery { this.selection = selection; } - protected IStatus runWithIndex(IIndex index, IProgressMonitor monitor) { - try { - IASTTranslationUnit ast= tu.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS); - ILanguage language = tu.getLanguage(); - IASTName[] names = language.getSelectedNames(ast, selection.getOffset(), selection.getLength()); - - for (int i = 0; i < names.length; ++i) { - IBinding binding = names[i].resolveBinding(); - if (binding != null) - createMatches(index, binding); + protected IStatus runWithIndex(final IIndex index, IProgressMonitor monitor) { + return ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_YES, monitor, new ASTRunnable() { + public IStatus runOnAST(ILanguage language, IASTTranslationUnit ast) throws CoreException { + IASTName[] names = language.getSelectedNames(ast, selection.getOffset(), selection.getLength()); + if (names != null) { + for (int i = 0; i < names.length; ++i) { + IBinding binding = names[i].resolveBinding(); + if (binding != null) + createMatches(index, binding); + } + } + return Status.OK_STATUS; } - return Status.OK_STATUS; - } catch (CoreException e) { - return e.getStatus(); - } + }); } public String getLabel() { return super.getLabel() + " " + selection.getText(); //$NON-NLS-1$ } - } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java index fd2553229e9..7ae8fc0cb37 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java @@ -41,6 +41,7 @@ import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.core.model.ICElement; 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.ISourceReference; 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 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 boolean found = false; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java index 204f59bc99c..e877e56a6c1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java @@ -40,8 +40,8 @@ import org.eclipse.cdt.internal.ui.editor.CEditorMessages; /** * Open Definition Action (Ctrl+F3). - * - * @author dsteffle + * + * @deprecated use {@link OpenDeclarationsAction}. */ public class OpenDefinitionAction extends SelectionParseAction { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java index 87819b30476..c28a9abecaa 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java @@ -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.model.CModelException; 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.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) */ - public IStatus runOnAST(IASTTranslationUnit ast) { + public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) { if (ast != null) { try { 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) { for (int i = 0; i < names.length; i++) { IASTName name= names[i]; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CContentAssistInvocationContext.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CContentAssistInvocationContext.java index 52da9668725..c8a3670b40b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CContentAssistInvocationContext.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CContentAssistInvocationContext.java @@ -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) { flags = 0; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/folding/DefaultCFoldingStructureProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/folding/DefaultCFoldingStructureProvider.java index 33acf033cf8..47812016913 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/folding/DefaultCFoldingStructureProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/folding/DefaultCFoldingStructureProvider.java @@ -59,6 +59,7 @@ import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElement; 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.IParent; import org.eclipse.cdt.core.model.ISourceRange; @@ -1038,7 +1039,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi if (ast == null) { final ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider(); 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) { ctx.fAST= ast; fInitialReconcilePending= false; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java index e1ca48b4406..fb0e1ef8564 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java @@ -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.ICompositeType; 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.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.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.ICPPTemplateParameter; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexBinding; 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.ICElement; 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.ISourceReference; import org.eclipse.cdt.core.model.ITranslationUnit; @@ -97,17 +106,48 @@ public class IndexUI { return binding instanceof IEnumeration; case ICElement.C_NAMESPACE: return binding instanceof ICPPNamespace; + case ICElement.C_STRUCT_DECLARATION: case ICElement.C_STRUCT: return binding instanceof ICompositeType && ((ICompositeType) binding).getKey() == ICompositeType.k_struct; case ICElement.C_CLASS: + case ICElement.C_CLASS_DECLARATION: return binding instanceof ICPPClassType && ((ICompositeType) binding).getKey() == ICPPClassType.k_class; case ICElement.C_UNION: + case ICElement.C_UNION_DECLARATION: return binding instanceof ICompositeType && ((ICompositeType) binding).getKey() == ICompositeType.k_union; case ICElement.C_TYPEDEF: 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) { // index bindings don't throw the DOMException. @@ -258,7 +298,7 @@ public class IndexUI { final IASTName[] result= {null}; 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); ast.accept(finder); result[0]= finder.getSelectedName();