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

2005-07-05 Alain Magloire

Fix for PR 102327: ContentType framework.
	* model/org/eclipse/cdt/core/model/CoreModel.java
	* model/org/eclipse/cdt/internal/core/model/ContentTypeProcessor.java
	* model/org/eclipse/cdt/internal/core/model/TranslationUnit.java
This commit is contained in:
Alain Magloire 2005-07-06 02:20:16 +00:00
parent 67840a34c9
commit 1594e1b8f9
4 changed files with 98 additions and 27 deletions

View file

@ -1,3 +1,9 @@
2005-07-05 Alain Magloire
Fix for PR 102327: ContentType framework.
* model/org/eclipse/cdt/core/model/CoreModel.java
* model/org/eclipse/cdt/internal/core/model/ContentTypeProcessor.java
* model/org/eclipse/cdt/internal/core/model/TranslationUnit.java
2005-07-05 Robert O'Callahan <robert@ocallahan.org>
fix for bug# 102434

View file

@ -193,14 +193,25 @@ public class CoreModel {
CCorePlugin.CONTENT_TYPE_CXXSOURCE
};
}
/**
* Return true if name is a valid name for a translation unit.
*/
public static boolean isValidTranslationUnitName(IProject project, String name) {
if (isValidHeaderUnitName(project, name)) {
return true;
} else if (isValidSourceUnitName(project, name)) {
return true;
IContentType contentType = CCorePlugin.getContentType(project, name);
if (contentType != null) {
String id = contentType.getId();
if (CCorePlugin.CONTENT_TYPE_CHEADER.equals(id)) {
return true;
} else if (CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(id)) {
return true;
} else if (CCorePlugin.CONTENT_TYPE_CSOURCE.equals(id)) {
return true;
} else if (CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(id)) {
return true;
} else if (CCorePlugin.CONTENT_TYPE_ASMSOURCE.equals(id)) {
return true;
}
}
return false;
}
@ -209,10 +220,14 @@ public class CoreModel {
* Return true if name is a valid name for a translation unit.
*/
public static boolean isValidHeaderUnitName(IProject project, String name) {
if (isValidCHeaderUnitName(project, name)) {
return true;
} else if (isValidCXXHeaderUnitName(project, name)) {
return true;
IContentType contentType = CCorePlugin.getContentType(project, name);
if (contentType != null) {
String id = contentType.getId();
if (CCorePlugin.CONTENT_TYPE_CHEADER.equals(id)) {
return true;
} else if (CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(id)) {
return true;
}
}
return false;
}
@ -221,12 +236,16 @@ public class CoreModel {
* Return true if name is a valid name for a translation unit.
*/
public static boolean isValidSourceUnitName(IProject project, String name) {
if (isValidCSourceUnitName(project, name)) {
return true;
} else if (isValidCXXSourceUnitName(project, name)) {
return true;
} else if (isValidASMSourceUnitName(project, name)) {
return true;
IContentType contentType = CCorePlugin.getContentType(project, name);
if (contentType != null) {
String id = contentType.getId();
if (CCorePlugin.CONTENT_TYPE_CSOURCE.equals(id)) {
return true;
} else if (CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(id)) {
return true;
} else if (CCorePlugin.CONTENT_TYPE_ASMSOURCE.equals(id)) {
return true;
}
}
return false;
}

View file

@ -19,6 +19,7 @@ import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ElementChangedEvent;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICElementDelta;
import org.eclipse.cdt.core.model.ICModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IOpenable;
@ -49,14 +50,13 @@ public class ContentTypeProcessor {
IContentType contentType = event.getContentType();
// only interested in our contentTypes
if (isRegisteredContentTypeId(contentType.getId())) {
// Go through the events and generate deltas
ICProject[] cprojects = getAffectedProjects(event);
for (int k = 0; k < cprojects.length; ++k) {
ICProject cproject = cprojects[k];
processContentType(cproject, contentType, event.getContext());
}
// Go through the events and generate deltas
ICProject[] cprojects = getAffectedProjects(event);
for (int k = 0; k < cprojects.length; ++k) {
ICProject cproject = cprojects[k];
processContentType(cproject, contentType, event.getContext());
}
if (fCurrentDelta.getAffectedChildren().length > 0) {
fManager.fire(fCurrentDelta, ElementChangedEvent.POST_CHANGE);
}
@ -98,15 +98,29 @@ public class ContentTypeProcessor {
members = ((IContainer)resource).members();
}
if (members != null) {
//IContentTypeMatcher matcher = resource.getProject().getContentTypeMatcher();
for (int i = 0; i < members.length; ++i) {
if (members[i] instanceof IFile) {
IFile file = (IFile) members[i];
IContentType cType = CCorePlugin.getContentType(file.getProject(), file.getName());
String name = file.getName();
IContentType cType = CCorePlugin.getContentType(file.getProject(), name);
if (cType != null && cType.equals(contentType)) {
ICElement newElement = CoreModel.getDefault().create(file);
if (newElement != null) {
elementAdded(newElement, celement);
boolean found = false;
for (int j = 0; j < celements.length; ++j) {
if (celements[j].getElementName().equals(name)
&& celements[j].getElementType() == ICElement.C_UNIT) {
ITranslationUnit unit = (ITranslationUnit)celements[j];
if (!cType.getId().equals(unit.getContentTypeId())) {
elementChanged(celements[j]);
}
found = true;
break;
}
}
if (! found) {
ICElement newElement = CoreModel.getDefault().create(file);
if (newElement != null) {
elementAdded(newElement, celement);
}
}
}
}
@ -126,7 +140,12 @@ public class ContentTypeProcessor {
if (contentType.getId().equals(id)) {
try {
if (! contentType.isAssociatedWith(celement.getElementName(), context)) {
elementRemoved(celement, celement.getParent());
IContentType cType = CCorePlugin.getContentType(celement.getCProject().getProject(), celement.getElementName());
if (cType != null && isRegisteredContentTypeId(cType.getId())) {
elementChanged(celement);
} else {
elementRemoved(celement, celement.getParent());
}
}
} catch (CoreException e) {
//
@ -205,6 +224,21 @@ public class ContentTypeProcessor {
fManager.releaseCElement(celement);
}
protected void elementChanged(ICElement element) throws CModelException {
// For Binary/Archive We can not call close() to do the work
// closing will remove the element from the {Binary,Archive}Container
// We neef to clear the cache explicitely
// if (element instanceof IBinary || element instanceof IArchive) {
// closeBinary(element);
// } else if (element instanceof Openable) {
// close((Openable)element);
// }
// fCurrentDelta.changed(element, ICElementDelta.F_CONTENT);
if (element instanceof IOpenable) {
((IOpenable)element).close();
}
fCurrentDelta.changed(element, ICElementDelta.F_CONTENT);
}
/**
* Removes the given element from its parents cache of children. If the
* element does not have a parent, or the parent is not currently open,

View file

@ -27,6 +27,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.content.IContentType;
/**
* @see ITranslationUnit
@ -659,4 +660,15 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
protected void setContentTypeID(String id) {
fContentTypeID = id;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.model.Openable#closing(java.lang.Object)
*/
protected void closing(Object info) throws CModelException {
IContentType cType = CCorePlugin.getContentType(getCProject().getProject(), getElementName());
if (cType != null) {
setContentTypeID(cType.getId());
}
super.closing(info);
}
}