From fb7433b86c013c10ce76a67566e3498051d5ad4f Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 16 Aug 2016 18:04:55 +0300 Subject: [PATCH] Cleanup (formatting) --- .../ide/fileTemplates/JavaTemplateUtil.java | 52 ++++----- .../fileTemplates/JavaFileTemplatesTest.java | 22 ++-- .../CreateFromTemplateHandler.java | 15 ++- .../ide/fileTemplates/FileTemplate.java | 16 +-- .../ide/fileTemplates/FileTemplateUtil.java | 101 +++++++++--------- .../actions/AttributesDefaults.java | 39 ++++--- .../src/messages/IdeBundle.properties | 2 +- 7 files changed, 122 insertions(+), 125 deletions(-) diff --git a/java/java-impl/src/com/intellij/ide/fileTemplates/JavaTemplateUtil.java b/java/java-impl/src/com/intellij/ide/fileTemplates/JavaTemplateUtil.java index 8f872d0060f8..709819d2e67d 100644 --- a/java/java-impl/src/com/intellij/ide/fileTemplates/JavaTemplateUtil.java +++ b/java/java-impl/src/com/intellij/ide/fileTemplates/JavaTemplateUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,47 +16,41 @@ package com.intellij.ide.fileTemplates; import com.intellij.psi.*; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import java.util.Properties; +import static com.intellij.util.ObjectUtils.notNull; + /** * @author yole */ public class JavaTemplateUtil { - @NonNls public static final String TEMPLATE_CATCH_BODY = "Catch Statement Body.java"; - @NonNls public static final String TEMPLATE_IMPLEMENTED_METHOD_BODY = "Implemented Method Body.java"; - @NonNls public static final String TEMPLATE_OVERRIDDEN_METHOD_BODY = "Overridden Method Body.java"; - @NonNls public static final String TEMPLATE_FROM_USAGE_METHOD_BODY = "New Method Body.java"; - @NonNls public static final String TEMPLATE_I18NIZED_EXPRESSION = "I18nized Expression.java"; - @NonNls public static final String TEMPLATE_I18NIZED_CONCATENATION = "I18nized Concatenation.java"; - @NonNls public static final String TEMPLATE_I18NIZED_JSP_EXPRESSION = "I18nized JSP Expression.jsp"; + public static final String TEMPLATE_CATCH_BODY = "Catch Statement Body.java"; + public static final String TEMPLATE_IMPLEMENTED_METHOD_BODY = "Implemented Method Body.java"; + public static final String TEMPLATE_OVERRIDDEN_METHOD_BODY = "Overridden Method Body.java"; + public static final String TEMPLATE_FROM_USAGE_METHOD_BODY = "New Method Body.java"; + public static final String TEMPLATE_I18NIZED_EXPRESSION = "I18nized Expression.java"; + public static final String TEMPLATE_I18NIZED_CONCATENATION = "I18nized Concatenation.java"; + public static final String TEMPLATE_I18NIZED_JSP_EXPRESSION = "I18nized JSP Expression.jsp"; - @NonNls public static final String INTERNAL_CLASS_TEMPLATE_NAME = "Class"; - @NonNls public static final String INTERNAL_INTERFACE_TEMPLATE_NAME = "Interface"; - @NonNls public static final String INTERNAL_ANNOTATION_TYPE_TEMPLATE_NAME = "AnnotationType"; - @NonNls public static final String INTERNAL_ENUM_TEMPLATE_NAME = "Enum"; + public static final String INTERNAL_CLASS_TEMPLATE_NAME = "Class"; + public static final String INTERNAL_INTERFACE_TEMPLATE_NAME = "Interface"; + public static final String INTERNAL_ANNOTATION_TYPE_TEMPLATE_NAME = "AnnotationType"; + public static final String INTERNAL_ENUM_TEMPLATE_NAME = "Enum"; - public static final String[] INTERNAL_JAVA_TEMPLATES = new String[]{INTERNAL_CLASS_TEMPLATE_NAME, - INTERNAL_INTERFACE_TEMPLATE_NAME, INTERNAL_ANNOTATION_TYPE_TEMPLATE_NAME, INTERNAL_ENUM_TEMPLATE_NAME}; + public static final String[] INTERNAL_JAVA_TEMPLATES = { + INTERNAL_CLASS_TEMPLATE_NAME, INTERNAL_INTERFACE_TEMPLATE_NAME, INTERNAL_ANNOTATION_TYPE_TEMPLATE_NAME, INTERNAL_ENUM_TEMPLATE_NAME}; - private JavaTemplateUtil() { - } + private JavaTemplateUtil() { } - public static void setClassAndMethodNameProperties (Properties properties, PsiClass aClass, PsiMethod method) { - String className = aClass.getQualifiedName(); - if (className == null) className = ""; - properties.setProperty(FileTemplate.ATTRIBUTE_CLASS_NAME, className); - - String classSimpleName = aClass.getName(); - if (classSimpleName == null) classSimpleName = ""; - properties.setProperty(FileTemplate.ATTRIBUTE_SIMPLE_CLASS_NAME, classSimpleName); - - String methodName = method.getName(); - properties.setProperty(FileTemplate.ATTRIBUTE_METHOD_NAME, methodName); + public static void setClassAndMethodNameProperties (@NotNull Properties properties, @NotNull PsiClass aClass, @NotNull PsiMethod method) { + properties.setProperty(FileTemplate.ATTRIBUTE_CLASS_NAME, notNull(aClass.getQualifiedName(), "")); + properties.setProperty(FileTemplate.ATTRIBUTE_SIMPLE_CLASS_NAME, notNull(aClass.getName(), "")); + properties.setProperty(FileTemplate.ATTRIBUTE_METHOD_NAME, method.getName()); } + @NotNull public static String getPackageName(@NotNull PsiDirectory directory) { PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(directory); return aPackage != null ? aPackage.getQualifiedName() : ""; @@ -65,4 +59,4 @@ public class JavaTemplateUtil { public static void setPackageNameAttribute(@NotNull Properties properties, @NotNull PsiDirectory directory) { properties.setProperty(FileTemplate.ATTRIBUTE_PACKAGE_NAME, getPackageName(directory)); } -} +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/ide/fileTemplates/JavaFileTemplatesTest.java b/java/java-tests/testSrc/com/intellij/ide/fileTemplates/JavaFileTemplatesTest.java index 1e01d6f2cea6..81cec72763db 100644 --- a/java/java-tests/testSrc/com/intellij/ide/fileTemplates/JavaFileTemplatesTest.java +++ b/java/java-tests/testSrc/com/intellij/ide/fileTemplates/JavaFileTemplatesTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,26 +20,26 @@ import com.intellij.ide.fileTemplates.actions.CreateFromTemplateAction; import com.intellij.ide.fileTemplates.actions.CreateFromTemplateGroup; import com.intellij.ide.fileTemplates.impl.FileTemplateManagerImpl; import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.util.Condition; import com.intellij.testFramework.TestActionEvent; import com.intellij.testFramework.TestDataProvider; import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; -import com.intellij.util.containers.ContainerUtil; import java.util.Arrays; +import java.util.stream.Stream; public class JavaFileTemplatesTest extends LightCodeInsightFixtureTestCase { - - public void testCreateFromTemplateGroup() throws Exception { - + public void testCreateFromTemplateGroup() { myFixture.configureByText("foo.java", ""); AnAction[] children = new CreateFromTemplateGroup().getChildren(new TestActionEvent(new TestDataProvider(getProject()))); - assertNull(ContainerUtil.find(children, action -> action instanceof CreateFromTemplateAction && ((CreateFromTemplateAction)action).getTemplate().getName().equals("Class"))); - assertNotNull(ContainerUtil.find(children, action -> action instanceof CreateFromTemplateAction && ((CreateFromTemplateAction)action).getTemplate().getName().equals("Singleton"))); + assertTrue(Stream.of(children).noneMatch(action -> isTemplateAction(action, "Class"))); + assertTrue(Stream.of(children).anyMatch(action -> isTemplateAction(action, "Singleton"))); } - @SuppressWarnings("ConstantConditions") - public void testManyTemplates() throws Exception { + private static boolean isTemplateAction(AnAction action, String name) { + return action instanceof CreateFromTemplateAction && name.equals(((CreateFromTemplateAction)action).getTemplate().getName()); + } + + public void testManyTemplates() { FileTemplateManagerImpl templateManager = (FileTemplateManagerImpl)FileTemplateManager.getInstance(getProject()); templateManager.getState().RECENT_TEMPLATES.clear(); FileTemplate[] before = templateManager.getAllTemplates(); @@ -56,4 +56,4 @@ public class JavaFileTemplatesTest extends LightCodeInsightFixtureTestCase { templateManager.getState().RECENT_TEMPLATES.clear(); } } -} +} \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/ide/fileTemplates/CreateFromTemplateHandler.java b/platform/lang-impl/src/com/intellij/ide/fileTemplates/CreateFromTemplateHandler.java index dc728e661ef0..ce0d6083f0c1 100644 --- a/platform/lang-impl/src/com/intellij/ide/fileTemplates/CreateFromTemplateHandler.java +++ b/platform/lang-impl/src/com/intellij/ide/fileTemplates/CreateFromTemplateHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.ide.fileTemplates; import com.intellij.openapi.extensions.ExtensionPointName; @@ -34,12 +33,18 @@ public interface CreateFromTemplateHandler { boolean handlesTemplate(FileTemplate template); @NotNull - PsiElement createFromTemplate(Project project, PsiDirectory directory, final String fileName, FileTemplate template, String templateText, + PsiElement createFromTemplate(Project project, + PsiDirectory directory, + String fileName, + FileTemplate template, + String templateText, @NotNull Map props) throws IncorrectOperationException; - boolean canCreate(final PsiDirectory[] dirs); + boolean canCreate(PsiDirectory[] dirs); + boolean isNameRequired(); + String getErrorMessage(); void prepareProperties(Map props); -} +} \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplate.java b/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplate.java index 644a94394e6b..7e7366cd2211 100644 --- a/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplate.java +++ b/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.ide.fileTemplates; import com.intellij.openapi.fileTypes.FileType; @@ -32,7 +31,9 @@ import java.util.Properties; */ public interface FileTemplate extends Cloneable { FileTemplate[] EMPTY_ARRAY = new FileTemplate[0]; - + + String ourEncoding = CharsetToolkit.UTF8; + String ATTRIBUTE_EXCEPTION = "EXCEPTION"; String ATTRIBUTE_EXCEPTION_TYPE = "EXCEPTION_TYPE"; String ATTRIBUTE_DESCRIPTION = "DESCRIPTION"; @@ -42,7 +43,6 @@ public interface FileTemplate extends Cloneable { String ATTRIBUTE_DEFAULT_RETURN_VALUE = "DEFAULT_RETURN_VALUE"; String ATTRIBUTE_CALL_SUPER = "CALL_SUPER"; - String ourEncoding = CharsetToolkit.UTF8; String ATTRIBUTE_CLASS_NAME = "CLASS_NAME"; String ATTRIBUTE_SIMPLE_CLASS_NAME = "SIMPLE_CLASS_NAME"; String ATTRIBUTE_METHOD_NAME = "METHOD_NAME"; @@ -51,7 +51,8 @@ public interface FileTemplate extends Cloneable { String ATTRIBUTE_FILE_NAME = "FILE_NAME"; /** Name without extension */ - @NotNull String getName(); + @NotNull + String getName(); void setName(@NotNull String name); @@ -87,5 +88,6 @@ public interface FileTemplate extends Cloneable { FileTemplate clone(); - @NotNull String[] getUnsetAttributes(@NotNull Properties properties, Project project) throws ParseException; -} + @NotNull + String[] getUnsetAttributes(@NotNull Properties properties, Project project) throws ParseException; +} \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplateUtil.java b/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplateUtil.java index b32dca727741..b87e09aa900c 100644 --- a/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplateUtil.java +++ b/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplateUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.ide.fileTemplates; import com.intellij.ide.IdeBundle; @@ -32,7 +31,6 @@ import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.project.ex.ProjectManagerEx; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.ClassLoaderUtil; -import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.ThrowableComputable; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiDirectory; @@ -48,7 +46,6 @@ import org.apache.velocity.runtime.parser.ParseException; import org.apache.velocity.runtime.parser.Token; import org.apache.velocity.runtime.parser.node.*; import org.apache.velocity.util.StringUtils; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -62,11 +59,11 @@ import java.util.regex.Pattern; /** * @author MYakovlev */ -public class FileTemplateUtil{ - private static final Logger LOG = Logger.getInstance("#com.intellij.ide.fileTemplates.FileTemplateUtil"); - private static final CreateFromTemplateHandler ourDefaultCreateFromTemplateHandler = new DefaultCreateFromTemplateHandler(); +public class FileTemplateUtil { + public static final String INTERNAL_PACKAGE_INFO_TEMPLATE_NAME = "package-info"; - @NonNls public static final String INTERNAL_PACKAGE_INFO_TEMPLATE_NAME = "package-info"; + private static final Logger LOG = Logger.getInstance("#com.intellij.ide.fileTemplates.FileTemplateUtil"); + private static final CreateFromTemplateHandler DEFAULT_HANDLER = new DefaultCreateFromTemplateHandler(); public static String[] calculateAttributes(String templateContent, Properties properties, boolean includeDummies, Project project) throws ParseException { Set propertiesNames = new HashSet<>(); @@ -83,7 +80,6 @@ public class FileTemplateUtil{ private static String[] calculateAttributes(String templateContent, Set propertiesNames, boolean includeDummies, Project project) throws ParseException { final Set unsetAttributes = new LinkedHashSet<>(); final Set definedAttributes = new HashSet<>(); - //noinspection HardCodedStringLiteral SimpleNode template = VelocityWrapper.parse(new StringReader(templateContent), "MyTemplate"); collectAttributes(unsetAttributes, definedAttributes, template, propertiesNames, includeDummies, new HashSet<>(), project); for (String definedAttribute : definedAttributes) { @@ -98,13 +94,12 @@ public class FileTemplateUtil{ final Set propertiesNames, final boolean includeDummies, Set visitedIncludes, - Project project) - throws ParseException { + Project project) throws ParseException { int childCount = apacheNode.jjtGetNumChildren(); - for(int i = 0; i < childCount; i++){ + for (int i = 0; i < childCount; i++) { Node apacheChild = apacheNode.jjtGetChild(i); collectAttributes(referenced, defined, apacheChild, propertiesNames, includeDummies, visitedIncludes, project); - if (apacheChild instanceof ASTReference){ + if (apacheChild instanceof ASTReference) { ASTReference apacheReference = (ASTReference)apacheChild; String s = apacheReference.literal(); s = referenceToAttribute(s, includeDummies); @@ -113,7 +108,7 @@ public class FileTemplateUtil{ } } else if (apacheChild instanceof ASTSetDirective) { - ASTReference lhs = (ASTReference) apacheChild.jjtGetChild(0); + ASTReference lhs = (ASTReference)apacheChild.jjtGetChild(0); String attr = referenceToAttribute(lhs.literal(), false); if (attr != null) { defined.add(attr); @@ -189,7 +184,7 @@ public class FileTemplateUtil{ return attrib; } - public static String mergeTemplate(Map attributes, String content, boolean useSystemLineSeparators) throws IOException{ + public static String mergeTemplate(Map attributes, String content, boolean useSystemLineSeparators) throws IOException { VelocityContext context = createVelocityContext(); for (final Object o : attributes.keySet()) { String name = (String)o; @@ -212,7 +207,7 @@ public class FileTemplateUtil{ @Nullable Consumer exceptionHandler) throws IOException { VelocityContext context = createVelocityContext(); Enumeration names = attributes.propertyNames(); - while (names.hasMoreElements()){ + while (names.hasMoreElements()) { String name = (String)names.nextElement(); context.put(name, attributes.getProperty(name)); } @@ -258,7 +253,7 @@ public class FileTemplateUtil{ } public static PsiElement createFromTemplate(@NotNull final FileTemplate template, - @NonNls @Nullable final String fileName, + @Nullable final String fileName, @Nullable Properties props, @NotNull final PsiDirectory directory) throws Exception { Map map; @@ -273,7 +268,7 @@ public class FileTemplateUtil{ } public static PsiElement createFromTemplate(@NotNull final FileTemplate template, - @NonNls @Nullable String fileName, + @Nullable String fileName, @Nullable Properties props, @NotNull final PsiDirectory directory, @Nullable ClassLoader classLoader) throws Exception { @@ -289,17 +284,19 @@ public class FileTemplateUtil{ } public static PsiElement createFromTemplate(@NotNull final FileTemplate template, - @NonNls @Nullable String fileName, + @Nullable String fileName, @Nullable Map propsMap, @NotNull final PsiDirectory directory, @Nullable ClassLoader classLoader) throws Exception { - @NotNull final Project project = directory.getProject(); + Project project = directory.getProject(); + FileTemplateManager.getInstance(project).addRecentName(template.getName()); + if (propsMap == null) { Properties p = FileTemplateManager.getInstance(project).getDefaultProperties(); propsMap = new HashMap<>(); putAll(propsMap, p); } - FileTemplateManager.getInstance(project).addRecentName(template.getName()); + Properties p = new Properties(); fillDefaultProperties(p, directory); putAll(propsMap, p); @@ -323,57 +320,59 @@ public class FileTemplateUtil{ handler.prepareProperties(propsMap); - final Map props_ = propsMap; - final String fileName_ = fileName; - String mergedText = ClassLoaderUtil.runWithClassLoader(classLoader != null ? classLoader : FileTemplateUtil.class.getClassLoader(), - new ThrowableComputable() { - @Override - public String compute() throws IOException { - return template.getText(props_); - } - }); - final String templateText = StringUtil.convertLineSeparators(mergedText); - final Exception[] commandException = new Exception[1]; - final PsiElement[] result = new PsiElement[1]; - CommandProcessor.getInstance().executeCommand(project, () -> ApplicationManager.getApplication().runWriteAction(() -> { - try{ - result[0] = handler.createFromTemplate(project, directory, fileName_, template, templateText, props_); - } - catch (Exception ex){ - commandException[0] = ex; - } - }), template.isTemplateOfType(StdFileTypes.JAVA) && !"package-info".equals(template.getName()) - ? IdeBundle.message("command.create.class.from.template") - : IdeBundle.message("command.create.file.from.template"), null); - if(commandException[0] != null){ + Map props_ = propsMap; + String fileName_ = fileName; + String mergedText = ClassLoaderUtil.runWithClassLoader( + classLoader != null ? classLoader : FileTemplateUtil.class.getClassLoader(), + (ThrowableComputable)() -> template.getText(props_)); + String templateText = StringUtil.convertLineSeparators(mergedText); + + Exception[] commandException = new Exception[1]; + PsiElement[] result = new PsiElement[1]; + CommandProcessor.getInstance().executeCommand( + project, + () -> ApplicationManager.getApplication().runWriteAction( + () -> { + try { + result[0] = handler.createFromTemplate(project, directory, fileName_, template, templateText, props_); + } + catch (Exception ex) { + commandException[0] = ex; + } + }), + IdeBundle.message(template.isTemplateOfType(StdFileTypes.JAVA) && !"package-info".equals(template.getName()) ? + "command.create.class.from.template" : "command.create.file.from.template"), + null); + + if (commandException[0] != null) { throw commandException[0]; } return result[0]; } public static CreateFromTemplateHandler findHandler(final FileTemplate template) { - for(CreateFromTemplateHandler handler: Extensions.getExtensions(CreateFromTemplateHandler.EP_NAME)) { + for (CreateFromTemplateHandler handler : Extensions.getExtensions(CreateFromTemplateHandler.EP_NAME)) { if (handler.handlesTemplate(template)) { return handler; } } - return ourDefaultCreateFromTemplateHandler; + return DEFAULT_HANDLER; } public static void fillDefaultProperties(final Properties props, final PsiDirectory directory) { final DefaultTemplatePropertiesProvider[] providers = Extensions.getExtensions(DefaultTemplatePropertiesProvider.EP_NAME); - for(DefaultTemplatePropertiesProvider provider: providers) { + for (DefaultTemplatePropertiesProvider provider : providers) { provider.fillProperties(directory, props); } } public static String indent(String methodText, Project project, FileType fileType) { int indent = CodeStyleSettingsManager.getSettings(project).getIndentSize(fileType); - return methodText.replaceAll("\n", "\n" + StringUtil.repeatSymbol(' ',indent)); + return methodText.replaceAll("\n", "\n" + StringUtil.repeatSymbol(' ', indent)); } - public static boolean canCreateFromTemplate (PsiDirectory[] dirs, FileTemplate template) { + public static boolean canCreateFromTemplate(PsiDirectory[] dirs, FileTemplate template) { FileType fileType = FileTypeManagerEx.getInstanceEx().getFileTypeByExtension(template.getExtension()); if (fileType.equals(FileTypes.UNKNOWN)) return false; CreateFromTemplateHandler handler = findHandler(template); @@ -386,7 +385,7 @@ public class FileTemplateUtil{ } public static void putAll(final Map props, final Properties p) { - for (Enumeration e = p.propertyNames(); e.hasMoreElements();) { + for (Enumeration e = p.propertyNames(); e.hasMoreElements(); ) { String s = (String)e.nextElement(); props.put(s, p.getProperty(s)); } @@ -468,4 +467,4 @@ public class FileTemplateUtil{ regex = StringUtil.replace(regex, "}", "\\}"); return regex; } -} +} \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/ide/fileTemplates/actions/AttributesDefaults.java b/platform/lang-impl/src/com/intellij/ide/fileTemplates/actions/AttributesDefaults.java index 89e3efebac77..18cf27b0738a 100644 --- a/platform/lang-impl/src/com/intellij/ide/fileTemplates/actions/AttributesDefaults.java +++ b/platform/lang-impl/src/com/intellij/ide/fileTemplates/actions/AttributesDefaults.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,22 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.ide.fileTemplates.actions; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.TextRange; import com.intellij.util.containers.HashMap; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Map; import java.util.Properties; +import static com.intellij.openapi.util.Pair.pair; + /** * @author Roman Chernyatchik -*/ + */ public class AttributesDefaults { private final String myDefaultName; private final TextRange myDefaultRange; @@ -36,38 +36,35 @@ public class AttributesDefaults { private Properties myDefaultProperties = null; private boolean myFixedName; - public AttributesDefaults(@NonNls @Nullable final String defaultName, - @Nullable final TextRange defaultRange) { - myDefaultName = defaultName; - myDefaultRange = defaultRange; + public AttributesDefaults() { + this(null, null); } - public AttributesDefaults(@NonNls @Nullable final String defaultName) { + public AttributesDefaults(@Nullable String defaultName) { this(defaultName, null); } - public AttributesDefaults() { - this(null, null); + public AttributesDefaults(@Nullable String defaultName, @Nullable TextRange defaultRange) { + myDefaultName = defaultName; + myDefaultRange = defaultRange; } @Nullable public String getDefaultFileName() { return myDefaultName; } + @Nullable public TextRange getDefaultFileNameSelection() { return myDefaultRange; } - public void add(@NonNls @NotNull final String attributeKey, - @NonNls @NotNull final String value, - @Nullable final TextRange selectionRange) { - myNamesToValueAndRangeMap.put(attributeKey, Pair.create(value, selectionRange)); + public void add(@NotNull String attributeKey, @NotNull String value) { + add(attributeKey, value, null); } - public void add(@NonNls @NotNull final String attributeKey, - @NonNls @NotNull final String value) { - add(attributeKey, value, null); + public void add(@NotNull String attributeKey, @NotNull String value, @Nullable TextRange selectionRange) { + myNamesToValueAndRangeMap.put(attributeKey, pair(value, selectionRange)); } public void addPredefined(@NotNull String key, @NotNull String value) { @@ -82,13 +79,13 @@ public class AttributesDefaults { } @Nullable - public TextRange getRangeFor(@NonNls @NotNull final String attributeKey) { + public TextRange getRangeFor(@NotNull String attributeKey) { final Pair valueAndRange = myNamesToValueAndRangeMap.get(attributeKey); return valueAndRange == null ? null : valueAndRange.second; } @Nullable - public String getDefaultValueFor(@NonNls @NotNull final String attributeKey) { + public String getDefaultValueFor(@NotNull String attributeKey) { final Pair valueAndRange = myNamesToValueAndRangeMap.get(attributeKey); return valueAndRange == null ? null : valueAndRange.first; } @@ -101,4 +98,4 @@ public class AttributesDefaults { myFixedName = fixedName; return this; } -} +} \ No newline at end of file diff --git a/platform/platform-resources-en/src/messages/IdeBundle.properties b/platform/platform-resources-en/src/messages/IdeBundle.properties index 8bf89711e8fa..c26690fb8057 100644 --- a/platform/platform-resources-en/src/messages/IdeBundle.properties +++ b/platform/platform-resources-en/src/messages/IdeBundle.properties @@ -352,11 +352,11 @@ title.cannot.create.annotation.type=Cannot Create @interface action.create.new.class=Create New Class action.create.new.class.description=Create new Java class action.create.new.package-info.title=package-info.java +action.create.new.package-info.description=Create new package-info.java error.package.already.contains.package-info=''package-info.java'' already exists for package ''{0}'' error.package.already.contains.package.html=Package ''{0}'' already has a ''package.html'' file. Create ''package-info.java'' anyway? error.package.html.found.title=Found 'package.html' button.create=&Create -action.create.new.package-info.description=Create new package-info.java prompt.enter.new.class.name=Enter a new class name: title.new.class=New Class progress.creating.class=Creating class {0}