Skip to content

Commit

Permalink
For supported the access to the inherited attributes in the agents (i…
Browse files Browse the repository at this point in the history
…ssue #49),

the agent's variables are generated as protected java fields.
  • Loading branch information
gallandarakhneorg committed May 15, 2014
1 parent 59212eb commit 3cf82ad
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

/**
* Use this class to register components to be used at runtime / without the Equinox extension registry.
*
* @author $Author: srodriguez$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
public class SARLRuntimeModule extends io.sarl.lang.AbstractSARLRuntimeModule {
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
/**
* Initialization support for running Xtext languages
* without equinox extension registry
*
* @author $Author: srodriguez$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
public class SARLStandaloneSetup extends SARLStandaloneSetupGenerated{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,20 @@ import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor
import org.eclipse.xtext.xbase.jvmmodel.JvmModelAssociator
import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder
import io.sarl.lang.SARLKeywords
import org.eclipse.xtext.common.types.JvmTypeReference

/**
* <p>Infers a JVM model from the source model.</p>
*
* <p>The JVM model should contain all elements that would appear in the Java code
* which is generated from the source model. Other models link against the JVM model rather than the source model.</p>
* which is generated from the source model. Other models link against
* the JVM model rather than the source model.</p>
*
* @author $Author: srodriguez$
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
class SARLJvmModelInferrer extends AbstractModelInferrer {

Expand All @@ -69,11 +77,9 @@ class SARLJvmModelInferrer extends AbstractModelInferrer {

@Inject protected JvmModelAssociator jvmModelAssociator

@Inject TypesFactory typesFactory
@Inject private TypesFactory typesFactory

@Inject Logger log

private Iterable<Capacity> kCapacities = null
@Inject private Logger log

/**
* The dispatch method {@code infer} is called for each instance of the
Expand Down Expand Up @@ -105,32 +111,37 @@ class SARLJvmModelInferrer extends AbstractModelInferrer {
[
documentation = element.documentation

var long serial = 1L

var JvmTypeReference parentType
if(element.superType != null){
superTypes += newTypeRef(element.superType.fullyQualifiedName.toString)
}else{
superTypes += newTypeRef(element, typeof(io.sarl.lang.core.Event))
parentType = newTypeRef(element.superType.fullyQualifiedName.toString)
serial = serial + element.superType.fullyQualifiedName.toString.hashCode
} else {
parentType = newTypeRef(element, typeof(io.sarl.lang.core.Event))
serial = serial + "io.sarl.lang.core.Event".hashCode
}

superTypes += parentType

var JvmField jvmField
var List<JvmField> jvmFields = new ArrayList()

for (feature : element.features) {
switch feature {
Attribute: {
jvmField = feature.toField(feature.name, feature.type) [
visibility = JvmVisibility::PUBLIC
documentation = feature.documentation
final = !feature.writeable
initializer = feature.initialValue
]
jvmFields.add(jvmField)
members += jvmField
members += feature.toGetter(feature.name, feature.type)
if (feature.writeable) {
members += feature.toSetter(feature.name, feature.type)
}

serial = serial + feature.name.hashCode
}
Constructor: {
generateConstructor(element, feature)
serial = serial + element.fullyQualifiedName.hashCode
}
}

Expand Down Expand Up @@ -174,6 +185,14 @@ class SARLJvmModelInferrer extends AbstractModelInferrer {
]
]

val serialValue = serial
members += element.toField("serialVersionUID", newTypeRef(long)) [
visibility = JvmVisibility::PRIVATE
final = true
static = true
initializer = [append(serialValue+"L")]
]

])
}

Expand Down Expand Up @@ -217,6 +236,7 @@ class SARLJvmModelInferrer extends AbstractModelInferrer {
}
Attribute: {
members += feature.toField(feature.name, feature.type) [
visibility = JvmVisibility::PROTECTED
documentation = feature.documentation
final = !feature.writeable
initializer = feature.initialValue
Expand Down Expand Up @@ -259,14 +279,11 @@ class SARLJvmModelInferrer extends AbstractModelInferrer {
}
Attribute: {
members += feature.toField(feature.name, feature.type) [
visibility = JvmVisibility::PROTECTED
documentation = feature.documentation
final = !feature.writeable
initializer = feature.initialValue
]
/*members += feature.toGetter(feature.name, feature.type)
if (feature.writeable) {
members += feature.toSetter(feature.name, feature.type)
}*/
}
}
}
Expand Down Expand Up @@ -304,15 +321,12 @@ class SARLJvmModelInferrer extends AbstractModelInferrer {

}
Attribute: {
members += feature.toField(feature.name, feature.type) [
documentation = feature.documentation
initializer = feature.initialValue
final = !feature.writeable
]
/*members += feature.toGetter(feature.name, feature.type)
if (feature.writeable) {
members += feature.toSetter(feature.name, feature.type)
}*/
members += feature.toField(feature.name, feature.type) [
visibility = JvmVisibility::PROTECTED
documentation = feature.documentation
final = !feature.writeable
initializer = feature.initialValue
]
}
CapacityUses: {
for (used : feature.capacitiesUsed) {
Expand Down Expand Up @@ -484,7 +498,6 @@ class SARLJvmModelInferrer extends AbstractModelInferrer {
newLine().append(declaredType.getSimpleName()+" other = (" + declaredType.getSimpleName() + ") obj;")
for (JvmField field : jvmFields) {
var String typeName = field.type.identifier
System.out.println("****DEBUG: type="+typeName)
if (Boolean.TYPE.name == typeName
|| Integer.TYPE.name == typeName
|| Long.TYPE.name == typeName
Expand Down
Loading

0 comments on commit 3cf82ad

Please sign in to comment.