From cc1407df9d2b5be69d2db99c314c1fa8f5d4decc Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 8 Nov 2006 08:39:12 +0000 Subject: [PATCH] Include Browser: using offsets from index --- .../index/tests/IndexIncludeTest.java | 40 ++++++- .../cdt/internal/core/model/CModelStatus.java | 5 +- .../core/model/CoreModelMessages.properties | 1 + .../core/parser/scanner2/DOMScanner.java | 4 +- .../ui/tests/viewsupport/AsyncViewerTest.java | 12 +- .../ui/includebrowser/IBContentProvider.java | 105 +++++++++++++----- .../internal/ui/includebrowser/IBNode.java | 10 +- .../ui/includebrowser/IBViewPart.java | 2 +- .../ui/missingapi/CIndexIncludeRelation.java | 53 --------- .../internal/ui/missingapi/CIndexQueries.java | 87 --------------- 10 files changed, 134 insertions(+), 185 deletions(-) delete mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexIncludeRelation.java diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java index 878a952d02f..4c5a1db29ae 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexIncludeTest.java @@ -114,7 +114,7 @@ public class IndexIncludeTest extends IndexTestBase { private void checkContext() throws Exception { final long timestamp= System.currentTimeMillis(); final IFile file= (IFile) fProject.getProject().findMember(new Path("included.h")); - assertNotNull(file); + assertNotNull("Can't find included.h", file); waitForIndexer(); ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { @@ -122,12 +122,13 @@ public class IndexIncludeTest extends IndexTestBase { file.setContents(new ByteArrayInputStream( "int included; int CONTEXT;\n".getBytes()), false, false, NPM); } }, NPM); - TestSourceReader.waitUntilFileIsIndexed(fIndex, file, 1000); + assertTrue("Timestamp was not increased", file.getLocalTimeStamp() >= timestamp); + TestSourceReader.waitUntilFileIsIndexed(fIndex, file, 4000); fIndex.acquireReadLock(); try { IIndexFile ifile= fIndex.getFile(file.getLocation()); - assertNotNull(ifile); - assertTrue(ifile.getTimestamp() >= timestamp); + assertNotNull("Can't find " + file.getLocation(), ifile); + assertTrue("timestamp not ok", ifile.getTimestamp() >= timestamp); IIndexBinding[] result= fIndex.findBindings(Pattern.compile("testInclude_cpp"), true, IndexFilter.ALL, NPM); assertEquals(1, result.length); @@ -140,7 +141,6 @@ public class IndexIncludeTest extends IndexTestBase { // {source20061107} // #include "user20061107.h" // #include - public void testIncludeProperties() throws Exception { waitForIndexer(); TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()}; @@ -169,6 +169,35 @@ public class IndexIncludeTest extends IndexTestBase { TestScannerProvider.sIncludes= null; } } + + public void testIncludeProperties_2() throws Exception { + TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()}; + try { + TestSourceReader.createFile(fProject.getProject(), "header20061107.h", ""); + String content = "// comment \n#include \"header20061107.h\"\n"; + IFile file= TestSourceReader.createFile(fProject.getProject(), "intermed20061107.h", content); + TestSourceReader.createFile(fProject.getProject(), "source20061107.cpp", "#include \"intermed20061107.h\"\n"); + CCoreInternals.getPDOMManager().getIndexer(fProject).reindex(); + waitForIndexer(); + + + fIndex.acquireReadLock(); + try { + IIndexFile ifile= fIndex.getFile(file.getLocation()); + assertNotNull(ifile); + IIndexInclude[] includes= ifile.getIncludes(); + assertEquals(1, includes.length); + + checkInclude(includes[0], content, "header20061107.h", false); + } + finally { + fIndex.releaseReadLock(); + } + } + finally { + TestScannerProvider.sIncludes= null; + } + } private void checkInclude(IIndexInclude include, String content, String includeName, boolean isSystem) throws CoreException { int offset= content.indexOf(includeName); @@ -176,4 +205,5 @@ public class IndexIncludeTest extends IndexTestBase { assertEquals(includeName.length(), include.getNameLength()); assertEquals(isSystem, include.isSystemInclude()); } + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java index 247dc89303e..eae2b8cfa88 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java @@ -7,6 +7,7 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.model; @@ -189,7 +190,7 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus return CoreModelMessages.getFormattedString("status.ParserError"); //$NON-NLS-1$ case ELEMENT_DOES_NOT_EXIST : - return CoreModelMessages.getFormattedString("element.doesNotExist", getFirstElementName()); //$NON-NLS-1$ + return CoreModelMessages.getFormattedString("status.elementDoesNotExist", getFirstElementName()); //$NON-NLS-1$ case EVALUATION_ERROR : return CoreModelMessages.getFormattedString("status.evaluationError", getString()); //$NON-NLS-1$ @@ -250,7 +251,7 @@ public class CModelStatus extends Status implements ICModelStatus, ICModelStatus if (fString != null) { return fString; } - return CoreModelMessages.getFormattedString("status.nameCollision", sb.toString()); //$NON-NLS-1$ //$NON-NLS-2$ + return CoreModelMessages.getFormattedString("status.nameCollision", sb.toString()); //$NON-NLS-1$ case NO_ELEMENTS_TO_PROCESS : return CoreModelMessages.getFormattedString("operation.needElements"); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.properties b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.properties index 510a10b7f15..2927794e6d6 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.properties +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.properties @@ -46,6 +46,7 @@ workingCopy.commit = Committing working copy... ### status status.cannotUseDeviceOnPath = Operation requires a path with no device. Path specified was: {0} +status.elementDoesNotExist = Element {0} does not exist. status.coreException = Core exception. status.defaultPackageReadOnly = Default package is read-only. status.evaluationError = Evaluation error: {0}. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java index fc3b3c3b48e..b73126e6b36 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java @@ -141,7 +141,9 @@ public class DOMScanner extends BaseScanner { char[] filenamePath, boolean local, int startOffset, int startingLineNumber, int nameOffset, int nameEndOffset, int nameLine, int endOffset, int endLine, boolean isForced) { - return new DOMInclusion(filenamePath, getGlobalOffset(startOffset), nameOffset, nameEndOffset, fileName, !local); + return new DOMInclusion(filenamePath, getGlobalOffset(startOffset), + getGlobalOffset(nameOffset), getGlobalOffset(nameEndOffset), + fileName, !local); } /* diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/viewsupport/AsyncViewerTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/viewsupport/AsyncViewerTest.java index 63838c2a6e0..5d4961a4058 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/viewsupport/AsyncViewerTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/viewsupport/AsyncViewerTest.java @@ -192,13 +192,13 @@ public class AsyncViewerTest extends BaseUITestCase { // + a // + b - dlg.fViewer.setInput(root); runEventQueue(0); + dlg.fViewer.setInput(root); runEventQueue(50); assertEquals(2, countVisibleItems(dlg.fViewer)); // - a // - ... // + b - dlg.fViewer.setExpandedState(a, true); runEventQueue(0); + dlg.fViewer.setExpandedState(a, true); runEventQueue(50); assertEquals("...", dlg.fViewer.getTree().getItem(0).getItem(0).getText()); assertEquals(3, countVisibleItems(dlg.fViewer)); @@ -211,10 +211,10 @@ public class AsyncViewerTest extends BaseUITestCase { // + a // + b dlg.fViewer.setInput(null); - dlg.fViewer.setInput(root); runEventQueue(0); + dlg.fViewer.setInput(root); runEventQueue(50); // expand async with two children - dlg.fViewer.setExpandedState(b, true); runEventQueue(0); + dlg.fViewer.setExpandedState(b, true); runEventQueue(50); // + a // - b // - ... @@ -231,7 +231,7 @@ public class AsyncViewerTest extends BaseUITestCase { // + a // + b dlg.fViewer.setInput(null); - dlg.fViewer.setInput(root); runEventQueue(0); + dlg.fViewer.setInput(root); runEventQueue(50); // wait until children are computed (for the sake of the +-sign) runEventQueue(800); @@ -255,7 +255,7 @@ public class AsyncViewerTest extends BaseUITestCase { }, 150) }, 0); - dlg.fViewer.setInput(root); runEventQueue(0); + dlg.fViewer.setInput(root); runEventQueue(50); assertEquals(2, countVisibleItems(dlg.fViewer)); dlg.fContentProvider.recompute(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBContentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBContentProvider.java index f28e8a3e239..c1a65c8bb83 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBContentProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBContentProvider.java @@ -13,18 +13,21 @@ package org.eclipse.cdt.internal.ui.includebrowser; import java.util.ArrayList; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; import org.eclipse.swt.widgets.Display; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.index.IIndexFile; +import org.eclipse.cdt.core.index.IIndexInclude; +import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.ui.CUIPlugin; -import org.eclipse.cdt.internal.ui.missingapi.CIndexQueries; -import org.eclipse.cdt.internal.ui.missingapi.CIndexIncludeRelation; import org.eclipse.cdt.internal.ui.viewsupport.AsyncTreeContentProvider; /** @@ -53,7 +56,7 @@ public class IBContentProvider extends AsyncTreeContentProvider { protected Object[] syncronouslyComputeChildren(Object parentElement) { if (parentElement instanceof ITranslationUnit) { ITranslationUnit tu = (ITranslationUnit) parentElement; - return new Object[] { new IBNode(null, new IBFile(tu), null, null, 0, 0) }; + return new Object[] { new IBNode(null, new IBFile(tu), null, null, 0, 0, 0) }; } if (parentElement instanceof IBNode) { IBNode node = (IBNode) parentElement; @@ -69,51 +72,64 @@ public class IBContentProvider extends AsyncTreeContentProvider { if (parentElement instanceof IBNode) { IBNode node = (IBNode) parentElement; ITranslationUnit tu= node.getRepresentedTranslationUnit(); - if (tu != null) { - CIndexIncludeRelation[] includes; + if (tu == null) { + return NO_CHILDREN; + } + + IIndex index; + try { + index = CCorePlugin.getIndexManager().getIndex(tu.getCProject(), + fComputeIncludedBy ? IIndexManager.ADD_DEPENDENT : IIndexManager.ADD_DEPENDENCIES); + index.acquireReadLock(); + } catch (CoreException e) { + CUIPlugin.getDefault().log(e); + return NO_CHILDREN; + } catch (InterruptedException e) { + return NO_CHILDREN; + } + + try { IBFile directiveFile= null; IBFile targetFile= null; + IIndexInclude[] includes; if (fComputeIncludedBy) { - ICProject[] projects; - try { - projects = CoreModel.getDefault().getCModel().getCProjects(); - } catch (CModelException e) { - CUIPlugin.getDefault().log(e); - return NO_CHILDREN; - } - includes= CIndexQueries.getInstance().findIncludedBy(projects, tu, NPM); + includes= findIncludedBy(index, tu, NPM); } else { - includes= CIndexQueries.getInstance().findIncludesTo(tu, NPM); + includes= findIncludesTo(index, tu, NPM); directiveFile= node.getRepresentedFile(); } if (includes.length > 0) { ArrayList result= new ArrayList(includes.length); for (int i = 0; i < includes.length; i++) { - CIndexIncludeRelation include = includes[i]; + IIndexInclude include = includes[i]; try { + Path includesPath = new Path(include.getIncludesLocation()); if (fComputeIncludedBy) { - directiveFile= targetFile= new IBFile(tu.getCProject(), include.getIncludedBy()); + directiveFile= targetFile= new IBFile(tu.getCProject(), new Path(include.getIncludedByLocation())); } else { - targetFile= new IBFile(tu.getCProject(), include.getIncludes()); + targetFile= new IBFile(tu.getCProject(), includesPath); } - } catch (CModelException e) { - CUIPlugin.getDefault().log(e); - targetFile= null; - } - - if (targetFile != null) { IBNode newnode= new IBNode(node, targetFile, directiveFile, - include.getName(), include.getOffset(), include.getTimestamp()); - newnode.setIsActiveCode(include.isActiveCode()); + includesPath.lastSegment(), include.getNameOffset(), + include.getNameLength(), + include.getIncludedBy().getTimestamp()); + newnode.setIsActiveCode(true); newnode.setIsSystemInclude(include.isSystemInclude()); result.add(newnode); } + catch (CoreException e) { + CUIPlugin.getDefault().log(e); + } } + return result.toArray(); } } + finally { + index.releaseReadLock(); + } } return NO_CHILDREN; } @@ -127,4 +143,37 @@ public class IBContentProvider extends AsyncTreeContentProvider { public boolean getComputeIncludedBy() { return fComputeIncludedBy; } + + + private IIndexInclude[] findIncludedBy(IIndex index, ITranslationUnit tu, IProgressMonitor pm) { + try { + IPath location= tu.getLocation(); + if (location != null) { + IIndexFile file= index.getFile(location); + if (file != null) { + return index.findIncludedBy(file); + } + } + } + catch (CoreException e) { + CUIPlugin.getDefault().log(e); + } + return new IIndexInclude[0]; + } + + public IIndexInclude[] findIncludesTo(IIndex index, ITranslationUnit tu, IProgressMonitor pm) { + try { + IPath location= tu.getLocation(); + if (location != null) { + IIndexFile file= index.getFile(location); + if (file != null) { + return index.findIncludes(file); + } + } + } + catch (CoreException e) { + CUIPlugin.getDefault().log(e); + } + return new IIndexInclude[0]; + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBNode.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBNode.java index ff889fc9c43..b5e80bf50f0 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBNode.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBNode.java @@ -30,6 +30,7 @@ public class IBNode implements IAdaptable { private IBFile fDirectiveFile; private String fDirectiveName; private int fDirectiveCharacterOffset; + private int fDirectiveLength; private int fHashCode; private boolean fIsSystemInclude= false; @@ -40,13 +41,14 @@ public class IBNode implements IAdaptable { /** * Creates a new node for the include browser */ - public IBNode(IBNode parent, IBFile represents, IBFile fileOfDirective, String nameOfDirective, - int charOffset, long timestamp) { + public IBNode(IBNode parent, IBFile represents, IBFile fileOfDirective, + String nameOfDirective, int charOffset, int length, long timestamp) { fParent= parent; fRepresentedFile= represents; fDirectiveFile= fileOfDirective; fDirectiveName= nameOfDirective; fDirectiveCharacterOffset= charOffset; + fDirectiveLength= length; fIsRecursive= computeIsRecursive(fParent, represents.getLocation()); fHashCode= computeHashCode(); fTimestamp= timestamp; @@ -148,6 +150,10 @@ public class IBNode implements IAdaptable { public int getDirectiveCharacterOffset() { return fDirectiveCharacterOffset; } + + public int getDirectiveLength() { + return fDirectiveLength; + } public IBFile getDirectiveFile() { return fDirectiveFile; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java index 31961c08c14..20e644ffa2e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java @@ -659,7 +659,7 @@ public class IBViewPart extends ViewPart IWorkbenchPage page= getSite().getPage(); IBFile ibf= node.getDirectiveFile(); if (ibf != null) { - IRegion region= new Region(node.getDirectiveCharacterOffset(), node.getDirectiveName().length() + 2); + IRegion region= new Region(node.getDirectiveCharacterOffset(), node.getDirectiveLength()); long timestamp= node.getTimestamp(); IFile f= ibf.getResource(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexIncludeRelation.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexIncludeRelation.java deleted file mode 100644 index 51933e51b41..00000000000 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexIncludeRelation.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * 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.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; - -import org.eclipse.cdt.core.index.IIndexInclude; - -/** - * Represents an include relation found in the index. - * @since 4.0 - */ -public class CIndexIncludeRelation { - private IPath fIncludedBy; - private IPath fIncludes; - - CIndexIncludeRelation(IIndexInclude include) throws CoreException { - fIncludedBy= Path.fromOSString(include.getIncludedByLocation()); - fIncludes= Path.fromOSString(include.getIncludesLocation()); - } - public boolean isSystemInclude() { - return false; - } - public boolean isActiveCode() { - return true; - } - public IPath getIncludedBy() { - return fIncludedBy; - } - public IPath getIncludes() { - return fIncludes; - } - public String getName() { - return fIncludes.lastSegment(); - } - public int getOffset() { - return 9; - } - public long getTimestamp() { - return 0; - } -} \ 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 a4ee5e9ba4e..dc5b3c53a54 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 @@ -12,8 +12,6 @@ package org.eclipse.cdt.internal.ui.missingapi; import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; @@ -34,9 +32,6 @@ import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding; import org.eclipse.cdt.core.index.IIndex; -import org.eclipse.cdt.core.index.IIndexFile; -import org.eclipse.cdt.core.index.IIndexInclude; -import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.core.index.IIndexName; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; @@ -57,7 +52,6 @@ import org.eclipse.cdt.internal.corext.util.CModelUtil; public class CIndexQueries { private static final int ASTTU_OPTIONS = ITranslationUnit.AST_SKIP_INDEXED_HEADERS; 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(); public static CIndexQueries getInstance() { @@ -99,87 +93,6 @@ public class CIndexQueries { return false; } - /** - * Searches for all include-relations that include the given translation unit. - * @param scope the projects to be searched. - * @param tu a translation unit - * @param pm a monitor for reporting progress. - * @return an array of include relations. - * @since 4.0 - */ - public CIndexIncludeRelation[] findIncludedBy(ICProject[] scope, ITranslationUnit tu, IProgressMonitor pm) { - HashMap result= new HashMap(); - try { - IIndex index= CCorePlugin.getIndexManager().getIndex(scope); - index.acquireReadLock(); - - try { - IPath location= tu.getLocation(); - if (location != null) { - IIndexFile file= index.getFile(location); - if (file != null) { - IIndexInclude[] includes= index.findIncludedBy(file); - for (int i = 0; i < includes.length; i++) { - IIndexInclude include = includes[i]; - CIndexIncludeRelation rel= new CIndexIncludeRelation(include); - result.put(rel.getIncludedBy(), rel); - } - } - } - } - finally { - index.releaseReadLock(); - } - } - catch (InterruptedException e) { - } - catch (CoreException e) { - CUIPlugin.getDefault().log(e); - } - Collection includes= result.values(); - return (CIndexIncludeRelation[]) includes.toArray(new CIndexIncludeRelation[includes.size()]); - } - - /** - * Searches for all include-relations defined in the given translation unit. - * @param tu a translation unit. - * @param pm a monitor to report progress. - * @return an array of include relations. - * @since 4.0 - */ - public CIndexIncludeRelation[] findIncludesTo(ITranslationUnit tu, IProgressMonitor pm) { - try { - ICProject cproject= tu.getCProject(); - if (cproject != null) { - IIndex index= CCorePlugin.getIndexManager().getIndex(cproject, IIndexManager.ADD_DEPENDENCIES); - index.acquireReadLock(); - try { - IPath location= tu.getLocation(); - if (location != null) { - IIndexFile file= index.getFile(location); - if (file != null) { - IIndexInclude includes[]= index.findIncludes(file); - ArrayList result= new ArrayList(); - for (int i = 0; i < includes.length; i++) { - IIndexInclude include = includes[i]; - result.add(new CIndexIncludeRelation(include)); - } - return (CIndexIncludeRelation[]) result.toArray(new CIndexIncludeRelation[result.size()]); - } - } - } - finally { - index.releaseReadLock(); - } - } - } - catch (CoreException e) { - CUIPlugin.getDefault().log(e); - } - catch (InterruptedException e) { - } - return EMPTY_INCLUDES; - } /** * Searches for functions and methods that call a given element.