diff --git a/CHANGELOG.md b/CHANGELOG.md index a18c515..f32fcac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,67 +1,68 @@ -# Changelog - -## [Unreleased] -### Added - -### Changed - -### Deprecated - -### Removed - -### Fixed - -### Security - -## [0.5.2] -### Changed -- Bumped `pluginUntilBuild` to allow for 2021.3 -- Upgraded to using JavaParser v3.24.0 -- Update the project with recent template project changes (workflow tweaks, added qodana, keeping detekt (for now)) -- Multiple other dependency updates - -## [0.5.1] -### Changed -- Builds now require JDK11 minimum, per IntelliJ Plugin requirement -- Upgraded to using JavaParser v3.23.0 -- Multiple other dependency updates - -## [0.5.0] -### Added -- Detection of the IntelliJ's project language level, and default to that within the AST Inspector - -### Changed -- Upgraded to using JavaParser v3.22.1 -- Upgraded multiple dependencies -- Made the plugin `dumbAware`, enabling it to be used while the project is being indexed -- The exporters now use the system's newline, rather than `\n` - -### Fixed -- Exporters now respect the `include new line` configuration option - -## [0.4.5] -### Changed -- Upgraded to using JavaParser v3.20.2 -- Upgraded many other dependencies too -- Upgraded compatibility with recent intellij builds - -## [0.4.4] -### Changed -- Upgraded to using JavaParser v3.16.2 -- Upgraded multiple dependencies -- Upgraded compatibility with recent intellij builds -- Switched to kotlin DSL for builds - -## [0.4.3] -### Changed -- Upgraded to using JavaParser v3.15.21 - -## [0.4.2] -### Added -- Initial submitted release of the plugin to the Jetbrains plugin repo, using JavaParser v3.15.18 -- Parsing via the plugin UI is feature complete, with analysis/generation/symbol resolution to come in future versions. -- Key highlights: - - Display of the AST produced, which can be explored (clicking on an item in the AST will highlight the relevant section of source code) - - Display of the parsed tokens - - Exporting of alternative representations of the AST (including as YAML, DOT, XML, Cypher, and others) - - Being able to view a log of parse attempts (including any errors, and the configuration used in the parse) +# Changelog + +## [Unreleased] +### Added +- Now includes a "live template" which inserts the JavaParser boilerplate (type `parseString` then `TAB` within a Java file) + +### Changed + +### Deprecated + +### Removed + +### Fixed + +### Security + +## [0.5.2] +### Changed +- Bumped `pluginUntilBuild` to allow for 2021.3 +- Upgraded to using JavaParser v3.24.0 +- Update the project with recent template project changes (workflow tweaks, added qodana, keeping detekt (for now)) +- Multiple other dependency updates + +## [0.5.1] +### Changed +- Builds now require JDK11 minimum, per IntelliJ Plugin requirement +- Upgraded to using JavaParser v3.23.0 +- Multiple other dependency updates + +## [0.5.0] +### Added +- Detection of the IntelliJ's project language level, and default to that within the AST Inspector + +### Changed +- Upgraded to using JavaParser v3.22.1 +- Upgraded multiple dependencies +- Made the plugin `dumbAware`, enabling it to be used while the project is being indexed +- The exporters now use the system's newline, rather than `\n` + +### Fixed +- Exporters now respect the `include new line` configuration option + +## [0.4.5] +### Changed +- Upgraded to using JavaParser v3.20.2 +- Upgraded many other dependencies too +- Upgraded compatibility with recent intellij builds + +## [0.4.4] +### Changed +- Upgraded to using JavaParser v3.16.2 +- Upgraded multiple dependencies +- Upgraded compatibility with recent intellij builds +- Switched to kotlin DSL for builds + +## [0.4.3] +### Changed +- Upgraded to using JavaParser v3.15.21 + +## [0.4.2] +### Added +- Initial submitted release of the plugin to the Jetbrains plugin repo, using JavaParser v3.15.18 +- Parsing via the plugin UI is feature complete, with analysis/generation/symbol resolution to come in future versions. +- Key highlights: + - Display of the AST produced, which can be explored (clicking on an item in the AST will highlight the relevant section of source code) + - Display of the parsed tokens + - Exporting of alternative representations of the AST (including as YAML, DOT, XML, Cypher, and others) + - Being able to view a log of parse attempts (including any errors, and the configuration used in the parse) diff --git a/src/main/java/com/github/rogerhowell/javaparser_ast_inspector/plugin/live_templates/JavaParserContext.java b/src/main/java/com/github/rogerhowell/javaparser_ast_inspector/plugin/live_templates/JavaParserContext.java new file mode 100644 index 0000000..980eb95 --- /dev/null +++ b/src/main/java/com/github/rogerhowell/javaparser_ast_inspector/plugin/live_templates/JavaParserContext.java @@ -0,0 +1,56 @@ +package com.github.rogerhowell.javaparser_ast_inspector.plugin.live_templates; + +import com.github.javaparser.JavaParser; +import com.github.javaparser.ParseResult; +import com.github.javaparser.ast.CompilationUnit; +import com.intellij.codeInsight.template.TemplateActionContext; +import com.intellij.codeInsight.template.TemplateContextType; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiImportStatementBase; +import com.intellij.psi.PsiJavaCodeReferenceElement; +import com.intellij.psi.PsiJavaFile; +import org.jetbrains.annotations.NotNull; + +public class JavaParserContext extends TemplateContextType { + + protected JavaParserContext() { + super("JAVAPARSER", "JavaParser"); + } + + + @Override + public boolean isInContext(@NotNull TemplateActionContext templateActionContext) { + PsiFile psiFile = templateActionContext.getFile(); + + if (!psiFile.getName().endsWith(".java")) { + // Only consider Java files +// System.err.println("JAVAPARSER (live template context) -- Not a file ending in .java"); + return false; + } + + if (!(psiFile.getContainingFile() instanceof PsiJavaFile)) { + // Only consider Java files +// System.err.println("JAVAPARSER (live template context) -- Not a PsiJavaFile"); + return false; + } + +// System.out.println("JAVAPARSER (live template context) -- valid context found"); + + return true; + +// /* THE FILTERING BELOW WORKS, BUT I'M DISABLING */ +// PsiJavaFile psiJavaFile = (PsiJavaFile) psiFile; +// for (final PsiImportStatementBase importStatement : psiJavaFile.getImportList().getAllImportStatements()) { +// PsiJavaCodeReferenceElement importReference = importStatement.getImportReference(); +// +// boolean isInJavaParserNamespace = importReference.getQualifiedName().startsWith("com.github.javaparser."); +// if (isInJavaParserNamespace) { +// return true; +// } +// } +// +// // If no matches, assume none of them are JavaParser, thus we are not in context. +// return false; + } + +} \ No newline at end of file diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 2d8cd1e..fdc423f 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -33,6 +33,12 @@ serviceImplementation="com.github.rogerhowell.javaparser_ast_inspector.plugin.services.impl.JavaParserServiceImpl"/> + + + + + + diff --git a/src/main/resources/liveTemplates/JavaParser.xml b/src/main/resources/liveTemplates/JavaParser.xml new file mode 100644 index 0000000..6a90852 --- /dev/null +++ b/src/main/resources/liveTemplates/JavaParser.xml @@ -0,0 +1,16 @@ + + + \ No newline at end of file