Skip to content

Commit

Permalink
Rule level tree functionality (essentially) restored
Browse files Browse the repository at this point in the history
However, see gh issue #799
  • Loading branch information
rensink committed Aug 2, 2024
1 parent fa58259 commit 84d3fb0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ public interface AspectElement extends Element, Fixable {
/** Returns the aspect graph to which this element belongs. */
public AspectGraph getGraph();

/** If */
default public AspectElement denormalise() {
if (getGraph() instanceof NormalAspectGraph nag) {
return nag.normalToSourceMap().get(this);
} else {
return this;
}
}

/** Returns the graph role set for this aspect element.
* Convenience method for {@code getGraph().getRole()}.
* */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import nl.utwente.groove.algebra.syntax.Variable;
import nl.utwente.groove.grammar.aspect.AspectContent.NestedValue;
import nl.utwente.groove.grammar.aspect.AspectKind.Category;
import nl.utwente.groove.graph.Element;
import nl.utwente.groove.util.Exceptions;
import nl.utwente.groove.util.Groove;
import nl.utwente.groove.util.Keywords;
Expand Down Expand Up @@ -92,8 +91,8 @@ public AspectGraphMorphism sourceToNormalMap() {
private final AspectGraphMorphism sourceToNormalMap;

/** Computes the inverse of {@link #sourceToNormalMap}. */
private final Map<Element,Element> initNormalToSourceMap() {
Map<Element,Element> result = new HashMap<>();
private final Map<AspectElement,AspectElement> initNormalToSourceMap() {
Map<AspectElement,AspectElement> result = new HashMap<>();
var toNormalMap = this.sourceToNormalMap;
toNormalMap.nodeMap().entrySet().forEach(e -> result.put(e.getValue(), e.getKey()));
toNormalMap.edgeMap().entrySet().forEach(e -> result.put(e.getValue(), e.getKey()));
Expand Down Expand Up @@ -135,13 +134,13 @@ private void replaceNormalisedNode(AspectNode orig, AspectNode replacement) {
/** Returns the morphism from this normalised graph to the source {@link AspectGraph}.
* Should only be called after the normalised graph has been fixed.
*/
public Map<Element,Element> normalToSourceMap() {
public Map<AspectElement,AspectElement> normalToSourceMap() {
assert isFixed();
return this.normalToSourceMap;
}

/** Inverse of the {@link #sourceToNormalMap} before actual normalisation. */
private final Map<Element,Element> normalToSourceMap;
private final Map<AspectElement,AspectElement> normalToSourceMap;

private AspectNode addNormalisedNode(AspectElement orig) {
AspectNode result = addNode();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/nl/utwente/groove/grammar/model/RuleModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ public AspectGraph getNormalSource() {
private @Nullable AspectGraph normalSource;

/** Returns an element map from the normalised graph to the source graph. */
private Map<Element,Element> normalToSourceMap() {
private Map<AspectElement,AspectElement> normalToSourceMap() {
var result = this.normalToSourceMap;
if (result == null) {
var normal = getNormalSource();
Expand All @@ -507,7 +507,7 @@ private Map<Element,Element> normalToSourceMap() {
}

/** Mapping from normalised source model to source model. */
private @Nullable Map<Element,Element> normalToSourceMap;
private @Nullable Map<AspectElement,AspectElement> normalToSourceMap;

@Override
protected FormatErrorSet createErrors() {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/nl/utwente/groove/gui/tree/RuleLevelTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ private boolean updateTree() {
Set<AspectJCell> levelCells = new HashSet<>();
// add all cells for this level according to the rule level tree
for (AspectElement elem : levelEntry.getValue()) {
AspectJCell jCell = jModel.getJCell(elem);
// this is an element from the normalised source, about which the AspectJModel is unaware
AspectJCell jCell = jModel.getJCell(elem.denormalise());
if (jCell != null) {
levelCells.add(jCell);
}
Expand All @@ -166,12 +167,12 @@ private boolean updateTree() {
// also add the nesting nodes and edges
AspectNode ruleLevelNode = index.getLevelNode();
if (ruleLevelNode != null) {
AspectJCell jCell = jModel.getJCell(ruleLevelNode);
AspectJCell jCell = jModel.getJCell(ruleLevelNode.denormalise());
if (jCell != null) {
levelCells.add(jCell);
}
for (AspectElement edge : this.rule.getSource().edgeSet(ruleLevelNode)) {
jCell = jModel.getJCell(edge);
jCell = jModel.getJCell(edge.denormalise());
if (jCell != null) {
levelCells.add(jCell);
}
Expand Down

0 comments on commit 84d3fb0

Please sign in to comment.