Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 68 additions & 67 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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;
}

}
6 changes: 6 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
serviceImplementation="com.github.rogerhowell.javaparser_ast_inspector.plugin.services.impl.JavaParserServiceImpl"/>
<projectService serviceInterface="com.github.rogerhowell.javaparser_ast_inspector.plugin.services.PrinterService"
serviceImplementation="com.github.rogerhowell.javaparser_ast_inspector.plugin.services.impl.PrinterServiceImpl"/>


<!-- Code completion -->
<defaultLiveTemplates file="/liveTemplates/JavaParser.xml"/>
<liveTemplateContext implementation="com.github.rogerhowell.javaparser_ast_inspector.plugin.live_templates.JavaParserContext"/>

</extensions>

<actions>
Expand Down
16 changes: 16 additions & 0 deletions src/main/resources/liveTemplates/JavaParser.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<templateSet group="Java/JavaParser">
<template name="parseString"
value="java.lang.String inputToParse = &quot;$INPUT_TO_BE_PARSED$&quot;;&#10;com.github.javaparser.JavaParser javaParser = new com.github.javaparser.JavaParser();&#10;com.github.javaparser.ParseResult&lt;$NODE_TYPE$&gt; parseResult = javaParser.$PARSE_METHOD$(inputToParse);&#10;if (parseResult.isSuccessful()) {&#10; if (parseResult.getResult().isPresent()) {&#10; $NODE_TYPE$ $NODE_TYPE_VAR_NAME$ = parseResult.getResult().get();&#10; // Do things with the compilation unit&#10; $END$&#10; } else {&#10; System.out.println(&quot;Warning: Parsing was successful, but no $NODE_TYPE$ found. &quot;);&#10; }&#10;} else {&#10; System.out.println(&quot;Warning: Parse was unsuccessful. Attempts to inspect/alter the AST may be possible, but may lead to unintended outputs.&quot;);&#10; if (parseResult.getResult().isPresent()) {&#10; $NODE_TYPE$ $NODE_TYPE_VAR_NAME$WithParseError = parseResult.getResult().get();&#10; // Do things with the compilation unit (with parse error)&#10; &#10; } else {&#10; System.out.println(&quot;Warning: Parsing was successful, but no $NODE_TYPE$ found. &quot;);&#10; }&#10;}"
description="Setup JavaParser to parse raw String input"
toReformat="true"
toShortenFQNames="true">
<variable name="INPUT_TO_BE_PARSED" expression="" defaultValue="&quot;class X {}&quot;" alwaysStopAt="true" />
<variable name="NODE_TYPE" expression="subTypes(&quot;com.github.javaparser.ast.Node&quot;)" defaultValue="&quot;com.github.javaparser.ast.CompilationUnit&quot;" alwaysStopAt="true" />
<variable name="PARSE_METHOD" expression="completeSmart()" defaultValue="&quot;parse&quot;" alwaysStopAt="true" />
<variable name="NODE_TYPE_VAR_NAME" expression="suggestVariableName()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
<option name="JAVAPARSER" value="true" />
</context>
</template>
</templateSet>