本文整理汇总了Java中com.intellij.ide.fileTemplates.FileTemplateDescriptor.getFileName方法的典型用法代码示例。如果您正苦于以下问题:Java FileTemplateDescriptor.getFileName方法的具体用法?Java FileTemplateDescriptor.getFileName怎么用?Java FileTemplateDescriptor.getFileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.ide.fileTemplates.FileTemplateDescriptor
的用法示例。
在下文中一共展示了FileTemplateDescriptor.getFileName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTestClassFromCodeTemplate
import com.intellij.ide.fileTemplates.FileTemplateDescriptor; //导入方法依赖的package包/类
private static PsiClass createTestClassFromCodeTemplate(final CreateTestDialog d,
final FileTemplateDescriptor fileTemplateDescriptor,
final PsiDirectory targetDirectory) {
final String templateName = fileTemplateDescriptor.getFileName();
final FileTemplate fileTemplate = FileTemplateManager.getInstance(targetDirectory.getProject()).getCodeTemplate(templateName);
final Properties defaultProperties = FileTemplateManager.getInstance(targetDirectory.getProject()).getDefaultProperties();
Properties properties = new Properties(defaultProperties);
properties.setProperty(FileTemplate.ATTRIBUTE_NAME, d.getClassName());
final PsiClass targetClass = d.getTargetClass();
if (targetClass != null && targetClass.isValid()) {
properties.setProperty(FileTemplate.ATTRIBUTE_CLASS_NAME, targetClass.getQualifiedName());
}
try {
final PsiElement psiElement = FileTemplateUtil.createFromTemplate(fileTemplate, templateName, properties, targetDirectory);
if (psiElement instanceof PsiClass) {
return (PsiClass)psiElement;
}
return null;
}
catch (Exception e) {
return null;
}
}
示例2: FileTemplateNode
import com.intellij.ide.fileTemplates.FileTemplateDescriptor; //导入方法依赖的package包/类
FileTemplateNode(FileTemplateDescriptor descriptor) {
this(descriptor.getDisplayName(),
descriptor.getIcon(),
descriptor instanceof FileTemplateGroupDescriptor ? ContainerUtil.map2List(((FileTemplateGroupDescriptor)descriptor).getTemplates(), new Function<FileTemplateDescriptor, FileTemplateNode>() {
@Override
public FileTemplateNode fun(FileTemplateDescriptor s) {
return new FileTemplateNode(s);
}
}) : Collections.<FileTemplateNode>emptyList(),
descriptor instanceof FileTemplateGroupDescriptor ? null : descriptor.getFileName());
}
示例3: createTestMethodTemplate
import com.intellij.ide.fileTemplates.FileTemplateDescriptor; //导入方法依赖的package包/类
public static Template createTestMethodTemplate(MethodKind methodKind,
TestFramework descriptor,
PsiClass targetClass,
@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 {
templateText = fileTemplate.getText(new 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}", "");
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;
}
示例4: createTestMethodTemplate
import com.intellij.ide.fileTemplates.FileTemplateDescriptor; //导入方法依赖的package包/类
private static Template createTestMethodTemplate(MethodKind methodKind,
TestFramework descriptor,
PsiClass targetClass,
@Nullable String name,
boolean automatic) {
FileTemplateDescriptor templateDesc = methodKind.getFileTemplateDescriptor(descriptor);
String templateName = templateDesc.getFileName();
FileTemplate fileTemplate = FileTemplateManager.getInstance().getCodeTemplate(templateName);
Template template = TemplateManager.getInstance(targetClass.getProject()).createTemplate("", "");
String templateText;
try {
templateText = fileTemplate.getText(new Properties());
}
catch (IOException e) {
LOG.warn(e);
templateText = fileTemplate.getText();
}
if (name == null) name = methodKind.getDefaultName();
templateText = StringUtil.replace(templateText, "${BODY}", "");
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;
}
示例5: createTestMethodTemplate
import com.intellij.ide.fileTemplates.FileTemplateDescriptor; //导入方法依赖的package包/类
private static Template createTestMethodTemplate(MethodKind methodKind,
TestFramework descriptor,
PsiClass targetClass,
@Nullable String name,
boolean automatic) {
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 {
templateText = fileTemplate.getText(new Properties());
}
catch (IOException e) {
LOG.warn(e);
templateText = fileTemplate.getText();
}
if (name == null) name = methodKind.getDefaultName();
templateText = StringUtil.replace(templateText, "${BODY}", "");
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;
}