Search in sources :

Example 56 with IToken

use of org.eclipse.jface.text.rules.IToken in project webtools.sourceediting by eclipse.

the class LineStyleProviderForJava method prepareRegions.

public boolean prepareRegions(ITypedRegion typedRegion, int ssssrequestedStart, int ssssrequestedLength, Collection holdResults) {
    boolean result = true;
    /* Initialize the text attributes. Also load the colors and initialize the rules of the scanner */
    getTextAttributes();
    try {
        // ideally, eventually, we'll have a "virtualDocument" we can
        // refer to, but for now ... we'll simple rescan the one region.
        // use simple adjustment (since "sub-content" starts at 0
        int lastStart = typedRegion.getOffset();
        int length = 0;
        IToken lastToken = Token.UNDEFINED;
        fScanner.setRange(getDocument(), lastStart, typedRegion.getLength());
        while (true) {
            IToken token = fScanner.nextToken();
            if (token.isEOF()) {
                if (!lastToken.isUndefined() && length != 0) {
                    addRange(holdResults, lastStart, length, getTokenTextAttribute(lastToken));
                }
                break;
            }
            if (token.isWhitespace()) {
                length += fScanner.getTokenLength();
                continue;
            }
            if (lastToken.isUndefined()) {
                lastToken = token;
                length += fScanner.getTokenLength();
                continue;
            }
            if (token != lastToken) {
                addRange(holdResults, lastStart, length, getTokenTextAttribute(lastToken));
                lastToken = token;
                lastStart = fScanner.getTokenOffset();
                length = fScanner.getTokenLength();
                continue;
            }
            length += fScanner.getTokenLength();
        }
    } catch (Exception e) {
        // shouldn't happen, but we don't want it to stop other
        // highlighting, if it does.
        result = false;
    }
    return result;
}
Also used : IToken(org.eclipse.jface.text.rules.IToken)

Example 57 with IToken

use of org.eclipse.jface.text.rules.IToken in project webtools.sourceediting by eclipse.

the class LineStyleProviderForJSPEL method prepareRegions.

public boolean prepareRegions(ITypedRegion typedRegion, int ssssrequestedStart, int ssssrequestedLength, Collection holdResults) {
    boolean result = true;
    try {
        // ideally, eventually, we'll have a "virtualDocument" we can
        // refer to, but for now ... we'll simple rescan the one region.
        // use simple adjustment (since "sub-content" starts at 0
        int offsetAdjustment = typedRegion.getOffset();
        String content = fDocument.get(typedRegion.getOffset(), typedRegion.getLength());
        IDocument document = new Document(content);
        int lastStart = 0;
        int length = 0;
        IToken lastToken = Token.UNDEFINED;
        int remainingLength = typedRegion.getLength();
        fScanner.setRange(document, lastStart, remainingLength);
        while (true) {
            IToken token = fScanner.nextToken();
            if (token.isEOF()) {
                if (!lastToken.isUndefined() && length != 0)
                    addRange(holdResults, lastStart + offsetAdjustment, length, getTokenTextAttribute(lastToken));
                break;
            }
            if (token.isWhitespace()) {
                length += fScanner.getTokenLength();
                continue;
            }
            if (lastToken.isUndefined()) {
                lastToken = token;
                length += fScanner.getTokenLength();
                continue;
            }
            if (token != lastToken) {
                addRange(holdResults, lastStart + offsetAdjustment, length, getTokenTextAttribute(lastToken));
                lastToken = token;
                lastStart = fScanner.getTokenOffset();
                length = fScanner.getTokenLength();
                continue;
            }
            length += fScanner.getTokenLength();
        }
    } catch (BadLocationException e) {
        // shouldn't happen, but we don't want it to stop other
        // highlighting, if it does.
        result = false;
    }
    return result;
}
Also used : IToken(org.eclipse.jface.text.rules.IToken) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 58 with IToken

use of org.eclipse.jface.text.rules.IToken in project liferay-ide by liferay.

the class Configuration method getPresentationReconciler.

public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
    PresentationReconciler reconciler = new PresentationReconciler();
    IToken defaultToken = null;
    DefaultDamagerRepairer dr = null;
    NonRuleBasedDamagerRepairer ndr = null;
    defaultToken = new Token(new TextAttribute(colorManager.getColor(Constants.COLOR_DIRECTIVE)));
    ContentScanner contentScanner = new ContentScanner(defaultToken, colorManager);
    for (int i = 0; i < PartitionScanner.DIRECTIVES.length; i++) {
        dr = new DefaultDamagerRepairer(contentScanner);
        reconciler.setDamager(dr, PartitionScanner.DIRECTIVES[i]);
        reconciler.setRepairer(dr, PartitionScanner.DIRECTIVES[i]);
    }
    dr = new DefaultDamagerRepairer(contentScanner);
    reconciler.setDamager(dr, PartitionScanner.FTL_DIRECTIVE);
    reconciler.setRepairer(dr, PartitionScanner.FTL_DIRECTIVE);
    dr = new DefaultDamagerRepairer(contentScanner);
    reconciler.setDamager(dr, PartitionScanner.FTL_DIRECTIVE_END);
    reconciler.setRepairer(dr, PartitionScanner.FTL_DIRECTIVE_END);
    ndr = new NonRuleBasedDamagerRepairer(new TextAttribute(colorManager.getColor(Constants.COLOR_XML_COMMENT)));
    reconciler.setDamager(ndr, PartitionScanner.XML_COMMENT);
    reconciler.setRepairer(ndr, PartitionScanner.XML_COMMENT);
    ndr = new NonRuleBasedDamagerRepairer(new TextAttribute(colorManager.getColor(Constants.COLOR_STRING)));
    reconciler.setDamager(ndr, PartitionScanner.STRING);
    reconciler.setRepairer(ndr, PartitionScanner.STRING);
    ndr = new NonRuleBasedDamagerRepairer(new TextAttribute(colorManager.getColor(Constants.COLOR_COMMENT)));
    reconciler.setDamager(ndr, PartitionScanner.FTL_COMMENT);
    reconciler.setRepairer(ndr, PartitionScanner.FTL_COMMENT);
    defaultToken = new Token(new TextAttribute(colorManager.getColor(Constants.COLOR_INTERPOLATION)));
    dr = new DefaultDamagerRepairer(new ContentScanner(defaultToken, colorManager));
    reconciler.setDamager(dr, PartitionScanner.FTL_INTERPOLATION);
    reconciler.setRepairer(dr, PartitionScanner.FTL_INTERPOLATION);
    defaultToken = new Token(new TextAttribute(colorManager.getColor(Constants.COLOR_XML_TAG)));
    dr = new DefaultDamagerRepairer(new ContentScanner(defaultToken, colorManager));
    reconciler.setDamager(dr, PartitionScanner.XML_TAG);
    reconciler.setRepairer(dr, PartitionScanner.XML_TAG);
    return reconciler;
}
Also used : IToken(org.eclipse.jface.text.rules.IToken) TextAttribute(org.eclipse.jface.text.TextAttribute) DefaultDamagerRepairer(org.eclipse.jface.text.rules.DefaultDamagerRepairer) IToken(org.eclipse.jface.text.rules.IToken) Token(org.eclipse.jface.text.rules.Token) IPresentationReconciler(org.eclipse.jface.text.presentation.IPresentationReconciler) PresentationReconciler(org.eclipse.jface.text.presentation.PresentationReconciler)

Example 59 with IToken

use of org.eclipse.jface.text.rules.IToken in project syncope by apache.

the class InnerCSSScanner method createRules.

@Override
protected List<IRule> createRules() {
    RGB rgb = IHTMLColorConstants.TAGLIB;
    Color color = new Color(Display.getCurrent(), rgb);
    IToken tag = new Token(new TextAttribute(color));
    rgb = IHTMLColorConstants.CSS_COMMENT;
    color = new Color(Display.getCurrent(), rgb);
    IToken comment = new Token(new TextAttribute(color));
    List<IRule> rules = new ArrayList<IRule>();
    rules.add(new SingleLineRule(" <style", ">", tag));
    rules.add(new SingleLineRule(" </style", ">", tag));
    rules.add(new MultiLineRule("/*", "*/", comment));
    rules.addAll(super.createRules());
    return rules;
}
Also used : IToken(org.eclipse.jface.text.rules.IToken) SingleLineRule(org.eclipse.jface.text.rules.SingleLineRule) TextAttribute(org.eclipse.jface.text.TextAttribute) Color(org.eclipse.swt.graphics.Color) ArrayList(java.util.ArrayList) MultiLineRule(org.eclipse.jface.text.rules.MultiLineRule) IToken(org.eclipse.jface.text.rules.IToken) Token(org.eclipse.jface.text.rules.Token) RGB(org.eclipse.swt.graphics.RGB) IRule(org.eclipse.jface.text.rules.IRule)

Example 60 with IToken

use of org.eclipse.jface.text.rules.IToken in project syncope by apache.

the class InnerJavaScriptScanner method createRules.

@Override
protected List<IRule> createRules() {
    IToken tag = new Token(new TextAttribute(new Color(Display.getCurrent(), IHTMLColorConstants.TAG)));
    IToken comment = new Token(new TextAttribute(new Color(Display.getCurrent(), IHTMLColorConstants.JAVA_COMMENT)));
    IToken jsdoc = new Token(new TextAttribute(new Color(Display.getCurrent(), IHTMLColorConstants.JSDOC)));
    List<IRule> rules = super.createRules();
    rules.add(new SingleLineRule(" <script", ">", tag));
    rules.add(new SingleLineRule(" </script", ">", tag));
    rules.add(new MultiLineRule("/**", "*/", jsdoc));
    rules.add(new MultiLineRule("/*", "*/", comment));
    return rules;
}
Also used : IToken(org.eclipse.jface.text.rules.IToken) SingleLineRule(org.eclipse.jface.text.rules.SingleLineRule) TextAttribute(org.eclipse.jface.text.TextAttribute) Color(org.eclipse.swt.graphics.Color) MultiLineRule(org.eclipse.jface.text.rules.MultiLineRule) IToken(org.eclipse.jface.text.rules.IToken) Token(org.eclipse.jface.text.rules.Token) IRule(org.eclipse.jface.text.rules.IRule)

Aggregations

IToken (org.eclipse.jface.text.rules.IToken)77 Token (org.eclipse.jface.text.rules.Token)25 Test (org.junit.Test)21 IDocument (org.eclipse.jface.text.IDocument)17 TextAttribute (org.eclipse.jface.text.TextAttribute)16 Document (org.eclipse.jface.text.Document)15 BadLocationException (org.eclipse.jface.text.BadLocationException)13 MultiLineRule (org.eclipse.jface.text.rules.MultiLineRule)13 IPartitionTokenScanner (org.eclipse.jface.text.rules.IPartitionTokenScanner)10 IPredicateRule (org.eclipse.jface.text.rules.IPredicateRule)10 IRule (org.eclipse.jface.text.rules.IRule)10 RuleBasedPartitionScanner (org.eclipse.jface.text.rules.RuleBasedPartitionScanner)10 ArrayList (java.util.ArrayList)9 WordRule (org.eclipse.jface.text.rules.WordRule)8 SingleLineRule (org.eclipse.jface.text.rules.SingleLineRule)6 NotNull (org.jkiss.code.NotNull)6 RuleBasedScanner (org.eclipse.jface.text.rules.RuleBasedScanner)5 Color (org.eclipse.swt.graphics.Color)5 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)4 TypedPosition (org.eclipse.jface.text.TypedPosition)4