Skip to main content
summaryrefslogtreecommitdiffstats
blob: a6ba34bfa3b2cfa40f721915135f0b821f8c1980 (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
package org.eclipse.xtend.middleend.old;

import java.util.Collection;
import java.util.List;

import org.eclipose.xtend.middleend.FunctionDefContextFactory;
import org.eclipse.xtend.backend.common.BackendType;
import org.eclipse.xtend.backend.common.BackendTypesystem;
import org.eclipse.xtend.backend.common.FunctionDefContext;
import org.eclipse.xtend.backend.common.NamedFunction;
import org.eclipse.xtend.backend.functions.SourceDefinedFunction;
import org.eclipse.xtend.backend.iface.BackendContributor;
import org.eclipse.xtend.backend.types.CompositeTypesystem;
import org.eclipse.xtend.expression.ExecutionContextImpl;
import org.eclipse.xtend.typesystem.MetaModel;


/**
 * 
 * @author Arno Haase (http://www.haase-consulting.com)
 */
public final class XtendBackendContributor implements BackendContributor {
    private final OldXtendRegistry _registry;
    private final String _xtendFile;
    private final BackendTypesystem _ts;
    
    public XtendBackendContributor (String xtendFile, Collection<MetaModel> mms, CompositeTypesystem ts) {
        _xtendFile = OldXtendHelper.normalizeXtendResourceName (xtendFile);
        _ts = ts;
        
        final ExecutionContextImpl ctx = new ExecutionContextImpl ();
        for (MetaModel mm: mms)
            ctx.registerMetaModel (mm);
        ctx.setFileEncoding("iso-8859-1"); //TODO really set the encoding

        //TODO redesign to allow reuse of the registry?
        _registry = new OldXtendRegistry ( ctx, ts);
        _registry.registerExtension(xtendFile);
    }
    
    public BackendType convertToType (List<String> segments) {
        return null;
    }

    public Collection<NamedFunction> getContributedFunctions () {
        return _registry.getContributedFunctions (_xtendFile);
    }
    
    public FunctionDefContext getFunctionDefContext () {
        if (getContributedFunctions().isEmpty())
            return new FunctionDefContextFactory(_ts).create();
        
        return ((SourceDefinedFunction) getContributedFunctions().iterator().next().getFunction()).getFunctionDefContext();
    }
}


Back to the top