1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 16:55:38 +02:00

Add missing locks when accessing PDOM.

This commit is contained in:
Markus Schorn 2006-09-06 13:48:22 +00:00
parent 683950da14
commit f687cd8f7a
2 changed files with 45 additions and 24 deletions

View file

@ -22,6 +22,8 @@ import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IWorkbenchPage; 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.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.model.CoreModel; 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 { private static ICElement[] findDefinitions(ICProject project, IEditorInput editorInput, ITextSelection sel) throws CoreException {
CIndexQueries index= CIndexQueries.getInstance(); CIndexQueries index= CIndexQueries.getInstance();
IASTName name= getSelectedName(editorInput, sel); IPDOM pdom= CCorePlugin.getPDOMManager().getPDOM(project);
if (name != null) { if (pdom != null) {
if (name.isDefinition()) { try {
ICElement elem= index.findDefinition(project, name); pdom.acquireReadLock();
if (elem != null) { } catch (InterruptedException e) {
return new ICElement[]{elem}; return null;
}
} }
else { }
ICElement[] elems= index.findAllDefinitions(project, name); try {
if (elems.length == 0) { IASTName name= getSelectedName(editorInput, sel);
ICProject[] allProjects= CoreModel.getDefault().getCModel().getCProjects(); if (name != null) {
elems= index.findAllDefinitions(allProjects, name); if (name.isDefinition()) {
if (elems.length == 0) { ICElement elem= index.findDefinition(project, name);
ICElement elem= index.findAnyDeclaration(project, name); if (elem != null) {
if (elem == null) { return new ICElement[]{elem};
elem= index.findAnyDeclaration(allProjects, name);
}
if (elem != null) {
elems= 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; return null;
@ -168,7 +185,7 @@ public class CallHierarchyUI {
if (workingCopy == null) if (workingCopy == null)
return 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); IASTTranslationUnit ast = workingCopy.getLanguage().getASTTranslationUnit(workingCopy, options);
FindNameForSelectionVisitor finder= new FindNameForSelectionVisitor(ast.getFilePath(), selectionStart, selectionLength); FindNameForSelectionVisitor finder= new FindNameForSelectionVisitor(ast.getFilePath(), selectionStart, selectionLength);
ast.accept(finder); ast.accept(finder);

View file

@ -55,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_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 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();
@ -231,6 +231,10 @@ public class CIndexQueries {
return; return;
} }
IASTName name= names[names.length-1]; 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++) { for (int i = 0; i < scope.length; i++) {
ICProject project = scope[i]; ICProject project = scope[i];
findCalledBy(name, project, result); findCalledBy(name, project, result);