1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

Draft work on LibaryReference and IncludeReference

This commit is contained in:
Alain Magloire 2004-04-05 04:29:11 +00:00
parent 8a6680ea21
commit 9561454a65
21 changed files with 462 additions and 101 deletions

View file

@ -1,3 +1,25 @@
2004-04-03 Alain Magloire
Draft work on LibraryReferences and IncludeReferences.
* model/org/eclipse/cdt/core/model/CoreModel.java
* model/org/eclipse/cdt/core/model/ICProject.java
* model/org/eclipse/cdt/core/model/IIncludeEntry.java
* model/org/eclipse/cdt/core/model/IIncludeReference.java
* model/org/eclipse/cdt/core/model/ILibararyentry.java
* model/org/eclipse/cdt/core/model/IPathEntry.java
* model/org/eclipse/cdt/internal/core/model/APathEntry.java
* model/org/eclipse/cdt/internal/core/model/CProject.java
* model/org/eclipse/cdt/internal/core/model/CProjectInfo.java
* model/org/eclipse/cdt/internal/core/model/IncludeEntry.java
* model/org/eclipse/cdt/internal/core/model/IncludeReference.java
* model/org/eclipse/cdt/internal/core/model/LibraryEntry.java
* model/org/eclipse/cdt/internal/core/model/LibraryReferenceArchive.java
* model/org/eclipse/cdt/internal/core/model/LibraryReferenceShared.java
* model/org/eclipse/cdt/internal/core/model/MacroEntry.java
* model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
2004-04-03 Alain Magloire
Fix for PR 57287

View file

@ -267,7 +267,7 @@ public class CoreModel {
* <p>
*
* @param path
* the absolute path of the binary archive
* the absolute path of the library
* @param sourceAttachmentPath
* the absolute path of the corresponding source archive or
* folder, or <code>null</code> if none.
@ -279,9 +279,9 @@ public class CoreModel {
* @return a new library entry
*
*/
public static ILibraryEntry newLibraryEntry(IPath path, IPath sourceAttachmentPath, IPath sourceAttachmentRootPath,
public static ILibraryEntry newLibraryEntry(IPath libraryPath, IPath sourceAttachmentPath, IPath sourceAttachmentRootPath,
IPath sourceAttachmentPrefixMapping) {
return newLibraryEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, sourceAttachmentPrefixMapping, false);
return newLibraryEntry(libraryPath, null, sourceAttachmentPath, sourceAttachmentRootPath, sourceAttachmentPrefixMapping, false);
}
/**
@ -293,7 +293,9 @@ public class CoreModel {
* <p>
*
* @param path
* the absolute path of the binary archive
* the path of the library
* @param path
* the base path of the library
* @param sourceAttachmentPath
* the absolute path of the corresponding source archive or
* folder, or <code>null</code> if none.
@ -305,9 +307,9 @@ public class CoreModel {
* @return a new library entry
*
*/
public static ILibraryEntry newLibraryEntry(IPath path, IPath sourceAttachmentPath, IPath sourceAttachmentRootPath,
public static ILibraryEntry newLibraryEntry(IPath libraryPath, IPath basePath, IPath sourceAttachmentPath, IPath sourceAttachmentRootPath,
IPath sourceAttachmentPrefixMapping, boolean isExported) {
return new LibraryEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, sourceAttachmentPrefixMapping, isExported);
return new LibraryEntry(libraryPath, basePath, sourceAttachmentPath, sourceAttachmentRootPath, sourceAttachmentPrefixMapping, isExported);
}
/**
@ -391,6 +393,17 @@ public class CoreModel {
return new SourceEntry(path, exclusionPatterns);
}
/**
* Creates and returns a new entry of kind <code>CDT_INCLUDE</code>
*
* @param includePath
* the absolute path of the include
* @return IIncludeEntry
*/
public static IIncludeEntry newIncludeEntry(IPath includePath) {
return newIncludeEntry(null, includePath, false);
}
/**
* Creates and returns a new entry of kind <code>CDT_INCLUDE</code>
*
@ -404,17 +417,6 @@ public class CoreModel {
return newIncludeEntry(resourcePath, includePath, false);
}
/**
* Creates and returns a new entry of kind <code>CDT_INCLUDE</code>
*
* @param includePath
* the absolute path of the include
* @return IIncludeEntry
*/
public static IIncludeEntry newIncludeEntry(IPath includePath) {
return newIncludeEntry(null, includePath, false);
}
/**
* * Creates and returns a new entry of kind <code>CDT_INCLUDE</code>
*
@ -428,7 +430,7 @@ public class CoreModel {
* @return IIncludeEntry
*/
public static IIncludeEntry newIncludeEntry(IPath resourcePath, IPath includePath, boolean isSystemInclude) {
return newIncludeEntry(resourcePath, includePath, isSystemInclude, IncludeEntry.NO_EXCLUSION_PATTERNS);
return newIncludeEntry(resourcePath, includePath, null, isSystemInclude, IncludeEntry.NO_EXCLUSION_PATTERNS);
}
/**
@ -448,9 +450,32 @@ public class CoreModel {
* exclusion patterns in the resource if a container
* @return IIincludeEntry
*/
public static IIncludeEntry newIncludeEntry(IPath resourcePath, IPath includePath, boolean isSystemInclude,
public static IIncludeEntry newIncludeEntry(IPath resourcePath, IPath includePath, boolean isSystemInclude, IPath[] exclusionPathterns) {
return newIncludeEntry(resourcePath, includePath, null, isSystemInclude, exclusionPathterns);
}
/**
* Creates and returns a new entry of kind <code>CDT_INCLUDE</code>
*
* @param path
* the affected project-relative resource path
* @param includePath
* the path of the include
* @param basePath
* the base path of the include
* @param isSystemInclude
* wheter this include path should be consider the system
* include path
* @param isRecursive
* if the resource is a folder the include applied to all
* recursively
* @param exclusionPatterns
* exclusion patterns in the resource if a container
* @return IIincludeEntry
*/
public static IIncludeEntry newIncludeEntry(IPath resourcePath, IPath includePath, IPath basePath, boolean isSystemInclude,
IPath[] exclusionPatterns) {
return new IncludeEntry(resourcePath, includePath, isSystemInclude, exclusionPatterns);
return new IncludeEntry(resourcePath, includePath, basePath, isSystemInclude, exclusionPatterns);
}
/**
@ -465,7 +490,7 @@ public class CoreModel {
* @return
*/
public static IMacroEntry newMacroEntry(String macroName, String macroValue) {
return newMacroEntry(null, macroName, macroValue, MacroEntry.NO_EXCLUSION_PATTERNS);
return newMacroEntry(null, macroName, macroValue);
}
/**
@ -479,8 +504,23 @@ public class CoreModel {
* the value of the macro
* @return
*/
public static IMacroEntry newMacroEntry(IPath path, String macroName, String macroValue) {
return newMacroEntry(path, macroName, macroValue, MacroEntry.NO_EXCLUSION_PATTERNS);
public static IMacroEntry newMacroEntry(IPath basePath, String macroName) {
return newMacroEntry(null, basePath, macroName, null, MacroEntry.NO_EXCLUSION_PATTERNS);
}
/**
* Creates and returns an entry kind <code>CDT_MACRO</code>
*
* @param path
* the affected workspace-relative resource path
* @param macroName
* the name of the macro
* @param macroValue
* the value of the macro
* @return
*/
public static IMacroEntry newMacroEntry(IPath resourcePath, String macroName, String macroValue) {
return newMacroEntry(resourcePath, macroName, macroValue, MacroEntry.NO_EXCLUSION_PATTERNS);
}
/**
@ -496,10 +536,26 @@ public class CoreModel {
* exclusion patterns in the resource if a container
* @return
*/
public static IMacroEntry newMacroEntry(IPath path, String macroName, String macroValue, IPath[] exclusionPatterns) {
return new MacroEntry(path, macroName, macroValue, exclusionPatterns);
public static IMacroEntry newMacroEntry(IPath resourcePath, String macroName, String macroValue, IPath[] exclusionPatterns) {
return newMacroEntry(resourcePath, null, macroName, macroValue, exclusionPatterns);
}
/**
* Creates and returns an entry kind <code>CDT_MACRO</code>
*
* @param path
* the affected workspace-relative resource path
* @param macroName
* the name of the macro
* @param macroValue
* the value of the macro
* @param exclusionPatterns
* exclusion patterns in the resource if a container
* @return
*/
public static IMacroEntry newMacroEntry(IPath resourcePath, IPath basePath, String macroName, String macroValue, IPath[] exclusionPatterns) {
return new MacroEntry(resourcePath, basePath, macroName, macroValue, exclusionPatterns);
}
/**
* Answers the project specific value for a given container. In case this
* container path could not be resolved, then will answer <code>null</code>.

View file

@ -94,6 +94,14 @@ public interface ICProject extends IParent, IOpenable, ICElement {
*/
ILibraryReference[] getLibraryReferences() throws CModelException;
/**
* Return the include paths set on the project.
*
* @return
* @throws CModelException
*/
IIncludeReference[] getIncludeReferences() throws CModelException;
/**
* Returns the names of the projects that are directly required by this
* project. A project is required if it is in its cpath entries.

View file

@ -22,6 +22,12 @@ public interface IIncludeEntry extends IPathEntry {
*/
IPath getIncludePath();
/**
* Return the base path of the includePath
* @return IPath
*/
IPath getBasePath();
/**
* Whether or not it a system include path
* @return boolean

View file

@ -0,0 +1,33 @@
/**********************************************************************
* Copyright (c) 2002,2003,2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.core.model;
import org.eclipse.core.runtime.IPath;
/**
* IIncludeReference
*/
public interface IIncludeReference extends IParent, ICElement {
/**
* Returns the pathEntry
*
* @return
*/
IIncludeEntry getIncludeEntry();
/**
* Return the affected path
* @return
*/
IPath getAffectedPath();
}

View file

@ -57,4 +57,10 @@ public interface ILibraryEntry extends IPathEntry {
*/
IPath getSourceAttachmentPrefixMapping();
/**
* Return the base path of the library.
* @return IPath
*/
IPath getBasePath();
}

View file

@ -35,4 +35,10 @@ public interface IMacroEntry extends IPathEntry {
*/
IPath[] getExclusionPatterns();
/**
* Return the base path.
* @return
*/
IPath getBasePath();
}

View file

@ -62,12 +62,6 @@ public interface IPathEntry {
*/
int CDT_OUTPUT = 7;
/**
* Entry kind constant describing an entry defined using
* a path that begins with a variable reference.
*/
int CDT_VARIABLE = 10;
/**
* Returns the kind of this path entry.
*

View file

@ -18,11 +18,13 @@ public abstract class APathEntry extends PathEntry {
public static IPath[] NO_EXCLUSION_PATTERNS = {};
IPath[] exclusionPatterns;
IPath basePath;
private final static char[][] UNINIT_PATTERNS = new char[][] { "Non-initialized yet".toCharArray() }; //$NON-NLS-1$
char[][]fullCharExclusionPatterns = UNINIT_PATTERNS;
public APathEntry (int kind, IPath path, IPath[] exclusionPatterns, boolean isExported) {
public APathEntry (int kind, IPath path, IPath basePath, IPath[] exclusionPatterns, boolean isExported) {
super(kind, path, isExported);
this.basePath = basePath;
this.exclusionPatterns = exclusionPatterns;
}
@ -34,7 +36,15 @@ public abstract class APathEntry extends PathEntry {
return exclusionPatterns;
}
/*
/**
* Returns the base Path
* @return IPath
*/
public IPath getBasePath() {
return basePath;
}
/**
* Returns a char based representation of the exclusions patterns full path.
*/
public char[][] fullExclusionPatternChars() {
@ -71,6 +81,12 @@ public abstract class APathEntry extends PathEntry {
}
}
}
IPath otherBasePath = otherEntry.getBasePath();
if (basePath != null) {
if (otherBasePath != null && !basePath.equals(otherBasePath)) {
return false;
}
}
return true;
}
return super.equals(obj);

View file

@ -27,6 +27,8 @@ import org.eclipse.cdt.core.model.IBinaryContainer;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModelStatusConstants;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IIncludeEntry;
import org.eclipse.cdt.core.model.IIncludeReference;
import org.eclipse.cdt.core.model.ILibraryEntry;
import org.eclipse.cdt.core.model.ILibraryReference;
import org.eclipse.cdt.core.model.IOutputEntry;
@ -131,14 +133,29 @@ public class CProject extends Openable implements ICProject {
return getProject().hashCode();
}
public IIncludeReference[] getIncludeReferences() throws CModelException {
IPathEntry[] entries = getResolvedPathEntries();
ArrayList list = new ArrayList(entries.length);
for (int i = 0; i < entries.length; i++) {
if (entries[i].getEntryKind() == IPathEntry.CDT_INCLUDE) {
IIncludeEntry entry = (IIncludeEntry) entries[i];
IIncludeReference inc = new IncludeReference(this, entry);
if (inc != null) {
list.add(inc);
}
}
}
return (IIncludeReference[]) list.toArray(new IIncludeReference[0]);
}
public ILibraryReference[] getLibraryReferences() throws CModelException {
ArrayList list = new ArrayList(5);
IBinaryParser[] binParsers = null;
try {
binParsers = CCorePlugin.getDefault().getBinaryParser(getProject());
} catch (CoreException e) {
}
IPathEntry[] entries = getResolvedPathEntries();
ArrayList list = new ArrayList(entries.length);
for (int i = 0; i < entries.length; i++) {
if (entries[i].getEntryKind() == IPathEntry.CDT_LIBRARY) {
ILibraryEntry entry = (ILibraryEntry) entries[i];

View file

@ -11,6 +11,7 @@ import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IArchiveContainer;
import org.eclipse.cdt.core.model.IBinaryContainer;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IIncludeReference;
import org.eclipse.cdt.core.model.ILibraryReference;
import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.core.resources.IContainer;
@ -27,6 +28,8 @@ class CProjectInfo extends OpenableInfo {
BinaryContainer vBin;
ArchiveContainer vLib;
ILibraryReference[] libReferences;
IIncludeReference[] incReferences;
Object[] nonCResources = null;
/**
@ -130,6 +133,16 @@ class CProjectInfo extends OpenableInfo {
try {
((CElement)libReferences[i]).close();
} catch (CModelException e) {
//
}
}
}
if (incReferences != null) {
for (int i = 0; i < incReferences.length; i++) {
try {
((CElement)incReferences[i]).close();
} catch (CModelException e) {
//
}
}
}

View file

@ -19,8 +19,8 @@ public class IncludeEntry extends APathEntry implements IIncludeEntry {
IPath includePath;
boolean isSystemInclude;
public IncludeEntry(IPath path, IPath includePath, boolean isSystemInclude, IPath[] exclusionPatterns) {
super(IIncludeEntry.CDT_INCLUDE, path, exclusionPatterns, path == null);
public IncludeEntry(IPath resourcePath, IPath includePath, IPath basePath, boolean isSystemInclude, IPath[] exclusionPatterns) {
super(IIncludeEntry.CDT_INCLUDE, resourcePath, basePath, exclusionPatterns, resourcePath == null);
this.includePath = includePath;
this.isSystemInclude = isSystemInclude;
}

View file

@ -0,0 +1,76 @@
/**********************************************************************
* Copyright (c) 2002,2003,2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.core.model;
import java.util.Map;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IIncludeEntry;
import org.eclipse.cdt.core.model.IIncludeReference;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
/**
* IncludeReference
*/
public class IncludeReference extends Openable implements IIncludeReference {
IIncludeEntry fIncludeEntry;
/**
* @param parent
* @param name
* @param type
*/
public IncludeReference(ICProject cproject, IIncludeEntry entry) {
super(cproject, null, entry.getIncludePath().toString(), ICElement.C_VCONTAINER);
fIncludeEntry = entry;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ICElement#getResource()
*/
public IResource getResource() {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.model.CElement#createElementInfo()
*/
protected CElementInfo createElementInfo() {
return new OpenableInfo(this);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.IIncludeReference#getIncludeEntry()
*/
public IIncludeEntry getIncludeEntry() {
return fIncludeEntry;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.model.Openable#generateInfos(org.eclipse.cdt.internal.core.model.OpenableInfo, org.eclipse.core.runtime.IProgressMonitor, java.util.Map, org.eclipse.core.resources.IResource)
*/
protected boolean generateInfos(OpenableInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws CModelException {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.IIncludeReference#getAffectedPath()
*/
public IPath getAffectedPath() {
return fIncludeEntry.getPath();
}
}

View file

@ -15,16 +15,16 @@ package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.ILibraryEntry;
import org.eclipse.core.runtime.IPath;
public class LibraryEntry extends PathEntry implements ILibraryEntry {
public class LibraryEntry extends APathEntry implements ILibraryEntry {
IPath libraryPath;
IPath sourceAttachmentPath;
IPath sourceAttachmentRootPath;
IPath sourceAttachmentPrefixMapping;
public LibraryEntry(IPath path, IPath sourceAttachmentPath,
public LibraryEntry(IPath libraryPath, IPath basePath, IPath sourceAttachmentPath,
IPath sourceAttachmentRootPath, IPath sourceAttachmentPrefixMapping, boolean isExported) {
super(ILibraryEntry.CDT_LIBRARY, path, isExported);
super(ILibraryEntry.CDT_LIBRARY, libraryPath, basePath, APathEntry.NO_EXCLUSION_PATTERNS, isExported);
this.sourceAttachmentPath = sourceAttachmentPath;
this.sourceAttachmentRootPath = sourceAttachmentRootPath;
this.sourceAttachmentPrefixMapping = sourceAttachmentPrefixMapping;

View file

@ -22,7 +22,6 @@ public class LibraryReferenceArchive extends Archive implements ILibraryReferenc
public LibraryReferenceArchive(ICElement parent, ILibraryEntry e, IBinaryArchive ar) {
super(parent, e.getPath(), ar);
setElementType(ICElement.C_VCONTAINER);
entry = e;
}

View file

@ -22,7 +22,6 @@ public class LibraryReferenceShared extends Binary implements ILibraryReference
public LibraryReferenceShared(ICElement parent, ILibraryEntry e, IBinaryObject bin) {
super(parent, e.getPath(), bin);
setElementType(ICElement.C_VCONTAINER);
entry = e;
}

View file

@ -20,8 +20,8 @@ public class MacroEntry extends APathEntry implements IMacroEntry {
String macroName;
String macroValue;
public MacroEntry (IPath path, String macroName, String macroValue, IPath[] exclusionPatterns) {
super(IMacroEntry.CDT_MACRO, path, exclusionPatterns, path == null);
public MacroEntry (IPath path, IPath basePath, String macroName, String macroValue, IPath[] exclusionPatterns) {
super(IMacroEntry.CDT_MACRO, path, basePath, exclusionPatterns, path == null);
this.macroName = macroName;
this.macroValue = macroValue;
}

View file

@ -25,7 +25,7 @@ public class OutputEntry extends APathEntry implements IOutputEntry {
* @param isExported
*/
public OutputEntry(IPath path, IPath[] exclusionPatterns, boolean isExported) {
super(CDT_OUTPUT, path, exclusionPatterns, isExported);
super(CDT_OUTPUT, path, null, exclusionPatterns, isExported);
}
public boolean equals(Object obj) {

View file

@ -98,8 +98,6 @@ public class PathEntry implements IPathEntry {
return "src"; //$NON-NLS-1$
case IPathEntry.CDT_LIBRARY :
return "lib"; //$NON-NLS-1$
//case IPathEntry.CDT_VARIABLE :
// return "var"; //$NON-NLS-1$
case IPathEntry.CDT_INCLUDE :
return "inc"; //$NON-NLS-1$
case IPathEntry.CDT_MACRO :

View file

@ -65,6 +65,7 @@ public class PathEntryManager implements ICDescriptorListener {
static String PATH_ENTRY_ID = "org.eclipse.cdt.core.pathentry"; //$NON-NLS-1$
static String ATTRIBUTE_KIND = "kind"; //$NON-NLS-1$
static String ATTRIBUTE_PATH = "path"; //$NON-NLS-1$
static String ATTRIBUTE_BASE_PATH = "base"; //$NON-NLS-1$
static String ATTRIBUTE_EXPORTED = "exported"; //$NON-NLS-1$
static String ATTRIBUTE_SOURCEPATH = "sourcepath"; //$NON-NLS-1$
static String ATTRIBUTE_ROOTPATH = "roopath"; //$NON-NLS-1$
@ -107,6 +108,84 @@ public class PathEntryManager implements ICDescriptorListener {
return pathEntryManager;
}
public IOutputEntry[] getOutputEntries(ICProject cproject) throws CModelException {
IPathEntry[] entries = getResolvedPathEntries(cproject);
ArrayList list = new ArrayList(entries.length);
for (int i = 0; i < entries.length; ++i) {
if (entries[i].getEntryKind() == IPathEntry.CDT_OUTPUT) {
list.add(entries[i]);
}
}
IOutputEntry[] outs = new IOutputEntry[list.size()];
list.toArray(outs);
return outs;
}
public IProjectEntry[] getProjectEntries(ICProject cproject) throws CModelException {
IPathEntry[] entries = getResolvedPathEntries(cproject);
ArrayList list = new ArrayList(entries.length);
for (int i = 0; i < entries.length; ++i) {
if (entries[i].getEntryKind() == IPathEntry.CDT_PROJECT) {
list.add(entries[i]);
}
}
IProjectEntry[] projects = new IProjectEntry[list.size()];
list.toArray(projects);
return projects;
}
public ISourceEntry[] getSourceEntries(ICProject cproject) throws CModelException {
IPathEntry[] entries = getResolvedPathEntries(cproject);
ArrayList list = new ArrayList(entries.length);
for (int i = 0; i < entries.length; ++i) {
if (entries[i].getEntryKind() == IPathEntry.CDT_SOURCE) {
list.add(entries[i]);
}
}
ISourceEntry[] sources = new ISourceEntry[list.size()];
list.toArray(sources);
return sources;
}
public ILibraryEntry[] getLibraryEntries(ICProject cproject) throws CModelException {
IPathEntry[] entries = getResolvedPathEntries(cproject);
ArrayList list = new ArrayList(entries.length);
for (int i = 0; i < entries.length; ++i) {
if (entries[i].getEntryKind() == IPathEntry.CDT_LIBRARY) {
list.add(entries[i]);
}
}
ILibraryEntry[] libs = new ILibraryEntry[list.size()];
list.toArray(libs);
return libs;
}
public IMacroEntry[] getMacroEntries(ICProject cproject) throws CModelException {
IPathEntry[] entries = getResolvedPathEntries(cproject);
ArrayList list = new ArrayList(entries.length);
for (int i = 0; i < entries.length; ++i) {
if (entries[i].getEntryKind() == IPathEntry.CDT_MACRO) {
list.add(entries[i]);
}
}
IMacroEntry[] macros = new IMacroEntry[list.size()];
list.toArray(macros);
return macros;
}
public IIncludeEntry[] getIncludeEntries(ICProject cproject) throws CModelException {
IPathEntry[] entries = getResolvedPathEntries(cproject);
ArrayList list = new ArrayList(entries.length);
for (int i = 0; i < entries.length; ++i) {
if (entries[i].getEntryKind() == IPathEntry.CDT_INCLUDE) {
list.add(entries[i]);
}
}
IIncludeEntry[] includes = new IIncludeEntry[list.size()];
list.toArray(includes);
return includes;
}
public IPathEntry[] getResolvedPathEntries(ICProject cproject) throws CModelException {
IPathEntry[] entries = (IPathEntry[]) resolvedMap.get(cproject);
if (entries == null) {
@ -235,8 +314,7 @@ public class PathEntryManager implements ICDescriptorListener {
continue;
}
remaining++;
oldResolvedEntries[i] = (IPathEntry[]) resolvedMap.get(affectedProject);
resolvedMap.put(affectedProject, null);
oldResolvedEntries[i] = (IPathEntry[]) resolvedMap.remove(affectedProject);
containerPut(affectedProject, containerPath, newContainer);
}
// Nothing change.
@ -422,7 +500,7 @@ public class PathEntryManager implements ICDescriptorListener {
encodePathEntries(cproject.getPath(), doc, rootElement, newRawEntries);
}
descriptor.saveProjectData();
resolvedMap.put(cproject, null);
resolvedMap.remove(cproject);
} catch (CoreException e) {
throw new CModelException(e);
}
@ -504,33 +582,46 @@ public class PathEntryManager implements ICDescriptorListener {
flag = ICElementDelta.F_PATHENTRY_REORDER;
} else {
int kind = entry.getEntryKind();
if (kind == IPathEntry.CDT_SOURCE) {
ISourceEntry source = (ISourceEntry) entry;
IPath path = source.getPath();
celement = CoreModel.getDefault().create(path);
flag = (removed) ? ICElementDelta.F_REMOVED_PATHENTRY_SOURCE : ICElementDelta.F_ADDED_PATHENTRY_SOURCE;
} else if (kind == IPathEntry.CDT_LIBRARY) {
ILibraryEntry lib = (ILibraryEntry) entry;
celement = CProject.getLibraryReference(cproject, null, lib);
flag = (removed) ? ICElementDelta.F_ADDED_PATHENTRY_LIBRARY : ICElementDelta.F_REMOVED_PATHENTRY_LIBRARY;
} else if (kind == IPathEntry.CDT_PROJECT) {
//IProjectEntry pentry = (IProjectEntry) entry;
celement = cproject;
flag = ICElementDelta.F_CHANGED_PATHENTRY_PROJECT;
} else if (kind == IPathEntry.CDT_INCLUDE) {
IIncludeEntry include = (IIncludeEntry) entry;
IPath path = include.getPath();
celement = CoreModel.getDefault().create(path);
flag = ICElementDelta.F_CHANGED_PATHENTRY_INCLUDE;
} else if (kind == IPathEntry.CDT_MACRO) {
IMacroEntry macro = (IMacroEntry) entry;
IPath path = macro.getPath();
celement = CoreModel.getDefault().create(path);
flag = ICElementDelta.F_CHANGED_PATHENTRY_MACRO;
} else if (kind == IPathEntry.CDT_CONTAINER) {
//IContainerEntry container = (IContainerEntry) entry;
//celement = cproject;
// SHOULD NOT BE HERE Container are resolved.
switch (kind) {
case IPathEntry.CDT_SOURCE: {
ISourceEntry source = (ISourceEntry) entry;
IPath path = source.getPath();
celement = CoreModel.getDefault().create(path);
flag = (removed) ? ICElementDelta.F_REMOVED_PATHENTRY_SOURCE : ICElementDelta.F_ADDED_PATHENTRY_SOURCE;
break;
}
case IPathEntry.CDT_LIBRARY: {
ILibraryEntry lib = (ILibraryEntry) entry;
celement = cproject;
flag = (removed) ? ICElementDelta.F_REMOVED_PATHENTRY_LIBRARY : ICElementDelta.F_ADDED_PATHENTRY_LIBRARY;
break;
}
case IPathEntry.CDT_PROJECT: {
//IProjectEntry pentry = (IProjectEntry) entry;
celement = cproject;
flag = ICElementDelta.F_CHANGED_PATHENTRY_PROJECT;
break;
}
case IPathEntry.CDT_INCLUDE: {
IIncludeEntry include = (IIncludeEntry) entry;
IPath path = include.getPath();
celement = CoreModel.getDefault().create(path);
flag = ICElementDelta.F_CHANGED_PATHENTRY_INCLUDE;
break;
}
case IPathEntry.CDT_MACRO: {
IMacroEntry macro = (IMacroEntry) entry;
IPath path = macro.getPath();
celement = CoreModel.getDefault().create(path);
flag = ICElementDelta.F_CHANGED_PATHENTRY_MACRO;
break;
}
case IPathEntry.CDT_CONTAINER: {
//IContainerEntry container = (IContainerEntry) entry;
//celement = cproject;
//SHOULD NOT BE HERE Container are resolved.
break;
}
}
}
if (celement == null) {
@ -566,21 +657,31 @@ public class PathEntryManager implements ICDescriptorListener {
static IPathEntry decodePathEntry(ICProject cProject, Element element) throws CModelException {
IPath projectPath = cProject.getProject().getFullPath();
// kind
String kindAttr = element.getAttribute(ATTRIBUTE_KIND);
int kind = PathEntry.kindFromString(kindAttr);
// exported flag
boolean isExported = false;
if (element.hasAttribute(ATTRIBUTE_EXPORTED)) {
isExported = element.getAttribute(ATTRIBUTE_EXPORTED).equals(VALUE_TRUE);
}
// ensure path is absolute
boolean hasPath = element.hasAttribute(ATTRIBUTE_PATH);
String pathAttr = element.getAttribute(ATTRIBUTE_PATH);
IPath path = new Path(pathAttr);
if (kind != IPathEntry.CDT_VARIABLE && !path.isAbsolute()) {
if (!path.isAbsolute()) {
path = projectPath.append(path);
}
// check fo the base path
IPath basePath = null;
if (element.hasAttribute(ATTRIBUTE_BASE_PATH)) {
basePath = new Path(element.getAttribute(ATTRIBUTE_BASE_PATH));
}
// source attachment info (optional)
IPath sourceAttachmentPath = element.hasAttribute(ATTRIBUTE_SOURCEPATH) ? new Path(
element.getAttribute(ATTRIBUTE_SOURCEPATH)) : null;
@ -588,6 +689,7 @@ public class PathEntryManager implements ICDescriptorListener {
element.getAttribute(ATTRIBUTE_ROOTPATH)) : null;
IPath sourceAttachmentPrefixMapping = element.hasAttribute(ATTRIBUTE_PREFIXMAPPING) ? new Path(
element.getAttribute(ATTRIBUTE_PREFIXMAPPING)) : null;
// exclusion patterns (optional)
String exclusion = element.getAttribute(ATTRIBUTE_EXCLUDING);
IPath[] exclusionPatterns = APathEntry.NO_EXCLUSION_PATTERNS;
@ -601,12 +703,13 @@ public class PathEntryManager implements ICDescriptorListener {
}
}
}
// recreate the CP entry
// recreate the entry
switch (kind) {
case IPathEntry.CDT_PROJECT :
return CoreModel.newProjectEntry(path, isExported);
case IPathEntry.CDT_LIBRARY :
return CoreModel.newLibraryEntry(path, sourceAttachmentPath, sourceAttachmentRootPath,
return CoreModel.newLibraryEntry(path, basePath, sourceAttachmentPath, sourceAttachmentRootPath,
sourceAttachmentPrefixMapping, isExported);
case IPathEntry.CDT_SOURCE :
{
@ -635,13 +738,13 @@ public class PathEntryManager implements ICDescriptorListener {
if (element.hasAttribute(ATTRIBUTE_SYSTEM)) {
isSystemInclude = element.getAttribute(ATTRIBUTE_SYSTEM).equals(VALUE_TRUE);
}
return CoreModel.newIncludeEntry(path, includePath, isSystemInclude, exclusionPatterns);
return CoreModel.newIncludeEntry(path, includePath, basePath, isSystemInclude, exclusionPatterns);
}
case IPathEntry.CDT_MACRO :
{
String macroName = element.getAttribute(ATTRIBUTE_NAME);
String macroValue = element.getAttribute(ATTRIBUTE_VALUE);
return CoreModel.newMacroEntry(path, macroName, macroValue, exclusionPatterns);
return CoreModel.newMacroEntry(path, basePath, macroName, macroValue, exclusionPatterns);
}
case IPathEntry.CDT_CONTAINER :
{
@ -691,6 +794,9 @@ public class PathEntryManager implements ICDescriptorListener {
ILibraryEntry lib = (ILibraryEntry) entries[i];
IPath path = lib.getPath();
element.setAttribute(ATTRIBUTE_PATH, path.toString());
if (lib.getBasePath() != null) {
element.setAttribute(ATTRIBUTE_BASE_PATH, lib.getBasePath().toString());
}
if (lib.getSourceAttachmentPath() != null) {
element.setAttribute(ATTRIBUTE_SOURCEPATH, lib.getSourceAttachmentPath().toString());
}
@ -706,9 +812,11 @@ public class PathEntryManager implements ICDescriptorListener {
element.setAttribute(ATTRIBUTE_PATH, path.toString());
} else if (kind == IPathEntry.CDT_INCLUDE) {
IIncludeEntry include = (IIncludeEntry) entries[i];
IPath path = include.getPath();
if (path != null) {
element.setAttribute(ATTRIBUTE_PATH, path.toString());
if (include.getPath() != null) {
element.setAttribute(ATTRIBUTE_PATH, include.getPath().toString());
}
if (include.getBasePath() != null) {
element.setAttribute(ATTRIBUTE_BASE_PATH, include.getBasePath().toString());
}
IPath includePath = include.getIncludePath();
element.setAttribute(ATTRIBUTE_INCLUDE, includePath.toString());
@ -717,9 +825,11 @@ public class PathEntryManager implements ICDescriptorListener {
}
} else if (kind == IPathEntry.CDT_MACRO) {
IMacroEntry macro = (IMacroEntry) entries[i];
IPath path = macro.getPath();
if (path != null) {
element.setAttribute(ATTRIBUTE_PATH, path.toString());
if (macro.getPath() != null) {
element.setAttribute(ATTRIBUTE_PATH, macro.getPath().toString());
}
if (macro.getBasePath() != null) {
element.setAttribute(ATTRIBUTE_BASE_PATH, macro.getBasePath().toString());
}
element.setAttribute(ATTRIBUTE_NAME, macro.getMacroName());
element.setAttribute(ATTRIBUTE_VALUE, macro.getMacroValue());
@ -744,21 +854,23 @@ public class PathEntryManager implements ICDescriptorListener {
ICDescriptor cdesc = event.getDescriptor();
if (cdesc != null) {
CModelManager manager = CModelManager.getDefault();
ICProject cproject = manager.create(cdesc.getProject());
IProject project = cproject.getProject();
try {
IPathEntry[] oldResolvedEntries = getResolvedPathEntries(cproject);
resolvedMap.remove(cproject);
IPathEntry[] newResolvedEntries = getResolvedPathEntries(cproject);
ICElementDelta[] deltas = generatePathEntryDeltas(cproject, oldResolvedEntries, newResolvedEntries);
if (deltas.length > 0) {
cproject.close();
for (int i = 0; i < deltas.length; i++) {
manager.registerCModelDelta(deltas[i]);
IProject project = cdesc.getProject();
if (manager.hasCNature(project) || manager.hasCCNature(project)) {
ICProject cproject = manager.create(project);
try {
IPathEntry[] oldResolvedEntries = getResolvedPathEntries(cproject);
resolvedMap.remove(cproject);
IPathEntry[] newResolvedEntries = getResolvedPathEntries(cproject);
ICElementDelta[] deltas = generatePathEntryDeltas(cproject, oldResolvedEntries, newResolvedEntries);
if (deltas.length > 0) {
cproject.close();
for (int i = 0; i < deltas.length; i++) {
manager.registerCModelDelta(deltas[i]);
}
manager.fire(ElementChangedEvent.POST_CHANGE);
}
manager.fire(ElementChangedEvent.POST_CHANGE);
} catch (CModelException e) {
}
} catch (CModelException e) {
}
}
}

View file

@ -18,7 +18,7 @@ import org.eclipse.core.runtime.IPath;
public class SourceEntry extends APathEntry implements ISourceEntry {
public SourceEntry(IPath path, IPath[] exclusionPatterns) {
super(ISourceEntry.CDT_SOURCE, path, exclusionPatterns, false);
super(ISourceEntry.CDT_SOURCE, path, null, exclusionPatterns, false);
}
public boolean equals (Object obj) {