IDEADEV-40480
[fedora-idea.git] / java / java-impl / src / com / intellij / ide / fileTemplates / JavaTemplateUtil.java
blob79f1ea49c86533cb76eb5ed37246fe07d6027e96
1 package com.intellij.ide.fileTemplates;
3 import com.intellij.psi.*;
4 import org.jetbrains.annotations.NonNls;
5 import org.jetbrains.annotations.NotNull;
7 import java.util.Properties;
9 /**
10 * @author yole
12 public class JavaTemplateUtil {
13 @NonNls public static final String TEMPLATE_CATCH_BODY = "Catch Statement Body.java";
14 @NonNls public static final String TEMPLATE_IMPLEMENTED_METHOD_BODY = "Implemented Method Body.java";
15 @NonNls public static final String TEMPLATE_OVERRIDDEN_METHOD_BODY = "Overridden Method Body.java";
16 @NonNls public static final String TEMPLATE_FROM_USAGE_METHOD_BODY = "New Method Body.java";
17 @NonNls public static final String TEMPLATE_I18NIZED_EXPRESSION = "I18nized Expression.java";
18 @NonNls public static final String TEMPLATE_I18NIZED_CONCATENATION = "I18nized Concatenation.java";
19 @NonNls public static final String TEMPLATE_I18NIZED_JSP_EXPRESSION = "I18nized JSP Expression.jsp";
20 @NonNls public static final String INTERNAL_CLASS_TEMPLATE_NAME = "Class";
21 @NonNls public static final String INTERNAL_INTERFACE_TEMPLATE_NAME = "Interface";
22 @NonNls public static final String INTERNAL_ANNOTATION_TYPE_TEMPLATE_NAME = "AnnotationType";
23 @NonNls public static final String INTERNAL_ENUM_TEMPLATE_NAME = "Enum";
25 private JavaTemplateUtil() {
28 public static void setClassAndMethodNameProperties (Properties properties, PsiClass aClass, PsiMethod method) {
29 String className = aClass.getQualifiedName();
30 if (className == null) className = "";
31 properties.setProperty(FileTemplate.ATTRIBUTE_CLASS_NAME, className);
33 String classSimpleName = aClass.getName();
34 if (classSimpleName == null) classSimpleName = "";
35 properties.setProperty(FileTemplate.ATTRIBUTE_SIMPLE_CLASS_NAME, classSimpleName);
37 String methodName = method.getName();
38 properties.setProperty(FileTemplate.ATTRIBUTE_METHOD_NAME, methodName);
41 public static void setPackageNameAttribute (@NotNull Properties properties, @NotNull PsiDirectory directory) {
42 PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(directory);
43 if (aPackage != null) {
44 String packageName = aPackage.getQualifiedName();
45 if (packageName.length() > 0) {
46 properties.setProperty(FileTemplate.ATTRIBUTE_PACKAGE_NAME, packageName);
47 return;
50 properties.setProperty(FileTemplate.ATTRIBUTE_PACKAGE_NAME, "");