use of com.intellij.ide.fileTemplates.FileTemplateDescriptor in project intellij-plugins by JetBrains.
the class StrutsFileTemplateGroupDescriptorFactory method getFileTemplatesDescriptor.
public FileTemplateGroupDescriptor getFileTemplatesDescriptor() {
final FileTemplateGroupDescriptor group = new FileTemplateGroupDescriptor(StrutsBundle.message("struts2"), Struts2Icons.Action);
group.addTemplate(new FileTemplateDescriptor(STRUTS_2_0_XML, StrutsIcons.STRUTS_CONFIG_FILE));
group.addTemplate(new FileTemplateDescriptor(STRUTS_2_1_XML, StrutsIcons.STRUTS_CONFIG_FILE));
group.addTemplate(new FileTemplateDescriptor(STRUTS_2_1_7_XML, StrutsIcons.STRUTS_CONFIG_FILE));
group.addTemplate(new FileTemplateDescriptor(STRUTS_2_3_XML, StrutsIcons.STRUTS_CONFIG_FILE));
group.addTemplate(new FileTemplateDescriptor(STRUTS_2_5_XML, StrutsIcons.STRUTS_CONFIG_FILE));
group.addTemplate(new FileTemplateDescriptor(VALIDATION_XML, StrutsIcons.VALIDATION_CONFIG_FILE));
return group;
}
use of com.intellij.ide.fileTemplates.FileTemplateDescriptor in project intellij-community by JetBrains.
the class TestIntegrationUtils method createTestMethodTemplate.
public static Template createTestMethodTemplate(@NotNull MethodKind methodKind, TestFramework descriptor, @NotNull PsiClass targetClass, @Nullable PsiClass sourceClass, @Nullable String name, boolean automatic, Set<String> existingNames) {
FileTemplateDescriptor templateDesc = methodKind.getFileTemplateDescriptor(descriptor);
String templateName = templateDesc.getFileName();
FileTemplate fileTemplate = FileTemplateManager.getInstance(targetClass.getProject()).getCodeTemplate(templateName);
Template template = TemplateManager.getInstance(targetClass.getProject()).createTemplate("", "");
String templateText;
try {
Properties properties = new Properties();
if (sourceClass != null && sourceClass.isValid()) {
properties.setProperty(FileTemplate.ATTRIBUTE_CLASS_NAME, sourceClass.getQualifiedName());
}
templateText = fileTemplate.getText(properties);
} catch (IOException e) {
LOG.warn(e);
templateText = fileTemplate.getText();
}
if (name == null)
name = methodKind.getDefaultName();
if (existingNames != null && !existingNames.add(name)) {
int idx = 1;
while (existingNames.contains(name)) {
final String newName = name + (idx++);
if (existingNames.add(newName)) {
name = newName;
break;
}
}
}
templateText = StringUtil.replace(templateText, "${BODY}\n", "");
int from = 0;
while (true) {
int index = templateText.indexOf("${NAME}", from);
if (index == -1)
break;
template.addTextSegment(templateText.substring(from, index));
if (index > 0 && !Character.isWhitespace(templateText.charAt(index - 1))) {
name = StringUtil.capitalize(name);
} else {
name = StringUtil.decapitalize(name);
}
if (from == 0) {
Expression nameExpr = new ConstantNode(name);
template.addVariable("name", nameExpr, nameExpr, !automatic);
} else {
template.addVariableSegment("name");
}
from = index + "${NAME}".length();
}
template.addTextSegment(templateText.substring(from, templateText.length()));
template.setToIndent(true);
template.setToReformat(true);
template.setToShortenLongNames(true);
return template;
}
use of com.intellij.ide.fileTemplates.FileTemplateDescriptor in project intellij-community by JetBrains.
the class TestNGDataProviderInspection method createMethodFix.
private static CreateMethodQuickFix createMethodFix(PsiAnnotationMemberValue provider, @NotNull PsiClass providerClass, PsiClass topLevelClass) {
final String name = StringUtil.unquoteString(provider.getText());
FileTemplateDescriptor templateDesc = new TestNGFramework().getParametersMethodFileTemplateDescriptor();
assert templateDesc != null;
final FileTemplate fileTemplate = FileTemplateManager.getInstance(provider.getProject()).getCodeTemplate(templateDesc.getFileName());
String body = "";
try {
final Properties attributes = new Properties();
attributes.put(FileTemplate.ATTRIBUTE_NAME, name);
body = fileTemplate.getText(attributes);
body = body.replace("${BODY}\n", "");
final PsiMethod methodFromTemplate = JavaPsiFacade.getElementFactory(providerClass.getProject()).createMethodFromText(body, providerClass);
final PsiCodeBlock methodBody = methodFromTemplate.getBody();
if (methodBody != null) {
body = StringUtil.trimEnd(StringUtil.trimStart(methodBody.getText(), "{"), "}");
} else {
body = "";
}
} catch (Exception ignored) {
}
if (StringUtil.isEmptyOrSpaces(body)) {
body = "return new Object[][]{};";
}
String signature = "@" + DataProvider.class.getName() + " public ";
if (providerClass == topLevelClass) {
signature += "static ";
}
signature += "Object[][] " + name + "()";
return CreateMethodQuickFix.createFix(providerClass, signature, body);
}
use of com.intellij.ide.fileTemplates.FileTemplateDescriptor in project intellij-community by JetBrains.
the class AppEngineTemplateGroupDescriptorFactory method getFileTemplatesDescriptor.
public FileTemplateGroupDescriptor getFileTemplatesDescriptor() {
final FileTemplateDescriptor appEngineXml = new FileTemplateDescriptor(APP_ENGINE_WEB_XML_TEMPLATE, StdFileTypes.XML.getIcon());
final FileTemplateDescriptor appEngineApplicationXml = new FileTemplateDescriptor(APP_ENGINE_APPLICATION_XML_TEMPLATE, StdFileTypes.XML.getIcon());
final FileTemplateDescriptor jdoConfigXml = new FileTemplateDescriptor(APP_ENGINE_JDO_CONFIG_TEMPLATE, StdFileTypes.XML.getIcon());
final FileTemplateDescriptor jpaConfigXml = new FileTemplateDescriptor(APP_ENGINE_JPA_CONFIG_TEMPLATE, StdFileTypes.XML.getIcon());
return new FileTemplateGroupDescriptor("Google App Engine", GoogleAppEngineIcons.AppEngine, appEngineXml, appEngineApplicationXml, jdoConfigXml, jpaConfigXml);
}
use of com.intellij.ide.fileTemplates.FileTemplateDescriptor in project Intellij-Plugin by getgauge.
the class SpecificationLiveTemplate method getFileTemplatesDescriptor.
@Override
public FileTemplateGroupDescriptor getFileTemplatesDescriptor() {
FileTemplateGroupDescriptor descriptor = new FileTemplateGroupDescriptor("Specification", GaugeIcon.GAUGE_SPEC_FILE_ICON);
descriptor.addTemplate(new FileTemplateDescriptor("Specification.spec", SpecFileType.INSTANCE.getIcon()));
descriptor.addTemplate(new FileTemplateDescriptor("Concept.cpt", ConceptFileType.INSTANCE.getIcon()));
return descriptor;
}
Aggregations