1 | package com.framsticks.framclipse.framScript; |
---|
2 | |
---|
3 | import java.util.LinkedHashMap; |
---|
4 | import java.util.List; |
---|
5 | import java.util.Map; |
---|
6 | |
---|
7 | import com.framsticks.framclipse.framScript.impl.FunctionImpl; |
---|
8 | import com.framsticks.framclipse.script.model.Argument; |
---|
9 | import com.framsticks.framclipse.script.model.Element; |
---|
10 | |
---|
11 | public class ProposableFunctionImpl extends FunctionImpl implements Proposable { |
---|
12 | |
---|
13 | private final String display; |
---|
14 | private final String proposal; |
---|
15 | private final Map<String, String> description = new LinkedHashMap<String, String>(); |
---|
16 | |
---|
17 | public ProposableFunctionImpl(Element element) { |
---|
18 | assert element.isFunction(); |
---|
19 | name = element.getName(); |
---|
20 | display = name + element.argumentsString(true) + " : " + element.returnType(); |
---|
21 | proposal = name + element.argumentsString(false) + ("void".equals(element.returnType()) ? ";" : ""); |
---|
22 | createDescription(element); |
---|
23 | } |
---|
24 | |
---|
25 | private void createDescription(Element element) { |
---|
26 | description.put("Description", element.getDescription()); |
---|
27 | description.put("Returns", element.returnType()); |
---|
28 | description.put("Arguments", createArguments(element.getArguments())); |
---|
29 | } |
---|
30 | |
---|
31 | private String createArguments(List<Argument> args) { |
---|
32 | StringBuilder builder = new StringBuilder(); |
---|
33 | for (int i = 0; i < args.size(); i++) { |
---|
34 | Argument a = args.get(i); |
---|
35 | builder.append(a.getName(i) + " : " + a.getType() + "\n"); |
---|
36 | } |
---|
37 | return builder.toString(); |
---|
38 | } |
---|
39 | |
---|
40 | @Override |
---|
41 | public String display() { |
---|
42 | return display; |
---|
43 | } |
---|
44 | |
---|
45 | @Override |
---|
46 | public String proposal() { |
---|
47 | return proposal; |
---|
48 | } |
---|
49 | |
---|
50 | @Override |
---|
51 | public Map<String, String> description() { |
---|
52 | return description; |
---|
53 | } |
---|
54 | |
---|
55 | } |
---|