1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26:01 +02:00

Fix and NPE in the IncludeEntry

This commit is contained in:
Alain Magloire 2004-04-28 21:11:26 +00:00
parent 9cc4fa6e5a
commit be49f6a48f
7 changed files with 52 additions and 11 deletions

View file

@ -1,3 +1,7 @@
2004-04-28 Alain Magloire
NPE in the PathEntry.
2004-04-28 Alain Magloire
Work in Progress for the PathEntry API

View file

@ -70,4 +70,11 @@ public interface ILibraryEntry extends IPathEntry {
*/
IPath getBaseReference();
/**
* Returns the complete path, equivalent to:
* getBasepath().append(getPath());
* @return
*/
IPath getFullLibraryPath();
}

View file

@ -13,6 +13,8 @@
package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.IIncludeEntry;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
public class IncludeEntry extends APathEntry implements IIncludeEntry {
@ -22,7 +24,7 @@ public class IncludeEntry extends APathEntry implements IIncludeEntry {
public IncludeEntry(IPath resourcePath, IPath basePath, IPath baseRef, IPath includePath, boolean isSystemInclude,
IPath[] exclusionPatterns, boolean isExported) {
super(IIncludeEntry.CDT_INCLUDE, basePath, baseRef, resourcePath, exclusionPatterns, isExported);
this.includePath = includePath;
this.includePath = (includePath == null) ? EMPTY_PATH : includePath;
this.isSystemInclude = isSystemInclude;
}
@ -80,6 +82,18 @@ public class IncludeEntry extends APathEntry implements IIncludeEntry {
* @see org.eclipse.cdt.core.model.IIncludeEntry#getFullIncludePath()
*/
public IPath getFullIncludePath() {
return basePath.append(includePath);
IPath p = (!basePath.isEmpty()) ? basePath.append(includePath) : includePath;
if (p.isAbsolute()) {
return p;
}
IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(p);
if (res != null) {
IPath location = res.getLocation();
if (location != null) {
return location;
}
}
return p;
}
}

View file

@ -16,6 +16,7 @@ import java.util.ArrayList;
import java.util.Map;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.CoreModelUtil;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
@ -40,7 +41,7 @@ public class IncludeReference extends Openable implements IIncludeReference {
* @param type
*/
public IncludeReference(ICProject cproject, IIncludeEntry entry) {
this(cproject, entry, entry.getIncludePath());
this(cproject, entry, entry.getFullIncludePath());
}
public IncludeReference(ICElement celement, IIncludeEntry entry, IPath path) {
@ -94,7 +95,7 @@ public class IncludeReference extends Openable implements IIncludeReference {
if (fPath != null) {
file = fPath.toFile();
} else if (fIncludeEntry != null) {
file = fIncludeEntry.getIncludePath().toFile();
file = fIncludeEntry.getFullIncludePath().toFile();
}
String[] names = null;
if (file != null && file.isDirectory()) {
@ -108,7 +109,7 @@ public class IncludeReference extends Openable implements IIncludeReference {
ICElement celement = null;
if (child.isDirectory()) {
celement = new IncludeReference(this, fIncludeEntry, new Path(child.getAbsolutePath()));
} else if (child.isFile()) {
} else if (CoreModel.isValidTranslationUnitName(names[i]) && child.isFile()) {
celement = new ExternalTranslationUnit(this, path.append(names[i]));
}
if (celement != null) {

View file

@ -13,6 +13,8 @@
package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.ILibraryEntry;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
public class LibraryEntry extends APathEntry implements ILibraryEntry {
@ -119,7 +121,20 @@ public class LibraryEntry extends APathEntry implements ILibraryEntry {
return super.equals(obj);
}
public IPath getFullLibaryPath() {
return basePath.append(getPath());
public IPath getFullLibraryPath() {
IPath lib = getPath();
IPath p = (!basePath.isEmpty()) ? basePath.append(lib) : lib;
if (p.isAbsolute()) {
return p;
}
IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(p);
if (res != null) {
IPath location = res.getLocation();
if (location != null) {
return location;
}
}
return p;
}
}

View file

@ -23,7 +23,7 @@ public class LibraryReferenceArchive extends Archive implements ILibraryReferenc
ILibraryEntry entry;
public LibraryReferenceArchive(ICElement parent, ILibraryEntry e, IBinaryArchive ar) {
super(parent, e.getPath(), ar);
super(parent, e.getFullLibraryPath(), ar);
entry = e;
}
@ -40,7 +40,7 @@ public class LibraryReferenceArchive extends Archive implements ILibraryReferenc
* @see org.eclipse.cdt.core.model.ICElement#getPath()
*/
public IPath getPath() {
return entry.getPath();
return entry.getFullLibraryPath();
}
/* (non-Javadoc)

View file

@ -23,7 +23,7 @@ public class LibraryReferenceShared extends Binary implements ILibraryReference
ILibraryEntry entry;
public LibraryReferenceShared(ICElement parent, ILibraryEntry e, IBinaryObject bin) {
super(parent, e.getPath(), bin);
super(parent, e.getFullLibraryPath(), bin);
entry = e;
}
@ -60,7 +60,7 @@ public class LibraryReferenceShared extends Binary implements ILibraryReference
* @see org.eclipse.cdt.core.model.ICElement#getPath()
*/
public IPath getPath() {
return entry.getPath();
return entry.getFullLibraryPath();
}
/* (non-Javadoc)