From f687cd8f7a65284323880214a28d4b2a3fb52d66 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 6 Sep 2006 13:48:22 +0000 Subject: [PATCH] Add missing locks when accessing PDOM. --- .../ui/callhierarchy/CallHierarchyUI.java | 61 ++++++++++++------- .../internal/ui/missingapi/CIndexQueries.java | 8 ++- 2 files changed, 45 insertions(+), 24 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CallHierarchyUI.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CallHierarchyUI.java index a48181b237e..12cf7ec1a6b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CallHierarchyUI.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CallHierarchyUI.java @@ -22,6 +22,8 @@ import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; +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.IASTTranslationUnit; import org.eclipse.cdt.core.model.CoreModel; @@ -130,30 +132,45 @@ public class CallHierarchyUI { private static ICElement[] findDefinitions(ICProject project, IEditorInput editorInput, ITextSelection sel) throws CoreException { CIndexQueries index= CIndexQueries.getInstance(); - IASTName name= getSelectedName(editorInput, sel); - if (name != null) { - if (name.isDefinition()) { - ICElement elem= index.findDefinition(project, name); - if (elem != null) { - return new ICElement[]{elem}; - } + IPDOM pdom= CCorePlugin.getPDOMManager().getPDOM(project); + if (pdom != null) { + try { + pdom.acquireReadLock(); + } catch (InterruptedException e) { + return null; } - else { - ICElement[] elems= index.findAllDefinitions(project, name); - if (elems.length == 0) { - ICProject[] allProjects= CoreModel.getDefault().getCModel().getCProjects(); - elems= index.findAllDefinitions(allProjects, name); - if (elems.length == 0) { - ICElement elem= index.findAnyDeclaration(project, name); - if (elem == null) { - elem= index.findAnyDeclaration(allProjects, name); - } - if (elem != null) { - elems= new ICElement[] {elem}; - } + } + try { + IASTName name= getSelectedName(editorInput, sel); + if (name != null) { + if (name.isDefinition()) { + ICElement elem= index.findDefinition(project, name); + if (elem != null) { + return new ICElement[]{elem}; } } - return elems; + else { + ICElement[] elems= index.findAllDefinitions(project, name); + if (elems.length == 0) { + ICProject[] allProjects= CoreModel.getDefault().getCModel().getCProjects(); + elems= index.findAllDefinitions(allProjects, name); + if (elems.length == 0) { + ICElement elem= index.findAnyDeclaration(project, name); + if (elem == null) { + elem= index.findAnyDeclaration(allProjects, name); + } + if (elem != null) { + elems= new ICElement[] {elem}; + } + } + } + return elems; + } + } + } + finally { + if (pdom != null) { + pdom.releaseReadLock(); } } return null; @@ -168,7 +185,7 @@ public class CallHierarchyUI { if (workingCopy == null) return null; - int options= ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX; + int options= ILanguage.AST_SKIP_INDEXED_HEADERS | ILanguage.AST_USE_INDEX; IASTTranslationUnit ast = workingCopy.getLanguage().getASTTranslationUnit(workingCopy, options); FindNameForSelectionVisitor finder= new FindNameForSelectionVisitor(ast.getFilePath(), selectionStart, selectionLength); ast.accept(finder); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexQueries.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexQueries.java index f0cbc288116..e4da868d7eb 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexQueries.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexQueries.java @@ -55,7 +55,7 @@ import org.eclipse.cdt.internal.corext.util.CModelUtil; * @since 4.0 */ public class CIndexQueries { - private static final int ASTTU_OPTIONS = ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX; + private static final int ASTTU_OPTIONS = ILanguage.AST_SKIP_INDEXED_HEADERS | ILanguage.AST_USE_INDEX; private static final ICElement[] EMPTY_ELEMENTS = new ICElement[0]; private static final CIndexIncludeRelation[] EMPTY_INCLUDES = new CIndexIncludeRelation[0]; private static final CIndexQueries sInstance= new CIndexQueries(); @@ -231,6 +231,10 @@ public class CIndexQueries { return; } IASTName name= names[names.length-1]; + IASTName[] a= ast.getReferences(name.resolveBinding()); + if (a.length > 0) { + a[0]= null; + } for (int i = 0; i < scope.length; i++) { ICProject project = scope[i]; findCalledBy(name, project, result); @@ -274,7 +278,7 @@ public class CIndexQueries { } private IBinding getPDOMBinding(PDOM pdom, IASTName name) { - IBinding binding= name.resolveBinding(); + IBinding binding= name.resolveBinding(); IASTTranslationUnit tu= name.getTranslationUnit(); ILanguage lang= tu.getLanguage(); PDOMLinkage linkage;