Skip to main content
summaryrefslogtreecommitdiffstats
blob: 08581da86396602d2f075d9539b431e3dab91dde (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
/*
Copyright (c) 2008 Arno Haase.
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:
    Arno Haase - initial API and implementation
 */
package org.eclipse.xtend.backend.testhelpers;

import org.eclipose.xtend.middleend.MiddleEnd;
import org.eclipse.xtend.backend.BackendFacade;
import org.eclipse.xtend.backend.common.BackendTypesystem;
import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.common.ExpressionBase;
import org.eclipse.xtend.backend.common.SourcePos;
import org.eclipse.xtend.backend.expr.LiteralExpression;
import org.eclipse.xtend.backend.functions.FunctionDefContextInternal;
import org.eclipse.xtend.backend.types.CompositeTypesystem;


/**
 * 
 * @author Arno Haase (http://www.haase-consulting.com)
 */
public class BackendTestHelper {
    public static final SourcePos SOURCE_POS = createSourcePos();
    
    /**
     * This method returns an ExecutionContext that is basically empty - no registered functions, and
     *  only the JavaBeansTypeSystem. It is useful for simple tests.
     */
    public static ExecutionContext createEmptyExecutionContext () {
        final BackendTypesystem ts = new CompositeTypesystem ();
        return BackendFacade.createExecutionContext (new MiddleEnd (ts, null).createEmptyFdc(), ts, true);
    }

    public static FunctionDefContextInternal createEmptyFdc (BackendTypesystem ts) {
        return new MiddleEnd (ts, null).createEmptyFdc();
    }
    
    public static ExpressionBase createLiteral (Object literal) {
        return new LiteralExpression (literal, SOURCE_POS);
    }
    
    public static SourcePos createSourcePos () {
        return new SourcePos ("<no file>", "<no callable>", 0);
    }
}

Back to the top