Skip to main content
summaryrefslogtreecommitdiffstats
blob: cde6c4a6b2f1fe7b3444b46173a1bb20649a424d (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
/*
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.eclipose.xtend.middleend;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.eclipose.xtend.middleend.internal.Activator;
import org.eclipose.xtend.middleend.plugins.LanguageSpecificMiddleEnd;
import org.eclipse.xtend.backend.common.BackendTypesystem;


/**
 * This class encapsulates the OSGi / Eclipse extension registry specific behavior and
 *  initialization code. It serves as an optional wrapper / convenience initialization
 *  code for the actual MiddleEnd class.
 * 
 * @author Arno Haase (http://www.haase-consulting.com)
 */
public final class MiddleEndFactory {
    /**
     * This method creates a MiddleEnd instance based on an explicitly provided list of handlers. It works without
     *  OSGi.
     */
    public static MiddleEnd create (BackendTypesystem ts, List<LanguageSpecificMiddleEnd> languageHandlers) {
        return new MiddleEnd (ts, languageHandlers);
    }
    
    /**
     * This method creates a middle end based on the handlers registered with the extension point. It relies
     *  on OSGi and makes use of the Eclipse extension registry.<br>
     * 
     * The map with "specific params" is used to initialize the contributed middle ends.
     *  The key must be the class implementing the LanguageSpecificMiddleEnd interface
     *  and contributed via the extension point.
     */
    public static MiddleEnd create (BackendTypesystem ts, Map<Class<?>, Object> specificParams) {
        final List<LanguageSpecificMiddleEnd> languageHandlers = new ArrayList<LanguageSpecificMiddleEnd> ();
        final MiddleEnd result = new MiddleEnd (ts, languageHandlers);
        
        languageHandlers.addAll (Activator.getInstance().getFreshMiddleEnds (result, specificParams));
        return result;
    }
}

Back to the top