github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

olabini / ioke

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 190
    • 25
  • Source
  • Commits
  • Network (25)
  • Issues (0)
  • Downloads (10)
  • Wiki (1)
  • Graphs
  • Tree: 0e20b49

click here to add a description

click here to add a homepage

  • Branches (4)
    • gh-pages
    • ikil
    • integration
    • master
  • Tags (10)
    • IOKEexit
    • IOKE_S_IKJ_0_2_0
    • IOKE_P_IKJ_0_4_0
    • IOKE_P_IKC_0_4_0
    • IOKE_P
    • IOKE_E_IKJ_0_3_1
    • IOKE_E_IKJ_0_3_0
    • IOKE_E_IKC_0_1_1
    • IOKE_E_IKC_0_1_0
    • IOKE0_IKJVM_0_1_0
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

ioke is a new language for the JVM, based on Io and other languages. — Read more

  cancel

http://ioke.org

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Add default arguments handler. 
melwin (author)
Sun Jan 18 15:32:45 -0800 2009
commit  0e20b492b8e057e9d2c006698deca02ebf8f45f7
tree    76e372495c6848f0b13bf8edc30daef90fbbca4d
parent  3f249e5db30e75133432339cef21c8b5b2acd956
ioke / src / main / ioke / lang / TypeCheckingArgumentsDefinition.java src/main/ioke/lang/TypeCheckingArgumentsDefinition.java
100644 165 lines (136 sloc) 5.161 kb
edit raw blame history
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package ioke.lang;
 
import ioke.lang.exceptions.ControlFlow;
 
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
 
public class TypeCheckingArgumentsDefinition extends DefaultArgumentsDefinition {
    private List<Object> mustMimic = new ArrayList<Object>();
    private Object receiverMustMimic;
    private List<Argument> arguments;
 
    private TypeCheckingArgumentsDefinition(List<Argument> arguments,
            Collection<String> keywords, String rest, String krest, int min,
            int max, boolean restUneval, List<Object> mustMimic,
            Object receiverMustMimic) {
        super(arguments, keywords, rest, krest, min, max, restUneval);
        this.arguments = arguments;
        this.mustMimic = mustMimic;
        this.receiverMustMimic = receiverMustMimic;
    }
 
    private Object convertToMimic(Object mimic, Object on, IokeObject message,
            IokeObject context) throws ControlFlow {
        if (mimic == null) {
            return on;
        } else {
            return IokeObject.as(mimic).convertToThis(on, message, context);
        }
 
    }
 
    public Object getValidatedArgumentsAndReceiver(IokeObject context,
            IokeObject message, Object on,
            List<Object> argumentsWithoutKeywords,
            Map<String, Object> givenKeywords) throws ControlFlow {
 
        getEvaluatedArguments(context, message, on,
                argumentsWithoutKeywords, givenKeywords);
 
        int ix = 0;
        for (int i = 0, j = this.arguments.size(); i < j; i++) {
            Argument a = this.arguments.get(i);
 
            if (a instanceof KeywordArgument) {
                String name = a.getName() + ":";
                Object given = givenKeywords.get(name);
                if (given != null) {
                    givenKeywords.put(name, convertToMimic(
                            mustMimic.get(i), given, message, context));
                }
            } else {
                argumentsWithoutKeywords.set(ix, convertToMimic(mustMimic.get(i),
                        argumentsWithoutKeywords.get(ix), message,
                        context));
                ix++;
            }
        }
 
        return convertToMimic(receiverMustMimic, on, message, context);
    }
 
    public static TypeCheckingArgumentsDefinition empty() {
        return emptyButReceiverMustMimic(null);
    }
 
    public static TypeCheckingArgumentsDefinition emptyButReceiverMustMimic(Object mimic) {
        return new TypeCheckingArgumentsDefinition(new ArrayList<Argument>(), new ArrayList<String>(), null, null, 0, 0, false, new ArrayList<Object>(), mimic);
    }
    
    public static class Builder extends DefaultArgumentsDefinition.Builder {
        private List<Object> mustMimic = new ArrayList<Object>();
        private Object receiverMustMimic;
 
        private boolean setMimic = true;
 
        private void next() {
            if (!setMimic)
                mustMimic.add(null);
            else
                setMimic = false;
        }
 
        public Builder whichMustMimic(Object mimic) {
            mustMimic.add(mimic);
            return this;
        }
 
        public Builder receiverMustMimic(Object mimic) {
            this.receiverMustMimic = mimic;
            return this;
        }
 
        @Override
        public Builder withKeyword(String name) {
            super.withKeyword(name);
            next();
            return this;
        }
 
        @Override
        public Builder withKeywordRest(String name) {
            super.withKeywordRest(name);
            next();
            return this;
        }
 
        @Override
        public Builder withOptionalPositional(String name, String defaultValue) {
            super.withOptionalPositional(name, defaultValue);
            next();
            return this;
        }
 
        @Override
        public Builder withOptionalPositionalUnevaluated(String name) {
            super.withOptionalPositionalUnevaluated(name);
            next();
            return this;
        }
 
        @Override
        public Builder withRequiredPositional(String name) {
            super.withRequiredPositional(name);
            next();
            return this;
        }
 
        @Override
        public Builder withRequiredPositionalUnevaluated(String name) {
            super.withRequiredPositionalUnevaluated(name);
            next();
            return this;
        }
 
        @Override
        public Builder withRest(String name) {
            super.withRest(name);
            next();
            return this;
        }
 
        @Override
        public Builder withRestUnevaluated(String name) {
            super.withRestUnevaluated(name);
            next();
            return this;
        }
 
        @Override
        public TypeCheckingArgumentsDefinition getArguments() {
            next();
            return new TypeCheckingArgumentsDefinition(arguments, keywords,
                    rest, krest, min, max, restUneval, mustMimic,
                    receiverMustMimic);
        }
    }
 
    public static Builder builder() {
        return new Builder();
    }
}
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server