Java Code Examples for org.eclipse.jface.text.TypedPosition#getType()

The following examples show how to use org.eclipse.jface.text.TypedPosition#getType() . 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: DocumentPartitioner.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * May be replaced or extended by subclasses.
 * </p>
 * 
 * @since 2.2
 */
@Override
public synchronized String getContentType(int offset) {
	checkInitialization();

	TypedPosition p = findClosestPosition(offset);
	if (p != null && p.includes(offset))
		return p.getType();

	return IDocument.DEFAULT_CONTENT_TYPE;
}
 
Example 2
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 String getContentType(int offset) {
    checkInitialization();

    TypedPosition p= findClosestPosition(offset);
    if (p != null && p.includes(offset))
        return p.getType();

    return IDocument.DEFAULT_CONTENT_TYPE;
}
 
Example 3
Source File: CompositePartitionScanner.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setPartialRange(IDocument document, int offset, int length, String contentType, int partitionOffset) {
	defaultTokenState = null;
	hasResume = false;
	resetRules(defaultPartitionScanner.getRules());
	resetRules(primaryPartitionScanner.getRules());
	currentPartitionScanner = defaultPartitionScanner;
	currentPartitionScanner.setLastToken(new Token(contentType));
	if (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) && partitioner != null) {
		TypedPosition partition = partitioner.findClosestPosition(offset);
		if (partition != null) {
			if (partition.overlapsWith(offset, length)) {
				partition = partitioner.findClosestPosition(offset - 1);
			}
		}
		if (partition != null) {
			String type = partition.getType();
			if (primaryPartitionScanner.hasContentType(type)) {
				currentPartitionScanner = primaryPartitionScanner;
			} else if (START_SWITCH_TAG.equals(type)) {
				hasSwitch = true;
			}
			currentPartitionScanner.setLastToken(new Token(type));
		}
	} else if (primaryPartitionScanner.hasContentType(contentType)) {
		currentPartitionScanner = primaryPartitionScanner;
	}
	super.setPartialRange(document, offset, length, contentType, partitionOffset);
}
 
Example 4
Source File: FastPartitioner.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * May be replaced or extended by subclasses.
 * </p>
 */
@Override
public String getContentType(int offset) {
    checkInitialization();

    TypedPosition p = findClosestPosition(offset);
    if (p != null && p.includes(offset)) {
        return p.getType();
    }

    return IDocument.DEFAULT_CONTENT_TYPE;
}
 
Example 5
Source File: DocumentScopeManager.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private String getTokenScopeFragments(ITextViewer viewer, IDocument document, int offset)
{
	if (!(viewer instanceof ISourceViewer))
	{
		return null;
	}

	try
	{
		// Force adding the category in case it doesn't exist yet...
		document.addPositionCategory(ICommonConstants.SCOPE_CATEGORY);
		Position[] scopes = document.getPositions(ICommonConstants.SCOPE_CATEGORY);
		int index = document.computeIndexInCategory(ICommonConstants.SCOPE_CATEGORY, offset);

		if (scopes == null || scopes.length == 0)
		{
			return null;
		}
		if (index >= scopes.length)
		{
			index = scopes.length - 1;
		}
		Position scope = scopes[index];
		if (scope == null)
		{
			return null;
		}
		if (!scope.includes(offset))
		{
			if (index > 0)
			{
				scope = scopes[--index];
				if (scope == null || !scope.includes(offset))
				{
					return null;
				}
			}
			else
			{
				return null;
			}
		}
		if (scope instanceof TypedPosition)
		{
			TypedPosition pos = (TypedPosition) scope;
			return pos.getType();
		}
	}
	catch (Exception e)
	{
		IdeLog.logError(CommonEditorPlugin.getDefault(), e);
	}
	return null;
}