Skip to content

Commit

Permalink
underscores can be used in template names
Browse files Browse the repository at this point in the history
  • Loading branch information
xylo committed Oct 21, 2018
1 parent 67737fc commit 0bbd314
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 60 deletions.
5 changes: 5 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions resources/META-INF/plugin.xml
@@ -1,7 +1,7 @@
<idea-plugin>
<id>de.endrullis.idea.postfixtemplates</id>
<name>Custom Postfix Templates</name>
<version>2.6.2.183</version>
<version>2.6.3.183</version>
<vendor email="stefan@endrullis.de" url="https://github.com/xylo/intellij-postfix-templates">Stefan Endrullis</vendor>
<category>code editing</category>

Expand All @@ -13,20 +13,21 @@
<p>
This plugin lets you define your own postfix templates for Java, Scala, SQL, PHP, Kotlin, Python, Dart, JavaScript, Rust, and Groovy.
It also comes with hundreds of useful postfix templates shared by the community. You're welcome to contribute your templates as well.
</p>
<p>
<i>So what is the difference to IDEA's postfix templates?</i>
<i>Apart from the community approach, how does the plugin differ from IDEA's postfix templates?</i>
</p>
<p>
Since IDEA 2018 you are now able to define your own postfix templates in the settings UI (<i>Editor → General → Postfix Templates</i>).
Since IDEA 2018 you are now able to define your own postfix templates for some languages in the settings UI (<i>Editor → General → Postfix Templates</i>).
However, this is a pretty new feature and it's less functional than this plugin.
Here are some of the advantages of this plugin:
<ul>
<li>You can define different template rules for the same template name, e.g. <code>.toList</code> should behave differently for arrays and for sets.</li>
<li>You can use template variables (e.g. <code>$varName$</code>) which are filled by the user while applying the template.</li>
<li>You can define different template rules (context based) for the same template name, e.g. <code>.toList</code> should behave differently for arrays and for sets.</li>
<li>You can use template variables (e.g. <code>$varName$</code>) which are filled in by the user while applying the template.</li>
<li>You can use live template macros to automatically fill some of the template variables (e.g. <code>$var:suggestVariableName()$</code>) as well as you can define default values.</li>
<li>You can restrict the availability of templates or template rules to the availability of certain classes or libraries (e.g. expand <code>"test".val</code> to <code>val s = "test"</code> if Lombok is available).</li>
<li>It allows you to use static imports instead of class imports (e.g. <code>array.toList</code> can be expanded to <code>asList(array)</code> instead of <code>Arrays.asList(array)</code> if you add <code>[USE_STATIC_IMPORTS]</code> to the rule).</li>
Expand All @@ -38,13 +39,18 @@
<li>file.getName().val → final String name = file.getName();</li>
</ul>
</li>
<li>The text based format for defining your templates allows you to easily share them via copy and paste.</li>
<li>There are multiple ways to easily <a href="https://github.com/xylo/intellij-postfix-templates/wiki/Share-a-template-file-with-others">share your templates with others</a>.</li>
</ul>
</p>
]]>
</description>

<change-notes><![CDATA[
<h3>Version 2.6.3</h3>
<ul>
<li>Underscores can be used in template names.</li>
</ul>
<h3>Version 2.6.2</h3>
<ul>
<li>Fixed bug #85: NoClassDefFoundError: com/intellij/psi/PsiType in PHPStorm and PyCharm.</li>
Expand Down
2 changes: 1 addition & 1 deletion src/de/endrullis/idea/postfixtemplates/language/Cpt.flex
Expand Up @@ -25,7 +25,7 @@ DOT=[.]
BRACKET_OPEN=\[
BRACKET_CLOSE=\]
MAP=("->"|"→")
NAME_CHAR=[a-zA-Z0-9]
NAME_CHAR=[a-zA-Z0-9_]
CLASS_NAME_CHAR=[a-zA-Z0-9._]
TEMPLATE_VARIABLE_START_CHAR=[$]
TEMPLATE_VARIABLE_CHAR=[^$\r\n\f\t\\:]
Expand Down
86 changes: 43 additions & 43 deletions src/de/endrullis/idea/postfixtemplates/language/CptLexer.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 13 additions & 7 deletions src/de/endrullis/idea/postfixtemplates/language/CptUtil.java
Expand Up @@ -123,7 +123,12 @@ public static List<CptMapping> findMappings(Project project) {
*/
public static String getDefaultTemplates(String language) {
InputStream stream = CptUtil.class.getResourceAsStream("defaulttemplates/" + language + ".postfixTemplates");
return getContent(stream);
try {
return getContent(stream);
} catch (IOException e) {
e.printStackTrace();
return "";
}
}

/**
Expand All @@ -134,7 +139,12 @@ public static String getDefaultTemplates(String language) {
* @throws FileNotFoundException
*/
public static String getContent(@NotNull File file) throws FileNotFoundException {
return getContent(new FileInputStream(file));
try {
return getContent(new FileInputStream(file));
} catch (IOException e) {
e.printStackTrace();
return "";
}
}

/**
Expand All @@ -143,7 +153,7 @@ public static String getContent(@NotNull File file) throws FileNotFoundException
* @param stream input stream
* @return content of the given input stream
*/
private static String getContent(@NotNull InputStream stream) {
private static String getContent(@NotNull InputStream stream) throws IOException {
StringBuilder sb = new StringBuilder();

// convert system newlines into UNIX newlines, because IDEA works only with UNIX newlines
Expand All @@ -154,11 +164,7 @@ private static String getContent(@NotNull InputStream stream) {
}

return sb.toString();
} catch (IOException e) {
e.printStackTrace();
}

return "";
}

/**
Expand Down

0 comments on commit 0bbd314

Please sign in to comment.