org.eclipse.jface.text.TypedRegion Java Examples

The following examples show how to use org.eclipse.jface.text.TypedRegion. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PyPartitioner.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public ITypedRegion getPartition(int offset, boolean preferOpenPartitions) {
    if (preferOpenPartitions) {
        if (offset <= 0) {
            return new TypedRegion(offset, 0, IDocument.DEFAULT_CONTENT_TYPE);
        }
        if (fDocument != null && offset == fDocument.getLength()) {
            // Fix issue where a wrong partition is being gotten when a comment is being typed
            // as the last thing in the document.
            // Fixes #PyDev-762: Code completion is active in comments.
            try {
                int lineOffset = fDocument.getLineOffset(fDocument.getLineOfOffset(offset));
                if (lineOffset != offset) { // A comment must start with a #, so, the char 0 of a line can't be a comment itself.
                    ITypedRegion region = getPartition(offset - 1);
                    if (IPythonPartitions.PY_COMMENT.equals(region.getType())
                            || IDocument.DEFAULT_CONTENT_TYPE.equals(region.getType())) {
                        return region;
                    }
                }
            } catch (BadLocationException e) {
                // ignore
            }
        }
    }
    return super.getPartition(offset, preferOpenPartitions);
}
 
Example #2
Source File: FastPartitioner.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * May be replaced or extended by subclasses.
 * </p>
 */
@Override
public ITypedRegion getPartition(int offset, boolean preferOpenPartitions) {
    ITypedRegion region = getPartition(offset);
    if (preferOpenPartitions) {
        if (region.getOffset() == offset && !region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE)) {
            if (offset > 0) {
                region = getPartition(offset - 1);
                if (region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE)) {
                    return region;
                }
            }
            return new TypedRegion(offset, 0, IDocument.DEFAULT_CONTENT_TYPE);
        }
    }
    return region;
}
 
Example #3
Source File: DocumentPartitioner.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * May be replaced or extended by subclasses.
 * </p>
 * 
 * @since 2.2
 */
@Override
public synchronized ITypedRegion getPartition(int offset, boolean preferOpenPartitions) {
	ITypedRegion region = getPartition(offset);
	if (preferOpenPartitions) {
		if (region.getOffset() == offset && !region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE)) {
			if (offset > 0) {
				region = getPartition(offset - 1);
				if (region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE))
					return region;
			}
			return new TypedRegion(offset, 0, IDocument.DEFAULT_CONTENT_TYPE);
		}
	}
	return region;
}
 
Example #4
Source File: TaskHighlightingTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void addPosition(int offset, int length, String... id) {
	Assert.assertEquals(1, id.length);
	TypedRegion region = new TypedRegion(offset, length, id[0]);
	Assert.assertFalse(region.toString(), expectedRegions.isEmpty());
	Assert.assertTrue("expected: " + expectedRegions.toString() + " but was: " + region, expectedRegions.remove(region));
}
 
Example #5
Source File: MultiRegionSpellingReconcileStrategy.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source File: CommonReconciler.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #7
Source File: TagBasedTLCAnalyzer.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * @return
 */
public ITypedRegion getUserRegion()
{
    if (hasUserPartitions())
    {
        ITypedRegion region = PartitionToolkit.mergePartitions((ITypedRegion[]) userOutput
                .toArray(new TypedRegion[userOutput.size()]));
        // re-initialize the user partitions
        resetUserPartitions();
        return region;
    } else
    {
        return null;
    }
}
 
Example #8
Source File: TLAFastPartitioner.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * May be replaced or extended by subclasses.
 * </p>
 */
public ITypedRegion getPartition(int offset, boolean preferOpenPartitions) {
    ITypedRegion region= getPartition(offset);
    if (preferOpenPartitions) {
        if (region.getOffset() == offset && !region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE)) {
            if (offset > 0) {
                region= getPartition(offset - 1);
                if (region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE))
                    return region;
            }
            return new TypedRegion(offset, 0, IDocument.DEFAULT_CONTENT_TYPE);
        }
    }
    return region;
}
 
Example #9
Source File: TypedRegionMerger.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public ITypedRegion[] merge(ITypedRegion[] original) {
	if (original == null || original.length == 0)
		return original;
	ITypedRegion[] result = new ITypedRegion[original.length];
	String contentType = original[0].getType();
	result[0] = original[0];
	for(int i = 1; i < original.length; i++) {
		ITypedRegion copyMe = original[i];
		result[i] = new TypedRegion(copyMe.getOffset(), copyMe.getLength(), contentType);
	}
	return result;
}
 
Example #10
Source File: ImpexDocumentPartitioner.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public ITypedRegion getPartition(int arg0) {
	/*
	 * Never gets called because this class implements IDocumentPartitioner
	 * rather than IDocumentPartitionerExtension2 which is required for
	 * IDocumentExtension3
	 * Confused ?? Me too...
	 */
	return new TypedRegion(0, fDocument.getLength(), IMPEX_HEADER);
}
 
Example #11
Source File: SemanticHighlightingTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void addPosition(int offset, int length, String... id) {
	assertEquals(1, id.length);
	TypedRegion region = new TypedRegion(offset, length, id[0]);
	assertFalse(region.toString(), expectedRegions.isEmpty());
	assertTrue("expected: " + expectedRegions.toString() + " but was: " + region, expectedRegions.remove(region));
}
 
Example #12
Source File: ImpexDocumentPartitioner.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public ITypedRegion[] computePartitioning(int offset, int length) {
	/*
	 * Never gets called because this class implements IDocumentPartitioner
	 * rather than IDocumentPartitionerExtension2 which is required for
	 * IDocumentExtension3
	 * Confused ?? Me too...
	 */
	List<TypedRegion> list = new ArrayList<TypedRegion>();
	try {
		int start;
		int nextOffset;
		boolean isHeader = true;
		int docLength = fDocument.getLength();
		
		if (offset == 0) {
			nextOffset = getLineEndOffset(1, fDocument);
			list.add(new TypedRegion(0, nextOffset + 1, IMPEX_HEADER));
			
			int i = 1;
			while (nextOffset + 1 < docLength) {
				start = nextOffset+ 1;
				if (Character.isDigit(fDocument.getChar(start))) {
					isHeader = true;
				}
				else {
					isHeader = false;
				}
				
				nextOffset = getLineEndOffset(i + 1, fDocument);
				if (isHeader) {
					list.add(new TypedRegion(start, nextOffset - start + 1, IMPEX_INSTRUCTION));
				}
				else {
					list.add(new TypedRegion(start, nextOffset - start + 1, IMPEX_DATA));
				}
				i = i + 1;
			}
		}
		else {
			if (Character.isDigit(fDocument.getChar(offset))) {
				isHeader = true;
			}
			else {
				isHeader = false;
			}
			
			if (isHeader) {
				list.add(new TypedRegion(offset, length, IMPEX_HEADER));
			}
			else {
				list.add(new TypedRegion(offset, length, IMPEX_DATA));
			}
		}
		
	}
	catch (BadLocationException ble) {
		Activator.logError("BadLocationException", ble);
	}
	
	if (list.isEmpty()) {
		list.add(new TypedRegion(offset, length, null));
	}
	
	TypedRegion[] result = new TypedRegion[list.size()];
	list.toArray(result);
	return result;
}
 
Example #13
Source File: AbstractDamagerRepairerTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void documentChanged(DocumentEvent event) {
	lastRegion = damager.getDamageRegion(new TypedRegion(0,event.getDocument().getLength(), IDocument.DEFAULT_CONTENT_TYPE), event, false);
}
 
Example #14
Source File: AbstractDamagerRepairerTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void documentChanged(DocumentEvent event) {
	lastRegion = damager.getDamageRegion(new TypedRegion(0,event.getDocument().getLength(), IDocument.DEFAULT_CONTENT_TYPE), event, false);
}
 
Example #15
Source File: ParsingToolkitTest.java    From tlaplus with MIT License 4 votes vote down vote up
/**
 * Test method for {@link org.lamport.tla.toolbox.tool.tlc.output.ParsingTLCOutputSink#mergePartitions(org.eclipse.jface.text.ITypedRegion[])}.
 */
public void testMergePartitions()
{
    assertEquals(new TypedRegion(0, 100, "type"), PartitionToolkit.mergePartitions(new ITypedRegion[] {
            new TypedRegion(0, 10, "type"), new TypedRegion(10, 80, "type"), new TypedRegion(90, 10, "type") }));
}
 
Example #16
Source File: ParsingToolkitTest.java    From tlaplus with MIT License 4 votes vote down vote up
public void testMergePartitions2()
{
    assertEquals(new TypedRegion(0, 100, "type"), PartitionToolkit
            .mergePartitions(new ITypedRegion[] { new TypedRegion(0, 100, "type") }));
}
 
Example #17
Source File: SemanticHighlightingTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected void expect(int offset, int length, String type) {
	expectedRegions.add(new TypedRegion(offset, length, type));
}
 
Example #18
Source File: DamagerRepairerPerformanceTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void documentChanged(DocumentEvent event) {
	lastRegion = damager.getDamageRegion(new TypedRegion(0,event.getDocument().getLength(), IDocument.DEFAULT_CONTENT_TYPE), event, false);
}
 
Example #19
Source File: TaskHighlightingTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected boolean expect(int offset, int length, String type) {
	return expectedRegions.add(new TypedRegion(offset, length, type));
}
 
Example #20
Source File: ScriptConsolePartitioner.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public ITypedRegion[] computePartitioning(int offset, int length) {
    return new TypedRegion[] { new TypedRegion(offset, length, IDocument.DEFAULT_CONTENT_TYPE) };
}
 
Example #21
Source File: ScriptConsolePartitioner.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public ITypedRegion getPartition(int offset) {
    return new TypedRegion(offset, 1, IDocument.DEFAULT_CONTENT_TYPE);
}