1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 09:55:29 +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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -56,6 +56,13 @@ public interface IIndexInclude {
* @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

View file

@ -234,7 +234,9 @@ public class CIndex implements IIndex {
IIndexInclude[] includes= file.getIncludes();
for (int k= 0; k < includes.length; 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);
if (depth != 0) {
IIndexFile includedByFile= resolveInclude(include);

View file

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

View file

@ -65,7 +65,9 @@ public class WritableCIndex extends CIndex implements IWritableIndex {
IIndexFragmentFile[] destFiles= new IIndexFragmentFile[includes.length];
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,
includes, destFiles, macros, names);

View file

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

View file

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

View file

@ -190,43 +190,57 @@ abstract public class PDOMWriter {
}
private IIndexFileLocation[] extractSymbols(IASTTranslationUnit ast, final Map symbolMap) throws CoreException {
LinkedHashSet/*<IIndexFileLocation>*/ orderedIncludes= new LinkedHashSet/*<IIndexFileLocation>*/();
ArrayList/*<IIndexFileLocation>*/ stack= new ArrayList/*<IIndexFileLocation>*/();
LinkedHashSet/*<IIndexFileLocation>*/ orderedIFLs= new LinkedHashSet/*<IIndexFileLocation>*/();
ArrayList/*<IIndexFileLocation>*/ iflStack= new ArrayList/*<IIndexFileLocation>*/();
final IIndexFileLocation astLocation = findLocation(ast.getFilePath());
IIndexFileLocation currentPath = astLocation;
IIndexFileLocation aboveStackIFL = astLocation;
IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives();
for (int i= 0; i < includes.length; i++) {
IASTPreprocessorIncludeStatement include = includes[i];
IASTFileLocation sourceLoc = include.getFileLocation();
IIndexFileLocation newPath= sourceLoc != null ? findLocation(sourceLoc.getFileName()) : astLocation; // command-line includes
while (!stack.isEmpty() && !currentPath.equals(newPath)) {
if (needToUpdate(currentPath)) {
prepareInMap(symbolMap, currentPath);
orderedIncludes.add(currentPath);
final IASTPreprocessorIncludeStatement include = includes[i];
// check if we have left a file.
final IASTFileLocation tmpLoc = include.getFileLocation();
final IIndexFileLocation nextIFL= tmpLoc != null ? findLocation(tmpLoc.getFileName()) : astLocation; // command-line includes
while (!aboveStackIFL.equals(nextIFL)) {
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);
addToMap(symbolMap, 0, newPath, include);
// save include in map
if (needToUpdate(nextIFL)) {
prepareInMap(symbolMap, nextIFL);
addToMap(symbolMap, 0, nextIFL, include);
}
// prepare to go into next level
if (include.isResolved()) {
stack.add(currentPath);
currentPath= findLocation(include.getPath());
iflStack.add(nextIFL);
aboveStackIFL= findLocation(include.getPath());
}
else if (include.isActive()) {
reportProblem(include);
}
}
stack.add(currentPath);
while (!stack.isEmpty()) {
currentPath= (IIndexFileLocation) stack.remove(stack.size()-1);
if (needToUpdate(currentPath)) {
prepareInMap(symbolMap, currentPath);
orderedIncludes.add(currentPath);
iflStack.add(aboveStackIFL);
while (!iflStack.isEmpty()) {
aboveStackIFL= (IIndexFileLocation) iflStack.remove(iflStack.size()-1);
if (needToUpdate(aboveStackIFL)) {
prepareInMap(symbolMap, aboveStackIFL);
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) {
@ -345,7 +359,9 @@ abstract public class PDOMWriter {
IIndexFileLocation[] includeLocations = new IIndexFileLocation[includes.length];
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);
}

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
* @throws CoreException
*/
public List/*<PDOMFile>*/ rewriteLocations(final IIndexLocationConverter newConverter) throws CoreException {
public void rewriteLocations(final IIndexLocationConverter newConverter) throws CoreException {
final List pdomfiles = new ArrayList();
getFileIndex().accept(new IBTreeVisitor(){
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() {

View file

@ -266,14 +266,13 @@ public class PDOMFile implements IIndexFragmentFile {
PDOMInclude lastInclude= null;
for (int i = 0; i < includes.length; i++) {
IASTPreprocessorIncludeStatement statement = includes[i];
PDOMFile thisIncludes= (PDOMFile) files[i];
assert thisIncludes.getIndexFragment() instanceof IWritableIndexFragment;
PDOMInclude pdomInclude = new PDOMInclude(pdom, statement);
pdomInclude.setIncludedBy(this);
pdomInclude.setIncludes(thisIncludes);
thisIncludes.addIncludedBy(pdomInclude);
PDOMFile targetFile= (PDOMFile) files[i];
PDOMInclude pdomInclude = new PDOMInclude(pdom, statement, this, targetFile);
if (targetFile != null) {
assert targetFile.getIndexFragment() instanceof IWritableIndexFragment;
targetFile.addIncludedBy(pdomInclude);
}
if (lastInclude == null) {
setFirstInclude(pdomInclude);
}
@ -391,4 +390,17 @@ public class PDOMFile implements IIndexFragmentFile {
public boolean hasNames() throws CoreException {
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
* are made available under the terms of the Eclipse Public License v1.0
* 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.IIndexFragmentInclude;
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;
/**
@ -32,7 +34,7 @@ public class PDOMInclude implements IIndexFragmentInclude {
private final PDOM pdom;
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 INCLUDES_NEXT = 8;
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 final int RECORD_SIZE = 27;
// cached fields
private String fName= null;
public PDOMInclude(PDOM pdom, int record) {
this.pdom = pdom;
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.record = pdom.getDB().malloc(RECORD_SIZE);
IASTName name= include.getName();
@ -61,10 +66,13 @@ public class PDOMInclude implements IIndexFragmentInclude {
if (loc != null) {
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;
if (include.isSystemInclude()) {
flags |= FLAG_SYSTEM_INCLUDE;
@ -72,7 +80,7 @@ public class PDOMInclude implements IIndexFragmentInclude {
if (!include.isActive()) {
flags |= FLAG_INACTIVE_INCLUDE;
}
if (!include.isResolved()) {
if (unresolved) {
flags |= FLAG_UNRESOLVED_INCLUDE;
}
return flags;
@ -83,29 +91,55 @@ public class PDOMInclude implements IIndexFragmentInclude {
}
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 nextInclude = getNextInIncludedBy();
if (prevInclude != null)
prevInclude.setNextInIncludedBy(nextInclude);
else
((PDOMFile) getIncludes()).setFirstIncludedBy(nextInclude);
if (nextInclude != null)
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 {
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;
}
public void setIncludes(PDOMFile includes) throws CoreException {
int rec = includes != null ? includes.getRecord() : 0;
pdom.getDB().putInt(record + INCLUDES, rec);
private void setIncludes(PDOMFile includes, char[] name) throws CoreException {
int rec= 0;
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 {
@ -113,7 +147,7 @@ public class PDOMInclude implements IIndexFragmentInclude {
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;
pdom.getDB().putInt(record + INCLUDED_BY, rec);
}
@ -153,6 +187,9 @@ public class PDOMInclude implements IIndexFragmentInclude {
}
public IIndexFileLocation getIncludesLocation() throws CoreException {
if (!isResolved()) {
return null;
}
return getIncludes().getLocation();
}
@ -191,5 +228,29 @@ public class PDOMInclude implements IIndexFragmentInclude {
public int getNameLength() throws CoreException {
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()) {
case ICElement.C_UNIT:
ITranslationUnit tu = (ITranslationUnit)element;
switch (delta.getKind()) {
case ICElementDelta.CHANGED:
if ((flags & ICElementDelta.F_CONTENT) != 0 &&
(fAllFiles || !CoreModel.isScannerInformationEmpty(tu.getResource())) || tu.isHeaderUnit()) {
changed.add(tu);
}
break;
case ICElementDelta.ADDED:
if (!tu.isWorkingCopy() &&
(fAllFiles || !CoreModel.isScannerInformationEmpty(tu.getResource())) || tu.isHeaderUnit()) {
added.add(tu);
}
break;
case ICElementDelta.REMOVED:
if (!tu.isWorkingCopy())
if (!tu.isWorkingCopy()) {
switch (delta.getKind()) {
case ICElementDelta.CHANGED:
if ((flags & ICElementDelta.F_CONTENT) != 0) {
if (fAllFiles || !CoreModel.isScannerInformationEmpty(tu.getResource()) || tu.isHeaderUnit()) {
changed.add(tu);
}
}
break;
case ICElementDelta.ADDED:
if (fAllFiles || !CoreModel.isScannerInformationEmpty(tu.getResource()) || tu.isHeaderUnit()) {
added.add(tu);
}
break;
case ICElementDelta.REMOVED:
removed.add(tu);
break;
break;
}
}
break;
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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -14,7 +14,6 @@ package org.eclipse.cdt.internal.ui.includebrowser;
import java.util.ArrayList;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.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.IIndexInclude;
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.ui.CUIPlugin;
@ -57,11 +56,11 @@ public class IBContentProvider extends AsyncTreeContentProvider {
protected Object[] syncronouslyComputeChildren(Object parentElement) {
if (parentElement instanceof ITranslationUnit) {
ITranslationUnit tu = (ITranslationUnit) parentElement;
return new Object[] { new IBNode(null, new IBFile(tu), null, null, 0, 0, 0) };
return new Object[] { new IBNode(null, new IBFile(tu), null, 0, 0, 0) };
}
if (parentElement instanceof IBNode) {
IBNode node = (IBNode) parentElement;
if (node.isRecursive() || node.getRepresentedTranslationUnit() == null) {
if (node.isRecursive() || node.getRepresentedIFL() == null) {
return NO_CHILDREN;
}
}
@ -72,14 +71,15 @@ public class IBContentProvider extends AsyncTreeContentProvider {
protected Object[] asyncronouslyComputeChildren(Object parentElement, IProgressMonitor monitor) {
if (parentElement instanceof IBNode) {
IBNode node = (IBNode) parentElement;
ITranslationUnit tu= node.getRepresentedTranslationUnit();
if (tu == null) {
IIndexFileLocation ifl= node.getRepresentedIFL();
ICProject project= node.getCProject();
if (ifl == null) {
return NO_CHILDREN;
}
IIndex index;
try {
index = CCorePlugin.getIndexManager().getIndex(tu.getCProject(),
index = CCorePlugin.getIndexManager().getIndex(project,
fComputeIncludedBy ? IIndexManager.ADD_DEPENDENT : IIndexManager.ADD_DEPENDENCIES);
index.acquireReadLock();
} catch (CoreException e) {
@ -94,10 +94,10 @@ public class IBContentProvider extends AsyncTreeContentProvider {
IBFile targetFile= null;
IIndexInclude[] includes;
if (fComputeIncludedBy) {
includes= findIncludedBy(index, tu, NPM);
includes= findIncludedBy(index, ifl, NPM);
}
else {
includes= findIncludesTo(index, tu, NPM);
includes= findIncludesTo(index, ifl, NPM);
directiveFile= node.getRepresentedFile();
}
if (includes.length > 0) {
@ -105,21 +105,20 @@ public class IBContentProvider extends AsyncTreeContentProvider {
for (int i = 0; i < includes.length; i++) {
IIndexInclude include = includes[i];
try {
IIndexFileLocation includesPath= include.getIncludesLocation();
if (fComputeIncludedBy) {
directiveFile= targetFile= new IBFile(tu.getCProject(), include.getIncludedByLocation());
directiveFile= targetFile= new IBFile(project, include.getIncludedByLocation());
}
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,
name, include.getNameOffset(),
include.getNameOffset(),
include.getNameLength(),
include.getIncludedBy().getTimestamp());
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 {
IIndexFileLocation location= IndexLocationFactory.getIFL(tu);
if (location != null) {
IIndexFile file= index.getFile(location);
if (ifl != null) {
IIndexFile file= index.getFile(ifl);
if (file != null) {
return index.findIncludedBy(file);
}
@ -168,11 +166,10 @@ public class IBContentProvider extends AsyncTreeContentProvider {
return new IIndexInclude[0];
}
public IIndexInclude[] findIncludesTo(IIndex index, ITranslationUnit tu, IProgressMonitor pm) {
public IIndexInclude[] findIncludesTo(IIndex index, IIndexFileLocation ifl, IProgressMonitor pm) {
try {
IIndexFileLocation location= IndexLocationFactory.getIFL(tu);
if (location != null) {
IIndexFile file= index.getFile(location);
if (ifl != null) {
IIndexFile file= index.getFile(ifl);
if (file != null) {
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
* are made available under the terms of the Eclipse Public License v1.0
* 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;
public class IBFile {
public IIndexFileLocation fLocation;
public ITranslationUnit fTU= null;
final public ITranslationUnit fTU;
final public IIndexFileLocation fLocation;
final public String fName;
public IBFile(ITranslationUnit tu) {
fTU= tu;
fLocation= IndexLocationFactory.getIFL(tu);
fName= tu.getElementName();
}
public IBFile(ICProject preferredProject, IIndexFileLocation location) throws CModelException {
fLocation= location;
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() {
return fLocation;
}
@ -53,7 +63,9 @@ public class IBFile {
}
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() {
@ -72,4 +84,8 @@ public class IBFile {
}
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
* are made available under the terms of the Eclipse Public License v1.0
* 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.LabelProvider;
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.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;
}

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
* are made available under the terms of the Eclipse Public License v1.0
* 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.IndexLocationFactory;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.util.CoreUtility;
@ -30,7 +31,6 @@ public class IBNode implements IAdaptable {
// navigation info
private IBFile fDirectiveFile;
private String fDirectiveName;
private int fDirectiveCharacterOffset;
private int fDirectiveLength;
private int fHashCode;
@ -44,11 +44,11 @@ public class IBNode implements IAdaptable {
* Creates a new node for the include browser
*/
public IBNode(IBNode parent, IBFile represents, IBFile fileOfDirective,
String nameOfDirective, int charOffset, int length, long timestamp) {
int charOffset, int length, long timestamp) {
assert represents != null;
fParent= parent;
fRepresentedFile= represents;
fDirectiveFile= fileOfDirective;
fDirectiveName= nameOfDirective;
fDirectiveCharacterOffset= charOffset;
fDirectiveLength= length;
fIsRecursive= computeIsRecursive(fParent, represents.getLocation());
@ -61,15 +61,7 @@ public class IBNode implements IAdaptable {
if (fParent != null) {
hashCode= fParent.hashCode() * 31;
}
if (fDirectiveName != null) {
hashCode+= fDirectiveName.hashCode();
}
else if (fRepresentedFile != null) {
IIndexFileLocation ifl= fRepresentedFile.getLocation();
if (ifl != null) {
hashCode+= ifl.hashCode();
}
}
hashCode+= fRepresentedFile.hashCode();
return hashCode;
}
@ -87,8 +79,7 @@ public class IBNode implements IAdaptable {
return false;
}
return (CoreUtility.safeEquals(fRepresentedFile, rhs.fRepresentedFile) &&
CoreUtility.safeEquals(fDirectiveName, rhs.fDirectiveName));
return CoreUtility.safeEquals(fRepresentedFile, rhs.fRepresentedFile);
}
private boolean computeIsRecursive(IBNode parent, IIndexFileLocation ifl) {
@ -162,7 +153,7 @@ public class IBNode implements IAdaptable {
}
public String getDirectiveName() {
return fDirectiveName;
return fRepresentedFile.getName();
}
public Object getAdapter(Class adapter) {
@ -194,8 +185,24 @@ public class IBNode implements IAdaptable {
}
return null;
}
public IIndexFileLocation getRepresentedIFL() {
return fRepresentedFile == null ? null : fRepresentedFile.getLocation();
}
public long getTimestamp() {
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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -30,6 +30,9 @@ public class WorkingSetFilter {
if (fResourceFilter == null) {
return true;
}
if (elem == null) {
return false;
}
IPath path= elem.getPath();
if (path == null) {
return false;