mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
added method for implementing firing events when
cpathentry is modified.
This commit is contained in:
parent
f61ea0d841
commit
7d41a65e94
12 changed files with 316 additions and 22 deletions
|
@ -100,8 +100,16 @@ public interface ICElementDelta {
|
|||
*/
|
||||
public int F_BINARY_PARSER_CHANGED = 0x0800;
|
||||
|
||||
//public int F_ADDED_TO_CLASSPATH = 0x0040;
|
||||
//public int F_REMOVED_FROM_CLASSPATH = 0x0080;
|
||||
/**
|
||||
* A cpathEntry was added for this resource.
|
||||
*/
|
||||
public int F_ADDED_TO_CPATHENTRY = 0x0040;
|
||||
|
||||
/**
|
||||
* A cpathEtnry was remove for this resource.
|
||||
*/
|
||||
public int F_REMOVED_FROM_CPATHENTRY = 0x0080;
|
||||
|
||||
//public int F_CLASSPATH_REORDER = 0x0100;
|
||||
//public int F_SUPER_TYPES = 0x0800;
|
||||
|
||||
|
|
|
@ -131,7 +131,18 @@ public interface ICProject extends ICContainer {
|
|||
* @exception CModelException if this element does not exist or if an
|
||||
* exception occurs while accessing its corresponding resource
|
||||
*/
|
||||
ICPathEntry[] getCPathEntries() throws CModelException;
|
||||
ICPathEntry[] getResolvedCPathEntries() throws CModelException;
|
||||
|
||||
/**
|
||||
* Returns the list of entries for the project. This corresponds to the exact set
|
||||
* of entries which were assigned using <code>setCPathEntries</code>.
|
||||
* <p>
|
||||
*
|
||||
* @return the list of entries for the project.
|
||||
* @exception CModelException if this element does not exist or if an
|
||||
* exception occurs while accessing its corresponding resource
|
||||
*/
|
||||
ICPathEntry[] getRawCPathEntries() throws CModelException;
|
||||
|
||||
/**
|
||||
* Sets the entries for this project.
|
||||
|
@ -144,6 +155,6 @@ public interface ICProject extends ICContainer {
|
|||
* <li> The entries are being modified during resource change event notification (CORE_EXCEPTION)
|
||||
* </ul>
|
||||
*/
|
||||
void setCPathEntries(ICPathEntry[] entries, IProgressMonitor monitor) throws CModelException;
|
||||
void setRawCPathEntries(ICPathEntry[] entries, IProgressMonitor monitor) throws CModelException;
|
||||
|
||||
}
|
||||
|
|
|
@ -42,4 +42,33 @@ public abstract class ACPathEntry extends CPathEntry {
|
|||
return isRecursive;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof ACPathEntry) {
|
||||
ACPathEntry otherEntry = (ACPathEntry)obj;
|
||||
if (!super.equals(otherEntry)) {
|
||||
return false;
|
||||
}
|
||||
if (isRecursive != otherEntry.isRecursive()) {
|
||||
return false;
|
||||
}
|
||||
IPath[] otherExcludes = otherEntry.getExclusionPatterns();
|
||||
if (exclusionPatterns != otherExcludes) {
|
||||
int excludeLength = (exclusionPatterns == null) ? 0 : exclusionPatterns.length;
|
||||
if (otherExcludes.length != excludeLength) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < excludeLength; i++) {
|
||||
// compare toStrings instead of IPaths
|
||||
// since IPath.equals is specified to ignore trailing separators
|
||||
String myPattern = exclusionPatterns[i].toString();
|
||||
if (!myPattern.equals(otherExcludes[i].toString())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,15 +39,18 @@ public class CPathEntry implements ICPathEntry {
|
|||
return isExported;
|
||||
}
|
||||
|
||||
public boolean equals(ICPathEntry otherEntry) {
|
||||
return entryKind == otherEntry.getEntryKind();
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof ICPathEntry) {
|
||||
ICPathEntry otherEntry = (ICPathEntry)obj;
|
||||
if (entryKind != otherEntry.getEntryKind()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(Object object) {
|
||||
if (object instanceof ICPathEntry) {
|
||||
return equals((ICPathEntry) object);
|
||||
if (isExported != otherEntry.isExported()) {
|
||||
return false;
|
||||
}
|
||||
return super.equals(object);
|
||||
return true;
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -115,7 +115,7 @@ public class CProject extends CContainer implements ICProject {
|
|||
binParser = CCorePlugin.getDefault().getBinaryParser(getProject());
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
ICPathEntry[] entries = getCPathEntries();
|
||||
ICPathEntry[] entries = getResolvedCPathEntries();
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
if (entries[i].getEntryKind() == ICPathEntry.CDT_LIBRARY) {
|
||||
ILibraryEntry entry = (ILibraryEntry) entries[i];
|
||||
|
@ -145,7 +145,7 @@ public class CProject extends CContainer implements ICProject {
|
|||
* @see ICProject#getRequiredProjectNames()
|
||||
*/
|
||||
public String[] getRequiredProjectNames() throws CModelException {
|
||||
return projectPrerequisites(getCPathEntries());
|
||||
return projectPrerequisites(getResolvedCPathEntries());
|
||||
}
|
||||
|
||||
public String[] projectPrerequisites(ICPathEntry[] entries) throws CModelException {
|
||||
|
@ -336,9 +336,17 @@ public class CProject extends CContainer implements ICProject {
|
|||
static String VALUE_TRUE = "true"; //$NON-NLS-1$
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ICProject#getCPathEntries()
|
||||
* @see org.eclipse.cdt.core.model.ICProject#getResolvedCPathEntries()
|
||||
*/
|
||||
public ICPathEntry[] getCPathEntries() throws CModelException {
|
||||
public ICPathEntry[] getResolvedCPathEntries() throws CModelException {
|
||||
// Not implemented
|
||||
return getRawCPathEntries();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ICProject#getRawCPathEntries()
|
||||
*/
|
||||
public ICPathEntry[] getRawCPathEntries() throws CModelException {
|
||||
ArrayList pathEntries = new ArrayList();
|
||||
try {
|
||||
ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(getProject());
|
||||
|
@ -359,11 +367,11 @@ public class CProject extends CContainer implements ICProject {
|
|||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ICProject#setCPathEntries(org.eclipse.cdt.core.model.ICPathEntry[], org.eclipse.core.runtime.IProgressMonitor)
|
||||
* @see org.eclipse.cdt.core.model.ICProject#setRawCPathEntries(org.eclipse.cdt.core.model.ICPathEntry[], org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public void setCPathEntries(ICPathEntry[] newEntries, IProgressMonitor monitor) throws CModelException {
|
||||
public void setRawCPathEntries(ICPathEntry[] newEntries, IProgressMonitor monitor) throws CModelException {
|
||||
try {
|
||||
SetCPathEntriesOperation op = new SetCPathEntriesOperation(this, getCPathEntries(), newEntries);
|
||||
SetCPathEntriesOperation op = new SetCPathEntriesOperation(this, getRawCPathEntries(), newEntries);
|
||||
runOperation(op, monitor);
|
||||
} catch (CoreException e) {
|
||||
throw new CModelException(e);
|
||||
|
@ -568,5 +576,4 @@ public class CProject extends CContainer implements ICProject {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,4 +31,24 @@ public class ContainerEntry extends CPathEntry implements IContainerEntry {
|
|||
return id;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof IContainerEntry) {
|
||||
IContainerEntry container = (IContainerEntry)obj;
|
||||
if (!super.equals(container)) {
|
||||
return false;
|
||||
}
|
||||
if (id == null) {
|
||||
if (container.getId() != null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!id.equals(container.getId())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -53,4 +53,36 @@ public class IncludeEntry extends ACPathEntry implements IIncludeEntry {
|
|||
return isSystemInclude;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof IIncludeEntry) {
|
||||
IIncludeEntry otherEntry = (IIncludeEntry)obj;
|
||||
if (!super.equals(otherEntry)) {
|
||||
return false;
|
||||
}
|
||||
if (resourcePath == null) {
|
||||
if (otherEntry.getResourcePath() != null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!resourcePath.toString().equals(otherEntry.getResourcePath().toString())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (includePath == null) {
|
||||
if (otherEntry.getIncludePath() != null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!includePath.toString().equals(otherEntry.getIncludePath().toString())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (isSystemInclude != otherEntry.isSystemInclude()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -86,4 +86,35 @@ public class LibraryEntry extends CPathEntry implements ILibraryEntry {
|
|||
return sourceAttachmentPrefixMapping;
|
||||
}
|
||||
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof ILibraryEntry) {
|
||||
ILibraryEntry otherEntry = (ILibraryEntry)obj;
|
||||
if (!super.equals(obj)) {
|
||||
return false;
|
||||
}
|
||||
IPath otherPath = otherEntry.getSourceAttachmentPath();
|
||||
if (sourceAttachmentPath == null) {
|
||||
if (otherPath != null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!sourceAttachmentPath.equals(otherPath)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
otherPath = otherEntry.getSourceAttachmentRootPath();
|
||||
if (sourceAttachmentRootPath == null) {
|
||||
if (otherPath != null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!sourceAttachmentRootPath.equals(otherPath)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,4 +54,33 @@ public class MacroEntry extends ACPathEntry implements IMacroEntry {
|
|||
return macroName;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof IMacroEntry) {
|
||||
IMacroEntry otherEntry = (IMacroEntry)obj;
|
||||
if (!super.equals(otherEntry)) {
|
||||
return false;
|
||||
}
|
||||
if (macroName == null) {
|
||||
if (otherEntry.getMacroName() != null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!macroName.equals(otherEntry.getMacroName())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (macroValue == null) {
|
||||
if (otherEntry.getMacroValue() != null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!macroValue.equals(otherEntry.getMacroValue())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,4 +33,24 @@ public class ProjectEntry extends CPathEntry implements IProjectEntry {
|
|||
return projectPath;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof IProjectEntry) {
|
||||
IProjectEntry otherEntry = (IProjectEntry)obj;
|
||||
if (!super.equals(otherEntry)) {
|
||||
return false;
|
||||
}
|
||||
if (projectPath == null) {
|
||||
if (otherEntry.getProjectPath() != null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!projectPath.toString().equals(otherEntry.getProjectPath().toString())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,11 +20,19 @@ import java.util.Iterator;
|
|||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.ICDescriptor;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICElementDelta;
|
||||
import org.eclipse.cdt.core.model.ICPathEntry;
|
||||
import org.eclipse.cdt.core.model.IContainerEntry;
|
||||
import org.eclipse.cdt.core.model.IIncludeEntry;
|
||||
import org.eclipse.cdt.core.model.IMacroEntry;
|
||||
import org.eclipse.cdt.core.model.ISourceEntry;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
@ -138,7 +146,74 @@ public class SetCPathEntriesOperation extends CModelOperation {
|
|||
}
|
||||
|
||||
private void generateCPathEntryDeltas() {
|
||||
CModelManager manager = CModelManager.getDefault();
|
||||
boolean needToUpdateDependents = false;
|
||||
CElementDelta delta = new CElementDelta(getCModel());
|
||||
boolean hasDelta = false;
|
||||
|
||||
// Check the removed entries.
|
||||
for (int i = 0; i < oldEntries.length; i++) {
|
||||
boolean found = false;
|
||||
for (int j = 0; j < newEntries.length; j++) {
|
||||
if (oldEntries[i].equals(newEntries[j])) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Was it deleted.
|
||||
if (!found) {
|
||||
addCPathEntryDeltas(oldEntries[i], ICElementDelta.F_REMOVED_FROM_CPATHENTRY, delta);
|
||||
}
|
||||
}
|
||||
// Check the new entries.
|
||||
for (int i = 0; i < newEntries.length; i++) {
|
||||
boolean found = false;
|
||||
for (int j = 0; j < oldEntries.length; j++) {
|
||||
if (newEntries[i].equals(oldEntries[j])) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// is it new?
|
||||
if (!found) {
|
||||
addCPathEntryDeltas(newEntries[i], ICElementDelta.F_ADDED_TO_CPATHENTRY, delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds deltas, with the specified change flag.
|
||||
*/
|
||||
protected void addCPathEntryDeltas(ICPathEntry entry, int flag, CElementDelta delta) {
|
||||
|
||||
int kind = entry.getEntryKind();
|
||||
ICElement celement = null;
|
||||
if (kind == ICPathEntry.CDT_SOURCE) {
|
||||
ISourceEntry source = (ISourceEntry) entry;
|
||||
IPath path = source.getSourcePath();
|
||||
celement = CoreModel.getDefault().create(path);
|
||||
} else if (kind == ICPathEntry.CDT_LIBRARY) {
|
||||
//ILibraryEntry lib = (ILibraryEntry) entry;
|
||||
//IPath path = lib.getLibraryPath();
|
||||
celement = project;
|
||||
} else if (kind == ICPathEntry.CDT_PROJECT) {
|
||||
//IProjectEntry pentry = (IProjectEntry) entry;
|
||||
//IPath path = pentry.getProjectPath();
|
||||
celement = project;
|
||||
} else if (kind == ICPathEntry.CDT_INCLUDE) {
|
||||
IIncludeEntry include = (IIncludeEntry) entry;
|
||||
IPath path = include.getResourcePath();
|
||||
celement = CoreModel.getDefault().create(path);
|
||||
} else if (kind == ICPathEntry.CDT_MACRO) {
|
||||
IMacroEntry macro = (IMacroEntry) entry;
|
||||
IPath path = macro.getResourcePath();
|
||||
celement = CoreModel.getDefault().create(path);
|
||||
} else if (kind == ICPathEntry.CDT_CONTAINER) {
|
||||
IContainerEntry container = (IContainerEntry) entry;
|
||||
celement = project;
|
||||
}
|
||||
if (celement != null) {
|
||||
delta.changed(celement, flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,4 +44,33 @@ public class SourceEntry extends ACPathEntry implements ISourceEntry {
|
|||
return outputLocation;
|
||||
}
|
||||
|
||||
public boolean equals (Object obj) {
|
||||
if (obj instanceof ISourceEntry) {
|
||||
ISourceEntry otherEntry = (ISourceEntry)obj;
|
||||
if (!super.equals(otherEntry)) {
|
||||
return false;
|
||||
}
|
||||
if (sourcePath == null) {
|
||||
if (otherEntry.getSourcePath() != null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!sourcePath.toString().equals(otherEntry.getSourcePath().toString())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (outputLocation == null) {
|
||||
if (otherEntry.getOutputLocation() != null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!outputLocation.toString().equals(otherEntry.getOutputLocation().toString())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue