use of org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent in project webtools.sourceediting by eclipse.
the class StructuredDocumentReParser method checkForQuotes.
/*
* For simplicity, if either text to be deleted, or text to be inserted
* contains at least one quote, we'll search for previous quote in
* document, if any, and use that document region as a dirty start, and we'll use
* end of document as dirty end. We need to assume either \" or \' is an
* acceptable quote. (NOTE: this is, loosely, an XML assumption -- other
* languages would differ, but we'll "hard code" for XML for now.
*
* future_TODO: this is a really bad heuristic ... we should be looking
* for odd number of quotes within a structuredDocumentRegion (or
* something!) This causes way too much reparsing on simple cases, like
* deleting a tag with a quoted attribute!
*/
private StructuredDocumentEvent checkForQuotes() {
// thing: deletion
if (fChanges == null)
// $NON-NLS-1$
fChanges = "";
//
StructuredDocumentEvent result = null;
try {
int dirtyStartPos = -1;
String proposedDeletion = fStructuredDocument.get(fStart, fLengthToReplace);
if (fStart < fStructuredDocument.getLength()) {
if ((fChanges.indexOf(singleQuote) > -1) || (proposedDeletion.indexOf(singleQuote) > -1)) {
IRegion singleQuoteRegion = getFindReplaceDocumentAdapter().find(fStart, singleQuote, false, false, false, false);
if (singleQuoteRegion != null) {
dirtyStartPos = singleQuoteRegion.getOffset();
}
} else if ((fChanges.indexOf(doubleQuote) > -1) || (proposedDeletion.indexOf(doubleQuote) > -1)) {
IRegion doubleQuoteRegion = getFindReplaceDocumentAdapter().find(fStart, doubleQuote, false, false, false, false);
if (doubleQuoteRegion != null) {
dirtyStartPos = doubleQuoteRegion.getOffset();
}
}
}
if (dirtyStartPos > -1) {
// then we found one, do create new structuredDocument event
// based on the previous quote to end of document
// except, we need to be positive that the previous quote is
// in a "safe start" region (e.g. if in JSP content, we need
// to
// backup till we include the whole JSP region, in order for
// it
// to be correctly re-parsed. The backing up is done in the
// reparse/find dirty start from hint
// method.
result = reparse(dirtyStartPos, fStructuredDocument.getLength() - 1);
}
} catch (BadLocationException e) {
Logger.logException(e);
}
if (result != null) {
result.setDeletedText(fDeletedText);
}
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent in project webtools.sourceediting by eclipse.
the class StructuredDocumentReParser method checkForSelfClosing.
/**
* Checks if the start region has become self-closing. e.g., <style> -> <style/>
*/
private StructuredDocumentEvent checkForSelfClosing(String tagName) {
StructuredDocumentEvent result = null;
if (dirtyStart.getText().toLowerCase().indexOf(tagName.toLowerCase()) >= 0) {
// within a start-tag
final int documentLength = fStructuredDocument.getLength();
int end = fStart + fLengthToReplace + fChanges.length() + 1;
if (end > documentLength)
end = documentLength - 1;
final String oldText = fStructuredDocument.get(fStart, 1);
final String peek = StringUtils.paste(oldText, fChanges, 0, fLengthToReplace);
if ("/>".equals(peek)) {
// Reparse afterwards if the tag became self-closing
result = reparse(dirtyStart.getStart(), documentLength - 1);
}
}
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent in project webtools.sourceediting by eclipse.
the class StructuredDocumentReParser method checkForCrossStructuredDocumentRegionBoundryCases.
// /**
// * Currently this method is pretty specific to ?ML
// * @deprecated - not really deprecated, but plan to make
// * protected ... I'm not sure why its public or misspelled?
// */
protected StructuredDocumentEvent checkForCrossStructuredDocumentRegionBoundryCases() {
StructuredDocumentEvent result = null;
// StructuredDocumentRegions be rescanned
if (result == null) {
result = checkForCrossStructuredDocumentRegionSyntax();
}
// Case 2: "block tags" whose content is left unparsed
if (result == null) {
Object parser = fStructuredDocument.getParser();
if (parser instanceof BlockTagParser) {
List blockTags = ((BlockTagParser) parser).getBlockMarkers();
result = _checkBlockNodeList(blockTags);
}
}
// or! do we already do it some other more central place?
if (result != null) {
result.setDeletedText(fDeletedText);
}
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent in project webtools.sourceediting by eclipse.
the class StructuredDocumentReParser method checkForCrossStructuredDocumentRegionSyntax.
/**
* Allow a reparser to check for extra syntactic cases that require
* parsing beyond the flatNode boundary.
*
* This implementation is very XML-centric.
*/
protected StructuredDocumentEvent checkForCrossStructuredDocumentRegionSyntax() {
StructuredDocumentEvent result;
// Case 1: Quote characters are involved
result = checkForQuotes();
if (result == null) {
// Case 2: The input forms or undoes a comment beginning or
// comment
// end
result = checkForComments();
}
if (result == null) {
// Case 3: The input forms or undoes a processing instruction
result = checkForPI();
}
if (result == null) {
// Case 4: The input forms or undoes a CDATA section
result = checkForCDATA();
}
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent in project webtools.sourceediting by eclipse.
the class StructuredDocumentReParser method quickCheck.
/**
* A method to allow any heuristic "quick checks" that might cover many
* many cases, before expending the time on a full reparse.
*/
public StructuredDocumentEvent quickCheck() {
StructuredDocumentEvent result = null;
// to handle, but only if there is one flatnode involved.
if (dirtyStart != null && dirtyStart == dirtyEnd) {
IStructuredDocumentRegion targetNode = dirtyStart;
result = dirtyStart.updateRegion(fRequester, targetNode, fChanges, fStart, fLengthToReplace);
if (result != null) {
// at this point only, we need to update the text store and
// and downstream nodes.
// FUTURE_TO_DO: can this dependency on structuredDocument
// method be eliminated?
fStructuredDocument.updateDocumentData(fStart, fLengthToReplace, fChanges);
IStructuredDocumentRegion firstDownStreamNode = targetNode.getNext();
// any downstream ones
if (firstDownStreamNode != null) {
StructuredDocumentRegionIterator.adjustStart(firstDownStreamNode, fLengthDifference);
}
}
}
if (result != null) {
result.setDeletedText(fDeletedText);
}
return result;
}
Aggregations