Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4478 #80

Merged
merged 37 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
bcba811
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer May 8, 2024
de2758c
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer May 21, 2024
375f489
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer May 29, 2024
f7e9aca
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Jun 6, 2024
579c161
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Jul 22, 2024
5ba0808
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Aug 26, 2024
71a8a98
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Sep 4, 2024
d04e6f8
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Sep 9, 2024
67fb180
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Sep 11, 2024
1452356
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Sep 11, 2024
c164d39
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Sep 17, 2024
242e11d
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Sep 18, 2024
19c7fb8
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Sep 23, 2024
c9381a4
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Sep 25, 2024
95c58c6
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Sep 25, 2024
4be629b
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Oct 2, 2024
e8f4b05
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Oct 14, 2024
f54f3d6
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Oct 15, 2024
e76863d
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Oct 16, 2024
df3a880
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Oct 17, 2024
cf61895
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Oct 22, 2024
a6e58f9
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Oct 29, 2024
4ddcfa6
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Nov 5, 2024
63fb988
Merge branch 'dev' of https://github.com/MontiCore/monticore into dev
maritabreuer Nov 7, 2024
62757f6
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Nov 11, 2024
6a60083
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Nov 12, 2024
17175bb
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Nov 12, 2024
e37323d
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Nov 13, 2024
792b782
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Nov 18, 2024
33ac9c4
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Dec 3, 2024
708a60e
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Dec 9, 2024
76d3429
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Dec 10, 2024
ab7f5a2
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Jan 6, 2025
36f704b
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Jan 9, 2025
4dfebde
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Jan 13, 2025
ffd5fd1
Merge remote-tracking branch 'origin/dev' into dev
maritabreuer Jan 15, 2025
8fb7f36
#4478: order of hook points
maritabreuer Jan 16, 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

package de.monticore.generating.templateengine;

import com.google.common.base.Strings;
import com.google.common.collect.*;
import de.monticore.ast.ASTNode;
import de.monticore.generating.templateengine.freemarker.SimpleHashFactory;
Expand All @@ -18,6 +17,12 @@
/**
* Class for managing hook points, features and (global) variables in templates.
*
* Order of template replacement:
* - specific before hook points
* - general before hook points
* - specific replacement or general replacement
* - specific after hook points
* - general after hook points
*/
public class GlobalExtensionManagement {

Expand Down Expand Up @@ -463,16 +468,17 @@ protected List<HookPoint> getTemplateForwardings(String templateName, ASTNode as
List<HookPoint> replacements = Lists.newArrayList();

// Before replacement
List<HookPoint> beforeHooks;
List<HookPoint> beforeHooks = Lists.newArrayList();
if (this.specificBefore.contains(templateName, ast)) {
beforeHooks = this.specificBefore.get(templateName, ast);
beforeHooks.addAll(this.specificBefore.get(templateName, ast));
Reporting.reportAddBeforeTemplate(templateName, Optional.of(ast), beforeHooks);
} else {
beforeHooks = Lists.newArrayList(this.before.get(templateName));
if (!beforeHooks.isEmpty()) {
Reporting.reportCallBeforeHookPoint(templateName, beforeHooks, ast);
}
}
List<HookPoint> hooks = Lists.newArrayList(this.before.get(templateName));
if (!hooks.isEmpty()) {
beforeHooks.addAll(hooks);
Reporting.reportCallBeforeHookPoint(templateName, hooks, ast);
}

replacements.addAll(beforeHooks);

// "normal" replacement
Expand All @@ -485,15 +491,16 @@ protected List<HookPoint> getTemplateForwardings(String templateName, ASTNode as
replacements.addAll(hps);

// After replacement
List<HookPoint> afterHooks;
List<HookPoint> afterHooks = Lists.newArrayList();
if (this.specificAfter.contains(templateName, ast)) {
afterHooks = this.specificAfter.get(templateName, ast);
Reporting.reportAddAfterTemplate(templateName, Optional.of(ast), afterHooks);
} else {
afterHooks = Lists.newArrayList(this.after.get(templateName));
if (!afterHooks.isEmpty()) {
Reporting.reportCallAfterHookPoint(templateName, afterHooks, ast);
}
}
hooks = Lists.newArrayList(this.after.get(templateName));
if (!hooks.isEmpty()) {
afterHooks.addAll(hooks);
Reporting.reportCallAfterHookPoint(templateName, hooks, ast);

}
replacements.addAll(afterHooks);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.IOException;
import java.util.Arrays;

import com.google.common.collect.Lists;
import de.monticore.ast.ASTNode;
import de.monticore.ast.ASTNodeMock;
import de.monticore.io.FileReaderWriter;
Expand Down Expand Up @@ -228,6 +229,208 @@ public void testSpecificBeforeTemplates() {

}

@Test
public void testOrderOfBeforeTemplates() {
ASTNode ast1 = new ASTNodeMock();

// Add specific template
glex.addBeforeTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.addBeforeTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("BCA", tc.include(TEMPLATE_PACKAGE + "A", ast1).toString());

// Reset
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", ast1, Lists.newArrayList());
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", Lists.newArrayList());

// set specific template
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("CA", tc.include(TEMPLATE_PACKAGE + "A", ast1).toString());

// Reset
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", ast1, Lists.newArrayList());
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", Lists.newArrayList());

// Add general template
glex.addBeforeTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.addBeforeTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("BCA", tc.include(TEMPLATE_PACKAGE + "A").toString());

// Reset
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", ast1, Lists.newArrayList());
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", Lists.newArrayList());

// set general template
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("CA", tc.include(TEMPLATE_PACKAGE + "A").toString());

// Reset
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", ast1, Lists.newArrayList());
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", Lists.newArrayList());

// Add and set specific template
glex.addBeforeTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("CA", tc.include(TEMPLATE_PACKAGE + "A", ast1).toString());

// Reset
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", ast1, Lists.newArrayList());
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", Lists.newArrayList());

// Set and add specific template
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.addBeforeTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("BCA", tc.include(TEMPLATE_PACKAGE + "A", ast1).toString());

// Reset
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", ast1, Lists.newArrayList());
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", Lists.newArrayList());

// Add and set general template
glex.addBeforeTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("CA", tc.include(TEMPLATE_PACKAGE + "A").toString());

// Reset
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", ast1, Lists.newArrayList());
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", Lists.newArrayList());

// Set and add general template
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.addBeforeTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("BCA", tc.include(TEMPLATE_PACKAGE + "A").toString());

// Reset
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", ast1, Lists.newArrayList());
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", Lists.newArrayList());

// Add specific and general template
glex.addBeforeTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.addBeforeTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("BCA", tc.include(TEMPLATE_PACKAGE + "A", ast1).toString());

// Reset
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", ast1, Lists.newArrayList());
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", Lists.newArrayList());

// Add general and specific template
glex.addBeforeTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.addBeforeTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("CBA", tc.include(TEMPLATE_PACKAGE + "A", ast1).toString());

// Set specific and general template
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("BCA", tc.include(TEMPLATE_PACKAGE + "A", ast1).toString());

// Set general and specific template
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.setBeforeTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("CBA", tc.include(TEMPLATE_PACKAGE + "A", ast1).toString());
}

@Test
public void testOrderOfAfterTemplates() {
ASTNode ast1 = new ASTNodeMock();

// Add specific template
glex.addAfterTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.addAfterTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("ABC", tc.include(TEMPLATE_PACKAGE + "A", ast1).toString());

// Reset
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", ast1, Lists.newArrayList());
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", Lists.newArrayList());

// set specific template
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("AC", tc.include(TEMPLATE_PACKAGE + "A", ast1).toString());

// Reset
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", ast1, Lists.newArrayList());
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", Lists.newArrayList());

// Add general template
glex.addAfterTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.addAfterTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("ABC", tc.include(TEMPLATE_PACKAGE + "A").toString());

// Reset
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", ast1, Lists.newArrayList());
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", Lists.newArrayList());

// set general template
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("AC", tc.include(TEMPLATE_PACKAGE + "A").toString());

// Reset
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", ast1, Lists.newArrayList());
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", Lists.newArrayList());

// Add and set specific template
glex.addAfterTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("AC", tc.include(TEMPLATE_PACKAGE + "A", ast1).toString());

// Reset
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", ast1, Lists.newArrayList());
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", Lists.newArrayList());

// Set and add specific template
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.addAfterTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("ABC", tc.include(TEMPLATE_PACKAGE + "A", ast1).toString());

// Reset
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", ast1, Lists.newArrayList());
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", Lists.newArrayList());

// Add and set general template
glex.addAfterTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("AC", tc.include(TEMPLATE_PACKAGE + "A").toString());

// Reset
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", ast1, Lists.newArrayList());
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", Lists.newArrayList());

// Set and add general template
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.addAfterTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("ABC", tc.include(TEMPLATE_PACKAGE + "A").toString());

// Reset
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", ast1, Lists.newArrayList());
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", Lists.newArrayList());

// Add specific and general template
glex.addAfterTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.addAfterTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("ABC", tc.include(TEMPLATE_PACKAGE + "A", ast1).toString());

// Reset
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", ast1, Lists.newArrayList());
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", Lists.newArrayList());

// Add general and specific template
glex.addAfterTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.addAfterTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("ACB", tc.include(TEMPLATE_PACKAGE + "A", ast1).toString());

// Set specific and general template
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("ABC", tc.include(TEMPLATE_PACKAGE + "A", ast1).toString());

// Set general and specific template
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", new TemplateHookPoint(TEMPLATE_PACKAGE + "B"));
glex.setAfterTemplate(TEMPLATE_PACKAGE + "A", ast1, new TemplateHookPoint(TEMPLATE_PACKAGE + "C"));
Assertions.assertEquals("ACB", tc.include(TEMPLATE_PACKAGE + "A", ast1).toString());
}

@Test
public void testAfterTemplates() {
Assertions.assertEquals("A", tc.include(TEMPLATE_PACKAGE + "A").toString());
Expand Down
Loading