Package com.github.sommeri.less4j.core.ast

Examples of com.github.sommeri.less4j.core.ast.NumberExpression


class Round extends AbtractMultiParameterMathFunction {

  @Override
  protected Expression evaluate(List<Expression> splitParameters, ProblemsHandler problemsHandler, FunctionExpression functionCall, HiddenTokenAwareTree parentToken) {
    NumberExpression parameter = (NumberExpression) splitParameters.get(0);
    Double oValue = parameter.getValueAsDouble();
    String suffix = parameter.getSuffix();
    Dimension dimension = parameter.getDimension();
   
    if (oValue.isInfinite() || oValue.isNaN())
      return new NumberExpression(parentToken, oValue, suffix, null, dimension);

    NumberExpression fraction = (NumberExpression) (splitParameters.size() > 1 ? splitParameters.get(1) : null);
    if (fraction != null) {
      double pow = Math.pow(10, fraction.getValueAsDouble());
      oValue = Math.round(oValue * pow) / pow;
    } else {
      oValue = (double) Math.round(oValue);
    }
    return new NumberExpression(parentToken, oValue, suffix, null, dimension);
  }
View Full Code Here


   
    if (next.getType()!=ASTCssNodeType.NUMBER) {
      return new FunctionExpression(token, getName(), null);
    }
   
    NumberExpression result = (NumberExpression) next;
    while (expanded.hasNext()) {
      next = expanded.next();
      if (next.getType()==ASTCssNodeType.NUMBER) {
        NumberExpression nextNum = (NumberExpression) next;
        if (!canCompare(result, nextNum)) {
          problemsHandler.errorIncompatibleTypesCompared(functionCall, result.getSuffix(), nextNum.getSuffix());
          return new FaultyExpression(functionCall);
        }
       
        result = compareCompatible(result, nextNum);
      }
View Full Code Here

class Pi extends AbstractFunction {

  @Override
  public Expression evaluate(List<Expression> parameters, ProblemsHandler problemsHandler, FunctionExpression call, Expression evaluatedParameter) {
    return new NumberExpression(call.getUnderlyingStructure(), Math.PI, "", null, Dimension.NUMBER);
  }
View Full Code Here

  protected String getName() {
    return MathFunctions.MIN;
  }

  protected NumberExpression compareCompatible(NumberExpression first, NumberExpression second) {
    NumberExpression secondConverted = second.convertTo(first.getSuffix());
    if (secondConverted.getValueAsDouble()<first.getValueAsDouble())
      return second;
   
    return first;
  }
View Full Code Here

  protected String getName() {
    return MathFunctions.MAX;
  }

  protected NumberExpression compareCompatible(NumberExpression first, NumberExpression second) {
    NumberExpression secondConverted = second.convertTo(first.getSuffix());
    if (secondConverted.getValueAsDouble()>first.getValueAsDouble())
      return second;
   
    return first;
  }
View Full Code Here

  @Override
  protected Expression evaluate(List<Expression> splitParameters, ProblemsHandler problemsHandler, FunctionExpression call, HiddenTokenAwareTree token) {
    Expression expression = splitParameters.get(0);
    if (expression.getType()!=ASTCssNodeType.LIST_EXPRESSION)
      return new NumberExpression(call.getUnderlyingStructure(), Double.valueOf(1), "", null, Dimension.NUMBER);
   
    ListExpression list = (ListExpression) expression;
    int length = list.getExpressions().size();
    return new NumberExpression(call.getUnderlyingStructure(), Double.valueOf(length), "", null, Dimension.NUMBER);
  }
View Full Code Here

  }

  private Expression createResult(Double originalValue, HiddenTokenAwareTree parentToken) {
    Double value = originalValue * 100.0;

    return new NumberExpression(parentToken, value, "%", null, Dimension.PERCENTAGE);
  }
View Full Code Here

    if (iParameter.getType() != ASTCssNodeType.NUMBER) {
      problemsHandler.wrongArgumentTypeToFunction(iParameter, getName(), iParameter.getType(), ASTCssNodeType.NUMBER);
      return new FaultyExpression(iParameter);
    }

    NumberExpression parameter = (NumberExpression) iParameter;
    HiddenTokenAwareTree parentToken = parameter.getUnderlyingStructure();
    Double oValue = parameter.getValueAsDouble();
    String suffix = parameter.getSuffix();
    Dimension dimension = parameter.getDimension();
   
    if (oValue.isInfinite() || oValue.isNaN())
      return new NumberExpression(parentToken, oValue, suffix, null, dimension);

    return calc(parentToken, oValue, suffix, dimension);
  }
View Full Code Here

    return calc(parentToken, oValue, suffix, dimension);
  }
 
  protected Expression calc(HiddenTokenAwareTree parentToken, Double oValue, String suffix, Dimension dimension) {
    return new NumberExpression(parentToken, calc(oValue, suffix, dimension), resultSuffix(suffix, dimension),
  null, resultDimension(suffix, dimension));
  }
View Full Code Here

TOP

Related Classes of com.github.sommeri.less4j.core.ast.NumberExpression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.