diff options
author | Tom Schindl | 2015-11-25 23:22:18 +0000 |
---|---|---|
committer | Tom Schindl | 2015-11-25 23:25:29 +0000 |
commit | 6bba38d194f90ef28a6500ada1eddf547b8e8c26 (patch) | |
tree | b972c94f534f33c8cd9b7d278af1fba89c6a2677 /bundles/code/org.eclipse.fx.code.editor.configuration.text/src/org/eclipse/fx/code/editor/configuration/text/Util.java | |
parent | c6eb653d23b0e2a2849344210ae279ea0d8a82c7 (diff) | |
download | org.eclipse.efxclipse-6bba38d194f90ef28a6500ada1eddf547b8e8c26.tar.gz org.eclipse.efxclipse-6bba38d194f90ef28a6500ada1eddf547b8e8c26.tar.xz org.eclipse.efxclipse-6bba38d194f90ef28a6500ada1eddf547b8e8c26.zip |
Bug 483038 - Allow to configures editor highlightings based on JSON
Diffstat (limited to 'bundles/code/org.eclipse.fx.code.editor.configuration.text/src/org/eclipse/fx/code/editor/configuration/text/Util.java')
-rw-r--r-- | bundles/code/org.eclipse.fx.code.editor.configuration.text/src/org/eclipse/fx/code/editor/configuration/text/Util.java | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/bundles/code/org.eclipse.fx.code.editor.configuration.text/src/org/eclipse/fx/code/editor/configuration/text/Util.java b/bundles/code/org.eclipse.fx.code.editor.configuration.text/src/org/eclipse/fx/code/editor/configuration/text/Util.java new file mode 100644 index 000000000..c0419d7e5 --- /dev/null +++ b/bundles/code/org.eclipse.fx.code.editor.configuration.text/src/org/eclipse/fx/code/editor/configuration/text/Util.java @@ -0,0 +1,50 @@ +package org.eclipse.fx.code.editor.configuration.text; + +import java.util.function.IntPredicate; + +import org.eclipse.fx.code.editor.configuration.Check; +import org.eclipse.fx.code.editor.configuration.Equals; +import org.eclipse.fx.code.editor.configuration.Range; +import org.eclipse.fx.core.function.IntRelationOperation; +import org.eclipse.fx.text.rules.ColumnStartRule; +import org.eclipse.fx.text.rules.PredicateColumnStartRule; +import org.eclipse.jface.text.rules.IPredicateRule; +import org.eclipse.jface.text.rules.IRule; + +@SuppressWarnings("restriction") +public class Util { + public static IRule wrap(Check check, IRule rule) { + if( check == null ) { + return rule; + } else { + IntPredicate p = null; + if( check instanceof Equals ) { + int c = ((Equals) check).getValue(); + p = v -> v == c; + } else if( check instanceof Range ) { + Range r = (Range) check; + if( r.getMin() != -1 && r.getMax() != -1 ) { + int min = r.getMin(); + int max = r.getMax(); + IntRelationOperation minOp = r.isMinIncl() ? IntRelationOperation::lt : IntRelationOperation::lte; + IntRelationOperation maxOp = r.isMaxIncl() ? IntRelationOperation::lt : IntRelationOperation::lte; + p = v -> minOp.apply(min, v) && maxOp.apply(v,max); + } else if( r.getMin() != -1 ) { + int min = r.getMin(); + IntRelationOperation minOp = r.isMinIncl() ? IntRelationOperation::lt : IntRelationOperation::lte; + p = v -> minOp.apply(min, v); + } else if( r.getMax() != -1 ) { + int max = r.getMax(); + IntRelationOperation maxOp = r.isMaxIncl() ? IntRelationOperation::lt : IntRelationOperation::lte; + p = v -> maxOp.apply(v,max); + } + } + + if( p != null ) { + return rule instanceof IPredicateRule ? new PredicateColumnStartRule((IPredicateRule) rule, p) : new ColumnStartRule(rule, p); + } else { + return rule; + } + } + } +} |