Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
languages
EmbeddedMontiArc
Commits
cb780ed0
Commit
cb780ed0
authored
Oct 07, 2017
by
Yannick Deuster
Browse files
tests for EMA tagging
parent
76aa6705
Changes
44
Expand all
Hide whitespace changes
Inline
Side-by-side
src/test/java/de/monticore/lang/embeddedmontiarc/tag/IsTraceableSymbol.java
0 → 100644
View file @
cb780ed0
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() {
// }
// }
//}
src/test/java/de/monticore/lang/embeddedmontiarc/tag/IsTraceableSymbolCreator.java
0 → 100644
View file @
cb780ed0
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;
// }
//}
src/test/java/de/monticore/lang/embeddedmontiarc/tag/PowerConsumptionSymbol.java
0 → 100644
View file @
cb780ed0
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() {
// }
// }
//}
src/test/java/de/monticore/lang/embeddedmontiarc/tag/PowerConsumptionSymbolCreator.java
0 → 100644
View file @
cb780ed0
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;
// }
//}
src/test/java/de/monticore/lang/embeddedmontiarc/tag/TagTest.java
0 → 100644
View file @
cb780ed0
This diff is collapsed.
Click to expand it.
src/test/java/de/monticore/lang/embeddedmontiarc/tag/drawing/ComponentLayoutSymbol.java
0 → 100644
View file @
cb780ed0
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
()
{
}
}
}
src/test/java/de/monticore/lang/embeddedmontiarc/tag/drawing/ComponentLayoutSymbolCreator.java
0 → 100644
View file @
cb780ed0
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
)
.
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
)
// if the symbol is not present, does not mean that the symbol
.
map
(
Optional:
:
get
)
// is not available at all, maybe it will be loaded later
.
forEachOrdered
(
s
->
s
.
addTag
(
new
ComponentLayoutSymbol
(
Integer
.
parseInt
(
m
.
group
(
1
)),
Integer
.
parseInt
(
m
.
group
(
2
)),
Integer
.
parseInt
(
m
.
group
(
3
)),
Integer
.
parseInt
(
m
.
group
(
4
)),
Integer
.
parseInt
(
m
.
group
(
5
)),
Integer
.
parseInt
(
m
.
group
(
6
)),
m
.
group
(
8
)
!=
null
,
Integer
.
parseInt
(
m
.
group
(
7
)))))
);
}
}
protected
Matcher
matchRegexPattern
(
String
regex
)
{
Matcher
matcher
=
pattern
.
matcher
(
regex
);
if
(
matcher
.
matches
())
{
return
matcher
;
}
Log
.
error
(
String
.
format
(
"'%s' does not match the specified regex pattern '%s'"
,
regex
,
"id = {id} , pos = ({x} , {y}) , size = ({width} , {height}) ,"
+
"layoutPosition = {layoutPosition} , reservedHorizontalSpace = {reservedHorizontalSpace}"
+
"( , isOnTop)?"
));
return
null
;
}
protected
boolean
checkScope
(
ASTScope
scope
)
{
if
(
scope
.
getScopeKind
().
equals
(
"NameScope"
))
{
return
true
;
}
Log
.
error
(
String
.
format
(
"Invalid scope kind: '%s'. ComponentLayout expects as scope kind 'NameScope'."
,
scope
.
getScopeKind
()));
return
false
;
}
}
src/test/java/de/monticore/lang/embeddedmontiarc/tag/drawing/ConnectorLayoutSymbol.java
0 → 100644
View file @
cb780ed0
package
de.monticore.lang.embeddedmontiarc.tag.drawing
;
public
class
ConnectorLayoutSymbol
extends
DrawableSymbol
{
public
static
final
ConnectorLayoutKind
KIND
=
ConnectorLayoutKind
.
INSTANCE
;
public
ConnectorLayoutSymbol
(
int
id
,
int
x
,
int
y
,
int
endX
,
int
endY
,
int
midX
,
int
midY
)
{
super
(
KIND
,
id
,
x
,
y
);
addValues
(
endX
,
endY
,
midX
,
midY
);
}
protected
ConnectorLayoutSymbol
(
ConnectorLayoutKind
kind
,
int
id
,
int
x
,
int
y
,
int
endX
,
int
endY
,
int
midX
,
int
midY
)
{
super
(
kind
,
id
,
x
,
y
);
addValues
(
endX
,
endY
,
midX
,
midY
);
}
public
int
getEndX
()
{
return
getValue
(
3
);
}
public
int
getEndY
()
{
return
getValue
(
4
);
}
public
int
getMidX
()
{
return
getValue
(
5
);
}
public
int
getMidY
()
{
return
getValue
(
6
);
}
@Override
public
String
toString
()
{
return
String
.
format
(
"connectorLayout { id=%d, startVal=(%d, %d), endVal=(%d, %d), mid=(%d, %d) }"
,
getId
(),
getX
(),
getY
(),
getEndX
(),
getEndY
(),
getMidX
(),
getMidY
());
}
public
static
class
ConnectorLayoutKind
extends
DrawableKind
{
public
static
final
ConnectorLayoutKind
INSTANCE
=
new
ConnectorLayoutKind
();
protected
ConnectorLayoutKind
()
{
}
}
}
src/test/java/de/monticore/lang/embeddedmontiarc/tag/drawing/ConnectorLayoutSymbolCreator.java
0 → 100644
View file @
cb780ed0
package
de.monticore.lang.embeddedmontiarc.tag.drawing
;
import
de.monticore.lang.montiarc.montiarc._symboltable.ConnectorSymbol
;
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
ConnectorLayoutSymbolCreator
implements
TagSymbolCreator
{
/**
* regular expression pattern:
* id = {id} , pos = ({x} , {y}) , endVal = ({endX} , {endY}) , mid = ({midX} , {midY})
* \s*id\s*=\s*([1-9]\d*)\s*,\s*pos\s*=\s*\(([1-9]\d*)\s*,\s*([1-9]\d*)\)\s*,
* \s*endVal\s*=\s*\(([1-9]\d*)\s*,\s*([1-9]\d*)\)\s*,\s*mid\s*=\s*\(([1-9]\d*)\s*,\s*([1-9]\d*)\)\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*end\\s*=\\s*\\(([1-9]\\d*)\\s*,"
+
"\\s*([1-9]\\d*)\\)\\s*,\\s*mid\\s*=\\s*\\(([1-9]\\d*)\\s*,"
+
"\\s*([1-9]\\d*)\\)\\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 no