Commit 18a6dc1d authored by vonWenckstern's avatar vonWenckstern
Browse files

moved my code from gitlab

parent 31d2d30c
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- == PROJECT COORDINATES ============================================= -->
<parent>
<groupId>montiarc.languages</groupId>
<artifactId>languages</artifactId>
<version>4.0.1-SNAPSHOT</version>
</parent>
<artifactId>tagging</artifactId>
<!-- == PROJECT DEPENDENCIES ============================================= -->
<dependencies>
<dependency>
<groupId>montiarc.languages</groupId>
<artifactId>common</artifactId>
<version>4.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>montiarc.languages</groupId>
<artifactId>common</artifactId>
<version>4.0.1-SNAPSHOT</version>
<classifier>${grammars.classifier}</classifier>
</dependency>
<dependency>
<groupId>de.se_rwth.commons</groupId>
<artifactId>se-commons-logging</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</dependency>
<dependency>
<groupId>org.jscience</groupId>
<artifactId>jscience</artifactId>
<version>4.3.1</version>
</dependency>
<!-- MontiCore Dependencies -->
<dependency>
<groupId>de.monticore</groupId>
<artifactId>monticore-runtime</artifactId>
</dependency>
<dependency>
<groupId>de.monticore</groupId>
<artifactId>monticore-grammar</artifactId>
</dependency>
<dependency>
<groupId>de.monticore</groupId>
<artifactId>monticore-grammar</artifactId>
<classifier>${grammars.classifier}</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.monticore</groupId>
<artifactId>javaDSL</artifactId>
</dependency>
<!-- .. Test Libraries ............................................... -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.monticore</groupId>
<artifactId>monticore-runtime</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.se_rwth.commons</groupId>
<artifactId>se-commons-groovy</artifactId>
<version>${se-commons.version}</version>
</dependency>
</dependencies>
<!-- == PROJECT BUILD SETTINGS =========================================== -->
<build>
<plugins>
<!-- MontiCore Generation -->
<plugin>
<groupId>de.monticore.mojo</groupId>
<artifactId>monticore-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Other Configuration -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<dependencies>
<dependency>
<groupId>de.monticore</groupId>
<artifactId>mc-assemblies</artifactId>
<version>${mc.grammars.assembly.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>grammars</id>
<configuration>
<finalName>${project.artifactId}-${project.version}</finalName>
<descriptorRefs>
<descriptorRef>grammars-assembly</descriptorRef>
</descriptorRefs>
<formats>
<format>jar</format>
</formats>
</configuration>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
package de.monticore.lang;
/**
* Basic grammar to tag non-functional properties
*
* @author Michael von Wenckstern
*/
grammar TagSchema extends de.monticore.common.Common {
TagSchemaUnit@! =
("package" package:(Name& || ".")+ ";")?
(ImportStatement)*
"tagschema" Name "{" TagType+ "}";
interface TagType;
//ComplexTagType | EnumeratedTagType | ValuedTagType | SimpleTagType;
ast TagType =
method public String getName() {
return "undefined";
};
interface ScopeIdentifier;
ast ScopeIdentifier =
method public String getScopeName() {
return "undefined";
};
/** maybe this should be moved into the MontiArc grammar, b/c MontiArc knows what is taggable */
ComponentScope implements ScopeIdentifier = "Component";
ast ComponentScope =
method public String getScopeName() {
return "Component";
};
PortScope implements ScopeIdentifier = "Port";
ast PortScope =
method public String getScopeName() {
return "Port";
};
ConnectorScope implements ScopeIdentifier = "Connector";
ast ConnectorScope =
method public String getScopeName() {
return "Connector";
};
ComponentInstanceScope implements ScopeIdentifier = "ComponentInstance";
ast ComponentInstanceScope =
method public String getScopeName() {
return "ExpandedComponentInstance";
};
// ScopeIdentifier = Name;
Scope = "for" (ScopeIdentifier || ",")+;
SimpleTagType implements TagType = ("private")? "tagtype" Name Scope? ";" ;
// modification form ML's tagging language (replaced String by Name --> is more to Java feeling)
EnumeratedTagType implements TagType = ("private")? "tagtype" name:Name ":" enumText:Enum Scope? ";" ;
token Enum = '[' (~('[' | ']') | String)+ ']';
ValuedTagType implements TagType = ("private")? "tagtype" Name ":"
(number:"Number"|string:"String"|boolean:"Boolean"|unitKind:Name) Scope? ";" ;
// not supported in Symbol Table yet
// ComplexTagType implements TagType = ("private")? "tagtype" Scope? "{" (Reference || ",")+ ";" "}" ;
// ast ComplexTagType =
// method public String getName() {
// return "undefined";
// };
// Reference = Name ":" datatype:Name ("?"|"+"|"*")? ;
// ComplexTagType = "tagtype" Name Scope ComplexTagDef;
ComplexTagType implements TagType = ("private")? "tagtype" Name Scope? complexTag:ComplexTagDef;
token ComplexTagDef = 'i' 's' WSS* Recursion (WSS* ';');
fragment token Recursion = '{' (~('{' | '}' | '"') | String | Recursion)+ '}';
fragment token WSS = (' ' | '\t' | '\r' | '\n');
/* ast ComplexTagType =
method public String getName() {
return "undefined";
};*/
}
\ No newline at end of file
package de.monticore.lang;
/**
* Basic grammar to tag non-functional properties
* grammar to create only parsers for tag values
*
* @author Michael von Wenckstern
*/
grammar TagValue extends de.monticore.common.Common {
interface TagValue;
ast TagValue =
method public String getValueKind() {
return "undefined";
};
StringTagValue implements TagValue = String;
ast StringTagValue =
method public String getValueKind() {
return "StringValue";
};
NumericTagValue implements TagValue = NumericLiteral;
ast NumericTagValue =
method public String getValueKind() {
return "NumericValue";
};
BooleanTagValue implements TagValue = (t:"true" | f:"false"); // cannot use true or True, that's why we use t, similar for f
ast BooleanTagValue =
method public String getValueKind() {
return "BooleanValue";
};
UnitTagValue implements TagValue = NumericLiteral unit:Name;
ast UnitTagValue =
method public String getValueKind() {
return "UnitValue";
};
ComplexTag implements TagValue = Name "{" (InnerTag || ";")+ "}";
ast ComplexTag =
method public String getValueKind() {
return "ComplexTag";
};
InnerTag = Name ITagValue;
fragment token IWSS = (' ' | '\t' | '\r' | '\n');
token ITagValue = ('=' IWSS* IRecursion) | ITagToken | ('=' IWSS* String IWSS* ';');
fragment token IRecursion = '{' (~('{' | '}' | '"') | String | IRecursion)+ '}';
fragment token ITagToken = '=' (~('"' | '{' | '}' | ';'))+ ';';
}
\ No newline at end of file
package de.monticore.lang;
/**
* Basic grammar to tag non-functional properties
*
* @author Michael von Wenckstern
*/
grammar Tagging extends de.monticore.common.Common {
TaggingUnit@! =
("package" package:(Name& || ".")+ ";")?
(ImportStatement)*
"conforms" "to" (QualifiedName || ",")+ ";"
TagBody;
// 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+ "}";
// interface TagElement;
Tag = "tag" (Scope || ",")+ "with" TagElement+;
TagElement = Name (TagValue | ";");
fragment token WSS = (' ' | '\t' | '\r' | '\n');
token TagValue = '=' WSS* BasicTagValue (WSS* ';');
fragment token BasicTagValue = (Recursion | TagToken | String);
fragment token Recursion = '{' (~('{' | '}' | '"') | String | Recursion)+ '}';
fragment token TagToken = (~('"' | '{' | '}' | ';'))+;
interface Scope;
ast Scope =
method public String getQualifiedNameString() {
return "";
}
method public String getScopeKind() {
return "undefined";
};
// this one is only defined here, to get Parser Tags
NameScope implements Scope = QualifiedName;
ast NameScope =
method public String getQualifiedNameString() {
return getQualifiedName().toString();
}
method public String getScopeKind() {
return "NameScope";
};
ConnectorScope extends NameScope = source:QualifiedName "->" QualifiedName;
ast ConnectorScope =
method public String getQualifiedNameString() {
return getQualifiedName().toString();
}
method public String getScopeKind() {
return "ConnectorScope";
};
/* ast Scope =
method public de.monticore.types.types._ast.ASTQualifiedName getQualifiedName() {
return null;
}
method public String getQualifiedNameAsString() {
return de.se_rwth.commons.Joiners.DOT.join(getQualifiedName().getParts());
};
ast NameScope =
method public String getQualifiedNameAsString() {
return de.se_rwth.commons.Joiners.DOT.join(getQualifiedName().getParts());
};
ast ConnectorScope =
method public String getQualifiedNameAsString() {
return de.se_rwth.commons.Joiners.DOT.join(getQualifiedName().getParts());
}; */
}
\ No newline at end of file
package de.monticore.lang.tagging._ast;
public class ASTTagElement extends ASTTagElementTOP {
protected ASTTagElement (String name, 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);
}
}
package de.monticore.lang.tagging._symboltable;
import java.util.Collection;
/**
* Created by Michael von Wenckstern on 30.05.2016.
*
* @author Michael von Wenckstern
*/
public interface IsTaggable {
/**
* if component a/Controller.arc is loaded, then only tags in the
* files a/*.tag are loaded
* but this allows you to save different tagging information for the
* same component in different files, e.g. a/PowerConsumption.tag
* and a/Time.tag
*
* @return all tags of the components
*/
Collection<TagSymbol> getTags();
/**
* returns only the tag of a special tag kind (e.g. if you want only
* to evaluate PowerConsumption of a component, than call
* getTags(PowerConsumption.TAGKIND)
* --> methodology is the same as in PN's resolve function
*/
<T extends TagSymbol> Collection<T> getTags(final TagKind tagKind);
/**
* adds a tag to the symbol
*
* @param tag the tag symbol which should be added
*/
void addTag(final TagSymbol tag);
/**
* adds all tags to the symbol
*
* @param tags
*/
void addTags(final TagSymbol... tags);
/**
* add all tags to the symbol
*
* @param tags
*/
void addTags(Iterable<? extends TagSymbol> tags);
}
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
package de.monticore.lang.tagging._symboltable;
import java.util.ArrayList;
import java.util.List;
import de.monticore.lang.montiarc.helper.IndentPrinter;
/**
* Symboltable entry for tag.
* This is the base class for tags, if you define a new tag
* this class must be extended
*
* @author Michael von Wenckstern
*/
public class TagSymbol extends de.monticore.symboltable.CommonSymbol {
public static final TagKind KIND = TagKind.INSTANCE;
protected ArrayList<Object> values = new ArrayList<>();
public TagSymbol(TagKind kind, Object... values) {
super("", kind);
for (Object value : values) {
this.values.add(value);
}
}
public List<Object> getValues() {
return this.values;
}
/**
* has no range check, it is should be only used for classes
* which extends this class, they know how many objects are stored
*/
protected <T> T getValue(int index) {
return (T) this.values.get(index);
}
/**
* is only needed for multiple inheritance chains
*/
protected void addValues(Object... values) {
for (Object value : values) {
this.values.add(value);
}
}
@Override
public String toString() {
return IndentPrinter.groups("{0}: ", "{1:'{':',':'}'}")
.<String, ArrayList<Object>>params(KIND.getName(), values)
.toString();
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof TagSymbol))
return false;
TagSymbol tagSymbol = (TagSymbol) o;
if (this.getKind() != tagSymbol.getKind())
return false;
return values.equals(tagSymbol.values);
}
@Override
public int hashCode() {
return values.hashCode();
}
}
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, Scope gs);
}
package de.monticore.lang.tagging._symboltable;
import de.monticore.ModelingLanguage;
/**
* Created by Michael von Wenckstern on 09.06.2016.
*/
public interface TagableModelingLanguage extends ModelingLanguage {
public static final String TAG_FILE_ENDING = "tag";
void addTagSymbolCreator(TagSymbolCreator tagSymbolCreator);
}
package de.monticore.lang.tagging._symboltable;
import java.util.Collection;
import java.util.Map;
import de.monticore.symboltable.CommonScopeSpanningSymbol;
import de.monticore.symboltable.Symbol;
import de.monticore.symboltable.SymbolKind;
/**
* Created by Michael von Wenckstern on 03.06.2016.
*
* @author Michael von Wenckstern
*/
public class TaggingScopeSpanningSymbol extends CommonScopeSpanningSymbol
implements IsTaggable {
/**
* @see CommonSymbol#CommonSymbol(String, SymbolKind)
*/
public TaggingScopeSpanningSymbol(String name, SymbolKind kind) {
super(name, kind);
}