use of org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParserExtension in project webtools.sourceediting by eclipse.
the class AbstractModelLoader method transformInstance.
/**
* this work is done better elsewhere, but done here for this version to
* reduce changes. especially since the need for it should go away once we
* no longer need to re-use old document instance.
*/
private void transformInstance(IStructuredDocument oldInstance, IStructuredDocument newInstance) {
/**
* https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=4920
*
* JSP taglib support broken, correct by duplicating extended setup
* information (BlockTagParser extension,
* StructuredDocumentRegionParser extensions)
*/
RegionParser oldParser = oldInstance.getParser();
RegionParser newParser = newInstance.getParser().newInstance();
// parser
if (oldParser instanceof StructuredDocumentRegionParserExtension && newParser instanceof StructuredDocumentRegionParserExtension) {
List oldHandlers = ((StructuredDocumentRegionParserExtension) oldParser).getStructuredDocumentRegionHandlers();
for (int i = 0; i < oldHandlers.size(); i++) {
StructuredDocumentRegionHandler handler = ((StructuredDocumentRegionHandler) oldHandlers.get(i));
if (handler instanceof StructuredDocumentRegionHandlerExtension) {
/**
* Skip the transferring here, the handler will do this
* after everything else but the source is transferred.
*/
} else {
((StructuredDocumentRegionParser) oldParser).removeStructuredDocumentRegionHandler(handler);
((StructuredDocumentRegionParser) newParser).addStructuredDocumentRegionHandler(handler);
handler.resetNodes();
}
}
}
// Add any global BlockMarkers to the new parser
if (oldParser instanceof BlockTagParser && newParser instanceof BlockTagParser) {
List oldBlockMarkers = ((BlockTagParser) oldParser).getBlockMarkers();
for (int i = 0; i < oldBlockMarkers.size(); i++) {
BlockMarker blockMarker = ((BlockMarker) oldBlockMarkers.get(i));
if (blockMarker.isGlobal()) {
((BlockTagParser) newParser).addBlockMarker(blockMarker);
}
}
}
((BasicStructuredDocument) oldInstance).setParser(newParser);
((BasicStructuredDocument) oldInstance).setReParser(newInstance.getReParser().newInstance());
if (newInstance.getDocumentPartitioner() instanceof StructuredTextPartitioner) {
StructuredTextPartitioner partitioner = null;
if (oldInstance instanceof IDocumentExtension3 && newInstance instanceof IDocumentExtension3) {
partitioner = ((StructuredTextPartitioner) ((IDocumentExtension3) newInstance).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING));
if (partitioner != null) {
partitioner = (StructuredTextPartitioner) partitioner.newInstance();
}
((IDocumentExtension3) oldInstance).setDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING, partitioner);
}
if (partitioner == null) {
partitioner = (StructuredTextPartitioner) ((StructuredTextPartitioner) newInstance.getDocumentPartitioner()).newInstance();
oldInstance.setDocumentPartitioner(partitioner);
}
if (partitioner != null) {
partitioner.connect(oldInstance);
}
}
String existingLineDelimiter = null;
try {
existingLineDelimiter = newInstance.getLineDelimiter(0);
} catch (BadLocationException e) {
// if empty file, assume platform default
// TODO: should be using user set preference, per content type?
// $NON-NLS-1$
existingLineDelimiter = System.getProperty("line.separator");
}
// $NON-NLS-1$);
oldInstance.setLineDelimiter(existingLineDelimiter);
if (newInstance.getEncodingMemento() != null) {
oldInstance.setEncodingMemento((EncodingMemento) newInstance.getEncodingMemento().clone());
}
/**
* https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=4920
*
* JSP taglib support broken, correct by duplicating extended setup
* information (BlockTagParser extension,
* StructuredDocumentRegionParser extensions)
*/
if (oldParser instanceof StructuredDocumentRegionParserExtension && newParser instanceof StructuredDocumentRegionParserExtension) {
List oldHandlers = ((StructuredDocumentRegionParserExtension) oldParser).getStructuredDocumentRegionHandlers();
for (int i = 0; i < oldHandlers.size(); i++) {
StructuredDocumentRegionHandler handler = ((StructuredDocumentRegionHandler) oldHandlers.get(i));
if (handler instanceof StructuredDocumentRegionHandlerExtension) {
StructuredDocumentRegionHandlerExtension handlerExtension = (StructuredDocumentRegionHandlerExtension) handler;
handlerExtension.setStructuredDocument(oldInstance);
}
}
}
String holdString = newInstance.get();
newInstance = null;
oldInstance.set(holdString);
}
Aggregations