Skip to content

Commit

Permalink
Simplify Xtend provided interface getter
Browse files Browse the repository at this point in the history
The method which returns the transitive closure of provided interfaces (so
considering the super-interfaces) is simplified, it now works with a list
instead of a map (no need to store the provided signatures, they can be
determined directly from the interface).
  • Loading branch information
Jakob Bach committed Jul 19, 2016
1 parent 59648e4 commit 1050a8a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package edu.kit.ipd.sdq.cbsm.codegen

import edu.kit.ipd.sdq.cbsm.repository.ComplexType
import edu.kit.ipd.sdq.cbsm.repository.Component
import edu.kit.ipd.sdq.cbsm.repository.DataType
import edu.kit.ipd.sdq.cbsm.repository.Interface
import edu.kit.ipd.sdq.cbsm.repository.Parameter
import edu.kit.ipd.sdq.cbsm.repository.ProvidedRole
import edu.kit.ipd.sdq.cbsm.repository.Repository
import edu.kit.ipd.sdq.cbsm.repository.Signature
import edu.kit.ipd.sdq.cbsm.repository.SimpleType
import java.util.Collection
import java.util.LinkedList
import java.util.TreeSet
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.emf.ecore.util.EcoreUtil
import org.eclipse.xtext.generator.IFileSystemAccess
import org.eclipse.xtext.generator.IGenerator
import edu.kit.ipd.sdq.cbsm.repository.Signature
import edu.kit.ipd.sdq.cbsm.repository.Component
import edu.kit.ipd.sdq.cbsm.repository.DataType
import edu.kit.ipd.sdq.cbsm.repository.Parameter
import java.util.TreeSet
import java.util.Collection
import edu.kit.ipd.sdq.cbsm.repository.ProvidedRole
import java.util.LinkedList
import java.util.HashMap
import java.util.List

class CbsmRepositoryCodeGenerator implements IGenerator {

Expand Down Expand Up @@ -80,9 +78,9 @@ class CbsmRepositoryCodeGenerator implements IGenerator {
}
«ENDFOR»

«FOR providedInterfaceEntry: component.providedRoles.providedInterfacesAndSignaturesRecursive.entrySet SEPARATOR '\n'»
«FOR signature: providedInterfaceEntry.value SEPARATOR '\n'»
//Implementing «signature.name» from interface «providedInterfaceEntry.key.name»
«FOR providedInterface: component.providedRoles.providedInterfacesAndSignaturesRecursive SEPARATOR '\n'»
«FOR signature: providedInterface.signatures SEPARATOR '\n'»
//Implementing «signature.name» from interface «providedInterface.name»
@Override
public «signature.compile» {
«FOR requiredRole: component.requiredRoles»
Expand Down Expand Up @@ -114,20 +112,19 @@ class CbsmRepositoryCodeGenerator implements IGenerator {
}
/**
* Returns a map with all provided interfaces and their corresponding signatures,
* considering that provided interfaces might have super interfaces (transitive
* closure).
* Returns a list with all provided interfaces, considering that provided interfaces
* might have super-interfaces (transitive closure).
*/
def providedInterfacesAndSignaturesRecursive(Collection<ProvidedRole> providedRoles) {
val result = new HashMap<Interface, List<Signature>>
val result = new LinkedList<Interface>
val interfacesToAnalyze = new LinkedList<Interface>
providedRoles.forEach[providedRole|
interfacesToAnalyze += providedRole.providedInterface
]
while (!interfacesToAnalyze.empty) {
val interfac = interfacesToAnalyze.remove
if (!result.containsKey(interfac)) {
result.put(interfac, interfac.signatures)
if (!result.contains(interfac)) {
result += interfac
}
interfacesToAnalyze += interfac.superInterfaces
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
import edu.kit.ipd.sdq.cbsm.repository.SimpleType;
import edu.kit.ipd.sdq.cbsm.repository.SimpleTypeInstance;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Consumer;
import org.eclipse.emf.common.util.EList;
Expand Down Expand Up @@ -247,19 +243,18 @@ public CharSequence compile(final Component component, final String repositoryNa
_builder.newLine();
{
EList<ProvidedRole> _providedRoles_2 = component.getProvidedRoles();
HashMap<Interface, List<Signature>> _providedInterfacesAndSignaturesRecursive = this.providedInterfacesAndSignaturesRecursive(_providedRoles_2);
Set<Map.Entry<Interface, List<Signature>>> _entrySet = _providedInterfacesAndSignaturesRecursive.entrySet();
LinkedList<Interface> _providedInterfacesAndSignaturesRecursive = this.providedInterfacesAndSignaturesRecursive(_providedRoles_2);
boolean _hasElements_2 = false;
for(final Map.Entry<Interface, List<Signature>> providedInterfaceEntry : _entrySet) {
for(final Interface providedInterface : _providedInterfacesAndSignaturesRecursive) {
if (!_hasElements_2) {
_hasElements_2 = true;
} else {
_builder.appendImmediate("\n", "\t");
}
{
List<Signature> _value = providedInterfaceEntry.getValue();
EList<Signature> _signatures = providedInterface.getSignatures();
boolean _hasElements_3 = false;
for(final Signature signature : _value) {
for(final Signature signature : _signatures) {
if (!_hasElements_3) {
_hasElements_3 = true;
} else {
Expand All @@ -270,8 +265,7 @@ public CharSequence compile(final Component component, final String repositoryNa
String _name_11 = signature.getName();
_builder.append(_name_11, "\t");
_builder.append(" from interface ");
Interface _key = providedInterfaceEntry.getKey();
String _name_12 = _key.getName();
String _name_12 = providedInterface.getName();
_builder.append(_name_12, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
Expand Down Expand Up @@ -351,12 +345,11 @@ public TreeSet<String> uniqueSortedInterfaceNames(final Component component) {
}

/**
* Returns a map with all provided interfaces and their corresponding signatures,
* considering that provided interfaces might have super interfaces (transitive
* closure).
* Returns a list with all provided interfaces, considering that provided interfaces
* might have super-interfaces (transitive closure).
*/
public HashMap<Interface, List<Signature>> providedInterfacesAndSignaturesRecursive(final Collection<ProvidedRole> providedRoles) {
final HashMap<Interface, List<Signature>> result = new HashMap<Interface, List<Signature>>();
public LinkedList<Interface> providedInterfacesAndSignaturesRecursive(final Collection<ProvidedRole> providedRoles) {
final LinkedList<Interface> result = new LinkedList<Interface>();
final LinkedList<Interface> interfacesToAnalyze = new LinkedList<Interface>();
final Consumer<ProvidedRole> _function = (ProvidedRole providedRole) -> {
Interface _providedInterface = providedRole.getProvidedInterface();
Expand All @@ -366,11 +359,10 @@ public HashMap<Interface, List<Signature>> providedInterfacesAndSignaturesRecurs
while ((!interfacesToAnalyze.isEmpty())) {
{
final Interface interfac = interfacesToAnalyze.remove();
boolean _containsKey = result.containsKey(interfac);
boolean _not = (!_containsKey);
boolean _contains = result.contains(interfac);
boolean _not = (!_contains);
if (_not) {
EList<Signature> _signatures = interfac.getSignatures();
result.put(interfac, _signatures);
result.add(interfac);
}
EList<Interface> _superInterfaces = interfac.getSuperInterfaces();
Iterables.<Interface>addAll(interfacesToAnalyze, _superInterfaces);
Expand Down

0 comments on commit 1050a8a

Please sign in to comment.