1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-09 17:25:38 +02:00

Fix for 180159, modelling of unresolved includes in index.

This commit is contained in:
Markus Schorn 2007-04-05 16:06:39 +00:00
parent 39e042242d
commit 0da5cc01ce
16 changed files with 259 additions and 135 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others. * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * 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
@ -56,6 +56,13 @@ public interface IIndexInclude {
* @throws CoreException * @throws CoreException
*/ */
IIndexFileLocation getIncludesLocation() throws CoreException; IIndexFileLocation getIncludesLocation() throws CoreException;
/**
* Returns the simple name of the directive. This skips any leading
* direcories. E.g.: for '<sys/types.h>' 'types.h' will be returned.
* @throws CoreException
*/
String getName() throws CoreException;
/** /**
* Returns the character offset of the name of the include in its source file. The name does * Returns the character offset of the name of the include in its source file. The name does

View file

@ -234,7 +234,9 @@ public class CIndex implements IIndex {
IIndexInclude[] includes= file.getIncludes(); IIndexInclude[] includes= file.getIncludes();
for (int k= 0; k < includes.length; k++) { for (int k= 0; k < includes.length; k++) {
IIndexInclude include = includes[k]; IIndexInclude include = includes[k];
if (handled.add(include.getIncludesLocation())) { IIndexFileLocation target= include.getIncludesLocation();
Object key= target != null ? (Object) target : include.getName();
if (handled.add(key)) {
out.add(include); out.add(include);
if (depth != 0) { if (depth != 0) {
IIndexFile includedByFile= resolveInclude(include); IIndexFile includedByFile= resolveInclude(include);

View file

@ -174,7 +174,6 @@ public class IndexFactory {
} }
public IWritableIndex getWritableIndex(ICProject project) throws CoreException { public IWritableIndex getWritableIndex(ICProject project) throws CoreException {
// mstodo to support dependent projects: Collection selectedProjects= getSelectedProjects(new ICProject[]{project}, false);
IndexProviderManager m = CCoreInternals.getPDOMManager().getIndexProviderManager(); IndexProviderManager m = CCoreInternals.getPDOMManager().getIndexProviderManager();
Collection selectedProjects= Collections.singleton(project); Collection selectedProjects= Collections.singleton(project);
@ -184,7 +183,7 @@ public class IndexFactory {
ICProject p = (ICProject) iter.next(); ICProject p = (ICProject) iter.next();
IWritableIndexFragment pdom= (IWritableIndexFragment) fPDOMManager.getPDOM(p); IWritableIndexFragment pdom= (IWritableIndexFragment) fPDOMManager.getPDOM(p);
if (pdom != null) { if (pdom != null) {
safeAddFragment(fragments, (IIndexFragment) pdom); safeAddFragment(fragments, pdom);
ICProjectDescription pd= CoreModel.getDefault().getProjectDescription(p.getProject(), false); ICProjectDescription pd= CoreModel.getDefault().getProjectDescription(p.getProject(), false);
if(pd!=null) { if(pd!=null) {
ICConfigurationDescription activeCfg= pd.getActiveConfiguration(); ICConfigurationDescription activeCfg= pd.getActiveConfiguration();

View file

@ -65,7 +65,9 @@ public class WritableCIndex extends CIndex implements IWritableIndex {
IIndexFragmentFile[] destFiles= new IIndexFragmentFile[includes.length]; IIndexFragmentFile[] destFiles= new IIndexFragmentFile[includes.length];
for (int i = 0; i < includes.length; i++) { for (int i = 0; i < includes.length; i++) {
destFiles[i]= addFile(includeLocations[i]); if (includeLocations[i] != null) {
destFiles[i]= addFile(includeLocations[i]);
}
} }
((IWritableIndexFragment) indexFragment).addFileContent(file, ((IWritableIndexFragment) indexFragment).addFileContent(file,
includes, destFiles, macros, names); includes, destFiles, macros, names);

View file

@ -73,7 +73,7 @@ import org.eclipse.core.runtime.Status;
public class PDOM extends PlatformObject implements IIndexFragment, IPDOM { public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
protected Database db; protected Database db;
public static final int VERSION = 28; public static final int VERSION = 29;
// 0 - the beginning of it all // 0 - the beginning of it all
// 1 - first change to kick off upgrades // 1 - first change to kick off upgrades
// 2 - added file inclusions // 2 - added file inclusions
@ -103,6 +103,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
// 26 - add properties storage // 26 - add properties storage
// 27 - templates: classes, functions, limited nesting support, only template type parameters // 27 - templates: classes, functions, limited nesting support, only template type parameters
// 28 - templates: class instance/specialization base classes // 28 - templates: class instance/specialization base classes
// 29 - includes: fixed modelling of unresolved includes (180159)
public static final int LINKAGES = Database.DATA_AREA; public static final int LINKAGES = Database.DATA_AREA;
public static final int FILE_INDEX = Database.DATA_AREA + 4; public static final int FILE_INDEX = Database.DATA_AREA + 4;

View file

@ -23,7 +23,6 @@ import java.text.MessageFormat;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
@ -51,7 +50,6 @@ import org.eclipse.cdt.internal.core.index.IndexerStateEvent;
import org.eclipse.cdt.internal.core.index.provider.IndexProviderManager; import org.eclipse.cdt.internal.core.index.provider.IndexProviderManager;
import org.eclipse.cdt.internal.core.pdom.PDOM.IListener; import org.eclipse.cdt.internal.core.pdom.PDOM.IListener;
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.dom.PDOMFile;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMProjectIndexLocationConverter; import org.eclipse.cdt.internal.core.pdom.dom.PDOMProjectIndexLocationConverter;
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMRebuildTask; import org.eclipse.cdt.internal.core.pdom.indexer.PDOMRebuildTask;
@ -967,13 +965,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
try { try {
newPDOM.acquireWriteLock(); newPDOM.acquireWriteLock();
try { try {
List notConverted= newPDOM.rewriteLocations(newConverter); newPDOM.rewriteLocations(newConverter);
// remove content where converter returns null
for(Iterator i = notConverted.iterator(); i.hasNext(); ) {
PDOMFile file = (PDOMFile) i.next();
file.clear();
}
// ensure fragment id has a sensible value, in case callee's do not // ensure fragment id has a sensible value, in case callee's do not
// overwrite their own values // overwrite their own values

View file

@ -190,43 +190,57 @@ abstract public class PDOMWriter {
} }
private IIndexFileLocation[] extractSymbols(IASTTranslationUnit ast, final Map symbolMap) throws CoreException { private IIndexFileLocation[] extractSymbols(IASTTranslationUnit ast, final Map symbolMap) throws CoreException {
LinkedHashSet/*<IIndexFileLocation>*/ orderedIncludes= new LinkedHashSet/*<IIndexFileLocation>*/(); LinkedHashSet/*<IIndexFileLocation>*/ orderedIFLs= new LinkedHashSet/*<IIndexFileLocation>*/();
ArrayList/*<IIndexFileLocation>*/ stack= new ArrayList/*<IIndexFileLocation>*/(); ArrayList/*<IIndexFileLocation>*/ iflStack= new ArrayList/*<IIndexFileLocation>*/();
final IIndexFileLocation astLocation = findLocation(ast.getFilePath()); final IIndexFileLocation astLocation = findLocation(ast.getFilePath());
IIndexFileLocation currentPath = astLocation; IIndexFileLocation aboveStackIFL = astLocation;
IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives(); IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives();
for (int i= 0; i < includes.length; i++) { for (int i= 0; i < includes.length; i++) {
IASTPreprocessorIncludeStatement include = includes[i]; final IASTPreprocessorIncludeStatement include = includes[i];
IASTFileLocation sourceLoc = include.getFileLocation();
IIndexFileLocation newPath= sourceLoc != null ? findLocation(sourceLoc.getFileName()) : astLocation; // command-line includes // check if we have left a file.
while (!stack.isEmpty() && !currentPath.equals(newPath)) { final IASTFileLocation tmpLoc = include.getFileLocation();
if (needToUpdate(currentPath)) { final IIndexFileLocation nextIFL= tmpLoc != null ? findLocation(tmpLoc.getFileName()) : astLocation; // command-line includes
prepareInMap(symbolMap, currentPath); while (!aboveStackIFL.equals(nextIFL)) {
orderedIncludes.add(currentPath); if (!iflStack.isEmpty()) {
if (needToUpdate(aboveStackIFL)) {
prepareInMap(symbolMap, aboveStackIFL);
orderedIFLs.add(aboveStackIFL);
}
aboveStackIFL= (IIndexFileLocation) iflStack.remove(iflStack.size()-1);
}
else {
assert false; // logics in parser is broken, still do something useful
iflStack.add(aboveStackIFL);
aboveStackIFL= nextIFL;
break;
} }
currentPath= (IIndexFileLocation) stack.remove(stack.size()-1);
} }
if (needToUpdate(newPath)) {
prepareInMap(symbolMap, newPath); // save include in map
addToMap(symbolMap, 0, newPath, include); if (needToUpdate(nextIFL)) {
prepareInMap(symbolMap, nextIFL);
addToMap(symbolMap, 0, nextIFL, include);
} }
// prepare to go into next level
if (include.isResolved()) { if (include.isResolved()) {
stack.add(currentPath); iflStack.add(nextIFL);
currentPath= findLocation(include.getPath()); aboveStackIFL= findLocation(include.getPath());
} }
else if (include.isActive()) { else if (include.isActive()) {
reportProblem(include); reportProblem(include);
} }
} }
stack.add(currentPath); iflStack.add(aboveStackIFL);
while (!stack.isEmpty()) { while (!iflStack.isEmpty()) {
currentPath= (IIndexFileLocation) stack.remove(stack.size()-1); aboveStackIFL= (IIndexFileLocation) iflStack.remove(iflStack.size()-1);
if (needToUpdate(currentPath)) { if (needToUpdate(aboveStackIFL)) {
prepareInMap(symbolMap, currentPath); prepareInMap(symbolMap, aboveStackIFL);
orderedIncludes.add(currentPath); orderedIFLs.add(aboveStackIFL);
} }
} }
@ -261,7 +275,7 @@ abstract public class PDOMWriter {
} }
} }
}); });
return (IIndexFileLocation[]) orderedIncludes.toArray(new IIndexFileLocation[orderedIncludes.size()]); return (IIndexFileLocation[]) orderedIFLs.toArray(new IIndexFileLocation[orderedIFLs.size()]);
} }
protected boolean isInheritanceSpec(IASTName name) { protected boolean isInheritanceSpec(IASTName name) {
@ -345,7 +359,9 @@ abstract public class PDOMWriter {
IIndexFileLocation[] includeLocations = new IIndexFileLocation[includes.length]; IIndexFileLocation[] includeLocations = new IIndexFileLocation[includes.length];
for(int i=0; i<includes.length; i++) { for(int i=0; i<includes.length; i++) {
includeLocations[i] = findLocation(includes[i].getPath()); if (includes[i].isResolved()) {
includeLocations[i] = findLocation(includes[i].getPath());
}
} }
index.setFileContent(file, includes, includeLocations, macros, names); index.setFileContent(file, includes, includeLocations, macros, names);
} }

View file

@ -99,7 +99,7 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
* @return a list of PDOMFiles for which the location converter returned null when queried for the new internal representation * @return a list of PDOMFiles for which the location converter returned null when queried for the new internal representation
* @throws CoreException * @throws CoreException
*/ */
public List/*<PDOMFile>*/ rewriteLocations(final IIndexLocationConverter newConverter) throws CoreException { public void rewriteLocations(final IIndexLocationConverter newConverter) throws CoreException {
final List pdomfiles = new ArrayList(); final List pdomfiles = new ArrayList();
getFileIndex().accept(new IBTreeVisitor(){ getFileIndex().accept(new IBTreeVisitor(){
public int compare(int record) throws CoreException { public int compare(int record) throws CoreException {
@ -125,7 +125,13 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
} }
} }
return notConverted;
// remove content where converter returns null
for(Iterator i = notConverted.iterator(); i.hasNext(); ) {
PDOMFile file = (PDOMFile) i.next();
file.convertIncludersToUnresolved();
file.clear();
}
} }
boolean isClearedBecauseOfVersionMismatch() { boolean isClearedBecauseOfVersionMismatch() {

View file

@ -266,14 +266,13 @@ public class PDOMFile implements IIndexFragmentFile {
PDOMInclude lastInclude= null; PDOMInclude lastInclude= null;
for (int i = 0; i < includes.length; i++) { for (int i = 0; i < includes.length; i++) {
IASTPreprocessorIncludeStatement statement = includes[i]; IASTPreprocessorIncludeStatement statement = includes[i];
PDOMFile thisIncludes= (PDOMFile) files[i]; PDOMFile targetFile= (PDOMFile) files[i];
assert thisIncludes.getIndexFragment() instanceof IWritableIndexFragment;
PDOMInclude pdomInclude = new PDOMInclude(pdom, statement, this, targetFile);
PDOMInclude pdomInclude = new PDOMInclude(pdom, statement); if (targetFile != null) {
pdomInclude.setIncludedBy(this); assert targetFile.getIndexFragment() instanceof IWritableIndexFragment;
pdomInclude.setIncludes(thisIncludes); targetFile.addIncludedBy(pdomInclude);
}
thisIncludes.addIncludedBy(pdomInclude);
if (lastInclude == null) { if (lastInclude == null) {
setFirstInclude(pdomInclude); setFirstInclude(pdomInclude);
} }
@ -391,4 +390,17 @@ public class PDOMFile implements IIndexFragmentFile {
public boolean hasNames() throws CoreException { public boolean hasNames() throws CoreException {
return getFirstName()!=null; return getFirstName()!=null;
} }
public void convertIncludersToUnresolved() throws CoreException {
// Remove the includes
PDOMInclude include = getFirstIncludedBy();
while (include != null) {
PDOMInclude nextInclude = include.getNextInIncludedBy();
include.convertToUnresolved();
include.setNextInIncludedBy(null);
include.setPrevInIncludedBy(null);
include = nextInclude;
}
setFirstIncludedBy(null);
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006 QNX Software Systems and others. * Copyright (c) 2006, 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
@ -21,6 +21,8 @@ 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.IIndexFragmentInclude; import org.eclipse.cdt.internal.core.index.IIndexFragmentInclude;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.db.IString;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
/** /**
@ -32,7 +34,7 @@ public class PDOMInclude implements IIndexFragmentInclude {
private final PDOM pdom; private final PDOM pdom;
private final int record; private final int record;
private final int INCLUDES = 0; private final int INCLUDES_FILE_OR_NAME = 0;
private final int INCLUDED_BY = 4; private final int INCLUDED_BY = 4;
private final int INCLUDES_NEXT = 8; private final int INCLUDES_NEXT = 8;
private final int INCLUDED_BY_NEXT = 12; private final int INCLUDED_BY_NEXT = 12;
@ -46,13 +48,16 @@ public class PDOMInclude implements IIndexFragmentInclude {
private static final int FLAG_UNRESOLVED_INCLUDE = 4; private static final int FLAG_UNRESOLVED_INCLUDE = 4;
private final int RECORD_SIZE = 27; private final int RECORD_SIZE = 27;
// cached fields
private String fName= null;
public PDOMInclude(PDOM pdom, int record) { public PDOMInclude(PDOM pdom, int record) {
this.pdom = pdom; this.pdom = pdom;
this.record = record; this.record = record;
} }
public PDOMInclude(PDOM pdom, IASTPreprocessorIncludeStatement include) throws CoreException { public PDOMInclude(PDOM pdom, IASTPreprocessorIncludeStatement include, PDOMFile containerFile, PDOMFile targetFile) throws CoreException {
this.pdom = pdom; this.pdom = pdom;
this.record = pdom.getDB().malloc(RECORD_SIZE); this.record = pdom.getDB().malloc(RECORD_SIZE);
IASTName name= include.getName(); IASTName name= include.getName();
@ -61,10 +66,13 @@ public class PDOMInclude implements IIndexFragmentInclude {
if (loc != null) { if (loc != null) {
setNameOffsetAndLength(loc.getNodeOffset(), (short) loc.getNodeLength()); setNameOffsetAndLength(loc.getNodeOffset(), (short) loc.getNodeLength());
} }
setFlag(encodeFlags(include));
setFlag(encodeFlags(include, targetFile == null));
setIncludedBy(containerFile);
setIncludes(targetFile, name.toCharArray());
} }
private byte encodeFlags(IASTPreprocessorIncludeStatement include) { private byte encodeFlags(IASTPreprocessorIncludeStatement include, boolean unresolved) {
byte flags= 0; byte flags= 0;
if (include.isSystemInclude()) { if (include.isSystemInclude()) {
flags |= FLAG_SYSTEM_INCLUDE; flags |= FLAG_SYSTEM_INCLUDE;
@ -72,7 +80,7 @@ public class PDOMInclude implements IIndexFragmentInclude {
if (!include.isActive()) { if (!include.isActive()) {
flags |= FLAG_INACTIVE_INCLUDE; flags |= FLAG_INACTIVE_INCLUDE;
} }
if (!include.isResolved()) { if (unresolved) {
flags |= FLAG_UNRESOLVED_INCLUDE; flags |= FLAG_UNRESOLVED_INCLUDE;
} }
return flags; return flags;
@ -83,29 +91,55 @@ public class PDOMInclude implements IIndexFragmentInclude {
} }
public void delete() throws CoreException { public void delete() throws CoreException {
// Remove us from the includedBy chain if (isResolved()) {
// Remove us from the includedBy chain
removeThisFromIncludedByChain();
}
else {
getNameForUnresolved().delete();
}
// Delete our record
pdom.getDB().free(record);
}
private void removeThisFromIncludedByChain() throws CoreException {
PDOMInclude prevInclude = getPrevInIncludedBy(); PDOMInclude prevInclude = getPrevInIncludedBy();
PDOMInclude nextInclude = getNextInIncludedBy(); PDOMInclude nextInclude = getNextInIncludedBy();
if (prevInclude != null) if (prevInclude != null)
prevInclude.setNextInIncludedBy(nextInclude); prevInclude.setNextInIncludedBy(nextInclude);
else else
((PDOMFile) getIncludes()).setFirstIncludedBy(nextInclude); ((PDOMFile) getIncludes()).setFirstIncludedBy(nextInclude);
if (nextInclude != null) if (nextInclude != null)
nextInclude.setPrevInIncludedBy(prevInclude); nextInclude.setPrevInIncludedBy(prevInclude);
// Delete our record
pdom.getDB().free(record);
} }
private IString getNameForUnresolved() throws CoreException {
if (isResolved()) {
return null;
}
final Database db = pdom.getDB();
return db.getString(db.getInt(record + INCLUDES_FILE_OR_NAME));
}
public IIndexFragmentFile getIncludes() throws CoreException { public IIndexFragmentFile getIncludes() throws CoreException {
int rec = pdom.getDB().getInt(record + INCLUDES); if (!isResolved()) {
return null;
}
int rec = pdom.getDB().getInt(record + INCLUDES_FILE_OR_NAME);
return rec != 0 ? new PDOMFile(pdom, rec) : null; return rec != 0 ? new PDOMFile(pdom, rec) : null;
} }
public void setIncludes(PDOMFile includes) throws CoreException { private void setIncludes(PDOMFile includes, char[] name) throws CoreException {
int rec = includes != null ? includes.getRecord() : 0; int rec= 0;
pdom.getDB().putInt(record + INCLUDES, rec); if (includes == null) {
rec= pdom.getDB().newString(name).getRecord();
}
else {
rec= includes.getRecord();
}
pdom.getDB().putInt(record + INCLUDES_FILE_OR_NAME, rec);
} }
public IIndexFile getIncludedBy() throws CoreException { public IIndexFile getIncludedBy() throws CoreException {
@ -113,7 +147,7 @@ public class PDOMInclude implements IIndexFragmentInclude {
return rec != 0 ? new PDOMFile(pdom, rec) : null; return rec != 0 ? new PDOMFile(pdom, rec) : null;
} }
public void setIncludedBy(PDOMFile includedBy) throws CoreException { private void setIncludedBy(PDOMFile includedBy) throws CoreException {
int rec = includedBy != null ? includedBy.getRecord() : 0; int rec = includedBy != null ? includedBy.getRecord() : 0;
pdom.getDB().putInt(record + INCLUDED_BY, rec); pdom.getDB().putInt(record + INCLUDED_BY, rec);
} }
@ -153,6 +187,9 @@ public class PDOMInclude implements IIndexFragmentInclude {
} }
public IIndexFileLocation getIncludesLocation() throws CoreException { public IIndexFileLocation getIncludesLocation() throws CoreException {
if (!isResolved()) {
return null;
}
return getIncludes().getLocation(); return getIncludes().getLocation();
} }
@ -191,5 +228,29 @@ public class PDOMInclude implements IIndexFragmentInclude {
public int getNameLength() throws CoreException { public int getNameLength() throws CoreException {
return pdom.getDB().getShort(record + NODE_LENGTH_OFFSET) & 0xffff; return pdom.getDB().getShort(record + NODE_LENGTH_OFFSET) & 0xffff;
} }
public String getName() throws CoreException {
if (fName == null) {
computeName();
}
return fName;
}
private void computeName() throws CoreException {
if (isResolved()) {
fName= getIncludes().getLocation().getURI().getPath();
fName= fName.substring(fName.lastIndexOf('/')+1);
}
else {
fName= getNameForUnresolved().getString();
}
}
public void convertToUnresolved() throws CoreException {
if (isResolved()) {
setIncludes(null, getName().toCharArray());
setFlag((byte) (getFlag() | FLAG_UNRESOLVED_INCLUDE));
}
}
} }

View file

@ -94,23 +94,24 @@ public class PDOMResourceDeltaTask implements IPDOMIndexerTask {
switch (element.getElementType()) { switch (element.getElementType()) {
case ICElement.C_UNIT: case ICElement.C_UNIT:
ITranslationUnit tu = (ITranslationUnit)element; ITranslationUnit tu = (ITranslationUnit)element;
switch (delta.getKind()) { if (!tu.isWorkingCopy()) {
case ICElementDelta.CHANGED: switch (delta.getKind()) {
if ((flags & ICElementDelta.F_CONTENT) != 0 && case ICElementDelta.CHANGED:
(fAllFiles || !CoreModel.isScannerInformationEmpty(tu.getResource())) || tu.isHeaderUnit()) { if ((flags & ICElementDelta.F_CONTENT) != 0) {
changed.add(tu); if (fAllFiles || !CoreModel.isScannerInformationEmpty(tu.getResource()) || tu.isHeaderUnit()) {
} changed.add(tu);
break; }
case ICElementDelta.ADDED: }
if (!tu.isWorkingCopy() && break;
(fAllFiles || !CoreModel.isScannerInformationEmpty(tu.getResource())) || tu.isHeaderUnit()) { case ICElementDelta.ADDED:
added.add(tu); if (fAllFiles || !CoreModel.isScannerInformationEmpty(tu.getResource()) || tu.isHeaderUnit()) {
} added.add(tu);
break; }
case ICElementDelta.REMOVED: break;
if (!tu.isWorkingCopy()) case ICElementDelta.REMOVED:
removed.add(tu); removed.add(tu);
break; break;
}
} }
break; break;
case ICElement.C_CCONTAINER: case ICElement.C_CCONTAINER:

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others. * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * 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
@ -14,7 +14,6 @@ package org.eclipse.cdt.internal.ui.includebrowser;
import java.util.ArrayList; import java.util.ArrayList;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
@ -25,7 +24,7 @@ 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.core.index.IIndexInclude; 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.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
@ -57,11 +56,11 @@ public class IBContentProvider extends AsyncTreeContentProvider {
protected Object[] syncronouslyComputeChildren(Object parentElement) { protected Object[] syncronouslyComputeChildren(Object parentElement) {
if (parentElement instanceof ITranslationUnit) { if (parentElement instanceof ITranslationUnit) {
ITranslationUnit tu = (ITranslationUnit) parentElement; ITranslationUnit tu = (ITranslationUnit) parentElement;
return new Object[] { new IBNode(null, new IBFile(tu), null, null, 0, 0, 0) }; return new Object[] { new IBNode(null, new IBFile(tu), null, 0, 0, 0) };
} }
if (parentElement instanceof IBNode) { if (parentElement instanceof IBNode) {
IBNode node = (IBNode) parentElement; IBNode node = (IBNode) parentElement;
if (node.isRecursive() || node.getRepresentedTranslationUnit() == null) { if (node.isRecursive() || node.getRepresentedIFL() == null) {
return NO_CHILDREN; return NO_CHILDREN;
} }
} }
@ -72,14 +71,15 @@ public class IBContentProvider extends AsyncTreeContentProvider {
protected Object[] asyncronouslyComputeChildren(Object parentElement, IProgressMonitor monitor) { protected Object[] asyncronouslyComputeChildren(Object parentElement, IProgressMonitor monitor) {
if (parentElement instanceof IBNode) { if (parentElement instanceof IBNode) {
IBNode node = (IBNode) parentElement; IBNode node = (IBNode) parentElement;
ITranslationUnit tu= node.getRepresentedTranslationUnit(); IIndexFileLocation ifl= node.getRepresentedIFL();
if (tu == null) { ICProject project= node.getCProject();
if (ifl == null) {
return NO_CHILDREN; return NO_CHILDREN;
} }
IIndex index; IIndex index;
try { try {
index = CCorePlugin.getIndexManager().getIndex(tu.getCProject(), index = CCorePlugin.getIndexManager().getIndex(project,
fComputeIncludedBy ? IIndexManager.ADD_DEPENDENT : IIndexManager.ADD_DEPENDENCIES); fComputeIncludedBy ? IIndexManager.ADD_DEPENDENT : IIndexManager.ADD_DEPENDENCIES);
index.acquireReadLock(); index.acquireReadLock();
} catch (CoreException e) { } catch (CoreException e) {
@ -94,10 +94,10 @@ public class IBContentProvider extends AsyncTreeContentProvider {
IBFile targetFile= null; IBFile targetFile= null;
IIndexInclude[] includes; IIndexInclude[] includes;
if (fComputeIncludedBy) { if (fComputeIncludedBy) {
includes= findIncludedBy(index, tu, NPM); includes= findIncludedBy(index, ifl, NPM);
} }
else { else {
includes= findIncludesTo(index, tu, NPM); includes= findIncludesTo(index, ifl, NPM);
directiveFile= node.getRepresentedFile(); directiveFile= node.getRepresentedFile();
} }
if (includes.length > 0) { if (includes.length > 0) {
@ -105,21 +105,20 @@ public class IBContentProvider extends AsyncTreeContentProvider {
for (int i = 0; i < includes.length; i++) { for (int i = 0; i < includes.length; i++) {
IIndexInclude include = includes[i]; IIndexInclude include = includes[i];
try { try {
IIndexFileLocation includesPath= include.getIncludesLocation();
if (fComputeIncludedBy) { if (fComputeIncludedBy) {
directiveFile= targetFile= new IBFile(tu.getCProject(), include.getIncludedByLocation()); directiveFile= targetFile= new IBFile(project, include.getIncludedByLocation());
} }
else { else {
targetFile= new IBFile(tu.getCProject(), includesPath); IIndexFileLocation includesPath= include.getIncludesLocation();
if (includesPath == null) {
targetFile= new IBFile(include.getName());
}
else {
targetFile= new IBFile(project, includesPath);
}
} }
IPath fullPath= IndexLocationFactory.getPath(includesPath);
String name= "???"; //$NON-NLS-1$
if (fullPath != null && fullPath.segmentCount() > 0) {
name= fullPath.lastSegment();
}
IBNode newnode= new IBNode(node, targetFile, directiveFile, IBNode newnode= new IBNode(node, targetFile, directiveFile,
name, include.getNameOffset(), include.getNameOffset(),
include.getNameLength(), include.getNameLength(),
include.getIncludedBy().getTimestamp()); include.getIncludedBy().getTimestamp());
newnode.setIsActiveCode(include.isActive()); newnode.setIsActiveCode(include.isActive());
@ -152,11 +151,10 @@ public class IBContentProvider extends AsyncTreeContentProvider {
} }
private IIndexInclude[] findIncludedBy(IIndex index, ITranslationUnit tu, IProgressMonitor pm) { private IIndexInclude[] findIncludedBy(IIndex index, IIndexFileLocation ifl, IProgressMonitor pm) {
try { try {
IIndexFileLocation location= IndexLocationFactory.getIFL(tu); if (ifl != null) {
if (location != null) { IIndexFile file= index.getFile(ifl);
IIndexFile file= index.getFile(location);
if (file != null) { if (file != null) {
return index.findIncludedBy(file); return index.findIncludedBy(file);
} }
@ -168,11 +166,10 @@ public class IBContentProvider extends AsyncTreeContentProvider {
return new IIndexInclude[0]; return new IIndexInclude[0];
} }
public IIndexInclude[] findIncludesTo(IIndex index, ITranslationUnit tu, IProgressMonitor pm) { public IIndexInclude[] findIncludesTo(IIndex index, IIndexFileLocation ifl, IProgressMonitor pm) {
try { try {
IIndexFileLocation location= IndexLocationFactory.getIFL(tu); if (ifl != null) {
if (location != null) { IIndexFile file= index.getFile(ifl);
IIndexFile file= index.getFile(location);
if (file != null) { if (file != null) {
return index.findIncludes(file); return index.findIncludes(file);
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others. * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * 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
@ -26,19 +26,29 @@ 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 {
public IIndexFileLocation fLocation; final public ITranslationUnit fTU;
public ITranslationUnit fTU= null; final public IIndexFileLocation fLocation;
final public String fName;
public IBFile(ITranslationUnit tu) { public IBFile(ITranslationUnit tu) {
fTU= tu; fTU= tu;
fLocation= IndexLocationFactory.getIFL(tu); fLocation= IndexLocationFactory.getIFL(tu);
fName= tu.getElementName();
} }
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= CModelUtil.findTranslationUnitForLocation(location, preferredProject);
String name= fLocation.getURI().getPath();
fName= name.substring(name.lastIndexOf('/')+1);
} }
public IBFile(String name) {
fName= name;
fLocation= null;
fTU= null;
}
public IIndexFileLocation getLocation() { public IIndexFileLocation getLocation() {
return fLocation; return fLocation;
} }
@ -53,7 +63,9 @@ public class IBFile {
} }
public int hashCode() { public int hashCode() {
return CoreUtility.safeHashcode(fLocation) + CoreUtility.safeHashcode(fTU); return CoreUtility.safeHashcode(fLocation)
+ 31* (CoreUtility.safeHashcode(fTU)
+ 31* CoreUtility.safeHashcode(fName));
} }
public ITranslationUnit getTranslationUnit() { public ITranslationUnit getTranslationUnit() {
@ -72,4 +84,8 @@ public class IBFile {
} }
return null; return null;
} }
public String getName() {
return fName;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others. * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * 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
@ -19,7 +19,9 @@ import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IColorProvider; import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.*; import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
@ -97,7 +99,7 @@ public class IBLabelProvider extends LabelProvider implements IColorProvider {
} }
} }
if (node.isActiveCode() && node.getRepresentedTranslationUnit() == null) { if (node.isActiveCode() && node.getRepresentedIFL() == null) {
flags |= CElementImageDescriptor.WARNING; flags |= CElementImageDescriptor.WARNING;
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others. * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * 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
@ -17,6 +17,7 @@ import org.eclipse.core.runtime.IPath;
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.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.util.CoreUtility; import org.eclipse.cdt.internal.ui.util.CoreUtility;
@ -30,7 +31,6 @@ public class IBNode implements IAdaptable {
// navigation info // navigation info
private IBFile fDirectiveFile; private IBFile fDirectiveFile;
private String fDirectiveName;
private int fDirectiveCharacterOffset; private int fDirectiveCharacterOffset;
private int fDirectiveLength; private int fDirectiveLength;
private int fHashCode; private int fHashCode;
@ -44,11 +44,11 @@ public class IBNode implements IAdaptable {
* Creates a new node for the include browser * Creates a new node for the include browser
*/ */
public IBNode(IBNode parent, IBFile represents, IBFile fileOfDirective, public IBNode(IBNode parent, IBFile represents, IBFile fileOfDirective,
String nameOfDirective, int charOffset, int length, long timestamp) { int charOffset, int length, long timestamp) {
assert represents != null;
fParent= parent; fParent= parent;
fRepresentedFile= represents; fRepresentedFile= represents;
fDirectiveFile= fileOfDirective; fDirectiveFile= fileOfDirective;
fDirectiveName= nameOfDirective;
fDirectiveCharacterOffset= charOffset; fDirectiveCharacterOffset= charOffset;
fDirectiveLength= length; fDirectiveLength= length;
fIsRecursive= computeIsRecursive(fParent, represents.getLocation()); fIsRecursive= computeIsRecursive(fParent, represents.getLocation());
@ -61,15 +61,7 @@ public class IBNode implements IAdaptable {
if (fParent != null) { if (fParent != null) {
hashCode= fParent.hashCode() * 31; hashCode= fParent.hashCode() * 31;
} }
if (fDirectiveName != null) { hashCode+= fRepresentedFile.hashCode();
hashCode+= fDirectiveName.hashCode();
}
else if (fRepresentedFile != null) {
IIndexFileLocation ifl= fRepresentedFile.getLocation();
if (ifl != null) {
hashCode+= ifl.hashCode();
}
}
return hashCode; return hashCode;
} }
@ -87,8 +79,7 @@ public class IBNode implements IAdaptable {
return false; return false;
} }
return (CoreUtility.safeEquals(fRepresentedFile, rhs.fRepresentedFile) && return CoreUtility.safeEquals(fRepresentedFile, rhs.fRepresentedFile);
CoreUtility.safeEquals(fDirectiveName, rhs.fDirectiveName));
} }
private boolean computeIsRecursive(IBNode parent, IIndexFileLocation ifl) { private boolean computeIsRecursive(IBNode parent, IIndexFileLocation ifl) {
@ -162,7 +153,7 @@ public class IBNode implements IAdaptable {
} }
public String getDirectiveName() { public String getDirectiveName() {
return fDirectiveName; return fRepresentedFile.getName();
} }
public Object getAdapter(Class adapter) { public Object getAdapter(Class adapter) {
@ -194,8 +185,24 @@ public class IBNode implements IAdaptable {
} }
return null; return null;
} }
public IIndexFileLocation getRepresentedIFL() {
return fRepresentedFile == null ? null : fRepresentedFile.getLocation();
}
public long getTimestamp() { public long getTimestamp() {
return fTimestamp; return fTimestamp;
} }
public ICProject getCProject() {
ITranslationUnit tu= getRepresentedTranslationUnit();
if (tu != null) {
return tu.getCProject();
}
IBNode parent= getParent();
if (parent != null) {
return parent.getCProject();
}
return null;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others. * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * 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
@ -30,6 +30,9 @@ public class WorkingSetFilter {
if (fResourceFilter == null) { if (fResourceFilter == null) {
return true; return true;
} }
if (elem == null) {
return false;
}
IPath path= elem.getPath(); IPath path= elem.getPath();
if (path == null) { if (path == null) {
return false; return false;