Skip to content

Commit 2d2fd3c

Browse files
committed
Add JavaDoc to Change classes
1 parent 22d6af4 commit 2d2fd3c

20 files changed

+124
-8
lines changed

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/edit/AspectChangeManager.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@
2929
import org.slf4j.Logger;
3030
import org.slf4j.LoggerFactory;
3131

32+
/**
33+
* The AspectChangeManager is the central place to to changes/edits/refactorings of an {@link AspectModel}. The AspectChangeManager
34+
* wraps an AspectModel and allows applying instances of the {@link Change} class using the {@link #applyChange(Change)} method.
35+
* Calling this method returns a {@link ChangeReport} that describes the performed changes in a structured way. Use the
36+
* {@link ChangeReportFormatter} to render the ChangeReport to a structured string representation.
37+
* <br/>
38+
* Note the following points:
39+
* <ul>
40+
* <li>Only one AspectChangeManager must wrap a given AspectModel at any time</li>
41+
* <li>All changes are done <i>in-memory</i>. In order to write them to the file system, use the
42+
* {@link org.eclipse.esmf.aspectmodel.serializer.AspectSerializer}</li>
43+
* <li>After performing an {@link #applyChange(Change)}, {@link #undoChange()} or {@link #redoChange()} operation, and until the
44+
* next call of one of them, the methods {@link #modifiedFiles()}, {@link #createdFiles()} and {@link #removedFiles()} indicate
45+
* corresponding changes in the AspectModel's files.
46+
* </ul>
47+
*/
3248
public class AspectChangeManager implements ChangeContext {
3349
private static final Logger LOG = LoggerFactory.getLogger( AspectChangeManager.class );
3450

@@ -37,7 +53,6 @@ public class AspectChangeManager implements ChangeContext {
3753
private final DefaultAspectModel aspectModel;
3854
private final AspectChangeManagerConfig config;
3955
private final Map<AspectModelFile, FileState> fileState = new HashMap<>();
40-
private boolean isUndoOperation = false;
4156

4257
private enum FileState {
4358
CREATED, CHANGED, REMOVED
@@ -59,7 +74,6 @@ public AspectChangeManager( final AspectModel aspectModel ) {
5974

6075
public synchronized ChangeReport applyChange( final Change change ) {
6176
resetFileStates();
62-
isUndoOperation = false;
6377
final ChangeReport result = change.fire( this );
6478
updateAspectModelAfterChange();
6579
undoStack.offerLast( change.reverse() );
@@ -70,7 +84,6 @@ public synchronized void undoChange() {
7084
if ( undoStack.isEmpty() ) {
7185
return;
7286
}
73-
isUndoOperation = true;
7487
resetFileStates();
7588
final Change change = undoStack.pollLast();
7689
change.fire( this );
@@ -84,7 +97,6 @@ public synchronized void redoChange() {
8497
}
8598
resetFileStates();
8699
final Change change = redoStack.pollLast();
87-
isUndoOperation = false;
88100
change.fire( this );
89101
updateAspectModelAfterChange();
90102
undoStack.offerLast( change.reverse() );

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/edit/AspectChangeManagerConfig.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ public record AspectChangeManagerConfig(
2222
List<String> defaultFileHeader,
2323
boolean detailedChangeReport
2424
) {
25-
public static AspectChangeManagerConfig DEFAULT = AspectChangeManagerConfigBuilder.builder().build();
26-
2725
public AspectChangeManagerConfig {
2826
if ( defaultFileHeader == null ) {
2927
defaultFileHeader = List.of();

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/edit/Change.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,26 @@
1313

1414
package org.eclipse.esmf.aspectmodel.edit;
1515

16+
/**
17+
* This interface represents a single modification to an Aspect Model. Instances of Change should be applied to an Aspect Model
18+
* using {@link AspectChangeManager}; see the description about the change mechanism there. Instances of Change <b>must not</b>
19+
* perform file system operations; synching "adding", "removing" and "modifying" files with the file system is a separate step.
20+
*/
1621
public interface Change {
22+
/**
23+
* "Run" this change. This method should not be directly called on a Change object, but will be executed by the AspectChangeManager.
24+
* The passed {@link ChangeContext} provides information to the Change implementation about the current state of the AspectModel.
25+
*
26+
* @param changeContext the change context
27+
* @return the report describing what has been changed
28+
*/
1729
ChangeReport fire( ChangeContext changeContext );
1830

31+
/**
32+
* Returns a Change that is the reverse operation of this one, i.e., running this change and the reverse change after another
33+
* effectively cancels out any changes.
34+
*
35+
* @return the Change representing the reverse operation
36+
*/
1937
Change reverse();
2038
}

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/edit/ChangeContext.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
import org.eclipse.esmf.aspectmodel.AspectModelFile;
1919

20+
/**
21+
* The ChangeContext encapsulates the functionality provided to {@link Change} implementations to access the current set of
22+
* Aspect Model Files and indicate changes.
23+
*/
2024
public interface ChangeContext {
2125
Stream<AspectModelFile> aspectModelFiles();
2226

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/edit/ChangeGroup.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
import java.util.Arrays;
1818
import java.util.List;
1919

20+
/**
21+
* A Change that groups other changes
22+
*/
2023
public class ChangeGroup implements Change {
2124
private final String summary;
2225
private final List<Change> changes;

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/edit/ChangeReport.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
import java.util.List;
1717
import java.util.Map;
1818

19+
/**
20+
* A structured representation of a number of {@link Change}s
21+
*/
1922
public interface ChangeReport {
2023
ChangeReport NoChanges = new ChangeReport() {
2124
};

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/edit/ChangeReportFormatter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
import org.apache.jena.rdf.model.Model;
2424
import org.apache.jena.rdf.model.ModelFactory;
2525

26+
/**
27+
* Takes a {@link ChangeReport} as an input and renders it as a string
28+
*/
2629
public class ChangeReportFormatter implements BiFunction<ChangeReport, AspectChangeManagerConfig, String> {
2730
public static final ChangeReportFormatter INSTANCE = new ChangeReportFormatter();
2831

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/edit/change/AddAspectModelFile.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
import org.apache.jena.rdf.model.Model;
2525
import org.apache.jena.rdf.model.ModelFactory;
2626

27+
/**
28+
* Represents the operation of adding an {@link AspectModelFile} to an AspectModel
29+
*/
2730
public class AddAspectModelFile extends AbstractChange {
2831
private final AspectModelFile newFile;
2932

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/edit/change/AddElementDefinition.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
import org.apache.jena.rdf.model.Model;
2121
import org.apache.jena.rdf.model.ModelFactory;
2222

23+
/**
24+
* Adds the definition of a model element to an AspectModelFile. The definition is given as a set of RDF statements (a {@link Model}).
25+
*/
2326
public class AddElementDefinition extends EditAspectModel {
2427
private final AspectModelUrn elementUrn;
2528
private final Model definition;

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/edit/change/EditAspectModel.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
package org.eclipse.esmf.aspectmodel.edit.change;
1515

16-
import java.util.AbstractMap;
1716
import java.util.Map;
1817
import java.util.stream.Collectors;
1918

@@ -23,11 +22,27 @@
2322

2423
import org.apache.jena.rdf.model.Model;
2524

25+
/**
26+
* Abstract base class for all Changes that change the content (i.e., the underlying RDF) of an Aspect Model file.
27+
*/
2628
public abstract class EditAspectModel extends AbstractChange {
29+
/**
30+
* Represents the changes to perform on the RDF model
31+
*
32+
* @param add the set of statements to add
33+
* @param remove the set of statements to remove
34+
* @param description the description of this change set (used in the {@link ChangeReport})
35+
*/
2736
protected record ModelChanges( Model add, Model remove, String description ) {
2837
public static final ModelChanges NONE = new ModelChanges( null, null, "" );
2938
}
3039

40+
/**
41+
* Each AspectModelFile is changed separately, so extending classes need to calculate changes for a given file.
42+
*
43+
* @param aspectModelFile the AspectModelFile to change
44+
* @return the set of changes
45+
*/
3146
abstract protected ModelChanges calculateChangesForFile( AspectModelFile aspectModelFile );
3247

3348
@Override

0 commit comments

Comments
 (0)