Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
b46347f
Same version as used MontiCore
ahellwig Feb 10, 2023
7efd6be
Move test corpus versions to separate catalog
TheMrMilchmann Feb 15, 2023
f0380e4
Simplify corpus dependency declarations
TheMrMilchmann Feb 23, 2023
41579d3
Avoid eager task creation
TheMrMilchmann Feb 23, 2023
a694b6f
Cleanup corpus catalog and add a Java 17 library
TheMrMilchmann Feb 23, 2023
10531ba
Support record declarations
TheMrMilchmann Mar 1, 2023
868a5db
Support text blocks
TheMrMilchmann Mar 8, 2023
4cdbd02
Document corpus testing
TheMrMilchmann Mar 8, 2023
b950d2d
Replace deprecated method usage
TheMrMilchmann Mar 8, 2023
ee29540
Remove outdated test case
TheMrMilchmann Mar 8, 2023
2b3f736
Fix the emf subproject build
TheMrMilchmann Mar 9, 2023
12bdd46
Fix CI by disabling the corpus test for Java 17
ahellwig Jun 7, 2023
ab32742
Exchange handwritten pretty-printer with generated one.
N-Jansen Jun 13, 2023
443a0cd
Release version 7.5.0.
N-Jansen Jun 14, 2023
3d7e91f
Update version to 7.6.0-SNAPSHOT.
N-Jansen Jun 14, 2023
274409a
Fix: TypeDeclarationSymbol should be top level symbol of the artifact…
ahellwig Jun 16, 2023
a181edc
Fix compilation
SE-FDr Jan 17, 2024
214bc74
Merge branch 'fixJD-ExtType' into 'dev'
SE-FDr Jan 17, 2024
c0e16ae
BR
rumpe Mar 13, 2024
360f19b
BR
rumpe Mar 13, 2024
0014527
add java to cd generator
JonasBoecker Mar 25, 2024
5f7cfd1
fix javadsl ASTMCQualifiedType
JonasBoecker Mar 25, 2024
da585ad
generator
JonasBoecker Mar 28, 2024
0dc3c09
generator
JonasBoecker Mar 28, 2024
c125c21
add cd dependency to emf
JonasBoecker Mar 28, 2024
39409b9
refactor get modifier
JonasBoecker Mar 28, 2024
f6f285e
Merge branch 'add-cd-generator' into 'dev'
JonasBoecker Mar 28, 2024
a2820b2
rework JavaDSLTool
JonasBoecker Mar 28, 2024
c8178eb
add comments
JonasBoecker Mar 28, 2024
60b8961
Merge branch 'rework-tool' into 'dev'
JonasBoecker Mar 28, 2024
07a416f
Fix incorrect interface type printing.
N-Jansen Apr 18, 2024
acac83e
update to MC 7.7.0
SE-FDr Aug 1, 2024
a6f106a
use new MontiCore Plugin
SE-FDr Aug 1, 2024
cfe9ef6
use TypeParameters from MC
SE-FDr Aug 1, 2024
3e76ef5
remove duplicate source
SE-FDr Aug 1, 2024
143f50e
BR
rumpe Sep 11, 2024
19a7c37
Merge branch 'typeParameters-MC' into 'dev'
SE-FDr Oct 2, 2024
e4584d6
BR
rumpe Oct 3, 2024
cb915c3
ParseVisitors
luepges Jan 8, 2025
e369f4a
add ref-code-adaptation
Feb 26, 2025
c7b9829
Merge branch 'dev' of github.com:monticore/javaDSL into dev
Feb 26, 2025
dd0a7f5
Merge branch 'refs/heads/dev' into ref-code-adaptation
Feb 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ allprojects {
subprojects {
apply plugin: "java-library"
apply plugin: "maven-publish"
apply plugin: "monticore"
apply plugin: "de.monticore.generator"

java {
toolchain {
Expand All @@ -36,13 +36,13 @@ subprojects {
withSourcesJar()
}

tasks.withType(JavaCompile) {
dependsOn(tasks.withType(MCTask))
tasks.withType(JavaCompile).configureEach {
dependsOn(tasks.withType(MCGenTask))

options.encoding = "UTF-8"
}

tasks.withType(Test) {
tasks.withType(Test).configureEach {
useJUnitPlatform()

testLogging {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repo=https://nexus.se.rwth-aachen.de/content/groups/public

useLocalRepo=false

version=7.4.0-SNAPSHOT
version=7.7.0-SNAPSHOT

org.gradle.caching=true
org.gradle.welcome=never
org.gradle.welcome=never
20 changes: 20 additions & 0 deletions gradle/corpus.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# The corpus of libraries is used to test the generated infrastructure. For this
# purpose, a variety of open-source libraries targeting different Java versions
# are used. Only the sources of these libraries are used during testing. Their
# versions must not necessarily align with the project's dependencies.
#
# Read more in javaDSL/src/main/grammars/de/monticore/java/JavaDSL.md
#
[libraries]
# com.osmerion.quitte - Quitte
# https://github.com/Osmerion/Quitte - Java 17
quitte = { module = "com.osmerion.quitte:quitte", version = "0.7.0" }

# com.google.guava - Guava
# https://github.com/google/guava - Java 8
guava = { module = "com.google.guava:guava", version = "31.1-jre" }

# de.monticore - MontiCore
# https://github.com/MontiCore/monticore - Java 11
monticore-runtime = { module = "de.monticore:monticore-runtime", version = "7.6.0-SNAPSHOT" }
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ emf = "2.15.0"
gradle-shadow-plugin = "7.1.2"
guava = "31.1-jre"
junit = "5.9.0"
monticore = "7.5.0-SNAPSHOT"
monticore = "7.7.0-SNAPSHOT"


[libraries]
Expand Down
19 changes: 18 additions & 1 deletion javaDSL-emf/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,26 @@ task copyTestSources(type: Copy) {
from "${project(':javaDSL').projectDir}/src/main"
}

task generate(type: MCTask) {
tasks.register("generateTextBlock", MCTask) {
dependsOn(copyMainSources, copyTestSources)

grammar = file "$grammarsDir/de/monticore/java/TextBlock.mc4"
outputDir = file "$buildDir/generated-sources/monticore/sourcecode"
handcodedPath "$srcMainDir/java"

script = "de/monticore/monticore_emf.groovy"

def upToDate = incCheck("de/monticore/java/TextBlock.mc4")
outputs.upToDateWhen { upToDate }
}

tasks.register("generate", MCTask) {
dependsOn(tasks.generateTextBlock)
dependsOn(copyMainSources, copyTestSources)

grammar = file "$grammarsDir/de/monticore/java/JavaDSL.mc4"
outputDir = file "$buildDir/generated-sources/monticore/sourcecode"
modelPath "$grammarsDir"
handcodedPath "$srcMainDir/java"

script = "de/monticore/monticore_emf.groovy"
Expand All @@ -48,6 +63,7 @@ task generate(type: MCTask) {

dependencies {
implementation(platform(libs.junit.bom))
implementation "de.monticore.lang:cd4analysis:7.7.0-SNAPSHOT"

api(libs.monticore.grammar.emf)
api(libs.monticore.runtime.emf)
Expand All @@ -63,5 +79,6 @@ dependencies {
}

testImplementation(libs.junit.jupiter.api)
testImplementation(libs.junit.jupiter.params)
testRuntimeOnly(libs.junit.jupiter.engine)
}
27 changes: 14 additions & 13 deletions javaDSL/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ def grammarsDir = "src/main/grammars"

configurations {
corpus {
canBeConsumed = false
canBeResolved = true

transitive = false

resolutionStrategy.dependencySubstitution.all {
artifactSelection {
selectArtifact("jar", "jar", "sources")
}
}
}
}

sourceSets {
main.java.srcDir("$buildDir/generated-sources/monticore/sourcecode")

grammars {
resources {
srcDir(grammarsDir)
Expand All @@ -25,15 +32,6 @@ java {
}
}

tasks.register('generate', MCTask) {
grammar = file "$projectDir/$grammarsDir/de/monticore/java/JavaDSL.mc4"
outputDir = file "$buildDir/generated-sources/monticore/sourcecode"
handcodedPath "$projectDir/src/main/java"

def upToDate = incCheck("de/monticore/java/JavaDSL.mc4")
outputs.upToDateWhen { upToDate }
}

tasks.register('extractCorpus') {
dependsOn(configurations.corpus)

Expand Down Expand Up @@ -65,6 +63,7 @@ tasks.withType(Test).configureEach {

dependencies {
implementation(platform(libs.junit.bom))
implementation "de.monticore.lang:cd4analysis:$version"

api(libs.monticore.grammar)
api(libs.monticore.runtime)
Expand All @@ -79,6 +78,8 @@ dependencies {
testImplementation(libs.junit.jupiter.params)
testRuntimeOnly(libs.junit.jupiter.engine)

corpus(libs.guava) { artifact { classifier = "sources" } }
corpus(libs.monticore.runtime) { artifact { classifier = "sources" } }
corpus(corpus.guava)
corpus(corpus.monticore.runtime)
// TODO: fix parser for Java 17 and enable
//corpus(corpus.quitte)
}
104 changes: 71 additions & 33 deletions javaDSL/src/main/grammars/de/monticore/java/JavaDSL.mc4
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,35 @@ package de.monticore.java;
* |-> de.monticore.types.MCSimpleGenericTypes
* |-> de.monticore.types.MCCollectionTypes
* |-> de.monticore.types.MCBasicTypes (*)
* |-> de.monticore.types.TypeParameters
* |-> de.monticore.symbols.BasicSymbols
* |-> de.monticore.MCBasics (*)
* |-> de.monticore.types.MCBasicTypes
* |-> de.monticore.MCBasics (*)
*
* (*) Dependencies are emitted because they have been listed previously.
* (*) Repeated Dependencies are omitted.
*/
grammar JavaDSL extends de.monticore.JavaLight,
grammar JavaDSL extends
de.monticore.java.TextBlock,
de.monticore.JavaLight,
de.monticore.expressions.BitExpressions,
de.monticore.expressions.LambdaExpressions, // TODO: move to JavaLight?
de.monticore.literals.MCJavaLiterals,
de.monticore.statements.MCFullJavaStatements,
de.monticore.types.MCArrayTypes,
de.monticore.types.MCFullGenericTypes {
de.monticore.types.MCFullGenericTypes,
de.monticore.types.TypeParameters {

start CompilationUnit;

// starting point for parsing a java file
interface scope CompilationUnit;
interface CompilationUnit;

scope OrdinaryCompilationUnit implements CompilationUnit
OrdinaryCompilationUnit implements CompilationUnit
= PackageDeclaration? ImportDeclaration* TypeDeclaration*
;

scope ModularCompilationUnit implements CompilationUnit
ModularCompilationUnit implements CompilationUnit
= ImportDeclaration* ModuleDeclaration
;

Expand Down Expand Up @@ -158,7 +166,40 @@ symbolrule ClassDeclaration =
ClassBody
= "{" ClassBodyDeclaration* "}"
;


/*
* Records Classes
*
* https://docs.oracle.com/javase/specs/jls/se19/html/jls-8.html#jls-8.10
*/

symbol scope RecordDeclaration extends TypeDeclaration
= JavaModifier* "record" Name TypeParameters? RecordHeader
("implements" implementedInterface:(MCType || ",")+)?
RecordBody
;

RecordHeader
= "(" (RecordComponent || ",")* ")"
;

RecordComponent
= JavaModifier* MCType (arrayAnnotations:Annotation* variableArity:"...")? Name
;

astrule RecordComponent =
method public boolean isHasVariableArity() {
return this.isPresentVariableArity();
};

RecordBody
= "{" (ClassBodyDeclaration | CompactConstructorDeclaration)* "}"
;

CompactConstructorDeclaration
= JavaModifier* Name body:MCJavaBlock
;

symbol scope InterfaceDeclaration extends TypeDeclaration
= JavaModifier* "interface" Name TypeParameters?
("extends" extendedInterface:(MCType || ",")+)?
Expand Down Expand Up @@ -187,18 +228,6 @@ EnumBody
= ";" ClassBodyDeclaration*
;

TypeParameters
= "<" (TypeParameter || ",")+ ">"
;

symbol TypeParameter
= Name ("extends" TypeBound)?
;

TypeBound
= (MCType || "&")+
;

ClassBlock implements ClassBodyDeclaration
= (["static"])? JavaBlock
;
Expand Down Expand Up @@ -260,8 +289,12 @@ AnnotatedName = Annotation* Name;

@Override
MCArrayType implements MCType
= MCType (AnnotatedDimension {_builder.setDimensions(_builder.getDimensions()+1);} )+
= MCType (AnnotatedDimension)+
;
astrule MCArrayType =
method public int getDimensions() {
return this.sizeAnnotatedDimensions();
};

@Override
MCBasicGenericType implements MCGenericType <20>
Expand Down Expand Up @@ -330,17 +363,6 @@ ClassCreatorRest
= Arguments ClassBody?
;

@Override ExtType = MCType;

ExtLiteral = Literal;

@Override ExtReturnType = MCReturnType;

@Override ExtTypeArgument = MCTypeArgument;

ExtTypeParameter = TypeParameter;
@Override ExtTypeParameters = TypeParameters;

/*
* TODO Remove this
* This is a workaround to a questionable behavior in the core grammar JavaLight
Expand All @@ -355,9 +377,8 @@ JavaAnnotation extends JavaModifier implements ElementValue
( "(" AnnotationArguments? ")" )?
;

@Override
AnonymousClass implements Creator
= ExtType Arguments ClassBody?
= MCType Arguments ClassBody?
;


Expand All @@ -375,5 +396,22 @@ interface MethodReferenceTarget;
ConstructorReferenceTarget implements MethodReferenceTarget = "new";
MethodNameReferenceTarget implements MethodReferenceTarget = Name;

TextBlockLiteral implements Literal, SignedLiteral
= source:TextBlock
;

/*========================================================================*/
/*============================ LEXER RULES ===============================*/
/*========================================================================*/

token TextBlock
= TextBlockDelimiter (TextBlockCharacters)? TextBlockDelimiter
: {setText(de.monticore.java.utils.TextBlockUtils.preprocessTextBlock(getText().substring(3, getText().length() - 4)));};

fragment token TextBlockCharacters
= (' ' | '\t')* ('\r' | '\n') (. | EscapeSequence)*;

fragment token TextBlockCharacter
= '"' | '\\' | EscapeSequence;

}
31 changes: 17 additions & 14 deletions javaDSL/src/main/grammars/de/monticore/java/JavaDSL.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
# JavaDSL
JavaDSL offers a full parser for Java (Spec 1.7), many context conditions and
a pretty printer.

The grammar file is [`de.monticore.java.JavaDSL`][JavaDSL].
JavaDSL provides a full spec-compliant parser for Java 17, a pretty printer and
additional tools for working with Java source artifacts.

## Handwritten Extensions
### AST
The core grammar definition can be found in [`de.monticore.java.JavaDSL`][JavaDSL].

## Parser
## Symboltable

## Functionality
### CoCos
## Testing

### PrettyPrinter
### Corpus Tests

### Helper
To ensure that the parser covers the entire specification, it is tested on a
large corpus of open-source libraries. _Corpus Tests_ are executed as part of
the regular unit tests.

To add a library to the corpus, modifications should be made in two places:

1. The dependency should be added to the [corpus' version catalog](../../../../../../../gradle/corpus.versions.toml), and
2. the dependency should be added to the "corpus" configuration in the [build script](../../../../../../build.gradle).

Note, that the libraries in the corpus must not be kept up-to-date. Instead, a
variety of libraries targeting different Java language versions and use-cases
should be used to cover different code-styles and language features.

### Reporting

### CLI Application

[JavaDSL]: https://git.rwth-aachen.de/monticore/javaDSL/blob/dev/javaDSL/src/main/grammars/de/monticore/java/JavaDSL.mc4
7 changes: 7 additions & 0 deletions javaDSL/src/main/grammars/de/monticore/java/TextBlock.mc4
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package de.monticore.java;

component grammar TextBlock {

token TextBlockDelimiter = '"' '"' '"';

}
Loading