Skip to main content
summaryrefslogtreecommitdiffstats
blob: fb8f2c5b71a8cc55283946382d4a8a9f7fca23ea (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
/*******************************************************************************
 * Copyright (c) 2005, 2007 committers of openArchitectureWare 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:
 *     committers of openArchitectureWare - initial API and implementation
 *******************************************************************************/

package org.eclipse.xtend.typesystem.emf;

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EEnumLiteral;
import org.eclipse.internal.xtend.type.baseimpl.StaticPropertyImpl;
import org.eclipse.xtend.typesystem.AbstractTypeImpl;
import org.eclipse.xtend.typesystem.Feature;

public class EEnumType extends AbstractTypeImpl {

    private EEnum eEnum;

    public EEnumType(final EmfRegistryMetaModel model, final String name, final EEnum eEnum) {
        super(model.getTypeSystem(), name);
        this.eEnum = eEnum;
    }

    @Override
    public Feature[] getContributedFeatures() {
        final Set<StaticPropertyImpl> result = new HashSet<StaticPropertyImpl>();
        final List<EEnumLiteral> enumLiterals = eEnum.getELiterals();
        for (final Iterator<EEnumLiteral> iter = enumLiterals.iterator(); iter.hasNext();) {
            final EEnumLiteral lit = iter.next();
            result.add(new StaticPropertyImpl(this, lit.getName(), this) {
                public Object get() {
                    return lit.getInstance();
                }
            });
        }
        return result.toArray(new Feature[result.size()]);
    }

    public boolean isInstance(final Object o) {
        return eEnum.isInstance(o);
    }

    public Object newInstance() {
        throw new UnsupportedOperationException("Enums are static!");
    }

}

Back to the top