use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.
the class JavascriptValidationStrategy method reconcile.
/* (non-Javadoc)
* @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.IRegion)
*/
public void reconcile(IRegion partition) {
ITypedRegion[] partitions = computePartitioning(partition);
// call the validator strategy once for each effected partition
DirtyRegion dirty = null;
for (int i = 0; i < partitions.length; i++) {
dirty = createDirtyRegion(partitions[i], DirtyRegion.INSERT);
// [source]validator (extension) for this partition
if (getValidatorStrategy() != null) {
getValidatorStrategy().reconcile(partitions[i], dirty);
}
}
}
use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.
the class AddBlockCommentHandler method processAction.
/**
* @see org.eclipse.wst.sse.ui.internal.handlers.AbstractCommentHandler#processAction(
* org.eclipse.ui.texteditor.ITextEditor, org.eclipse.jface.text.IDocument, org.eclipse.jface.text.ITextSelection)
*/
protected void processAction(ITextEditor textEditor, IStructuredDocument document, ITextSelection textSelection) {
IStructuredModel model = null;
boolean changed = false;
DocumentRewriteSession session = null;
try {
model = StructuredModelManager.getModelManager().getModelForEdit(document);
if (model != null) {
// makes it so one undo will undo all the edits to the document
model.beginRecording(this, SSEUIMessages.AddBlockComment_label, SSEUIMessages.AddBlockComment_description);
// keeps listeners from doing anything until updates are all done
model.aboutToChangeModel();
if (document instanceof IDocumentExtension4) {
session = ((IDocumentExtension4) document).startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);
}
changed = true;
ITypedRegion[] typedRegions = document.computePartitioning(textSelection.getOffset(), textSelection.getLength());
CommentingStrategy commentType = CommentingStrategyRegistry.getDefault().getBlockCommentingStrategy(model.getContentTypeIdentifier(), typedRegions);
if (commentType != null) {
commentType.apply(document, textSelection.getOffset(), textSelection.getLength());
}
}
} catch (BadLocationException e) {
// $NON-NLS-1$ //$NON-NLS-2$
Logger.logException("The given selection " + textSelection + " must be invalid", e);
} finally {
// clean everything up
if (session != null && document instanceof IDocumentExtension4) {
((IDocumentExtension4) document).stopRewriteSession(session);
}
if (model != null) {
model.endRecording(this);
if (changed) {
model.changedModel();
}
model.releaseFromEdit();
}
}
}
use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.
the class TestXSLLineStyleProvider method testPrepareRegion.
@Test
public void testPrepareRegion() throws Exception {
setUpTest("utils.xsl");
LineStyleProvider provider = initializeProvider();
ITypedRegion[] partitions = setupPartitions();
assertTrue("No Partitions found.", partitions.length > 0);
ArrayList holdStyleResults = new ArrayList();
applyStyles(provider, partitions, holdStyleResults);
assertFalse("No styles applied.", holdStyleResults.isEmpty());
assertEquals("Unexpected StyleRange size", 241, holdStyleResults.size());
}
use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.
the class TestXSLLineStyleProvider method setupPartitions.
private ITypedRegion[] setupPartitions() throws BadLocationException {
int startOffset = document.getFirstStructuredDocumentRegion().getStartOffset();
int endLineLength = document.getLength();
IRegion styleRegion = getDocumentRangeFromWidgetRange(startOffset, endLineLength);
ITypedRegion[] partitions = TextUtilities.computePartitioning(document, Partitioning, styleRegion.getOffset(), styleRegion.getLength(), false);
return partitions;
}
use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.
the class XSLBreakpointProvider method getValidPosition.
private int getValidPosition(IDocument idoc, int editorLineNumber) {
int result = -1;
if (idoc != null) {
int startOffset = 0;
int endOffset = 0;
try {
IRegion line = idoc.getLineInformation(editorLineNumber - 1);
startOffset = line.getOffset();
endOffset = Math.max(line.getOffset(), line.getOffset() + line.getLength());
String lineText = idoc.get(startOffset, endOffset - startOffset).trim();
// blank lines or PI's cannot have breakpoints
if (// $NON-NLS-1$ //$NON-NLS-2$
lineText.trim().equals("") || lineText.startsWith("<?")) {
result = -1;
} else {
// get all partitions for current line
ITypedRegion[] partitions = null;
partitions = idoc.computePartitioning(startOffset, endOffset - startOffset);
for (int i = 0; i < partitions.length; ++i) {
// String type = partitions[i].getType();
result = partitions[i].getOffset();
}
}
} catch (BadLocationException e) {
result = -1;
}
}
return result;
}
Aggregations