Commit 1d65fdbe authored by Malte Heithoff's avatar Malte Heithoff
Browse files

Merge branch 'master' into 'UpdateVersions'

# Conflicts:
#   pom.xml
parents 61ac26f2 cb4f1563
Pipeline #325211 passed with stage
in 1 minute and 46 seconds
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.monticar.emadl.tagging.dltag;
import de.monticore.lang.tagging._symboltable.TagKind;
import de.monticore.lang.tagging._symboltable.TagSymbol;
public class LayerPathParameterSymbol extends TagSymbol {
public static final LayerPathParameterKind KIND = LayerPathParameterKind.INSTANCE;
public LayerPathParameterSymbol() {
super(KIND, ".");
}
public LayerPathParameterSymbol(String path, String name) {
this(KIND, path, name);
}
public LayerPathParameterSymbol(LayerPathParameterKind kind, String path, String name) {
super(kind, path, name);
}
public String getPath() {
return getValue(0);
}
public String getId() {
return getValue(1);
}
@Override
public String toString() {
return super.toString();
}
public static class LayerPathParameterKind extends TagKind {
public static final LayerPathParameterKind INSTANCE = new LayerPathParameterKind();
protected LayerPathParameterKind() {
}
}
}
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.monticar.emadl.tagging.dltag;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.EMAComponentSymbol;
import de.monticore.lang.embeddedmontiarcdynamic.embeddedmontiarcdynamic._symboltable.instanceStructure.EMADynamicComponentInstantiationSymbol;
import de.monticore.lang.tagging._ast.ASTNameScope;
import de.monticore.lang.tagging._ast.ASTTag;
import de.monticore.lang.tagging._ast.ASTTagBody;
import de.monticore.lang.tagging._ast.ASTTaggingUnit;
import de.monticore.lang.tagging._symboltable.TagSymbolCreator;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.monticore.symboltable.SymbolKind;
import de.monticore.types.types._ast.ASTQualifiedName;
import de.se_rwth.commons.Joiners;
import de.se_rwth.commons.logging.Log;
import org.apache.commons.lang3.StringUtils;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class LayerPathParameterSymbolCreator implements TagSymbolCreator {
protected final String regexExpression = "\\s*\\{\\s*path\\s*=\\s*(.*)\\s*,\\s*id\\s*=\\s*(.*)\\s*\\}\\s*";
protected final Pattern pattern = Pattern.compile(regexExpression, Pattern.MULTILINE);
@Override
public void create(ASTTaggingUnit unit, TaggingResolver tagging) {
boolean hasLayerPathParameterTag =
unit.getQualifiedNameList().stream()
.map(ASTQualifiedName::toString)
.anyMatch(n -> n.endsWith("LayerPathParameterTagSchema"));
if (!hasLayerPathParameterTag) {
return;
}
final String packageName = Joiners.DOT.join(unit.getPackageList());
final ASTTagBody tagBody = unit.getTagBody();
final String root =
(tagBody.getTargetModelOpt().isPresent()) ?
Joiners.DOT.join(packageName, tagBody.getTargetModelOpt().get()
.getQualifiedNameString()) :
packageName;
for (ASTTag tag : unit.getTagBody().getTagList()) {
addTag(tag, tagging, root, EMADynamicComponentInstantiationSymbol.KIND);
addTag(tag, tagging, root, EMAComponentSymbol.KIND);
}
}
protected void addTag(ASTTag tag, TaggingResolver tagging, String root, SymbolKind kind) {
tag.getTagElementList().stream()
.filter(tagElement -> tagElement.getName().equals("LayerPathParameter"))
.forEachOrdered(tagElement -> {
Matcher matcher = matchRegexPattern(tagElement.getTagValue());
tag.getScopeList().stream()
.filter(scope -> scope.getScopeKind().equals("NameScope"))
.map(scope -> (ASTNameScope) scope)
.map(scope ->
tagging.resolve(dotJoin(root, scope.getQualifiedNameString()), kind)
)
.filter(Optional::isPresent)
.map(Optional::get)
.forEachOrdered(scope ->
tagging.addTag(scope, new LayerPathParameterSymbol(matcher.group(1), matcher.group(2)))
);
});
}
protected Matcher matchRegexPattern(String regex) {
Matcher matcher = pattern.matcher(regex);
if (matcher.matches()) {
return matcher;
}
else {
Log.error(
String.format(
"'%s' does not match the specified regex pattern '%s'",
regex, "{path = {LayerPathParameter}, name = {tagId}}"
)
);
return null;
}
}
protected String dotJoin(String root, String name) {
if (StringUtils.isEmpty(root)) {
return name;
}
else {
return Joiners.DOT.join(root, name);
}
}
}
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.monticar.emadl.tagging.dltag;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.monticore.symboltable.resolving.CommonResolvingFilter;
public class LayerPathParameterTagSchema {
protected static LayerPathParameterTagSchema instance = null;
protected LayerPathParameterTagSchema() {
}
protected static LayerPathParameterTagSchema getInstance() {
if (instance == null) {
instance = new LayerPathParameterTagSchema();
}
return instance;
}
protected void doRegisterTagTypes(TaggingResolver tagging) {
tagging.addTagSymbolCreator(new LayerPathParameterSymbolCreator());
tagging.addTagSymbolResolvingFilter(CommonResolvingFilter.create(LayerPathParameterSymbol.KIND));
}
public static void registerTagTypes(TaggingResolver tagging) {
getInstance().doRegisterTagTypes(tagging);
}
}
......@@ -14,6 +14,7 @@ import de.monticore.lang.monticar.emadl.AbstractTaggingResolverTest;
import de.monticore.lang.tagging._symboltable.TagSymbol;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.monticore.lang.monticar.emadl.tagging.dltag.DataPathSymbol;
import de.monticore.lang.monticar.emadl.tagging.dltag.LayerPathParameterSymbol;
import org.junit.Test;
......@@ -32,9 +33,9 @@ public class TaggingTest extends AbstractTaggingResolverTest {
Collection<TagSymbol> tags = tagging.getTags(symbol, DataPathSymbol.KIND);
assertEquals(1, tags.size());
DataPathSymbol tag = (DataPathSymbol) tags.iterator().next();
assertEquals(tag.getPath(), "data");
assertEquals(tag.getType(), "random");
DataPathSymbol tagDataPath = (DataPathSymbol) tags.iterator().next();
assertEquals(tagDataPath.getPath(), "data");
assertEquals(tagDataPath.getType(), "random");
}
@Test
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment