本文整理汇总了Java中org.eclipse.jface.text.TextUtilities.computePartitioning方法的典型用法代码示例。如果您正苦于以下问题:Java TextUtilities.computePartitioning方法的具体用法?Java TextUtilities.computePartitioning怎么用?Java TextUtilities.computePartitioning使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jface.text.TextUtilities
的用法示例。
在下文中一共展示了TextUtilities.computePartitioning方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: recordSlavePartitionsText
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
/**
* Records the text of partitions for which we have a slave formatting
* strategy.
*/
private void recordSlavePartitionsText() {
try {
ITypedRegion[] partitions = TextUtilities.computePartitioning(
tempDocument, partitioning, 0, tempDocument.getLength(), false);
savedPartitionText = new String[partitions.length];
for (int i = 0; i < savedPartitionText.length; i++) {
if (!isSlaveContentType(partitions[i].getType())) {
continue;
}
savedPartitionText[i] = tempDocument.get(partitions[i].getOffset(),
partitions[i].getLength());
}
} catch (BadLocationException e) {
// This will never happen, according to super.formatSlaves
}
}
示例2: replaceSlavePartitionsWithDummyText
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
private void replaceSlavePartitionsWithDummyText() {
try {
ITypedRegion[] partitions = TextUtilities.computePartitioning(
tempDocument, partitioning, 0, tempDocument.getLength(), false);
for (int i = 0; i < partitions.length; i++) {
if (!isSlaveContentType(partitions[i].getType())) {
continue;
}
// Ideally, we'd like to use whitespace as the dummy text, but it may
// cause the partition to be lost by the master formatter. Instead this
// uses periods.
tempDocument.replace(partitions[i].getOffset(),
partitions[i].getLength(), StringUtilities.repeatCharacter('.',
partitions[i].getLength()));
}
} catch (BadLocationException e) {
// This should not happen according to super class
}
}
示例3: getPartition
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
/**
* Finds the partition containing the given offset.
*
* @param document the document to search
* @param offset the offset used to find a matching partition
* @return the partition, or null
*/
public static ITypedRegion getPartition(IStructuredDocument document, int offset) {
ITypedRegion[] partitions;
try {
partitions = TextUtilities.computePartitioning(document,
IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING, 0,
document.getLength(), true);
} catch (BadLocationException e) {
CorePluginLog.logError(e, "Unexpected bad location exception.");
return null;
}
for (ITypedRegion partition : partitions) {
if (partition.getOffset() <= offset
&& offset < partition.getOffset() + partition.getLength()) {
return partition;
}
}
return null;
}
示例4: getJsniMethods
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
public static String[] getJsniMethods(IDocument document) {
try {
List<String> jsniMethods = new LinkedList<String>();
ITypedRegion[] regions = TextUtilities.computePartitioning(document,
GWTPartitions.GWT_PARTITIONING, 0, document.getLength(), false);
// Format all JSNI blocks in the document
for (ITypedRegion region : regions) {
if (region.getType().equals(GWTPartitions.JSNI_METHOD)) {
String jsni = document.get(region.getOffset(), region.getLength());
jsniMethods.add(jsni);
}
}
return jsniMethods.toArray(new String[0]);
} catch (BadLocationException e) {
GWTPluginLog.logError(e);
return null;
}
}
示例5: computeFoldingStructure
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
private void computeFoldingStructure(final FoldingStructureComputationContext ctx) {
try {
IDocument doc = ctx.getDocument();
ITypedRegion[] partitions = TextUtilities.computePartitioning(doc, Partitions.MK_PARTITIONING, 0,
doc.getLength(), false);
computeBlockFoldingStructure(partitions, ctx);
} catch (BadLocationException e) {}
}
示例6: computePartitioning
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
protected ITypedRegion[] computePartitioning(int offset, int length, String partitionType) {
ITypedRegion[] result = new ITypedRegion[0];
ITypedRegion[] allRegions = new ITypedRegion[0];
try {
allRegions = TextUtilities.computePartitioning(getDocument(), partitionType, offset, length, false);
} catch (BadLocationException x) {
}
for (int i = 0; i < allRegions.length; i++) {
if (shouldProcess(allRegions[i])) {
result = concat(result, allRegions[i]);
}
}
return result;
}
示例7: format
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
/**
* Returns a text edit that formats the given document according to the given
* settings.
*
* @param document The document to format.
* @param javaFormattingPrefs The formatting preferences for Java, used to
* determine the method level indentation.
* @param javaScriptFormattingPrefs The formatting preferences for JavaScript.
* See org.eclipse.wst.jsdt.internal.formatter
* .DefaultCodeFormatterOptions and
* org.eclipse.wst.jsdt.core.formatter.DefaultCodeFormatterConstants
* @param originalJsniMethods The original jsni methods to use if the
* formatter fails to format the method. The original jsni Strings
* must be in the same order that the jsni methods occur in the
* document. This is to work around the Java formatter blasting the
* jsni tabbing for the format-on-save action. May be null.
* @return A text edit that when applied to the document, will format the jsni
* methods.
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public static TextEdit format(IDocument document, Map javaFormattingPrefs,
Map javaScriptFormattingPrefs, String[] originalJsniMethods) {
TextEdit combinedEdit = new MultiTextEdit();
try {
ITypedRegion[] regions = TextUtilities.computePartitioning(document,
GWTPartitions.GWT_PARTITIONING, 0, document.getLength(), false);
// Format all JSNI blocks in the document
int i = 0;
for (ITypedRegion region : regions) {
if (region.getType().equals(GWTPartitions.JSNI_METHOD)) {
String originalJsniMethod = null;
if (originalJsniMethods != null && i < originalJsniMethods.length) {
originalJsniMethod = originalJsniMethods[i];
}
TextEdit edit = format(document, new TypedPosition(region),
javaFormattingPrefs, javaScriptFormattingPrefs,
originalJsniMethod);
if (edit != null) {
combinedEdit.addChild(edit);
}
i++;
}
}
return combinedEdit;
} catch (BadLocationException e) {
GWTPluginLog.logError(e);
return null;
}
}
示例8: check
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
@Override
protected void check(IDocument document, IRegion[] regions,
ISpellChecker checker, ISpellingProblemCollector collector,
IProgressMonitor monitor) {
try {
List<IRegion> regionList = new ArrayList<IRegion>();
for (int i = 0; i < regions.length; i++) {
IRegion region = regions[i];
// Compute the GWT partitioning so we can identify JSNI blocks
ITypedRegion[] partitions = TextUtilities.computePartitioning(
document, GWTPartitions.GWT_PARTITIONING, region.getOffset(),
region.getLength(), false);
// Spelling engine should ignore all JSNI block regions
for (int j = 0; j < partitions.length; j++) {
ITypedRegion partition = partitions[j];
if (!GWTPartitions.JSNI_METHOD.equals(partition.getType())) {
regionList.add(partition);
}
}
}
super.check(document,
regionList.toArray(new IRegion[regionList.size()]), checker,
collector, monitor);
} catch (BadLocationException e) {
// Ignore: the document has been changed in another thread and will be
// checked again (our super class JavaSpellingEngine does the same).
}
}
示例9: computePartitioning
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
protected ITypedRegion[] computePartitioning(int offset, int length)
{
ITypedRegion[] regions = null;
try
{
regions = TextUtilities
.computePartitioning(getDocument(), getDocumentPartitioning(), offset, length, false);
}
catch (BadLocationException x)
{
regions = new TypedRegion[0];
}
return regions;
}
示例10: computePartitioning
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
/**
* Computes and returns the partitioning for the given region of the input document
* of the reconciler's connected text viewer.
*
* @param offset the region offset
* @param length the region length
* @return the computed partitioning
* @since 3.0
*/
private ITypedRegion[] computePartitioning(int offset, int length)
{
ITypedRegion[] regions = null;
try
{
regions = TextUtilities.computePartitioning(getDocument(), getDocumentPartitioning(), offset, length, false);
} catch (BadLocationException x)
{
regions = new TypedRegion[0];
}
return regions;
}
示例11: formatSlaves
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
@Override
protected void formatSlaves(IFormattingContext context, IDocument document,
int offset, int length) {
try {
if (masterFormatterHadError) {
// Do not proceed if the master formatter had an error
return;
}
// Revert any master changes of partitions for which we have a slave
// formatting strategy
try {
ITypedRegion[] partitions = TextUtilities.computePartitioning(
tempDocument, partitioning, 0, tempDocument.getLength(), false);
if (partitions.length == savedPartitionText.length) {
for (int i = 0; i < savedPartitionText.length; i++) {
if (savedPartitionText[i] == null) {
continue;
}
tempDocument.replace(partitions[i].getOffset(),
partitions[i].getLength(), savedPartitionText[i]);
if (partitions[i].getLength() != savedPartitionText[i].length()) {
// Recompute partitions since our replacement affects subsequent
// offsets
partitions = TextUtilities.computePartitioning(tempDocument,
partitioning, 0, tempDocument.getLength(), false);
}
}
}
} catch (BadLocationException e) {
// This will never happen, according to super.formatSlaves
}
if (length > tempDocument.getLength()) {
// Safeguard against the master formatter shortening the document
length = tempDocument.getLength();
}
// Ensure the superclass works off the temp document
setToTempDocument(context);
super.formatSlaves(context, tempDocument, offset, length);
String tempText = tempDocument.get();
if (!tempText.equals(premasterDocumentText)) {
if (!checkForNonwhitespaceChanges
|| StringUtilities.equalsIgnoreWhitespace(tempText,
premasterDocumentText, true)) {
// Replace the text since it is different than what we started the
// with
document.set(tempText);
} else {
CorePluginLog.logWarning("Not applying formatting since it would cause non-whitespace changes.");
}
}
} finally {
/*
* This will always be called. The super.format method tries calling
* formatMaster, and in a finally block calls formatSlaves. We try-finally
* on entry into formatSlaves.
*/
documentCloner.release(tempDocument);
}
}
示例12: run
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
public void run(IAction action) {
if (targetEditor == null) {
GWTPluginLog.logWarning("targetEditor is null");
return;
}
IEditorInput editorInput = targetEditor.getEditorInput();
IResource resource = (IResource) editorInput.getAdapter(IResource.class);
ITextEditor javaEditor = (ITextEditor) targetEditor;
ITextSelection sel = (ITextSelection) javaEditor.getSelectionProvider().getSelection();
IDocument document = javaEditor.getDocumentProvider().getDocument(
javaEditor.getEditorInput());
IDocumentExtension3 document3 = (IDocumentExtension3) document;
IDocumentPartitioner gwtPartitioner = document3.getDocumentPartitioner(GWTPartitions.GWT_PARTITIONING);
String[] partitionings = document3.getPartitionings();
String partitioning = (gwtPartitioner != null
? GWTPartitions.GWT_PARTITIONING : IJavaPartitions.JAVA_PARTITIONING);
ITypedRegion[] types;
try {
types = TextUtilities.computePartitioning(document, partitioning,
sel.getOffset(), sel.getLength(), false);
} catch (BadLocationException e) {
GWTPluginLog.logError(e);
return;
}
String msg = "File: " + resource.getName();
msg += "\nPartitionings: ";
for (String part : partitionings) {
msg += "\n" + part;
}
msg += "\n\nContent types: ";
for (ITypedRegion type : types) {
msg += "\n" + type.getType();
}
msg += "\n\nSelection range: (offset = " + sel.getOffset() + ", length = "
+ sel.getLength() + ")";
MessageDialog.openInformation(targetEditor.getSite().getShell(),
"Selection Info", msg);
}
示例13: createPresentation
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
protected TextPresentation createPresentation(IRegion damage, IDocument document, IProgressMonitor monitor)
{
try
{
int damageOffset = damage.getOffset();
int damageLength = damage.getLength();
if (damageOffset + damageLength > document.getLength())
{
int adjustedLength = document.getLength() - damageOffset;
synchronized (this)
{
delayedRegions.remove(new Region(document.getLength(), damageLength - adjustedLength));
}
if (adjustedLength <= 0)
{
return null;
}
damageLength = adjustedLength;
}
TextPresentation presentation = new TextPresentation(damage, iterationPartitionLimit * 5);
ITypedRegion[] partitioning = TextUtilities.computePartitioning(document, getDocumentPartitioning(),
damageOffset, damageLength, false);
if (partitioning.length == 0)
{
return presentation;
}
int limit = Math.min(iterationPartitionLimit, partitioning.length);
int processingLength = partitioning[limit - 1].getOffset() + partitioning[limit - 1].getLength()
- damageOffset;
if (EclipseUtil.showSystemJobs())
{
monitor.subTask(MessageFormat.format(
"processing region at offset {0}, length {1} in document of length {2}", damageOffset, //$NON-NLS-1$
processingLength, document.getLength()));
}
for (int i = 0; i < limit; ++i)
{
ITypedRegion r = partitioning[i];
IPresentationRepairer repairer = getRepairer(r.getType());
if (monitor.isCanceled())
{
return null;
}
if (repairer != null)
{
repairer.createPresentation(presentation, r);
}
monitor.worked(r.getLength());
}
synchronized (this)
{
delayedRegions.remove(new Region(damageOffset, processingLength));
if (limit < partitioning.length)
{
int offset = partitioning[limit].getOffset();
delayedRegions.append(new Region(offset, damageOffset + damageLength - offset));
}
}
return presentation;
}
catch (BadLocationException e)
{
return null;
}
}
示例14: applyStyles
import org.eclipse.jface.text.TextUtilities; //导入方法依赖的package包/类
/**
* Color the text in the sample area according to the current preferences
*/
void applyStyles( )
{
if ( fText == null || fText.isDisposed( ) )
return;
try
{
ITypedRegion[] regions = TextUtilities.computePartitioning( fDocument,
IDocumentExtension3.DEFAULT_PARTITIONING,
0,
fDocument.getLength( ),
true );
if ( regions.length > 0 )
{
for ( int i = 0; i < regions.length; i++ )
{
ITypedRegion region = regions[i];
String namedStyle = (String) fContextToStyleMap.get( region.getType( ) );
if ( namedStyle == null )
continue;
TextAttribute attribute = getAttributeFor( namedStyle );
if ( attribute == null )
continue;
int fontStyle = attribute.getStyle( )
& ( SWT.ITALIC | SWT.BOLD | SWT.NORMAL );
StyleRange style = new StyleRange( region.getOffset( ),
region.getLength( ),
attribute.getForeground( ),
attribute.getBackground( ),
fontStyle );
style.strikeout = ( attribute.getStyle( ) & TextAttribute.STRIKETHROUGH ) != 0;
style.underline = ( attribute.getStyle( ) & TextAttribute.UNDERLINE ) != 0;
style.font = attribute.getFont( );
fText.setStyleRange( style );
}
}
}
catch ( BadLocationException e )
{
ExceptionHandler.handle( e );
}
}