Skip to content

Commit 0ff95ea

Browse files
committed
Merge master; implement R024 and R026; small bug fixes
2 parents 1699e83 + 9ca520c commit 0ff95ea

50 files changed

Lines changed: 2389 additions & 318 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎javaDSL/src/main/grammars/de/monticore/java/JavaDSL.mc4‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,13 @@ ArrayInitializer implements VariableInitializer
267267

268268
// ANNOTATIONS
269269

270+
Annotation implements JavaModifier;
271+
272+
astrule Annotation =
273+
method public int getModifier() {
274+
return -1;
275+
};
276+
270277
symbol scope AnnotationTypeDeclaration extends TypeDeclaration
271278
= JavaModifier* "@" "interface" Name AnnotationTypeBody
272279
;
@@ -381,19 +388,6 @@ LambdaParameter implements Variable = (["var"] | MCType)? Name;
381388

382389
nokeyword "var";
383390

384-
/*
385-
* TODO Remove this
386-
* This is a workaround to a questionable behavior in the core grammar JavaLight
387-
* where the production "Annotation" does not extend "JavaModifier" whereas
388-
* various productions use JavaModifier in places where annotations are allowed.
389-
*
390-
* We cannot override the Annotation production because we already extend
391-
* JavaModifier either, so we'll have to live with a separate production for now.
392-
*/
393-
JavaAnnotation extends JavaModifier implements ElementValue
394-
= "@" annotationName:MCQualifiedName
395-
( "(" AnnotationArguments? ")" )?
396-
;
397391

398392
AnonymousClass implements Creator
399393
= MCType Arguments ClassBody?

‎ref-code-adaptation/README.md‎

Lines changed: 75 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ Required inputs:
1111
- concrete class diagram
1212
- mapping names, such as `buildPat`, `observer`, or `ref`
1313
- adapter/reference Java source directory
14-
- concrete Java source directory
1514
- output directory
1615

16+
The API accepts an optional concrete Java source directory. When it is omitted,
17+
does not exist, or contains no Java files, `CodeAdapter` generates the concrete
18+
Java baseline from the final concrete CD. A supplied directory that contains
19+
Java remains authoritative handwritten concrete code. The CLI still requires
20+
its existing concrete-code argument.
21+
1722
The class diagrams define which reference classes, fields, and methods incarnate as concrete Java elements. Java code is parsed and transformed with MontiCore JavaDSL and Spoon.
1823

1924
## Adaptation Flow
@@ -24,17 +29,22 @@ The class diagrams define which reference classes, fields, and methods incarnate
2429
a staging workspace or changing existing output.
2530
4. Copy and filter reference adapter code for the active mapping.
2631
5. Adapt types, fields, methods, parameters, constructor calls, and pattern-derived members.
27-
6. Merge adapted code with existing concrete code.
28-
7. Clean generated Java:
32+
6. Merge adapted code with existing concrete code, when present.
33+
7. Clean staged handwritten Java:
2934
- remove `@Adapt` annotations with Spoon
3035
- remove invalid generated imports through JavaDSL import declarations
3136
- preserve valid existing imports without inventing imports for unresolved
3237
simple names
3338
- keep Spoon as the only whole-file formatter; import cleanup edits only
3439
import declaration source ranges
35-
8. Publish the completed staging directory transactionally, restoring the
40+
8. If no concrete Java was supplied, serialize the final concrete CD and run
41+
CD4Code with the staged adapted code as handwritten code. Merge generated
42+
`*TOP.java` companions and model-only declarations without overwriting the
43+
staged handwritten implementation.
44+
9. Clean the combined Java tree and publish the completed staging directory
45+
transactionally, restoring the
3646
previous output if publication fails.
37-
9. Compile and structurally verify generated Java in tests.
47+
10. Compile and structurally verify generated Java in tests.
3848

3949
The context-building step depends on the `useConcretization` argument of
4050
`CodeAdapter.adapt(...)`.
@@ -51,6 +61,11 @@ This mode delegates model repair to cdconcretization before code adaptation:
5161
3. `JavaTypeUpdateService` projects Java-expressible elements that were added
5262
to the completed concrete CD, such as missing fields, methods, types, enum
5363
constants, inheritance, and interfaces.
64+
4. `ReferenceCodeDependencySelector` retains the transitive source-local
65+
helper closure of mapped reference types. Required Java-only helper members
66+
and helper classes do not need ignore annotations; unrelated source units
67+
are excluded. Reference-CD type uses inside retained helpers are adapted by
68+
the normal transformation passes.
5469

5570
Use this mode when the concrete CD may need deterministic model-level repair
5671
before Java adaptation.
@@ -60,16 +75,15 @@ before Java adaptation.
6075
This mode does not mutate or complete the concrete CD. It builds a manual
6176
incarnation context from:
6277

63-
- explicit stereotypes for the active mapping name,
64-
- deterministic name and adapted-name rules enabled by `CDConfParameter`,
78+
- explicit stereotypes on concrete-CD elements for the active mapping name,
79+
- deterministic same-name rules enabled by `CDConfParameter.NAME_MAPPING`,
6580
- manual `<<forEach="...">>` mappings derived from already-known
6681
incarnations.
6782

6883
The manual branch does not call `ConcretizationCompleter` or
6984
`CDConformanceChecker`, and it does not clone or create CD elements. Conflicts
70-
are reported together as a `CodeAdaptationException` before
71-
`JavaLoader.removeDirectory(outputPath)` is executed, so existing output is
72-
preserved when adaptation cannot safely start.
85+
are reported together as a `CodeAdaptationException` before staging is created
86+
or existing output is touched.
7387

7488
Supported manual `forEach` targets:
7589

@@ -83,6 +97,50 @@ example `getAttribute()` to `getFirstName()` and `getAge()`. The manual mode
8397
does not invent cdconcretization suffix rules; concrete stereotypes or enabled
8498
name rules must make the target deterministic.
8599

100+
#### Manual mappings without concrete Java (R-024)
101+
102+
The no-concrete-code API and manual mapping derivation are independent choices.
103+
This call combines them explicitly:
104+
105+
```java
106+
adapter.adaptWithoutConcreteCode(
107+
referenceCD,
108+
concreteCD,
109+
mappings,
110+
referenceCodePath,
111+
outputPath,
112+
false, // do not run cdconcretization
113+
true); // allow exact common-parent grouping
114+
```
115+
116+
The implementation then follows one transactional pipeline:
117+
118+
1. `AdaptationWorkspace` represents the concrete Java input as absent, while
119+
both CDs and the reference Java directory remain read-only inputs.
120+
2. Because `useConcretization` is false, the parsed concrete CD is neither
121+
cloned nor completed. `AdaptationContextFactory` delegates every mapping to
122+
`ManualIncarnationContextBuilder`.
123+
3. The builder scans concrete types first, then members within their mapped
124+
owners. An explicit `<<mapping="ReferenceElement">>` wins; enabled
125+
same-name/signature rules are the deterministic fallback. Reference-side
126+
`forEach` stereotypes copy or expand mappings already found in those passes.
127+
4. `AdaptationConflictDetector` and strict reference-Java validation run before
128+
staging. Manual mode does not enable R-026's unannotated-helper policy.
129+
5. Normal isolated mapping passes transform the reference Java. With no
130+
concrete Java base, this adapted result becomes the staged authoritative
131+
handwritten code.
132+
6. `ConcreteCodeGenerationService` serializes the unchanged concrete CD and
133+
runs CD4Code in a separate JVM, using the staged adapted Java as HWC.
134+
`OutputCodeService` keeps that HWC and adds generated `*TOP.java` companions,
135+
association fields, and model-only declarations.
136+
7. The combined sources are cleaned and published only after the entire run
137+
succeeds. Empty reference Java still reaches generation, so the concrete CD
138+
alone can produce a model baseline.
139+
140+
R-026 is intentionally a concretization-mode feature. Its transitive
141+
Java-helper selection is not used by the manual path above; unmatched manual
142+
helpers must still satisfy the normal manual validation policy.
143+
86144
## Association Adaptation
87145

88146
Associations affect Java through navigable role fields. For example,
@@ -117,6 +175,13 @@ assignments are rewritten only inside that owning Java type.
117175
immutable stable-key selection. An empty selection represents the ordinary case.
118176
- `MappingAdaptationRunner` owns the isolated per-pass updater lifecycle, output filtering, merge,
119177
cleanup, and error wrapping.
178+
- `ReferenceCodeDependencySelector` builds a package-qualified dependency graph
179+
once from the reference source snapshot and selects mapping-specific helper
180+
closures in concretization mode. Ambiguous source-local type resolution is
181+
rejected deterministically.
182+
- `ConcreteCodeGenerationService` runs CD4Code in an isolated JVM and workspace when
183+
the API receives no concrete Java. `OutputCodeService` merges its result with
184+
staged handwritten code, which always has precedence.
120185
- `CDTypeRelations` centralizes direct generated-AST access for interfaces,
121186
superclasses, modifiers, and type-reference printing. Runtime Java reflection
122187
is not used by the adapter.

0 commit comments

Comments
 (0)