Skip to content

Commit

Permalink
Align to new api and drop some old versions of Jetrains Platform
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Kravets committed Feb 13, 2021
1 parent a38e121 commit c0e057c
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 264 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
out
generated
27 changes: 8 additions & 19 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,17 @@
</html>]]>
</change-notes>

<!-- please see http://confluence.jetbrains.com/display/IDEADEV/Build+Number+Ranges for description -->
<idea-version since-build="131"/>
<idea-version since-build="193.5233.102"/>

<!-- please see http://confluence.jetbrains.com/display/IDEADEV/Plugin+Compatibility+with+IntelliJ+Platform+Products
on how to target different products -->
<!-- uncomment to enable plugin in all products -->
<depends>com.intellij.modules.lang</depends>
<depends>com.intellij.modules.platform</depends>

<extensions defaultExtensionNs="com.intellij">
<defaultTemplatePropertiesProvider implementation="org.vkravets.idea.project.filetemplate.PerProjectTemplatePropertiesProvider"/>
<projectConfigurable instance="org.vkravets.idea.project.filetemplate.configuration.PerProjectTemplateVariableConfigurable"/>
<defaultTemplatePropertiesProvider
implementation="org.vkravets.idea.project.filetemplate.ProjectTemplatePropertiesProvider"/>
<projectConfigurable
instance="org.vkravets.idea.project.filetemplate.configuration.ProjectTemplateVariableConfigurable"/>
<projectService
serviceImplementation="org.vkravets.idea.project.filetemplate.ProjectTemplateVariableManager"/>
</extensions>

<application-components/>

<project-components>
<component>
<implementation-class>org.vkravets.idea.project.filetemplate.PerProjectTemplateManager</implementation-class>
<loadForDefaultProject/>
</component>
</project-components>

<actions/>

</idea-plugin>

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.vkravets.idea.project.filetemplate;

import com.intellij.ide.fileTemplates.DefaultTemplatePropertiesProvider;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDirectory;

import java.util.Map;
import java.util.Properties;

import static java.util.stream.Collectors.toMap;

/**
* Created by IntelliJ IDEA.
* Author: Vladimir Kravets
* E-Mail: vova.kravets@gmail.com
* Date: 2/14/14
* Time: 5:52 PM
*/
public class ProjectTemplatePropertiesProvider implements DefaultTemplatePropertiesProvider {
@Override
public void fillProperties(PsiDirectory psiDirectory, Properties properties) {
final Project project = psiDirectory.getProject();
final ProjectTemplateVariableManager manager = project.getService(ProjectTemplateVariableManager.class);

final VariablesConfigurationState projectVariables = manager.getProjectVariables();
final Map<String, String> variablesMap = projectVariables.templateVariables.stream()
.collect(toMap(TemplateVariable::getName,
TemplateVariable::getValue));
properties.putAll(variablesMap);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package org.vkravets.idea.project.filetemplate;

import com.intellij.ide.fileTemplates.FileTemplate;
import com.intellij.ide.fileTemplates.FileTemplateManager;
import com.intellij.ide.fileTemplates.FileTemplateUtil;
import com.intellij.openapi.components.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import org.apache.velocity.runtime.parser.ParseException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;


/**
* Created by IntelliJ IDEA.
* Author: Vladimir Kravets
* E-Mail: vova.kravets@gmail.com
*/
@State(name = "ProjectTemplateVariables",
storages = {
@Storage(value = "template/template_variable_settings.xml")
}
)
public class ProjectTemplateVariableManager implements PersistentStateComponent<VariablesConfigurationState> {

public VariablesConfigurationState state = new VariablesConfigurationState();

private static final Logger logger = Logger.getInstance("#org.vkravets.idea.project.filetemplate.ProjectTemplateVariableManager");

protected ProjectTemplateVariableManager() {
}

@Nullable
@Override
public VariablesConfigurationState getState() {
return this.state;
}

@Override
public void loadState(@NotNull VariablesConfigurationState element) {
this.state = element;
}

public VariablesConfigurationState getProjectVariables() {
return this.state;
}

public Set<String> getAllFileTemplatesVariables(Project project) {
Set<String> result = new TreeSet<>();
List<FileTemplate> allTemplates = new ArrayList<>();
FileTemplateManager fileTemplateManager = FileTemplateManager.getDefaultInstance();
FileTemplate[] templates = fileTemplateManager.getAllTemplates();
FileTemplate[] patterns = fileTemplateManager.getAllPatterns();
FileTemplate[] codeTemplates = fileTemplateManager.getAllCodeTemplates();
FileTemplate[] j2eeTemplates = fileTemplateManager.getAllJ2eeTemplates();
allTemplates.addAll(Arrays.asList(templates));
allTemplates.addAll(Arrays.asList(codeTemplates));
allTemplates.addAll(Arrays.asList(j2eeTemplates));
allTemplates.addAll(Arrays.asList(patterns));

for (FileTemplate template : allTemplates) {
try {
String[] variables = FileTemplateUtil.calculateAttributes(template.getText(),
new Properties(),
true,
project);
result.addAll(Arrays.asList(variables));
}
catch (ParseException e) {
logger.warn("Parsing exception", e);
}
}
return result;
}
}
33 changes: 33 additions & 0 deletions src/org/vkravets/idea/project/filetemplate/TemplateVariable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.vkravets.idea.project.filetemplate;

import com.intellij.util.xmlb.annotations.Attribute;
import com.intellij.util.xmlb.annotations.Tag;
import com.intellij.util.xmlb.annotations.Text;

/**
* Created by IntelliJ IDEA. Author: vkravets E-Mail: Date: 13.02.2021 Time: 19:48
*/
@Tag("variable")
public class TemplateVariable {

@Attribute("name")
public String name;

@Text
public String value;

public String getName() {
return name;
}

public String getValue() {
return value;
}

public static TemplateVariable build(String name, String value) {
TemplateVariable templateVariable = new TemplateVariable();
templateVariable.name = name;
templateVariable.value = value;
return templateVariable;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.vkravets.idea.project.filetemplate;

import com.intellij.util.xmlb.annotations.Tag;
import com.intellij.util.xmlb.annotations.XCollection;

import java.util.ArrayList;
import java.util.List;

/**
* Created by IntelliJ IDEA. Author: vkravets E-Mail: Date: 13.02.2021 Time: 19:48
*/
public class VariablesConfigurationState {

@Tag("templateVariables")
@XCollection(propertyElementName = "templateVariables",
elementName = "variable",
valueAttributeName = "",
elementTypes = TemplateVariable.class,
style = XCollection.Style.v2)
public List<TemplateVariable> templateVariables = new ArrayList<>();

public VariablesConfigurationState() {

}
}
Loading

0 comments on commit c0e057c

Please sign in to comment.