diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHContentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHContentProvider.java index 3f9063bac74..6ba693082fb 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHContentProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHContentProvider.java @@ -12,10 +12,6 @@ package org.eclipse.cdt.internal.ui.callhierarchy; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -23,15 +19,7 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.text.Region; import org.eclipse.swt.widgets.Display; -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.IPositionConverter; -import org.eclipse.cdt.core.dom.ast.IASTName; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; -import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IFunctionDeclaration; -import org.eclipse.cdt.core.model.ILanguage; -import org.eclipse.cdt.core.model.IParent; import org.eclipse.cdt.core.model.ISourceRange; import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.core.model.ITranslationUnit; @@ -39,8 +27,11 @@ import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.internal.corext.util.CModelUtil; +import org.eclipse.cdt.internal.ui.missingapi.CElementSet; import org.eclipse.cdt.internal.ui.missingapi.CIndexQueries; -import org.eclipse.cdt.internal.ui.missingapi.CIndexQueries.IPDOMReference; +import org.eclipse.cdt.internal.ui.missingapi.CIndexReference; +import org.eclipse.cdt.internal.ui.missingapi.CalledByResult; +import org.eclipse.cdt.internal.ui.missingapi.CallsToResult; import org.eclipse.cdt.internal.ui.viewsupport.AsyncTreeContentProvider; /** @@ -101,37 +92,63 @@ public class CHContentProvider extends AsyncTreeContentProvider { } return NO_CHILDREN; } - - private static IASTName toASTName(ICElement elem) throws CoreException { - if (elem instanceof ISourceReference) { - ISourceReference sf= (ISourceReference) elem; - ISourceRange range = sf.getSourceRange(); - ITranslationUnit tu = sf.getTranslationUnit(); - if (tu != null) { - 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()); - if (names.length > 0) { - return names[names.length-1]; - } - } - } - return null; - } private Object[] asyncronouslyComputeReferencedBy(CHNode parent, ICElement elem) { try { - IASTName name = toASTName(elem); - if (name != null) { - IPDOMReference[] refs= CIndexQueries.getInstance().findReferences(name, NPM); - HashMap refsPerElement = sortPerElement(refs); + CalledByResult calledBy= CIndexQueries.getInstance().findCalledBy(elem, NPM); + ArrayList result= new ArrayList(); + + ICElement[] elements= calledBy.getElements(); + for (int i = 0; i < elements.length; i++) { + ICElement element = elements[i]; + CIndexReference[] refs= calledBy.getReferences(element); + if (refs != null && refs.length > 0) { + CHNode node = createRefbyNode(parent, element, refs); + result.add(node); + } + } + return result.toArray(); + } catch (CoreException e) { + CUIPlugin.getDefault().log(e); + } catch (InterruptedException e) { + } + return NO_CHILDREN; + } + + private CHNode createRefbyNode(CHNode parent, ICElement element, CIndexReference[] refs) { + ITranslationUnit tu= CModelUtil.getTranslationUnit(element); + CHNode node= new CHNode(parent, tu, refs[0].getTimestamp(), element); + for (int i = 0; i < refs.length; i++) { + CIndexReference reference = refs[i]; + node.addReference(new CHReferenceInfo(reference.getOffset(), reference.getLength())); + } + return node; + } + + private CHNode createReftoNode(CHNode parent, ITranslationUnit tu, ICElement[] elements, CIndexReference[] references) { + CIndexReference firstRef= references[0]; + CHNode node= new CHNode(parent, tu, firstRef.getTimestamp(), elements[0]); + for (int i = 0; i < references.length; i++) { + CIndexReference reference = references[i]; + node.addReference(new CHReferenceInfo(reference.getOffset(), reference.getLength())); + } + return node; + } + + private Object[] asyncronouslyComputeRefersTo(CHNode parent, ICElement elem) { + try { + if (elem instanceof ISourceReference) { + ISourceReference sf= (ISourceReference) elem; + ITranslationUnit tu= sf.getTranslationUnit(); + ISourceRange range= sf.getSourceRange(); + CallsToResult callsTo= CIndexQueries.getInstance().findCallsToInRange(tu, new Region(range.getStartPos(), range.getLength()), NPM); ArrayList result= new ArrayList(); - for (Iterator iter= refsPerElement.entrySet().iterator(); iter.hasNext(); ) { - Map.Entry entry= (Map.Entry) iter.next(); - ICElement element= (ICElement) entry.getKey(); - List references= (List) entry.getValue(); - if (!references.isEmpty()) { - CHNode node = createRefbyNode(parent, element, references); + CElementSet[] elementSets= callsTo.getElementSets(); + for (int i = 0; i < elementSets.length; i++) { + CElementSet set = elementSets[i]; + if (!set.isEmpty()) { + CIndexReference[] refs= callsTo.getReferences(set); + CHNode node = createReftoNode(parent, tu, set.getElements(), refs); result.add(node); } } @@ -144,74 +161,6 @@ public class CHContentProvider extends AsyncTreeContentProvider { return NO_CHILDREN; } - private CHNode createRefbyNode(CHNode parent, ICElement element, List references) { - IPDOMReference firstRef= (IPDOMReference) references.get(0); - ITranslationUnit tu= CModelUtil.getTranslationUnit(element); - CHNode node= new CHNode(parent, tu, firstRef.getTimestamp(), element); - for (Iterator iter = references.iterator(); iter.hasNext(); ) { - IPDOMReference nextRef = (IPDOMReference) iter.next(); - node.addReference(new CHReferenceInfo(nextRef.getOffset(), nextRef.getLength())); - } - return node; - } - - private HashMap sortPerElement(IPDOMReference[] refs) throws CoreException { - HashMap refsPerElement= new HashMap(); - for (int i = 0; i < refs.length; i++) { - IPDOMReference reference = refs[i]; - ICElement caller= findCaller(reference); - if (caller != null) { - addToMap(caller, reference, refsPerElement); - } - } - return refsPerElement; - } - - private ICElement findCaller(IPDOMReference reference) throws CoreException { - ITranslationUnit tu= reference.getTranslationUnit(); - long timestamp= reference.getTimestamp(); - IPositionConverter pc= CCorePlugin.getPositionTrackerManager().findPositionConverter(tu.getPath(), timestamp); - int offset= reference.getOffset(); - if (pc != null) { - offset= pc.historicToActual(new Region(offset, 0)).getOffset(); - } - return findCaller(tu, offset); - } - - private ICElement findCaller(ICElement element, int offset) throws CModelException { - if (element == null || (element instanceof IFunctionDeclaration)) { - return element; - } - if (element instanceof IParent) { - ICElement[] children= ((IParent) element).getChildren(); - for (int i = 0; i < children.length; i++) { - ICElement child = children[i]; - if (child instanceof ISourceReference) { - ISourceRange sr= ((ISourceReference) child).getSourceRange(); - int startPos= sr.getStartPos(); - if (startPos <= offset && offset < startPos + sr.getLength()) { - return findCaller(child, offset); - } - } - } - } - return null; - } - - private void addToMap(ICElement caller, IPDOMReference reference, Map map) { - List list= (List) map.get(caller); - if (list == null) { - list= new ArrayList(); - map.put(caller, list); - } - list.add(reference); - } - - private Object[] asyncronouslyComputeRefersTo(CHNode parent, ICElement elem) { - // mstodo Auto-generated method stub - return NO_CHILDREN; - } - public void setComputeReferencedBy(boolean value) { fComputeReferencedBy = value; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CElementSet.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CElementSet.java new file mode 100644 index 00000000000..7291e18a21d --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CElementSet.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2006 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.ui.missingapi; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.eclipse.cdt.core.model.ICElement; + +public class CElementSet { + private Set fSet= new HashSet(); + private int fHashCode; + + CElementSet( ICElement[] elements) { + fSet.addAll(Arrays.asList(elements)); + fHashCode= 0; + for (int i = 0; i < elements.length; i++) { + fHashCode = 31*fHashCode + elements[i].hashCode(); + } + } + + public int hashCode() { + return fHashCode; + } + + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final CElementSet other = (CElementSet) obj; + if (fHashCode != other.fHashCode) { + return false; + } + if (fSet == null) { + if (other.fSet != null) { + return false; + } + } + else { + if (fSet.size() != other.fSet.size()) { + return false; + } + for (Iterator iter = fSet.iterator(); iter.hasNext(); ) { + if (!other.fSet.contains(iter.next())) { + return false; + } + } + } + return true; + } + + public boolean isEmpty() { + return fSet.isEmpty(); + } + + public ICElement[] getElements() { + return (ICElement[]) fSet.toArray(new ICElement[fSet.size()]); + } +} \ No newline at end of file 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 36239bd3b67..53b82a473b3 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 @@ -23,19 +23,32 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.Region; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.IPositionConverter; +import org.eclipse.cdt.core.dom.ast.IASTFileLocation; 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.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.IFunctionDeclaration; +import org.eclipse.cdt.core.model.ILanguage; +import org.eclipse.cdt.core.model.IParent; +import org.eclipse.cdt.core.model.ISourceRange; +import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.core.model.IVariableDeclaration; 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.PDOMFile; import org.eclipse.cdt.internal.core.pdom.dom.PDOMInclude; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMName; public class CIndexQueries { public static class IPDOMInclude { @@ -67,29 +80,7 @@ public class CIndexQueries { } } - public static class IPDOMReference { - private IASTName fName; - private ICProject fProject; - - public IPDOMReference(ICProject cproject, IASTName name) { - fProject= cproject; - fName= name; - } - public ITranslationUnit getTranslationUnit() throws CoreException { - return toTranslationUnit(fProject, fName); - } - public int getOffset() { - return fName.getFileLocation().getNodeOffset(); - } - public long getTimestamp() { - return 0; - } - public int getLength() { - return fName.getFileLocation().getNodeLength(); - } - } - - private static final IPDOMInclude[] EMPTY_INCLUDES = new IPDOMInclude[0]; + private static final IPDOMInclude[] EMPTY_INCLUDES = new IPDOMInclude[0]; private static final CIndexQueries sInstance= new CIndexQueries(); public static CIndexQueries getInstance() { @@ -184,20 +175,45 @@ public class CIndexQueries { return EMPTY_INCLUDES; } - public IPDOMReference[] findReferences(IASTName name, IProgressMonitor pm) throws CoreException, InterruptedException { - ArrayList result= new ArrayList(); + public CalledByResult findCalledBy(ICElement callee, IProgressMonitor pm) throws CoreException, InterruptedException { LinkedList projects= new LinkedList(Arrays.asList(CoreModel.getDefault().getCModel().getCProjects())); - - // resolve the binding. - name.resolveBinding(); + IASTName name= toASTName(callee); - for (Iterator iter = projects.iterator(); iter.hasNext();) { - findReferences(name, (ICProject) iter.next(), result); + CalledByResult result= new CalledByResult(); + if (name != null) { + // resolve the binding. + name.resolveBinding(); + + for (Iterator iter = projects.iterator(); iter.hasNext();) { + findCalledBy(name, (ICProject) iter.next(), result); + } } - return (IPDOMReference[]) result.toArray(new IPDOMReference[result.size()]); + return result; } - private void findReferences(IASTName name, ICProject project, Collection result) throws InterruptedException, CoreException { + private IASTName toASTName(ICElement elem) throws CoreException { + if (elem instanceof ISourceReference) { + ISourceReference sf= (ISourceReference) elem; + ISourceRange range = sf.getSourceRange(); + ITranslationUnit tu = sf.getTranslationUnit(); + if (tu != null) { + ILanguage language = tu.getLanguage(); + IASTTranslationUnit ast = language.getASTTranslationUnit(tu, ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX); + return getASTName(language, ast, range); + } + } + return null; + } + + private static IASTName getASTName(ILanguage language, IASTTranslationUnit ast, ISourceRange range) { + IASTName[] names = language.getSelectedNames(ast, range.getIdStartPos(), range.getIdLength()); + if (names.length > 0) { + return names[names.length-1]; + } + return null; + } + + private void findCalledBy(IASTName name, ICProject project, CalledByResult result) throws InterruptedException, CoreException { PDOM pdom= (PDOM) CCorePlugin.getPDOMManager().getPDOM(project); if (pdom != null) { pdom.acquireReadLock(); @@ -207,7 +223,10 @@ public class CIndexQueries { IASTName[] names= pdom.getReferences(binding); for (int i = 0; i < names.length; i++) { IASTName rname = names[i]; - result.add(new IPDOMReference(project, rname)); + ITranslationUnit tu= toTranslationUnit(project, name); + CIndexReference ref= new CIndexReference(tu, rname); + ICElement elem= findCaller(ref); + result.add(elem, ref); } } } @@ -216,4 +235,123 @@ public class CIndexQueries { } } } + + public CallsToResult findCallsToInRange(ITranslationUnit tu, IRegion range, IProgressMonitor pm) throws CoreException, InterruptedException { + CallsToResult result= new CallsToResult(); + ICProject project = tu.getCProject(); + PDOM pdom= (PDOM) CCorePlugin.getPDOMManager().getPDOM(project); + if (pdom != null) { + pdom.acquireReadLock(); + try { + IPath location= locationForTU(tu); + PDOMFile file= pdom.getFile(location); + if (file != null) { + // mstodo use correct timestamp + long timestamp= location.toFile().lastModified(); + IPositionConverter pc= CCorePlugin.getPositionTrackerManager().findPositionConverter(tu.getPath(), timestamp); + if (pc != null) { + range= pc.historicToActual(range); + } + PDOMName name= file.getFirstName(); + while (name != null) { + if (name.isReference()) { + IASTFileLocation loc= name.getFileLocation(); + if (encloses(range, loc.getNodeOffset(), loc.getNodeLength())) { + ICElement[] defs= findDefinitions(project, name); + if (defs != null && defs.length > 0) { + CIndexReference ref= new CIndexReference(tu, name); + result.add(defs, ref); + } + } + } + name= name.getNextInFile(); + } + } + } + finally { + pdom.releaseReadLock(); + } + } + return result; + } + + private ICElement[] findDefinitions(ICProject project, PDOMName name) throws CoreException { + ArrayList defs= new ArrayList(); + PDOMBinding binding= name.getPDOMBinding(); + if (binding != null) { + PDOMName declName= binding.getFirstDefinition(); + while (declName != null) { + ICElement elem= findEnclosingElement(project, declName); + if (elem != null) { + defs.add(elem); + } + declName= declName.getNextInBinding(); + } + if (defs.isEmpty()) { + declName= binding.getFirstDeclaration(); + while (declName != null) { + ICElement elem= findEnclosingElement(project, declName); + if (elem != null) { + defs.add(elem); + } + declName= declName.getNextInBinding(); + } + } + } + return (ICElement[]) defs.toArray(new ICElement[defs.size()]); + } + + private boolean encloses(IRegion range, int nodeOffset, int nodeLength) { + int d1= nodeOffset - range.getOffset(); + int d2= range.getLength() - nodeLength - d1; + return d1 >= 0 && d2 >= 0; + } + + private ICElement findEnclosingElement(ICProject project, PDOMName declName) throws CoreException { + ITranslationUnit tu= toTranslationUnit(project, declName); + if (tu != null) { + // mstodo use correct timestamp + // PDOMFile file= declName.getFile(); + long timestamp= tu.getPath().toFile().lastModified(); + IPositionConverter pc= CCorePlugin.getPositionTrackerManager().findPositionConverter(tu.getPath(), timestamp); + int offset= declName.getNodeOffset(); + if (pc != null) { + offset= pc.historicToActual(new Region(offset, 0)).getOffset(); + } + return findElement(tu, offset, true); + } + return null; + } + + private ICElement findCaller(CIndexReference reference) throws CoreException { + ITranslationUnit tu= reference.getTranslationUnit(); + long timestamp= reference.getTimestamp(); + IPositionConverter pc= CCorePlugin.getPositionTrackerManager().findPositionConverter(tu.getPath(), timestamp); + int offset= reference.getOffset(); + if (pc != null) { + offset= pc.historicToActual(new Region(offset, 0)).getOffset(); + } + return findElement(tu, offset, false); + } + + private ICElement findElement(ICElement element, int offset, boolean allowVars) throws CModelException { + if (element == null || (element instanceof IFunctionDeclaration) || + (allowVars && element instanceof IVariableDeclaration)) { + return element; + } + if (element instanceof IParent) { + ICElement[] children= ((IParent) element).getChildren(); + for (int i = 0; i < children.length; i++) { + ICElement child = children[i]; + if (child instanceof ISourceReference) { + ISourceRange sr= ((ISourceReference) child).getSourceRange(); + int startPos= sr.getStartPos(); + if (startPos <= offset && offset < startPos + sr.getLength()) { + return findElement(child, offset, allowVars); + } + } + } + } + return null; + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexReference.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexReference.java new file mode 100644 index 00000000000..9388baa21ef --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexReference.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2006 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.ui.missingapi; + +import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.model.ITranslationUnit; + +public class CIndexReference { + private int fOffset; + private int fLength; + private ITranslationUnit fTranslationUnit; + + public CIndexReference(ITranslationUnit tu, IASTName name) { + fTranslationUnit= tu; + fOffset= name.getFileLocation().getNodeOffset(); + fLength= name.getFileLocation().getNodeLength(); + } + public ITranslationUnit getTranslationUnit() { + return fTranslationUnit; + } + public int getOffset() { + return fOffset; + } + public long getTimestamp() { + return 0; + } + public int getLength() { + return fLength; + } +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CalledByResult.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CalledByResult.java new file mode 100644 index 00000000000..924e6a27171 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CalledByResult.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2006 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.ui.missingapi; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.cdt.core.model.ICElement; + +public class CalledByResult { + private Map fElementToReferences= new HashMap(); + + public ICElement[] getElements() { + Set elements = fElementToReferences.keySet(); + return (ICElement[]) elements.toArray(new ICElement[elements.size()]); + } + + public CIndexReference[] getReferences(ICElement calledElement) { + List references= (List) fElementToReferences.get(calledElement); + return (CIndexReference[]) references.toArray(new CIndexReference[references.size()]); + } + + public void add(ICElement elem, CIndexReference ref) { + List list= (List) fElementToReferences.get(elem); + if (list == null) { + list= new ArrayList(); + fElementToReferences.put(elem, list); + } + list.add(ref); + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CallsToResult.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CallsToResult.java new file mode 100644 index 00000000000..66abc541c61 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CallsToResult.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2006 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.ui.missingapi; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.cdt.core.model.ICElement; + +public class CallsToResult { + private Map fElementSetsToReferences= new HashMap(); + + public CElementSet[] getElementSets() { + Set elementSets = fElementSetsToReferences.keySet(); + return (CElementSet[]) elementSets.toArray(new CElementSet[elementSets.size()]); + } + + public CIndexReference[] getReferences(CElementSet elementSet) { + List references= (List) fElementSetsToReferences.get(elementSet); + return (CIndexReference[]) references.toArray(new CIndexReference[references.size()]); + } + + public void add(ICElement[] elems, CIndexReference ref) { + CElementSet key= new CElementSet(elems); + List list= (List) fElementSetsToReferences.get(key); + if (list == null) { + list= new ArrayList(); + fElementSetsToReferences.put(key, list); + } + list.add(ref); + } +}