1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 08:45:44 +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.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);

View file

@ -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);