1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-05 08:46:02 +02:00

Avoid logging of problem bindings using CallHierarchy or TypeHierarchy.

This commit is contained in:
Markus Schorn 2007-05-24 09:17:54 +00:00
parent 2645d4879d
commit 8af8fc67df
9 changed files with 106 additions and 100 deletions

View file

@ -7,12 +7,13 @@
*
* Contributors:
* Anton Leherbauer (Wind River Systems) - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.browser;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.browser.TypeReference;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ITranslationUnit;
@ -54,8 +55,8 @@ public class IndexTypeReference extends TypeReference {
IRegion region= new Region(getOffset(), getLength());
try {
return CElementHandleFactory.create(tu, binding, true, region, timestamp);
} catch (CoreException exc) {
} catch (DOMException exc) {
} catch (CoreException e) {
CCorePlugin.log(e);
}
}
return null;

View file

@ -46,9 +46,19 @@ import org.eclipse.jface.text.IRegion;
public class CElementHandleFactory {
private CElementHandleFactory() {}
public static ICElementHandle create(ITranslationUnit tu, IBinding binding, boolean definition,
IRegion region, long timestamp) throws CoreException, DOMException {
public static ICElementHandle create(ITranslationUnit tu, IBinding binding, boolean isDefinition,
IRegion region, long timestamp) throws CoreException {
try {
return internalCreate(tu, binding, isDefinition, region, timestamp);
}
catch (DOMException e) {
return null;
}
}
public static ICElementHandle internalCreate(ITranslationUnit tu, IBinding binding, boolean definition,
IRegion region, long timestamp) throws CoreException, DOMException {
ICElement parentElement= create(tu, binding.getScope());
if (parentElement == null) {
return null;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -19,7 +19,6 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.swt.widgets.Display;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexName;
@ -100,15 +99,13 @@ public class CHContentProvider extends AsyncTreeContentProvider {
}
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
} catch (DOMException e) {
CUIPlugin.getDefault().log(e);
} catch (InterruptedException e) {
}
}
return NO_CHILDREN;
}
private Object[] asyncronouslyComputeReferencedBy(CHNode parent) throws CoreException, InterruptedException, DOMException {
private Object[] asyncronouslyComputeReferencedBy(CHNode parent) throws CoreException, InterruptedException {
ICProject[] scope= CoreModel.getDefault().getCModel().getCProjects();
IIndex index= CCorePlugin.getIndexManager().getIndex(scope);
index.acquireReadLock();
@ -120,7 +117,7 @@ public class CHContentProvider extends AsyncTreeContentProvider {
}
}
private Object[] asyncronouslyComputeRefersTo(CHNode parent) throws CoreException, InterruptedException, DOMException {
private Object[] asyncronouslyComputeRefersTo(CHNode parent) throws CoreException, InterruptedException {
ICProject[] scope= CoreModel.getDefault().getCModel().getCProjects();
IIndex index= CCorePlugin.getIndexManager().getIndex(scope);
index.acquireReadLock();

View file

@ -14,7 +14,6 @@ package org.eclipse.cdt.internal.ui.callhierarchy;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexName;
@ -36,10 +35,9 @@ public class CHQueries {
/**
* Searches for functions and methods that call a given element.
* @throws DOMException
*/
public static CHNode[] findCalledBy(CHContentProvider cp, CHNode node,
IIndex index, IProgressMonitor pm) throws CoreException, DOMException {
public static CHNode[] findCalledBy(CHContentProvider cp, CHNode node, IIndex index, IProgressMonitor pm)
throws CoreException {
CalledByResult result= new CalledByResult();
ICElement callee= node.getRepresentedDeclaration();
if (! (callee instanceof ISourceReference)) {
@ -51,7 +49,8 @@ public class CHQueries {
return cp.createNodes(node, result);
}
private static void findCalledBy(IIndex index, IBinding callee, ICProject project, CalledByResult result) throws CoreException, DOMException {
private static void findCalledBy(IIndex index, IBinding callee, ICProject project, CalledByResult result)
throws CoreException {
if (callee != null) {
IIndexName[] names= index.findReferences(callee);
for (int i = 0; i < names.length; i++) {
@ -69,9 +68,9 @@ public class CHQueries {
/**
* Searches for all calls that are made within a given range.
* @throws DOMException
*/
public static CHNode[] findCalls(CHContentProvider cp, CHNode node, IIndex index, IProgressMonitor pm) throws CoreException, DOMException {
public static CHNode[] findCalls(CHContentProvider cp, CHNode node, IIndex index, IProgressMonitor pm)
throws CoreException {
ICElement caller= node.getRepresentedDeclaration();
CallsToResult result= new CallsToResult();
IIndexName callerName= IndexUI.elementToName(index, caller);

View file

@ -24,7 +24,6 @@ import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
@ -186,9 +185,6 @@ public class CallHierarchyUI {
catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
catch (DOMException e) {
CUIPlugin.getDefault().log(e);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
@ -229,9 +225,6 @@ public class CallHierarchyUI {
catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
catch (DOMException e) {
CUIPlugin.getDefault().log(e);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
}

View file

@ -131,7 +131,7 @@ public class OpenDeclarationsAction extends SelectionParseAction {
declNames= findNames(fIndex, ast, false, clsBinding);
}
} catch (DOMException e) {
CCorePlugin.log(e);
// don't log problem bindings.
}
}
}
@ -227,8 +227,6 @@ public class OpenDeclarationsAction extends SelectionParseAction {
}
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
} catch (DOMException e) {
CUIPlugin.getDefault().log(e);
}
}
if (elements.isEmpty()) {

View file

@ -31,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
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.ICElement;
import org.eclipse.cdt.ui.CUIPlugin;
@ -140,8 +141,6 @@ class THGraph {
fInputNode= addNode(inputHandle == null ? input : inputHandle);
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
} catch (DOMException e) {
CUIPlugin.getDefault().log(e);
}
}
}
@ -161,7 +160,7 @@ class THGraph {
ICElement elem= (ICElement) stack.remove(stack.size()-1);
THGraphNode graphNode= addNode(elem);
try {
IBinding binding = IndexUI.elementToBinding(index, elem);
IIndexBinding binding = IndexUI.elementToBinding(index, elem);
if (binding != null) {
addMembers(index, graphNode, binding);
}
@ -205,6 +204,7 @@ class THGraph {
}
}
} catch (DOMException e) {
// index bindings should not throw this kind of exception, might as well log it.
CUIPlugin.getDefault().log(e);
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
@ -254,33 +254,35 @@ class THGraph {
}
}
}
} catch (DOMException e) {
CUIPlugin.getDefault().log(e);
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
}
}
private void addMembers(IIndex index, THGraphNode graphNode, IBinding binding) throws DOMException, CoreException {
private void addMembers(IIndex index, THGraphNode graphNode, IBinding binding) throws CoreException {
if (graphNode.getMembers(false) == null) {
ArrayList memberList= new ArrayList();
if (binding instanceof ICPPClassType) {
ICPPClassType ct= (ICPPClassType) binding;
IBinding[] members= ct.getDeclaredFields();
addMemberElements(index, members, memberList);
members= ct.getDeclaredMethods();
addMemberElements(index, members, memberList);
}
else if (binding instanceof ICompositeType) {
ICompositeType ct= (ICompositeType) binding;
IBinding[] members= ct.getFields();
addMemberElements(index, members, memberList);
}
else if (binding instanceof IEnumeration) {
IEnumeration ct= (IEnumeration) binding;
IBinding[] members= ct.getEnumerators();
addMemberElements(index, members, memberList);
try {
if (binding instanceof ICPPClassType) {
ICPPClassType ct= (ICPPClassType) binding;
IBinding[] members= ct.getDeclaredFields();
addMemberElements(index, members, memberList);
members= ct.getDeclaredMethods();
addMemberElements(index, members, memberList);
}
else if (binding instanceof ICompositeType) {
ICompositeType ct= (ICompositeType) binding;
IBinding[] members= ct.getFields();
addMemberElements(index, members, memberList);
}
else if (binding instanceof IEnumeration) {
IEnumeration ct= (IEnumeration) binding;
IBinding[] members= ct.getEnumerators();
addMemberElements(index, members, memberList);
}
} catch (DOMException e) {
// problem bindings should not be reported to the log.
}
if (memberList.isEmpty()) {
graphNode.setMembers(NO_MEMBERS);
@ -291,7 +293,8 @@ class THGraph {
}
}
private void addMemberElements(IIndex index, IBinding[] members, ArrayList memberList) throws CoreException, DOMException {
private void addMemberElements(IIndex index, IBinding[] members, ArrayList memberList)
throws CoreException {
for (int i = 0; i < members.length; i++) {
IBinding binding = members[i];
ICElement[] elems= IndexUI.findRepresentative(index, binding);

View file

@ -176,9 +176,6 @@ public class TypeHierarchyUI {
catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
catch (DOMException e) {
CUIPlugin.getDefault().log(e);
}
catch (InterruptedException e) {
}
return null;
@ -212,32 +209,33 @@ public class TypeHierarchyUI {
catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
catch (DOMException e) {
CUIPlugin.getDefault().log(e);
}
catch (InterruptedException e) {
}
return null;
}
private static IBinding findTypeBinding(IBinding memberBinding) throws DOMException {
if (memberBinding instanceof IEnumerator) {
IType type= ((IEnumerator) memberBinding).getType();
if (type instanceof IBinding) {
return (IBinding) type;
private static IBinding findTypeBinding(IBinding memberBinding) {
try {
if (memberBinding instanceof IEnumerator) {
IType type= ((IEnumerator) memberBinding).getType();
if (type instanceof IBinding) {
return (IBinding) type;
}
}
}
else if (memberBinding instanceof ICPPMember) {
return ((ICPPMember) memberBinding).getClassOwner();
}
else if (memberBinding instanceof IField) {
return ((IField) memberBinding).getCompositeTypeOwner();
else if (memberBinding instanceof ICPPMember) {
return ((ICPPMember) memberBinding).getClassOwner();
}
else if (memberBinding instanceof IField) {
return ((IField) memberBinding).getCompositeTypeOwner();
}
} catch (DOMException e) {
// don't log problem bindings
}
return null;
}
private static ICElement findDefinition(ICProject project, IIndex index,
IASTName name, IBinding binding) throws CoreException, DOMException {
private static ICElement findDefinition(ICProject project, IIndex index, IASTName name, IBinding binding)
throws CoreException {
if (name != null && name.isDefinition()) {
return IndexUI.getCElementForName(project, index, name);
}
@ -249,8 +247,8 @@ public class TypeHierarchyUI {
return IndexUI.findAnyDeclaration(index, project, binding);
}
private static ICElement findDeclaration(ICProject project, IIndex index,
IASTName name, IBinding binding) throws CoreException, DOMException {
private static ICElement findDeclaration(ICProject project, IIndex index, IASTName name, IBinding binding)
throws CoreException {
if (name != null && name.isDefinition()) {
return IndexUI.getCElementForName(project, index, name);
}

View file

@ -65,7 +65,7 @@ import org.eclipse.cdt.internal.ui.editor.ASTProvider;
public class IndexUI {
private static final ICElementHandle[] EMPTY_ELEMENTS = new ICElementHandle[0];
public static IIndexBinding elementToBinding(IIndex index, ICElement element) throws CoreException, DOMException {
public static IIndexBinding elementToBinding(IIndex index, ICElement element) throws CoreException {
if (element instanceof ISourceReference) {
ISourceReference sf = ((ISourceReference)element);
ISourceRange range= sf.getSourceRange();
@ -90,23 +90,27 @@ public class IndexUI {
return null;
}
private static boolean checkBinding(IIndexBinding binding, ICElement element) throws DOMException {
switch(element.getElementType()) {
case ICElement.C_ENUMERATION:
return binding instanceof IEnumeration;
case ICElement.C_NAMESPACE:
return binding instanceof ICPPNamespace;
case ICElement.C_STRUCT:
return binding instanceof ICompositeType &&
((ICompositeType) binding).getKey() == ICompositeType.k_struct;
case ICElement.C_CLASS:
return binding instanceof ICPPClassType &&
((ICompositeType) binding).getKey() == ICPPClassType.k_class;
case ICElement.C_UNION:
return binding instanceof ICompositeType &&
((ICompositeType) binding).getKey() == ICompositeType.k_union;
case ICElement.C_TYPEDEF:
return binding instanceof ITypedef;
private static boolean checkBinding(IIndexBinding binding, ICElement element) {
try {
switch(element.getElementType()) {
case ICElement.C_ENUMERATION:
return binding instanceof IEnumeration;
case ICElement.C_NAMESPACE:
return binding instanceof ICPPNamespace;
case ICElement.C_STRUCT:
return binding instanceof ICompositeType &&
((ICompositeType) binding).getKey() == ICompositeType.k_struct;
case ICElement.C_CLASS:
return binding instanceof ICPPClassType &&
((ICompositeType) binding).getKey() == ICPPClassType.k_class;
case ICElement.C_UNION:
return binding instanceof ICompositeType &&
((ICompositeType) binding).getKey() == ICompositeType.k_union;
case ICElement.C_TYPEDEF:
return binding instanceof ITypedef;
}
} catch (DOMException e) {
// index bindings don't throw the DOMException.
}
return false;
}
@ -142,8 +146,7 @@ public class IndexUI {
return null;
}
public static ICElementHandle[] findRepresentative(IIndex index, IBinding binding)
throws CoreException, DOMException {
public static ICElementHandle[] findRepresentative(IIndex index, IBinding binding) throws CoreException {
ICElementHandle[] defs = IndexUI.findAllDefinitions(index, binding);
if (defs.length == 0) {
ICElementHandle elem = IndexUI.findAnyDeclaration(index, null, binding);
@ -154,7 +157,7 @@ public class IndexUI {
return defs;
}
public static ICElementHandle[] findAllDefinitions(IIndex index, IBinding binding) throws CoreException, DOMException {
public static ICElementHandle[] findAllDefinitions(IIndex index, IBinding binding) throws CoreException {
if (binding != null) {
IIndexName[] defs= index.findDefinitions(binding);
@ -172,7 +175,8 @@ public class IndexUI {
return EMPTY_ELEMENTS;
}
public static ICElementHandle getCElementForName(ICProject preferProject, IIndex index, IName declName) throws CoreException, DOMException {
public static ICElementHandle getCElementForName(ICProject preferProject, IIndex index, IName declName)
throws CoreException {
if (declName instanceof IASTName) {
return getCElementForName(preferProject, index, (IASTName) declName);
}
@ -182,7 +186,8 @@ public class IndexUI {
return null;
}
public static ICElementHandle getCElementForName(ICProject preferProject, IIndex index, IASTName declName) throws CoreException, DOMException {
public static ICElementHandle getCElementForName(ICProject preferProject, IIndex index, IASTName declName)
throws CoreException {
assert !declName.isReference();
IBinding binding= declName.resolveBinding();
if (binding != null) {
@ -212,7 +217,8 @@ public class IndexUI {
}
}
public static ICElementHandle getCElementForName(ICProject preferProject, IIndex index, IIndexName declName) throws CoreException, DOMException {
public static ICElementHandle getCElementForName(ICProject preferProject, IIndex index, IIndexName declName)
throws CoreException {
assert !declName.isReference();
ITranslationUnit tu= getTranslationUnit(preferProject, declName);
if (tu != null) {
@ -221,14 +227,15 @@ public class IndexUI {
return null;
}
public static ICElementHandle getCElementForName(ITranslationUnit tu, IIndex index, IIndexName declName) throws CoreException,
DOMException {
public static ICElementHandle getCElementForName(ITranslationUnit tu, IIndex index, IIndexName declName)
throws CoreException {
IRegion region= new Region(declName.getNodeOffset(), declName.getNodeLength());
long timestamp= declName.getFile().getTimestamp();
return CElementHandleFactory.create(tu, index.findBinding(declName), declName.isDefinition(), region, timestamp);
}
public static ICElementHandle findAnyDeclaration(IIndex index, ICProject preferProject, IBinding binding) throws CoreException, DOMException {
public static ICElementHandle findAnyDeclaration(IIndex index, ICProject preferProject, IBinding binding)
throws CoreException {
if (binding != null) {
IIndexName[] names= index.findNames(binding, IIndex.FIND_DECLARATIONS);
for (int i = 0; i < names.length; i++) {