Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6a5a8ec0b721350d1d5eceda7eae6f2f2aa1f17a (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
/*
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.middleend.old.common;

import java.util.Collection;

import org.eclipse.internal.xtend.expression.parser.SyntaxConstants;
import org.eclipse.internal.xtend.xtend.XtendFile;
import org.eclipse.xpand2.XpandUtil;
import org.eclipse.xtend.backend.common.BackendTypesystem;
import org.eclipse.xtend.backend.types.CompositeTypesystem;
import org.eclipse.xtend.backend.types.emf.EmfTypesystem;
import org.eclipse.xtend.typesystem.MetaModel;
import org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel;


/**
 * 
 * @author Arno Haase (http://www.haase-consulting.com)
 */
public final class OldHelper {
    public static BackendTypesystem guessTypesystem (Collection<MetaModel> mms) {
        boolean hasEmf = false;
        
        for (MetaModel mm: mms) {
            if (mm instanceof EmfRegistryMetaModel)
                hasEmf = true;
        }
        
        final CompositeTypesystem result = new CompositeTypesystem ();
        if (hasEmf)
            result.register (new EmfTypesystem ());
        //TODO register uml mm
        //TODO replace this by adding "asBackendType" to the frontend types
        
        return result;
    }

    
    public static String normalizedFileEncoding (String fileEncoding) {
        if (fileEncoding == null)
            return System.getProperty ("file.encoding");

        return fileEncoding;
    }
    
    public static String normalizeXtendResourceName (String xtendName) {
        if (xtendName == null)
            return null;
        
        xtendName = xtendName.replace (SyntaxConstants.NS_DELIM, "/");
        if (xtendName.endsWith ("." + XtendFile.FILE_EXTENSION))
            xtendName = xtendName.substring (0, xtendName.length() - (XtendFile.FILE_EXTENSION.length() + 1));

        return xtendName;
    }
    
    public static String normalizeXpandResourceName (String xpandName) {
        if (xpandName == null)
            return null;
        
        if (! xpandName.endsWith("." + XpandUtil.TEMPLATE_EXTENSION))
            xpandName += "." + XpandUtil.TEMPLATE_EXTENSION;

        xpandName = xpandName.replace (SyntaxConstants.NS_DELIM, "/");
        
        return xpandName;
    }
    
    public static String xpandFileAsOldResourceName (String xpandName) {
        if (xpandName == null)
            return null;
        
        if (xpandName.toLowerCase().endsWith (XpandUtil.TEMPLATE_EXTENSION))
            xpandName = xpandName.substring (0, xpandName.length() - XpandUtil.TEMPLATE_EXTENSION.length() - 1);
        
        xpandName = xpandName.replace ("/", SyntaxConstants.NS_DELIM);
        
        return xpandName;
    }
}

Back to the top