From 0b36b7c387d05800c2b788aff9d551361c89b7f0 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 18 May 2022 16:59:21 -0700 Subject: [PATCH 1/6] Add default template that is just a skeleton --- .../ui/wizard/LFProjectTemplateProvider.java | 30 ++++++++++++------- .../lflang/ui/wizard/templates/c/src/Main.lf | 10 +++++++ 2 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 org.lflang.ui/src/org/lflang/ui/wizard/templates/c/src/Main.lf diff --git a/org.lflang.ui/src/org/lflang/ui/wizard/LFProjectTemplateProvider.java b/org.lflang.ui/src/org/lflang/ui/wizard/LFProjectTemplateProvider.java index 79ee55acb8..c43ad486e8 100644 --- a/org.lflang.ui/src/org/lflang/ui/wizard/LFProjectTemplateProvider.java +++ b/org.lflang.ui/src/org/lflang/ui/wizard/LFProjectTemplateProvider.java @@ -20,18 +20,16 @@ * * Each template is able to generate one or more projects. Each project can be configured such that any number of files are included. */ -@SuppressWarnings("restriction") class LFProjectTemplateProvider implements IProjectTemplateProvider { @Override public AbstractProjectTemplate[] getProjectTemplates() { - return new AbstractProjectTemplate[] { new FederatedProject(), + return new AbstractProjectTemplate[] { + new DefaultProject(), new FederatedProject(), new HelloWorldProject(), new InteractiveProject(), new ParallelProject(), new PipelineProject(), new ReflexGameProject(), new WebServerProject()}; } } - -@SuppressWarnings("restriction") abstract class LFProjectTemplate extends AbstractProjectTemplate { ProjectFactory setup(List folders) { @@ -58,7 +56,22 @@ String readFromFile(String target, String fileName) { } } -@SuppressWarnings("restriction") +@ProjectTemplate( + label="Default", + icon="project_template.png", + description="

Default

Project with an empty main reactor.

" +) +final class DefaultProject extends LFProjectTemplate { + + @Override + public void generateProjects(IProjectGenerator generator) { + var proj = setup(List.of("src")); + var fileName = "src/Main.lf"; + this.addFile(proj, fileName, readFromFile("c", fileName)); + generator.generate(proj); + } +} + @ProjectTemplate(label="Parallel", icon="project_template.png", description="

Parallel

A simple" + " fork-join pattern that exploits parallelism.

") final class PipelineProject extends LFProjectTemplate { @@ -72,9 +85,9 @@ public void generateProjects(IProjectGenerator generator) { } } + @ProjectTemplate(label="Federated", icon="project_template.png", description="

Federated

" + "

A federated \"Hello World\" program.

") -@SuppressWarnings("restriction") final class FederatedProject extends LFProjectTemplate { @Override @@ -88,7 +101,6 @@ public void generateProjects(IProjectGenerator generator) { @ProjectTemplate(label="Parallel", icon="project_template.png", description="

Parallel

" + "

A simple fork-join pattern that exploits parallelism.

") -@SuppressWarnings("restriction") final class ParallelProject extends LFProjectTemplate { @Override @@ -102,7 +114,6 @@ public void generateProjects(IProjectGenerator generator) { @ProjectTemplate(label="Hello World", icon="project_template.png", description="

Hello World

" + "

Print \"Hello world!\" in a target language of choice.

") -@SuppressWarnings("restriction") final class HelloWorldProject extends LFProjectTemplate { GroupTemplateVariable config = group("Configuration"); // FIXME: draw from Target enum instead @@ -132,7 +143,6 @@ public void generateProjects(IProjectGenerator generator) { @ProjectTemplate(label="Interactive", icon="project_template.png", description="

Interactive

" + "

Simulate sensor input through key strokes.

") -@SuppressWarnings("restriction") final class InteractiveProject extends LFProjectTemplate { @Override @@ -148,7 +158,6 @@ public void generateProjects(IProjectGenerator generator) { @ProjectTemplate(label="WebServer", icon="project_template.png", description="

Web Server

" + "

A simple web server implemented using TypeScript.

") -@SuppressWarnings("restriction") final class WebServerProject extends LFProjectTemplate { @Override @@ -162,7 +171,6 @@ public void generateProjects(IProjectGenerator generator) { @ProjectTemplate(label="ReflexGame", icon="project_template.png", description="

ReflexGame

" + "

A simple reflex game.

") -@SuppressWarnings("restriction") final class ReflexGameProject extends LFProjectTemplate { GroupTemplateVariable config = group("Configuration"); // FIXME: draw from Target enum instead diff --git a/org.lflang.ui/src/org/lflang/ui/wizard/templates/c/src/Main.lf b/org.lflang.ui/src/org/lflang/ui/wizard/templates/c/src/Main.lf new file mode 100644 index 0000000000..9b85a04b7b --- /dev/null +++ b/org.lflang.ui/src/org/lflang/ui/wizard/templates/c/src/Main.lf @@ -0,0 +1,10 @@ +target C // Other options: Python, Cpp, TypeScript, Rust. + +// Import and/or declare reactor classes. + +main reactor { + + // Instantiate reactors. + + // Connect ports. +} From e31e4ea15b7675a87b51a12f2457ad71b2c2c8b5 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 18 May 2022 17:31:09 -0700 Subject: [PATCH 2/6] Formatting only. Still have not found the bug. --- .../ui/wizard/LFProjectTemplateProvider.java | 151 ++++++++++-------- 1 file changed, 87 insertions(+), 64 deletions(-) diff --git a/org.lflang.ui/src/org/lflang/ui/wizard/LFProjectTemplateProvider.java b/org.lflang.ui/src/org/lflang/ui/wizard/LFProjectTemplateProvider.java index c43ad486e8..c1f03e1d5d 100644 --- a/org.lflang.ui/src/org/lflang/ui/wizard/LFProjectTemplateProvider.java +++ b/org.lflang.ui/src/org/lflang/ui/wizard/LFProjectTemplateProvider.java @@ -16,22 +16,23 @@ import org.eclipse.xtext.ui.wizard.template.StringSelectionTemplateVariable; /** - * Create a list with all project templates to be shown in the template new project wizard. - * - * Each template is able to generate one or more projects. Each project can be configured such that any number of files are included. + * Create a list with all project templates to be shown in the template new + * project wizard. Each template is able to generate one or more projects. Each + * project can be configured such that any number of files are included. */ class LFProjectTemplateProvider implements IProjectTemplateProvider { - @Override - public AbstractProjectTemplate[] getProjectTemplates() { - return new AbstractProjectTemplate[] { - new DefaultProject(), new FederatedProject(), - new HelloWorldProject(), new InteractiveProject(), - new ParallelProject(), new PipelineProject(), - new ReflexGameProject(), new WebServerProject()}; - } + @Override + public AbstractProjectTemplate[] getProjectTemplates() { + return new AbstractProjectTemplate[] { new DefaultProject(), + new FederatedProject(), new HelloWorldProject(), + new InteractiveProject(), new ParallelProject(), + new PipelineProject(), new ReflexGameProject(), + new WebServerProject() }; + } } + abstract class LFProjectTemplate extends AbstractProjectTemplate { - + ProjectFactory setup(List folders) { var proj = new PluginProjectFactory(); proj.setProjectName(this.getProjectInfo().getProjectName()); @@ -41,30 +42,30 @@ ProjectFactory setup(List folders) { proj.addFolders(folders); return proj; } - + String readFromFile(String target, String fileName) { - var stream = this.getClass().getResourceAsStream("templates/" + target + "/" + fileName); + var stream = this.getClass() + .getResourceAsStream("templates/" + target + "/" + fileName); var str = ""; if (stream != null) { - str = new BufferedReader( - new InputStreamReader(stream) - ).lines().collect(Collectors.joining("\n")); + str = new BufferedReader(new InputStreamReader(stream)).lines() + .collect(Collectors.joining("\n")); } else { - throw new RuntimeException("Unable to open template for '" + fileName + "'"); + throw new RuntimeException( + "Unable to open template for '" + fileName + "'"); } return str; } } @ProjectTemplate( - label="Default", - icon="project_template.png", - description="

Default

Project with an empty main reactor.

" -) + label = "Default", + icon = "project_template.png", + description = "

Default

Project with an empty main reactor.

") final class DefaultProject extends LFProjectTemplate { - @Override - public void generateProjects(IProjectGenerator generator) { + @Override + public void generateProjects(IProjectGenerator generator) { var proj = setup(List.of("src")); var fileName = "src/Main.lf"; this.addFile(proj, fileName, readFromFile("c", fileName)); @@ -72,12 +73,15 @@ public void generateProjects(IProjectGenerator generator) { } } -@ProjectTemplate(label="Parallel", icon="project_template.png", description="

Parallel

A simple" + - " fork-join pattern that exploits parallelism.

") +@ProjectTemplate( + label = "Pipeline", + icon = "project_template.png", + description = "

Parallel

A simple" + + " pipeline pattern that exploits parallelism.

") final class PipelineProject extends LFProjectTemplate { - @Override - public void generateProjects(IProjectGenerator generator) { + @Override + public void generateProjects(IProjectGenerator generator) { var proj = setup(List.of("src")); var fileName = "src/Pipeline.lf"; this.addFile(proj, fileName, readFromFile("c", fileName)); @@ -85,24 +89,29 @@ public void generateProjects(IProjectGenerator generator) { } } - -@ProjectTemplate(label="Federated", icon="project_template.png", description="

Federated

" + - "

A federated \"Hello World\" program.

") +@ProjectTemplate( + label = "Federated", + icon = "project_template.png", + description = "

Federated

" + + "

A federated \"Hello World\" program.

") final class FederatedProject extends LFProjectTemplate { - + @Override public void generateProjects(IProjectGenerator generator) { var proj = setup(List.of("src")); var fileName = "src/FederatedHelloWorld.lf"; this.addFile(proj, fileName, readFromFile("c", fileName)); - generator.generate(proj); + generator.generate(proj); } } -@ProjectTemplate(label="Parallel", icon="project_template.png", description="

Parallel

" + -"

A simple fork-join pattern that exploits parallelism.

") +@ProjectTemplate( + label = "Parallel", + icon = "project_template.png", + description = "

Parallel

" + + "

A simple fork-join pattern that exploits parallelism.

") final class ParallelProject extends LFProjectTemplate { - + @Override public void generateProjects(IProjectGenerator generator) { var proj = setup(List.of("src")); @@ -112,43 +121,51 @@ public void generateProjects(IProjectGenerator generator) { } } -@ProjectTemplate(label="Hello World", icon="project_template.png", description="

Hello World

" + -"

Print \"Hello world!\" in a target language of choice.

") +@ProjectTemplate( + label = "Hello World", + icon = "project_template.png", + description = "

Hello World

" + + "

Print \"Hello world!\" in a target language of choice.

") final class HelloWorldProject extends LFProjectTemplate { GroupTemplateVariable config = group("Configuration"); // FIXME: draw from Target enum instead - StringSelectionTemplateVariable target = combo("Target:", new String[] {"C", "C++", "Python", "TypeScript"}, "The target language to compile down to", config); - + StringSelectionTemplateVariable target = combo("Target:", + new String[] { "C", "C++", "Python", "TypeScript" }, + "The target language to compile down to", config); + @Override public void generateProjects(IProjectGenerator generator) { var proj = setup(List.of("src")); var fileName = "src/HelloWorld.lf"; switch (target.getValue()) { - case "C++": - addFile(proj, fileName, readFromFile("cpp", fileName)); - break; - case "C": - addFile(proj, fileName, readFromFile("c", fileName)); - break; - case "Python": - addFile(proj, fileName, readFromFile("py", fileName)); - break; - case "TypeScript": - addFile(proj, fileName, readFromFile("ts", fileName)); - break; + case "C++": + addFile(proj, fileName, readFromFile("cpp", fileName)); + break; + case "C": + addFile(proj, fileName, readFromFile("c", fileName)); + break; + case "Python": + addFile(proj, fileName, readFromFile("py", fileName)); + break; + case "TypeScript": + addFile(proj, fileName, readFromFile("ts", fileName)); + break; } generator.generate(proj); } } -@ProjectTemplate(label="Interactive", icon="project_template.png", description="

Interactive

" + -"

Simulate sensor input through key strokes.

") +@ProjectTemplate( + label = "Interactive", + icon = "project_template.png", + description = "

Interactive

" + + "

Simulate sensor input through key strokes.

") final class InteractiveProject extends LFProjectTemplate { - + @Override public void generateProjects(IProjectGenerator generator) { var proj = setup(List.of("src", "src/include")); - var fileName = "src/Interactive.lf"; + var fileName = "src/Interactive.lf"; this.addFile(proj, fileName, readFromFile("c", fileName)); var cmakeFile = "src/include/ncurses-cmake-extension.txt"; this.addFile(proj, cmakeFile, readFromFile("c", cmakeFile)); @@ -156,27 +173,33 @@ public void generateProjects(IProjectGenerator generator) { } } -@ProjectTemplate(label="WebServer", icon="project_template.png", description="

Web Server

" + -"

A simple web server implemented using TypeScript.

") +@ProjectTemplate( + label = "WebServer", + icon = "project_template.png", + description = "

Web Server

" + + "

A simple web server implemented using TypeScript.

") final class WebServerProject extends LFProjectTemplate { - + @Override public void generateProjects(IProjectGenerator generator) { var proj = setup(List.of("src")); - var fileName = "src/WebServer.lf"; + var fileName = "src/WebServer.lf"; this.addFile(proj, fileName, readFromFile("ts", fileName)); generator.generate(proj); } } -@ProjectTemplate(label="ReflexGame", icon="project_template.png", description="

ReflexGame

" + -"

A simple reflex game.

") +@ProjectTemplate( + label = "ReflexGame", + icon = "project_template.png", + description = "

ReflexGame

" + + "

A simple reflex game.

") final class ReflexGameProject extends LFProjectTemplate { GroupTemplateVariable config = group("Configuration"); // FIXME: draw from Target enum instead StringSelectionTemplateVariable target = combo("Target:", - new String[] { "C" }, - "The target language to compile down to", config); + new String[] { "C" }, "The target language to compile down to", + config); @Override public void generateProjects(IProjectGenerator generator) { From becde77f3caed23f674446ff2615b00ac7623ea2 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 18 May 2022 18:35:39 -0700 Subject: [PATCH 3/6] Address missing description issue. --- org.lflang.ui/src/org/lflang/ui/wizard/Messages.java | 4 +++- org.lflang.ui/src/org/lflang/ui/wizard/messages.properties | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/org.lflang.ui/src/org/lflang/ui/wizard/Messages.java b/org.lflang.ui/src/org/lflang/ui/wizard/Messages.java index 40095fc6fd..7f27c9da27 100644 --- a/org.lflang.ui/src/org/lflang/ui/wizard/Messages.java +++ b/org.lflang.ui/src/org/lflang/ui/wizard/Messages.java @@ -7,7 +7,9 @@ public class Messages extends NLS { private static final String BUNDLE_NAME = "org.lflang.ui.wizard.messages"; //$NON-NLS-1$ - + + public static String DefaultProject_Label; + public static String DefaultProject_Description; public static String HelloWorldProject_Label; public static String HelloWorldProject_Description; public static String InteractiveProject_Label; diff --git a/org.lflang.ui/src/org/lflang/ui/wizard/messages.properties b/org.lflang.ui/src/org/lflang/ui/wizard/messages.properties index b8bb01cda4..1afe7dad2e 100644 --- a/org.lflang.ui/src/org/lflang/ui/wizard/messages.properties +++ b/org.lflang.ui/src/org/lflang/ui/wizard/messages.properties @@ -1,3 +1,5 @@ +DefaultProject_Label=Default +DefaultProject_Description=

Default

Project with an empty main reactor.

HelloWorldProject_Label=Hello World HelloWorldProject_Description=

Hello World

Print "Hello world!" in a target language of choice.

InteractiveProject_Label=Interactive From 0ac62cf6aba16f1f985e263089e95ee3907fff86 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 18 May 2022 21:56:02 -0700 Subject: [PATCH 4/6] Comments and removal of superfluous label --- .../org/lflang/ui/wizard/LFProjectTemplateProvider.java | 9 ++++++++- org.lflang.ui/src/org/lflang/ui/wizard/Messages.java | 2 -- .../src/org/lflang/ui/wizard/messages.properties | 2 -- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/org.lflang.ui/src/org/lflang/ui/wizard/LFProjectTemplateProvider.java b/org.lflang.ui/src/org/lflang/ui/wizard/LFProjectTemplateProvider.java index c1f03e1d5d..a1924c9206 100644 --- a/org.lflang.ui/src/org/lflang/ui/wizard/LFProjectTemplateProvider.java +++ b/org.lflang.ui/src/org/lflang/ui/wizard/LFProjectTemplateProvider.java @@ -18,7 +18,14 @@ /** * Create a list with all project templates to be shown in the template new * project wizard. Each template is able to generate one or more projects. Each - * project can be configured such that any number of files are included. + * project can be configured such that any number of files are included. + * + * NOTE: + * Xtext is responsible for automatically populating the contents of several + * files in this package based on the parameters given to the @ProjectTemplate + * annotations. However, this capability appears to be broken. + * Upon adding a new template, manually add entries to messages.properties and + * Messages.java in order to the template the register properly in the wizard. */ class LFProjectTemplateProvider implements IProjectTemplateProvider { @Override diff --git a/org.lflang.ui/src/org/lflang/ui/wizard/Messages.java b/org.lflang.ui/src/org/lflang/ui/wizard/Messages.java index 7f27c9da27..8adf8f49a6 100644 --- a/org.lflang.ui/src/org/lflang/ui/wizard/Messages.java +++ b/org.lflang.ui/src/org/lflang/ui/wizard/Messages.java @@ -14,8 +14,6 @@ public class Messages extends NLS { public static String HelloWorldProject_Description; public static String InteractiveProject_Label; public static String InteractiveProject_Description; - public static String WebserverProject_Label; - public static String WebserverProject_Description; public static String WebServerProject_Label; public static String WebServerProject_Description; public static String ReflexGameProject_Label; diff --git a/org.lflang.ui/src/org/lflang/ui/wizard/messages.properties b/org.lflang.ui/src/org/lflang/ui/wizard/messages.properties index 1afe7dad2e..f05d71c7c0 100644 --- a/org.lflang.ui/src/org/lflang/ui/wizard/messages.properties +++ b/org.lflang.ui/src/org/lflang/ui/wizard/messages.properties @@ -4,8 +4,6 @@ HelloWorldProject_Label=Hello World HelloWorldProject_Description=

Hello World

Print "Hello world!" in a target language of choice.

InteractiveProject_Label=Interactive InteractiveProject_Description=

Interactive

Simulate sensor input through key strokes.

-WebserverProject_Label=WebServer -WebserverProject_Description=

Web Server

A simple web server implemented using TypeScript.

WebServerProject_Label=WebServer WebServerProject_Description=

Web Server

A simple web server implemented using TypeScript.

ReflexGameProject_Label=ReflexGame From 5e0c7a65c5e9d31633a1d5d76ac2ef2705270f9d Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 18 May 2022 22:10:48 -0700 Subject: [PATCH 5/6] Fix typo in comment --- .../src/org/lflang/ui/wizard/LFProjectTemplateProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang.ui/src/org/lflang/ui/wizard/LFProjectTemplateProvider.java b/org.lflang.ui/src/org/lflang/ui/wizard/LFProjectTemplateProvider.java index a1924c9206..b8981f58ac 100644 --- a/org.lflang.ui/src/org/lflang/ui/wizard/LFProjectTemplateProvider.java +++ b/org.lflang.ui/src/org/lflang/ui/wizard/LFProjectTemplateProvider.java @@ -25,7 +25,7 @@ * files in this package based on the parameters given to the @ProjectTemplate * annotations. However, this capability appears to be broken. * Upon adding a new template, manually add entries to messages.properties and - * Messages.java in order to the template the register properly in the wizard. + * Messages.java in order to get the template registered properly in the wizard. */ class LFProjectTemplateProvider implements IProjectTemplateProvider { @Override From fe673496421fffedf6c8140594513e1d57423bec Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Wed, 18 May 2022 22:13:23 -0700 Subject: [PATCH 6/6] Updated comment --- .../src/org/lflang/ui/wizard/LFProjectTemplateProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang.ui/src/org/lflang/ui/wizard/LFProjectTemplateProvider.java b/org.lflang.ui/src/org/lflang/ui/wizard/LFProjectTemplateProvider.java index b8981f58ac..f15f111d24 100644 --- a/org.lflang.ui/src/org/lflang/ui/wizard/LFProjectTemplateProvider.java +++ b/org.lflang.ui/src/org/lflang/ui/wizard/LFProjectTemplateProvider.java @@ -23,7 +23,7 @@ * NOTE: * Xtext is responsible for automatically populating the contents of several * files in this package based on the parameters given to the @ProjectTemplate - * annotations. However, this capability appears to be broken. + * annotations. However, this mechanism appears to be broken. * Upon adding a new template, manually add entries to messages.properties and * Messages.java in order to get the template registered properly in the wizard. */