Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
ecore2relast
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JastAdd
ecore2relast
Commits
3abd9f42
Commit
3abd9f42
authored
5 years ago
by
Johannes Mey
Browse files
Options
Downloads
Patches
Plain Diff
main file for version 0.1
parent
08a8406d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
build.gradle
+5
-1
5 additions, 1 deletion
build.gradle
src/main/java/de/tudresden/inf/st/e2j/Main.java
+94
-1
94 additions, 1 deletion
src/main/java/de/tudresden/inf/st/e2j/Main.java
with
99 additions
and
2 deletions
build.gradle
+
5
−
1
View file @
3abd9f42
group
'de.tudresden.inf.st'
version
'
1.0-SNAPSHOT
'
version
'
0.1
'
apply
plugin:
'java'
apply
plugin:
'application'
...
...
@@ -65,6 +65,10 @@ jar {
'Main-Class'
:
'de.tudresden.inf.st.e2j.Main'
)
}
from
{
configurations
.
compile
.
collect
{
it
.
isDirectory
()
?
it
:
zipTree
(
it
)
}
}
}
task
preprocess
(
type:
JavaExec
)
{
...
...
This diff is collapsed.
Click to expand it.
src/main/java/de/tudresden/inf/st/e2j/Main.java
+
94
−
1
View file @
3abd9f42
package
de.tudresden.inf.st.e2j
;
import
de.tudresden.inf.st.e2j.jastadd.model.EObject
;
import
de.tudresden.inf.st.e2j.jastadd.model.EPackage
;
import
de.tudresden.inf.st.e2j.jastadd.model.Grammar
;
import
de.tudresden.inf.st.e2j.parser.EcoreParser
;
import
de.tudresden.inf.st.e2j.parser.XMIParseException
;
import
java.io.*
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.List
;
public
class
Main
{
private
static
final
String
VERSION
=
"0.1"
;
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"Hello, world!"
);
if
(
args
.
length
!=
2
)
{
printUsage
();
}
else
{
transformFile
(
args
[
0
],
args
[
1
]);
}
}
private
static
void
transformFile
(
String
sourceFileName
,
String
targetFileName
)
{
List
<
EObject
>
ePackages
=
null
;
EcoreParser
parser
=
new
EcoreParser
();
// check if the input file exists
Path
sourcePath
=
Paths
.
get
(
sourceFileName
);
if
(
Files
.
notExists
(
sourcePath
))
{
exitWithError
(
"the source file does not exist."
);
}
Path
targetPath
=
Paths
.
get
(
targetFileName
);
if
(
Files
.
exists
(
targetPath
))
{
exitWithError
(
"the target file already exists."
);
}
try
(
InputStream
stream
=
Files
.
newInputStream
(
sourcePath
))
{
ePackages
=
parser
.
parse
(
stream
);
}
catch
(
IOException
e
)
{
exitWithError
(
"Unable to open or read source file."
);
}
catch
(
XMIParseException
e
)
{
exitWithError
(
"Parse error occurred: "
+
e
.
getMessage
());
}
if
(
ePackages
==
null
||
ePackages
.
size
()
==
0
)
{
exitWithError
(
"No ecore packages were parsed."
);
}
StringBuilder
b
=
new
StringBuilder
();
for
(
EObject
eObject
:
ePackages
)
{
if
(!(
eObject
instanceof
EPackage
))
{
exitWithError
(
"One of the parsed top-level objects is no EPackage."
);
}
EPackage
ePackage
=
((
EPackage
)
eObject
);
try
{
Grammar
grammar
=
ePackage
.
getGrammar
();
grammar
.
print
(
b
);
}
catch
(
Exception
e
)
{
exitWithError
(
"Unable to transform Ecore package "
+
ePackage
.
getName
()
+
" to grammar."
);
}
b
.
append
(
"\n\n"
);
}
if
(!
targetFileName
.
endsWith
(
".relast"
))
{
targetFileName
+=
".relast"
;
}
try
(
PrintWriter
out
=
new
PrintWriter
(
targetFileName
,
StandardCharsets
.
UTF_8
.
name
()))
{
out
.
print
(
b
.
toString
());
}
catch
(
FileNotFoundException
|
UnsupportedEncodingException
e
)
{
exitWithError
(
"Unable to write relast file"
);
}
}
private
static
void
exitWithError
(
String
message
)
{
System
.
err
.
println
(
"ERROR: "
+
message
);
System
.
err
.
println
(
"exiting..."
);
System
.
exit
(-
1
);
}
private
static
void
printUsage
()
{
System
.
out
.
println
(
"Ecore2Relast version "
+
VERSION
+
": generate a relational JastAdd grammar from an ecore model"
);
System
.
out
.
println
(
"Attention: this is a very early version that might contain bugs. please review the generated grammars."
);
System
.
out
.
println
(
"Limitations: Only essential structural parts of ecore models are transformed. Multiple inheritance is not supported."
);
System
.
out
.
println
(
"Usage:"
);
System
.
out
.
println
(
" -h, --help print this message"
);
System
.
out
.
println
(
" <input.ecore> <output.relast> transform the input ecore model into an equivalent grammar with the given name"
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment