mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-26 10:25:32 +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:
parent
67840a34c9
commit
1594e1b8f9
4 changed files with 98 additions and 27 deletions
|
@ -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>
|
2005-07-05 Robert O'Callahan <robert@ocallahan.org>
|
||||||
|
|
||||||
fix for bug# 102434
|
fix for bug# 102434
|
||||||
|
|
|
@ -193,14 +193,25 @@ public class CoreModel {
|
||||||
CCorePlugin.CONTENT_TYPE_CXXSOURCE
|
CCorePlugin.CONTENT_TYPE_CXXSOURCE
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if name is a valid name for a translation unit.
|
* Return true if name is a valid name for a translation unit.
|
||||||
*/
|
*/
|
||||||
public static boolean isValidTranslationUnitName(IProject project, String name) {
|
public static boolean isValidTranslationUnitName(IProject project, String name) {
|
||||||
if (isValidHeaderUnitName(project, name)) {
|
IContentType contentType = CCorePlugin.getContentType(project, name);
|
||||||
return true;
|
if (contentType != null) {
|
||||||
} else if (isValidSourceUnitName(project, name)) {
|
String id = contentType.getId();
|
||||||
return true;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -209,10 +220,14 @@ public class CoreModel {
|
||||||
* Return true if name is a valid name for a translation unit.
|
* Return true if name is a valid name for a translation unit.
|
||||||
*/
|
*/
|
||||||
public static boolean isValidHeaderUnitName(IProject project, String name) {
|
public static boolean isValidHeaderUnitName(IProject project, String name) {
|
||||||
if (isValidCHeaderUnitName(project, name)) {
|
IContentType contentType = CCorePlugin.getContentType(project, name);
|
||||||
return true;
|
if (contentType != null) {
|
||||||
} else if (isValidCXXHeaderUnitName(project, name)) {
|
String id = contentType.getId();
|
||||||
return true;
|
if (CCorePlugin.CONTENT_TYPE_CHEADER.equals(id)) {
|
||||||
|
return true;
|
||||||
|
} else if (CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -221,12 +236,16 @@ public class CoreModel {
|
||||||
* Return true if name is a valid name for a translation unit.
|
* Return true if name is a valid name for a translation unit.
|
||||||
*/
|
*/
|
||||||
public static boolean isValidSourceUnitName(IProject project, String name) {
|
public static boolean isValidSourceUnitName(IProject project, String name) {
|
||||||
if (isValidCSourceUnitName(project, name)) {
|
IContentType contentType = CCorePlugin.getContentType(project, name);
|
||||||
return true;
|
if (contentType != null) {
|
||||||
} else if (isValidCXXSourceUnitName(project, name)) {
|
String id = contentType.getId();
|
||||||
return true;
|
if (CCorePlugin.CONTENT_TYPE_CSOURCE.equals(id)) {
|
||||||
} else if (isValidASMSourceUnitName(project, name)) {
|
return true;
|
||||||
return true;
|
} else if (CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(id)) {
|
||||||
|
return true;
|
||||||
|
} else if (CCorePlugin.CONTENT_TYPE_ASMSOURCE.equals(id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ElementChangedEvent;
|
import org.eclipse.cdt.core.model.ElementChangedEvent;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
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.ICModel;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.core.model.IOpenable;
|
import org.eclipse.cdt.core.model.IOpenable;
|
||||||
|
@ -49,14 +50,13 @@ public class ContentTypeProcessor {
|
||||||
IContentType contentType = event.getContentType();
|
IContentType contentType = event.getContentType();
|
||||||
|
|
||||||
// only interested in our contentTypes
|
// only interested in our contentTypes
|
||||||
if (isRegisteredContentTypeId(contentType.getId())) {
|
// Go through the events and generate deltas
|
||||||
// Go through the events and generate deltas
|
ICProject[] cprojects = getAffectedProjects(event);
|
||||||
ICProject[] cprojects = getAffectedProjects(event);
|
for (int k = 0; k < cprojects.length; ++k) {
|
||||||
for (int k = 0; k < cprojects.length; ++k) {
|
ICProject cproject = cprojects[k];
|
||||||
ICProject cproject = cprojects[k];
|
processContentType(cproject, contentType, event.getContext());
|
||||||
processContentType(cproject, contentType, event.getContext());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fCurrentDelta.getAffectedChildren().length > 0) {
|
if (fCurrentDelta.getAffectedChildren().length > 0) {
|
||||||
fManager.fire(fCurrentDelta, ElementChangedEvent.POST_CHANGE);
|
fManager.fire(fCurrentDelta, ElementChangedEvent.POST_CHANGE);
|
||||||
}
|
}
|
||||||
|
@ -98,15 +98,29 @@ public class ContentTypeProcessor {
|
||||||
members = ((IContainer)resource).members();
|
members = ((IContainer)resource).members();
|
||||||
}
|
}
|
||||||
if (members != null) {
|
if (members != null) {
|
||||||
//IContentTypeMatcher matcher = resource.getProject().getContentTypeMatcher();
|
|
||||||
for (int i = 0; i < members.length; ++i) {
|
for (int i = 0; i < members.length; ++i) {
|
||||||
if (members[i] instanceof IFile) {
|
if (members[i] instanceof IFile) {
|
||||||
IFile file = (IFile) members[i];
|
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)) {
|
if (cType != null && cType.equals(contentType)) {
|
||||||
ICElement newElement = CoreModel.getDefault().create(file);
|
boolean found = false;
|
||||||
if (newElement != null) {
|
for (int j = 0; j < celements.length; ++j) {
|
||||||
elementAdded(newElement, celement);
|
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)) {
|
if (contentType.getId().equals(id)) {
|
||||||
try {
|
try {
|
||||||
if (! contentType.isAssociatedWith(celement.getElementName(), context)) {
|
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) {
|
} catch (CoreException e) {
|
||||||
//
|
//
|
||||||
|
@ -205,6 +224,21 @@ public class ContentTypeProcessor {
|
||||||
fManager.releaseCElement(celement);
|
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
|
* 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,
|
* element does not have a parent, or the parent is not currently open,
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.content.IContentType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ITranslationUnit
|
* @see ITranslationUnit
|
||||||
|
@ -659,4 +660,15 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
||||||
protected void setContentTypeID(String id) {
|
protected void setContentTypeID(String id) {
|
||||||
fContentTypeID = 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue