diff options
Diffstat (limited to 'plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.xtext')
-rw-r--r-- | plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.xtext/src/org/eclipse/papyrus/infra/gmfdiag/validation/CSSJavaValidator.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.xtext/src/org/eclipse/papyrus/infra/gmfdiag/validation/CSSJavaValidator.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.xtext/src/org/eclipse/papyrus/infra/gmfdiag/validation/CSSJavaValidator.java index e03031f3cea..a3f23360674 100644 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.xtext/src/org/eclipse/papyrus/infra/gmfdiag/validation/CSSJavaValidator.java +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.xtext/src/org/eclipse/papyrus/infra/gmfdiag/validation/CSSJavaValidator.java @@ -11,10 +11,18 @@ *****************************************************************************/ package org.eclipse.papyrus.infra.gmfdiag.validation; + +import org.eclipse.emf.ecore.EObject; import org.eclipse.papyrus.infra.gmfdiag.css.Attribute; import org.eclipse.papyrus.infra.gmfdiag.css.CssPackage; +import org.eclipse.papyrus.infra.gmfdiag.css.Expression; +import org.eclipse.papyrus.infra.gmfdiag.css.Function; import org.eclipse.papyrus.infra.gmfdiag.css.HexColor; +import org.eclipse.papyrus.infra.gmfdiag.css.Number; import org.eclipse.papyrus.infra.gmfdiag.css.SimpleSelector; +import org.eclipse.papyrus.infra.gmfdiag.css.Subterm; +import org.eclipse.papyrus.infra.gmfdiag.css.Term; +import org.eclipse.papyrus.infra.gmfdiag.css.UNARY; import org.eclipse.xtext.validation.Check; @@ -34,6 +42,59 @@ public class CSSJavaValidator extends AbstractCSSJavaValidator { } } + @Check + public void checkRGBColor(Function function) { + if("rgb".equals(function.getName().toLowerCase())) { + if(function.getArgs().getSubterms().size() != 2) { //3 Args: 1 Term + 2 Subterms + warning("Invalid color. The RGB color must have exactly 3 arguments", CssPackage.Literals.FUNCTION__ARGS); + } + + + } + } + + @Check + public void checkRGBTerm(Term term) { + Expression owningExpression = findExpression(term); + if(owningExpression == null) { + return; + } + + if(owningExpression.eContainer() instanceof Function) { + if("rgb".equals(((Function)owningExpression.eContainer()).getName().toLowerCase())) { + if(!(term instanceof Number)) { + warning("The RGB color arguments must be integers. Actual type: " + term.eClass().getName(), term.eClass().getEStructuralFeature("value")); + } else { + Number number = (Number)term; + + boolean validValue = true; + try { + int absoluteValue = Integer.parseInt(number.getValue()); + validValue = (number.getOp() == null || number.getOp().getOperator() == UNARY.PLUS) && absoluteValue <= 255; + } catch (NumberFormatException ex) { + validValue = false; + } + + if(!validValue) { + warning("The RGB color arguments must be integers between 0 and 255", term.eClass().getEStructuralFeature("value")); + } + } + } + } + } + + protected Expression findExpression(EObject term) { + if(term.eContainer() instanceof Expression) { + return (Expression)term.eContainer(); + } + + if(term.eContainer() instanceof Subterm) { + return findExpression(term.eContainer()); + } + + return null; + } + ////////////////////////// // EMF Only // ////////////////////////// |