diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixDescriptionPanel.form b/java/java-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixDescriptionPanel.form new file mode 100644 index 000000000000..cd60a7de70f4 --- /dev/null +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixDescriptionPanel.form @@ -0,0 +1,82 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixDescriptionPanel.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixDescriptionPanel.java new file mode 100644 index 000000000000..a97216fb13a5 --- /dev/null +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixDescriptionPanel.java @@ -0,0 +1,114 @@ +/* + * Copyright 2000-2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.template.postfix.settings; + +import com.intellij.codeInsight.intention.impl.config.ActionUsagePanel; +import com.intellij.codeInsight.intention.impl.config.TextDescriptor; +import com.intellij.openapi.Disposable; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.fileTypes.ex.FileTypeManagerEx; +import com.intellij.openapi.util.Disposer; +import com.intellij.ui.TitledSeparator; +import com.intellij.util.ArrayUtil; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.awt.*; +import java.io.IOException; + +class PostfixDescriptionPanel implements Disposable { + private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.intention.impl.config.IntentionDescriptionPanel"); + private JPanel myPanel; + + private JPanel myAfterPanel; + private JPanel myBeforePanel; + private JEditorPane myDescriptionBrowser; + + + public void reset(PostfixTemplateMetaData actionMetaData) { + try { + final TextDescriptor url = actionMetaData.getDescription(); + final String description = url == null ? "" : url.getText(); + myDescriptionBrowser.setText(description); + + showUsages(myBeforePanel, ArrayUtil.getFirstElement(actionMetaData.getExampleUsagesBefore())); + showUsages(myAfterPanel, ArrayUtil.getFirstElement(actionMetaData.getExampleUsagesAfter())); + } + catch (IOException e) { + LOG.error(e); + } + } + + private void showUsages(final JPanel panel, @Nullable final TextDescriptor exampleUsage) throws IOException { + boolean createMode = exampleUsage == null || panel.getComponents().length == 0; + if (createMode) { + panel.setLayout(new BorderLayout()); + panel.removeAll(); + } + + if (exampleUsage != null) { + final String name = exampleUsage.getFileName(); + final FileTypeManagerEx fileTypeManager = FileTypeManagerEx.getInstanceEx(); + final String extension = fileTypeManager.getExtension(name); + final FileType fileType = fileTypeManager.getFileTypeByExtension(extension); + + ActionUsagePanel actionUsagePanel; + if (createMode) { + actionUsagePanel = new ActionUsagePanel(); + Disposer.register(this, actionUsagePanel); + } + else { + actionUsagePanel = (ActionUsagePanel)panel.getComponent(0); + } + + actionUsagePanel.reset(exampleUsage.getText(), fileType); + + if (createMode) { + panel.add(actionUsagePanel); + } + } + panel.repaint(); + } + + JPanel getComponent() { + return myPanel; + } + + @Override + public void dispose() { + } + + public void init(final int preferredWidth) { + double height = + (myDescriptionBrowser.getSize().getHeight() + myBeforePanel.getSize().getHeight() + myAfterPanel.getSize().getHeight()) / 3; + Dimension newd = new Dimension(preferredWidth, (int)height); + myDescriptionBrowser.setSize(newd); + myDescriptionBrowser.setPreferredSize(newd); + myDescriptionBrowser.setMaximumSize(newd); + myDescriptionBrowser.setMinimumSize(newd); + + myBeforePanel.setSize(newd); + myBeforePanel.setPreferredSize(newd); + myBeforePanel.setMaximumSize(newd); + myBeforePanel.setMinimumSize(newd); + + myAfterPanel.setSize(newd); + myAfterPanel.setPreferredSize(newd); + myAfterPanel.setMaximumSize(newd); + myAfterPanel.setMinimumSize(newd); + } +} diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplateMetaData.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplateMetaData.java new file mode 100644 index 000000000000..a467b186e62c --- /dev/null +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplateMetaData.java @@ -0,0 +1,101 @@ +/* + * Copyright 2000-2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.intellij.codeInsight.template.postfix.settings; + +import com.intellij.codeInsight.intention.impl.config.BeforeAfterActionMetaData; +import com.intellij.codeInsight.intention.impl.config.TextDescriptor; +import com.intellij.codeInsight.template.postfix.templates.PostfixTemplate; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.lang.UrlClassLoader; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; + +public final class PostfixTemplateMetaData extends BeforeAfterActionMetaData { + + private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.template.postfix.settings.PostfixTemplateMetaData"); + private static final String DESCRIPTION_FOLDER = "postfixTemplates"; + public static final String KEY = "$key"; + + private URL urlDir = null; + private PostfixTemplate myTemplate; + + public PostfixTemplateMetaData(PostfixTemplate template) { + super(template.getClass().getClassLoader(), template.getClass().getSimpleName()); + myTemplate = template; + } + + @NotNull + @Override + public TextDescriptor[] getExampleUsagesBefore() { + + return decorateTextDescription(super.getExampleUsagesBefore()); + } + + private TextDescriptor[] decorateTextDescription(TextDescriptor[] before) { + List list = ContainerUtil.newArrayList(); + for (final TextDescriptor descriptor : before) { + list.add(new TextDescriptor() { + @Override + public String getText() throws IOException { + return StringUtil.replace(descriptor.getText(), KEY, myTemplate.getKey()); + } + + @Override + public String getFileName() { + return descriptor.getFileName(); + } + }); + } + return list.toArray(new TextDescriptor[list.size()]); + } + + @NotNull + @Override + public TextDescriptor[] getExampleUsagesAfter() { + return decorateTextDescription(super.getExampleUsagesAfter()); + } + + @Override + protected URL getDirURL() { + if (urlDir != null) { + return urlDir; + } + + final URL pageURL = myLoader.getResource(DESCRIPTION_FOLDER + "/" + myDescriptionDirectoryName + "/" + DESCRIPTION_FILE_NAME); + if (LOG.isDebugEnabled()) { + LOG.debug("Path:" + DESCRIPTION_FOLDER + "/" + myDescriptionDirectoryName); + LOG.debug("URL:" + pageURL); + } + if (pageURL != null) { + try { + final String url = pageURL.toExternalForm(); + urlDir = UrlClassLoader.internProtocol(new URL(url.substring(0, url.lastIndexOf('/')))); + return urlDir; + } + catch (MalformedURLException e) { + LOG.error(e); + } + } + return null; + } +} diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplatesConfigurable.form b/java/java-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplatesConfigurable.form index a94559ac8385..6e1f73ee0538 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplatesConfigurable.form +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplatesConfigurable.form @@ -16,15 +16,6 @@ - - - - - - - - - @@ -49,6 +40,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplatesConfigurable.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplatesConfigurable.java index 90d4eed6e2b9..3356244672a3 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplatesConfigurable.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplatesConfigurable.java @@ -28,6 +28,7 @@ import com.intellij.openapi.options.Configurable; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.options.SearchableConfigurable; import com.intellij.openapi.ui.ComboBox; +import com.intellij.openapi.util.Disposer; import com.intellij.ui.components.JBCheckBox; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.Nls; @@ -37,6 +38,8 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; import java.awt.*; import java.util.Comparator; import java.util.List; @@ -48,11 +51,14 @@ public class PostfixTemplatesConfigurable implements SearchableConfigurable, Edi @NotNull private final PostfixTemplatesSettings myTemplatesSettings; + private final PostfixDescriptionPanel myInnerPostfixDescriptionPanel = new PostfixDescriptionPanel(); + private JComponent myPanel; private JBCheckBox myCompletionEnabledCheckbox; private JBCheckBox myPostfixTemplatesEnabled; private JPanel myTemplatesListPanelContainer; private ComboBox myShortcutComboBox; + private JPanel myDescriptionPanel; private static final String SPACE = CodeInsightBundle.message("template.shortcut.space"); private static final String TAB = CodeInsightBundle.message("template.shortcut.tab"); @@ -82,7 +88,7 @@ public class PostfixTemplatesConfigurable implements SearchableConfigurable, Edi }); myTemplatesListPanel = new PostfixTemplatesListPanel(templates); myTemplatesListPanelContainer.setLayout(new BorderLayout()); - myTemplatesListPanelContainer.add(myTemplatesListPanel.getComponent(), BorderLayout.CENTER); + myTemplatesListPanelContainer.add(myTemplatesListPanel.getComponent()); myPostfixTemplatesEnabled.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { @@ -92,6 +98,30 @@ public class PostfixTemplatesConfigurable implements SearchableConfigurable, Edi myShortcutComboBox.addItem(TAB); myShortcutComboBox.addItem(SPACE); myShortcutComboBox.addItem(ENTER); + + myDescriptionPanel.setLayout(new BorderLayout()); + myDescriptionPanel.add(myInnerPostfixDescriptionPanel.getComponent()); + + myTemplatesListPanel.addSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + + resetDescriptionPanel(); + } + }); + myDescriptionPanel.setVisible(false); + } + + private void resetDescriptionPanel() { + assert myTemplatesListPanel != null; + PostfixTemplate template = myTemplatesListPanel.getTemplate(); + if (null != template) { + myDescriptionPanel.setVisible(true); + myInnerPostfixDescriptionPanel.reset(new PostfixTemplateMetaData(template)); + } + else { + myDescriptionPanel.setVisible(false); + } } @NotNull @@ -147,6 +177,7 @@ public class PostfixTemplatesConfigurable implements SearchableConfigurable, Edi myPostfixTemplatesEnabled.setSelected(myTemplatesSettings.isPostfixTemplatesEnabled()); myCompletionEnabledCheckbox.setSelected(myTemplatesSettings.isTemplatesCompletionEnabled()); myShortcutComboBox.setSelectedItem(shortcutToString((char)myTemplatesSettings.getShortcut())); + resetDescriptionPanel(); updateComponents(); } } @@ -164,6 +195,7 @@ public class PostfixTemplatesConfigurable implements SearchableConfigurable, Edi @Override public void disposeUIResources() { + Disposer.dispose(myInnerPostfixDescriptionPanel); myTemplatesListPanel = null; } diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplatesListPanel.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplatesListPanel.java index 4ecc8c0ee4ac..3665b7e9e42b 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplatesListPanel.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplatesListPanel.java @@ -32,6 +32,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; +import javax.swing.event.ListSelectionListener; import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; import java.util.Arrays; @@ -48,24 +49,6 @@ public class PostfixTemplatesListPanel { } }; - private static final NotNullFunction GET_DESCRIPTION_FUNCTION = - new NotNullFunction() { - @NotNull - @Override - public String fun(@NotNull PostfixTemplate template) { - return template.getDescription(); - } - }; - - private static final NotNullFunction GET_EXAMPLE_FUNCTION = - new NotNullFunction() { - @NotNull - @Override - public String fun(@NotNull PostfixTemplate template) { - return template.getExample(); - } - }; - @NotNull private final Map myTemplatesState = ContainerUtil.newHashMap(); @NotNull private final JPanel myPanelWithTableView; private final TableView myTemplatesTableView; @@ -79,7 +62,7 @@ public class PostfixTemplatesListPanel { myTemplatesTableView.setAutoCreateRowSorter(true); myTemplatesTableView.setShowGrid(false); myTemplatesTableView.setBorder(null); - + myTemplatesTableView.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); new TableViewSpeedSearch(myTemplatesTableView) { @Override protected String getItemText(@NotNull PostfixTemplate template) { @@ -94,21 +77,19 @@ public class PostfixTemplatesListPanel { .disableUpDownActions().createPanel(); } + public PostfixTemplate getTemplate() { + return ContainerUtil.getFirstItem(myTemplatesTableView.getSelection()); + } + @NotNull private ColumnInfo[] generateColumns(@NotNull List templates) { String longestTemplateName = ""; - String longestDescription = ""; - String longestExample = ""; for (PostfixTemplate template : templates) { longestTemplateName = longestString(longestTemplateName, GET_SHORTCUT_FUNCTION.fun(template)); - longestDescription = longestString(longestDescription, GET_DESCRIPTION_FUNCTION.fun(template)); - longestExample = longestString(longestExample, GET_EXAMPLE_FUNCTION.fun(template)); } return new ColumnInfo[]{ new BooleanColumnInfo(), - new StringColumnInfo("Shortcut", GET_SHORTCUT_FUNCTION, longestTemplateName), - new StringColumnInfo("Description", GET_DESCRIPTION_FUNCTION, longestDescription), - new StringColumnInfo("Example", GET_EXAMPLE_FUNCTION, longestExample), + new StringColumnInfo("Shortcut", GET_SHORTCUT_FUNCTION, longestTemplateName) }; } @@ -228,4 +209,8 @@ public class PostfixTemplatesListPanel { return myValueOfFunction.fun(template); } } + + public void addSelectionListener(ListSelectionListener listener) { + myTemplatesTableView.getSelectionModel().addListSelectionListener(listener); + } } diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/AssertStatementPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/AssertStatementPostfixTemplate.java index daa4da26a4f4..c48ef1b97ba1 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/AssertStatementPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/AssertStatementPostfixTemplate.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.codeInsight.template.postfix.templates; import com.intellij.codeInsight.template.postfix.util.PostfixTemplatesUtils; @@ -7,7 +22,7 @@ import org.jetbrains.annotations.NotNull; public class AssertStatementPostfixTemplate extends BooleanPostfixTemplate { public AssertStatementPostfixTemplate() { - super("assert", "Creates assertion from boolean expression", "assert expr;"); + super("assert", "assert expr;"); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/BooleanPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/BooleanPostfixTemplate.java index f8700bed4644..1f4ad8eb695b 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/BooleanPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/BooleanPostfixTemplate.java @@ -22,8 +22,8 @@ import com.intellij.psi.PsiExpression; import org.jetbrains.annotations.NotNull; abstract public class BooleanPostfixTemplate extends PostfixTemplate { - protected BooleanPostfixTemplate(@NotNull String name, @NotNull String description, @NotNull String example) { - super(name, description, example); + protected BooleanPostfixTemplate(@NotNull String name, @NotNull String example) { + super(name, example); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/CastExpressionPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/CastExpressionPostfixTemplate.java index 414b79ce0b20..7c56047fe059 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/CastExpressionPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/CastExpressionPostfixTemplate.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.codeInsight.template.postfix.templates; import com.intellij.codeInsight.generation.surroundWith.JavaWithCastSurrounder; @@ -8,7 +23,7 @@ import org.jetbrains.annotations.NotNull; public class CastExpressionPostfixTemplate extends ExpressionPostfixTemplateWithChooser { public CastExpressionPostfixTemplate() { - super("cast", "Surrounds expression with cast", "((SomeType) expr)"); + super("cast", "((SomeType) expr)"); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ElseStatementPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ElseStatementPostfixTemplate.java index a148a1bf8896..f92f4c81f71b 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ElseStatementPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ElseStatementPostfixTemplate.java @@ -25,7 +25,7 @@ import org.jetbrains.annotations.NotNull; public class ElseStatementPostfixTemplate extends BooleanPostfixTemplate { public ElseStatementPostfixTemplate() { - super("else", "Checks boolean expression to be 'false'", "if (!expr)"); + super("else", "if (!expr)"); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ExpressionPostfixTemplateWithChooser.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ExpressionPostfixTemplateWithChooser.java index 3bd7928c3e1c..69df4ccd40a7 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ExpressionPostfixTemplateWithChooser.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ExpressionPostfixTemplateWithChooser.java @@ -38,15 +38,14 @@ import java.util.List; * @author ignatov */ public abstract class ExpressionPostfixTemplateWithChooser extends PostfixTemplate { - protected ExpressionPostfixTemplateWithChooser(@NotNull String name, @NotNull String description, @NotNull String example) { - super(name, description, example); + protected ExpressionPostfixTemplateWithChooser(@NotNull String name, @NotNull String example) { + super(name, example); } protected ExpressionPostfixTemplateWithChooser(@NotNull String name, @NotNull String key, - @NotNull String description, @NotNull String example) { - super(name, key, description, example); + super(name, key, example); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ForAscendingPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ForAscendingPostfixTemplate.java index f2282eb15145..550b1c70b0c1 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ForAscendingPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ForAscendingPostfixTemplate.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.codeInsight.template.postfix.templates; import com.intellij.openapi.util.Pair; @@ -7,7 +22,7 @@ import org.jetbrains.annotations.Nullable; public class ForAscendingPostfixTemplate extends ForIndexedPostfixTemplate { public ForAscendingPostfixTemplate() { - super("fori", "Iterates with index over collection", "for (int i = 0; i < expr.length; i++)"); + super("fori", "for (int i = 0; i < expr.length; i++)"); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ForDescendingPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ForDescendingPostfixTemplate.java index 33888a5920e9..b55405b01e3c 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ForDescendingPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ForDescendingPostfixTemplate.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.codeInsight.template.postfix.templates; import com.intellij.codeInsight.template.postfix.util.PostfixTemplatesUtils; @@ -8,7 +23,7 @@ import org.jetbrains.annotations.Nullable; public class ForDescendingPostfixTemplate extends ForIndexedPostfixTemplate { public ForDescendingPostfixTemplate() { - super("forr", "Iterates with index in reverse order", "for (int i = expr.length-1; i >= 0; i--)"); + super("forr", "for (int i = expr.length-1; i >= 0; i--)"); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ForIndexedPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ForIndexedPostfixTemplate.java index bf025d17741f..4fd22ed5e67d 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ForIndexedPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ForIndexedPostfixTemplate.java @@ -31,8 +31,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public abstract class ForIndexedPostfixTemplate extends PostfixTemplate { - protected ForIndexedPostfixTemplate(@NotNull String key, @NotNull String description, @NotNull String example) { - super(key, description, example); + protected ForIndexedPostfixTemplate(@NotNull String key, @NotNull String example) { + super(key, example); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ForeachPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ForeachPostfixTemplate.java index 72bbb4f703bf..88f07dca85ce 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ForeachPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ForeachPostfixTemplate.java @@ -32,7 +32,7 @@ import org.jetbrains.annotations.NotNull; public class ForeachPostfixTemplate extends PostfixTemplate { public ForeachPostfixTemplate() { - super("for", "Iterates over enumerable collection", "for (T item : collection)"); + super("for", "for (T item : collection)"); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/FormatPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/FormatPostfixTemplate.java index a799f39ca466..288df0770259 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/FormatPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/FormatPostfixTemplate.java @@ -26,7 +26,7 @@ import org.jetbrains.annotations.NotNull; public class FormatPostfixTemplate extends PostfixTemplate { public FormatPostfixTemplate() { - super("format", "Creates String.format call", "String.format(expr);"); + super("format", "String.format(expr);"); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/IfStatementPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/IfStatementPostfixTemplate.java index 812247428e51..231a7a2cf10f 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/IfStatementPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/IfStatementPostfixTemplate.java @@ -24,7 +24,7 @@ import org.jetbrains.annotations.NotNull; public class IfStatementPostfixTemplate extends BooleanPostfixTemplate { public IfStatementPostfixTemplate() { - super("if", "Checks boolean expression to be 'true'", "if (expr)"); + super("if", "if (expr)"); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/InstanceofExpressionPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/InstanceofExpressionPostfixTemplate.java index 1884d099edcd..1bb19448b1ea 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/InstanceofExpressionPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/InstanceofExpressionPostfixTemplate.java @@ -41,7 +41,7 @@ public class InstanceofExpressionPostfixTemplate extends PostfixTemplate { } public InstanceofExpressionPostfixTemplate(String alias) { - super(alias, "Surrounds expression with instanceof", "expr instanceof SomeType ? ((SomeType) expr). : null"); + super(alias, "expr instanceof Type ? ((Type) expr). : null"); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/IntroduceFieldPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/IntroduceFieldPostfixTemplate.java index cb85db9e04fd..88220955ecbf 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/IntroduceFieldPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/IntroduceFieldPostfixTemplate.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.codeInsight.template.postfix.templates; import com.intellij.openapi.application.ApplicationManager; @@ -10,7 +25,7 @@ import org.jetbrains.annotations.NotNull; public class IntroduceFieldPostfixTemplate extends ExpressionPostfixTemplateWithChooser { public IntroduceFieldPostfixTemplate() { - super("field", "Introduces field for expression", "myField = expr;"); + super("field", "myField = expr;"); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/IntroduceVariablePostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/IntroduceVariablePostfixTemplate.java index 019a4fed72bd..216565b0f9c7 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/IntroduceVariablePostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/IntroduceVariablePostfixTemplate.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.codeInsight.template.postfix.templates; import com.intellij.openapi.application.ApplicationManager; @@ -16,7 +31,7 @@ import org.jetbrains.annotations.NotNull; // todo: support for int[].var (parses as .class access!) public class IntroduceVariablePostfixTemplate extends ExpressionPostfixTemplateWithChooser { public IntroduceVariablePostfixTemplate() { - super("var", "Introduces variable for expression", "T name = expr;"); + super("var", "T name = expr;"); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/IsNullCheckPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/IsNullCheckPostfixTemplate.java index 0d6ce72f7776..428935a7870b 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/IsNullCheckPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/IsNullCheckPostfixTemplate.java @@ -1,10 +1,25 @@ +/* + * Copyright 2000-2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.codeInsight.template.postfix.templates; import org.jetbrains.annotations.NotNull; public class IsNullCheckPostfixTemplate extends NullCheckPostfixTemplate { public IsNullCheckPostfixTemplate() { - super("null", "Checks expression to be null", "if (expr == null)"); + super("null", "if (expr == null)"); } @NotNull diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/NonVoidPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/NonVoidPostfixTemplate.java index 09757e53e826..6fcd986588df 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/NonVoidPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/NonVoidPostfixTemplate.java @@ -22,8 +22,8 @@ import com.intellij.psi.PsiExpression; import org.jetbrains.annotations.NotNull; abstract public class NonVoidPostfixTemplate extends PostfixTemplate { - protected NonVoidPostfixTemplate(@NotNull String name, @NotNull String description, @NotNull String example) { - super(name, description, example); + protected NonVoidPostfixTemplate(@NotNull String name, @NotNull String example) { + super(name, example); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/NotExpressionPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/NotExpressionPostfixTemplate.java index e2e3db8b8be6..29cfb22c02fa 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/NotExpressionPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/NotExpressionPostfixTemplate.java @@ -31,11 +31,11 @@ public class NotExpressionPostfixTemplate extends ExpressionPostfixTemplateWithC }; public NotExpressionPostfixTemplate() { - super("not", "Negates boolean expression", "!expr"); + super("not", "!expr"); } public NotExpressionPostfixTemplate(String alias) { - super(alias, alias, "Negates boolean expression", "!expr"); + super(alias, alias, "!expr"); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/NotNullCheckPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/NotNullCheckPostfixTemplate.java index ea2480f86a0e..58a9ebf7a484 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/NotNullCheckPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/NotNullCheckPostfixTemplate.java @@ -24,7 +24,7 @@ public class NotNullCheckPostfixTemplate extends NullCheckPostfixTemplate { } public NotNullCheckPostfixTemplate(String alias) { - super(alias, "Checks expression to be not-null", "if (expr != null)"); + super(alias, "if (expr != null)"); } @NotNull diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/NullCheckPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/NullCheckPostfixTemplate.java index c7ad21b2fb11..c77b2d527b54 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/NullCheckPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/NullCheckPostfixTemplate.java @@ -30,8 +30,8 @@ import org.jetbrains.annotations.NotNull; * @author ignatov */ public abstract class NullCheckPostfixTemplate extends PostfixTemplate { - protected NullCheckPostfixTemplate(@NotNull String name, @NotNull String description, @NotNull String example) { - super(name, description, example); + protected NullCheckPostfixTemplate(@NotNull String name, @NotNull String example) { + super(name, example); } @NotNull diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ParenthesizedExpressionPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ParenthesizedExpressionPostfixTemplate.java index 52492fb54f79..adfe635950a3 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ParenthesizedExpressionPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ParenthesizedExpressionPostfixTemplate.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.codeInsight.template.postfix.templates; import com.intellij.openapi.editor.Editor; @@ -9,7 +24,7 @@ import org.jetbrains.annotations.NotNull; public class ParenthesizedExpressionPostfixTemplate extends ExpressionPostfixTemplateWithChooser { public ParenthesizedExpressionPostfixTemplate() { - super("par", "Parenthesizes expression", "(expression)"); + super("par", "(expression)"); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/PostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/PostfixTemplate.java index 747366d1832f..21f0d832abfb 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/PostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/PostfixTemplate.java @@ -15,27 +15,36 @@ */ package com.intellij.codeInsight.template.postfix.templates; +import com.intellij.codeInsight.template.postfix.settings.PostfixTemplateMetaData; import com.intellij.codeInsight.template.postfix.settings.PostfixTemplatesSettings; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; +import java.io.IOException; + public abstract class PostfixTemplate { @NotNull private final String myPresentableName; @NotNull private final String myKey; @NotNull private final String myDescription; @NotNull private final String myExample; - protected PostfixTemplate(@NotNull String name, @NotNull String description, @NotNull String example) { - this(name, "." + name, description, example); + protected PostfixTemplate(@NotNull String name, @NotNull String example) { + this(name, "." + name, example); } - protected PostfixTemplate(@NotNull String name, @NotNull String key, @NotNull String description, @NotNull String example) { + protected PostfixTemplate(@NotNull String name, @NotNull String key, @NotNull String example) { myPresentableName = name; myKey = key; - myDescription = description; myExample = example; + + try { + myDescription = new PostfixTemplateMetaData(this).getDescription().getText(); + } + catch (IOException e) { + throw new RuntimeException(e.getMessage(), e); + } } @NotNull diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ReturnStatementPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ReturnStatementPostfixTemplate.java index afc3236b8319..f16ca44bf51d 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ReturnStatementPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ReturnStatementPostfixTemplate.java @@ -22,7 +22,7 @@ import org.jetbrains.annotations.NotNull; public class ReturnStatementPostfixTemplate extends NonVoidPostfixTemplate { public ReturnStatementPostfixTemplate() { - super("return", "Returns value from containing method", "return expr;"); + super("return", "return expr;"); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/SoutPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/SoutPostfixTemplate.java index 4f0667f5af5e..b04d001402c9 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/SoutPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/SoutPostfixTemplate.java @@ -22,7 +22,7 @@ import org.jetbrains.annotations.NotNull; public class SoutPostfixTemplate extends NonVoidPostfixTemplate { public SoutPostfixTemplate() { - super("sout", "Creates System.out.println call", "System.out.println(expr);"); + super("sout", "System.out.println(expr);"); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/StatementPostfixTemplateBase.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/StatementPostfixTemplateBase.java index 8f26ec08fae0..593e45f930d5 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/StatementPostfixTemplateBase.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/StatementPostfixTemplateBase.java @@ -28,8 +28,8 @@ import com.intellij.psi.util.PsiTreeUtil; * @author ignatov */ public abstract class StatementPostfixTemplateBase extends PostfixTemplate { - protected StatementPostfixTemplateBase(String name, String description, String example) { - super(name, description, example); + protected StatementPostfixTemplateBase(String name, String example) { + super(name, example); } protected void surroundWith(PsiElement context, Editor editor, String text) { diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/SwitchStatementPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/SwitchStatementPostfixTemplate.java index 20a7299af8ec..e84aa8ed38fd 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/SwitchStatementPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/SwitchStatementPostfixTemplate.java @@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable; public class SwitchStatementPostfixTemplate extends StatementPostfixTemplateBase { public SwitchStatementPostfixTemplate() { - super("switch", "Produces switch over integral/enum/string values", "switch (expr)"); + super("switch", "switch (expr)"); } private static boolean isSwitchCompatibleType(@Nullable PsiType type, @NotNull PsiElement context) { diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/SynchronizedStatementPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/SynchronizedStatementPostfixTemplate.java index eb46ba9f0540..2bf17b5fad5f 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/SynchronizedStatementPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/SynchronizedStatementPostfixTemplate.java @@ -26,7 +26,7 @@ import org.jetbrains.annotations.NotNull; public class SynchronizedStatementPostfixTemplate extends StatementPostfixTemplateBase { public SynchronizedStatementPostfixTemplate() { - super("synchronized", "Produces synchronization statement", "synchronized (expr)"); + super("synchronized", "synchronized (expr)"); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ThrowExceptionPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ThrowExceptionPostfixTemplate.java index 7b0aaa00f4c1..98762cd5c0f7 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ThrowExceptionPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/ThrowExceptionPostfixTemplate.java @@ -24,7 +24,7 @@ import org.jetbrains.annotations.NotNull; public class ThrowExceptionPostfixTemplate extends PostfixTemplate { public ThrowExceptionPostfixTemplate() { - super("throw", "Throws expression of 'Throwable' type", "throw expr;"); + super("throw", "throw expr;"); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/TryStatementPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/TryStatementPostfixTemplate.java index f14754f30270..9b890d6e473f 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/TryStatementPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/TryStatementPostfixTemplate.java @@ -29,7 +29,7 @@ import org.jetbrains.annotations.NotNull; public class TryStatementPostfixTemplate extends PostfixTemplate { protected TryStatementPostfixTemplate() { - super("try", "Insert statement in try-catch block", "try { exp } catch (Exception e) { e.printStackTrace(); }"); + super("try", "try { exp } catch(Ex e) { e.printStackTrace(); }"); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/TryWithResourcesPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/TryWithResourcesPostfixTemplate.java index 9e857ad9ce95..74a56c8da21a 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/TryWithResourcesPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/TryWithResourcesPostfixTemplate.java @@ -38,7 +38,7 @@ import java.util.Collections; public class TryWithResourcesPostfixTemplate extends PostfixTemplate { protected TryWithResourcesPostfixTemplate() { - super("twr", "Description", "Example"); + super("twr", "try(Type f = new Type()) {} catch (Ex e) {}"); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/WhileStatementPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/WhileStatementPostfixTemplate.java index 4c856f7e8299..7ec46518e9f7 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/WhileStatementPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/WhileStatementPostfixTemplate.java @@ -22,7 +22,7 @@ import org.jetbrains.annotations.NotNull; public class WhileStatementPostfixTemplate extends BooleanPostfixTemplate { public WhileStatementPostfixTemplate() { - super("while", "Iterating while boolean statement is 'true'", "while (expr)"); + super("while", "while (expr)"); } @Override diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/ActionUsagePanel.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/ActionUsagePanel.java new file mode 100644 index 000000000000..93fb332f475b --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/ActionUsagePanel.java @@ -0,0 +1,146 @@ +/* + * Copyright 2000-2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.intention.impl.config; + +import com.intellij.openapi.Disposable; +import com.intellij.openapi.editor.*; +import com.intellij.openapi.editor.colors.CodeInsightColors; +import com.intellij.openapi.editor.colors.EditorColorsManager; +import com.intellij.openapi.editor.colors.EditorColorsScheme; +import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.openapi.editor.highlighter.EditorHighlighterFactory; +import com.intellij.openapi.editor.markup.TextAttributes; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.util.Segment; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.DocumentUtil; +import com.intellij.util.ui.RangeBlinker; +import org.jetbrains.annotations.NonNls; + +import javax.swing.*; +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + + +public class ActionUsagePanel extends JPanel implements Disposable { + @NonNls private static final String SPOT_MARKER = "spot"; + protected final EditorEx myEditor; + protected final RangeBlinker myRangeBlinker; + + + public ActionUsagePanel() { + myEditor = (EditorEx)createEditor("", 10, 3, -1); + setLayout(new BorderLayout()); + add(myEditor.getComponent(), BorderLayout.CENTER); + TextAttributes blinkAttributes = + EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES); + myRangeBlinker = new RangeBlinker(myEditor, blinkAttributes, Integer.MAX_VALUE); + } + + protected static Editor createEditor(String text, int column, int line, int selectedLine) { + EditorFactory editorFactory = EditorFactory.getInstance(); + Document editorDocument = editorFactory.createDocument(text); + EditorEx editor = (EditorEx)editorFactory.createViewer(editorDocument); + EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); + editor.setColorsScheme(scheme); + EditorSettings settings = editor.getSettings(); + settings.setWhitespacesShown(true); + settings.setLineMarkerAreaShown(false); + settings.setIndentGuidesShown(false); + settings.setFoldingOutlineShown(false); + settings.setAdditionalColumnsCount(0); + settings.setAdditionalLinesCount(0); + settings.setRightMarginShown(true); + settings.setRightMargin(60); + + LogicalPosition pos = new LogicalPosition(line, column); + editor.getCaretModel().moveToLogicalPosition(pos); + if (selectedLine >= 0) { + editor.getSelectionModel().setSelection(editorDocument.getLineStartOffset(selectedLine), + editorDocument.getLineEndOffset(selectedLine)); + } + + return editor; + } + + public void reset(final String usageText, final FileType fileType) { + reinitViews(); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + if (myEditor.isDisposed()) return; + DocumentUtil.writeInRunUndoTransparentAction(new Runnable() { + @Override + public void run() { + configureByText(usageText, fileType); + } + }); + } + }); + } + + private void configureByText(final String usageText, FileType fileType) { + Document document = myEditor.getDocument(); + String text = StringUtil.convertLineSeparators(usageText); + document.replaceString(0, document.getTextLength(), text); + final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); + myEditor.setHighlighter(EditorHighlighterFactory.getInstance().createEditorHighlighter(fileType, scheme, null)); + setupSpots(document); + } + + private void setupSpots(Document document) { + List markers = new ArrayList(); + while (true) { + String text = document.getText(); + final int spotStart = text.indexOf("<" + SPOT_MARKER + ">"); + if (spotStart < 0) break; + final int spotEnd = text.indexOf("", spotStart); + if (spotEnd < 0) break; + + document.deleteString(spotEnd, spotEnd + SPOT_MARKER.length() + 3); + document.deleteString(spotStart, spotStart + SPOT_MARKER.length() + 2); + Segment spotMarker = new Segment() { + @Override + public int getStartOffset() { + return spotStart; + } + + @Override + public int getEndOffset() { + return spotEnd - SPOT_MARKER.length() - 2; + } + }; + markers.add(spotMarker); + } + myRangeBlinker.resetMarkers(markers); + if (!markers.isEmpty()) { + myRangeBlinker.startBlinking(); + } + } + + @Override + public void dispose() { + myRangeBlinker.stopBlinking(); + EditorFactory editorFactory = EditorFactory.getInstance(); + editorFactory.releaseEditor(myEditor); + } + + private void reinitViews() { + myEditor.reinitSettings(); + myEditor.getMarkupModel().removeAllHighlighters(); + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/BeforeAfterActionMetaData.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/BeforeAfterActionMetaData.java new file mode 100644 index 000000000000..3f0f19e42fa4 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/BeforeAfterActionMetaData.java @@ -0,0 +1,163 @@ +/* + * Copyright 2000-2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.intention.impl.config; + +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.fileTypes.FileTypeManager; +import com.intellij.util.ArrayUtil; +import com.intellij.util.ObjectUtils; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + + +public abstract class BeforeAfterActionMetaData { + private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.intention.impl.config.BeforeAfterActionMetaData"); + + @NonNls protected static final String DESCRIPTION_FILE_NAME = "description.html"; + @NonNls static final String EXAMPLE_USAGE_URL_SUFFIX = ".template"; + @NonNls private static final String BEFORE_TEMPLATE_PREFIX = "before"; + @NonNls private static final String AFTER_TEMPLATE_PREFIX = "after"; + protected final ClassLoader myLoader; + protected final String myDescriptionDirectoryName; + protected TextDescriptor[] myExampleUsagesBefore = null; + protected TextDescriptor[] myExampleUsagesAfter = null; + protected TextDescriptor myDescription = null; + + + public BeforeAfterActionMetaData(ClassLoader loader, String descriptionDirectoryName) { + myLoader = loader; + myDescriptionDirectoryName = descriptionDirectoryName; + } + + public BeforeAfterActionMetaData(final TextDescriptor description, + final TextDescriptor[] exampleUsagesBefore, + final TextDescriptor[] exampleUsagesAfter) { + myLoader = null; + myDescriptionDirectoryName = null; + + myExampleUsagesBefore = exampleUsagesBefore; + myExampleUsagesAfter = exampleUsagesAfter; + myDescription = description; + } + + + @NotNull + private static TextDescriptor[] retrieveURLs(@NotNull URL descriptionDirectory, @NotNull String prefix, @NotNull String suffix) + throws MalformedURLException { + List urls = new ArrayList(); + final FileType[] fileTypes = FileTypeManager.getInstance().getRegisteredFileTypes(); + for (FileType fileType : fileTypes) { + final String[] extensions = FileTypeManager.getInstance().getAssociatedExtensions(fileType); + for (String extension : extensions) { + for (int i = 0; ; i++) { + URL url = new URL(descriptionDirectory.toExternalForm() + "/" + + prefix + "." + extension + (i == 0 ? "" : Integer.toString(i)) + + suffix); + try { + InputStream inputStream = url.openStream(); + inputStream.close(); + urls.add(new ResourceTextDescriptor(url)); + } + catch (IOException ioe) { + break; + } + } + } + } + if (urls.isEmpty()) { + String[] children; + Exception cause = null; + try { + URI uri = descriptionDirectory.toURI(); + children = uri.isOpaque() ? null : ObjectUtils.notNull(new File(uri).list(), ArrayUtil.EMPTY_STRING_ARRAY); + } + catch (URISyntaxException e) { + cause = e; + children = null; + } + catch (IllegalArgumentException e) { + cause = e; + children = null; + } + LOG.error("URLs not found for available file types and prefix: '" + + prefix + + "', suffix: '" + + suffix + + "';" + + " in directory: '" + + descriptionDirectory + + "'" + + (children == null ? "" : "; directory contents: " + Arrays.asList(children)), cause); + return new TextDescriptor[0]; + } + return urls.toArray(new TextDescriptor[urls.size()]); + } + + @NotNull + public TextDescriptor[] getExampleUsagesBefore() { + if (myExampleUsagesBefore == null) { + try { + myExampleUsagesBefore = retrieveURLs(getDirURL(), BEFORE_TEMPLATE_PREFIX, EXAMPLE_USAGE_URL_SUFFIX); + } + catch (MalformedURLException e) { + LOG.error(e); + } + } + return myExampleUsagesBefore; + } + + @NotNull + public TextDescriptor[] getExampleUsagesAfter() { + if (myExampleUsagesAfter == null) { + try { + myExampleUsagesAfter = retrieveURLs(getDirURL(), AFTER_TEMPLATE_PREFIX, EXAMPLE_USAGE_URL_SUFFIX); + } + catch (MalformedURLException e) { + LOG.error(e); + } + } + return myExampleUsagesAfter; + } + + @NotNull + public TextDescriptor getDescription() { + if (myDescription == null) { + try { + final URL dirURL = getDirURL(); + URL descriptionURL = new URL(dirURL.toExternalForm() + "/" + DESCRIPTION_FILE_NAME); + myDescription = new ResourceTextDescriptor(descriptionURL); + } + catch (MalformedURLException e) { + LOG.error(e); + } + } + return myDescription; + } + + protected abstract URL getDirURL(); +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionActionMetaData.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionActionMetaData.java index 31ecb8a5481d..7fe9433edc04 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionActionMetaData.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionActionMetaData.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -23,54 +23,30 @@ import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.ide.plugins.cl.PluginClassLoader; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.PluginId; -import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.fileTypes.FileTypeManager; -import com.intellij.util.ArrayUtil; -import com.intellij.util.ObjectUtils; import com.intellij.util.lang.UrlClassLoader; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public final class IntentionActionMetaData { +public final class IntentionActionMetaData extends BeforeAfterActionMetaData { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.intention.impl.config.IntentionActionMetaData"); @NotNull private final IntentionAction myAction; - private final ClassLoader myIntentionLoader; - private final String myDescriptionDirectoryName; @NotNull public final String[] myCategory; - - private TextDescriptor[] myExampleUsagesBefore = null; - private TextDescriptor[] myExampleUsagesAfter = null; - private TextDescriptor myDescription = null; private URL myDirURL = null; - - @NonNls private static final String BEFORE_TEMPLATE_PREFIX = "before"; - @NonNls private static final String AFTER_TEMPLATE_PREFIX = "after"; - @NonNls static final String EXAMPLE_USAGE_URL_SUFFIX = ".template"; - @NonNls private static final String DESCRIPTION_FILE_NAME = "description.html"; @NonNls private static final String INTENTION_DESCRIPTION_FOLDER = "intentionDescriptions"; public IntentionActionMetaData(@NotNull IntentionAction action, @Nullable ClassLoader loader, @NotNull String[] category, @NotNull String descriptionDirectoryName) { + super(loader, descriptionDirectoryName); + myAction = action; - myIntentionLoader = loader; myCategory = category; - myDescriptionDirectoryName = descriptionDirectoryName; } public IntentionActionMetaData(@NotNull final IntentionAction action, @@ -78,110 +54,22 @@ public final class IntentionActionMetaData { final TextDescriptor description, final TextDescriptor[] exampleUsagesBefore, final TextDescriptor[] exampleUsagesAfter) { + super(description, exampleUsagesBefore, exampleUsagesAfter); + myAction = action; myCategory = category; - myExampleUsagesBefore = exampleUsagesBefore; - myExampleUsagesAfter = exampleUsagesAfter; - myDescription = description; - myIntentionLoader = null; - myDescriptionDirectoryName = null; } public String toString() { return getFamily(); } - @NotNull - public TextDescriptor[] getExampleUsagesBefore() { - if(myExampleUsagesBefore == null){ - try { - myExampleUsagesBefore = retrieveURLs(getDirURL(), BEFORE_TEMPLATE_PREFIX, EXAMPLE_USAGE_URL_SUFFIX); - } - catch (MalformedURLException e) { - LOG.error(e); - } - } - return myExampleUsagesBefore; - } - - @NotNull - public TextDescriptor[] getExampleUsagesAfter() { - if(myExampleUsagesAfter == null){ - try { - myExampleUsagesAfter = retrieveURLs(getDirURL(), AFTER_TEMPLATE_PREFIX, EXAMPLE_USAGE_URL_SUFFIX); - } - catch (MalformedURLException e) { - LOG.error(e); - } - } - return myExampleUsagesAfter; - } - - @NotNull - public TextDescriptor getDescription() { - if(myDescription == null){ - try { - final URL dirURL = getDirURL(); - URL descriptionURL = new URL(dirURL.toExternalForm() + "/" + DESCRIPTION_FILE_NAME); - myDescription = new ResourceTextDescriptor(descriptionURL); - } - catch (MalformedURLException e) { - LOG.error(e); - } - } - return myDescription; - } - - @NotNull - private static TextDescriptor[] retrieveURLs(@NotNull URL descriptionDirectory, @NotNull String prefix, @NotNull String suffix) throws MalformedURLException { - List urls = new ArrayList(); - final FileType[] fileTypes = FileTypeManager.getInstance().getRegisteredFileTypes(); - for (FileType fileType : fileTypes) { - final String[] extensions = FileTypeManager.getInstance().getAssociatedExtensions(fileType); - for (String extension : extensions) { - for (int i = 0; ; i++) { - URL url = new URL(descriptionDirectory.toExternalForm() + "/" + - prefix + "." + extension + (i == 0 ? "" : Integer.toString(i)) + - suffix); - try { - InputStream inputStream = url.openStream(); - inputStream.close(); - urls.add(new ResourceTextDescriptor(url)); - } - catch (IOException ioe) { - break; - } - } - } - } - if (urls.isEmpty()) { - String[] children; - Exception cause = null; - try { - URI uri = descriptionDirectory.toURI(); - children = uri.isOpaque()? null : ObjectUtils.notNull(new File(uri).list(), ArrayUtil.EMPTY_STRING_ARRAY); - } - catch (URISyntaxException e) { - cause = e; - children = null; - } - catch (IllegalArgumentException e) { - cause = e; - children = null; - } - LOG.error("URLs not found for available file types and prefix: '"+prefix+"', suffix: '"+suffix+"';" + - " in directory: '"+descriptionDirectory+ "'" + (children == null? "" : "; directory contents: "+ Arrays.asList(children)), cause); - return new TextDescriptor[0]; - } - return urls.toArray(new TextDescriptor[urls.size()]); - } - @Nullable private static URL getIntentionDescriptionDirURL(ClassLoader aClassLoader, String intentionFolderName) { - final URL pageURL = aClassLoader.getResource(INTENTION_DESCRIPTION_FOLDER + "/" + intentionFolderName+"/"+ DESCRIPTION_FILE_NAME); + final URL pageURL = aClassLoader.getResource(INTENTION_DESCRIPTION_FOLDER + "/" + intentionFolderName + "/" + DESCRIPTION_FILE_NAME); if (LOG.isDebugEnabled()) { - LOG.debug("Path:"+"intentionDescriptions/" + intentionFolderName); - LOG.debug("URL:"+pageURL); + LOG.debug("Path:" + "intentionDescriptions/" + intentionFolderName); + LOG.debug("URL:" + pageURL); } if (pageURL != null) { try { @@ -195,21 +83,10 @@ public final class IntentionActionMetaData { return null; } - private URL getDirURL() { - if (myDirURL == null) { - myDirURL = getIntentionDescriptionDirURL(myIntentionLoader, myDescriptionDirectoryName); - } - if (myDirURL == null) { //plugin compatibility - myDirURL = getIntentionDescriptionDirURL(myIntentionLoader, getFamily()); - } - LOG.assertTrue(myDirURL != null, "Intention Description Dir URL is null: " + - getFamily() +"; "+myDescriptionDirectoryName + ", " + myIntentionLoader); - return myDirURL; - } - - @Nullable public PluginId getPluginId() { - if (myIntentionLoader instanceof PluginClassLoader) { - return ((PluginClassLoader)myIntentionLoader).getPluginId(); + @Nullable + public PluginId getPluginId() { + if (myLoader instanceof PluginClassLoader) { + return ((PluginClassLoader)myLoader).getPluginId(); } return null; } @@ -223,4 +100,16 @@ public final class IntentionActionMetaData { public IntentionAction getAction() { return myAction; } + + protected URL getDirURL() { + if (myDirURL == null) { + myDirURL = getIntentionDescriptionDirURL(myLoader, myDescriptionDirectoryName); + } + if (myDirURL == null) { //plugin compatibility + myDirURL = getIntentionDescriptionDirURL(myLoader, getFamily()); + } + LOG.assertTrue(myDirURL != null, "Intention Description Dir URL is null: " + + getFamily() + "; " + myDescriptionDirectoryName + ", " + myLoader); + return myDirURL; + } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionUsagePanel.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionUsagePanel.java index d422881187cb..68c1a2547266 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionUsagePanel.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionUsagePanel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -19,128 +19,7 @@ */ package com.intellij.codeInsight.intention.impl.config; -import com.intellij.openapi.editor.*; -import com.intellij.openapi.editor.colors.CodeInsightColors; -import com.intellij.openapi.editor.colors.EditorColorsManager; -import com.intellij.openapi.editor.colors.EditorColorsScheme; -import com.intellij.openapi.editor.ex.EditorEx; -import com.intellij.openapi.editor.highlighter.EditorHighlighterFactory; -import com.intellij.openapi.editor.markup.TextAttributes; -import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.util.Segment; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.util.DocumentUtil; -import com.intellij.util.ui.RangeBlinker; -import org.jetbrains.annotations.NonNls; +class IntentionUsagePanel extends ActionUsagePanel { -import javax.swing.*; -import java.awt.*; -import java.util.ArrayList; -import java.util.List; - -class IntentionUsagePanel extends JPanel{ - private final EditorEx myEditor; - @NonNls private static final String SPOT_MARKER = "spot"; - private final RangeBlinker myRangeBlinker; - - public IntentionUsagePanel() { - myEditor = (EditorEx)createEditor("", 10, 3, -1); - setLayout(new BorderLayout()); - add(myEditor.getComponent(), BorderLayout.CENTER); - TextAttributes blinkAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES); - myRangeBlinker = new RangeBlinker(myEditor, blinkAttributes, Integer.MAX_VALUE); - } - - public void reset(final String usageText, final FileType fileType) { - reinitViews(); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if (myEditor.isDisposed()) return; - DocumentUtil.writeInRunUndoTransparentAction(new Runnable() { - @Override - public void run() { - configureByText(usageText, fileType); - } - }); - } - }); - } - - private void configureByText(final String usageText, FileType fileType) { - Document document = myEditor.getDocument(); - String text = StringUtil.convertLineSeparators(usageText); - document.replaceString(0, document.getTextLength(), text); - final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); - myEditor.setHighlighter(EditorHighlighterFactory.getInstance().createEditorHighlighter(fileType, scheme, null)); - setupSpots(document); - } - - private void setupSpots(Document document) { - List markers = new ArrayList(); - while (true) { - String text = document.getText(); - final int spotStart = text.indexOf("<" + SPOT_MARKER + ">"); - if (spotStart < 0) break; - final int spotEnd = text.indexOf("", spotStart); - if (spotEnd < 0) break; - - document.deleteString(spotEnd, spotEnd + SPOT_MARKER.length() + 3); - document.deleteString(spotStart, spotStart + SPOT_MARKER.length() + 2); - Segment spotMarker = new Segment() { - @Override - public int getStartOffset() { - return spotStart; - } - - @Override - public int getEndOffset() { - return spotEnd - SPOT_MARKER.length() - 2; - } - }; - markers.add(spotMarker); - } - myRangeBlinker.resetMarkers(markers); - if (!markers.isEmpty()) { - myRangeBlinker.startBlinking(); - } - } - - public void dispose() { - myRangeBlinker.stopBlinking(); - EditorFactory editorFactory = EditorFactory.getInstance(); - editorFactory.releaseEditor(myEditor); - } - - private void reinitViews() { - myEditor.reinitSettings(); - myEditor.getMarkupModel().removeAllHighlighters(); - } - - private static Editor createEditor(String text, int column, int line, int selectedLine) { - EditorFactory editorFactory = EditorFactory.getInstance(); - Document editorDocument = editorFactory.createDocument(text); - EditorEx editor = (EditorEx)editorFactory.createViewer(editorDocument); - EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); - editor.setColorsScheme(scheme); - EditorSettings settings = editor.getSettings(); - settings.setWhitespacesShown(true); - settings.setLineMarkerAreaShown(false); - settings.setIndentGuidesShown(false); - settings.setFoldingOutlineShown(false); - settings.setAdditionalColumnsCount(0); - settings.setAdditionalLinesCount(0); - settings.setRightMarginShown(true); - settings.setRightMargin(60); - - LogicalPosition pos = new LogicalPosition(line, column); - editor.getCaretModel().moveToLogicalPosition(pos); - if (selectedLine >= 0) { - editor.getSelectionModel().setSelection(editorDocument.getLineStartOffset(selectedLine), - editorDocument.getLineEndOffset(selectedLine)); - } - - return editor; - } } diff --git a/resources/src/postfixTemplates/AssertStatementPostfixTemplate/after.java.template b/resources/src/postfixTemplates/AssertStatementPostfixTemplate/after.java.template new file mode 100644 index 000000000000..a4b85def855b --- /dev/null +++ b/resources/src/postfixTemplates/AssertStatementPostfixTemplate/after.java.template @@ -0,0 +1,3 @@ +public void m(boolean value) { + assert value; +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/AssertStatementPostfixTemplate/before.java.template b/resources/src/postfixTemplates/AssertStatementPostfixTemplate/before.java.template new file mode 100644 index 000000000000..54970484a6de --- /dev/null +++ b/resources/src/postfixTemplates/AssertStatementPostfixTemplate/before.java.template @@ -0,0 +1,3 @@ +public void m(boolean value) { + value$key +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/AssertStatementPostfixTemplate/description.html b/resources/src/postfixTemplates/AssertStatementPostfixTemplate/description.html new file mode 100644 index 000000000000..2a472356ab71 --- /dev/null +++ b/resources/src/postfixTemplates/AssertStatementPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Creates assertion from boolean expression. + + diff --git a/resources/src/postfixTemplates/CastExpressionPostfixTemplate/after.java.template b/resources/src/postfixTemplates/CastExpressionPostfixTemplate/after.java.template new file mode 100644 index 000000000000..96281669cc1f --- /dev/null +++ b/resources/src/postfixTemplates/CastExpressionPostfixTemplate/after.java.template @@ -0,0 +1,5 @@ +public class Foo { + void m(Object o) { + (() o) + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/CastExpressionPostfixTemplate/before.java.template b/resources/src/postfixTemplates/CastExpressionPostfixTemplate/before.java.template new file mode 100644 index 000000000000..8a3222bc076b --- /dev/null +++ b/resources/src/postfixTemplates/CastExpressionPostfixTemplate/before.java.template @@ -0,0 +1,5 @@ +public class Foo { + void m(Object o) { + o$key + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/CastExpressionPostfixTemplate/description.html b/resources/src/postfixTemplates/CastExpressionPostfixTemplate/description.html new file mode 100644 index 000000000000..7d20d583eb16 --- /dev/null +++ b/resources/src/postfixTemplates/CastExpressionPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Surrounds expression with cast. + + diff --git a/resources/src/postfixTemplates/ElseStatementPostfixTemplate/after.java.template b/resources/src/postfixTemplates/ElseStatementPostfixTemplate/after.java.template new file mode 100644 index 000000000000..dafa3def9c30 --- /dev/null +++ b/resources/src/postfixTemplates/ElseStatementPostfixTemplate/after.java.template @@ -0,0 +1,7 @@ +public class Foo { + void m(boolean b) { + if (!b) { + + } + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/ElseStatementPostfixTemplate/before.java.template b/resources/src/postfixTemplates/ElseStatementPostfixTemplate/before.java.template new file mode 100644 index 000000000000..92452fe17c14 --- /dev/null +++ b/resources/src/postfixTemplates/ElseStatementPostfixTemplate/before.java.template @@ -0,0 +1,5 @@ +public class Foo { + void m(boolean b) { + b$key + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/ElseStatementPostfixTemplate/description.html b/resources/src/postfixTemplates/ElseStatementPostfixTemplate/description.html new file mode 100644 index 000000000000..862ad3ab3c55 --- /dev/null +++ b/resources/src/postfixTemplates/ElseStatementPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Checks boolean expression to be 'false'. + + diff --git a/resources/src/postfixTemplates/ForAscendingPostfixTemplate/after.java.template b/resources/src/postfixTemplates/ForAscendingPostfixTemplate/after.java.template new file mode 100644 index 000000000000..d4ecc14a155f --- /dev/null +++ b/resources/src/postfixTemplates/ForAscendingPostfixTemplate/after.java.template @@ -0,0 +1,8 @@ +public class Foo { + void m() { + int foo = 100; + for (int i = 0; i < foo; i++) { + + } + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/ForAscendingPostfixTemplate/before.java.template b/resources/src/postfixTemplates/ForAscendingPostfixTemplate/before.java.template new file mode 100644 index 000000000000..115be39a5f23 --- /dev/null +++ b/resources/src/postfixTemplates/ForAscendingPostfixTemplate/before.java.template @@ -0,0 +1,6 @@ +public class Foo { + void m() { + int foo = 100; + foo$key + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/ForAscendingPostfixTemplate/description.html b/resources/src/postfixTemplates/ForAscendingPostfixTemplate/description.html new file mode 100644 index 000000000000..6b6212f51fbd --- /dev/null +++ b/resources/src/postfixTemplates/ForAscendingPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Iterates with index over collection. + + diff --git a/resources/src/postfixTemplates/ForDescendingPostfixTemplate/after.java.template b/resources/src/postfixTemplates/ForDescendingPostfixTemplate/after.java.template new file mode 100644 index 000000000000..f96245290f3b --- /dev/null +++ b/resources/src/postfixTemplates/ForDescendingPostfixTemplate/after.java.template @@ -0,0 +1,8 @@ +public class Foo { + void m() { + int foo = 100; + for (int i = foo; i > 0; i--) { + + } + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/ForDescendingPostfixTemplate/before.java.template b/resources/src/postfixTemplates/ForDescendingPostfixTemplate/before.java.template new file mode 100644 index 000000000000..115be39a5f23 --- /dev/null +++ b/resources/src/postfixTemplates/ForDescendingPostfixTemplate/before.java.template @@ -0,0 +1,6 @@ +public class Foo { + void m() { + int foo = 100; + foo$key + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/ForDescendingPostfixTemplate/description.html b/resources/src/postfixTemplates/ForDescendingPostfixTemplate/description.html new file mode 100644 index 000000000000..22f6cbccd39d --- /dev/null +++ b/resources/src/postfixTemplates/ForDescendingPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Iterates with index in reverse order. + + diff --git a/resources/src/postfixTemplates/ForeachPostfixTemplate/after.java.template b/resources/src/postfixTemplates/ForeachPostfixTemplate/after.java.template new file mode 100644 index 000000000000..7425db77b63c --- /dev/null +++ b/resources/src/postfixTemplates/ForeachPostfixTemplate/after.java.template @@ -0,0 +1,8 @@ +public class Foo { + void m() { + int[] values = {1, 2, 3}; + for (int value : values) { + + } + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/ForeachPostfixTemplate/before.java.template b/resources/src/postfixTemplates/ForeachPostfixTemplate/before.java.template new file mode 100644 index 000000000000..702be307985f --- /dev/null +++ b/resources/src/postfixTemplates/ForeachPostfixTemplate/before.java.template @@ -0,0 +1,6 @@ +public class Foo { + void m() { + int[] values = {1, 2, 3}; + values$key + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/ForeachPostfixTemplate/description.html b/resources/src/postfixTemplates/ForeachPostfixTemplate/description.html new file mode 100644 index 000000000000..fc31a3ae8341 --- /dev/null +++ b/resources/src/postfixTemplates/ForeachPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Iterates over enumerable collection. + + diff --git a/resources/src/postfixTemplates/FormatPostfixTemplate/after.java.template b/resources/src/postfixTemplates/FormatPostfixTemplate/after.java.template new file mode 100644 index 000000000000..af86ed847c1f --- /dev/null +++ b/resources/src/postfixTemplates/FormatPostfixTemplate/after.java.template @@ -0,0 +1,3 @@ +public void m(String value) { + String.format(value, ); +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/FormatPostfixTemplate/before.java.template b/resources/src/postfixTemplates/FormatPostfixTemplate/before.java.template new file mode 100644 index 000000000000..d6196caec002 --- /dev/null +++ b/resources/src/postfixTemplates/FormatPostfixTemplate/before.java.template @@ -0,0 +1,6 @@ +public class Foo { + void m() { + int foo = 100; + foo.fori + } + } \ No newline at end of file diff --git a/resources/src/postfixTemplates/FormatPostfixTemplate/description.html b/resources/src/postfixTemplates/FormatPostfixTemplate/description.html new file mode 100644 index 000000000000..c62959a48280 --- /dev/null +++ b/resources/src/postfixTemplates/FormatPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Creates String.format call. + + diff --git a/resources/src/postfixTemplates/IfStatementPostfixTemplate/after.java.template b/resources/src/postfixTemplates/IfStatementPostfixTemplate/after.java.template new file mode 100644 index 000000000000..6f18db2dfcbe --- /dev/null +++ b/resources/src/postfixTemplates/IfStatementPostfixTemplate/after.java.template @@ -0,0 +1,7 @@ +public class Foo { + void m(boolean b) { + if (b) { + + } + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/IfStatementPostfixTemplate/before.java.template b/resources/src/postfixTemplates/IfStatementPostfixTemplate/before.java.template new file mode 100644 index 000000000000..92452fe17c14 --- /dev/null +++ b/resources/src/postfixTemplates/IfStatementPostfixTemplate/before.java.template @@ -0,0 +1,5 @@ +public class Foo { + void m(boolean b) { + b$key + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/IfStatementPostfixTemplate/description.html b/resources/src/postfixTemplates/IfStatementPostfixTemplate/description.html new file mode 100644 index 000000000000..28234e198291 --- /dev/null +++ b/resources/src/postfixTemplates/IfStatementPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Checks boolean expression to be 'true'. + + diff --git a/resources/src/postfixTemplates/InstanceofExpressionPostfixTemplate/after.java.template b/resources/src/postfixTemplates/InstanceofExpressionPostfixTemplate/after.java.template new file mode 100644 index 000000000000..61d87d250695 --- /dev/null +++ b/resources/src/postfixTemplates/InstanceofExpressionPostfixTemplate/after.java.template @@ -0,0 +1,5 @@ +public class Foo { + void m(Object o) { + o instanceof ? (() o) : null; + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/InstanceofExpressionPostfixTemplate/before.java.template b/resources/src/postfixTemplates/InstanceofExpressionPostfixTemplate/before.java.template new file mode 100644 index 000000000000..02d34d8b34a1 --- /dev/null +++ b/resources/src/postfixTemplates/InstanceofExpressionPostfixTemplate/before.java.template @@ -0,0 +1,5 @@ +public class Foo { + void m(Object o) { + o$key + } +} diff --git a/resources/src/postfixTemplates/InstanceofExpressionPostfixTemplate/description.html b/resources/src/postfixTemplates/InstanceofExpressionPostfixTemplate/description.html new file mode 100644 index 000000000000..249f7daac259 --- /dev/null +++ b/resources/src/postfixTemplates/InstanceofExpressionPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Surrounds expression with instanceof. + + diff --git a/resources/src/postfixTemplates/IntroduceFieldPostfixTemplate/after.java.template b/resources/src/postfixTemplates/IntroduceFieldPostfixTemplate/after.java.template new file mode 100644 index 000000000000..7ef89f986aac --- /dev/null +++ b/resources/src/postfixTemplates/IntroduceFieldPostfixTemplate/after.java.template @@ -0,0 +1,7 @@ +public class Foo { + private int foo; + + public Foo(int arg) { + foo = arg; + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/IntroduceFieldPostfixTemplate/before.java.template b/resources/src/postfixTemplates/IntroduceFieldPostfixTemplate/before.java.template new file mode 100644 index 000000000000..cf7732872da6 --- /dev/null +++ b/resources/src/postfixTemplates/IntroduceFieldPostfixTemplate/before.java.template @@ -0,0 +1,5 @@ +public class Foo { + public Foo(int arg) { + arg$key + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/IntroduceFieldPostfixTemplate/description.html b/resources/src/postfixTemplates/IntroduceFieldPostfixTemplate/description.html new file mode 100644 index 000000000000..4f20d5109618 --- /dev/null +++ b/resources/src/postfixTemplates/IntroduceFieldPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Introduces field for expression. + + diff --git a/resources/src/postfixTemplates/IntroduceVariablePostfixTemplate/after.java.template b/resources/src/postfixTemplates/IntroduceVariablePostfixTemplate/after.java.template new file mode 100644 index 000000000000..6e23f45dce05 --- /dev/null +++ b/resources/src/postfixTemplates/IntroduceVariablePostfixTemplate/after.java.template @@ -0,0 +1,5 @@ +public class Foo { + void m(Object o) { + boolean foo = o instanceof String; + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/IntroduceVariablePostfixTemplate/before.java.template b/resources/src/postfixTemplates/IntroduceVariablePostfixTemplate/before.java.template new file mode 100644 index 000000000000..b2c2925d1581 --- /dev/null +++ b/resources/src/postfixTemplates/IntroduceVariablePostfixTemplate/before.java.template @@ -0,0 +1,5 @@ +public class Foo { + void m(Object o) { + o instanceof String$key + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/IntroduceVariablePostfixTemplate/description.html b/resources/src/postfixTemplates/IntroduceVariablePostfixTemplate/description.html new file mode 100644 index 000000000000..2024a122609d --- /dev/null +++ b/resources/src/postfixTemplates/IntroduceVariablePostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Introduces variable for expression. + + diff --git a/resources/src/postfixTemplates/IsNullCheckPostfixTemplate/after.java.template b/resources/src/postfixTemplates/IsNullCheckPostfixTemplate/after.java.template new file mode 100644 index 000000000000..1c7879a93145 --- /dev/null +++ b/resources/src/postfixTemplates/IsNullCheckPostfixTemplate/after.java.template @@ -0,0 +1,7 @@ +public class Foo { + void m(Object o) { + if (o == null){ + + } + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/IsNullCheckPostfixTemplate/before.java.template b/resources/src/postfixTemplates/IsNullCheckPostfixTemplate/before.java.template new file mode 100644 index 000000000000..8a3222bc076b --- /dev/null +++ b/resources/src/postfixTemplates/IsNullCheckPostfixTemplate/before.java.template @@ -0,0 +1,5 @@ +public class Foo { + void m(Object o) { + o$key + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/IsNullCheckPostfixTemplate/description.html b/resources/src/postfixTemplates/IsNullCheckPostfixTemplate/description.html new file mode 100644 index 000000000000..eb854ae563ad --- /dev/null +++ b/resources/src/postfixTemplates/IsNullCheckPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Checks expression to be null. + + diff --git a/resources/src/postfixTemplates/NotExpressionPostfixTemplate/after.java.template b/resources/src/postfixTemplates/NotExpressionPostfixTemplate/after.java.template new file mode 100644 index 000000000000..c062ee94d410 --- /dev/null +++ b/resources/src/postfixTemplates/NotExpressionPostfixTemplate/after.java.template @@ -0,0 +1,5 @@ +public class Foo { + void m(boolean b) { + m(!b); + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/NotExpressionPostfixTemplate/before.java.template b/resources/src/postfixTemplates/NotExpressionPostfixTemplate/before.java.template new file mode 100644 index 000000000000..fcbac10b541a --- /dev/null +++ b/resources/src/postfixTemplates/NotExpressionPostfixTemplate/before.java.template @@ -0,0 +1,5 @@ +public class Foo { + void m(boolean b) { + m(b$key); + } + } \ No newline at end of file diff --git a/resources/src/postfixTemplates/NotExpressionPostfixTemplate/description.html b/resources/src/postfixTemplates/NotExpressionPostfixTemplate/description.html new file mode 100644 index 000000000000..533a7601fe8f --- /dev/null +++ b/resources/src/postfixTemplates/NotExpressionPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Negates boolean expression. + + diff --git a/resources/src/postfixTemplates/NotNullCheckPostfixTemplate/after.java.template b/resources/src/postfixTemplates/NotNullCheckPostfixTemplate/after.java.template new file mode 100644 index 000000000000..40a5e8c2ec6d --- /dev/null +++ b/resources/src/postfixTemplates/NotNullCheckPostfixTemplate/after.java.template @@ -0,0 +1,7 @@ +public class Foo { + void m(Object o) { + if (o != null){ + + } + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/NotNullCheckPostfixTemplate/before.java.template b/resources/src/postfixTemplates/NotNullCheckPostfixTemplate/before.java.template new file mode 100644 index 000000000000..8a3222bc076b --- /dev/null +++ b/resources/src/postfixTemplates/NotNullCheckPostfixTemplate/before.java.template @@ -0,0 +1,5 @@ +public class Foo { + void m(Object o) { + o$key + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/NotNullCheckPostfixTemplate/description.html b/resources/src/postfixTemplates/NotNullCheckPostfixTemplate/description.html new file mode 100644 index 000000000000..65a10f3669bd --- /dev/null +++ b/resources/src/postfixTemplates/NotNullCheckPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Checks expression to be not-null. + + diff --git a/resources/src/postfixTemplates/ParenthesizedExpressionPostfixTemplate/after.java.template b/resources/src/postfixTemplates/ParenthesizedExpressionPostfixTemplate/after.java.template new file mode 100644 index 000000000000..2d29ebb18252 --- /dev/null +++ b/resources/src/postfixTemplates/ParenthesizedExpressionPostfixTemplate/after.java.template @@ -0,0 +1,5 @@ +public class Foo { + void m(Object o) { + (o) + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/ParenthesizedExpressionPostfixTemplate/before.java.template b/resources/src/postfixTemplates/ParenthesizedExpressionPostfixTemplate/before.java.template new file mode 100644 index 000000000000..8a3222bc076b --- /dev/null +++ b/resources/src/postfixTemplates/ParenthesizedExpressionPostfixTemplate/before.java.template @@ -0,0 +1,5 @@ +public class Foo { + void m(Object o) { + o$key + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/ParenthesizedExpressionPostfixTemplate/description.html b/resources/src/postfixTemplates/ParenthesizedExpressionPostfixTemplate/description.html new file mode 100644 index 000000000000..f3effd96dd97 --- /dev/null +++ b/resources/src/postfixTemplates/ParenthesizedExpressionPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Parenthesizes expression. + + diff --git a/resources/src/postfixTemplates/ReturnStatementPostfixTemplate/after.java.template b/resources/src/postfixTemplates/ReturnStatementPostfixTemplate/after.java.template new file mode 100644 index 000000000000..a4e60b342497 --- /dev/null +++ b/resources/src/postfixTemplates/ReturnStatementPostfixTemplate/after.java.template @@ -0,0 +1,5 @@ +public class Foo { + String m() { + return "result"; + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/ReturnStatementPostfixTemplate/before.java.template b/resources/src/postfixTemplates/ReturnStatementPostfixTemplate/before.java.template new file mode 100644 index 000000000000..cdbeed6545e7 --- /dev/null +++ b/resources/src/postfixTemplates/ReturnStatementPostfixTemplate/before.java.template @@ -0,0 +1,5 @@ +public class Foo { + String m() { + "result"$key + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/ReturnStatementPostfixTemplate/description.html b/resources/src/postfixTemplates/ReturnStatementPostfixTemplate/description.html new file mode 100644 index 000000000000..4efea2894c04 --- /dev/null +++ b/resources/src/postfixTemplates/ReturnStatementPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Returns value from containing method. + + diff --git a/resources/src/postfixTemplates/SoutPostfixTemplate/after.java.template b/resources/src/postfixTemplates/SoutPostfixTemplate/after.java.template new file mode 100644 index 000000000000..ce506f8aa3c6 --- /dev/null +++ b/resources/src/postfixTemplates/SoutPostfixTemplate/after.java.template @@ -0,0 +1,5 @@ +public class Foo { + void m(boolean b) { + System.out.println(b); + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/SoutPostfixTemplate/before.java.template b/resources/src/postfixTemplates/SoutPostfixTemplate/before.java.template new file mode 100644 index 000000000000..4ee356d8a508 --- /dev/null +++ b/resources/src/postfixTemplates/SoutPostfixTemplate/before.java.template @@ -0,0 +1,5 @@ +public class Foo { + void m(boolean b) { + b$key + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/SoutPostfixTemplate/description.html b/resources/src/postfixTemplates/SoutPostfixTemplate/description.html new file mode 100644 index 000000000000..02dacc2cb7a9 --- /dev/null +++ b/resources/src/postfixTemplates/SoutPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Creates System.out.println call. + + diff --git a/resources/src/postfixTemplates/SwitchStatementPostfixTemplate/after.java.template b/resources/src/postfixTemplates/SwitchStatementPostfixTemplate/after.java.template new file mode 100644 index 000000000000..6ce35d4847e7 --- /dev/null +++ b/resources/src/postfixTemplates/SwitchStatementPostfixTemplate/after.java.template @@ -0,0 +1,9 @@ +public enum Foo { + A, B, C; + + void f(Foo foo) { + switch (foo) { + + } + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/SwitchStatementPostfixTemplate/before.java.template b/resources/src/postfixTemplates/SwitchStatementPostfixTemplate/before.java.template new file mode 100644 index 000000000000..6fa2d087c75c --- /dev/null +++ b/resources/src/postfixTemplates/SwitchStatementPostfixTemplate/before.java.template @@ -0,0 +1,7 @@ +public enum Foo { + A, B, C; + + void f(Foo foo) { + foo$key + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/SwitchStatementPostfixTemplate/description.html b/resources/src/postfixTemplates/SwitchStatementPostfixTemplate/description.html new file mode 100644 index 000000000000..e1e63da8325c --- /dev/null +++ b/resources/src/postfixTemplates/SwitchStatementPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Produces switch over integral/enum/string values. + + diff --git a/resources/src/postfixTemplates/SynchronizedStatementPostfixTemplate/after.java.template b/resources/src/postfixTemplates/SynchronizedStatementPostfixTemplate/after.java.template new file mode 100644 index 000000000000..565f507c4f64 --- /dev/null +++ b/resources/src/postfixTemplates/SynchronizedStatementPostfixTemplate/after.java.template @@ -0,0 +1,7 @@ +public class Foo { + void m(Object o) { + synchronized (o) { + + } + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/SynchronizedStatementPostfixTemplate/before.java.template b/resources/src/postfixTemplates/SynchronizedStatementPostfixTemplate/before.java.template new file mode 100644 index 000000000000..8a3222bc076b --- /dev/null +++ b/resources/src/postfixTemplates/SynchronizedStatementPostfixTemplate/before.java.template @@ -0,0 +1,5 @@ +public class Foo { + void m(Object o) { + o$key + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/SynchronizedStatementPostfixTemplate/description.html b/resources/src/postfixTemplates/SynchronizedStatementPostfixTemplate/description.html new file mode 100644 index 000000000000..1589a80dcd4d --- /dev/null +++ b/resources/src/postfixTemplates/SynchronizedStatementPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Produces synchronization statement. + + diff --git a/resources/src/postfixTemplates/ThrowExceptionPostfixTemplate/after.java.template b/resources/src/postfixTemplates/ThrowExceptionPostfixTemplate/after.java.template new file mode 100644 index 000000000000..7d102b4924cd --- /dev/null +++ b/resources/src/postfixTemplates/ThrowExceptionPostfixTemplate/after.java.template @@ -0,0 +1,5 @@ +public class Foo { + void m() { + throw new RuntimeException("error"); + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/ThrowExceptionPostfixTemplate/before.java.template b/resources/src/postfixTemplates/ThrowExceptionPostfixTemplate/before.java.template new file mode 100644 index 000000000000..80663ec0ed7b --- /dev/null +++ b/resources/src/postfixTemplates/ThrowExceptionPostfixTemplate/before.java.template @@ -0,0 +1,5 @@ +public class Foo { + void m() { + new RuntimeException("error")$key + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/ThrowExceptionPostfixTemplate/description.html b/resources/src/postfixTemplates/ThrowExceptionPostfixTemplate/description.html new file mode 100644 index 000000000000..d81b2d78ae7d --- /dev/null +++ b/resources/src/postfixTemplates/ThrowExceptionPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Throws expression of 'Throwable' type. + + diff --git a/resources/src/postfixTemplates/TryStatementPostfixTemplate/after.java.template b/resources/src/postfixTemplates/TryStatementPostfixTemplate/after.java.template new file mode 100644 index 000000000000..08c481ba84f5 --- /dev/null +++ b/resources/src/postfixTemplates/TryStatementPostfixTemplate/after.java.template @@ -0,0 +1,9 @@ +public void m2() { + try { + m(); + } catch(CheckedException e) { + e.printStackTrace(); + } +} + +public void m() throws CheckedException { } \ No newline at end of file diff --git a/resources/src/postfixTemplates/TryStatementPostfixTemplate/before.java.template b/resources/src/postfixTemplates/TryStatementPostfixTemplate/before.java.template new file mode 100644 index 000000000000..a67a6a667100 --- /dev/null +++ b/resources/src/postfixTemplates/TryStatementPostfixTemplate/before.java.template @@ -0,0 +1,5 @@ +public void m2() { + m().try +} + +public void m() throws CheckedException { } \ No newline at end of file diff --git a/resources/src/postfixTemplates/TryStatementPostfixTemplate/description.html b/resources/src/postfixTemplates/TryStatementPostfixTemplate/description.html new file mode 100644 index 000000000000..582e5dd9681f --- /dev/null +++ b/resources/src/postfixTemplates/TryStatementPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Insert statement in try-catch block. + + diff --git a/resources/src/postfixTemplates/TryWithResourcesPostfixTemplate/after.java.template b/resources/src/postfixTemplates/TryWithResourcesPostfixTemplate/after.java.template new file mode 100644 index 000000000000..a6afe88de388 --- /dev/null +++ b/resources/src/postfixTemplates/TryWithResourcesPostfixTemplate/after.java.template @@ -0,0 +1,13 @@ +public class Foo { + void m() { + try (AutoCloseable stream = getStream()) { + + } catch (Exception e) { + } + } + + AutoCloseable getStream() + { + return null; + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/TryWithResourcesPostfixTemplate/before.java.template b/resources/src/postfixTemplates/TryWithResourcesPostfixTemplate/before.java.template new file mode 100644 index 000000000000..259e5c823fad --- /dev/null +++ b/resources/src/postfixTemplates/TryWithResourcesPostfixTemplate/before.java.template @@ -0,0 +1,10 @@ +public class Foo { + void m() { + getStream()$key + } + + AutoCloseable getStream() + { + return null; + } +} \ No newline at end of file diff --git a/resources/src/postfixTemplates/TryWithResourcesPostfixTemplate/description.html b/resources/src/postfixTemplates/TryWithResourcesPostfixTemplate/description.html new file mode 100644 index 000000000000..50ed7fde3aa1 --- /dev/null +++ b/resources/src/postfixTemplates/TryWithResourcesPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Insert statement in try-with-resources block. + + diff --git a/resources/src/postfixTemplates/WhileStatementPostfixTemplate/after.java.template b/resources/src/postfixTemplates/WhileStatementPostfixTemplate/after.java.template new file mode 100644 index 000000000000..408080e0f358 --- /dev/null +++ b/resources/src/postfixTemplates/WhileStatementPostfixTemplate/after.java.template @@ -0,0 +1,6 @@ +public class Foo { + void m(boolean x) { + while (x) + return; + } +} diff --git a/resources/src/postfixTemplates/WhileStatementPostfixTemplate/before.java.template b/resources/src/postfixTemplates/WhileStatementPostfixTemplate/before.java.template new file mode 100644 index 000000000000..41046af6dcb4 --- /dev/null +++ b/resources/src/postfixTemplates/WhileStatementPostfixTemplate/before.java.template @@ -0,0 +1,6 @@ +public class Foo { + void m(boolean x) { + x$key + return; + } +} diff --git a/resources/src/postfixTemplates/WhileStatementPostfixTemplate/description.html b/resources/src/postfixTemplates/WhileStatementPostfixTemplate/description.html new file mode 100644 index 000000000000..daf90248cd28 --- /dev/null +++ b/resources/src/postfixTemplates/WhileStatementPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Iterating while boolean statement is 'true'. + +