-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Align to new api and drop some old versions of Jetrains Platform
- Loading branch information
Vladimir Kravets
committed
Feb 13, 2021
1 parent
a38e121
commit c0e057c
Showing
12 changed files
with
221 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
out | ||
generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 0 additions & 158 deletions
158
src/org/vkravets/idea/project/filetemplate/PerProjectTemplateManager.java
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
src/org/vkravets/idea/project/filetemplate/PerProjectTemplatePropertiesProvider.java
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
src/org/vkravets/idea/project/filetemplate/ProjectTemplatePropertiesProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/org/vkravets/idea/project/filetemplate/ProjectTemplateVariableManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
33
src/org/vkravets/idea/project/filetemplate/TemplateVariable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/org/vkravets/idea/project/filetemplate/VariablesConfigurationState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
|
||
} | ||
} |
Oops, something went wrong.