Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2dccc2eca51043c84e5e803686168f85544dbfe7 (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
package org.eclipse.xtend.backend.types.builtin;

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

import org.eclipse.xtend.backend.common.BackendType;
import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.types.AbstractType;
import org.eclipse.xtend.backend.util.ReflectionHelper;


/**
 * This class represents the type of a type. It serves as an entry point for meta programming.
 * 
 * @author Arno Haase (http://www.haase-consulting.com)
 */
public final class TypeType extends AbstractType {
    public static final TypeType INSTANCE = new TypeType ();
    
    private TypeType () {
        super ("Type");
        
        register (new BuiltinProperty (this, StringType.INSTANCE, "name", ReflectionHelper.getKnownMethod (BackendType.class, "getName"), null));
        register (new BuiltinProperty (this, ListType.INSTANCE, "superTypes", ReflectionHelper.getKnownMethod (BackendType.class, "getSuperTypes"), null));
        register (new BuiltinProperty (this, ListType.INSTANCE, "allProperties", ReflectionHelper.getKnownMethod (BackendType.class, "getProperties"), null));
        register (new BuiltinProperty (this, ListType.INSTANCE, "allStaticProperties", ReflectionHelper.getKnownMethod (BackendType.class, "getStaticProperties"), null));
        
        register (new BuiltinProperty (this, ListType.INSTANCE, "allOperations", null, null) {
            @Override
            public Object get (ExecutionContext ctx, Object o) {
                final BackendType t = (BackendType) o;
                final List<Object> result = new ArrayList<Object>();
                result.addAll (ctx.getFunctionDefContext().getByFirstParameterType(t));
                result.addAll (t.getBuiltinOperations());
                return result;
            } 
        });
    }

    public boolean isAssignableFrom (BackendType other) {
        return other == this || other == VoidType.INSTANCE;
    }
}


Back to the top