Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0f8f3231a5a34195caac9604612f1995f4242aca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * Copyright (c) 2013 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.emf.cdo.expressions.util;

import org.eclipse.emf.cdo.expressions.BooleanValue;
import org.eclipse.emf.cdo.expressions.ByteValue;
import org.eclipse.emf.cdo.expressions.CharValue;
import org.eclipse.emf.cdo.expressions.DoubleValue;
import org.eclipse.emf.cdo.expressions.Expression;
import org.eclipse.emf.cdo.expressions.ExpressionsFactory;
import org.eclipse.emf.cdo.expressions.FloatValue;
import org.eclipse.emf.cdo.expressions.FunctionInvocation;
import org.eclipse.emf.cdo.expressions.IntValue;
import org.eclipse.emf.cdo.expressions.ListConstruction;
import org.eclipse.emf.cdo.expressions.LongValue;
import org.eclipse.emf.cdo.expressions.MemberInvocation;
import org.eclipse.emf.cdo.expressions.ShortValue;
import org.eclipse.emf.cdo.expressions.StringValue;

import java.util.Arrays;

/**
 * @author Eike Stepper
 */
public class ExpressionsUtil
{
  public ExpressionsUtil()
  {
  }

  public static BooleanValue value(boolean literal)
  {
    BooleanValue value = ExpressionsFactory.eINSTANCE.createBooleanValue();
    value.setLiteral(literal);
    return value;
  }

  public static ByteValue value(byte literal)
  {
    ByteValue value = ExpressionsFactory.eINSTANCE.createByteValue();
    value.setLiteral(literal);
    return value;
  }

  public static CharValue value(char literal)
  {
    CharValue value = ExpressionsFactory.eINSTANCE.createCharValue();
    value.setLiteral(literal);
    return value;
  }

  public static DoubleValue value(double literal)
  {
    DoubleValue value = ExpressionsFactory.eINSTANCE.createDoubleValue();
    value.setLiteral(literal);
    return value;
  }

  public static FloatValue value(float literal)
  {
    FloatValue value = ExpressionsFactory.eINSTANCE.createFloatValue();
    value.setLiteral(literal);
    return value;
  }

  public static IntValue value(int literal)
  {
    IntValue value = ExpressionsFactory.eINSTANCE.createIntValue();
    value.setLiteral(literal);
    return value;
  }

  public static LongValue value(long literal)
  {
    LongValue value = ExpressionsFactory.eINSTANCE.createLongValue();
    value.setLiteral(literal);
    return value;
  }

  public static ShortValue value(short literal)
  {
    ShortValue value = ExpressionsFactory.eINSTANCE.createShortValue();
    value.setLiteral(literal);
    return value;
  }

  public static StringValue value(String literal)
  {
    StringValue value = ExpressionsFactory.eINSTANCE.createStringValue();
    value.setLiteral(literal);
    return value;
  }

  public static ListConstruction list(Expression... elements)
  {
    ListConstruction value = ExpressionsFactory.eINSTANCE.createListConstruction();
    value.getElements().addAll(Arrays.asList(elements));
    return value;
  }

  public static MemberInvocation invokeMember(Expression object, Expression name, Expression... arguments)
  {
    MemberInvocation expression = ExpressionsFactory.eINSTANCE.createMemberInvocation();
    expression.setObject(object);
    expression.setName(name);
    expression.getArguments().addAll(Arrays.asList(arguments));
    return expression;
  }

  public static FunctionInvocation invoke(Expression name, Expression... arguments)
  {
    FunctionInvocation expression = ExpressionsFactory.eINSTANCE.createFunctionInvocation();
    expression.setName(name);
    expression.getArguments().addAll(Arrays.asList(arguments));
    return expression;
  }

  public static FunctionInvocation construct(Expression className, Expression... arguments)
  {
    return invoke(value(className + ".new"), arguments);
  }

  // public static void main(String[] args)
  // {
  // System.out.println(Math.min(2, 4));
  // System.out.println(invoke(value("Math.min"), value(2), value(4)).evaluate(new EvaluationContextImpl()));
  // }
}

Back to the top