Commit c91a085b authored by vonwenckstern's avatar vonwenckstern Committed by GitHub
Browse files

Merge pull request #1 from EmbeddedMontiArc/yannick.deuster

Yannick.deuster
parents 2335e388 b501d3f2
......@@ -42,7 +42,7 @@
<!-- .. SE-Libraries .................................................. -->
<monticore.version>4.5.3-SNAPSHOT</monticore.version>
<monticore.version>4.5.2.1</monticore.version>
<se-commons.version>1.7.7</se-commons.version>
<mc.grammars.assembly.version>0.0.6-SNAPSHOT</mc.grammars.assembly.version>
<languages.version>4.0.1-SNAPSHOT</languages.version>
......@@ -376,6 +376,14 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
......
......@@ -36,7 +36,7 @@ import java.util.Optional;
*
* @author Robert Heim
*/
public class ComponentInstanceSymbol extends TaggingScopeSpanningSymbol {
public class ComponentInstanceSymbol extends TaggingScopeSpanningSymbol implements ElementInstance {
public static final EMAComponentInstanceKind KIND = EMAComponentInstanceKind.INSTANCE;
......
......@@ -38,7 +38,7 @@ import java.util.Optional;
*
* @author Arne Haber, Michael von Wenckstern
*/
public class ConnectorSymbol extends TaggingSymbol {
public class ConnectorSymbol extends TaggingSymbol implements ElementInstance {
/* generated by template symboltable.symbols.KindConstantDeclaration*/
......
package de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable;
import de.monticore.lang.montiarc.tagging._symboltable.TagKind;
import de.monticore.lang.montiarc.tagging._symboltable.TagSymbol;
import de.monticore.symboltable.Scope;
import java.util.Collection;
/**
* Created by kt on 27.02.2017.
*/
public interface ElementInstance {
public Collection<TagSymbol> getTags();
public <T extends TagSymbol> Collection<T> getTags(final TagKind tagKind);
public String getName();
public Scope getEnclosingScope() ;
}
......@@ -88,7 +88,7 @@ import java.util.stream.Collectors;
* standard symbol table mechanism
*/
public class ExpandedComponentInstanceSymbol
extends TaggingScopeSpanningSymbol {
extends TaggingScopeSpanningSymbol implements ElementInstance {
public static final EMAExpandedComponentInstanceKind KIND = new EMAExpandedComponentInstanceKind();
......
......@@ -37,7 +37,7 @@ import java.util.stream.Collectors;
/**
* Symboltable entry for ports.
*/
public class PortSymbol extends TaggingSymbol {
public class PortSymbol extends TaggingSymbol implements ElementInstance {
public static final EmbeddedPortKind KIND = EmbeddedPortKind.INSTANCE;
private final Map<String, Optional<String>> stereotype = new HashMap<>();
......@@ -262,4 +262,48 @@ public class PortSymbol extends TaggingSymbol {
public boolean isPartOfPortArray() {
return getName().contains("[") && getName().contains("]");
}
/**
* if model input is;
* component X {
* port ...;
*
* component A {
* port in Integer p1,
* out Integer p2;
* }
*
* component A a1, a2, a3;
*
* connect a1.p2 -> a2.p1, a3.p1;
* }
*
* if I have the port symbol a1.p2 than this method returns the list of port symbols {a2.p1, a3.p1}
* @return
*/
public List<PortSymbol> getTargetConnectedPorts(ExpandedComponentInstanceSymbol topComponent) {
//It does not works for components, when one of them is top component and another not.
List<PortSymbol> targetPorts = new ArrayList<>();
if(!topComponent.getConnectors().equals(null))
{
//If the port is Outgoing then return incoming ports of connected components
if(this.isOutgoing()) {
topComponent.getConnectors().stream()
.filter(s -> s.getSourcePort().equals(this))
.forEach(s -> targetPorts.add(s.getTargetPort()));
} else if(this.isIncoming())
{
//If the port is incoming then return outgoing ports of connected components
topComponent.getConnectors().stream()
.filter(s -> s.getTargetPort().equals(this))
.forEach(s -> targetPorts.add(s.getSourcePort()));
}
}
return targetPorts;
//TODO: Find the way to get connections from the top element
}
}
package nfp;
tagschema PowerConsumptionTagSchema {
tagtype PowerConsumption: Power for ComponentInstance;
tagtype PowerTester: String for Port;
tagtype PowerId: Number for Component;
tagtype PowerBoolean: Boolean for Connector;
}
\ No newline at end of file
package de.monticore.lang.embeddedmontiarc.tag;//package de.monticore.lang.montiarc.tag;
//
//import de.monticore.lang.montiarc.tagging._symboltable.TagKind;
//import de.monticore.lang.montiarc.tagging._symboltable.TagSymbol;
//
///**
// * Created by Michael von Wenckstern on 31.05.2016.
// */
//public class IsTraceableSymbol extends TagSymbol {
// public static final TraceabilityKind KIND = TraceabilityKind.INSTANCE;
//
// /**
// * is marker symbol so it has no value by itself
// */
// public IsTraceableSymbol() {
// // true to set that it is marked
// super(KIND);
// }
//
// @Override
// public String toString() {
// return "IsTraceable";
// }
//
// public static class TraceabilityKind extends TagKind {
// public static final TraceabilityKind INSTANCE = new TraceabilityKind();
//
// protected TraceabilityKind() {
// }
// }
//}
package de.monticore.lang.embeddedmontiarc.tag;//package de.monticore.lang.montiarc.tag;
//
//import java.util.Optional;
//
//import de.monticore.lang.montiarc.montiarc._symboltable.ComponentSymbol;
//import de.monticore.lang.montiarc.tagging._ast.ASTNameScope;
//import de.monticore.lang.montiarc.tagging._ast.ASTScope;
//import de.monticore.lang.montiarc.tagging._ast.ASTTag;
//import de.monticore.lang.montiarc.tagging._ast.ASTTaggingUnit;
//import de.monticore.lang.montiarc.tagging._symboltable.TagSymbolCreator;
//import de.monticore.symboltable.Scope;
//import de.se_rwth.commons.Joiners;
//import de.se_rwth.commons.logging.Log;
//
///**
// * Created by Michael von Wenckstern on 31.05.2016.
// * only for this tests --> this should be generated using the tag schema
// */
//public class IsTraceableSymbolCreator implements TagSymbolCreator {
//
// public static Scope getGlobalScope(final Scope scope) {
// Scope s = scope;
// while (s.getEnclosingScope().isPresent()) {
// s = s.getEnclosingScope().get();
// }
// return s;
// }
//
// public void create(ASTTaggingUnit unit, Scope gs) {
// if (unit.getQualifiedNames().stream()
// .map(q -> q.toString())
// .filter(n -> n.endsWith("TraceabilityTagSchema"))
// .count() == 0) {
// return; // the tagging model is not conform to the traceability tagging schema
// }
// final String packageName = Joiners.DOT.join(unit.getPackage());
// final String rootCmp = // if-else does not work b/c of final (required by streams)
// (unit.getTagBody().getTargetModel().isPresent()) ?
// Joiners.DOT.join(packageName, ((ASTNameScope) unit.getTagBody().getTargetModel().get())
// .getQualifiedName().toString()) :
// packageName;
//
// for (ASTTag element : unit.getTagBody().getTags()) {
// element.getTagElements().stream()
// .filter(t -> t.getName().equals("IsTraceable"))
// .filter(t -> !t.getTagValue().isPresent()) // only marker tag with no value
// .forEachOrdered(t ->
// element.getScopes().stream()
// .filter(this::checkScope)
// .map(s -> (ASTNameScope) s)
// .map(s -> getGlobalScope(gs).<ComponentSymbol>resolveDown(
// Joiners.DOT.join(rootCmp, s.getQualifiedName().toString()),
// ComponentSymbol.KIND))
// .filter(Optional::isPresent)
// .map(Optional::get)
// .forEachOrdered(s -> s.addTag(new IsTraceableSymbol())));
// }
// }
//
//
// protected boolean checkScope(ASTScope scope) {
// if (scope.getScopeKind().equals("NameScope")) {
// return true;
// }
// Log.error(String.format("0xT0005 Invalid scope kind: '%s'. IsTraceable expects as scope kind 'NameScope'.",
// scope.getScopeKind()), scope.get_SourcePositionStart());
// return false;
// }
//}
package de.monticore.lang.embeddedmontiarc.tag;//package de.monticore.lang.montiarc.tag;
//
//import de.monticore.lang.montiarc.helper.IndentPrinter;
//import de.monticore.lang.montiarc.tagging._symboltable.TagKind;
//import de.monticore.lang.montiarc.tagging._symboltable.TagSymbol;
//import de.monticore.lang.montiarc.unit.Power;
//
///**
// * Created by Michael von Wenckstern on 31.05.2016.
// */
//public class PowerConsumptionSymbol extends TagSymbol {
// public static final PowerConsumptionKind KIND = PowerConsumptionKind.INSTANCE;
//
// /**
// * is marker symbol so it has no value by itself
// */
// public PowerConsumptionSymbol(double value, Power unit) {
// // true to set that it is marked
// super(KIND, value, unit);
// }
//
// public double getNumber() {
// return getValue(0);
// }
//
// public Power getUnit() {
// return getValue(1);
// }
//
// @Override
// public String toString() {
// return IndentPrinter.groups("PowerConsumption = {0} {1}")
// .params(getNumber(), getUnit())
// .toString();
// }
//
// public static class PowerConsumptionKind extends TagKind {
// public static final PowerConsumptionKind INSTANCE = new PowerConsumptionKind();
//
// protected PowerConsumptionKind() {
// }
// }
//}
package de.monticore.lang.embeddedmontiarc.tag;//package de.monticore.lang.montiarc.tag;
//
//import java.util.Optional;
//
//import de.monticore.lang.montiarc.montiarc._symboltable.ExpandedComponentInstanceSymbol;
//import de.monticore.lang.montiarc.tagging._ast.ASTNameScope;
//import de.monticore.lang.montiarc.tagging._ast.ASTScope;
//import de.monticore.lang.montiarc.tagging._ast.ASTTag;
//import de.monticore.lang.montiarc.tagging._ast.ASTTagElement;
//import de.monticore.lang.montiarc.tagging._ast.ASTTaggingUnit;
//import de.monticore.lang.montiarc.tagging._ast.ASTTargetElement;
//import de.monticore.lang.montiarc.tagging._ast.ASTUnitTagValue;
//import de.monticore.lang.montiarc.tagging._ast.ASTValuedTag;
//import de.monticore.lang.montiarc.tagging._symboltable.TagSymbolCreator;
//import de.monticore.lang.montiarc.unit.Unit;
//import de.monticore.lang.montiarc.unit.Units;
//import de.monticore.literals.literals._ast.ASTDoubleLiteral;
//import de.monticore.literals.literals._ast.ASTFloatLiteral;
//import de.monticore.literals.literals._ast.ASTIntLiteral;
//import de.monticore.literals.literals._ast.ASTLongLiteral;
//import de.monticore.literals.literals._ast.ASTNumericLiteral;
//import de.monticore.literals.literals._ast.ASTSignedDoubleLiteral;
//import de.monticore.literals.literals._ast.ASTSignedFloatLiteral;
//import de.monticore.literals.literals._ast.ASTSignedIntLiteral;
//import de.monticore.literals.literals._ast.ASTSignedLongLiteral;
//import de.monticore.symboltable.Scope;
//import de.se_rwth.commons.Joiners;
//import de.se_rwth.commons.logging.Log;
//
///**
// * Created by Michael von Wenckstern on 31.05.2016.
// * only for this tests --> this should be generated using the tag schema
// */
//public class PowerConsumptionSymbolCreator implements TagSymbolCreator {
// // TODO ASTNumericLiteral should have a getValue() method
// protected static double getValue(ASTNumericLiteral numericLiteral) {
// if (numericLiteral instanceof ASTDoubleLiteral) {
// return ((ASTDoubleLiteral) numericLiteral).getValue();
// }
// else if (numericLiteral instanceof ASTSignedDoubleLiteral) {
// return ((ASTSignedDoubleLiteral) numericLiteral).getValue();
// }
// else if (numericLiteral instanceof ASTIntLiteral) {
// return ((ASTIntLiteral) numericLiteral).getValue();
// }
// else if (numericLiteral instanceof ASTSignedIntLiteral) {
// return ((ASTSignedIntLiteral) numericLiteral).getValue();
// }
// else if (numericLiteral instanceof ASTFloatLiteral) {
// return ((ASTFloatLiteral) numericLiteral).getValue();
// }
// else if (numericLiteral instanceof ASTSignedFloatLiteral) {
// return ((ASTSignedFloatLiteral) numericLiteral).getValue();
// }
// else if (numericLiteral instanceof ASTLongLiteral) {
// return ((ASTLongLiteral) numericLiteral).getValue();
// }
// else if (numericLiteral instanceof ASTSignedLongLiteral) {
// return ((ASTSignedLongLiteral) numericLiteral).getValue();
// }
// else {
// throw new Error("unexpected ASTNumericLiteral: " + numericLiteral.getClass());
// }
// }
//
// public static Scope getGlobalScope(final Scope scope) {
// Scope s = scope;
// while (s.getEnclosingScope().isPresent()) {
// s = s.getEnclosingScope().get();
// }
// return s;
// }
//
// public void create(ASTTaggingUnit unit, Scope gs) {
// if (unit.getQualifiedNames().stream()
// .map(q -> q.toString())
// .filter(n -> n.endsWith("PowerConsumptionTagSchema"))
// .count() == 0) {
// return; // the tagging model is not conform to the traceability tagging schema
// }
// final String packageName = Joiners.DOT.join(unit.getPackage());
// final String rootCmp = // if-else does not work b/c of final (required by streams)
// (unit.getTagBody().getTargetModel().isPresent()) ?
// Joiners.DOT.join(packageName, ((ASTNameScope) unit.getTagBody().getTargetModel().get())
// .getQualifiedName().toString()) :
// packageName;
//
// for (final ASTTagElement element : unit.getTagBody().getTagElements()) {
// if (element instanceof ASTTargetElement) {
// ((ASTTargetElement) element).getTags().stream()
// .filter(t -> t.getName().equals("PowerConsumption"))
// .filter(this::checkASTTagKind)
// .map(t -> (ASTValuedTag) t)
// .filter(this::checkValueKind)
// .map(v -> (ASTUnitTagValue) v.getTagValue())
// .filter(this::checkUnitKind)
// .forEachOrdered(v ->
// ((ASTTargetElement) element).getScopes().stream()
// .filter(this::checkScope)
// .map(s -> (ASTNameScope) s)
// .map(s -> getGlobalScope(gs).<ExpandedComponentInstanceSymbol>
// resolveDown(Joiners.DOT.join(rootCmp, // resolve down does not try to reload symbol
// s.getQualifiedName().toString()), ExpandedComponentInstanceSymbol.KIND))
// .filter(Optional::isPresent)
// .map(Optional::get)
// .forEachOrdered(s -> s.addTag(new PowerConsumptionSymbol(getValue(v.getNumericLiteral()),
// Units.getPower(v.getUnit()).get())))
// );
// }
// }
// }
//
// protected boolean checkUnitKind(ASTUnitTagValue unit) {
// if (Units.getPower(unit.getUnit()).isPresent()) {
// return true;
// }
// Optional<Unit> u = Units.getUnit(unit.getUnit());
// if(u.isPresent()) {
// Log.error(String.format("0xTEST1 Invalid unit kind: '%s' of unit '%s'. ComponentLayout expects as unit kind 'Power'.",
// u.get().getKind(), u.get().toString()), unit.get_SourcePositionStart(), Units.getAvailablePowerUnits());
// return false;
// }
// Log.error(String.format("0xTEST2 Unit is unknown: '%s'.", unit.getUnit()), unit.get_SourcePositionStart());
// return false;
// }
//
// protected boolean checkASTTagKind(ASTTag tag) {
// if (tag.getTagKind().equals("ValuedTag")) {
// return true;
// }
// Log.error(String.format("0xTEST3 Invalid tag kind: '%s'. ComponentLayout expects as tag kind 'ValuedTag'.",
// tag.getTagKind()), tag.get_SourcePositionStart());
// return false;
// }
//
// protected boolean checkValueKind(ASTValuedTag tag) {
// if (tag.getTagValue() != null &&
// tag.getTagValue().getValueKind().equals("UnitValue")) {
// return true;
// }
// Log.error(String.format("0xTEST4 Invalid value kind: '%s'. ComponentLayout expects as tag kind 'UnitValue'.",
// tag.getTagValue() != null ? tag.getTagValue().getValueKind() : "tag value is zero"),
// tag.get_SourcePositionStart());
// return false;
// }
//
// protected boolean checkScope(ASTScope scope) {
// if (scope.getScopeKind().equals("NameScope")) {
// return true;
// }
// Log.error(String.format("0xTEST5 Invalid scope kind: '%s'. ComponentLayout expects as scope kind 'NameScope'.",
// scope.getScopeKind()), scope.get_SourcePositionStart());
// return false;
// }
//}
package de.monticore.lang.embeddedmontiarc.tag.drawing;
public class ComponentLayoutSymbol extends DrawableSymbol {
public static final ComponentLayoutKind KIND = ComponentLayoutKind.INSTANCE;
public ComponentLayoutSymbol(int id, int x, int y, int width, int height,
int layoutPosition, boolean isOnTop, int reservedHorizontalSpace) {
super(KIND, id, x, y);
addValues(width, height, layoutPosition, isOnTop, reservedHorizontalSpace);
}
protected ComponentLayoutSymbol(ComponentLayoutKind kind, int id, int x, int y, int width, int height,
int layoutPosition, boolean isOnTop, int reservedHorizontalSpace) {
super(kind, id, x, y);
addValues(width, height, layoutPosition, isOnTop, reservedHorizontalSpace);
}
public int getWidth() {
return getValue(3);
}
public int getHeight() {
return getValue(4);
}
public int getLayoutPosition() {
return getValue(5);
}
public boolean isOnTop() {
return getValue(6);
}
public int getReservedHorizontalSpace() {
return getValue(7);
}
@Override
public String toString() {
return String.format(
"componentLayout = { id=%d, x=%d, y=%d, width=%d, height=%d, \n" +
" layoutPosition=%d, %s reservedHorizontalSpace=%d }",
getId(), getX(), getY(), getWidth(), getHeight(),
getLayoutPosition(), isOnTop() ? "isOnTop," : "", getReservedHorizontalSpace());
}
public static class ComponentLayoutKind extends DrawableKind {
public static final ComponentLayoutKind INSTANCE = new ComponentLayoutKind();
protected ComponentLayoutKind() {
}
}
}
package de.monticore.lang.embeddedmontiarc.tag.drawing;
import de.monticore.lang.montiarc.montiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.montiarc.tagging._ast.ASTNameScope;
import de.monticore.lang.montiarc.tagging._ast.ASTScope;
import de.monticore.lang.montiarc.tagging._ast.ASTTag;
import de.monticore.lang.montiarc.tagging._ast.ASTTaggingUnit;
import de.monticore.lang.montiarc.tagging._symboltable.TagSymbolCreator;
import de.monticore.symboltable.Scope;
import de.se_rwth.commons.Joiners;
import de.se_rwth.commons.logging.Log;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by MichaelvonWenckstern on 04.06.2016.
*/
public class ComponentLayoutSymbolCreator implements TagSymbolCreator {
/**
* regular expression pattern:
* id = {id} , pos = ({x} , {y}) , size = ({width} , {height}) ,
* layoutPosition = {layoutPosition} , reservedHorizontalSpace = {reservedHorizontalSpace}
* ( , isOnTop)?
* to test the pattern just enter:
* \s*id\s*=\s*([1-9]\d*)\s*,\s*pos\s*=\s*\(([1-9]\d*)\s*,\s*([1-9]\d*)\)\s*,
* \s*size\s*=\s*\(([1-9]\d*)\s*,\s*([1-9]\d*)\)\s*,\s*layoutPosition\s*=
* \s*([1-9]\d*)\s*,\s*reservedHorizontalSpace\s*=\s*([1-9]\d*)\s*(?:,\s*(isOnTop))?\s*
* at http://www.regexplanet.com/advanced/java/index.html
*/
public static final Pattern pattern = Pattern.compile(
"\\{\\s*id\\s*=\\s*([1-9]\\d*)\\s*,\\s*pos\\s*=\\s*\\(([1-9]\\d*)\\s*,\\s*"
+ "([1-9]\\d*)\\)\\s*,\\s*size\\s*=\\s*\\(([1-9]\\d*)\\s*,\\s*([1-9]"
+ "\\d*)\\)\\s*,\\s*layoutPosition\\s*=\\s*([1-9]\\d*)\\s*,\\s*"
+ "reservedHorizontalSpace\\s*=\\s*([1-9]\\d*)\\s*(?:,\\s*(isOnTop))?\\s*\\}");
public static Scope getGlobalScope(final Scope scope) {
Scope s = scope;
while (s.getEnclosingScope().isPresent()) {
s = s.getEnclosingScope().get();
}
return s;
}
public void create(ASTTaggingUnit unit, Scope gs) {
if (unit.getQualifiedNames().stream()
.map(q -> q.toString())
.filter(n -> n.endsWith("LayoutTagSchema"))
.count() == 0) {
return; // the tagging model is not conform to the traceability tagging schema
}
final String packageName = Joiners.DOT.join(unit.getPackage());
final String rootCmp = // if-else does not work b/c of final (required by streams)
(unit.getTagBody().getTargetModel().isPresent()) ?
Joiners.DOT.join(packageName, ((ASTNameScope) unit.getTagBody().getTargetModel().get())
.getQualifiedName().toString()) :
packageName;
for (ASTTag element : unit.getTagBody().getTags()) {
element.getTagElements().stream()
.filter(t -> t.getName().equals("ComponentLayout")) // after that point we can throw error messages
.filter(t -> t.getTagValue().isPresent())
.map(t -> matchRegexPattern(t.getTagValue().get()))
.filter(r -> r != null)
.forEachOrdered(m ->
element.getScopes().stream()
.filter(this::checkScope)
.map(s -> (ASTNameScope) s)