Skip to content

Commit

Permalink
Switched to a Gradle build
Browse files Browse the repository at this point in the history
  • Loading branch information
bjansen committed Feb 14, 2019
1 parent e88f626 commit 0b8d515
Show file tree
Hide file tree
Showing 55 changed files with 408 additions and 199 deletions.
51 changes: 40 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# ANTLR4
*.tokens
*.tokens

target/
/build/
/.gradle/

# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
.idea/modules.xml
.idea/*.iml
.idea/modules

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

This file was deleted.

1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

31 changes: 0 additions & 31 deletions .idea/compiler.xml

This file was deleted.

4 changes: 2 additions & 2 deletions .idea/encodings.xml

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

1 change: 0 additions & 1 deletion .idea/vcs.xml

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

57 changes: 46 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,55 @@
# Sample Jetbrains plugin using ANTLR grammar
# Sample IntelliJ plugin using ANTLR grammar

This is a demonstration of [ANTLR-jetbrains supported library](https://github.com/antlr/jetbrains).
This is a demonstration of [ANTLRv4 library for IntelliJ plugins](https://github.com/antlr/antlr4-intellij-adaptor/),
which makes it easy to create plugins for IntelliJ-based IDEs based on an ANTLRv4 grammar.

<img src=screenshot.png>

**WARNING**. Turn on Dragon speech recognition for Mac and do a rename.
GUI deadlocks. Every time. Turn off dragon. No problem ever.
See [jetbrains forum](https://devnet.jetbrains.com/message/5566967#5566967).

## Running the plugin for the first time

You need to fetch the antlr dependencies from the maven pom file with `mvn dependency:resolve`. To process the
grammar files, call `mvn process-resources`.
Make sure the Gradle plugin is installed in your IDE, go to `File -> Open`, select the `build.gradle` file
and choose `Open as Project`.

If you already imported the project when it was not based on Gradle, then choose the option to delete the existing
project and reimport it.

Once the IDE is done downloading dependencies and refreshing the project, you can use the `Gradle` tool window
and use the following `Tasks`:
* `build > assemble` to build the project
* `intellij > runIde` to run the plugin in a sandboxed instance

## Noteworthy things

### Gradle build
The build is based on Gradle, and uses the [gradle-intellij-plugin](https://github.com/JetBrains/gradle-intellij-plugin),
which makes it easy to:

* pull dependencies, especially the IntelliJ SDK and `antlr4-intellij-adaptor`
* build and run tests in a CI environment on different versions of the SDK
* generate lexers & parsers from your grammars, thanks to the [ANTLR plugin for Gradle](https://docs.gradle.org/current/userguide/antlr_plugin.html)
* publish plugins to the [JetBrains Plugins Repository](https://plugins.jetbrains.com/)
* configure the project for occasional contributors 🙂

Go to `File -> Project Structure -> Project` and add a new `IntelliJ Platform Plugin SDK` or use a valid existing one.
### ANTLRPsiNode

You also need the jetbrains antlr adapter. It may be added with `git submodule init` and `git submodule update`.
PSI nodes defined in the plugin extend `ANTLRPsiNode` and `IdentifierDefSubtree`, which automatically
makes them `PsiNameIdentifierOwner`s.

Now create a new `Run Configuration` of the type `Plugin`.
### Error highlighting

Errors are shown by `SampleExternalAnnotator`, which makes use of `org.antlr.intellij.adaptor.xpath.XPath` to
detect references to unknown functions.

### ParserDefinition

`SampleParserDefinition` uses several handy classes from the adaptor library:

* `PSIElementTypeFactory` to generate `IElementType`s from tokens and rules defined in your ANTLRv4 grammar
* `ANTLRLexerAdaptor` to bind generated lexers to a `com.intellij.lexer.Lexer`
* `ANTLRParserAdaptor` to bind generated parsers to a `com.intellij.lang.PsiParser`

## Misc

**WARNING**. Turn on Dragon speech recognition for Mac and do a rename.
GUI deadlocks. Every time. Turn off dragon. No problem ever.
See [JetBrains forum](https://devnet.jetbrains.com/message/5566967#5566967).
1 change: 0 additions & 1 deletion adaptor
Submodule adaptor deleted from 3cbca2
49 changes: 49 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
buildscript {
repositories {
mavenCentral()
}
}

plugins {
id "org.jetbrains.intellij" version "0.4.2"
}

wrapper {
gradleVersion = '5.2.1'
}

group 'antlr'
version pluginVersion

apply plugin: 'java'
apply plugin: 'org.jetbrains.intellij'
apply plugin: 'antlr'

compileJava {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}

intellij {
version = ideaVersion

pluginName 'antlr4-intellij-plugin-sample'
downloadSources true
updateSinceUntilBuild false
}

repositories {
mavenCentral()
}

dependencies {
antlr("org.antlr:antlr4:$antlr4Version") { // use ANTLR version 4
exclude group:'com.ibm.icu', module:'icu4j'
}
implementation 'org.antlr:antlr4-intellij-adaptor:0.1'
testCompile group: 'junit', name: 'junit', version: '4.11'
}

generateGrammarSource {
arguments += ["-package", "org.antlr.jetbrains.sample.parser", "-Xexact-output-dir"]
}
3 changes: 2 additions & 1 deletion contributors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ CONTRIBUTORS:

YYYY/MM/DD, github id, Full name, email
2015/11/09, parrt, Terence Parr, [email protected]
2019/02/13, Kisioj, Krzysztof Jura, [email protected]
2019/02/13, Kisioj, Krzysztof Jura, [email protected]
2019/02/13, bjansen, Bastien Jansen, [email protected]
8 changes: 8 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pluginVersion=0.1

# 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 https://www.jetbrains.com/intellij-repository/releases
ideaVersion=2018.3.2

# The version of ANTLR v4 that will be used to generate the parser
antlr4Version=4.7.2
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 0b8d515

Please sign in to comment.