1
0
Fork 0
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:
Markus Schorn 2007-04-27 13:41:47 +00:00
parent 269b4e7072
commit 897d6b87e6
16 changed files with 273 additions and 222 deletions

View file

@ -318,11 +318,15 @@ public class IndexIncludeTest extends IndexTestBase {
// #include "resolved20070426.h" // #include "resolved20070426.h"
public void testFixedContext() throws Exception { public void testFixedContext() throws Exception {
waitForIndexer();
TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()}; TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()};
String source= getContentsForTest(1)[0].toString(); String source= getContentsForTest(1)[0].toString();
IFile header= TestSourceReader.createFile(fProject.getProject(), "resolved20070426.h", ""); IFile header= TestSourceReader.createFile(fProject.getProject(), "resolved20070426.h", "");
IFile s1= TestSourceReader.createFile(fProject.getProject(), "s1.cpp", source); 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); IFile s2= TestSourceReader.createFile(fProject.getProject(), "s2.cpp", source);
TestSourceReader.waitUntilFileIsIndexed(fIndex, s2, INDEXER_WAIT_TIME); TestSourceReader.waitUntilFileIsIndexed(fIndex, s2, INDEXER_WAIT_TIME);
@ -332,8 +336,12 @@ public class IndexIncludeTest extends IndexTestBase {
assertNotNull(ifile); assertNotNull(ifile);
IIndexInclude[] includes= fIndex.findIncludedBy(ifile); IIndexInclude[] includes= fIndex.findIncludedBy(ifile);
assertEquals(2, includes.length); assertEquals(2, includes.length);
assertEquals(s2.getFullPath().toString(), includes[0].getIncludedByLocation().getFullPath()); assertEquals(s1.getFullPath().toString(), includes[0].getIncludedByLocation().getFullPath());
assertEquals(s1.getFullPath().toString(), includes[1].getIncludedByLocation().getFullPath()); assertEquals(s2.getFullPath().toString(), includes[1].getIncludedByLocation().getFullPath());
IIndexInclude context= ifile.getParsedInContext();
assertNotNull(context);
assertEquals(s1.getFullPath().toString(), context.getIncludedByLocation().getFullPath());
} }
finally { finally {
fIndex.releaseReadLock(); fIndex.releaseReadLock();
@ -348,8 +356,11 @@ public class IndexIncludeTest extends IndexTestBase {
assertNotNull(ifile); assertNotNull(ifile);
IIndexInclude[] includes= fIndex.findIncludedBy(ifile); IIndexInclude[] includes= fIndex.findIncludedBy(ifile);
assertEquals(2, includes.length); assertEquals(2, includes.length);
assertEquals(s2.getFullPath().toString(), includes[0].getIncludedByLocation().getFullPath()); assertEquals(s1.getFullPath().toString(), includes[0].getIncludedByLocation().getFullPath());
assertEquals(s1.getFullPath().toString(), includes[1].getIncludedByLocation().getFullPath()); assertEquals(s2.getFullPath().toString(), includes[1].getIncludedByLocation().getFullPath());
IIndexInclude context= ifile.getParsedInContext();
assertNotNull(context);
assertEquals(s1.getFullPath().toString(), context.getIncludedByLocation().getFullPath());
} }
finally { finally {
fIndex.releaseReadLock(); fIndex.releaseReadLock();
@ -364,8 +375,11 @@ public class IndexIncludeTest extends IndexTestBase {
assertNotNull(ifile); assertNotNull(ifile);
IIndexInclude[] includes= fIndex.findIncludedBy(ifile); IIndexInclude[] includes= fIndex.findIncludedBy(ifile);
assertEquals(2, includes.length); assertEquals(2, includes.length);
assertEquals(s2.getFullPath().toString(), includes[0].getIncludedByLocation().getFullPath()); assertEquals(s1.getFullPath().toString(), includes[0].getIncludedByLocation().getFullPath());
assertEquals(s1.getFullPath().toString(), includes[1].getIncludedByLocation().getFullPath()); assertEquals(s2.getFullPath().toString(), includes[1].getIncludedByLocation().getFullPath());
IIndexInclude context= ifile.getParsedInContext();
assertNotNull(context);
assertEquals(s1.getFullPath().toString(), context.getIncludedByLocation().getFullPath());
} }
finally { finally {
fIndex.releaseReadLock(); fIndex.releaseReadLock();

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.model; package org.eclipse.cdt.core.model;
@ -17,6 +18,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin; 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.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
@ -569,6 +572,40 @@ public class CoreModelUtil {
return null; 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>. * Returns the translation unit for the file given or <code>null</code>.
*/ */
@ -654,10 +691,10 @@ public class CoreModelUtil {
if(cfgDes!=null) { if(cfgDes!=null) {
CoreModel core= CoreModel.getDefault(); CoreModel core= CoreModel.getDefault();
IProject[] cprojects= ResourcesPlugin.getWorkspace().getRoot().getProjects(); IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (int i=0; i<cprojects.length; i++) { for (int i=0; i<projects.length; i++) {
IProject cproject= (IProject) cprojects[i]; IProject cproject= projects[i];
ICProjectDescription prjDes= core.getProjectDescription(cproject, writable); ICProjectDescription prjDes= core.getProjectDescription(cproject, writable);
//in case this is not a CDT project the description will be null, so check for null //in case this is not a CDT project the description will be null, so check for null
if(prjDes != null){ if(prjDes != null){

View file

@ -70,4 +70,10 @@ public interface IIndexFile {
* Find all names within the given range. * Find all names within the given range.
*/ */
IIndexName[] findNames(int offset, int length) throws CoreException; 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;
} }

View file

@ -12,6 +12,8 @@
package org.eclipse.cdt.internal.core.index; 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.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
@ -25,6 +27,13 @@ import org.eclipse.core.runtime.CoreException;
* @since 4.0 * @since 4.0
*/ */
public interface IWritableIndex extends IIndex { 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. * 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. * Adds content to the given file.
*/ */
void setFileContent(IIndexFragmentFile sourceFile, void setFileContent(IIndexFragmentFile sourceFile,
IncludeInformation[] includes,
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names) throws CoreException; IASTPreprocessorMacroDefinition[] macros, IASTName[][] names) throws CoreException;
/** /**
@ -44,10 +54,11 @@ public interface IWritableIndex extends IIndex {
/** /**
* Clears the given file in the index. * Clears the given file in the index.
* @param newIncludes * @param file a file to clear.
* @param newIncludeLocations * @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. * Acquires a write lock, while giving up a certain amount of read locks.

View file

@ -12,10 +12,12 @@
package org.eclipse.cdt.internal.core.index; 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.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
/** /**
@ -30,10 +32,11 @@ public interface IWritableIndexFragment extends IIndexFragment {
/** /**
* Clears the given file in the index. * Clears the given file in the index.
* @param newIncludes list of includes to set * @param file a file to clear, must belong to this fragment.
* @param destFiles list of file objects for the includes * @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. * 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. * Adds an include to the given file.
*/ */
void addFileContent(IIndexFragmentFile sourceFile, void addFileContent(IIndexFragmentFile sourceFile,
IncludeInformation[] includes,
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names) throws CoreException; IASTPreprocessorMacroDefinition[] macros, IASTName[][] names) throws CoreException;
/** /**

View file

@ -12,8 +12,9 @@
package org.eclipse.cdt.internal.core.index; 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.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -56,12 +57,19 @@ public class WritableCIndex extends CIndex implements IWritableIndex {
} }
public void setFileContent(IIndexFragmentFile file, public void setFileContent(IIndexFragmentFile file,
IncludeInformation[] includes,
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names) throws CoreException { IASTPreprocessorMacroDefinition[] macros, IASTName[][] names) throws CoreException {
IIndexFragment indexFragment = file.getIndexFragment(); IIndexFragment indexFragment = file.getIndexFragment();
assert isWritableFragment(indexFragment); 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 { public void clear() throws CoreException {
@ -71,20 +79,11 @@ public class WritableCIndex extends CIndex implements IWritableIndex {
} }
} }
public void clearFile(IIndexFragmentFile file, public void clearFile(IIndexFragmentFile file, Collection clearedContexts) throws CoreException {
IASTPreprocessorIncludeStatement[] newIncludes,
IIndexFileLocation[] newIncludeLocations) throws CoreException {
IIndexFragment indexFragment = file.getIndexFragment(); IIndexFragment indexFragment = file.getIndexFragment();
assert isWritableFragment(indexFragment); assert isWritableFragment(indexFragment);
IIndexFragmentFile[] destFiles= new IIndexFragmentFile[newIncludes.length]; ((IWritableIndexFragment) indexFragment).clearFile(file, clearedContexts);
for (int i = 0; i < newIncludes.length; i++) {
if (newIncludeLocations[i] != null) {
destFiles[i]= addFile(newIncludeLocations[i]);
}
}
((IWritableIndexFragment) indexFragment).clearFile(file, newIncludes, destFiles);
} }

View file

@ -12,10 +12,15 @@
package org.eclipse.cdt.internal.core.pdom; package org.eclipse.cdt.internal.core.pdom;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; 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.core.index.IIndexFileLocation;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile; import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IWritableIndex; 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.dom.PDOMASTAdapter;
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerASTVisitor; import org.eclipse.cdt.internal.core.pdom.indexer.IndexerASTVisitor;
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerStatistics; import org.eclipse.cdt.internal.core.pdom.indexer.IndexerStatistics;
@ -49,9 +56,6 @@ import org.eclipse.core.runtime.IProgressMonitor;
* @since 4.0 * @since 4.0
*/ */
abstract public class PDOMWriter { 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_ALL_REFERENCES= -1;
public static int SKIP_TYPE_REFERENCES= 1; public static int SKIP_TYPE_REFERENCES= 1;
public static int SKIP_NO_REFERENCES= 0; public static int SKIP_NO_REFERENCES= 0;
@ -117,7 +121,8 @@ abstract public class PDOMWriter {
IProgressMonitor pm) throws InterruptedException, CoreException { IProgressMonitor pm) throws InterruptedException, CoreException {
final Map symbolMap= new HashMap(); final Map symbolMap= new HashMap();
try { 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++) { for (int i=0; i<orderedPaths.length; i++) {
if (pm.isCanceled()) { if (pm.isCanceled()) {
return; return;
@ -164,7 +169,7 @@ abstract public class PDOMWriter {
if (fShowActivity) { if (fShowActivity) {
System.out.println("Indexer: adding " + path.getURI()); //$NON-NLS-1$ 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); boolean wasRequested= postAddToIndex(path, file);
synchronized(fInfo) { synchronized(fInfo) {
@ -193,11 +198,12 @@ 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>*/(); LinkedHashSet/*<IIndexFileLocation>*/ orderedIFLs= new LinkedHashSet/*<IIndexFileLocation>*/();
ArrayList/*<IIndexFileLocation>*/ iflStack= new ArrayList/*<IIndexFileLocation>*/(); ArrayList/*<IIndexFileLocation>*/ iflStack= new ArrayList/*<IIndexFileLocation>*/();
HashMap firstIncludePerTarget= new HashMap();
final IIndexFileLocation astLocation = findLocation(ast.getFilePath()); final IIndexFileLocation astLocation = findLocation(ast.getFilePath());
IIndexFileLocation aboveStackIFL = astLocation; IIndexFileLocation aboveStackIFL = astLocation;
@ -234,6 +240,11 @@ abstract public class PDOMWriter {
if (include.isResolved()) { if (include.isResolved()) {
iflStack.add(nextIFL); iflStack.add(nextIFL);
aboveStackIFL= findLocation(include.getPath()); aboveStackIFL= findLocation(include.getPath());
if (include.isActive()) {
if (!firstIncludePerTarget.containsKey(aboveStackIFL)) {
firstIncludePerTarget.put(aboveStackIFL, include);
}
}
} }
else if (include.isActive()) { else if (include.isActive()) {
reportProblem(include); 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 // macros
IASTPreprocessorMacroDefinition[] macros = ast.getMacroDefinitions(); IASTPreprocessorMacroDefinition[] macros = ast.getMacroDefinitions();
for (int i2 = 0; i2 < macros.length; ++i2) { for (int i2 = 0; i2 < macros.length; ++i2) {
@ -344,36 +364,37 @@ abstract public class PDOMWriter {
return false; return false;
} }
private IIndexFragmentFile addToIndex(IWritableIndex index, IIndexFileLocation location, Map symbolMap, int configHash) throws CoreException { private IIndexFragmentFile addToIndex(IWritableIndex index, IIndexFileLocation location, Map symbolMap, int configHash, Set contextIncludes) throws CoreException {
ArrayList[] lists= (ArrayList[]) symbolMap.get(location); Set clearedContexts= Collections.EMPTY_SET;
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());
}
}
}
IIndexFragmentFile file= (IIndexFragmentFile) index.getFile(location); IIndexFragmentFile file= (IIndexFragmentFile) index.getFile(location);
if (file == null) { if (file != null) {
clearedContexts= new HashSet();
index.clearFile(file, clearedContexts);
} else {
file= index.addFile(location); file= index.addFile(location);
} }
index.clearFile(file, includes, includeLocations);
file.setTimestamp(getLastModified(location)); file.setTimestamp(getLastModified(location));
file.setScannerConfigurationHashcode(configHash); file.setScannerConfigurationHashcode(configHash);
ArrayList[] lists= (ArrayList[]) symbolMap.get(location);
if (lists != null) { 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; return file;
} }
@ -410,17 +431,4 @@ abstract public class PDOMWriter {
protected long getLastModified(IIndexFileLocation location) throws CoreException { protected long getLastModified(IIndexFileLocation location) throws CoreException {
return EFS.getStore(location.getURI()).fetchInfo().getLastModified(); 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;
}
} }

View file

@ -30,7 +30,6 @@ import java.util.zip.ZipFile;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMIndexerTask; 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.IIndexFileLocation;
import org.eclipse.cdt.core.index.IndexLocationFactory; import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.CoreModel; 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_BEGIN = "\\${$1:"; //$NON-NLS-1$
private static final String PROJECT_VAR_REPLACEMENT_END = "}"; //$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 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 Pattern DOLLAR_OR_BACKSLASH_PATTERN= Pattern.compile("[\\$\\\\]"); //$NON-NLS-1$
private static final IIndexFragmentFile[] NO_IDS = {};
private static final class FileAndChecksum { private static final class FileAndChecksum {
public ITranslationUnit fFile; public ITranslationUnit fFile;
@ -268,7 +265,7 @@ public class TeamPDOMImportOperation implements IWorkspaceRunnable {
IndexFileLocation ifl = (IndexFileLocation) i.next(); IndexFileLocation ifl = (IndexFileLocation) i.next();
IIndexFragmentFile file= pdom.getFile(ifl); IIndexFragmentFile file= pdom.getFile(ifl);
pdom.clearFile(file, NO_INCLUDES, NO_IDS); pdom.clearFile(file, null);
} }
for (Iterator i = updateTimestamps.iterator(); i.hasNext();) { for (Iterator i = updateTimestamps.iterator(); i.hasNext();) {
checkMonitor(monitor); checkMonitor(monitor);

View file

@ -15,18 +15,19 @@ package org.eclipse.cdt.internal.core.pdom;
import java.io.File; import java.io.File;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTName; 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.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexLocationConverter; import org.eclipse.cdt.core.index.IIndexLocationConverter;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile; import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IWritableIndexFragment; 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.ChunkCache;
import org.eclipse.cdt.internal.core.pdom.db.DBProperties; import org.eclipse.cdt.internal.core.pdom.db.DBProperties;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor; 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, public void addFileContent(IIndexFragmentFile sourceFile,
IncludeInformation[] includes,
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names) throws CoreException { IASTPreprocessorMacroDefinition[] macros, IASTName[][] names) throws CoreException {
assert sourceFile.getIndexFragment() == this; assert sourceFile.getIndexFragment() == this;
PDOMFile pdomFile = (PDOMFile) sourceFile; PDOMFile pdomFile = (PDOMFile) sourceFile;
pdomFile.addIncludesTo(includes);
pdomFile.addMacros(macros); pdomFile.addMacros(macros);
pdomFile.addNames(names); pdomFile.addNames(names);
} }
public void clearFile(IIndexFragmentFile file, public void clearFile(IIndexFragmentFile file, Collection contextsRemoved) throws CoreException {
IASTPreprocessorIncludeStatement[] newIncludes, IIndexFragmentFile[] destFiles) throws CoreException {
assert file.getIndexFragment() == this; assert file.getIndexFragment() == this;
assert newIncludes.length == destFiles.length; ((PDOMFile) file).clear(contextsRemoved);
((PDOMFile) file).clear(newIncludes, destFiles);
} }
public void clear() throws CoreException { public void clear() throws CoreException {
@ -130,7 +131,7 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
for(Iterator i = notConverted.iterator(); i.hasNext(); ) { for(Iterator i = notConverted.iterator(); i.hasNext(); ) {
PDOMFile file = (PDOMFile) i.next(); PDOMFile file = (PDOMFile) i.next();
file.convertIncludersToUnresolved(); file.convertIncludersToUnresolved();
file.clear(null, null); file.clear(null);
} }
} }

View file

@ -13,13 +13,13 @@
package org.eclipse.cdt.internal.core.pdom.dom; package org.eclipse.cdt.internal.core.pdom.dom;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTName; 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.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexInclude; 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.IIndexFragment;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile; import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IWritableIndexFragment; 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.PDOM;
import org.eclipse.cdt.internal.core.pdom.WritablePDOM; import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
import org.eclipse.cdt.internal.core.pdom.db.BTree; import org.eclipse.cdt.internal.core.pdom.db.BTree;
@ -45,7 +46,6 @@ import org.eclipse.core.runtime.CoreException;
* *
*/ */
public class PDOMFile implements IIndexFragmentFile { public class PDOMFile implements IIndexFragmentFile {
private final PDOM pdom; private final PDOM pdom;
private final int record; private final int record;
@ -165,6 +165,10 @@ public class PDOMFile implements IIndexFragmentFile {
int rec = pdom.getDB().getInt(record + FIRST_INCLUDED_BY); int rec = pdom.getDB().getInt(record + FIRST_INCLUDED_BY);
return rec != 0 ? new PDOMInclude(pdom, rec) : null; return rec != 0 ? new PDOMInclude(pdom, rec) : null;
} }
public IIndexInclude getParsedInContext() throws CoreException {
return getFirstIncludedBy();
}
public void setFirstIncludedBy(PDOMInclude includedBy) throws CoreException { public void setFirstIncludedBy(PDOMInclude includedBy) throws CoreException {
int rec = includedBy != null ? includedBy.getRecord() : 0; int rec = includedBy != null ? includedBy.getRecord() : 0;
@ -235,63 +239,18 @@ public class PDOMFile implements IIndexFragmentFile {
return result; return result;
} }
public void clear(IASTPreprocessorIncludeStatement[] newIncludes, IIndexFragmentFile[] destFiles) throws CoreException { public void clear(Collection contextsRemoved) throws CoreException {
int[] records= new int[destFiles.length]; // Remove the includes
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
PDOMInclude include = getFirstInclude(); PDOMInclude include = getFirstInclude();
while (include != null) { while (include != null) {
PDOMInclude nextInclude = include.getNextInIncludes(); PDOMInclude nextInclude = include.getNextInIncludes();
final PDOMFile includes= (PDOMFile) include.getIncludes(); if (contextsRemoved != null && include.getPrevInIncludedByRecord() == 0) {
if (includes != null) { contextsRemoved.add(include.getIncludesLocation());
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();
}
} }
include.delete();
include = nextInclude; include = nextInclude;
} }
setFirstInclude(null); setFirstInclude(include);
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;
}
// Delete all the macros in this file // Delete all the macros in this file
PDOMMacro macro = getFirstMacro(); PDOMMacro macro = getFirstMacro();
@ -318,16 +277,51 @@ public class PDOMFile implements IIndexFragmentFile {
setFirstName(null); setFirstName(null);
} }
public void addIncludedBy(PDOMInclude include) throws CoreException { public void addIncludesTo(IncludeInformation[] includeInfos) throws CoreException {
PDOMInclude firstIncludedBy = getFirstIncludedBy(); assert getFirstInclude() == null;
if (firstIncludedBy != null) {
include.setNextInIncludedBy(firstIncludedBy); PDOMInclude lastInclude= null;
firstIncludedBy.setPrevInIncludedBy(include); 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 { public IIndexInclude[] getIncludes() throws CoreException {
List result= new ArrayList(); List result= new ArrayList();

View file

@ -72,20 +72,6 @@ public class PDOMInclude implements IIndexFragmentInclude {
setIncludes(targetFile, name.toCharArray()); 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) { private byte encodeFlags(IASTPreprocessorIncludeStatement include, boolean unresolved) {
byte flags= 0; byte flags= 0;
if (include.isSystemInclude()) { if (include.isSystemInclude()) {
@ -187,9 +173,13 @@ public class PDOMInclude implements IIndexFragmentInclude {
} }
public PDOMInclude getPrevInIncludedBy() throws CoreException { 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; 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 { public void setPrevInIncludedBy(PDOMInclude include) throws CoreException {
int rec = include != null ? include.getRecord() : 0; int rec = include != null ? include.getRecord() : 0;

View file

@ -25,7 +25,6 @@ import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMIndexer; import org.eclipse.cdt.core.dom.IPDOMIndexer;
import org.eclipse.cdt.core.dom.IPDOMIndexerTask; 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.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFile; 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.IIndexManager;
import org.eclipse.cdt.core.index.IndexLocationFactory; import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.AbstractLanguage; 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.CoreModelUtil;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ILanguage; 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 Object NO_CONTEXT = new Object();
private static final int MAX_ERRORS = 500; private static final int MAX_ERRORS = 500;
private static final String TRUE = "true"; //$NON-NLS-1$ private static final String TRUE = "true"; //$NON-NLS-1$
private static final IIndexFileLocation[] NO_LOCATIONS= {};
private static final IASTPreprocessorIncludeStatement[] NO_INCLUDES= {};
private AbstractPDOMIndexer fIndexer; private AbstractPDOMIndexer fIndexer;
protected Map/*<IIndexFileLocation, Object>*/ fContextMap = new HashMap/*<IIndexFileLocation, Object>*/(); 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); Object cachedContext= fContextMap.get(location);
if (cachedContext != null) { if (cachedContext != null) {
return cachedContext == NO_CONTEXT ? null : (ITranslationUnit) cachedContext; 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 fContextMap.put(location, NO_CONTEXT); // prevent recursion
IIndexFile pdomFile; IIndexFile pdomFile;
try { try {
final ICProject project= getIndexer().getProject();
pdomFile = index.getFile(location); pdomFile = index.getFile(location);
if (pdomFile != null) { 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); IIndexInclude[] includedBy = index.findIncludedBy(pdomFile, IIndex.DEPTH_ZERO);
for (int i = includedBy.length-1; i >=0; i--) { for (int i = includedBy.length-1; i >=0; i--) {
IIndexInclude include = includedBy[i]; final IIndexFileLocation loc= includedBy[i].getIncludedByLocation();
IIndexFileLocation incLocation = include.getIncludedByLocation(); ITranslationUnit context= getSourceUnit(project, loc);
ITranslationUnit context= null; if (context == null) {
if (CoreModel.isValidSourceUnitName(project.getProject(), incLocation.getURI().toString())) { // FIXME - is this ok? context= findContext(index, loc);
context = CoreModelUtil.findTranslationUnitForLocation(IndexLocationFactory.getAbsolutePath(incLocation), project);
}
else {
context= findContext(index, incLocation);
} }
if (context != null) { if (context != null) {
fContextMap.put(location, context); fContextMap.put(location, context);
@ -407,6 +413,17 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
return null; 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. * Conveninence method for subclasses, removes a translation unit from the index.
* @since 4.0 * @since 4.0
@ -416,7 +433,7 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
try { try {
IIndexFragmentFile file = (IIndexFragmentFile) index.getFile(IndexLocationFactory.getIFL(tu)); IIndexFragmentFile file = (IIndexFragmentFile) index.getFile(IndexLocationFactory.getIFL(tu));
if (file != null) if (file != null)
index.clearFile(file, NO_INCLUDES, NO_LOCATIONS); index.clearFile(file, null);
} finally { } finally {
index.releaseWriteLock(readlocks); index.releaseWriteLock(readlocks);
} }

View file

@ -361,8 +361,9 @@ CDTIndexer.nullindexer=No Indexer (search based features will not work correctly
CDTIndexer.fastindexer=Fast C/C++ Indexer (recommended) CDTIndexer.fastindexer=Fast C/C++ Indexer (recommended)
IndexView.name=C/C++ Index IndexView.name=C/C++ Index
RebuildIndex.name=Rebuild RebuildIndex.name=&Rebuild
SyncIndex.name=Update with Modified Files SyncIndex.name=&Update with Modified Files
FreshenIndex.name=&Freshen All Files
indexerPage.name = Indexer Page indexerPage.name = Indexer Page
proposalFilter.name = Code Completion Proposal Filter proposalFilter.name = Code Completion Proposal Filter

View file

@ -711,6 +711,11 @@
</and> </and>
</or> </or>
</visibility> </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 <action
class="org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesAction" class="org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesAction"
id="org.eclipse.cdt.ui.syncIndexWithDiskAction" id="org.eclipse.cdt.ui.syncIndexWithDiskAction"
@ -721,7 +726,7 @@
label="%Index.menu" label="%Index.menu"
path="buildGroup"> path="buildGroup">
<groupMarker name="rebuild"/> <groupMarker name="rebuild"/>
<groupMarker name="update"/> <separator name="update"/>
</menu> </menu>
</objectContribution> </objectContribution>
<objectContribution <objectContribution
@ -737,7 +742,7 @@
label="%Index.menu" label="%Index.menu"
path="buildGroup"> path="buildGroup">
<groupMarker name="rebuild"/> <groupMarker name="rebuild"/>
<groupMarker name="update"/> <separator name="update"/>
</menu> </menu>
</objectContribution> </objectContribution>
<!-- project explorer shows IProjects, we need to handle this --> <!-- project explorer shows IProjects, we need to handle this -->
@ -748,7 +753,12 @@
<objectState <objectState
name="projectNature" name="projectNature"
value="org.eclipse.cdt.core.cnature"/> value="org.eclipse.cdt.core.cnature"/>
</visibility> </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 <action
class="org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesAction" class="org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesAction"
id="org.eclipse.cdt.ui.syncIndexWithDiskAction" id="org.eclipse.cdt.ui.syncIndexWithDiskAction"
@ -764,7 +774,7 @@
label="%Index.menu" label="%Index.menu"
path="buildGroup"> path="buildGroup">
<groupMarker name="rebuild"/> <groupMarker name="rebuild"/>
<groupMarker name="update"/> <separator name="update"/>
</menu> </menu>
</objectContribution> </objectContribution>
<objectContribution <objectContribution

View file

@ -14,11 +14,8 @@ package org.eclipse.cdt.internal.corext.util;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath; 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.CModelException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.CoreModelUtil; import org.eclipse.cdt.core.model.CoreModelUtil;
@ -152,38 +149,4 @@ public class CModelUtil {
public static ITranslationUnit findTranslationUnitForLocation(IPath location, ICProject preferredProject) throws CModelException { public static ITranslationUnit findTranslationUnitForLocation(IPath location, ICProject preferredProject) throws CModelException {
return CoreModelUtil.findTranslationUnitForLocation(location, preferredProject); 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;
}
} }

View file

@ -18,11 +18,10 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IndexLocationFactory; import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.CModelException; 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.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.corext.util.CModelUtil;
import org.eclipse.cdt.internal.ui.util.CoreUtility; import org.eclipse.cdt.internal.ui.util.CoreUtility;
public class IBFile { public class IBFile {
@ -38,7 +37,7 @@ public class IBFile {
public IBFile(ICProject preferredProject, IIndexFileLocation location) throws CModelException { public IBFile(ICProject preferredProject, IIndexFileLocation location) throws CModelException {
fLocation= location; fLocation= location;
fTU= CModelUtil.findTranslationUnitForLocation(location, preferredProject); fTU= CoreModelUtil.findTranslationUnitForLocation(location, preferredProject);
String name= fLocation.getURI().getPath(); String name= fLocation.getURI().getPath();
fName= name.substring(name.lastIndexOf('/')+1); fName= name.substring(name.lastIndexOf('/')+1);
} }