Skip to main content
summaryrefslogtreecommitdiffstats
blob: d0d5d40222b5cace7537e32ee2e78ddba9fbafff (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
/*
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.backend.types.internal;

import java.util.Arrays;

import org.eclipse.xtend.backend.common.BackendType;
import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.common.Property;


/**
 * 
 * @author Arno Haase (http://www.haase-consulting.com)
 */
public final class FunctionBackedProperty implements Property {
    private final String _name;
    private final BackendType _owner;
    private final String _getterName;
    private final String _setterName;
    
    //TODO inherit from AbstractProperty once the JavaConversion stuff is factored to a more generic place

    public FunctionBackedProperty (String name, String getterName, String setterName, BackendType owner) {
        _name = name;
        _owner = owner;
        _getterName = getterName;
        _setterName = setterName;
    }


    public Object get (ExecutionContext ctx, Object o) {
        return ctx.getFunctionDefContext().invoke (ctx, _getterName, Arrays.asList (o));
    }

    public void set (ExecutionContext ctx, Object o, Object newValue) {
        ctx.getFunctionDefContext().invoke (ctx, _setterName, Arrays.asList (o, newValue));
    }

    public String getName () {
        return _name;
    }

    public BackendType getOwner () {
        return _owner;
    }

    public boolean isReadable () {
        return _getterName != null;
    }
    
    public boolean isWritable () {
        return _setterName != null;
    }
}

Back to the top