mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Simplification of fix for 184042, updating index for changes in configuration.
This commit is contained in:
parent
269b4e7072
commit
897d6b87e6
16 changed files with 273 additions and 222 deletions
|
@ -318,11 +318,15 @@ public class IndexIncludeTest extends IndexTestBase {
|
|||
|
||||
// #include "resolved20070426.h"
|
||||
public void testFixedContext() throws Exception {
|
||||
waitForIndexer();
|
||||
TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()};
|
||||
String source= getContentsForTest(1)[0].toString();
|
||||
IFile header= TestSourceReader.createFile(fProject.getProject(), "resolved20070426.h", "");
|
||||
IFile s1= TestSourceReader.createFile(fProject.getProject(), "s1.cpp", source);
|
||||
// make sure it is parsed in context
|
||||
waitForIndexer();
|
||||
CCorePlugin.getIndexManager().reindex(fProject);
|
||||
waitForIndexer();
|
||||
|
||||
IFile s2= TestSourceReader.createFile(fProject.getProject(), "s2.cpp", source);
|
||||
TestSourceReader.waitUntilFileIsIndexed(fIndex, s2, INDEXER_WAIT_TIME);
|
||||
|
||||
|
@ -332,8 +336,12 @@ public class IndexIncludeTest extends IndexTestBase {
|
|||
assertNotNull(ifile);
|
||||
IIndexInclude[] includes= fIndex.findIncludedBy(ifile);
|
||||
assertEquals(2, includes.length);
|
||||
assertEquals(s2.getFullPath().toString(), includes[0].getIncludedByLocation().getFullPath());
|
||||
assertEquals(s1.getFullPath().toString(), includes[1].getIncludedByLocation().getFullPath());
|
||||
assertEquals(s1.getFullPath().toString(), includes[0].getIncludedByLocation().getFullPath());
|
||||
assertEquals(s2.getFullPath().toString(), includes[1].getIncludedByLocation().getFullPath());
|
||||
|
||||
IIndexInclude context= ifile.getParsedInContext();
|
||||
assertNotNull(context);
|
||||
assertEquals(s1.getFullPath().toString(), context.getIncludedByLocation().getFullPath());
|
||||
}
|
||||
finally {
|
||||
fIndex.releaseReadLock();
|
||||
|
@ -348,8 +356,11 @@ public class IndexIncludeTest extends IndexTestBase {
|
|||
assertNotNull(ifile);
|
||||
IIndexInclude[] includes= fIndex.findIncludedBy(ifile);
|
||||
assertEquals(2, includes.length);
|
||||
assertEquals(s2.getFullPath().toString(), includes[0].getIncludedByLocation().getFullPath());
|
||||
assertEquals(s1.getFullPath().toString(), includes[1].getIncludedByLocation().getFullPath());
|
||||
assertEquals(s1.getFullPath().toString(), includes[0].getIncludedByLocation().getFullPath());
|
||||
assertEquals(s2.getFullPath().toString(), includes[1].getIncludedByLocation().getFullPath());
|
||||
IIndexInclude context= ifile.getParsedInContext();
|
||||
assertNotNull(context);
|
||||
assertEquals(s1.getFullPath().toString(), context.getIncludedByLocation().getFullPath());
|
||||
}
|
||||
finally {
|
||||
fIndex.releaseReadLock();
|
||||
|
@ -364,8 +375,11 @@ public class IndexIncludeTest extends IndexTestBase {
|
|||
assertNotNull(ifile);
|
||||
IIndexInclude[] includes= fIndex.findIncludedBy(ifile);
|
||||
assertEquals(2, includes.length);
|
||||
assertEquals(s2.getFullPath().toString(), includes[0].getIncludedByLocation().getFullPath());
|
||||
assertEquals(s1.getFullPath().toString(), includes[1].getIncludedByLocation().getFullPath());
|
||||
assertEquals(s1.getFullPath().toString(), includes[0].getIncludedByLocation().getFullPath());
|
||||
assertEquals(s2.getFullPath().toString(), includes[1].getIncludedByLocation().getFullPath());
|
||||
IIndexInclude context= ifile.getParsedInContext();
|
||||
assertNotNull(context);
|
||||
assertEquals(s1.getFullPath().toString(), context.getIncludedByLocation().getFullPath());
|
||||
}
|
||||
finally {
|
||||
fIndex.releaseReadLock();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2006 QNX Software Systems and others.
|
||||
* Copyright (c) 2002, 2007 QNX Software Systems 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
|
||||
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.core.model;
|
||||
|
@ -17,6 +18,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
@ -569,6 +572,40 @@ public class CoreModelUtil {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the translation unit for the location given or <code>null</code>.
|
||||
* @throws CModelException
|
||||
*/
|
||||
public static ITranslationUnit findTranslationUnitForLocation(IIndexFileLocation ifl, ICProject preferredProject) throws CModelException {
|
||||
String fullPath= ifl.getFullPath();
|
||||
if (fullPath != null) {
|
||||
IResource file= ResourcesPlugin.getWorkspace().getRoot().findMember(fullPath);
|
||||
if (file instanceof IFile) {
|
||||
return findTranslationUnit((IFile) file);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
IPath location= IndexLocationFactory.getAbsolutePath(ifl);
|
||||
if (location != null) {
|
||||
CoreModel coreModel = CoreModel.getDefault();
|
||||
ITranslationUnit tu= null;
|
||||
if (preferredProject != null) {
|
||||
tu= coreModel.createTranslationUnitFrom(preferredProject, location);
|
||||
}
|
||||
if (tu == null) {
|
||||
ICProject[] projects= coreModel.getCModel().getCProjects();
|
||||
for (int i = 0; i < projects.length && tu == null; i++) {
|
||||
ICProject project = projects[i];
|
||||
if (!project.equals(preferredProject)) {
|
||||
tu= coreModel.createTranslationUnitFrom(project, location);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tu;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the translation unit for the file given or <code>null</code>.
|
||||
*/
|
||||
|
@ -654,10 +691,10 @@ public class CoreModelUtil {
|
|||
|
||||
if(cfgDes!=null) {
|
||||
CoreModel core= CoreModel.getDefault();
|
||||
IProject[] cprojects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
|
||||
IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
|
||||
|
||||
for (int i=0; i<cprojects.length; i++) {
|
||||
IProject cproject= (IProject) cprojects[i];
|
||||
for (int i=0; i<projects.length; i++) {
|
||||
IProject cproject= projects[i];
|
||||
ICProjectDescription prjDes= core.getProjectDescription(cproject, writable);
|
||||
//in case this is not a CDT project the description will be null, so check for null
|
||||
if(prjDes != null){
|
||||
|
|
|
@ -70,4 +70,10 @@ public interface IIndexFile {
|
|||
* Find all names within the given range.
|
||||
*/
|
||||
IIndexName[] findNames(int offset, int length) throws CoreException;
|
||||
|
||||
/**
|
||||
* Returns the include that was used to parse this file, may be null.
|
||||
*/
|
||||
IIndexInclude getParsedInContext() throws CoreException;
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
|
||||
package org.eclipse.cdt.internal.core.index;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||
|
@ -26,6 +28,13 @@ import org.eclipse.core.runtime.CoreException;
|
|||
*/
|
||||
public interface IWritableIndex extends IIndex {
|
||||
|
||||
static class IncludeInformation {
|
||||
public IASTPreprocessorIncludeStatement fStatement;
|
||||
public IIndexFileLocation fLocation;
|
||||
public IIndexFragmentFile fTargetFile;
|
||||
public boolean fIsContext= false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a file object for the given location or returns an existing one.
|
||||
*/
|
||||
|
@ -35,6 +44,7 @@ public interface IWritableIndex extends IIndex {
|
|||
* Adds content to the given file.
|
||||
*/
|
||||
void setFileContent(IIndexFragmentFile sourceFile,
|
||||
IncludeInformation[] includes,
|
||||
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names) throws CoreException;
|
||||
|
||||
/**
|
||||
|
@ -44,10 +54,11 @@ public interface IWritableIndex extends IIndex {
|
|||
|
||||
/**
|
||||
* Clears the given file in the index.
|
||||
* @param newIncludes
|
||||
* @param newIncludeLocations
|
||||
* @param file a file to clear.
|
||||
* @param a collection that receives IndexFileLocation objects for files that
|
||||
* had the cleared file as a context. May be <code>null</code>.
|
||||
*/
|
||||
void clearFile(IIndexFragmentFile file, IASTPreprocessorIncludeStatement[] newIncludes, IIndexFileLocation[] newIncludeLocations) throws CoreException;
|
||||
void clearFile(IIndexFragmentFile file, Collection clearedContexts) throws CoreException;
|
||||
|
||||
/**
|
||||
* Acquires a write lock, while giving up a certain amount of read locks.
|
||||
|
|
|
@ -12,10 +12,12 @@
|
|||
|
||||
package org.eclipse.cdt.internal.core.index;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
|
@ -30,10 +32,11 @@ public interface IWritableIndexFragment extends IIndexFragment {
|
|||
|
||||
/**
|
||||
* Clears the given file in the index.
|
||||
* @param newIncludes list of includes to set
|
||||
* @param destFiles list of file objects for the includes
|
||||
* @param file a file to clear, must belong to this fragment.
|
||||
* @param a collection that receives IndexFileLocation objects for files that
|
||||
* had the cleared file as a context.
|
||||
*/
|
||||
void clearFile(IIndexFragmentFile file, IASTPreprocessorIncludeStatement[] newIncludes, IIndexFragmentFile[] destFiles) throws CoreException;
|
||||
void clearFile(IIndexFragmentFile file, Collection contextsRemoved) throws CoreException;
|
||||
|
||||
/**
|
||||
* Creates a file object for the given location or returns an existing one.
|
||||
|
@ -47,6 +50,7 @@ public interface IWritableIndexFragment extends IIndexFragment {
|
|||
* Adds an include to the given file.
|
||||
*/
|
||||
void addFileContent(IIndexFragmentFile sourceFile,
|
||||
IncludeInformation[] includes,
|
||||
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names) throws CoreException;
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,8 +12,9 @@
|
|||
|
||||
package org.eclipse.cdt.internal.core.index;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -56,12 +57,19 @@ public class WritableCIndex extends CIndex implements IWritableIndex {
|
|||
}
|
||||
|
||||
public void setFileContent(IIndexFragmentFile file,
|
||||
IncludeInformation[] includes,
|
||||
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names) throws CoreException {
|
||||
|
||||
IIndexFragment indexFragment = file.getIndexFragment();
|
||||
assert isWritableFragment(indexFragment);
|
||||
|
||||
((IWritableIndexFragment) indexFragment).addFileContent(file, macros, names);
|
||||
for (int i = 0; i < includes.length; i++) {
|
||||
IncludeInformation ii= includes[i];
|
||||
if (ii.fLocation != null) {
|
||||
ii.fTargetFile= addFile(ii.fLocation);
|
||||
}
|
||||
}
|
||||
((IWritableIndexFragment) indexFragment).addFileContent(file, includes, macros, names);
|
||||
}
|
||||
|
||||
public void clear() throws CoreException {
|
||||
|
@ -71,20 +79,11 @@ public class WritableCIndex extends CIndex implements IWritableIndex {
|
|||
}
|
||||
}
|
||||
|
||||
public void clearFile(IIndexFragmentFile file,
|
||||
IASTPreprocessorIncludeStatement[] newIncludes,
|
||||
IIndexFileLocation[] newIncludeLocations) throws CoreException {
|
||||
public void clearFile(IIndexFragmentFile file, Collection clearedContexts) throws CoreException {
|
||||
IIndexFragment indexFragment = file.getIndexFragment();
|
||||
assert isWritableFragment(indexFragment);
|
||||
|
||||
IIndexFragmentFile[] destFiles= new IIndexFragmentFile[newIncludes.length];
|
||||
for (int i = 0; i < newIncludes.length; i++) {
|
||||
if (newIncludeLocations[i] != null) {
|
||||
destFiles[i]= addFile(newIncludeLocations[i]);
|
||||
}
|
||||
}
|
||||
|
||||
((IWritableIndexFragment) indexFragment).clearFile(file, newIncludes, destFiles);
|
||||
((IWritableIndexFragment) indexFragment).clearFile(file, clearedContexts);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -12,10 +12,15 @@
|
|||
package org.eclipse.cdt.internal.core.pdom;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
|
@ -37,6 +42,8 @@ import org.eclipse.cdt.core.index.IIndexFile;
|
|||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
|
||||
import org.eclipse.cdt.internal.core.index.IWritableIndex;
|
||||
import org.eclipse.cdt.internal.core.index.IndexFileLocation;
|
||||
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation;
|
||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMASTAdapter;
|
||||
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerASTVisitor;
|
||||
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerStatistics;
|
||||
|
@ -49,9 +56,6 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
|||
* @since 4.0
|
||||
*/
|
||||
abstract public class PDOMWriter {
|
||||
private static final IASTPreprocessorIncludeStatement[] NO_INCLUDES = {};
|
||||
private static final IIndexFileLocation[] NO_LOCATIONS = {};
|
||||
|
||||
public static int SKIP_ALL_REFERENCES= -1;
|
||||
public static int SKIP_TYPE_REFERENCES= 1;
|
||||
public static int SKIP_NO_REFERENCES= 0;
|
||||
|
@ -117,7 +121,8 @@ abstract public class PDOMWriter {
|
|||
IProgressMonitor pm) throws InterruptedException, CoreException {
|
||||
final Map symbolMap= new HashMap();
|
||||
try {
|
||||
IIndexFileLocation[] orderedPaths= extractSymbols(ast, symbolMap, configHash);
|
||||
HashSet contextIncludes= new HashSet();
|
||||
IIndexFileLocation[] orderedPaths= extractSymbols(ast, symbolMap, configHash, contextIncludes);
|
||||
for (int i=0; i<orderedPaths.length; i++) {
|
||||
if (pm.isCanceled()) {
|
||||
return;
|
||||
|
@ -164,7 +169,7 @@ abstract public class PDOMWriter {
|
|||
if (fShowActivity) {
|
||||
System.out.println("Indexer: adding " + path.getURI()); //$NON-NLS-1$
|
||||
}
|
||||
IIndexFile file= addToIndex(index, path, symbolMap, configHash);
|
||||
IIndexFile file= addToIndex(index, path, symbolMap, configHash, contextIncludes);
|
||||
boolean wasRequested= postAddToIndex(path, file);
|
||||
|
||||
synchronized(fInfo) {
|
||||
|
@ -193,10 +198,11 @@ abstract public class PDOMWriter {
|
|||
}
|
||||
}
|
||||
|
||||
private IIndexFileLocation[] extractSymbols(IASTTranslationUnit ast, final Map symbolMap, int confighash) throws CoreException {
|
||||
private IIndexFileLocation[] extractSymbols(IASTTranslationUnit ast,
|
||||
final Map symbolMap, int confighash, Collection contextIncludes) throws CoreException {
|
||||
LinkedHashSet/*<IIndexFileLocation>*/ orderedIFLs= new LinkedHashSet/*<IIndexFileLocation>*/();
|
||||
ArrayList/*<IIndexFileLocation>*/ iflStack= new ArrayList/*<IIndexFileLocation>*/();
|
||||
|
||||
HashMap firstIncludePerTarget= new HashMap();
|
||||
|
||||
final IIndexFileLocation astLocation = findLocation(ast.getFilePath());
|
||||
IIndexFileLocation aboveStackIFL = astLocation;
|
||||
|
@ -234,6 +240,11 @@ abstract public class PDOMWriter {
|
|||
if (include.isResolved()) {
|
||||
iflStack.add(nextIFL);
|
||||
aboveStackIFL= findLocation(include.getPath());
|
||||
if (include.isActive()) {
|
||||
if (!firstIncludePerTarget.containsKey(aboveStackIFL)) {
|
||||
firstIncludePerTarget.put(aboveStackIFL, include);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (include.isActive()) {
|
||||
reportProblem(include);
|
||||
|
@ -248,6 +259,15 @@ abstract public class PDOMWriter {
|
|||
}
|
||||
}
|
||||
|
||||
// extract context includes
|
||||
for (Iterator iterator = orderedIFLs.iterator(); iterator.hasNext();) {
|
||||
IndexFileLocation loc = (IndexFileLocation) iterator.next();
|
||||
Object contextInclude= firstIncludePerTarget.get(loc);
|
||||
if (contextInclude != null) {
|
||||
contextIncludes.add(contextInclude);
|
||||
}
|
||||
}
|
||||
|
||||
// macros
|
||||
IASTPreprocessorMacroDefinition[] macros = ast.getMacroDefinitions();
|
||||
for (int i2 = 0; i2 < macros.length; ++i2) {
|
||||
|
@ -344,36 +364,37 @@ abstract public class PDOMWriter {
|
|||
return false;
|
||||
}
|
||||
|
||||
private IIndexFragmentFile addToIndex(IWritableIndex index, IIndexFileLocation location, Map symbolMap, int configHash) throws CoreException {
|
||||
ArrayList[] lists= (ArrayList[]) symbolMap.get(location);
|
||||
IASTPreprocessorIncludeStatement[] includes= NO_INCLUDES;
|
||||
IASTPreprocessorMacroDefinition[] macros= null;
|
||||
IASTName[][] names= null;
|
||||
IIndexFileLocation[] includeLocations= NO_LOCATIONS;
|
||||
if (lists != null) {
|
||||
ArrayList list= lists[0];
|
||||
includes= (IASTPreprocessorIncludeStatement[]) list.toArray(new IASTPreprocessorIncludeStatement[list.size()]);
|
||||
list= lists[1];
|
||||
macros= (IASTPreprocessorMacroDefinition[]) list.toArray(new IASTPreprocessorMacroDefinition[list.size()]);
|
||||
list= lists[2];
|
||||
names= (IASTName[][]) list.toArray(new IASTName[list.size()][]);
|
||||
|
||||
includeLocations = new IIndexFileLocation[includes.length];
|
||||
for(int i=0; i<includes.length; i++) {
|
||||
if (includes[i].isResolved()) {
|
||||
includeLocations[i] = findLocation(includes[i].getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
private IIndexFragmentFile addToIndex(IWritableIndex index, IIndexFileLocation location, Map symbolMap, int configHash, Set contextIncludes) throws CoreException {
|
||||
Set clearedContexts= Collections.EMPTY_SET;
|
||||
IIndexFragmentFile file= (IIndexFragmentFile) index.getFile(location);
|
||||
if (file == null) {
|
||||
if (file != null) {
|
||||
clearedContexts= new HashSet();
|
||||
index.clearFile(file, clearedContexts);
|
||||
} else {
|
||||
file= index.addFile(location);
|
||||
}
|
||||
index.clearFile(file, includes, includeLocations);
|
||||
file.setTimestamp(getLastModified(location));
|
||||
file.setScannerConfigurationHashcode(configHash);
|
||||
ArrayList[] lists= (ArrayList[]) symbolMap.get(location);
|
||||
if (lists != null) {
|
||||
index.setFileContent(file, macros, names);
|
||||
ArrayList list= lists[1];
|
||||
IASTPreprocessorMacroDefinition[] macros= (IASTPreprocessorMacroDefinition[]) list.toArray(new IASTPreprocessorMacroDefinition[list.size()]);
|
||||
list= lists[2];
|
||||
IASTName[][] names= (IASTName[][]) list.toArray(new IASTName[list.size()][]);
|
||||
|
||||
list= lists[0];
|
||||
IncludeInformation[] includeInfos= new IncludeInformation[list.size()];
|
||||
for (int i=0; i<list.size(); i++) {
|
||||
final IASTPreprocessorIncludeStatement include = (IASTPreprocessorIncludeStatement) list.get(i);
|
||||
final IncludeInformation info= includeInfos[i]= new IncludeInformation();
|
||||
info.fStatement= include;
|
||||
if (include.isResolved()) {
|
||||
info.fLocation= findLocation(include.getPath());
|
||||
info.fIsContext= contextIncludes.contains(include) ||
|
||||
clearedContexts.contains(info.fLocation);
|
||||
}
|
||||
}
|
||||
index.setFileContent(file, includeInfos, macros, names);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
@ -410,17 +431,4 @@ abstract public class PDOMWriter {
|
|||
protected long getLastModified(IIndexFileLocation location) throws CoreException {
|
||||
return EFS.getStore(location.getURI()).fetchInfo().getLastModified();
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the scanner configuration hash code for an index file location. With
|
||||
* that it can be determined at a later point if the scanner configuration has
|
||||
* potentially been changed for a particular file.
|
||||
* @param location the location for which the scanner configuration hash code is obtained.
|
||||
* @return the hashcode or <code>0</code>, if unknown.
|
||||
* @throws CoreException
|
||||
* @since 4.0
|
||||
*/
|
||||
protected int getScannerConfigurationHashcode(IIndexFileLocation location) throws CoreException {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ import java.util.zip.ZipFile;
|
|||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
|
@ -65,9 +64,7 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable {
|
|||
private static final String PROJECT_VAR_REPLACEMENT_BEGIN = "\\${$1:"; //$NON-NLS-1$
|
||||
private static final String PROJECT_VAR_REPLACEMENT_END = "}"; //$NON-NLS-1$
|
||||
private static final String DOLLAR_OR_BACKSLASH_REPLACEMENT = "\\\\$0"; //$NON-NLS-1$
|
||||
private static final IASTPreprocessorIncludeStatement[] NO_INCLUDES = {};
|
||||
private static final Pattern DOLLAR_OR_BACKSLASH_PATTERN= Pattern.compile("[\\$\\\\]"); //$NON-NLS-1$
|
||||
private static final IIndexFragmentFile[] NO_IDS = {};
|
||||
|
||||
private static final class FileAndChecksum {
|
||||
public ITranslationUnit fFile;
|
||||
|
@ -268,7 +265,7 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable {
|
|||
|
||||
IndexFileLocation ifl = (IndexFileLocation) i.next();
|
||||
IIndexFragmentFile file= pdom.getFile(ifl);
|
||||
pdom.clearFile(file, NO_INCLUDES, NO_IDS);
|
||||
pdom.clearFile(file, null);
|
||||
}
|
||||
for (Iterator i = updateTimestamps.iterator(); i.hasNext();) {
|
||||
checkMonitor(monitor);
|
||||
|
|
|
@ -15,18 +15,19 @@ package org.eclipse.cdt.internal.core.pdom;
|
|||
import java.io.File;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.index.IIndexLocationConverter;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
|
||||
import org.eclipse.cdt.internal.core.index.IWritableIndexFragment;
|
||||
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.ChunkCache;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.DBProperties;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
|
||||
|
@ -52,19 +53,19 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
|
|||
}
|
||||
|
||||
public void addFileContent(IIndexFragmentFile sourceFile,
|
||||
IncludeInformation[] includes,
|
||||
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names) throws CoreException {
|
||||
assert sourceFile.getIndexFragment() == this;
|
||||
|
||||
PDOMFile pdomFile = (PDOMFile) sourceFile;
|
||||
pdomFile.addIncludesTo(includes);
|
||||
pdomFile.addMacros(macros);
|
||||
pdomFile.addNames(names);
|
||||
}
|
||||
|
||||
public void clearFile(IIndexFragmentFile file,
|
||||
IASTPreprocessorIncludeStatement[] newIncludes, IIndexFragmentFile[] destFiles) throws CoreException {
|
||||
public void clearFile(IIndexFragmentFile file, Collection contextsRemoved) throws CoreException {
|
||||
assert file.getIndexFragment() == this;
|
||||
assert newIncludes.length == destFiles.length;
|
||||
((PDOMFile) file).clear(newIncludes, destFiles);
|
||||
((PDOMFile) file).clear(contextsRemoved);
|
||||
}
|
||||
|
||||
public void clear() throws CoreException {
|
||||
|
@ -130,7 +131,7 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
|
|||
for(Iterator i = notConverted.iterator(); i.hasNext(); ) {
|
||||
PDOMFile file = (PDOMFile) i.next();
|
||||
file.convertIncludersToUnresolved();
|
||||
file.clear(null, null);
|
||||
file.clear(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,13 +13,13 @@
|
|||
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.index.IIndexInclude;
|
||||
|
@ -29,6 +29,7 @@ import org.eclipse.cdt.core.index.IIndexName;
|
|||
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
|
||||
import org.eclipse.cdt.internal.core.index.IWritableIndexFragment;
|
||||
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.BTree;
|
||||
|
@ -45,7 +46,6 @@ import org.eclipse.core.runtime.CoreException;
|
|||
*
|
||||
*/
|
||||
public class PDOMFile implements IIndexFragmentFile {
|
||||
|
||||
private final PDOM pdom;
|
||||
private final int record;
|
||||
|
||||
|
@ -166,6 +166,10 @@ public class PDOMFile implements IIndexFragmentFile {
|
|||
return rec != 0 ? new PDOMInclude(pdom, rec) : null;
|
||||
}
|
||||
|
||||
public IIndexInclude getParsedInContext() throws CoreException {
|
||||
return getFirstIncludedBy();
|
||||
}
|
||||
|
||||
public void setFirstIncludedBy(PDOMInclude includedBy) throws CoreException {
|
||||
int rec = includedBy != null ? includedBy.getRecord() : 0;
|
||||
pdom.getDB().putInt(record + FIRST_INCLUDED_BY, rec);
|
||||
|
@ -235,63 +239,18 @@ public class PDOMFile implements IIndexFragmentFile {
|
|||
return result;
|
||||
}
|
||||
|
||||
public void clear(IASTPreprocessorIncludeStatement[] newIncludes, IIndexFragmentFile[] destFiles) throws CoreException {
|
||||
int[] records= new int[destFiles.length];
|
||||
PDOMInclude[] oldDirectives= new PDOMInclude[destFiles.length];
|
||||
for (int i = 0; i < records.length; i++) {
|
||||
PDOMFile destFile= (PDOMFile) destFiles[i];
|
||||
if (destFile != null) {
|
||||
records[i]= destFile.getRecord();
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the includes preserving the unchanged
|
||||
public void clear(Collection contextsRemoved) throws CoreException {
|
||||
// Remove the includes
|
||||
PDOMInclude include = getFirstInclude();
|
||||
while (include != null) {
|
||||
PDOMInclude nextInclude = include.getNextInIncludes();
|
||||
final PDOMFile includes= (PDOMFile) include.getIncludes();
|
||||
if (includes != null) {
|
||||
final int rec= includes.record;
|
||||
int i;
|
||||
for (i=0; i < records.length; i++) {
|
||||
if (rec == records[i]) {
|
||||
records[i]= 0;
|
||||
oldDirectives[i]= include;
|
||||
include.setNextInIncludes(null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i >= records.length) {
|
||||
include.delete();
|
||||
}
|
||||
if (contextsRemoved != null && include.getPrevInIncludedByRecord() == 0) {
|
||||
contextsRemoved.add(include.getIncludesLocation());
|
||||
}
|
||||
include.delete();
|
||||
include = nextInclude;
|
||||
}
|
||||
setFirstInclude(null);
|
||||
|
||||
PDOMInclude lastInclude= null;
|
||||
for (int i = 0; i < newIncludes.length; i++) {
|
||||
IASTPreprocessorIncludeStatement statement = newIncludes[i];
|
||||
PDOMFile targetFile= (PDOMFile) destFiles[i];
|
||||
PDOMInclude pdomInclude= oldDirectives[i];
|
||||
if (pdomInclude == null) {
|
||||
pdomInclude= new PDOMInclude(pdom, statement, this, targetFile);
|
||||
if (targetFile != null) {
|
||||
assert targetFile.getIndexFragment() instanceof IWritableIndexFragment;
|
||||
targetFile.addIncludedBy(pdomInclude);
|
||||
}
|
||||
}
|
||||
else {
|
||||
pdomInclude.update(statement);
|
||||
}
|
||||
if (lastInclude == null) {
|
||||
setFirstInclude(pdomInclude);
|
||||
}
|
||||
else {
|
||||
lastInclude.setNextInIncludes(pdomInclude);
|
||||
}
|
||||
lastInclude= pdomInclude;
|
||||
}
|
||||
setFirstInclude(include);
|
||||
|
||||
// Delete all the macros in this file
|
||||
PDOMMacro macro = getFirstMacro();
|
||||
|
@ -318,16 +277,51 @@ public class PDOMFile implements IIndexFragmentFile {
|
|||
setFirstName(null);
|
||||
}
|
||||
|
||||
public void addIncludedBy(PDOMInclude include) throws CoreException {
|
||||
PDOMInclude firstIncludedBy = getFirstIncludedBy();
|
||||
if (firstIncludedBy != null) {
|
||||
include.setNextInIncludedBy(firstIncludedBy);
|
||||
firstIncludedBy.setPrevInIncludedBy(include);
|
||||
public void addIncludesTo(IncludeInformation[] includeInfos) throws CoreException {
|
||||
assert getFirstInclude() == null;
|
||||
|
||||
PDOMInclude lastInclude= null;
|
||||
for (int i = 0; i < includeInfos.length; i++) {
|
||||
final IncludeInformation info= includeInfos[i];
|
||||
final PDOMFile targetFile= (PDOMFile) info.fTargetFile;
|
||||
|
||||
PDOMInclude pdomInclude = new PDOMInclude(pdom, info.fStatement, this, targetFile);
|
||||
if (targetFile != null) {
|
||||
assert targetFile.getIndexFragment() instanceof IWritableIndexFragment;
|
||||
targetFile.addIncludedBy(pdomInclude, info.fIsContext);
|
||||
}
|
||||
if (lastInclude == null) {
|
||||
setFirstInclude(pdomInclude);
|
||||
}
|
||||
else {
|
||||
lastInclude.setNextInIncludes(pdomInclude);
|
||||
}
|
||||
lastInclude= pdomInclude;
|
||||
}
|
||||
setFirstIncludedBy(include);
|
||||
}
|
||||
|
||||
|
||||
public void addIncludedBy(PDOMInclude include, boolean isContext) throws CoreException {
|
||||
PDOMInclude firstIncludedBy = getFirstIncludedBy();
|
||||
if (firstIncludedBy != null) {
|
||||
if (isContext) {
|
||||
setFirstIncludedBy(include);
|
||||
include.setNextInIncludedBy(firstIncludedBy);
|
||||
firstIncludedBy.setPrevInIncludedBy(include);
|
||||
}
|
||||
else {
|
||||
PDOMInclude secondIncludedBy= firstIncludedBy.getNextInIncludedBy();
|
||||
if (secondIncludedBy != null) {
|
||||
include.setNextInIncludedBy(secondIncludedBy);
|
||||
secondIncludedBy.setPrevInIncludedBy(include);
|
||||
}
|
||||
include.setPrevInIncludedBy(firstIncludedBy);
|
||||
firstIncludedBy.setNextInIncludedBy(include);
|
||||
}
|
||||
}
|
||||
else {
|
||||
setFirstIncludedBy(include);
|
||||
}
|
||||
}
|
||||
|
||||
public IIndexInclude[] getIncludes() throws CoreException {
|
||||
List result= new ArrayList();
|
||||
|
|
|
@ -72,20 +72,6 @@ public class PDOMInclude implements IIndexFragmentInclude {
|
|||
setIncludes(targetFile, name.toCharArray());
|
||||
}
|
||||
|
||||
public void update(IASTPreprocessorIncludeStatement include) throws CoreException {
|
||||
IASTName name= include.getName();
|
||||
IASTFileLocation loc= name.getFileLocation();
|
||||
// includes generated by -include or -macro don't have a location
|
||||
if (loc != null) {
|
||||
setNameOffsetAndLength(loc.getNodeOffset(), (short) loc.getNodeLength());
|
||||
}
|
||||
else {
|
||||
setNameOffsetAndLength(0, (short) 0);
|
||||
}
|
||||
|
||||
setFlag(encodeFlags(include, false));
|
||||
}
|
||||
|
||||
private byte encodeFlags(IASTPreprocessorIncludeStatement include, boolean unresolved) {
|
||||
byte flags= 0;
|
||||
if (include.isSystemInclude()) {
|
||||
|
@ -187,10 +173,14 @@ public class PDOMInclude implements IIndexFragmentInclude {
|
|||
}
|
||||
|
||||
public PDOMInclude getPrevInIncludedBy() throws CoreException {
|
||||
int rec = pdom.getDB().getInt(record + INCLUDED_BY_PREV);
|
||||
int rec = getPrevInIncludedByRecord();
|
||||
return rec != 0 ? new PDOMInclude(pdom, rec) : null;
|
||||
}
|
||||
|
||||
int getPrevInIncludedByRecord() throws CoreException {
|
||||
return pdom.getDB().getInt(record + INCLUDED_BY_PREV);
|
||||
}
|
||||
|
||||
public void setPrevInIncludedBy(PDOMInclude include) throws CoreException {
|
||||
int rec = include != null ? include.getRecord() : 0;
|
||||
pdom.getDB().putInt(record + INCLUDED_BY_PREV, rec);
|
||||
|
|
|
@ -25,7 +25,6 @@ import java.util.Map;
|
|||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IPDOMIndexer;
|
||||
import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IIndexFile;
|
||||
|
@ -34,7 +33,6 @@ import org.eclipse.cdt.core.index.IIndexInclude;
|
|||
import org.eclipse.cdt.core.index.IIndexManager;
|
||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||
import org.eclipse.cdt.core.model.AbstractLanguage;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.CoreModelUtil;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
|
@ -66,8 +64,6 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
|||
private static final Object NO_CONTEXT = new Object();
|
||||
private static final int MAX_ERRORS = 500;
|
||||
private static final String TRUE = "true"; //$NON-NLS-1$
|
||||
private static final IIndexFileLocation[] NO_LOCATIONS= {};
|
||||
private static final IASTPreprocessorIncludeStatement[] NO_INCLUDES= {};
|
||||
|
||||
private AbstractPDOMIndexer fIndexer;
|
||||
protected Map/*<IIndexFileLocation, Object>*/ fContextMap = new HashMap/*<IIndexFileLocation, Object>*/();
|
||||
|
@ -372,7 +368,7 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
|||
}
|
||||
}
|
||||
|
||||
private ITranslationUnit findContext(IIndex index, IIndexFileLocation location) {
|
||||
private ITranslationUnit findContext(IIndex index, final IIndexFileLocation location) {
|
||||
Object cachedContext= fContextMap.get(location);
|
||||
if (cachedContext != null) {
|
||||
return cachedContext == NO_CONTEXT ? null : (ITranslationUnit) cachedContext;
|
||||
|
@ -381,19 +377,29 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
|||
fContextMap.put(location, NO_CONTEXT); // prevent recursion
|
||||
IIndexFile pdomFile;
|
||||
try {
|
||||
final ICProject project= getIndexer().getProject();
|
||||
pdomFile = index.getFile(location);
|
||||
if (pdomFile != null) {
|
||||
ICProject project= getIndexer().getProject();
|
||||
final IIndexInclude contextInclude= pdomFile.getParsedInContext();
|
||||
if (contextInclude != null) {
|
||||
final IIndexFileLocation loc= contextInclude.getIncludedByLocation();
|
||||
ITranslationUnit context= getSourceUnit(project, loc);
|
||||
if (context == null) {
|
||||
context= findContext(index, loc);
|
||||
}
|
||||
if (context != null) {
|
||||
fContextMap.put(location, context);
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
||||
// fallback to other includes
|
||||
IIndexInclude[] includedBy = index.findIncludedBy(pdomFile, IIndex.DEPTH_ZERO);
|
||||
for (int i = includedBy.length-1; i >=0; i--) {
|
||||
IIndexInclude include = includedBy[i];
|
||||
IIndexFileLocation incLocation = include.getIncludedByLocation();
|
||||
ITranslationUnit context= null;
|
||||
if (CoreModel.isValidSourceUnitName(project.getProject(), incLocation.getURI().toString())) { // FIXME - is this ok?
|
||||
context = CoreModelUtil.findTranslationUnitForLocation(IndexLocationFactory.getAbsolutePath(incLocation), project);
|
||||
}
|
||||
else {
|
||||
context= findContext(index, incLocation);
|
||||
final IIndexFileLocation loc= includedBy[i].getIncludedByLocation();
|
||||
ITranslationUnit context= getSourceUnit(project, loc);
|
||||
if (context == null) {
|
||||
context= findContext(index, loc);
|
||||
}
|
||||
if (context != null) {
|
||||
fContextMap.put(location, context);
|
||||
|
@ -407,6 +413,17 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
|||
return null;
|
||||
}
|
||||
|
||||
private ITranslationUnit getSourceUnit(final ICProject project, final IIndexFileLocation location)
|
||||
throws CoreException {
|
||||
ITranslationUnit tu= CoreModelUtil.findTranslationUnitForLocation(location, getIndexer().getProject());
|
||||
if (tu != null) {
|
||||
if (tu.isSourceUnit()) {
|
||||
return tu;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Conveninence method for subclasses, removes a translation unit from the index.
|
||||
* @since 4.0
|
||||
|
@ -416,7 +433,7 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
|||
try {
|
||||
IIndexFragmentFile file = (IIndexFragmentFile) index.getFile(IndexLocationFactory.getIFL(tu));
|
||||
if (file != null)
|
||||
index.clearFile(file, NO_INCLUDES, NO_LOCATIONS);
|
||||
index.clearFile(file, null);
|
||||
} finally {
|
||||
index.releaseWriteLock(readlocks);
|
||||
}
|
||||
|
|
|
@ -361,8 +361,9 @@ CDTIndexer.nullindexer=No Indexer (search based features will not work correctly
|
|||
CDTIndexer.fastindexer=Fast C/C++ Indexer (recommended)
|
||||
|
||||
IndexView.name=C/C++ Index
|
||||
RebuildIndex.name=Rebuild
|
||||
SyncIndex.name=Update with Modified Files
|
||||
RebuildIndex.name=&Rebuild
|
||||
SyncIndex.name=&Update with Modified Files
|
||||
FreshenIndex.name=&Freshen All Files
|
||||
|
||||
indexerPage.name = Indexer Page
|
||||
proposalFilter.name = Code Completion Proposal Filter
|
||||
|
|
|
@ -711,6 +711,11 @@
|
|||
</and>
|
||||
</or>
|
||||
</visibility>
|
||||
<action
|
||||
class="org.eclipse.cdt.internal.ui.actions.FreshenIndexAction"
|
||||
id="org.eclipse.cdt.ui.updateIndexAction"
|
||||
label="%FreshenIndex.name"
|
||||
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
|
||||
<action
|
||||
class="org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesAction"
|
||||
id="org.eclipse.cdt.ui.syncIndexWithDiskAction"
|
||||
|
@ -721,7 +726,7 @@
|
|||
label="%Index.menu"
|
||||
path="buildGroup">
|
||||
<groupMarker name="rebuild"/>
|
||||
<groupMarker name="update"/>
|
||||
<separator name="update"/>
|
||||
</menu>
|
||||
</objectContribution>
|
||||
<objectContribution
|
||||
|
@ -737,7 +742,7 @@
|
|||
label="%Index.menu"
|
||||
path="buildGroup">
|
||||
<groupMarker name="rebuild"/>
|
||||
<groupMarker name="update"/>
|
||||
<separator name="update"/>
|
||||
</menu>
|
||||
</objectContribution>
|
||||
<!-- project explorer shows IProjects, we need to handle this -->
|
||||
|
@ -749,6 +754,11 @@
|
|||
name="projectNature"
|
||||
value="org.eclipse.cdt.core.cnature"/>
|
||||
</visibility>
|
||||
<action
|
||||
class="org.eclipse.cdt.internal.ui.actions.FreshenIndexAction"
|
||||
id="org.eclipse.cdt.ui.updateIndexAction"
|
||||
label="%FreshenIndex.name"
|
||||
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
|
||||
<action
|
||||
class="org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesAction"
|
||||
id="org.eclipse.cdt.ui.syncIndexWithDiskAction"
|
||||
|
@ -764,7 +774,7 @@
|
|||
label="%Index.menu"
|
||||
path="buildGroup">
|
||||
<groupMarker name="rebuild"/>
|
||||
<groupMarker name="update"/>
|
||||
<separator name="update"/>
|
||||
</menu>
|
||||
</objectContribution>
|
||||
<objectContribution
|
||||
|
|
|
@ -14,11 +14,8 @@ package org.eclipse.cdt.internal.corext.util;
|
|||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.CoreModelUtil;
|
||||
|
@ -152,38 +149,4 @@ public class CModelUtil {
|
|||
public static ITranslationUnit findTranslationUnitForLocation(IPath location, ICProject preferredProject) throws CModelException {
|
||||
return CoreModelUtil.findTranslationUnitForLocation(location, preferredProject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the translation unit for the location given or <code>null</code>.
|
||||
* @throws CModelException
|
||||
*/
|
||||
public static ITranslationUnit findTranslationUnitForLocation(IIndexFileLocation ifl, ICProject preferredProject) throws CModelException {
|
||||
String fullPath= ifl.getFullPath();
|
||||
if (fullPath != null) {
|
||||
IResource file= ResourcesPlugin.getWorkspace().getRoot().findMember(fullPath);
|
||||
if (file instanceof IFile) {
|
||||
return findTranslationUnit((IFile) file);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
IPath location= IndexLocationFactory.getAbsolutePath(ifl);
|
||||
if (location != null) {
|
||||
CoreModel coreModel = CoreModel.getDefault();
|
||||
ITranslationUnit tu= null;
|
||||
if (preferredProject != null) {
|
||||
tu= coreModel.createTranslationUnitFrom(preferredProject, location);
|
||||
}
|
||||
if (tu == null) {
|
||||
ICProject[] projects= coreModel.getCModel().getCProjects();
|
||||
for (int i = 0; i < projects.length && tu == null; i++) {
|
||||
ICProject project = projects[i];
|
||||
if (!project.equals(preferredProject)) {
|
||||
tu= coreModel.createTranslationUnitFrom(project, location);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tu;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,10 @@ import org.eclipse.core.resources.ResourcesPlugin;
|
|||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModelUtil;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
|
||||
import org.eclipse.cdt.internal.corext.util.CModelUtil;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.util.CoreUtility;
|
||||
|
||||
public class IBFile {
|
||||
|
@ -38,7 +37,7 @@ public class IBFile {
|
|||
|
||||
public IBFile(ICProject preferredProject, IIndexFileLocation location) throws CModelException {
|
||||
fLocation= location;
|
||||
fTU= CModelUtil.findTranslationUnitForLocation(location, preferredProject);
|
||||
fTU= CoreModelUtil.findTranslationUnitForLocation(location, preferredProject);
|
||||
String name= fLocation.getURI().getPath();
|
||||
fName= name.substring(name.lastIndexOf('/')+1);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue