Skip to content

Commit

Permalink
Merge pull request #1 from lotabout/topic-workflow
Browse files Browse the repository at this point in the history
Topic workflow
  • Loading branch information
lotabout authored Oct 17, 2017
2 parents b531926 + ceea369 commit 2f53dd2
Show file tree
Hide file tree
Showing 31 changed files with 1,435 additions and 936 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
out
target
3 changes: 1 addition & 2 deletions CodeGenerator.iml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="innerbuilder" level="project" />
</component>
</module>
</module>
3 changes: 2 additions & 1 deletion resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>me.lotabout.codegenerator</id>
<name>CodeGenerator</name>
<version>1.0</version>
<version>1.1</version>
<vendor email="[email protected]" url="https://lotabout.me">Personal</vendor>

<description><![CDATA[
Expand All @@ -20,6 +20,7 @@

<change-notes><![CDATA[
<ul>
<li>version 1.1 <p>Able to define workflows for selecting members/classes</p></li>
<li>version 1.0 <p>First release</p></li>
</ul>
]]>
Expand Down
1 change: 1 addition & 0 deletions resources/template/default.vm
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
## - PsiShortNamesCache: Class utility to search classes
## - PsiJavaPsiFacade: Class Java specific utility to search classes
## - GlobalSearchScope: Class class to create search scopes, used by above utilities
## - EntryFactory: Class EntryFactory.of(...) to turn PsiXXX to XXXEntry.
##
## References
## ----------
Expand Down
23 changes: 14 additions & 9 deletions src/me/lotabout/codegenerator/CodeGeneratorSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.xmlb.XmlSerializerUtil;
import me.lotabout.codegenerator.config.CodeTemplate;
import me.lotabout.codegenerator.config.MemberSelectionConfig;
import me.lotabout.codegenerator.config.PipelineStep;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -19,13 +21,13 @@
public class CodeGeneratorSettings implements PersistentStateComponent<CodeGeneratorSettings> {

private static final Logger LOGGER = Logger.getInstance(CodeGeneratorSettings.class);
private Map<String, CodeTemplate> codeTemplates;
private List<CodeTemplate> codeTemplates;

public CodeGeneratorSettings() {

}

public CodeGeneratorSettings setCodeTemplates(Map<String, CodeTemplate> codeTemplates) {
public CodeGeneratorSettings setCodeTemplates(List<CodeTemplate> codeTemplates) {
this.codeTemplates = codeTemplates;
return this;
}
Expand All @@ -42,39 +44,42 @@ public CodeGeneratorSettings setCodeTemplates(Map<String, CodeTemplate> codeTemp
XmlSerializerUtil.copyBean(codeGeneratorSettings, this);
}

public Map<String, CodeTemplate> getCodeTemplates() {
public List<CodeTemplate> getCodeTemplates() {
if (codeTemplates == null) {
codeTemplates = loadDefaultTemplates();
}
return codeTemplates;
}

public Optional<CodeTemplate> getCodeTemplate(String templateId) {
return Optional.ofNullable(codeTemplates.get(templateId));
return codeTemplates.stream()
.filter(t -> t!= null && t.getId().equals(templateId))
.findFirst();
}

public void removeCodeTemplate(String templateId) {
codeTemplates.remove(templateId);
codeTemplates.removeIf(template -> template.name.equals(templateId));
}

private Map<String, CodeTemplate> loadDefaultTemplates() {
private List<CodeTemplate> loadDefaultTemplates() {
List<CodeTemplate> templates = new ArrayList<>();
try {
templates.add(createTemplate("HUESerialization", "body"));
templates.add(createTemplate("HUESerialization", "body", Collections.singletonList(new MemberSelectionConfig())));
} catch (Exception e) {
LOGGER.error("loadDefaultTemplates failed", e);
}

return templates.stream().collect(Collectors.toMap(CodeTemplate::getId, Function.identity()));
return templates;
}

@NotNull
private CodeTemplate createTemplate(String name, String type) throws IOException {
private CodeTemplate createTemplate(String name, String type, List<PipelineStep> pipeline) throws IOException {
String velocityTemplate = FileUtil.loadTextAndClose(CodeGeneratorSettings.class.getResourceAsStream("/template/" + name + ".vm"));
CodeTemplate codeTemplate = new CodeTemplate();
codeTemplate.type = type;
codeTemplate.name = name;
codeTemplate.template = velocityTemplate;
codeTemplate.pipeline.addAll(pipeline);
return codeTemplate;
}

Expand Down
Loading

0 comments on commit 2f53dd2

Please sign in to comment.