Java Code Examples for org.eclipse.jface.text.rules.IToken#getData()

The following examples show how to use org.eclipse.jface.text.rules.IToken#getData() . 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: TagStyleConfigurator.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public static void configure(TextLayout textLayout) {
	String text = textLayout.getText();
	Document doc = new Document(text);
	ITokenScanner scanner = getRecipeScanner(doc);
	scanner.setRange(doc, 0, doc.getLength());
	IToken token;
	while ((token = scanner.nextToken()) != Token.EOF) {
		int offset = scanner.getTokenOffset();
		int length = scanner.getTokenLength();
		Object data = token.getData();
		if (data != null && data instanceof TextStyle) {
			TextStyle textStyle = (TextStyle) data;
			textLayout.setStyle(textStyle, offset, offset + length - 1);
		}
	}
	scanner = null;
	doc = null;
}
 
Example 2
Source File: TagStyleConfigurator.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public static void configure(TextLayout textLayout) {
	String text = textLayout.getText();
	Document doc = new Document(text);
	ITokenScanner scanner = getRecipeScanner(doc);
	scanner.setRange(doc, 0, doc.getLength());
	IToken token;
	while ((token = scanner.nextToken()) != Token.EOF) {
		int offset = scanner.getTokenOffset();
		int length = scanner.getTokenLength();
		Object data = token.getData();
		if (data != null && data instanceof TextStyle) {
			TextStyle textStyle = (TextStyle) data;
			textLayout.setStyle(textStyle, offset, offset + length - 1);
		}
	}
	scanner = null;
	doc = null;
}
 
Example 3
Source File: TagStyleConfigurator.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public static void configure(TextLayout textLayout) {
	String text = textLayout.getText();
	Document doc = new Document(text);
	ITokenScanner scanner = getRecipeScanner(doc);
	scanner.setRange(doc, 0, doc.getLength());
	IToken token;
	while ((token = scanner.nextToken()) != Token.EOF) {
		int offset = scanner.getTokenOffset();
		int length = scanner.getTokenLength();
		Object data = token.getData();
		if (data != null && data instanceof TextStyle) {
			TextStyle textStyle = (TextStyle) data;
			textLayout.setStyle(textStyle, offset, offset + length - 1);
		}
	}
}
 
Example 4
Source File: CompositeTokenScanner.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public IToken nextToken()
{
	IToken token = fPrimaryTokenScanner.nextToken();
	Object data = token.getData();

	if (data != null)
	{
		if (fCurrentIndex == DEFAULT_INDEX)
		{
			fCurrentIndex = getScannerIndex(data.toString());
		}
		else
		{
			if (hasExitToken(data.toString()))
			{
				// exits out to the top level
				resetIndex();
			}
		}
	}
	return token;
}
 
Example 5
Source File: TagStyleConfigurator.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public static void configure(TextLayout textLayout) {
	String text = textLayout.getText();
	Document doc = new Document(text);
	ITokenScanner scanner = getRecipeScanner(doc);
	scanner.setRange(doc, 0, doc.getLength());
	IToken token;
	while ((token = scanner.nextToken()) != Token.EOF) {
		int offset = scanner.getTokenOffset();
		int length = scanner.getTokenLength();
		Object data = token.getData();
		if (data != null && data instanceof TextStyle) {
			TextStyle textStyle = (TextStyle) data;
			textLayout.setStyle(textStyle, offset, offset + length - 1);
		}
	}
}
 
Example 6
Source File: HTMLParserScanner.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Symbol createSymbol(int start, int end, String text, IToken token)
{
	short type = HTMLTokens.EOF;
	Object data = token.getData();
	if (data != null)
	{
		type = ((HTMLScanner) getTokenScanner()).getTokenType(data);
	}
	return new Symbol(type, start, end, text);
}
 
Example 7
Source File: HTMLParserScanner.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean isIgnored(IToken token)
{
	if (super.isIgnored(token))
	{
		return true;
	}
	Object data = token.getData();
	if (data == null)
	{
		return false;
	}
	// ignores doctype declaration
	return data.equals(HTMLTokens.getTokenName(HTMLTokens.DOCTYPE));
}
 
Example 8
Source File: XMLSubPartitionScanner.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setLastToken(IToken token) {
	super.setLastToken(token);
	if (token == null) {
		return;
	}
	if (!(token.getData() instanceof String)) {
		current = TYPE_DEFAULT;
		return;
	}

	String contentType = (String) token.getData();

	if (XMLSourceConfiguration.DOCTYPE.equals(contentType)) {
		if (token instanceof ExtendedToken && ((ExtendedToken) token).getContents().endsWith("[")) { //$NON-NLS-1$
			current = TYPE_DTD;
			resumeToken = token;
			super.setLastToken(null);
		}
	} else if (XMLSourceConfiguration.DEFAULT.equals(contentType) || IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) {
		current = TYPE_DEFAULT;
	} else {
		for (int i = 0; i < subPartitionScanners.length; ++i) {
			if (subPartitionScanners[i].hasContentType(contentType)) {
				current = i;
				break;
			}
		}
	}
}
 
Example 9
Source File: SVGSubPartitionerScanner.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setLastToken(IToken token) {
	super.setLastToken(token);
	if (token == null) {
		return;
	}
	if (!(token.getData() instanceof String)) {
		current = TYPE_DEFAULT;
		return;
	}

	String contentType = (String) token.getData();

	if (SVGSourceConfiguration.SCRIPT.equals(contentType)) {
		current = TYPE_JS;
		super.setLastToken(null);
	} else if (SVGSourceConfiguration.STYLE.equals(contentType)) {
		current = TYPE_CSS;
		super.setLastToken(null);
	} else if (SVGSourceConfiguration.DEFAULT.equals(contentType) || IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) {
		current = TYPE_DEFAULT;
	} else {
		for (int i = 0; i < subPartitionScanners.length; ++i) {
			if (subPartitionScanners[i].hasContentType(contentType)) {
				current = i;
				break;
			}
		}
	}
}
 
Example 10
Source File: CompositePartitionScanner.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public IToken nextToken() {
  IToken token = javaScanner.nextToken();
  Object data = token.getData();
  if (JAVA_MULTI_LINE_COMMENT.equals(data)) {
    jsniScanner.setRange(document, javaScanner.getTokenOffset(),
        javaScanner.getTokenLength());
    IToken jsniToken = jsniScanner.nextToken();
    if (jsniToken.getData() != null) {
      return jsniToken;
    }
  }
  return token;
}
 
Example 11
Source File: DTDScanner.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * getToken
 * 
 * @return
 */
protected IToken getToken()
{
	IToken token = null;

	while (this._nestedScanners.size() > 0)
	{
		DTDParserScanner nestedScanner = this._nestedScanners.peek();

		token = nestedScanner.nextToken();

		if (token.isWhitespace() == false && token.getData() == null)
		{
			this._nestedScanners.pop();
			token = null;

			if (Platform.inDevelopmentMode())
			{
				int end = nestedScanner.getTokenOffset() + nestedScanner.getTokenLength();
				int length = nestedScanner.getDocument().getLength();

				if (end != length)
				{
					System.out.println("end = " + end + ", length = " + length); //$NON-NLS-1$ //$NON-NLS-2$
					System.out.println(nestedScanner.getDocument().get());
				}
			}
		}
		else
		{
			break;
		}
	}

	if (token == null)
	{
		token = this._sourceScanner.nextToken();
	}

	return token;
}
 
Example 12
Source File: CSSTokenScanner.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
@Override
public IToken nextToken()
{
	IToken token = super.nextToken();
	Object data = token.getData();

	if (data instanceof CSSTokenType)
	{
		switch ((CSSTokenType) data)
		{
			case MEDIA_KEYWORD:
				this._inMediaRule = true;
				break;

			case LCURLY:
				this._curlyBraceCount++;
				break;

			case RCURLY:
				this._curlyBraceCount--;

				if (this._curlyBraceCount == 0 && this._inMediaRule)
				{
					this._inMediaRule = false;
				}
				break;

			case RGB:
				// fixup colors in selectors
				if (isOutsideRule())
				{
					token = createToken(CSSTokenType.ID);
				}
				break;

			case CLASS:
				// potentially fixup a class inside of a ruleset to be a number
				if (!isOutsideRule())
				{
					try
					{
						String text = fDocument.get(getTokenOffset(), getTokenLength());

						if (CLASS_IS_NUMBER_PATTERN.matcher(text).matches())
						{
							token = createToken(CSSTokenType.NUMBER);
						}
					}
					catch (BadLocationException e)
					{
						// ignore
					}
				}
				break;
		}
	}

	return token;
}
 
Example 13
Source File: HTMLSubPartitionScanner.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setLastToken(IToken token)
{
	super.setLastToken(token);
	if (token == null)
	{
		return;
	}

	Object data = token.getData();
	if (!(data instanceof String))
	{
		current = TYPE_DEFAULT;
		return;
	}

	String contentType = (String) data;

	if (HTMLSourceConfiguration.HTML_SCRIPT.equals(contentType)
			|| SVGSourceConfiguration.SCRIPT.equals(contentType))
	{
		if (!(token instanceof ExtendedToken && ((HTMLUtils.isTagSelfClosing(((ExtendedToken) token).getContents())) || !HTMLUtils
				.isJavaScriptTag(((ExtendedToken) token).getContents()))))
		{
			current = TYPE_JS;
			super.setLastToken(null);
		}
	}
	else if (HTMLSourceConfiguration.HTML_STYLE.equals(contentType)
			|| SVGSourceConfiguration.STYLE.equals(contentType))
	{
		if (!(token instanceof ExtendedToken && (HTMLUtils.isTagSelfClosing(((ExtendedToken) token).getContents()) || !HTMLUtils
				.isTagComplete(((ExtendedToken) token).getContents()))))
		{
			current = TYPE_CSS;
			super.setLastToken(null);
		}
	}
	else if (HTMLSourceConfiguration.HTML_SVG.equals(contentType))
	{
		if (!(token instanceof ExtendedToken && HTMLUtils.isTagSelfClosing(((ExtendedToken) token).getContents()) || !HTMLUtils
				.isTagComplete(((ExtendedToken) token).getContents())))
		{
			current = TYPE_SVG;
			super.setLastToken(null);
		}
	}
	else if (HTMLSourceConfiguration.DEFAULT.equals(contentType)
			|| IDocument.DEFAULT_CONTENT_TYPE.equals(contentType))
	{
		current = TYPE_DEFAULT;
	}
	else
	{
		for (int i = 0; i < subPartitionScanners.length; ++i)
		{
			if (subPartitionScanners[i].hasContentType(contentType))
			{
				current = i;
				break;
			}
		}
	}
}
 
Example 14
Source File: TMPresentationReconciler.java    From tm4e with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Returns a text attribute encoded in the given token. If the token's data is
 * not <code>null</code> and a text attribute it is assumed that it is the
 * encoded text attribute. It returns the default text attribute if there is no
 * encoded text attribute found.
 *
 * @param token
 *            the token whose text attribute is to be determined
 * @return the token's text attribute
 */
protected TextAttribute getTokenTextAttribute(IToken token) {
	Object data = token.getData();
	if (data instanceof TextAttribute) {
		return (TextAttribute) data;
	}
	return fDefaultTextAttribute;
}
 
Example 15
Source File: PresentationRepairer.java    From tmxeditor8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a text style encoded in the given token. If the token's data is not <code>null</code> and a text style it
 * is assumed that it is the encoded text style. It returns the default text style if there is no encoded text style
 * found.
 * @param token
 *            the token whose text style is to be determined
 * @return the token's text style
 */
protected TextStyle getTokenTextStyle(IToken token) {
	Object data = token.getData();
	if (data instanceof TextStyle)
		return (TextStyle) data;
	return fDefaultTextStyle;
}
 
Example 16
Source File: PresentationRepairer.java    From tmxeditor8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a text style encoded in the given token. If the token's data is not <code>null</code> and a text style it
 * is assumed that it is the encoded text style. It returns the default text style if there is no encoded text style
 * found.
 * @param token
 *            the token whose text style is to be determined
 * @return the token's text style
 */
protected TextStyle getTokenTextStyle(IToken token) {
	Object data = token.getData();
	if (data instanceof TextStyle)
		return (TextStyle) data;
	return fDefaultTextStyle;
}
 
Example 17
Source File: DamageRepairer.java    From LogViewer with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Returns a text attribute encoded in the given token. If the token's
 * data is not <code>null</code> and a text attribute it is assumed that
 * it is the encoded text attribute. It returns the default text attribute
 * if there is no encoded text attribute found.
 *
 * @param token the token whose text attribute is to be determined
 * @return the token's text attribute
 */
private TextAttribute getTokenTextAttribute(IToken token) {
    Object data= token.getData();
    if(data instanceof TokenData) {
        return ((TokenData)data).getTextAttribute();
    }
    return defaultTextAttribute;
}
 
Example 18
Source File: PresentationRepairer.java    From translationstudio8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a text style encoded in the given token. If the token's data is not <code>null</code> and a text style it
 * is assumed that it is the encoded text style. It returns the default text style if there is no encoded text style
 * found.
 * @param token
 *            the token whose text style is to be determined
 * @return the token's text style
 */
protected TextStyle getTokenTextStyle(IToken token) {
	Object data = token.getData();
	if (data instanceof TextStyle)
		return (TextStyle) data;
	return fDefaultTextStyle;
}
 
Example 19
Source File: TLAFastPartitioner.java    From tlaplus with MIT License 3 votes vote down vote up
/**
 * Returns a content type encoded in the given token. If the token's
 * data is not <code>null</code> and a string it is assumed that
 * it is the encoded content type.
 * <p>
 * May be replaced or extended by subclasses.
 * </p>
 *
 * @param token the token whose content type is to be determined
 * @return the token's content type
 */
protected String getTokenContentType(IToken token) {
    Object data= token.getData();
    if (data instanceof String)
        return (String) data;
    return null;
}
 
Example 20
Source File: PresentationRepairer.java    From translationstudio8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns a text style encoded in the given token. If the token's data is not <code>null</code> and a text style it
 * is assumed that it is the encoded text style. It returns the default text style if there is no encoded text style
 * found.
 * @param token
 *            the token whose text style is to be determined
 * @return the token's text style
 */
protected TextStyle getTokenTextStyle(IToken token) {
	Object data = token.getData();
	if (data instanceof TextStyle)
		return (TextStyle) data;
	return fDefaultTextStyle;
}