updated to 5.3.0

parent f518a6a4
Pipeline #206224 failed with stage
in 2 minutes and 14 seconds
......@@ -34,7 +34,7 @@
<properties>
<Common-MontiCar.version>0.1.0-SNAPSHOT</Common-MontiCar.version>
<!-- .. SE-Libraries .................................................. -->
<monticore.version>5.0.6.NewSymTab-SNAPSHOT</monticore.version>
<monticore.version>5.3.0</monticore.version>
<se-commons.version>1.7.7</se-commons.version>
<mc.grammars.assembly.version>0.0.8</mc.grammars.assembly.version>
......@@ -45,7 +45,7 @@
<jscience.version>4.3.1</jscience.version>
<!-- .. Plugins ....................................................... -->
<monticore.plugin>5.0.6.NewSymTab-SNAPSHOT</monticore.plugin>
<monticore.plugin>5.3.0</monticore.plugin>
<assembly.plugin>2.5.4</assembly.plugin>
<compiler.plugin>3.3</compiler.plugin>
<source.plugin>2.4</source.plugin>
......@@ -130,14 +130,6 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.monticore</groupId>
<artifactId>monticore-runtime</artifactId>
<version>${monticore.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
......
......@@ -11,18 +11,18 @@ grammar Tagging extends external1.Common0 {
("package" package:(Name& || ".")+ ";")?
(ImportStatement)*
"conforms" "to" (QualifiedName || ",")+ ";"
TagBody;
Tag;
// name should be optional, but than we need an transformation step in the parser
// b/c the symbol table needs a name
// and we need the symbol table for coco checks
// maybe later for convience we make the optional
TagBody = "tags" Name? ("for" targetModel: Scope)? "{"
Tag+ "}";
symbol Tag = "tags" Name? ("for" targetModel: Scope)? "{"
TagSingle+ "}";
// interface TagElement;
Tag = "tag" (Scope || ",")+ "with" TagElement+;
TagSingle = "tag" (Scope || ",")+ "with" TagElement+;
symbol TagElement = Name (TagValue | ";");
fragment token WSS = (' ' | '\t' | '\r' | '\n');
......
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.monticore.lang.tagging._ast;
import java.util.Optional;
public class ASTTagElement extends ASTTagElementTOP {
protected ASTTagElement(String name, Optional<String> tagValue) {
super(name, tagValue);
}
protected ASTTagElement () {
super();
}
public void setTagValue(String tagValue) {
if (tagValue != null) {
if (tagValue.startsWith("=")) {
tagValue = tagValue.substring(1);
}
if (tagValue.endsWith(";")) {
tagValue = tagValue.substring(0, tagValue.length() - 1);
}
tagValue = tagValue.trim();
}
super.setTagValue(tagValue);
}
}
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.monticore.lang.tagging._ast;
import java.util.Optional;
public class ASTTagElement extends ASTTagElementTOP {
protected ASTTagElement(String name, Optional<String> tagValue) {
setName(name);
if(tagValue.isPresent())
setTagValue(tagValue.get());
}
protected ASTTagElement () {
super();
}
public void setTagValue(String tagValue) {
if (tagValue != null) {
if (tagValue.startsWith("=")) {
tagValue = tagValue.substring(1);
}
if (tagValue.endsWith(";")) {
tagValue = tagValue.substring(0, tagValue.length() - 1);
}
tagValue = tagValue.trim();
}
super.setTagValue(tagValue);
}
}
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.monticore.lang.tagging._symboltable;
public class TagKind implements de.monticore.symboltable.SymbolKind {
public static final TagKind INSTANCE = new TagKind();
protected TagKind() {
}
}
\ No newline at end of file
......@@ -31,14 +31,13 @@ import java.util.stream.Collectors;
*
* @author Michael von Wenckstern
*/
public class TagSymbol extends de.monticore.symboltable.CommonSymbol {
public class TagSymbol extends TagSymbolTOP {
public static final TagKind KIND = TagKind.INSTANCE;
protected ArrayList<Object> values = new ArrayList<>();
public TagSymbol(String name, Object... values) {
super(name, KIND);
super(name);
for (Object value : values) {
this.values.add(value);
}
......@@ -68,7 +67,7 @@ public class TagSymbol extends de.monticore.symboltable.CommonSymbol {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(KIND.getName());
sb.append(getName());
if (!values.isEmpty()) {
sb.append("{")
.append(values.stream().map(v -> v.toString()).collect(Collectors.joining(";")))
......@@ -86,11 +85,7 @@ public class TagSymbol extends de.monticore.symboltable.CommonSymbol {
TagSymbol tagSymbol = (TagSymbol) o;
if (this.getKind() != tagSymbol.getKind())
return false;
return values.equals(tagSymbol.values);
}
@Override
......
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.monticore.lang.tagging._symboltable;
import de.monticore.lang.tagging._ast.ASTTaggingUnit;
import de.monticore.symboltable.Scope;
/**
* Created by Michael von Wenckstern on 31.05.2016.
*
* @author Michael von Wenckstern
*/
public interface TagSymbolCreator {
void create(ASTTaggingUnit unit, TaggingResolver scope);
}
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.monticore.lang.tagging._symboltable;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import de.monticore.ast.ASTNode;
import de.monticore.lang.tagging._ast.*;
import de.monticore.lang.tagging._parser.TaggingParser;
import de.monticore.lang.tagging.helper.RangeFixer;
import de.monticore.symboltable.CommonScope;
import de.monticore.symboltable.Scope;
import de.monticore.symboltable.Scope;
import de.monticore.symboltable.ScopeSpanningSymbol;
import de.monticore.symboltable.Symbol;
import de.monticore.symboltable.SymbolKind;
import de.monticore.symboltable.SymbolPredicate;
import de.monticore.symboltable.modifiers.AccessModifier;
import de.monticore.symboltable.resolving.ResolvingFilter;
import de.monticore.symboltable.resolving.ResolvingInfo;
import de.se_rwth.commons.logging.Log;
import org.apache.commons.io.FileUtils;
/**
* Created by MichaelvonWenckstern on 16.11.2017.
*/
public class TaggingResolver implements Scope {
public static final String TAG_FILE_ENDING = "tag";
public static TaggingResolver currentTaggingResolver; // will be set by symbol table creator
private Collection<String> modelPaths;
private TaggingResolver taggingResolver;
private Scope globalScope;
private boolean tagModelsLoaded = false;
private Set<TagSymbolCreator> tagSymbolCreators = new LinkedHashSet<>();
private Set<ResolvingFilter> tagSymbolResolvingFilters = new LinkedHashSet<>();
// create for each symbol its own scope where all the tags for this symbol are stored
private HashMap<Symbol, Scope> tagSymbolRepository = new LinkedHashMap<>();
public TaggingResolver(Scope globalScope, Collection<String> modelPaths) {
if (globalScope instanceof TaggingResolver) {
taggingResolver = (TaggingResolver)globalScope; // use the already existing tagging resolver
taggingResolver.modelPaths.addAll(modelPaths);
} else { // to allow chaining of tagging schemas
taggingResolver = this;
this.globalScope = globalScope;
this.modelPaths = modelPaths;
}
}
// implements all Scope methods by delegating it to globalScope to make reusage easier
public void addTagSymbolCreator(TagSymbolCreator tagSymbolCreator) {
taggingResolver.tagSymbolCreators.add(tagSymbolCreator);
}
public void addTagSymbolResolvingFilter(ResolvingFilter resolvingFilter) {
taggingResolver.tagSymbolResolvingFilters.add(resolvingFilter);
}
public Collection<TagSymbol> getTags(Symbol symbol, TagKind tagKind) {
if (!taggingResolver.tagModelsLoaded) {
taggingResolver.loadTagModels();
taggingResolver.tagModelsLoaded = true;
}
Scope s = taggingResolver.tagSymbolRepository.get(symbol);
if (s == null) return Collections.emptyList();
return s.resolveLocally(tagKind);
}
private void loadTagModels() {
// parse all tag files in the model paths and
Collection<ASTTaggingUnit> tags = taggingResolver.parseTags(taggingResolver.modelPaths);
for (ASTTaggingUnit tag : tags) {
// for each tag file apply all registered tagSymbolCreators
taggingResolver.applyTagSymbolCreators(tag);
}
}
private void applyTagSymbolCreators(ASTTaggingUnit tag) {
for (TagSymbolCreator tsc : taggingResolver.tagSymbolCreators) {
tsc.create(tag, taggingResolver);
}
}
protected Collection<ASTTaggingUnit> parseTags(final Collection<String> modelPaths) {
final Collection<ASTTaggingUnit> foundModels = new ArrayList<>();
for (String mp : modelPaths) {
final Path completePath = Paths.get(mp);
final File f = completePath.toFile();
if (f != null && f.isDirectory()) {
Collection<File> tagFiles = FileUtils.listFiles(f, new String[] {TAG_FILE_ENDING}, true);
tagFiles.stream().forEachOrdered(t -> {
final TaggingParser parser = new TaggingParser();
Optional<ASTTaggingUnit> ast = Optional.empty();
try {
ast = parser.parse(t.getAbsolutePath());
}
catch (IOException e) {
Log.error("could not open file " + t, e);
}
if (ast.isPresent()) {
// todo check package conformity
RangeFixer.fixTaggingUnit(ast.get());
foundModels.add(ast.get());
}
});
}
}
return foundModels;
}
public void addTag(Symbol symbol, TagSymbol tagDefinition) {
// add the tags to the scope belonging to the symbol in tagSymbolRepository
// when the symbol has no scope yet, create a new scope and register all resolving filters
Scope scope = taggingResolver.tagSymbolRepository.get(symbol);
if (scope == null) {
scope = new CommonScope();
addResolvingFilters(scope);
taggingResolver.tagSymbolRepository.put(symbol, scope);
}
scope.add(tagDefinition);
}
protected void addResolvingFilters(final Scope scope) {
taggingResolver.tagSymbolResolvingFilters.forEach(filter -> scope.addResolver(filter));
}
@Override
public Optional<String> getName() {
return globalScope.getName();
}
@Override
public Optional<? extends Scope> getEnclosingScope() {
return globalScope.getEnclosingScope();
}
@Override
public List<? extends Scope> getSubScopes() {
return globalScope.getSubScopes();
}
@Override
public <T extends Symbol> Optional<T> resolve(String s, SymbolKind symbolKind) {
return globalScope.resolve(s, symbolKind);
}
@Override
public <T extends Symbol> Optional<T> resolve(String s, SymbolKind symbolKind, AccessModifier accessModifier) {
return globalScope.resolve(s, symbolKind, accessModifier);
}
@Override
public <T extends Symbol> Optional<T> resolve(String s, SymbolKind symbolKind, AccessModifier accessModifier, Predicate<Symbol> predicate) {
return globalScope.resolve(s, symbolKind, accessModifier, predicate);
}
@Override
public <T extends Symbol> Optional<T> resolveImported(String s, SymbolKind symbolKind, AccessModifier accessModifier) {
return globalScope.resolveImported(s, symbolKind, accessModifier);
}
@Override
public <T extends Symbol> Collection<T> resolveMany(String s, SymbolKind symbolKind) {
return globalScope.resolveMany(s, symbolKind);
}
@Override
public <T extends Symbol> Collection<T> resolveMany(String s, SymbolKind symbolKind, AccessModifier accessModifier) {
return globalScope.resolveMany(s, symbolKind, accessModifier);
}
@Override
public <T extends Symbol> Collection<T> resolveMany(String s, SymbolKind symbolKind, Predicate<Symbol> predicate) {
return globalScope.resolveMany(s, symbolKind, predicate);
}
@Override
public <T extends Symbol> Collection<T> resolveMany(String s, SymbolKind symbolKind, AccessModifier accessModifier, Predicate<Symbol> predicate) {
return globalScope.resolveMany(s, symbolKind, accessModifier, predicate);
}
@Override
public <T extends Symbol> Optional<T> resolveLocally(String s, SymbolKind symbolKind) {
return globalScope.resolveLocally(s, symbolKind);
}
@Override
public <T extends Symbol> Collection<T> resolveLocally(SymbolKind symbolKind) {
return globalScope.resolveLocally(symbolKind);
}
@Override
public <T extends Symbol> Optional<T> resolveDown(String s, SymbolKind symbolKind) {
return globalScope.resolveDown(s, symbolKind);
}
@Override
public <T extends Symbol> Optional<T> resolveDown(String s, SymbolKind symbolKind, AccessModifier accessModifier) {
return globalScope.resolveDown(s, symbolKind, accessModifier);
}
@Override
public <T extends Symbol> Optional<T> resolveDown(String s, SymbolKind symbolKind, AccessModifier accessModifier, Predicate<Symbol> predicate) {
return globalScope.resolveDown(s, symbolKind, accessModifier, predicate);
}
@Override
public <T extends Symbol> Collection<T> resolveDownMany(String s, SymbolKind symbolKind) {
return globalScope.resolveDownMany(s, symbolKind);
}
@Override
public <T extends Symbol> Collection<T> resolveDownMany(String s, SymbolKind symbolKind, AccessModifier accessModifier) {
return globalScope.resolveDownMany(s, symbolKind, accessModifier);
}
@Override
public <T extends Symbol> Collection<T> resolveDownMany(String s, SymbolKind symbolKind, AccessModifier accessModifier, Predicate<Symbol> predicate) {
return globalScope.resolveDownMany(s, symbolKind, accessModifier, predicate);
}
@Override
public Map<String, Collection<Symbol>> getLocalSymbols() {
return globalScope.getLocalSymbols();
}
@Override
public int getSymbolsSize() {
return globalScope.getSymbolsSize();
}
@Override
public boolean isShadowingScope() {
return globalScope.isShadowingScope();
}
@Override
public boolean isSpannedBySymbol() {
return globalScope.isSpannedBySymbol();
}
@Override
public Optional<? extends ScopeSpanningSymbol> getSpanningSymbol() {
return globalScope.getSpanningSymbol();
}
@Override
public boolean exportsSymbols() {
return globalScope.exportsSymbols();
}
@Override
public Set<ResolvingFilter<? extends Symbol>> getResolvingFilters() {
return globalScope.getResolvingFilters();
}
@Override
public Optional<? extends ASTNode> getAstNode() {
return globalScope.getAstNode();
}
@Override
public void setAstNode(ASTNode astNode)
{
//TODO
}
@Override
public void setName(String s)
{
//TODO
}
@Override
public void setEnclosingScope(Scope scope)
{
//TODO
}
@Override
public void addSubScope(Scope scope)
{