Skip to content
Snippets Groups Projects
Commit dafb9350 authored by René Schöne's avatar René Schöne
Browse files

*

parents
No related branches found
No related tags found
No related merge requests found
Pipeline #9929 failed
Showing
with 1003 additions and 0 deletions
build
.gradle
.idea
src/gen-res/
src/gen/
out/
*.class
variables:
GIT_SUBMODULE_STRATEGY: recursive
stages:
- build
- ragdoc_build
- ragdoc_view
- test
- publish
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
cache:
paths:
- .gradle/wrapper
- .gradle/caches
build:
image: openjdk:11
stage: build
script:
# see discussion in the answer of https://stackoverflow.com/questions/44911155/gradle-how-to-include-runtimeonly-dependencies-in-javaexec-classpath
- ./gradlew --console=plain --no-daemon relast.preprocessor:jar
- ./gradlew --console=plain --no-daemon :assemble :jar
artifacts:
paths:
- build/libs/*.jar
test:
image: openjdk:11
stage: test
script:
- ./gradlew --console=plain --no-daemon check
artifacts:
reports:
junit: build/test-results/test/**/TEST-*.xml
publish:
image: openjdk:11
stage: publish
needs:
- test
script:
- "./gradlew :publish"
only:
- main
ragdoc_build:
image:
name: "git-st.inf.tu-dresden.de:4567/jastadd/ragdoc-builder"
entrypoint: [""]
stage: ragdoc_build
needs:
- build
script:
- JAVA_FILES=$(find src/ -name '*.java')
- /ragdoc-builder/start-builder.sh -excludeGenerated -d data/ $JAVA_FILES
only:
- main
artifacts:
paths:
- "data/"
ragdoc_view:
image:
name: "git-st.inf.tu-dresden.de:4567/jastadd/ragdoc-view:relations"
entrypoint: [""]
stage: ragdoc_view
needs:
- ragdoc_build
script:
- DATA_DIR=$(pwd -P)/data
- mkdir -p pages/docs/ragdoc
- OUTPUT_DIR=$(pwd -P)/pages/docs/ragdoc
- cd /ragdoc-view/src/ && rm -rf data && ln -s $DATA_DIR
- /ragdoc-view/build-view.sh --output-path=$OUTPUT_DIR
only:
- main
artifacts:
paths:
- "pages/docs/ragdoc"
pages:
image: python:3.8-buster
stage: publish
needs:
- test
before_script:
- pip install -U mkdocs mkdocs-macros-plugin mkdocs-git-revision-date-localized-plugin
script:
- cd pages && mkdocs build
only:
- main
artifacts:
paths:
- public
[submodule "relast.preprocessor"]
path = relast.preprocessor
url = ../../relast-preprocessor.git
branch = develop
plugins {
id 'java'
id 'org.jastadd'
id 'application'
id 'maven-publish'
id 'idea'
}
ext {
mainClassName = 'org.jastadd.preprocessor.coverage_gen.Main'
}
// set the main class name for `gradle run`
application.mainClassName = "${mainClassName}"
repositories {
mavenCentral()
}
dependencies {
implementation project(':relast.preprocessor')
testImplementation testFixtures(project(":relast.preprocessor"))
}
group = 'de.tudresden.inf.st'
def versionFile = 'src/main/resources/coverageGeneratorVersion.properties'
def oldProps = new Properties()
try {
file(versionFile).withInputStream { stream -> oldProps.load(stream) }
version = oldProps['version']
} catch (e) {
// this happens, if either the properties file is not present, or cannot be read from
throw new GradleException("File ${versionFile} not found or unreadable. Aborting.", e)
}
task printVersion() {
doLast {
println(version)
}
}
task newVersion() {
doFirst {
def props = new Properties()
props['version'] = value
props.store(file(versionFile).newWriter(), null)
}
}
File genSrc = file("src/gen/java")
sourceSets.main.java.srcDir genSrc
idea.module.generatedSourceDirs += genSrc
test {
useJUnitPlatform()
maxHeapSize = '1G'
}
jar {
manifest {
attributes "Main-Class": "${mainClassName}"
}
from {
configurations.runtimeClasspath.collect { return (it.exists() && !it.toString().endsWith("model.jar")) ? (it.isDirectory() ? it : zipTree(it)) : null }
}
}
// Input and output files for relast
def relastInputFiles = [
"relast.preprocessor/src/main/jastadd/RelAst.relast",
"relast.preprocessor/src/main/jastadd/mustache/Mustache.relast"
]
def relastOutputFiles = [
"src/gen/jastadd/RelAst.ast",
"src/gen/jastadd/RelAst.jadd",
"src/gen/jastadd/RelAstRefResolver.jadd",
"src/gen/jastadd/RelAstResolverStubs.jrag"
]
task relast(type: JavaExec) {
classpath = files("relast.preprocessor/libs/relast.jar")
group = 'Build'
doFirst {
delete relastOutputFiles
mkdir "src/gen/jastadd/"
}
args = [
"--listClass=java.util.ArrayList",
"--jastAddList=JastAddList",
"--useJastAddNames",
"--file",
"--resolverHelper",
"--grammarName=./src/gen/jastadd/RelAst"
] + relastInputFiles
inputs.files relastInputFiles
outputs.files relastOutputFiles
}
jastadd {
configureModuleBuild()
modules {
//noinspection GroovyAssignabilityCheck
module("Preprocessor") {
jastadd {
basedir "."
include "relast.preprocessor/src/main/jastadd/**/*.ast"
include "relast.preprocessor/src/main/jastadd/**/*.jadd"
include "relast.preprocessor/src/main/jastadd/**/*.jrag"
include "src/main/jastadd/**/*.ast"
include "src/main/jastadd/**/*.jadd"
include "src/main/jastadd/**/*.jrag"
include "src/gen/jastadd/**/*.ast"
include "src/gen/jastadd/**/*.jadd"
include "src/gen/jastadd/**/*.jrag"
}
scanner {
include "relast.preprocessor/src/main/jastadd/scanner/Header.flex", [-4]
include "relast.preprocessor/src/main/jastadd/scanner/Preamble.flex", [-3]
include "relast.preprocessor/src/main/jastadd/scanner/Macros.flex", [-2]
include "relast.preprocessor/src/main/jastadd/scanner/RulesPreamble.flex", [-1]
include "relast.preprocessor/src/main/jastadd/scanner/Keywords.flex", [ 0]
include "relast.preprocessor/src/main/jastadd/scanner/Symbols.flex", [ 1]
include "relast.preprocessor/src/main/jastadd/scanner/RulesPostamble.flex", [ 2]
}
parser {
include "relast.preprocessor/src/main/jastadd/parser/Preamble.parser"
include "relast.preprocessor/src/main/jastadd/parser/RelAst.parser"
}
}
}
cleanGen.doFirst {
delete "src/gen"
delete "src/gen-res"
}
preprocessParser.doFirst {
args += ["--no-beaver-symbol"]
}
module = "Preprocessor"
astPackage = 'org.jastadd.relast.ast'
parser.name = 'RelAstParser'
genDir = 'src/gen/java'
buildInfoDir = 'src/gen-res'
scanner.genDir = "src/gen/java/org/jastadd/relast/scanner"
parser.genDir = "src/gen/java/org/jastadd/relast/parser"
jastaddOptions = ["--lineColumnNumbers", "--List=JastAddList", "--safeLazy", "--visitCheck=true", "--rewrite=cnta", "--cache=all"]
}
clean.dependsOn(cleanGen)
generateAst.dependsOn(relast)
//991
publishing {
publications {
maven(MavenPublication) {
artifactId = 'coverage_generator'
// Comment rs: components.java does not include relast.preprocessor
// from components.java
artifact("build/libs/coverage_generator-${version}.jar") {
extension 'jar'
}
}
}
repositories {
maven {
url "https://git-st.inf.tu-dresden.de/api/v4/projects/991/packages/maven"
// Uncomment the following lines to publish manually (and comment out the other credentials section)
// credentials(HttpHeaderCredentials) {
// name = "Private-Token"
// value = gitLabPrivateToken // the variable resides in ~/.gradle/gradle.properties
// }
credentials(HttpHeaderCredentials) {
name = 'Job-Token'
value = System.getenv("CI_JOB_TOKEN")
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
}
publish.dependsOn jar
File added
#Sun Nov 01 15:07:09 CET 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
gradlew 0 → 100644
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
/docs/ragdoc/
__pycache__
{% block footer %}
<p>{% if config.copyright %}
<small>{{ config.copyright }}<br></small>
{% endif %}
<hr>
Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
{% if page and page.meta and page.meta.git_revision_date_localized %}
<small><br><i>Last updated {{ page.meta.git_revision_date_localized }}</i></small>
{% endif %}
</p>
{% endblock %}
# Coverage Generator Documentation
[Coverage Generator](https://git-st.inf.tu-dresden.de/jastadd/preprocessors/coverage-generator) is a preprocessor to enable realistic coverage by providing means to call all methods generated by [JastAdd](http://jastadd.org/).
# Using the Coverage Generator in your project
## Include in your build setup
Add/Merge the following snippet in your `build.gradle`.
**Note**: List all grammar files in the arguments and the changed name of JastAdd's list class, if applicable.
```groovy
repositories {
mavenCentral()
maven {
name "gitlab-maven"
url "https://git-st.inf.tu-dresden.de/api/v4/groups/jastadd/-/packages/maven"
}
}
configurations {
coverageGeneratorClasspath
}
dependencies {
coverageGeneratorClasspath group: 'de.tudresden.inf.st', name: 'coverageGenerator', version: '0.0.1'
}
task generateCoverage(type: JavaExec) {
main = 'org.jastadd.preprocessor.coverage_gen.Main'
classpath = configurations.coverageGeneratorClasspath
args([
'--jastAddList=JastAddList',
'--outBaseDir=src/gen/jastadd',
'src/main/jastadd/Example.relast'
])
}
generateAst.dependsOn generateCoverage
```
## Write a testcase
Create a new test class with the following content.
**Note**: Import the `ASTNode` using your matching package, as well as `@Test` using the correct test framework.
```java
public class GenerateCoverageTest {
@Test
public void testGeneratedCoverage() {
ASTNode.runCoverageAll();
}
}
```
coverageGenVersionFileName = '../src/main/resources/coverageGeneratorVersion.properties'
def get_version():
with open(coverageGenVersionFileName) as coverageGenVersionFile:
versionFileContent = coverageGenVersionFile.read()
return versionFileContent[versionFileContent.rindex('version=') + 8:].strip()
def define_env(env):
"""
This is the hook for defining variables, macros and filters
- variables: the dictionary that contains the environment variables
- macro: a decorator function, to declare a macro.
"""
env.conf['site_name'] = 'RagConnect ' + get_version()
@env.macro
def coverageGen_version():
return get_version()
if __name__ == '__main__':
print(get_version())
site_name: Coverage Generator
nav:
- using.md
- API documentation: ragdoc/index.html
theme:
name: readthedocs
custom_dir: custom_theme/
plugins:
- search
- git-revision-date-localized:
type: datetime
timezone: Europe/Berlin
locale: en
fallback_to_build_date: True
- macros
repo_url: https://git-st.inf.tu-dresden.de/jastadd/preprocessors/coverage-generator
site_dir: ../public
Subproject commit 02f8e35993dc3f62ab49e94f69a6dc27170660da
pluginManagement {
plugins {
id 'org.jastadd' version '1.13.3'
}
}
rootProject.name = 'coverage_generator'
include 'relast.preprocessor'
aspect GrammarToCoverage {
syn nta Document Program.toCoverage(String jastAddList) {
Document coverage = new Document();
coverage.setFileName("Coverage.yaml");
MappingElement rootElement = new MappingElement();
rootElement.put("ListClass", jastAddList);
coverage.setRootElement(rootElement);
ListElement types = new ListElement();
for (TypeDecl typeDecl : typeDecls()) {
MappingElement typeElement = new MappingElement();
types.add(typeElement);
typeElement.put("Name", typeDecl.getName());
typeElement.put("Abstract", typeDecl.getAbstract());
if (typeDecl.hasSuperType() && typeDecl.getSuperType().getAbstract()) {
typeElement.put("hasAbstractParent", true);
}
ListElement normalComponents = new ListElement();
ListElement listComponents = new ListElement();
ListElement optComponents = new ListElement();
ListElement tokenComponents = new ListElement();
for (Component component : typeDecl.getComponentList()) {
MappingElement componentElement = new MappingElement();
componentElement.put("Name", component.getName());
componentElement.put("NTA", component.getNTA());
if (component.isTypeComponent()) {
TypeComponent typeComponent = component.asTypeComponent();
componentElement.put("TypeName", typeComponent.getTypeDecl().getName());
componentElement.put("instantiableTypeName", typeComponent.getTypeDecl().instantiableTypeName());
if (typeComponent.isNormalComponent()) {
normalComponents.add(componentElement);
} else if (typeComponent.isListComponent()) {
listComponents.add(componentElement);
} else if (typeComponent.isOptComponent()) {
optComponents.add(componentElement);
}
} else if (component.isTokenComponent()) {
componentElement.put("createTokenStatement", component.asTokenComponent().createTokenStatement());
tokenComponents.add(componentElement);
}
}
typeElement.put("NormalComponents", normalComponents);
typeElement.put("ListComponents", listComponents);
typeElement.put("OptComponents", optComponents);
typeElement.put("TokenComponents", tokenComponents);
ListElement normalRelations = new ListElement();
ListElement listRelations = new ListElement();
for (Role role : typeDecl.getRoleList()) {
if (role.isNavigableRole()) {
MappingElement relationComponent = new MappingElement();
NavigableRole navRole = role.asNavigableRole();
relationComponent.put("SourceName", navRole.getName());
relationComponent.put("instantiableTypeName", navRole.oppositeTypeDecl().instantiableTypeName());
if (navRole.isListRole()) {
listRelations.add(relationComponent);
} else if (navRole.isNormalRole() || navRole.isOptRole()) {
normalRelations.add(relationComponent);
}
}
}
typeElement.put("NormalRelations", normalRelations);
typeElement.put("ListRelations", listRelations);
}
rootElement.put("types", types);
return coverage;
}
syn String TypeDecl.instantiableTypeName() {
if (!getAbstract()) {
return getName();
}
for (TypeDecl subType : getSubTypeList()) {
if (subType.instantiableTypeName() != null) {
return subType.instantiableTypeName();
}
}
return null;
}
syn String TokenComponent.prettyPrintJavaType() {
if (!hasJavaTypeUse()) {
return "String";
}
StringBuilder sb = new StringBuilder();
getJavaTypeUse().generateAbstractGrammar(sb);
return sb.toString();
}
syn boolean TokenComponent.isString() {
return prettyPrintJavaType().equals("String");
}
syn String TokenComponent.createTokenStatement() {
switch (prettyPrintJavaType()) {
case "boolean":
case "Boolean": return "true";
case "int":
case "Integer": return "0";
case "short":
case "Short": return "0";
case "long":
case "Long": return "0L";
case "float":
case "Float": return "0.0f";
case "double":
case "Double": return "0.0d";
case "char":
case "Character": return "'a'";
case "String": return "\"\"";
// add paranetheses here to prevent mustache ignoring the value
default: return "(null)";
}
}
inh TypeDecl NavigableRole.oppositeTypeDecl();
eq DirectedRelation.getSource().oppositeTypeDecl() {
return getTarget().getType();
}
eq BidirectionalRelation.getLeft().oppositeTypeDecl() {
return getRight().getType();
}
eq BidirectionalRelation.getRight().oppositeTypeDecl() {
return getLeft().getType();
}
}
\ No newline at end of file
package org.jastadd.preprocessor.coverage_gen;
import org.jastadd.option.BooleanOption;
import org.jastadd.relast.ast.Document;
import org.jastadd.relast.ast.Program;
import org.jastadd.relast.compiler.CompilerException;
import java.io.IOException;
import java.nio.file.Path;
import static org.jastadd.relast.compiler.Mustache.javaMustache;
public class Main extends org.jastadd.relast.compiler.RelAstProcessor {
private static final String MUSTACHE_TEMPLATE = "Coverage";
protected BooleanOption optionPrintYaml;
public Main() {
super("Coverage Generator", true);
}
public static void main(String[] args) {
try {
int returnValue = new Main().run(args);
System.exit(returnValue);
} catch (CompilerException e) {
System.err.println(e.getMessage());
System.exit(-1);
}
}
@Override
protected void initOptions() {
super.initOptions();
optionPrintYaml = addOption(new BooleanOption("printYaml", "create YAML file used by Mustache in the ouput directory"));
optionPrintYaml.defaultValue(false);
}
@Override
protected int processGrammar(Program program, Path inputBasePath, Path outputBasePath) throws CompilerException {
Document navigation = program.toCoverage(getConfiguration().listType());
Path yamlFile = outputBasePath.resolve(navigation.getFileName());
Path jragFile = yamlFile.getParent().resolve(MUSTACHE_TEMPLATE + ".jrag");
if (optionPrintYaml.value() != null && optionPrintYaml.value()) {
writeToFile(yamlFile, navigation.prettyPrint(false));
}
try {
javaMustache(MUSTACHE_TEMPLATE, navigation.prettyPrint(), jragFile.toString());
} catch (IOException e) {
throw new CompilerException("Unable to expand template", e);
}
return 0;
}
}
aspect Coverage {
public static void ASTNode.runCoverageAll() {
{{#types}}
{{^Abstract}}
new {{Name}}().runCoverage();
{{/Abstract}}
{{/types}}
}
{{#types}}
public void {{Name}}.runCoverage() {
{{!TODO constructors}}
{{#hasAbstractParent}}
super.runCoverage();
{{/hasAbstractParent}}
numChildren();
mayHaveRewrite();
try { flushAttrCache(); } catch (Exception ignore) {}
try { flushCollectionCache(); } catch (Exception ignore) {}
try { clone(); } catch (Exception ignore) {}
{{^Abstract}}
try { fullCopy(); } catch (Exception ignore) {}
try { treeCopyNoTransform(); } catch (Exception ignore) {}
try { treeCopy(); } catch (Exception ignore) {}
canRewrite();
try { rewriteTo(); } catch (Exception ignore) {}
{{/Abstract}}
{{#NormalComponents}}
{{^NTA}}
try { set{{Name}}(new {{instantiableTypeName}}()); } catch (Exception ignore) {}
{{/NTA}}
get{{Name}}();
get{{Name}}NoTransform();
{{/NormalComponents}}
{{#OptComponents}}
has{{Name}}();
{{^NTA}}
try { set{{Name}}Opt(new Opt<{{TypeName}}>()); } catch (Exception ignore) {}
try { set{{Name}}(new {{instantiableTypeName}}()); } catch (Exception ignore) {}
{{/NTA}}
try { get{{Name}}(); } catch (Exception ignore) {}
try { get{{Name}}Opt(); } catch (Exception ignore) {}
try { get{{Name}}OptNoTransform(); } catch (Exception ignore) {}
{{/OptComponents}}
{{#ListComponents}}
{{^NTA}}
try { set{{Name}}List(new {{ListClass}}<{{TypeName}}>()); } catch (Exception ignore) {}
try { set{{Name}}(new {{instantiableTypeName}}(), 0); } catch (Exception ignore) {}
try { add{{Name}}NoTransform(new {{instantiableTypeName}}()); } catch (Exception ignore) {}
try { add{{Name}}(new {{instantiableTypeName}}()); } catch (Exception ignore) {}
{{/NTA}}
try { getNum{{Name}}(); } catch (Exception ignore) {}
try { getNum{{Name}}NoTransform(); } catch (Exception ignore) {}
get{{Name}}(0);
get{{Name}}NoTransform(0);
has{{Name}}();
get{{Name}}List();
get{{Name}}ListNoTransform();
get{{Name}}s();
get{{Name}}sNoTransform();
{{/ListComponents}}
{{#TokenComponents}}
try { set{{Name}}({{{createTokenStatement}}}); } catch (Exception ignore) {}
{{#isString}}
try { set{{Name}}(new beaver.Symbol(null)}; } catch (Exception ignore) {}
try { set{{Name}}(new beaver.Symbol("")}; } catch (Exception ignore) {}
{{/isString}}
get{{Name}}();
{{/TokenComponents}}
{{#NormalRelations}}
get{{SourceName}}();
set{{SourceName}}(new {{instantiableTypeName}}());
{{/NormalRelations}}
{{#ListRelations}}
get{{SourceName}}s();
add{{SourceName}}(0, new {{instantiableTypeName}}());
try {
{{instantiableTypeName}} obj = new {{instantiableTypeName}}();
add{{SourceName}}(obj);
remove{{SourceName}}(obj);
} catch (Exception ignore) {}
try { remove{{SourceName}}(null); } catch (Exception ignore) {}
{{/ListRelations}}
{{!TODO isA/asA}}
}
{{/types}}
}
#Sat Jun 05 15:39:02 CEST 2021
version=0.0.1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment