Commit b725071a authored by Ferdinand Alexander Mehlan's avatar Ferdinand Alexander Mehlan
Browse files

fix creator template

parent 9b8c8052
Pipeline #64236 passed with stage
in 52 seconds
......@@ -63,7 +63,7 @@ public class ${tagTypeName}SymbolCreator implements TagSymbolCreator {
for (ASTTag element : unit.getTagBody().getTagList()) {
element.getTagElementList().stream()
.filter(t -> t.getName().equals("${tagTypeName}"))
.filter(t -> !t.getTagValueOpt().isPresent())
.filter(t -> t.isPresentTagValue)
.map(t -> matchRegexPattern(t.getTagValueOpt().get()))
.filter(r -> r != null)
.forEachOrdered(m ->
......
......@@ -66,7 +66,7 @@ public class ${tagTypeName}SymbolCreator implements TagSymbolCreator {
for (ASTTag element : unit.getTagBody().getTagList()) {
element.getTagElementList().stream()
.filter(t -> t.getName().equals("${tagTypeName}"))
.filter(t -> !t.getTagValueOpt().isPresent())
.filter(t -> t.isPresentTagValue)
.map(t -> checkContent(t.getTagValueOpt().get()))
.filter(r -> r != null)
<#if isUnit>
......
......@@ -138,4 +138,16 @@ public class GeneratorTest {
generator.generate(Paths.get("PhysicalTags"), Paths.get("src/test/resources/nfp"), symbolScopeMap);
}
@Test
public void testOCL2JavaTag() throws Exception {
GeneratorSetup setup = new GeneratorSetup();
setup.setOutputDirectory(getPathFromRelativePath("src/test/resources/generator").toFile());
setup.setTracing(true);
TagSchemaGenerator generator = new TagSchemaGenerator(setup);
Map<String, String> symbolScopeMap = new LinkedHashMap<>();
symbolScopeMap.put("CDType", "NameScope");
generator.generate(Paths.get("OCL2JavaTags"), Paths.get("src/test/resources/tags"), symbolScopeMap);
}
}
/* generated by template templates.de.monticore.lang.tagschema.TagSchema*/
package nfp.OCL2JavaTags;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.monticore.symboltable.resolving.CommonResolvingFilter;
/**
* generated by TagSchema.ftl
*/
public class OCL2JavaTags {
protected static OCL2JavaTags instance = null;
protected OCL2JavaTags() {}
protected static OCL2JavaTags getInstance() {
if (instance == null) {
instance = new OCL2JavaTags();
}
return instance;
}
protected void doRegisterTagTypes(TaggingResolver tagging) {
tagging.addTagSymbolCreator(new SymbolNameSymbolCreator());
tagging.addTagSymbolResolvingFilter(CommonResolvingFilter.create(SymbolNameSymbol.KIND));
}
public static void registerTagTypes(TaggingResolver tagging) {
getInstance().doRegisterTagTypes(tagging);
}
}
\ No newline at end of file
/* generated by template templates.de.monticore.lang.tagschema.ValuedTagType*/
package nfp.OCL2JavaTags;
import de.monticore.lang.tagging._symboltable.TagKind;
import de.monticore.lang.tagging._symboltable.TagSymbol;
/**
* Created by ValuedTagType.ftl
*/
public class SymbolNameSymbol extends TagSymbol {
public static final SymbolNameKind KIND = SymbolNameKind.INSTANCE;
public SymbolNameSymbol(String value) {
super(KIND, value);
}
protected SymbolNameSymbol(SymbolNameKind kind, String value) {
super(kind, value);
}
public String getValue() {
return getValue(0);
}
@Override
public String toString() {
return String.format("SymbolName = \"%s\"",
getValue().toString());
}
public static class SymbolNameKind extends TagKind {
public static final SymbolNameKind INSTANCE = new SymbolNameKind();
protected SymbolNameKind() {
}
}
}
\ No newline at end of file
/* generated by template templates.de.monticore.lang.tagschema.ValuedTagTypeCreator*/
package nfp.OCL2JavaTags;
import java.util.Collection;
import java.util.Optional;
import java.util.stream.Collectors;
import de.monticore.umlcd4a.symboltable.CDTypeSymbol;
import de.monticore.lang.tagging._ast.ASTNameScope;
import de.monticore.lang.tagging._ast.ASTScope;
import de.monticore.lang.tagging._ast.ASTTag;
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.Scope;
import de.monticore.symboltable.Symbol;
import de.se_rwth.commons.Joiners;
import de.se_rwth.commons.logging.Log;
import de.monticore.lang.tagvalue._parser.TagValueParser;
import de.monticore.lang.tagvalue._ast.ASTStringTagValue;
/**
* created by ValuedTagTypeCreator.ftl
*/
public class SymbolNameSymbolCreator 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, TaggingResolver tagging) {
if (unit.getQualifiedNameList().stream()
.map(q -> q.toString())
.filter(n -> n.endsWith("OCL2JavaTags"))
.count() == 0) {
return; // the tagging model is not conform to the OCL2JavaTags tagging schema
}
final String packageName = Joiners.DOT.join(unit.getPackageList());
final String rootCmp = // if-else does not work b/c of final (required by streams)
(unit.getTagBody().getTargetModelOpt().isPresent()) ?
Joiners.DOT.join(packageName, ((ASTNameScope) unit.getTagBody().getTargetModelOpt().get())
.getQualifiedName().toString()) :
packageName;
for (ASTTag element : unit.getTagBody().getTagList()) {
element.getTagElementList().stream()
.filter(t -> t.getName().equals("SymbolName"))
.filter(t -> !t.getTagValueOpt().isPresent())
.map(t -> checkContent(t.getTagValueOpt().get()))
.filter(r -> r != null)
.forEachOrdered(v ->
element.getScopeList().stream()
.filter(this::checkScope)
.map(s -> (ASTNameScope) s)
.map(s -> tagging.resolve(Joiners.DOT.join(rootCmp, // resolve down does not try to reload symbol
s.getQualifiedName().toString()), CDTypeSymbol.KIND))
.filter(Optional::isPresent)
.map(Optional::get)
.forEachOrdered(s -> tagging.addTag(s, new SymbolNameSymbol(v))));
}
}
protected String checkContent(String s) {
TagValueParser parser = new TagValueParser();
Optional<ASTStringTagValue> ast;
try {
boolean enableFailQuick = Log.isFailQuickEnabled();
Log.enableFailQuick(false);
long errorCount = Log.getErrorCount();
ast = parser.parseStringTagValue(s);
Log.enableFailQuick(enableFailQuick);
if (Log.getErrorCount() > errorCount) {
throw new Exception("Error occured during parsing.");
}
} catch (Exception e) {
Log.error(String.format("0xT0004 Could not parse %s with TagValueParser#parseStringTagValue.",
s), e);
return null;
}
if (!ast.isPresent()) {
return null;
}
return ast.get().getString();
}
protected CDTypeSymbol checkKind(Collection<Symbol> symbols) {
CDTypeSymbol ret = null;
for (Symbol symbol : symbols) {
if (symbol.getKind().isSame(CDTypeSymbol.KIND)) {
if (ret != null) {
Log.error(String.format("0xA4095 Found more than one symbol: '%s' and '%s'",
ret, symbol));
return null;
}
ret = (CDTypeSymbol)symbol;
}
}
if (ret == null) {
Log.error(String.format("0xT0001 Invalid symbol kinds: %s. tagTypeName expects as symbol kind 'CDTypeSymbol.KIND'.",
symbols.stream().map(s -> "'" + s.getKind().toString() + "'").collect(Collectors.joining(", "))));
return null;
}
return ret;
}
protected boolean checkScope(ASTScope scope) {
if (scope.getScopeKind().equals("NameScope")) {
return true;
}
Log.error(String.format("0xT0005 Invalid scope kind: '%s'. SymbolName expects as scope kind 'NameScope'.",
scope.getScopeKind()), scope.get_SourcePositionStart());
return false;
}
}
\ No newline at end of file
package nfp;
import de.monticore.umlcd4a.symboltable.CDTypeSymbol;
tagschema OCL2JavaTags {
tagtype SymbolName:String for CDType;
}
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