mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Introduces an API to access the PDOM, bug 149565.
This commit is contained in:
parent
f5a4ba1d76
commit
2119729ff7
24 changed files with 642 additions and 752 deletions
|
@ -23,14 +23,14 @@ import org.eclipse.ui.IWorkbenchPage;
|
||||||
import org.eclipse.ui.IWorkbenchWindow;
|
import org.eclipse.ui.IWorkbenchWindow;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.IPDOM;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
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.model.CoreModel;
|
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.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.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;
|
||||||
|
|
||||||
|
@ -132,38 +132,30 @@ public class CallHierarchyUI {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ICElement[] findDefinitions(ICProject project, IEditorInput editorInput, ITextSelection sel) throws CoreException {
|
private static ICElement[] findDefinitions(ICProject project, IEditorInput editorInput, ITextSelection sel) throws CoreException {
|
||||||
CIndexQueries index= CIndexQueries.getInstance();
|
|
||||||
IPDOM pdom= CCorePlugin.getPDOMManager().getPDOM(project);
|
|
||||||
if (pdom != null) {
|
|
||||||
try {
|
try {
|
||||||
pdom.acquireReadLock();
|
CIndexQueries indexq= CIndexQueries.getInstance();
|
||||||
} catch (InterruptedException e) {
|
IIndex index= CCorePlugin.getIndexManager().getIndex(project, IIndexManager.ADD_DEPENDENCIES | IIndexManager.ADD_DEPENDENT);
|
||||||
return null;
|
|
||||||
}
|
index.acquireReadLock();
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
IASTName name= getSelectedName(editorInput, sel);
|
IASTName name= getSelectedName(index, editorInput, sel);
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
IBinding binding= name.resolveBinding();
|
IBinding binding= name.resolveBinding();
|
||||||
if (CIndexQueries.isRelevantForCallHierarchy(binding)) {
|
if (CIndexQueries.isRelevantForCallHierarchy(binding)) {
|
||||||
if (name.isDefinition()) {
|
if (name.isDefinition()) {
|
||||||
ICElement elem= index.findDefinition(project, name);
|
ICElement elem= indexq.getCElementForName(project, name);
|
||||||
if (elem != null) {
|
if (elem != null) {
|
||||||
return new ICElement[]{elem};
|
return new ICElement[]{elem};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ICElement[] elems= index.findAllDefinitions(project, name);
|
ICElement[] elems= indexq.findAllDefinitions(index, name);
|
||||||
if (elems.length == 0) {
|
if (elems.length == 0) {
|
||||||
ICProject[] allProjects= CoreModel.getDefault().getCModel().getCProjects();
|
elems= indexq.findAllDefinitions(index, name);
|
||||||
elems= index.findAllDefinitions(allProjects, name);
|
|
||||||
if (elems.length == 0) {
|
if (elems.length == 0) {
|
||||||
ICElement elem= index.findAnyDeclaration(project, name);
|
ICElement elem= indexq.findAnyDeclaration(index, project, name);
|
||||||
if (elem == null) {
|
if (elems != null) {
|
||||||
elem= index.findAnyDeclaration(allProjects, name);
|
elems= new ICElement[]{elem};
|
||||||
}
|
|
||||||
if (elem != null) {
|
|
||||||
elems= new ICElement[] {elem};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,14 +165,20 @@ public class CallHierarchyUI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if (pdom != null) {
|
if (index != null) {
|
||||||
pdom.releaseReadLock();
|
index.releaseReadLock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (CoreException e) {
|
||||||
|
CUIPlugin.getDefault().log(e);
|
||||||
|
}
|
||||||
|
catch (InterruptedException e) {
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IASTName getSelectedName(IEditorInput editorInput, ITextSelection selection) throws CoreException {
|
private static IASTName getSelectedName(IIndex index, IEditorInput editorInput, ITextSelection selection) throws CoreException {
|
||||||
int selectionStart = selection.getOffset();
|
int selectionStart = selection.getOffset();
|
||||||
int selectionLength = selection.getLength();
|
int selectionLength = selection.getLength();
|
||||||
|
|
||||||
|
@ -188,8 +186,8 @@ public class CallHierarchyUI {
|
||||||
if (workingCopy == null)
|
if (workingCopy == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
int options= ILanguage.AST_SKIP_INDEXED_HEADERS | ILanguage.AST_USE_INDEX;
|
int options= ITranslationUnit.AST_SKIP_INDEXED_HEADERS;
|
||||||
IASTTranslationUnit ast = workingCopy.getLanguage().getASTTranslationUnit(workingCopy, options);
|
IASTTranslationUnit ast = workingCopy.getAST(index, options);
|
||||||
FindNameForSelectionVisitor finder= new FindNameForSelectionVisitor(ast.getFilePath(), selectionStart, selectionLength);
|
FindNameForSelectionVisitor finder= new FindNameForSelectionVisitor(ast.getFilePath(), selectionStart, selectionLength);
|
||||||
ast.accept(finder);
|
ast.accept(finder);
|
||||||
return finder.getSelectedName();
|
return finder.getSelectedName();
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
* Anton Leherbauer (Wind River Systems) - Adapted for CDT
|
* Anton Leherbauer (Wind River Systems) - Adapted for CDT
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.editor;
|
package org.eclipse.cdt.internal.ui.editor;
|
||||||
|
@ -28,11 +29,12 @@ import org.eclipse.ui.IWorkbenchPartReference;
|
||||||
import org.eclipse.ui.IWorkbenchWindow;
|
import org.eclipse.ui.IWorkbenchWindow;
|
||||||
import org.eclipse.ui.PlatformUI;
|
import org.eclipse.ui.PlatformUI;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.IPositionConverter;
|
import org.eclipse.cdt.core.IPositionConverter;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
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.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.ISourceReference;
|
import org.eclipse.cdt.core.model.ISourceReference;
|
||||||
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;
|
||||||
|
@ -47,6 +49,10 @@ import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
*/
|
*/
|
||||||
public final class ASTProvider {
|
public final class ASTProvider {
|
||||||
|
|
||||||
|
public static interface ASTRunnable {
|
||||||
|
IStatus runOnAST(IASTTranslationUnit tu);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wait flag.
|
* Wait flag.
|
||||||
*/
|
*/
|
||||||
|
@ -97,7 +103,7 @@ public final class ASTProvider {
|
||||||
/** Full parse mode (no PDOM) */
|
/** Full parse mode (no PDOM) */
|
||||||
public static int PARSE_MODE_FULL= 0;
|
public static int PARSE_MODE_FULL= 0;
|
||||||
/** Fast parse mode (use PDOM) */
|
/** Fast parse mode (use PDOM) */
|
||||||
public static int PARSE_MODE_FAST= ILanguage.AST_SKIP_INDEXED_HEADERS | ILanguage.AST_USE_INDEX;
|
public static int PARSE_MODE_FAST= ITranslationUnit.AST_SKIP_INDEXED_HEADERS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells whether this class is in debug mode.
|
* Tells whether this class is in debug mode.
|
||||||
|
@ -241,6 +247,8 @@ public final class ASTProvider {
|
||||||
|
|
||||||
protected int fParseMode= PARSE_MODE_FAST;
|
protected int fParseMode= PARSE_MODE_FAST;
|
||||||
|
|
||||||
|
private long fLastWriteOnIndex= -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the C plug-in's AST provider.
|
* Returns the C plug-in's AST provider.
|
||||||
*
|
*
|
||||||
|
@ -409,6 +417,7 @@ public final class ASTProvider {
|
||||||
disposeAST();
|
disposeAST();
|
||||||
|
|
||||||
fAST= ast;
|
fAST= ast;
|
||||||
|
fLastWriteOnIndex= fAST == null ? 0 : fAST.getIndex().getLastWriteAccess();
|
||||||
fActivePositionConverter= converter;
|
fActivePositionConverter= converter;
|
||||||
|
|
||||||
// Signal AST change
|
// Signal AST change
|
||||||
|
@ -426,11 +435,12 @@ public final class ASTProvider {
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param cElement the C element
|
* @param cElement the C element
|
||||||
|
* @param index the index used to create the AST, needs to be read-locked.
|
||||||
* @param waitFlag {@link #WAIT_YES}, {@link #WAIT_NO} or {@link #WAIT_ACTIVE_ONLY}
|
* @param waitFlag {@link #WAIT_YES}, {@link #WAIT_NO} or {@link #WAIT_ACTIVE_ONLY}
|
||||||
* @param progressMonitor the progress monitor or <code>null</code>
|
* @param progressMonitor the progress monitor or <code>null</code>
|
||||||
* @return the AST or <code>null</code> if the AST is not available
|
* @return the AST or <code>null</code> if the AST is not available
|
||||||
*/
|
*/
|
||||||
public IASTTranslationUnit getAST(ICElement cElement, WAIT_FLAG waitFlag, IProgressMonitor progressMonitor) {
|
public IASTTranslationUnit getAST(ICElement cElement, IIndex index, WAIT_FLAG waitFlag, IProgressMonitor progressMonitor) {
|
||||||
if (cElement == null)
|
if (cElement == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@ -444,11 +454,16 @@ public final class ASTProvider {
|
||||||
isActiveElement= cElement.equals(fActiveCElement);
|
isActiveElement= cElement.equals(fActiveCElement);
|
||||||
if (isActiveElement) {
|
if (isActiveElement) {
|
||||||
if (fAST != null) {
|
if (fAST != null) {
|
||||||
|
if (fLastWriteOnIndex < index.getLastWriteAccess()) {
|
||||||
|
disposeAST();
|
||||||
|
}
|
||||||
|
else {
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "returning cached AST:" + toString(fAST) + " for: " + cElement.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "returning cached AST:" + toString(fAST) + " for: " + cElement.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||||
|
|
||||||
return fAST;
|
return fAST;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (waitFlag == WAIT_NO) {
|
if (waitFlag == WAIT_NO) {
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "returning null (WAIT_NO) for: " + cElement.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$
|
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "returning null (WAIT_NO) for: " + cElement.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
@ -479,7 +494,7 @@ public final class ASTProvider {
|
||||||
return fAST;
|
return fAST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return getAST(cElement, waitFlag, progressMonitor);
|
return getAST(cElement, index, waitFlag, progressMonitor);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
return null; // thread has been interrupted don't compute AST
|
return null; // thread has been interrupted don't compute AST
|
||||||
}
|
}
|
||||||
|
@ -494,7 +509,7 @@ public final class ASTProvider {
|
||||||
|
|
||||||
IASTTranslationUnit ast= null;
|
IASTTranslationUnit ast= null;
|
||||||
try {
|
try {
|
||||||
ast= createAST(cElement, progressMonitor);
|
ast= createAST(cElement, index, progressMonitor);
|
||||||
if (progressMonitor != null && progressMonitor.isCanceled())
|
if (progressMonitor != null && progressMonitor.isCanceled())
|
||||||
ast= null;
|
ast= null;
|
||||||
else if (DEBUG && ast != null)
|
else if (DEBUG && ast != null)
|
||||||
|
@ -509,7 +524,6 @@ public final class ASTProvider {
|
||||||
reconciled(ast, null, cElement, null);
|
reconciled(ast, null, cElement, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ast;
|
return ast;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -530,10 +544,11 @@ public final class ASTProvider {
|
||||||
* Creates a new translation unit AST.
|
* Creates a new translation unit AST.
|
||||||
*
|
*
|
||||||
* @param cElement the C element for which to create the AST
|
* @param cElement the C element for which to create the AST
|
||||||
|
* @param index for AST generation, needs to be read-locked.
|
||||||
* @param progressMonitor the progress monitor
|
* @param progressMonitor the progress monitor
|
||||||
* @return AST
|
* @return AST
|
||||||
*/
|
*/
|
||||||
IASTTranslationUnit createAST(ICElement cElement, final IProgressMonitor progressMonitor) {
|
IASTTranslationUnit createAST(ICElement cElement, final IIndex index, final IProgressMonitor progressMonitor) {
|
||||||
if (!hasSource(cElement))
|
if (!hasSource(cElement))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@ -552,7 +567,7 @@ public final class ASTProvider {
|
||||||
if (progressMonitor != null && progressMonitor.isCanceled()) {
|
if (progressMonitor != null && progressMonitor.isCanceled()) {
|
||||||
root[0]= null;
|
root[0]= null;
|
||||||
} else {
|
} else {
|
||||||
root[0]= tu.getLanguage().getASTTranslationUnit(tu, fParseMode);
|
root[0]= tu.getAST(index, fParseMode);
|
||||||
}
|
}
|
||||||
} catch (OperationCanceledException ex) {
|
} catch (OperationCanceledException ex) {
|
||||||
root[0]= null;
|
root[0]= null;
|
||||||
|
@ -649,5 +664,25 @@ public final class ASTProvider {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IStatus runOnAST(ICElement cElement, WAIT_FLAG waitFlag, IProgressMonitor monitor,
|
||||||
|
ASTRunnable astRunnable) {
|
||||||
|
IIndex index;
|
||||||
|
try {
|
||||||
|
index = CCorePlugin.getIndexManager().getIndex(cElement.getCProject());
|
||||||
|
index.acquireReadLock();
|
||||||
|
} catch (CoreException e) {
|
||||||
|
return e.getStatus();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
return Status.CANCEL_STATUS;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
IASTTranslationUnit ast= getAST(cElement, index, waitFlag, monitor);
|
||||||
|
return astRunnable.runOnAST(ast);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
index.releaseReadLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IProjectDescription;
|
|
||||||
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.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
@ -45,17 +44,16 @@ import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.browser.IQualifiedTypeName;
|
import org.eclipse.cdt.core.browser.IQualifiedTypeName;
|
||||||
import org.eclipse.cdt.core.browser.PathUtil;
|
import org.eclipse.cdt.core.browser.PathUtil;
|
||||||
import org.eclipse.cdt.core.browser.QualifiedTypeName;
|
import org.eclipse.cdt.core.browser.QualifiedTypeName;
|
||||||
import org.eclipse.cdt.core.dom.IName;
|
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
|
||||||
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexManager;
|
||||||
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.index.IndexFilter;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||||
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
||||||
|
@ -65,11 +63,6 @@ import org.eclipse.cdt.ui.IRequiredInclude;
|
||||||
import org.eclipse.cdt.ui.browser.typeinfo.TypeInfoLabelProvider;
|
import org.eclipse.cdt.ui.browser.typeinfo.TypeInfoLabelProvider;
|
||||||
import org.eclipse.cdt.ui.text.ICHelpInvocationContext;
|
import org.eclipse.cdt.ui.text.ICHelpInvocationContext;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner;
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.CHelpProviderManager;
|
import org.eclipse.cdt.internal.ui.CHelpProviderManager;
|
||||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||||
import org.eclipse.cdt.internal.ui.actions.WorkbenchRunnableAdapter;
|
import org.eclipse.cdt.internal.ui.actions.WorkbenchRunnableAdapter;
|
||||||
|
@ -152,10 +145,25 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
ITranslationUnit tu= getTranslationUnit();
|
ITranslationUnit tu= getTranslationUnit();
|
||||||
|
IIndex index;
|
||||||
|
try {
|
||||||
|
index = CCorePlugin.getIndexManager().getIndex(tu.getCProject(), IIndexManager.ADD_DEPENDENCIES);
|
||||||
|
index.acquireReadLock();
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CUIPlugin.getDefault().log(e);
|
||||||
|
return;
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
if (tu != null) {
|
if (tu != null) {
|
||||||
extractIncludes(fEditor);
|
extractIncludes(fEditor, index);
|
||||||
addInclude(tu);
|
addInclude(tu);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
index.releaseReadLock();
|
||||||
|
}
|
||||||
fUsings = null;
|
fUsings = null;
|
||||||
fRequiredIncludes = null;
|
fRequiredIncludes = null;
|
||||||
}
|
}
|
||||||
|
@ -164,18 +172,19 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
|
||||||
* To be used by ElementListSelectionDialog for user to choose which declarations/
|
* To be used by ElementListSelectionDialog for user to choose which declarations/
|
||||||
* definitions for "add include" when there are more than one to choose from.
|
* definitions for "add include" when there are more than one to choose from.
|
||||||
*/
|
*/
|
||||||
private class DisplayName extends Object
|
private static class DisplayName extends Object
|
||||||
{
|
{
|
||||||
private IIndexName name;
|
private IIndexName name;
|
||||||
|
private IIndexBinding binding;
|
||||||
|
|
||||||
public DisplayName(IIndexName name) {
|
public DisplayName(IIndexName name, IIndexBinding binding) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.binding= binding;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
PDOMBinding binding = (PDOMBinding) name.resolveBinding();
|
|
||||||
if (binding != null)
|
if (binding != null)
|
||||||
{
|
{
|
||||||
return getBindingQualifiedName(binding) + " - " + name.getFileName(); //$NON-NLS-1$
|
return getBindingQualifiedName(binding) + " - " + name.getFileName(); //$NON-NLS-1$
|
||||||
|
@ -188,11 +197,14 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IIndexName getPDOMName()
|
public IIndexName getName() {
|
||||||
{
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IIndexBinding getBinding() {
|
||||||
|
return binding;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -200,8 +212,9 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
|
||||||
* Extract the includes for the given selection. This can be both used to perform
|
* Extract the includes for the given selection. This can be both used to perform
|
||||||
* the work as well as being invoked when there is a change. The actual results
|
* the work as well as being invoked when there is a change. The actual results
|
||||||
* can and should be cached as the lookup process could be potentially costly.
|
* can and should be cached as the lookup process could be potentially costly.
|
||||||
|
* @param index
|
||||||
*/
|
*/
|
||||||
private void extractIncludes(ITextEditor editor) {
|
private void extractIncludes(ITextEditor editor, IIndex index) {
|
||||||
if (editor == null) {
|
if (editor == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -234,67 +247,26 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IPDOMManager pdomManager = CCorePlugin.getPDOMManager();
|
|
||||||
try {
|
try {
|
||||||
ITranslationUnit unit = getTranslationUnit();
|
|
||||||
//get all referenced projects
|
|
||||||
if (unit != null)
|
|
||||||
{
|
|
||||||
ICProject cProj = unit.getCProject();
|
|
||||||
if (cProj != null)
|
|
||||||
{
|
|
||||||
IProject proj = cProj.getProject();
|
|
||||||
if (proj != null)
|
|
||||||
{
|
|
||||||
IProjectDescription projectDescription = proj.getDescription();
|
|
||||||
if (projectDescription != null)
|
|
||||||
{
|
|
||||||
IProject[] projects = projectDescription.getReferencedProjects();
|
|
||||||
List cProjectsToSearch = new ArrayList();
|
|
||||||
//get all the ICProjects for the referenced projects
|
|
||||||
for(int i = 0; i < projects.length; i++)
|
|
||||||
{
|
|
||||||
IProject project = projects[i];
|
|
||||||
try {
|
|
||||||
ICProject[] cProjects = CoreModel.getDefault().getCModel().getCProjects();
|
|
||||||
if (cProjects != null) {
|
|
||||||
for (int j = 0; j < cProjects.length; j++) {
|
|
||||||
ICProject cProject = cProjects[j];
|
|
||||||
if (project.equals(cProjects[j].getProject()))
|
|
||||||
cProjectsToSearch.add(cProject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (CModelException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cProjectsToSearch.add(cProj); //current project
|
|
||||||
Pattern pattern = Pattern.compile(name);
|
Pattern pattern = Pattern.compile(name);
|
||||||
List pdomNames = new ArrayList();
|
|
||||||
//search the projects and get name matching bindings
|
|
||||||
for (int n = 0; n < cProjectsToSearch.size(); n++)
|
|
||||||
{
|
|
||||||
PDOM pdom = (PDOM)pdomManager.getPDOM((ICProject) cProjectsToSearch.get(n));
|
|
||||||
IBinding[] bindings = pdom.findBindings(pattern, new NullProgressMonitor());
|
|
||||||
|
|
||||||
|
IndexFilter filter= new IndexFilter() {
|
||||||
|
};
|
||||||
|
IIndexBinding[] bindings= index.findBindings(pattern, false, filter, new NullProgressMonitor());
|
||||||
|
ArrayList pdomNames= new ArrayList();
|
||||||
for (int i = 0; i < bindings.length; ++i) {
|
for (int i = 0; i < bindings.length; ++i) {
|
||||||
PDOMBinding binding = (PDOMBinding)bindings[i];
|
IIndexBinding binding= bindings[i];
|
||||||
PDOMBinding pdomBinding = pdom.getLinkage(getTranslationUnit().getLanguage()).adaptBinding(binding);
|
IIndexName[] defs= null;
|
||||||
|
// class, struct union, enumeration
|
||||||
IName[] defs= null;
|
if (binding instanceof ICompositeType || binding instanceof IEnumeration) {
|
||||||
if (pdomBinding instanceof IPDOMMemberOwner //class or struct
|
defs= index.findDefinitions(binding);
|
||||||
|| pdomBinding instanceof IEnumeration)
|
|
||||||
{
|
|
||||||
defs= pdom.getDefinitions(pdomBinding);
|
|
||||||
}
|
}
|
||||||
else if (pdomBinding instanceof ITypedef || pdomBinding instanceof IFunction)
|
else if (binding instanceof ITypedef || binding instanceof IFunction) {
|
||||||
{
|
defs= index.findDeclarations(binding);
|
||||||
defs= pdom.getDeclarations(pdomBinding);
|
|
||||||
}
|
}
|
||||||
if (defs != null) {
|
if (defs != null) {
|
||||||
for (int j = 0; j < defs.length; j++) {
|
for (int j = 0; j < defs.length; j++) {
|
||||||
pdomNames.add(new DisplayName((IIndexName)defs[j]));
|
pdomNames.add(new DisplayName(defs[j], binding));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,14 +284,14 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
|
||||||
fRequiredIncludes = new IRequiredInclude[selects.length];
|
fRequiredIncludes = new IRequiredInclude[selects.length];
|
||||||
List usings = new ArrayList(selects.length);
|
List usings = new ArrayList(selects.length);
|
||||||
for (int i = 0; i < fRequiredIncludes.length; i++) {
|
for (int i = 0; i < fRequiredIncludes.length; i++) {
|
||||||
IRequiredInclude include = getRequiredInclude(((DisplayName)selects[i]).getPDOMName().getFileName(), getTranslationUnit());
|
IRequiredInclude include = getRequiredInclude(((DisplayName)selects[i]).getName().getFileName(), getTranslationUnit());
|
||||||
if (include != null) {
|
if (include != null) {
|
||||||
fRequiredIncludes[i] = include;
|
fRequiredIncludes[i] = include;
|
||||||
PDOMBinding pdomBinding = ((PDOMBinding)(((DisplayName)selects[i]).getPDOMName().resolveBinding()));
|
IIndexBinding binding = ((DisplayName)selects[i]).getBinding();
|
||||||
if (pdomBinding instanceof ICPPBinding)
|
if (binding instanceof ICPPBinding)
|
||||||
{
|
{
|
||||||
//find the enclosing namespace, if there's one
|
//find the enclosing namespace, if there's one
|
||||||
IQualifiedTypeName qualifiedName = new QualifiedTypeName(getBindingQualifiedName(pdomBinding));
|
IQualifiedTypeName qualifiedName = new QualifiedTypeName(getBindingQualifiedName(binding));
|
||||||
String qualifiedEnclosingName = (new QualifiedTypeName(qualifiedName.getEnclosingNames())).getFullyQualifiedName();
|
String qualifiedEnclosingName = (new QualifiedTypeName(qualifiedName.getEnclosingNames())).getFullyQualifiedName();
|
||||||
if (!qualifiedEnclosingName.equals("")) //$NON-NLS-1$
|
if (!qualifiedEnclosingName.equals("")) //$NON-NLS-1$
|
||||||
usings.add(qualifiedEnclosingName);
|
usings.add(qualifiedEnclosingName);
|
||||||
|
@ -338,23 +310,18 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
|
||||||
}
|
}
|
||||||
else if (pdomNames.size() == 1)
|
else if (pdomNames.size() == 1)
|
||||||
{
|
{
|
||||||
String fileName = ((DisplayName)pdomNames.get(0)).getPDOMName().getFileName();
|
String fileName = ((DisplayName)pdomNames.get(0)).getName().getFileName();
|
||||||
fRequiredIncludes = new IRequiredInclude[] {getRequiredInclude(fileName, getTranslationUnit())};
|
fRequiredIncludes = new IRequiredInclude[] {getRequiredInclude(fileName, getTranslationUnit())};
|
||||||
PDOMBinding pdomBinding = (PDOMBinding) ((DisplayName)pdomNames.get(0)).getPDOMName().resolveBinding();
|
IIndexBinding binding = ((DisplayName)pdomNames.get(0)).getBinding();
|
||||||
|
|
||||||
if (pdomBinding instanceof ICPPBinding)
|
if (binding instanceof ICPPBinding) {
|
||||||
{
|
|
||||||
//find the enclosing namespace, if there's one
|
//find the enclosing namespace, if there's one
|
||||||
IQualifiedTypeName qualifiedName = new QualifiedTypeName(getBindingQualifiedName(pdomBinding));
|
IQualifiedTypeName qualifiedName = new QualifiedTypeName(getBindingQualifiedName(binding));
|
||||||
String qualifiedEnclosingName = new QualifiedTypeName(qualifiedName.getEnclosingNames()).getFullyQualifiedName();
|
String qualifiedEnclosingName = new QualifiedTypeName(qualifiedName.getEnclosingNames()).getFullyQualifiedName();
|
||||||
if (!qualifiedEnclosingName.equals("")) //$NON-NLS-1$
|
if (!qualifiedEnclosingName.equals("")) //$NON-NLS-1$
|
||||||
fUsings = new String[] {qualifiedEnclosingName};
|
fUsings = new String[] {qualifiedEnclosingName};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -471,17 +438,13 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
|
||||||
* @return binding's fully qualified name
|
* @return binding's fully qualified name
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
private String getBindingQualifiedName(PDOMBinding pdomBinding) throws CoreException
|
private static String getBindingQualifiedName(IIndexBinding binding) throws CoreException
|
||||||
{
|
{
|
||||||
StringBuffer buf = new StringBuffer(pdomBinding.getName());
|
StringBuffer buf = new StringBuffer(binding.getName());
|
||||||
PDOMNode parent = pdomBinding.getParentNode();
|
binding= binding.getParentBinding();
|
||||||
while (parent != null)
|
while (binding != null) {
|
||||||
{
|
buf.insert(0, binding.getName() + "::"); //$NON-NLS-1$
|
||||||
if (parent instanceof PDOMBinding)
|
binding= binding.getParentBinding();
|
||||||
{
|
|
||||||
buf.insert(0, ((PDOMBinding)parent).getName() + "::"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
parent = parent.getParentNode();
|
|
||||||
}
|
}
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,6 +154,7 @@ import org.eclipse.cdt.core.CCorePreferenceConstants;
|
||||||
import org.eclipse.cdt.core.IPositionConverter;
|
import org.eclipse.cdt.core.IPositionConverter;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
|
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
|
||||||
|
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.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
@ -2893,10 +2894,22 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR
|
||||||
SimplePositionTracker positionTracker= new SimplePositionTracker();
|
SimplePositionTracker positionTracker= new SimplePositionTracker();
|
||||||
positionTracker.startTracking(doc);
|
positionTracker.startTracking(doc);
|
||||||
|
|
||||||
|
ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider();
|
||||||
|
IIndex index;
|
||||||
try {
|
try {
|
||||||
IASTTranslationUnit ast= CUIPlugin.getDefault().getASTProvider().createAST(cElement, null);
|
index = CCorePlugin.getIndexManager().getIndex(cElement.getCProject());
|
||||||
|
index.acquireReadLock();
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CUIPlugin.getDefault().log(e);
|
||||||
|
return;
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
IASTTranslationUnit ast= astProvider.createAST(cElement, index, null);
|
||||||
reconciled(ast, positionTracker, null);
|
reconciled(ast, positionTracker, null);
|
||||||
} finally {
|
} finally {
|
||||||
|
index.releaseReadLock();
|
||||||
positionTracker.stopTracking();
|
positionTracker.stopTracking();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.editor;
|
package org.eclipse.cdt.internal.ui.editor;
|
||||||
|
@ -40,6 +41,7 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.LineBackgroundPainter;
|
import org.eclipse.cdt.internal.ui.LineBackgroundPainter;
|
||||||
|
import org.eclipse.cdt.internal.ui.editor.ASTProvider.ASTRunnable;
|
||||||
import org.eclipse.cdt.internal.ui.text.ICReconcilingListener;
|
import org.eclipse.cdt.internal.ui.text.ICReconcilingListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,11 +97,16 @@ public class InactiveCodeHighlighting implements ICReconcilingListener {
|
||||||
synchronized (fJobLock) {
|
synchronized (fJobLock) {
|
||||||
if (fUpdateJob == null) {
|
if (fUpdateJob == null) {
|
||||||
fUpdateJob = new Job(CEditorMessages.getString("InactiveCodeHighlighting_job")) { //$NON-NLS-1$
|
fUpdateJob = new Job(CEditorMessages.getString("InactiveCodeHighlighting_job")) { //$NON-NLS-1$
|
||||||
protected IStatus run(IProgressMonitor monitor) {
|
protected IStatus run(final IProgressMonitor monitor) {
|
||||||
IStatus result = Status.OK_STATUS;
|
IStatus result = Status.OK_STATUS;
|
||||||
if (fTranslationUnit != null) {
|
if (fTranslationUnit != null) {
|
||||||
IASTTranslationUnit ast= CUIPlugin.getDefault().getASTProvider().getAST(fTranslationUnit, ASTProvider.WAIT_YES, monitor);
|
final ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider();
|
||||||
|
result= astProvider.runOnAST(fTranslationUnit, ASTProvider.WAIT_YES, monitor, new ASTRunnable() {
|
||||||
|
public IStatus runOnAST(IASTTranslationUnit ast) {
|
||||||
reconciled(ast, null, monitor);
|
reconciled(ast, null, monitor);
|
||||||
|
return Status.OK_STATUS;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (monitor.isCanceled()) {
|
if (monitor.isCanceled()) {
|
||||||
result = Status.CANCEL_STATUS;
|
result = Status.CANCEL_STATUS;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
* Anton Leherbauer (Wind River Systems) - Adapted for CDT
|
* Anton Leherbauer (Wind River Systems) - Adapted for CDT
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.editor;
|
package org.eclipse.cdt.internal.ui.editor;
|
||||||
|
@ -40,6 +41,7 @@ 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.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.editor.ASTProvider.ASTRunnable;
|
||||||
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager.HighlightedPosition;
|
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager.HighlightedPosition;
|
||||||
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager.HighlightingStyle;
|
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager.HighlightingStyle;
|
||||||
import org.eclipse.cdt.internal.ui.text.ICReconcilingListener;
|
import org.eclipse.cdt.internal.ui.text.ICReconcilingListener;
|
||||||
|
@ -420,7 +422,7 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
|
||||||
|
|
||||||
if (element != null) {
|
if (element != null) {
|
||||||
fJob= new Job(CEditorMessages.getString("SemanticHighlighting_job")) { //$NON-NLS-1$
|
fJob= new Job(CEditorMessages.getString("SemanticHighlighting_job")) { //$NON-NLS-1$
|
||||||
protected IStatus run(IProgressMonitor monitor) {
|
protected IStatus run(final IProgressMonitor monitor) {
|
||||||
if (oldJob != null) {
|
if (oldJob != null) {
|
||||||
try {
|
try {
|
||||||
oldJob.join();
|
oldJob.join();
|
||||||
|
@ -431,15 +433,22 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
|
||||||
}
|
}
|
||||||
if (monitor.isCanceled())
|
if (monitor.isCanceled())
|
||||||
return Status.CANCEL_STATUS;
|
return Status.CANCEL_STATUS;
|
||||||
IASTTranslationUnit ast= CUIPlugin.getDefault().getASTProvider().getAST(element, ASTProvider.WAIT_YES, monitor);
|
|
||||||
|
final Job me= this;
|
||||||
|
ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider();
|
||||||
|
IStatus status= astProvider.runOnAST(element, ASTProvider.WAIT_YES, monitor, new ASTRunnable() {
|
||||||
|
public IStatus runOnAST(IASTTranslationUnit ast) {
|
||||||
reconciled(ast, null, monitor);
|
reconciled(ast, null, monitor);
|
||||||
synchronized (fJobLock) {
|
synchronized (fJobLock) {
|
||||||
// allow the job to be gc'ed
|
// allow the job to be gc'ed
|
||||||
if (fJob == this)
|
if (fJob == me)
|
||||||
fJob= null;
|
fJob= null;
|
||||||
}
|
}
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
return status;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
// fJob.setSystem(true);
|
// fJob.setSystem(true);
|
||||||
fJob.setPriority(Job.DECORATE);
|
fJob.setPriority(Job.DECORATE);
|
||||||
|
|
|
@ -183,18 +183,11 @@ public class IndexView extends ViewPart implements PDOM.IListener, IElementChang
|
||||||
try {
|
try {
|
||||||
if (parentElement instanceof ICProject) {
|
if (parentElement instanceof ICProject) {
|
||||||
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM((ICProject)parentElement);
|
PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM((ICProject)parentElement);
|
||||||
int n = 0;
|
PDOMLinkage[] linkages= pdom.getLinkages();
|
||||||
PDOMLinkage firstLinkage = pdom.getFirstLinkage();
|
if (linkages.length == 1) {
|
||||||
for (PDOMLinkage linkage = firstLinkage; linkage != null; linkage = linkage.getNextLinkage())
|
|
||||||
++n;
|
|
||||||
if (n == 1) {
|
|
||||||
// Skip linkages in hierarchy if there is only one
|
// Skip linkages in hierarchy if there is only one
|
||||||
return getChildren(firstLinkage);
|
return getChildren(linkages[0]);
|
||||||
}
|
}
|
||||||
PDOMLinkage[] linkages = new PDOMLinkage[n];
|
|
||||||
int i = 0;
|
|
||||||
for (PDOMLinkage linkage = pdom.getFirstLinkage(); linkage != null; linkage = linkage.getNextLinkage())
|
|
||||||
linkages[i++] = linkage;
|
|
||||||
return linkages;
|
return linkages;
|
||||||
} else if (parentElement instanceof IPDOMNode) {
|
} else if (parentElement instanceof IPDOMNode) {
|
||||||
IPDOMNode node = (IPDOMNode)parentElement;
|
IPDOMNode node = (IPDOMNode)parentElement;
|
||||||
|
|
|
@ -15,7 +15,7 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMInclude;
|
import org.eclipse.cdt.core.index.IIndexInclude;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an include relation found in the index.
|
* Represents an include relation found in the index.
|
||||||
|
@ -25,9 +25,9 @@ public class CIndexIncludeRelation {
|
||||||
private IPath fIncludedBy;
|
private IPath fIncludedBy;
|
||||||
private IPath fIncludes;
|
private IPath fIncludes;
|
||||||
|
|
||||||
CIndexIncludeRelation(PDOMInclude include) throws CoreException {
|
CIndexIncludeRelation(IIndexInclude include) throws CoreException {
|
||||||
fIncludedBy= Path.fromOSString(include.getIncludedBy().getFileName().getString());
|
fIncludedBy= Path.fromOSString(include.getIncludedByLocation());
|
||||||
fIncludes= Path.fromOSString(include.getIncludes().getFileName().getString());
|
fIncludes= Path.fromOSString(include.getIncludesLocation());
|
||||||
}
|
}
|
||||||
public boolean isSystemInclude() {
|
public boolean isSystemInclude() {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -12,12 +12,9 @@
|
||||||
package org.eclipse.cdt.internal.ui.missingapi;
|
package org.eclipse.cdt.internal.ui.missingapi;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
import org.eclipse.core.resources.IResource;
|
|
||||||
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.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
@ -28,7 +25,6 @@ import org.eclipse.jface.text.Region;
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.IPositionConverter;
|
import org.eclipse.cdt.core.IPositionConverter;
|
||||||
import org.eclipse.cdt.core.dom.IName;
|
import org.eclipse.cdt.core.dom.IName;
|
||||||
import org.eclipse.cdt.core.dom.IPDOM;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
|
@ -37,6 +33,10 @@ import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
|
import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
|
||||||
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexFile;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexInclude;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexManager;
|
||||||
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.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
@ -48,10 +48,6 @@ import org.eclipse.cdt.core.model.ISourceReference;
|
||||||
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;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMInclude;
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
|
||||||
import org.eclipse.cdt.internal.corext.util.CModelUtil;
|
import org.eclipse.cdt.internal.corext.util.CModelUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,7 +55,7 @@ import org.eclipse.cdt.internal.corext.util.CModelUtil;
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
public class CIndexQueries {
|
public class CIndexQueries {
|
||||||
private static final int ASTTU_OPTIONS = ILanguage.AST_SKIP_INDEXED_HEADERS | ILanguage.AST_USE_INDEX;
|
private static final int ASTTU_OPTIONS = ITranslationUnit.AST_SKIP_INDEXED_HEADERS;
|
||||||
private static final ICElement[] EMPTY_ELEMENTS = new ICElement[0];
|
private static final ICElement[] EMPTY_ELEMENTS = new ICElement[0];
|
||||||
private static final CIndexIncludeRelation[] EMPTY_INCLUDES = new CIndexIncludeRelation[0];
|
private static final CIndexIncludeRelation[] EMPTY_INCLUDES = new CIndexIncludeRelation[0];
|
||||||
private static final CIndexQueries sInstance= new CIndexQueries();
|
private static final CIndexQueries sInstance= new CIndexQueries();
|
||||||
|
@ -113,74 +109,35 @@ public class CIndexQueries {
|
||||||
*/
|
*/
|
||||||
public CIndexIncludeRelation[] findIncludedBy(ICProject[] scope, ITranslationUnit tu, IProgressMonitor pm) {
|
public CIndexIncludeRelation[] findIncludedBy(ICProject[] scope, ITranslationUnit tu, IProgressMonitor pm) {
|
||||||
HashMap result= new HashMap();
|
HashMap result= new HashMap();
|
||||||
ICProject projectOfTU= tu.getCProject();
|
try {
|
||||||
|
IIndex index= CCorePlugin.getIndexManager().getIndex(scope);
|
||||||
|
index.acquireReadLock();
|
||||||
|
|
||||||
// mstodo progress monitor
|
|
||||||
for (int i = scope.length-1; i >= 0; i--) {
|
|
||||||
ICProject cproject = scope[i];
|
|
||||||
// prefer the project of the translation unit.
|
|
||||||
if (i != 0) {
|
|
||||||
if (cproject.equals(projectOfTU)) {
|
|
||||||
System.arraycopy(scope, 0, scope, 1, i);
|
|
||||||
scope[0]= projectOfTU;
|
|
||||||
cproject= scope[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CIndexIncludeRelation[] includes= findIncludedBy(cproject, tu);
|
|
||||||
for (int j = 0; j < includes.length; j++) {
|
|
||||||
CIndexIncludeRelation include = includes[j];
|
|
||||||
result.put(include.getIncludedBy(), include);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Collection includes= result.values();
|
|
||||||
return (CIndexIncludeRelation[]) includes.toArray(new CIndexIncludeRelation[includes.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Searches for all include-relations in a project that include the given translation unit.
|
|
||||||
* @param project the project to be searched.
|
|
||||||
* @param tu a translation unit
|
|
||||||
* @return an array of include relations.
|
|
||||||
* @since 4.0
|
|
||||||
*/
|
|
||||||
public CIndexIncludeRelation[] findIncludedBy(ICProject project, ITranslationUnit tu) {
|
|
||||||
try {
|
try {
|
||||||
PDOM pdom= (PDOM) CCorePlugin.getPDOMManager().getPDOM(project);
|
IPath location= tu.getLocation();
|
||||||
if (pdom != null) {
|
if (location != null) {
|
||||||
pdom.acquireReadLock();
|
IIndexFile file= index.getFile(location);
|
||||||
try {
|
if (file != null) {
|
||||||
PDOMFile fileTarget= pdom.getFile(locationForTU(tu));
|
IIndexInclude[] includes= index.findIncludedBy(file);
|
||||||
if (fileTarget != null) {
|
for (int i = 0; i < includes.length; i++) {
|
||||||
ArrayList result= new ArrayList();
|
IIndexInclude include = includes[i];
|
||||||
PDOMInclude include= fileTarget.getFirstIncludedBy();
|
CIndexIncludeRelation rel= new CIndexIncludeRelation(include);
|
||||||
while (include != null) {
|
result.put(rel.getIncludedBy(), rel);
|
||||||
try {
|
|
||||||
result.add(new CIndexIncludeRelation(include));
|
|
||||||
} catch (CoreException e) {
|
|
||||||
CUIPlugin.getDefault().log(e);
|
|
||||||
}
|
}
|
||||||
include= include.getNextInIncludedBy();
|
|
||||||
}
|
}
|
||||||
return (CIndexIncludeRelation[]) result.toArray(new CIndexIncludeRelation[result.size()]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
pdom.releaseReadLock();
|
index.releaseReadLock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (CoreException e) {
|
catch (InterruptedException e) {
|
||||||
|
}
|
||||||
|
catch (CoreException e) {
|
||||||
CUIPlugin.getDefault().log(e);
|
CUIPlugin.getDefault().log(e);
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
}
|
||||||
return EMPTY_INCLUDES;
|
Collection includes= result.values();
|
||||||
}
|
return (CIndexIncludeRelation[]) includes.toArray(new CIndexIncludeRelation[includes.size()]);
|
||||||
|
|
||||||
private IPath locationForTU(ITranslationUnit tu) {
|
|
||||||
IResource r= tu.getResource();
|
|
||||||
if (r != null) {
|
|
||||||
return r.getLocation();
|
|
||||||
}
|
|
||||||
return tu.getPath();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -191,36 +148,35 @@ public class CIndexQueries {
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
public CIndexIncludeRelation[] findIncludesTo(ITranslationUnit tu, IProgressMonitor pm) {
|
public CIndexIncludeRelation[] findIncludesTo(ITranslationUnit tu, IProgressMonitor pm) {
|
||||||
|
try {
|
||||||
ICProject cproject= tu.getCProject();
|
ICProject cproject= tu.getCProject();
|
||||||
if (cproject != null) {
|
if (cproject != null) {
|
||||||
|
IIndex index= CCorePlugin.getIndexManager().getIndex(cproject, IIndexManager.ADD_DEPENDENCIES);
|
||||||
|
index.acquireReadLock();
|
||||||
try {
|
try {
|
||||||
PDOM pdom= (PDOM) CCorePlugin.getPDOMManager().getPDOM(cproject);
|
IPath location= tu.getLocation();
|
||||||
if (pdom != null) {
|
if (location != null) {
|
||||||
pdom.acquireReadLock();
|
IIndexFile file= index.getFile(location);
|
||||||
try {
|
if (file != null) {
|
||||||
PDOMFile fileTarget= pdom.getFile(locationForTU(tu));
|
IIndexInclude includes[]= index.findIncludes(file);
|
||||||
if (fileTarget != null) {
|
|
||||||
ArrayList result= new ArrayList();
|
ArrayList result= new ArrayList();
|
||||||
PDOMInclude include= fileTarget.getFirstInclude();
|
for (int i = 0; i < includes.length; i++) {
|
||||||
while (include != null) {
|
IIndexInclude include = includes[i];
|
||||||
try {
|
|
||||||
result.add(new CIndexIncludeRelation(include));
|
result.add(new CIndexIncludeRelation(include));
|
||||||
} catch (CoreException e) {
|
|
||||||
CUIPlugin.getDefault().log(e);
|
|
||||||
}
|
|
||||||
include= include.getNextInIncludes();
|
|
||||||
}
|
}
|
||||||
return (CIndexIncludeRelation[]) result.toArray(new CIndexIncludeRelation[result.size()]);
|
return (CIndexIncludeRelation[]) result.toArray(new CIndexIncludeRelation[result.size()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
finally {
|
finally {
|
||||||
pdom.releaseReadLock();
|
index.releaseReadLock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (CoreException e) {
|
}
|
||||||
|
catch (CoreException e) {
|
||||||
CUIPlugin.getDefault().log(e);
|
CUIPlugin.getDefault().log(e);
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
}
|
||||||
|
catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
return EMPTY_INCLUDES;
|
return EMPTY_INCLUDES;
|
||||||
}
|
}
|
||||||
|
@ -255,13 +211,11 @@ public class CIndexQueries {
|
||||||
ISourceRange range;
|
ISourceRange range;
|
||||||
range = sf.getSourceRange();
|
range = sf.getSourceRange();
|
||||||
ITranslationUnit tu= sf.getTranslationUnit();
|
ITranslationUnit tu= sf.getTranslationUnit();
|
||||||
IPDOM pdom= CCorePlugin.getPDOMManager().getPDOM(tu.getCProject());
|
IIndex index= CCorePlugin.getIndexManager().getIndex(scope);
|
||||||
if (pdom != null) {
|
index.acquireReadLock();
|
||||||
pdom.acquireReadLock();
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
ILanguage language = tu.getLanguage();
|
ILanguage language = tu.getLanguage();
|
||||||
IASTTranslationUnit ast= language.getASTTranslationUnit(tu, ASTTU_OPTIONS);
|
IASTTranslationUnit ast= tu.getAST(index, ASTTU_OPTIONS);
|
||||||
if (ast == null) {
|
if (ast == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -272,25 +226,18 @@ public class CIndexQueries {
|
||||||
IASTName name= names[names.length-1];
|
IASTName name= names[names.length-1];
|
||||||
for (int i = 0; i < scope.length; i++) {
|
for (int i = 0; i < scope.length; i++) {
|
||||||
ICProject project = scope[i];
|
ICProject project = scope[i];
|
||||||
findCalledBy(name, project, result);
|
findCalledBy(index, name, project, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if (pdom != null) {
|
index.releaseReadLock();
|
||||||
pdom.releaseReadLock();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void findCalledBy(IASTName name, ICProject project, CalledByResult result) {
|
private void findCalledBy(IIndex index, IASTName name, ICProject project, CalledByResult result) throws CoreException {
|
||||||
try {
|
IBinding binding= name.resolveBinding();
|
||||||
PDOM pdom= (PDOM) CCorePlugin.getPDOMManager().getPDOM(project);
|
|
||||||
if (pdom != null) {
|
|
||||||
pdom.acquireReadLock();
|
|
||||||
try {
|
|
||||||
IBinding binding= getPDOMBinding(pdom, name);
|
|
||||||
if (binding != null) {
|
if (binding != null) {
|
||||||
IName[] names= pdom.getReferences(binding);
|
IName[] names= index.findReferences(binding);
|
||||||
for (int i = 0; i < names.length; i++) {
|
for (int i = 0; i < names.length; i++) {
|
||||||
IName rname = names[i];
|
IName rname = names[i];
|
||||||
ITranslationUnit tu= getTranslationUnit(project, rname);
|
ITranslationUnit tu= getTranslationUnit(project, rname);
|
||||||
|
@ -302,29 +249,6 @@ public class CIndexQueries {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
pdom.releaseReadLock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (CoreException e) {
|
|
||||||
CUIPlugin.getDefault().log(e);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private IBinding getPDOMBinding(PDOM pdom, IASTName name) {
|
|
||||||
IBinding binding= name.resolveBinding();
|
|
||||||
IASTTranslationUnit tu= name.getTranslationUnit();
|
|
||||||
ILanguage lang= tu.getLanguage();
|
|
||||||
PDOMLinkage linkage;
|
|
||||||
try {
|
|
||||||
linkage = pdom.getLinkage(lang);
|
|
||||||
return linkage.adaptBinding(binding);
|
|
||||||
} catch (CoreException e) {
|
|
||||||
CUIPlugin.getDefault().log(e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ICElement findCalledBy(CIndexReference reference) {
|
private ICElement findCalledBy(CIndexReference reference) {
|
||||||
ITranslationUnit tu= reference.getTranslationUnit();
|
ITranslationUnit tu= reference.getTranslationUnit();
|
||||||
|
@ -399,13 +323,10 @@ public class CIndexQueries {
|
||||||
|
|
||||||
private void findCallsInRange(ICProject[] scope, ITranslationUnit tu, IRegion range, IProgressMonitor pm, CallsToResult result)
|
private void findCallsInRange(ICProject[] scope, ITranslationUnit tu, IRegion range, IProgressMonitor pm, CallsToResult result)
|
||||||
throws CoreException, InterruptedException {
|
throws CoreException, InterruptedException {
|
||||||
IPDOM pdom= CCorePlugin.getPDOMManager().getPDOM(tu.getCProject());
|
IIndex index= CCorePlugin.getIndexManager().getIndex(scope);
|
||||||
if (pdom != null) {
|
index.acquireReadLock();
|
||||||
pdom.acquireReadLock();
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
ILanguage language = tu.getLanguage();
|
IASTTranslationUnit astTU= tu.getAST(index, ASTTU_OPTIONS);
|
||||||
IASTTranslationUnit astTU= language.getASTTranslationUnit(tu, ASTTU_OPTIONS);
|
|
||||||
if (astTU != null) {
|
if (astTU != null) {
|
||||||
ReferenceVisitor refVisitor= new ReferenceVisitor(astTU.getFilePath(), range.getOffset(), range.getLength());
|
ReferenceVisitor refVisitor= new ReferenceVisitor(astTU.getFilePath(), range.getOffset(), range.getLength());
|
||||||
astTU.accept(refVisitor);
|
astTU.accept(refVisitor);
|
||||||
|
@ -415,9 +336,9 @@ public class CIndexQueries {
|
||||||
IASTName name = refs[i];
|
IASTName name = refs[i];
|
||||||
IBinding binding= name.resolveBinding();
|
IBinding binding= name.resolveBinding();
|
||||||
if (isRelevantForCallHierarchy(binding)) {
|
if (isRelevantForCallHierarchy(binding)) {
|
||||||
ICElement[] defs = findAllDefinitions(scope, name);
|
ICElement[] defs = findAllDefinitions(index, name);
|
||||||
if (defs.length == 0) {
|
if (defs.length == 0) {
|
||||||
ICElement elem = findAnyDeclaration(scope, name);
|
ICElement elem = findAnyDeclaration(index, null, name);
|
||||||
if (elem != null) {
|
if (elem != null) {
|
||||||
defs = new ICElement[] { elem };
|
defs = new ICElement[] { elem };
|
||||||
}
|
}
|
||||||
|
@ -431,67 +352,32 @@ public class CIndexQueries {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if (pdom != null) {
|
index.releaseReadLock();
|
||||||
pdom.releaseReadLock();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICElement[] findAllDefinitions(ICProject[] projectsToSearch, IASTName name) {
|
public ICElement[] findAllDefinitions(IIndex index, IASTName name) throws CoreException {
|
||||||
ArrayList result= new ArrayList();
|
IBinding binding= name.resolveBinding();
|
||||||
for (int i = 0; i < projectsToSearch.length; i++) {
|
|
||||||
ICProject project = projectsToSearch[i];
|
|
||||||
ICElement[] definitions= findAllDefinitions(project, name);
|
|
||||||
if (definitions != null && definitions.length > 0) {
|
|
||||||
result.addAll(Arrays.asList(definitions));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (ICElement[]) result.toArray(new ICElement[result.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ICElement[] findAllDefinitions(ICProject project, IASTName name) {
|
|
||||||
PDOM pdom;
|
|
||||||
try {
|
|
||||||
pdom = (PDOM) CCorePlugin.getPDOMManager().getPDOM(project);
|
|
||||||
if (pdom != null) {
|
|
||||||
pdom.acquireReadLock();
|
|
||||||
try {
|
|
||||||
IBinding binding= getPDOMBinding(pdom, name);
|
|
||||||
if (binding != null) {
|
if (binding != null) {
|
||||||
return getCElementsForNames(project, pdom.getDefinitions(binding));
|
IIndexName[] defs= index.findDefinitions(binding);
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
pdom.releaseReadLock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (CoreException e) {
|
|
||||||
CUIPlugin.getDefault().log(e);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
return EMPTY_ELEMENTS;
|
ArrayList result= new ArrayList();
|
||||||
}
|
|
||||||
|
|
||||||
private ICElement[] getCElementsForNames(ICProject project, IName[] defs) {
|
|
||||||
if (defs != null && defs.length > 0) {
|
|
||||||
HashSet result= new HashSet(defs.length);
|
|
||||||
for (int i = 0; i < defs.length; i++) {
|
for (int i = 0; i < defs.length; i++) {
|
||||||
IName defName = defs[i];
|
IIndexName in = defs[i];
|
||||||
assert !defName.isReference();
|
ICElement definition= getCElementForName(null, in);
|
||||||
ICElement elem= getCElementForName(project, defName);
|
if (definition != null) {
|
||||||
if (elem != null) {
|
result.add(definition);
|
||||||
result.add(elem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return (ICElement[]) result.toArray(new ICElement[result.size()]);
|
return (ICElement[]) result.toArray(new ICElement[result.size()]);
|
||||||
}
|
}
|
||||||
return EMPTY_ELEMENTS;
|
return EMPTY_ELEMENTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ICElement getCElementForName(ICProject project, IName declName) {
|
public ICElement getCElementForName(ICProject preferProject, IName declName) {
|
||||||
assert !declName.isReference();
|
assert !declName.isReference();
|
||||||
ITranslationUnit tu= getTranslationUnit(project, declName);
|
ITranslationUnit tu= getTranslationUnit(preferProject, declName);
|
||||||
if (tu != null) {
|
if (tu != null) {
|
||||||
IRegion region= null;
|
IRegion region= null;
|
||||||
if (declName instanceof IIndexName) {
|
if (declName instanceof IIndexName) {
|
||||||
|
@ -553,104 +439,17 @@ public class CIndexQueries {
|
||||||
return deltaOffset >= 0 && deltaEndoffset <= 0;
|
return deltaOffset >= 0 && deltaEndoffset <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICElement findDefinition(ICProject[] projectsToSearch, IASTName name) {
|
public ICElement findAnyDeclaration(IIndex index, ICProject preferProject, IASTName name) throws CoreException {
|
||||||
name.resolveBinding();
|
IBinding binding= name.resolveBinding();
|
||||||
|
|
||||||
for (int i = 0; i < projectsToSearch.length; i++) {
|
|
||||||
ICProject project = projectsToSearch[i];
|
|
||||||
ICElement definition= findDefinition(project, name);
|
|
||||||
if (definition != null) {
|
|
||||||
return definition;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ICElement findDefinition(ICProject project, IASTName name) {
|
|
||||||
if (name.isDefinition()) {
|
|
||||||
return getCElementForName(project, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
PDOM pdom;
|
|
||||||
try {
|
|
||||||
pdom = (PDOM) CCorePlugin.getPDOMManager().getPDOM(project);
|
|
||||||
if (pdom != null) {
|
|
||||||
pdom.acquireReadLock();
|
|
||||||
try {
|
|
||||||
IBinding binding= getPDOMBinding(pdom, name);
|
|
||||||
if (binding != null) {
|
if (binding != null) {
|
||||||
ICElement elem= getFirstCElementForNames(project, pdom.getDefinitions(binding));
|
IIndexName[] names= index.findNames(binding, IIndex.FIND_DECLARATIONS);
|
||||||
|
for (int i = 0; i < names.length; i++) {
|
||||||
|
ICElement elem= getCElementForName(preferProject, names[i]);
|
||||||
if (elem != null) {
|
if (elem != null) {
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
pdom.releaseReadLock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (CoreException e) {
|
|
||||||
CUIPlugin.getDefault().log(e);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ICElement getFirstCElementForNames(ICProject project, IName[] defs) {
|
|
||||||
if (defs != null) {
|
|
||||||
for (int i = 0; i < defs.length; i++) {
|
|
||||||
IName defName = defs[i];
|
|
||||||
ICElement elem= getCElementForName(project, defName);
|
|
||||||
if (elem != null) {
|
|
||||||
return elem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ICElement findAnyDeclaration(ICProject[] projectsToSearch, IASTName name) {
|
|
||||||
name.resolveBinding();
|
|
||||||
|
|
||||||
for (int i = 0; i < projectsToSearch.length; i++) {
|
|
||||||
ICProject project = projectsToSearch[i];
|
|
||||||
ICElement declaration= findAnyDeclaration(project, name);
|
|
||||||
if (declaration != null) {
|
|
||||||
return declaration;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ICElement findAnyDeclaration(ICProject project, IASTName name) {
|
|
||||||
PDOM pdom;
|
|
||||||
try {
|
|
||||||
pdom = (PDOM) CCorePlugin.getPDOMManager().getPDOM(project);
|
|
||||||
if (pdom != null) {
|
|
||||||
pdom.acquireReadLock();
|
|
||||||
try {
|
|
||||||
IBinding binding= getPDOMBinding(pdom, name);
|
|
||||||
if (binding != null) {
|
|
||||||
ICElement elem= getFirstCElementForNames(project, pdom.getDefinitions(binding));
|
|
||||||
if (elem != null) {
|
|
||||||
return elem;
|
|
||||||
}
|
|
||||||
elem= getFirstCElementForNames(project, pdom.getDeclarations(binding));
|
|
||||||
if (elem != null) {
|
|
||||||
return elem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
pdom.releaseReadLock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (CoreException e) {
|
|
||||||
CUIPlugin.getDefault().log(e);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,19 +7,22 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.search;
|
package org.eclipse.cdt.internal.ui.search;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
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.index.IIndex;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
*
|
*
|
||||||
|
@ -27,16 +30,16 @@ import org.eclipse.core.runtime.Status;
|
||||||
*/
|
*/
|
||||||
public class PDOMSearchBindingQuery extends PDOMSearchQuery {
|
public class PDOMSearchBindingQuery extends PDOMSearchQuery {
|
||||||
|
|
||||||
private PDOMBinding binding;
|
private IIndexBinding binding;
|
||||||
|
|
||||||
public PDOMSearchBindingQuery(ICElement[] scope, PDOMBinding binding, int flags) {
|
public PDOMSearchBindingQuery(ICElement[] scope, IIndexBinding binding, int flags) {
|
||||||
super(scope, flags);
|
super(scope, flags);
|
||||||
this.binding = binding;
|
this.binding = binding;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
|
public IStatus runWithIndex(IIndex index, IProgressMonitor monitor) throws OperationCanceledException {
|
||||||
try {
|
try {
|
||||||
createMatches(binding.getLinkage().getLanguage(), binding);
|
createMatches(index, binding);
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
return new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, 0, e.getLocalizedMessage(), e);
|
return new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, 0, e.getLocalizedMessage(), e);
|
||||||
|
|
|
@ -7,14 +7,16 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.search;
|
package org.eclipse.cdt.internal.ui.search;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Element class used to group matches.
|
* Element class used to group matches.
|
||||||
*
|
*
|
||||||
|
@ -22,14 +24,14 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
*/
|
*/
|
||||||
public class PDOMSearchElement {
|
public class PDOMSearchElement {
|
||||||
|
|
||||||
private final PDOMBinding binding;
|
private final IIndexBinding binding;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String filename;
|
private final String filename;
|
||||||
|
|
||||||
public PDOMSearchElement(PDOMName name) throws CoreException {
|
public PDOMSearchElement(IIndexName name, IIndexBinding binding) throws CoreException {
|
||||||
binding = name.getPDOMBinding();
|
this.binding= binding;
|
||||||
this.name = binding.getName();
|
this.name = binding.getName();
|
||||||
filename = name.getFile().getFileName().getString();
|
filename = name.getFileName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
|
@ -50,7 +52,7 @@ public class PDOMSearchElement {
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PDOMBinding getBinding() {
|
public IIndexBinding getBinding() {
|
||||||
return binding;
|
return binding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,24 +7,27 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.search;
|
package org.eclipse.cdt.internal.ui.search;
|
||||||
|
|
||||||
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.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.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
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.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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
*
|
*
|
||||||
|
@ -38,17 +41,17 @@ public class PDOMSearchElementQuery extends PDOMSearchQuery {
|
||||||
this.element = element;
|
this.element = element;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
|
public IStatus runWithIndex(IIndex index, IProgressMonitor monitor) throws OperationCanceledException {
|
||||||
try {
|
try {
|
||||||
ISourceRange range = element.getSourceRange();
|
ISourceRange range = element.getSourceRange();
|
||||||
ITranslationUnit tu = element.getTranslationUnit();
|
ITranslationUnit tu = element.getTranslationUnit();
|
||||||
|
IASTTranslationUnit ast= tu.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS);
|
||||||
ILanguage language = tu.getLanguage();
|
ILanguage language = tu.getLanguage();
|
||||||
IASTTranslationUnit ast = language.getASTTranslationUnit(tu, ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX);
|
|
||||||
IASTName[] names = language.getSelectedNames(ast, range.getIdStartPos(), range.getIdLength());
|
IASTName[] names = language.getSelectedNames(ast, range.getIdStartPos(), range.getIdLength());
|
||||||
|
|
||||||
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();
|
||||||
createMatches(language, binding);
|
createMatches(index, binding);
|
||||||
}
|
}
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
|
|
|
@ -7,22 +7,25 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.search;
|
package org.eclipse.cdt.internal.ui.search;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.search.ui.text.Match;
|
import org.eclipse.search.ui.text.Match;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class PDOMSearchMatch extends Match {
|
public class PDOMSearchMatch extends Match {
|
||||||
|
|
||||||
public PDOMSearchMatch(PDOMName name, int offset, int length) throws CoreException {
|
public PDOMSearchMatch(IIndexBinding binding, IIndexName name, int offset, int length) throws CoreException {
|
||||||
super(new PDOMSearchElement(name), offset, length);
|
super(new PDOMSearchElement(name, binding), offset, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFileName() throws CoreException {
|
public String getFileName() throws CoreException {
|
||||||
|
|
|
@ -24,9 +24,6 @@ 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.CCorePlugin;
|
|
||||||
import org.eclipse.cdt.core.dom.IPDOM;
|
|
||||||
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.IEnumerator;
|
||||||
|
@ -38,10 +35,10 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
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.ICPPNamespaceAlias;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
|
||||||
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
|
import org.eclipse.cdt.core.index.IndexFilter;
|
||||||
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.internal.core.pdom.dom.PDOMBinding;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.util.Messages;
|
import org.eclipse.cdt.internal.ui.util.Messages;
|
||||||
|
|
||||||
|
@ -122,29 +119,12 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
|
||||||
pattern = (Pattern[])patternList.toArray(new Pattern[patternList.size()]);
|
pattern = (Pattern[])patternList.toArray(new Pattern[patternList.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
|
public IStatus runWithIndex(IIndex index, IProgressMonitor monitor) throws OperationCanceledException {
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < projects.length; ++i)
|
IndexFilter filter= new IndexFilter();
|
||||||
searchProject(projects[i], monitor);
|
IIndexBinding[] bindings = index.findBindings(pattern, false, filter, monitor);
|
||||||
return Status.OK_STATUS;
|
|
||||||
} catch (CoreException e) {
|
|
||||||
return e.getStatus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void searchProject(ICProject project, IProgressMonitor monitor) throws CoreException {
|
|
||||||
IPDOM pdom = CCorePlugin.getPDOMManager().getPDOM(project);
|
|
||||||
|
|
||||||
try {
|
|
||||||
pdom.acquireReadLock();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
IBinding[] bindings = pdom.findBindings(pattern, monitor);
|
|
||||||
for (int i = 0; i < bindings.length; ++i) {
|
for (int i = 0; i < bindings.length; ++i) {
|
||||||
PDOMBinding pdomBinding = (PDOMBinding)bindings[i];
|
IIndexBinding pdomBinding = bindings[i];
|
||||||
|
|
||||||
//check for the element type of this binding and create matches if
|
//check for the element type of this binding and create matches if
|
||||||
//the element type checkbox is checked in the C/C++ Search Page
|
//the element type checkbox is checked in the C/C++ Search Page
|
||||||
|
@ -192,12 +172,13 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
|
||||||
matches= (flags & FIND_TYPEDEF) != 0;
|
matches= (flags & FIND_TYPEDEF) != 0;
|
||||||
}
|
}
|
||||||
if (matches) {
|
if (matches) {
|
||||||
createMatches(pdomBinding.getLinkage().getLanguage(), pdomBinding);
|
createMatches(index, pdomBinding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} catch (CoreException e) {
|
||||||
pdom.releaseReadLock();
|
return e.getStatus();
|
||||||
}
|
}
|
||||||
|
return Status.OK_STATUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.search;
|
package org.eclipse.cdt.internal.ui.search;
|
||||||
|
@ -14,21 +15,24 @@ package org.eclipse.cdt.internal.ui.search;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.IStatus;
|
||||||
|
import org.eclipse.core.runtime.OperationCanceledException;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
|
import org.eclipse.search.ui.ISearchQuery;
|
||||||
|
import org.eclipse.search.ui.ISearchResult;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
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.IIndexBinding;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexName;
|
||||||
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.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.core.model.ILanguage;
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
|
||||||
import org.eclipse.search.ui.ISearchQuery;
|
|
||||||
import org.eclipse.search.ui.ISearchResult;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
|
@ -101,37 +105,46 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
||||||
* @param name
|
* @param name
|
||||||
* @return true to filter name out of the match list
|
* @return true to filter name out of the match list
|
||||||
*/
|
*/
|
||||||
protected boolean filterName(PDOMName name) {
|
protected boolean filterName(IIndexName name) {
|
||||||
return false; // i.e. keep it
|
return false; // i.e. keep it
|
||||||
}
|
}
|
||||||
|
|
||||||
private void collectNames(PDOMName name) throws CoreException {
|
private void collectNames(IIndex index, IIndexName[] names) throws CoreException {
|
||||||
while (name != null) {
|
for (int i = 0; i < names.length; i++) {
|
||||||
|
IIndexName name = names[i];
|
||||||
if (!filterName(name)) {
|
if (!filterName(name)) {
|
||||||
IASTFileLocation loc = name.getFileLocation();
|
IASTFileLocation loc = name.getFileLocation();
|
||||||
result.addMatch(new PDOMSearchMatch(name, loc.getNodeOffset(), loc.getNodeLength()));
|
IIndexBinding binding= index.findBinding(name);
|
||||||
name = name.getNextInBinding();
|
result.addMatch(new PDOMSearchMatch(binding, name, loc.getNodeOffset(), loc.getNodeLength()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void createMatches(ILanguage language, IBinding binding) throws CoreException {
|
protected void createMatches(IIndex index, IBinding binding) throws CoreException {
|
||||||
IPDOMManager manager = CCorePlugin.getPDOMManager();
|
if (binding != null) {
|
||||||
for (int i = 0; i < projects.length; ++i) {
|
IIndexName[] names= index.findNames(binding, flags);
|
||||||
PDOM pdom = (PDOM)manager.getPDOM(projects[i]);
|
collectNames(index, names);
|
||||||
PDOMBinding pdomBinding = pdom.getLinkage(language).adaptBinding(binding);
|
|
||||||
if (pdomBinding != null) {
|
|
||||||
if ((flags & FIND_DECLARATIONS) != 0) {
|
|
||||||
collectNames(pdomBinding.getFirstDeclaration());
|
|
||||||
}
|
|
||||||
if ((flags & FIND_DEFINITIONS) != 0) {
|
|
||||||
collectNames(pdomBinding.getFirstDefinition());
|
|
||||||
}
|
|
||||||
if ((flags & FIND_REFERENCES) != 0) {
|
|
||||||
collectNames(pdomBinding.getFirstReference());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
|
||||||
|
try {
|
||||||
|
IIndex index= CCorePlugin.getIndexManager().getIndex(projects, 0);
|
||||||
|
try {
|
||||||
|
index.acquireReadLock();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
return Status.CANCEL_STATUS;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return runWithIndex(index, monitor);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
index.releaseReadLock();
|
||||||
|
}
|
||||||
|
} catch (CoreException e) {
|
||||||
|
return e.getStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract protected IStatus runWithIndex(IIndex index, IProgressMonitor monitor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.search;
|
package org.eclipse.cdt.internal.ui.search;
|
||||||
|
@ -14,10 +15,6 @@ package org.eclipse.cdt.internal.ui.search;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
|
||||||
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
|
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
@ -33,6 +30,11 @@ import org.eclipse.ui.IEditorInput;
|
||||||
import org.eclipse.ui.IEditorPart;
|
import org.eclipse.ui.IEditorPart;
|
||||||
import org.eclipse.ui.part.FileEditorInput;
|
import org.eclipse.ui.part.FileEditorInput;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.index.IIndexName;
|
||||||
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
*
|
*
|
||||||
|
@ -117,10 +119,9 @@ public class PDOMSearchResult extends AbstractTextSearchResult implements IEdito
|
||||||
}
|
}
|
||||||
|
|
||||||
public IFile getFile(Object element) {
|
public IFile getFile(Object element) {
|
||||||
if (element instanceof PDOMName) {
|
if (element instanceof IIndexName) {
|
||||||
PDOMName name = (PDOMName)element;
|
IIndexName name = (IIndexName)element;
|
||||||
IASTFileLocation loc = name.getFileLocation();
|
IPath path = new Path(name.getFileName());
|
||||||
IPath path = new Path(loc.getFileName());
|
|
||||||
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
|
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
|
||||||
if (files.length > 0)
|
if (files.length > 0)
|
||||||
return files[0];
|
return files[0];
|
||||||
|
|
|
@ -7,23 +7,25 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.search;
|
package org.eclipse.cdt.internal.ui.search;
|
||||||
|
|
||||||
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.model.ICElement;
|
|
||||||
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.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.OperationCanceledException;
|
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.jface.text.ITextSelection;
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
|
|
||||||
|
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.ITranslationUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
*
|
*
|
||||||
|
@ -39,16 +41,16 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery {
|
||||||
this.selection = selection;
|
this.selection = selection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
|
protected IStatus runWithIndex(IIndex index, IProgressMonitor monitor) {
|
||||||
try {
|
try {
|
||||||
|
IASTTranslationUnit ast= tu.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS);
|
||||||
ILanguage language = tu.getLanguage();
|
ILanguage language = tu.getLanguage();
|
||||||
IASTTranslationUnit ast = language.getASTTranslationUnit(tu, ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX);
|
|
||||||
IASTName[] names = language.getSelectedNames(ast, selection.getOffset(), selection.getLength());
|
IASTName[] names = language.getSelectedNames(ast, selection.getOffset(), selection.getLength());
|
||||||
|
|
||||||
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(language, binding);
|
createMatches(index, binding);
|
||||||
}
|
}
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
|
|
|
@ -29,8 +29,6 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||||
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;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||||
import org.eclipse.cdt.internal.ui.editor.CEditorMessages;
|
import org.eclipse.cdt.internal.ui.editor.CEditorMessages;
|
||||||
|
|
||||||
|
@ -65,8 +63,8 @@ public class OpenDeclarationsAction extends SelectionParseAction {
|
||||||
int style = 0;
|
int style = 0;
|
||||||
// IPDOM pdom = CCorePlugin.getPDOMManager().getPDOM(workingCopy.getCProject());
|
// IPDOM pdom = CCorePlugin.getPDOMManager().getPDOM(workingCopy.getCProject());
|
||||||
// if (!pdom.isEmpty())
|
// if (!pdom.isEmpty())
|
||||||
// style |= ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX;
|
// style |= ITranslationUnit.AST_SKIP_ALL_HEADERS;
|
||||||
IASTTranslationUnit ast = workingCopy.getLanguage().getASTTranslationUnit(workingCopy, style);
|
IASTTranslationUnit ast = workingCopy.getAST(null, style);
|
||||||
IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength);
|
IASTName[] selectedNames = workingCopy.getLanguage().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
|
||||||
|
@ -85,24 +83,32 @@ public class OpenDeclarationsAction extends SelectionParseAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (binding instanceof PDOMBinding) {
|
|
||||||
PDOMBinding pdomBinding = (PDOMBinding)binding;
|
|
||||||
IName name = pdomBinding.getFirstDefinition();
|
|
||||||
if (name == null)
|
|
||||||
name = pdomBinding.getFirstDeclaration();
|
|
||||||
if (name != null) {
|
|
||||||
final IName dname = name;
|
|
||||||
Display.getDefault().asyncExec(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
open(dname);
|
|
||||||
} catch (CoreException e) {
|
|
||||||
CUIPlugin.getDefault().log(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// mstodo revisit
|
||||||
|
// else if (binding instanceof IIndexBinding) {
|
||||||
|
// IIndexBinding pdomBinding = (IIndexBinding)binding;
|
||||||
|
// IName name = pdomBinding.getFirstDefinition();
|
||||||
|
// if (name == null)
|
||||||
|
// name = pdomBinding.getFirstDeclaration();
|
||||||
|
// // no source location - TODO spit out an error in the status bar
|
||||||
|
// if (name != null) {
|
||||||
|
// IASTFileLocation fileloc = name.getFileLocation();
|
||||||
|
// if (fileloc != null) {
|
||||||
|
// final IPath path = new Path(fileloc.getFileName());
|
||||||
|
// final int offset = fileloc.getNodeOffset();
|
||||||
|
// final int length = fileloc.getNodeLength();
|
||||||
|
// Display.getDefault().asyncExec(new Runnable() {
|
||||||
|
// public void run() {
|
||||||
|
// try {
|
||||||
|
// open(path, offset, length);
|
||||||
|
// } catch (CoreException e) {
|
||||||
|
// CUIPlugin.getDefault().log(e);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,19 +12,25 @@
|
||||||
package org.eclipse.cdt.internal.ui.search.actions;
|
package org.eclipse.cdt.internal.ui.search.actions;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
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.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.core.runtime.jobs.Job;
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
import org.eclipse.jface.text.ITextSelection;
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
import org.eclipse.swt.widgets.Display;
|
import org.eclipse.swt.widgets.Display;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.IName;
|
import org.eclipse.cdt.core.dom.IName;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
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.model.ILanguage;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexManager;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@ -65,7 +71,15 @@ public class OpenDefinitionAction extends SelectionParseAction {
|
||||||
if (workingCopy == null)
|
if (workingCopy == null)
|
||||||
return Status.CANCEL_STATUS;
|
return Status.CANCEL_STATUS;
|
||||||
|
|
||||||
IASTTranslationUnit ast = workingCopy.getLanguage().getASTTranslationUnit(workingCopy, ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX);
|
IIndex index= CCorePlugin.getIndexManager().getIndex(workingCopy.getCProject(),
|
||||||
|
IIndexManager.ADD_DEPENDENCIES | IIndexManager.ADD_DEPENDENT);
|
||||||
|
try {
|
||||||
|
index.acquireReadLock();
|
||||||
|
} catch (InterruptedException e1) {
|
||||||
|
return Status.CANCEL_STATUS;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
IASTTranslationUnit ast = workingCopy.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS);
|
||||||
IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength);
|
IASTName[] selectedNames = workingCopy.getLanguage().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
|
||||||
|
@ -75,10 +89,17 @@ public class OpenDefinitionAction extends SelectionParseAction {
|
||||||
if (binding != null) {
|
if (binding != null) {
|
||||||
final IName[] declNames = ast.getDefinitions(binding);
|
final IName[] declNames = ast.getDefinitions(binding);
|
||||||
if (declNames.length > 0) {
|
if (declNames.length > 0) {
|
||||||
|
IASTFileLocation fileloc = declNames[0].getFileLocation();
|
||||||
|
// no source location - TODO spit out an error in the status bar
|
||||||
|
if (fileloc != null) {
|
||||||
|
final IPath path = new Path(fileloc.getFileName());
|
||||||
|
final int offset = fileloc.getNodeOffset();
|
||||||
|
final int length = fileloc.getNodeLength();
|
||||||
|
|
||||||
runInUIThread(new Runnable() {
|
runInUIThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
open(declNames[0]);
|
open(path, offset, length);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
CUIPlugin.getDefault().log(e);
|
CUIPlugin.getDefault().log(e);
|
||||||
}
|
}
|
||||||
|
@ -87,6 +108,11 @@ public class OpenDefinitionAction extends SelectionParseAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
index.releaseReadLock();
|
||||||
|
}
|
||||||
|
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.eclipse.ui.IEditorSite;
|
||||||
import org.eclipse.ui.IFileEditorInput;
|
import org.eclipse.ui.IFileEditorInput;
|
||||||
import org.eclipse.ui.IViewSite;
|
import org.eclipse.ui.IViewSite;
|
||||||
import org.eclipse.ui.IWorkbenchSite;
|
import org.eclipse.ui.IWorkbenchSite;
|
||||||
|
import org.eclipse.ui.PartInitException;
|
||||||
import org.eclipse.ui.ide.IDE;
|
import org.eclipse.ui.ide.IDE;
|
||||||
import org.eclipse.ui.texteditor.IDocumentProvider;
|
import org.eclipse.ui.texteditor.IDocumentProvider;
|
||||||
import org.eclipse.ui.texteditor.ITextEditor;
|
import org.eclipse.ui.texteditor.ITextEditor;
|
||||||
|
@ -459,10 +460,15 @@ public class SelectionParseAction extends Action {
|
||||||
if (fileloc == null)
|
if (fileloc == null)
|
||||||
// no source location - TODO spit out an error in the status bar
|
// no source location - TODO spit out an error in the status bar
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
IPath path = new Path(fileloc.getFileName());
|
||||||
int currentOffset = fileloc.getNodeOffset();
|
int currentOffset = fileloc.getNodeOffset();
|
||||||
int currentLength = fileloc.getNodeLength();
|
int currentLength = fileloc.getNodeLength();
|
||||||
|
|
||||||
IPath path = new Path(fileloc.getFileName());
|
open(path, currentOffset, currentLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void open(IPath path, int currentOffset, int currentLength) throws PartInitException {
|
||||||
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
|
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
|
||||||
if (files.length > 0) {
|
if (files.length > 0) {
|
||||||
IEditorPart editor = IDE.openEditor(CUIPlugin.getActivePage(), files[0]);
|
IEditorPart editor = IDE.openEditor(CUIPlugin.getActivePage(), files[0]);
|
||||||
|
@ -484,7 +490,6 @@ public class SelectionParseAction extends Action {
|
||||||
textEditor.selectAndReveal(currentOffset, currentLength);
|
textEditor.selectAndReveal(currentOffset, currentLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
|
|
|
@ -744,11 +744,7 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (contentType != null) {
|
if (contentType != null) {
|
||||||
try {
|
|
||||||
return LanguageManager.getInstance().getLanguage(contentType);
|
return LanguageManager.getInstance().getLanguage(contentType);
|
||||||
} catch (CoreException exc) {
|
|
||||||
CUIPlugin.getDefault().log(exc.getStatus());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -7,14 +7,17 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.text.contentassist;
|
package org.eclipse.cdt.internal.ui.text.contentassist;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.jface.text.ITextViewer;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.IPDOM;
|
|
||||||
import org.eclipse.cdt.core.dom.IPDOMNode;
|
import org.eclipse.cdt.core.dom.IPDOMNode;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
|
||||||
|
@ -28,13 +31,12 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IField;
|
import org.eclipse.cdt.core.dom.ast.IField;
|
||||||
import org.eclipse.cdt.core.dom.ast.IType;
|
import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
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.text.contentassist.ICompletionContributor;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
|
||||||
import org.eclipse.cdt.ui.text.contentassist.ICompletionContributor;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
|
||||||
import org.eclipse.jface.text.ITextViewer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Doug Schaefer
|
* @author Doug Schaefer
|
||||||
|
@ -59,7 +61,7 @@ public class PDOMCompletionContributor extends DOMCompletionContributor implemen
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IPDOM pdom = CCorePlugin.getPDOMManager().getPDOM(workingCopy.getCProject());
|
PDOM pdom = (PDOM) CCorePlugin.getPDOMManager().getPDOM(workingCopy.getCProject());
|
||||||
IASTName[] names = completionNode.getNames();
|
IASTName[] names = completionNode.getNames();
|
||||||
for (int i = 0; i < names.length; ++i) {
|
for (int i = 0; i < names.length; ++i) {
|
||||||
IASTName name = names[i];
|
IASTName name = names[i];
|
||||||
|
@ -88,7 +90,7 @@ public class PDOMCompletionContributor extends DOMCompletionContributor implemen
|
||||||
IType type = expression.getExpressionType();
|
IType type = expression.getExpressionType();
|
||||||
if (type != null && type instanceof IBinding) {
|
if (type != null && type instanceof IBinding) {
|
||||||
IBinding binding = (IBinding)type;
|
IBinding binding = (IBinding)type;
|
||||||
PDOMLinkage linkage = ((PDOM)pdom).getLinkage(workingCopy.getLanguage());
|
PDOMLinkage linkage = pdom.getLinkage(name.getLinkage().getID());
|
||||||
PDOMBinding pdomBinding = linkage.adaptBinding(binding);
|
PDOMBinding pdomBinding = linkage.adaptBinding(binding);
|
||||||
if (pdomBinding != null) {
|
if (pdomBinding != null) {
|
||||||
pdomBinding.accept(new IPDOMVisitor() {
|
pdomBinding.accept(new IPDOMVisitor() {
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
* Anton Leherbauer (Wind River Systems)
|
* Anton Leherbauer (Wind River Systems)
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.text.folding;
|
package org.eclipse.cdt.internal.ui.text.folding;
|
||||||
|
@ -24,7 +25,9 @@ import java.util.Map;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.jface.preference.IPreferenceStore;
|
import org.eclipse.jface.preference.IPreferenceStore;
|
||||||
import org.eclipse.jface.text.Assert;
|
import org.eclipse.jface.text.Assert;
|
||||||
import org.eclipse.jface.text.BadLocationException;
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
|
@ -71,6 +74,7 @@ import org.eclipse.cdt.ui.text.folding.ICFoldingStructureProvider;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.editor.ASTProvider;
|
import org.eclipse.cdt.internal.ui.editor.ASTProvider;
|
||||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||||
|
import org.eclipse.cdt.internal.ui.editor.ASTProvider.ASTRunnable;
|
||||||
import org.eclipse.cdt.internal.ui.text.DocumentCharacterIterator;
|
import org.eclipse.cdt.internal.ui.text.DocumentCharacterIterator;
|
||||||
import org.eclipse.cdt.internal.ui.text.ICReconcilingListener;
|
import org.eclipse.cdt.internal.ui.text.ICReconcilingListener;
|
||||||
|
|
||||||
|
@ -1060,7 +1064,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void computeFoldingStructure(FoldingStructureComputationContext ctx) {
|
private void computeFoldingStructure(final FoldingStructureComputationContext ctx) {
|
||||||
if (fCommentFoldingEnabled) {
|
if (fCommentFoldingEnabled) {
|
||||||
// compute comment positions from partitioning
|
// compute comment positions from partitioning
|
||||||
try {
|
try {
|
||||||
|
@ -1079,13 +1083,20 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
if (fPreprocessorBranchFoldingEnabled) {
|
if (fPreprocessorBranchFoldingEnabled) {
|
||||||
IASTTranslationUnit ast= ctx.getAST();
|
IASTTranslationUnit ast= ctx.getAST();
|
||||||
if (ast == null) {
|
if (ast == null) {
|
||||||
ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider();
|
final ASTProvider astProvider= CUIPlugin.getDefault().getASTProvider();
|
||||||
ast= astProvider.getAST(getInputElement(), ASTProvider.WAIT_ACTIVE_ONLY, null);
|
IStatus status= astProvider.runOnAST(getInputElement(), ASTProvider.WAIT_ACTIVE_ONLY, null, new ASTRunnable() {
|
||||||
|
public IStatus runOnAST(IASTTranslationUnit ast) {
|
||||||
if (ast != null) {
|
if (ast != null) {
|
||||||
ctx.fAST= ast;
|
ctx.fAST= ast;
|
||||||
ctx.fASTPositionConverter= astProvider.getActivePositionConverter(getInputElement());
|
ctx.fASTPositionConverter= astProvider.getActivePositionConverter(getInputElement());
|
||||||
fInitialASTReconcile= false;
|
fInitialASTReconcile= false;
|
||||||
}
|
}
|
||||||
|
return Status.OK_STATUS;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!status.isOK()) {
|
||||||
|
CUIPlugin.getDefault().log(status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
computeFoldingStructure(ast, ctx);
|
computeFoldingStructure(ast, ctx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - initial API and implementation
|
* QNX Software Systems - initial API and implementation
|
||||||
* IBM Corporation
|
* IBM Corporation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.wizards.classwizard;
|
package org.eclipse.cdt.internal.ui.wizards.classwizard;
|
||||||
|
|
||||||
|
@ -23,6 +24,7 @@ import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IAdaptable;
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.jface.operation.IRunnableContext;
|
import org.eclipse.jface.operation.IRunnableContext;
|
||||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
|
@ -37,13 +39,15 @@ import org.eclipse.cdt.core.browser.IQualifiedTypeName;
|
||||||
import org.eclipse.cdt.core.browser.ITypeInfo;
|
import org.eclipse.cdt.core.browser.ITypeInfo;
|
||||||
import org.eclipse.cdt.core.browser.ITypeReference;
|
import org.eclipse.cdt.core.browser.ITypeReference;
|
||||||
import org.eclipse.cdt.core.browser.TypeSearchScope;
|
import org.eclipse.cdt.core.browser.TypeSearchScope;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
import org.eclipse.cdt.core.dom.ILinkage;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
|
||||||
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.ICPPNamespace;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||||
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
|
import org.eclipse.cdt.core.index.IndexFilter;
|
||||||
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.ICContainer;
|
import org.eclipse.cdt.core.model.ICContainer;
|
||||||
|
@ -56,12 +60,10 @@ import org.eclipse.cdt.core.parser.IScannerInfoProvider;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||||
import org.eclipse.cdt.internal.ui.viewsupport.IViewPartInputProvider;
|
import org.eclipse.cdt.internal.ui.viewsupport.IViewPartInputProvider;
|
||||||
import org.eclipse.cdt.internal.ui.wizards.filewizard.NewSourceFileGenerator;
|
import org.eclipse.cdt.internal.ui.wizards.filewizard.NewSourceFileGenerator;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
|
||||||
|
|
||||||
public class NewClassWizardUtil {
|
public class NewClassWizardUtil {
|
||||||
|
|
||||||
|
@ -381,16 +383,30 @@ public class NewClassWizardUtil {
|
||||||
* {@link #SEARCH_MATCH_NOTFOUND}.
|
* {@link #SEARCH_MATCH_NOTFOUND}.
|
||||||
*/
|
*/
|
||||||
public static int searchForCppType(IQualifiedTypeName typeName, ICProject project, Class queryType) {
|
public static int searchForCppType(IQualifiedTypeName typeName, ICProject project, Class queryType) {
|
||||||
if(project == null) {
|
IIndex index= null;
|
||||||
|
try {
|
||||||
|
if (project != null) {
|
||||||
|
index = CCorePlugin.getIndexManager().getIndex(project);
|
||||||
|
index.acquireReadLock();
|
||||||
|
}
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CUIPlugin.getDefault().log(e);
|
||||||
|
return SEARCH_MATCH_ERROR;
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
}
|
||||||
|
if (index == null) {
|
||||||
return SEARCH_MATCH_ERROR;
|
return SEARCH_MATCH_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
String fullyQualifiedTypeName = typeName.getFullyQualifiedName();
|
|
||||||
|
|
||||||
IPDOMManager pdomManager = CCorePlugin.getPDOMManager();
|
|
||||||
try {
|
try {
|
||||||
PDOM pdom = (PDOM)pdomManager.getPDOM(project);
|
String fullyQualifiedTypeName = typeName.getFullyQualifiedName();
|
||||||
IBinding[] bindings = pdom.findBindings(Pattern.compile(typeName.getName()), new NullProgressMonitor());
|
try {
|
||||||
|
IndexFilter filter= new IndexFilter() {
|
||||||
|
public boolean acceptLinkage(ILinkage linkage) {
|
||||||
|
return linkage.getID() == ILinkage.CPP_LINKAGE_ID;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// mstodo revisit, the pattern must be split
|
||||||
|
IBinding[] bindings = index.findBindings(Pattern.compile(typeName.getName()), true, filter, new NullProgressMonitor());
|
||||||
boolean sameTypeNameExists = false;
|
boolean sameTypeNameExists = false;
|
||||||
boolean sameNameDifferentTypeExists = false;
|
boolean sameNameDifferentTypeExists = false;
|
||||||
|
|
||||||
|
@ -399,7 +415,6 @@ public class NewClassWizardUtil {
|
||||||
|
|
||||||
//get the fully qualified name of this binding
|
//get the fully qualified name of this binding
|
||||||
String bindingFullName = CPPVisitor.renderQualifiedName(binding.getQualifiedName());
|
String bindingFullName = CPPVisitor.renderQualifiedName(binding.getQualifiedName());
|
||||||
|
|
||||||
Class currentNodeType = binding.getClass();
|
Class currentNodeType = binding.getClass();
|
||||||
// full binding
|
// full binding
|
||||||
if (queryType.isAssignableFrom(currentNodeType)) {
|
if (queryType.isAssignableFrom(currentNodeType)) {
|
||||||
|
@ -436,4 +451,8 @@ public class NewClassWizardUtil {
|
||||||
}
|
}
|
||||||
return SEARCH_MATCH_NOTFOUND;
|
return SEARCH_MATCH_NOTFOUND;
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
index.releaseReadLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue