/
SarlCapacityBuilderImpl.java
167 lines (151 loc) · 5.15 KB
/
SarlCapacityBuilderImpl.java
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
166
/*
* $Id$
*
* File is automatically generated by the Xtext language generator.
* Do not change it.
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2018 the original authors or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.sarl.lang.codebuilder.builders;
import io.sarl.lang.core.Capacity;
import io.sarl.lang.sarl.SarlCapacity;
import io.sarl.lang.sarl.SarlFactory;
import io.sarl.lang.sarl.SarlScript;
import java.util.function.Predicate;
import javax.inject.Inject;
import javax.inject.Provider;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.xtend.core.xtend.XtendFactory;
import org.eclipse.xtext.common.types.JvmParameterizedTypeReference;
import org.eclipse.xtext.common.types.JvmTypeReference;
import org.eclipse.xtext.common.types.access.IJvmTypeProvider;
import org.eclipse.xtext.util.EmfFormatter;
import org.eclipse.xtext.util.Strings;
import org.eclipse.xtext.xbase.compiler.DocumentationAdapter;
import org.eclipse.xtext.xbase.lib.Pure;
/** Builder of a Sarl SarlCapacity.
*/
@SuppressWarnings("all")
public class SarlCapacityBuilderImpl extends AbstractBuilder implements ISarlCapacityBuilder {
private SarlCapacity sarlCapacity;
@Override
@Pure
public String toString() {
return EmfFormatter.objToStr(getSarlCapacity());
}
/** Initialize the Ecore element when inside a script.
*/
public void eInit(SarlScript script, String name, IJvmTypeProvider context) {
setTypeResolutionContext(context);
if (this.sarlCapacity == null) {
this.sarlCapacity = SarlFactory.eINSTANCE.createSarlCapacity();
script.getXtendTypes().add(this.sarlCapacity);
this.sarlCapacity.setAnnotationInfo(XtendFactory.eINSTANCE.createXtendTypeDeclaration());
if (!Strings.isEmpty(name)) {
this.sarlCapacity.setName(name);
}
}
}
/** Replies the generated SarlCapacity.
*/
@Pure
public SarlCapacity getSarlCapacity() {
return this.sarlCapacity;
}
/** Replies the resource to which the SarlCapacity is attached.
*/
@Pure
public Resource eResource() {
return getSarlCapacity().eResource();
}
/** Change the documentation of the element.
*
* <p>The documentation will be displayed just before the element.
*
* @param doc the documentation.
*/
public void setDocumentation(String doc) {
if (Strings.isEmpty(doc)) {
getSarlCapacity().eAdapters().removeIf(new Predicate<Adapter>() {
public boolean test(Adapter adapter) {
return adapter.isAdapterForType(DocumentationAdapter.class);
}
});
} else {
DocumentationAdapter adapter = (DocumentationAdapter) EcoreUtil.getExistingAdapter(
getSarlCapacity(), DocumentationAdapter.class);
if (adapter == null) {
adapter = new DocumentationAdapter();
getSarlCapacity().eAdapters().add(adapter);
}
adapter.setDocumentation(doc);
}
}
/** Add the super type.
* @param superType the qualified name of the super type.
*/
public void addExtends(String superType) {
if (!Strings.isEmpty(superType)
&& !Capacity.class.getName().equals(superType)) {
JvmParameterizedTypeReference superTypeRef = newTypeRef(this.sarlCapacity, superType);
JvmTypeReference baseTypeRef = findType(this.sarlCapacity, Capacity.class.getCanonicalName());
if (isSubTypeOf(this.sarlCapacity, superTypeRef, baseTypeRef)) {
this.sarlCapacity.getExtends().add(superTypeRef);
return;
}
}
}
/** Add a modifier.
* @param modifier the modifier to add.
*/
public void addModifier(String modifier) {
if (!Strings.isEmpty(modifier)) {
this.sarlCapacity.getModifiers().add(modifier);
}
}
@Inject
private Provider<ISarlActionBuilder> iSarlActionBuilderProvider;
/** Create a SarlAction.
* @param name the name of the SarlAction.
* @return the builder.
*/
public ISarlActionBuilder addDefSarlAction(String name) {
ISarlActionBuilder builder = this.iSarlActionBuilderProvider.get();
builder.eInit(getSarlCapacity(), name, "def", getTypeResolutionContext());
return builder;
}
/** Create a SarlAction.
* @param name the name of the SarlAction.
* @return the builder.
*/
public ISarlActionBuilder addOverrideSarlAction(String name) {
ISarlActionBuilder builder = this.iSarlActionBuilderProvider.get();
builder.eInit(getSarlCapacity(), name, "override", getTypeResolutionContext());
return builder;
}
/** Create a SarlAction. *
* <p>This function is equivalent to {@link #addDefSarlAction}.
* @param name the name of the SarlAction.
* @return the builder.
*/
public ISarlActionBuilder addSarlAction(String name) {
return this.addDefSarlAction(name);
}
}