diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 57ffca35..81cae9df 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -15,15 +15,11 @@ jobs: env: # see https://www.jetbrains.com/idea/download/previous.html # and https://www.jetbrains.com/intellij-repository/snapshots/ - - IDEA_VERSION: IC-2018.3.6 - - IDEA_VERSION: IC-2019.1.4 - - IDEA_VERSION: IC-2019.2.4 - - IDEA_VERSION: IC-2019.3.3 - IDEA_VERSION: IC-2020.1 - IDEA_VERSION: IC-2020.2 - IDEA_VERSION: IC-2020.3 - IDEA_VERSION: IC-2021.2.4 - - IDEA_VERSION: IC-2021.3 + - IDEA_VERSION: IC-2021.3.3 - IDEA_VERSION: IU-LATEST-EAP-SNAPSHOT steps: diff --git a/README.md b/README.md index f77b3d47..01e2013b 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # IntelliJ Idea Plugin for ANTLR v4 ![Java CI](https://github.com/antlr/intellij-plugin-v4/workflows/Java%20CI/badge.svg?branch=master) [![Latest version](https://img.shields.io/jetbrains/plugin/v/7358.svg?label=latest%20version)](https://plugins.jetbrains.com/plugin/7358) ![Downloads](https://img.shields.io/jetbrains/plugin/d/7358.svg) -An [IntelliJ](https://www.jetbrains.com/idea/) 2018.3 .. 2021.x plugin for ANTLR v4 ([plugin source at github](https://github.com/antlr/intellij-plugin-v4)). +An [IntelliJ](https://www.jetbrains.com/idea/) 2020.3+ plugin for ANTLR v4 ([plugin source at github](https://github.com/antlr/intellij-plugin-v4)). (Technically, the plugin will load in 2019.2+ but you might not have much luck earlier than 2020.3) [Plugin page at intellij](http://plugins.jetbrains.com/plugin/7358?pr=idea) -This plugin is for ANTLR v4 grammars and includes ANTLR 4.9.1. Works with IntelliJ IDEA and other IntelliJ-based IDEs. +This plugin is for ANTLR v4 grammars and includes ANTLR 4.10. Works with IntelliJ IDEA and other IntelliJ-based IDEs. ## Features: @@ -131,7 +131,7 @@ If you see ambiguities highlighted, those you should definitely take a look consistent with the speed of a generated and compiled parser but it does use single-stage full LL parsing which can be slower. It needs to do that so that it gets full and complete profiling information. For those in the know, - it uses PredictionMode.LL_EXACT_AMBIG_DETECTION. For really big files and + it uses `PredictionMode.LL_EXACT_AMBIG_DETECTION`. For really big files and slow grammars, there is an appreciable delay when displaying the parse tree or profiling information. ![parse-region.png](images/profiler.png) @@ -173,7 +173,7 @@ Even when a grammar is getting a single interpretation of the input, we often wo # Contributing -We [moved to Gradle](https://github.com/antlr/intellij-plugin-v4/pull/295) for 1.9. To contribute to the project, +We [use Gradle](https://github.com/antlr/intellij-plugin-v4/pull/295) to build. To contribute to the project, you need a recent version of IntelliJ IDEA (either Community or Ultimate) with the `Gradle` and `Plugin DevKit` plugins enabled. @@ -189,6 +189,21 @@ To launch unit tests, run `./gradlew check`. To build a zipped version of the plugin and its dependencies, run `./gradlew buildPlugin`. -You can tweak the version of the IntelliJ platform used to build/test the plugin in `gradle.properties`. Versions prior to 2018.1.5 require a JDK 1.8, but later versions also support JDK 9+. +You can tweak the version of the IntelliJ platform used to build/test the plugin in `gradle.properties`, such as: + +``` +ideaVersion=IC-2020.2.2 +``` + +As of 1.18, java 11 is assumed but you might get away with earlier java. A high level description of how the plugin works can be found in `ARCHITECTURE.md`. + +# Releasing + +* Search for 4.9, 4.10 etc... of ANTLR. +* Update release notes in plugin.xml +* Test with multiple IDE versions +* Run unit tests +* Upload to https://plugins.jetbrains.com/plugin/add#intellij +* Write release note in github diff --git a/build.gradle b/build.gradle index ad5b2424..9e6b85a6 100644 --- a/build.gradle +++ b/build.gradle @@ -5,11 +5,11 @@ buildscript { } plugins { - id "org.jetbrains.intellij" version "1.4.0" + id "org.jetbrains.intellij" version "1.5.2" } wrapper { - gradleVersion = '6.8' + gradleVersion = '7.4.2' } group 'antlr' @@ -34,6 +34,10 @@ intellij { repositories { mavenCentral() + mavenLocal() + maven { // Gets snapshots of antlr if needed + url "https://oss.sonatype.org/content/repositories/snapshots/" + } } dependencies { @@ -42,7 +46,7 @@ dependencies { } implementation "org.antlr:antlr4-intellij-adaptor:0.1" testImplementation group: 'junit', name: 'junit', version: '4.13.2' - testImplementation group: 'org.mockito', name: 'mockito-core', version: '4.3.1' + testImplementation group: 'org.mockito', name: 'mockito-core', version: '4.4.0' } generateGrammarSource { diff --git a/gradle.properties b/gradle.properties index 02019b9a..3ce9f154 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -pluginVersion=1.17 +pluginVersion=1.18 # e.g. IC-2016.3.3, IU-2018.2.5 etc # For a list of possible values, refer to the section 'com.jetbrains.intellij.idea' at @@ -7,12 +7,16 @@ pluginVersion=1.17 # Old version we use to test code #ideaVersion=IC-2019.1.3 +#ideaVersion=IC-2020.1 might work on non mac + # Fixes OS X Monterey error about missing a .dylib #ideaVersion=IC-2020.2.1 #ideaVersion=IC-2020.2.2 -ideaVersion=IC-2021.2 +#ideaVersion=IC-2021.2 + +ideaVersion=IC-2021.3.3 # The version of ANTLR v4 that will be used to generate the parser -antlr4Version=4.9.3 +antlr4Version=4.10-SNAPSHOT diff --git a/src/main/antlr/org/antlr/intellij/plugin/parser/ANTLRv4Parser.g4 b/src/main/antlr/org/antlr/intellij/plugin/parser/ANTLRv4Parser.g4 index 380fec03..4e2d3fc3 100644 --- a/src/main/antlr/org/antlr/intellij/plugin/parser/ANTLRv4Parser.g4 +++ b/src/main/antlr/org/antlr/intellij/plugin/parser/ANTLRv4Parser.g4 @@ -207,7 +207,7 @@ labeledAlt lexerRule : DOC_COMMENT* FRAGMENT? - TOKEN_REF COLON lexerRuleBlock SEMI + TOKEN_REF optionsSpec? COLON lexerRuleBlock SEMI ; lexerRuleBlock diff --git a/src/main/java/org/antlr/intellij/plugin/ANTLRv4ExternalAnnotator.java b/src/main/java/org/antlr/intellij/plugin/ANTLRv4ExternalAnnotator.java index 537f90d5..03e13704 100644 --- a/src/main/java/org/antlr/intellij/plugin/ANTLRv4ExternalAnnotator.java +++ b/src/main/java/org/antlr/intellij/plugin/ANTLRv4ExternalAnnotator.java @@ -122,6 +122,9 @@ private Optional annotate(@NotNull AnnotationHolder holder, GrammarI case WARNING_ONE_OFF: case INFO: + /* When trying to remove the deprecation warning, you will need something like this: + AnnotationBuilder builder = holder.newAnnotation(HighlightSeverity.WEAK_WARNING, issue.getAnnotation()).range(range); + */ return Optional.of(holder.createWeakWarningAnnotation(range, issue.getAnnotation())); default: diff --git a/src/main/java/org/antlr/intellij/plugin/parsing/PreviewParser.java b/src/main/java/org/antlr/intellij/plugin/parsing/PreviewParser.java index 20e0910d..8886531a 100644 --- a/src/main/java/org/antlr/intellij/plugin/parsing/PreviewParser.java +++ b/src/main/java/org/antlr/intellij/plugin/parsing/PreviewParser.java @@ -1,16 +1,8 @@ package org.antlr.intellij.plugin.parsing; import com.intellij.openapi.progress.ProgressManager; -import org.antlr.v4.runtime.InterpreterRuleContext; -import org.antlr.v4.runtime.ParserRuleContext; -import org.antlr.v4.runtime.RecognitionException; -import org.antlr.v4.runtime.Token; -import org.antlr.v4.runtime.TokenStream; -import org.antlr.v4.runtime.atn.ATN; -import org.antlr.v4.runtime.atn.ATNDeserializer; -import org.antlr.v4.runtime.atn.ATNSerializer; -import org.antlr.v4.runtime.atn.ATNState; -import org.antlr.v4.runtime.atn.DecisionState; +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.atn.*; import org.antlr.v4.tool.Grammar; import org.antlr.v4.tool.GrammarParserInterpreter; @@ -33,7 +25,7 @@ public PreviewParser(Grammar g, ATN atn, TokenStream input) { } public PreviewParser(Grammar g, TokenStream input) { - this(g, new ATNDeserializer().deserialize(ATNSerializer.getSerializedAsChars(g.getATN())), input); + this(g, new ATNDeserializer().deserialize(ATNSerializer.getSerialized(g.getATN()).toArray()), input); } @Override diff --git a/src/main/java/org/antlr/intellij/plugin/parsing/RunANTLROnGrammarFile.java b/src/main/java/org/antlr/intellij/plugin/parsing/RunANTLROnGrammarFile.java index dae5ce2e..f53abce9 100644 --- a/src/main/java/org/antlr/intellij/plugin/parsing/RunANTLROnGrammarFile.java +++ b/src/main/java/org/antlr/intellij/plugin/parsing/RunANTLROnGrammarFile.java @@ -86,7 +86,7 @@ public void run(@NotNull ProgressIndicator indicator) { Grammar g = previewState.lg; String language = g.getOptionString(ANTLRv4GrammarProperties.PROP_LANGUAGE); Tool tool = ParsingUtils.createANTLRToolForLoadingGrammars(getGrammarProperties(project, grammarFile)); - CodeGenerator gen = new CodeGenerator(tool, g, language); + CodeGenerator gen = CodeGenerator.create(tool, g, language); gen.writeVocabFile(); } } @@ -106,7 +106,7 @@ private boolean isGrammarStale(ANTLRv4GrammarProperties grammarProperties) { } String language = g.getOptionString(ANTLRv4GrammarProperties.PROP_LANGUAGE); - CodeGenerator generator = new CodeGenerator(null, g, language); + CodeGenerator generator = CodeGenerator.create(null, g, language); String recognizerFileName = generator.getRecognizerFileName(); VirtualFile contentRoot = getContentRoot(project, grammarFile); diff --git a/src/main/java/org/antlr/intellij/plugin/validation/GrammarIssuesCollector.java b/src/main/java/org/antlr/intellij/plugin/validation/GrammarIssuesCollector.java index e0f42f16..77e8a72c 100644 --- a/src/main/java/org/antlr/intellij/plugin/validation/GrammarIssuesCollector.java +++ b/src/main/java/org/antlr/intellij/plugin/validation/GrammarIssuesCollector.java @@ -8,6 +8,8 @@ import org.antlr.runtime.ANTLRReaderStream; import org.antlr.runtime.Token; import org.antlr.v4.Tool; +import org.antlr.v4.codegen.CodeGenerator; +import org.antlr.v4.codegen.Target; import org.antlr.v4.parse.ANTLRParser; import org.antlr.v4.runtime.misc.IntervalSet; import org.antlr.v4.tool.*; @@ -19,9 +21,9 @@ import java.io.File; import java.io.StringReader; +import java.lang.reflect.Constructor; import java.util.*; -import static org.antlr.v4.codegen.CodeGenerator.targetExists; public class GrammarIssuesCollector { private static final String LANGUAGE_ARG_PREFIX = "-Dlanguage="; @@ -189,4 +191,16 @@ else if ( x instanceof RuleRefAST) { ruleDefs.keySet().removeAll(ruleRefs); return ruleDefs; } + + public static boolean targetExists(String language) { + String targetName = "org.antlr.v4.codegen.target."+language+"Target"; + try { + Class c = Class.forName(targetName).asSubclass(Target.class); + Constructor ctor = c.getConstructor(CodeGenerator.class); + return true; + } + catch (Exception e) { // ignore errors; we're detecting presence only + } + return false; + } } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index f53d0bc4..7d90ac1c 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -6,8 +6,8 @@ - This plugin is for ANTLR v4 grammars and includes ANTLR 4.9.1. It works with - 2018.3-2021.x. It should work in other JetBrains IDEs. + This plugin is for ANTLR v4 grammars and includes ANTLR 4.10. It works with + 2020.2.1 and above. It should work in other JetBrains IDEs.

- See the complete list of fixed issues. + See the complete list of fixed issues. ]]> - - + +