Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade gradle and fix tests #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
16 changes: 6 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ buildscript {
}

plugins {
id "org.jetbrains.intellij" version "0.4.2"
id "org.jetbrains.intellij" version "1.1.3"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to go along with the gradle upgrade.

}

wrapper {
gradleVersion = '5.2.1'
gradleVersion = '7.1.1'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Picked the latest so that it will hopefully keep working for the coming years.

}

group 'antlr'
Expand All @@ -27,9 +27,9 @@ compileJava {
intellij {
version = ideaVersion

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

repositories {
Expand All @@ -41,9 +41,5 @@ dependencies {
exclude group:'com.ibm.icu', module:'icu4j'
}
implementation 'org.antlr:antlr4-intellij-adaptor:0.1'
testCompile group: 'junit', name: 'junit', version: '4.11'
testImplementation group: 'junit', name: 'junit', version: '4.11'
}

generateGrammarSource {
arguments += ["-package", "org.antlr.jetbrains.sample.parser", "-Xexact-output-dir"]
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd stuff. Replaced with a single package header in the grammar (not perfect either) and now the files are generated in the correct package with the correct package statement.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a downside to this method, but I can't remember what it is 🤔 .

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The upside is that you can open the generated files in an IDE and not get compile errors :-)
I'm happy to revert it though, just say the word.

1 change: 1 addition & 0 deletions contributors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ 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, bjansen, Bastien Jansen, [email protected]
2021/07/15, matozoid, Danny van Bruggen, [email protected]
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
* Generate the parser via "mvn compile" from root dir of project.
*/
grammar SampleLanguage;
@header {package org.antlr.jetbrains.sample.parser;}

/** The start rule must be whatever you would normally use, such as script
* or compilationUnit, etc...
*/
script
: vardef* function* statement* EOF
: (vardef|function|statement)* EOF
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes a lot more sense and fixes a few tests.

;

function
Expand Down
51 changes: 24 additions & 27 deletions src/test/java/org/antlr/jetbrains/adaptor/test/TestXPath.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
package org.antlr.intellij.adaptor.test;
package org.antlr.jetbrains.adaptor.test;

import com.intellij.lang.Language;
import com.intellij.psi.PsiElement;
import com.intellij.psi.impl.source.tree.LeafPsiElement;
import com.intellij.testFramework.ParsingTestCase;
import org.antlr.intellij.adaptor.xpath.XPath;
import org.antlr.jetbrains.sample.SampleLanguage;
import org.antlr.jetbrains.sample.SampleParserDefinition;

import java.io.IOException;
import java.util.Collection;

public class TestXPath extends ParsingTestCase {

public static final String TEST_SAMPLE = "src/test/java/org/antlr/jetbrains/adaptor/test/test.sample";
public static final String BUBBLESORT_SAMPLE = "src/test/java/org/antlr/jetbrains/adaptor/test/bubblesort.sample";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The testfiles couldn't be found, the paths were all wrong.


public TestXPath() {
super("", "Sample", new SampleParserDefinition());
}

public void testSingleVarDef() throws Exception {
public void testSingleVarDef() {
String code = "var x = 1";
String output = code;
String xpath = "/script/statement";
String xpath = "/script";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vardefs are not under statement (anymore?)

checkXPathResults(code, xpath, output);
}

public void testMultiVarDef() throws Exception {
public void testMultiVarDef() {
String code =
"var x = 1\n" +
"var y = [1,2,3]\n";
String output = code;
String xpath = "/script/statement";
String xpath = "/script";
checkXPathResults(code, xpath, output);
}

public void testFuncNames() throws Exception {
String code = loadFile("test/org/antlr/jetbrains/adaptor/test/test.sample");
String code = loadFile(TEST_SAMPLE);
String output =
"f\n"+
"g\n"+
Expand All @@ -43,7 +45,7 @@ public void testFuncNames() throws Exception {
}

public void testAllIDs() throws Exception {
String code = loadFile("test/org/antlr/jetbrains/adaptor/test/test.sample");
String code = loadFile(TEST_SAMPLE);
String output =
"f\n"+
"x\n"+
Expand All @@ -60,7 +62,7 @@ public void testAllIDs() throws Exception {
}

public void testAnyVarDef() throws Exception {
String code = loadFile("test/org/antlr/jetbrains/adaptor/test/test.sample");
String code = loadFile(TEST_SAMPLE);
String output =
"var y = x\n"+
"var z = 9";
Expand All @@ -69,7 +71,7 @@ public void testAnyVarDef() throws Exception {
}

public void testVarDefIDs() throws Exception {
String code = loadFile("test/org/antlr/jetbrains/adaptor/test/test.sample");
String code = loadFile(TEST_SAMPLE);
String output =
"y\n" +
"z";
Expand All @@ -78,44 +80,43 @@ public void testVarDefIDs() throws Exception {
}

public void testAllVarDefIDsInScopes() throws Exception {
String code = loadFile("test/org/antlr/jetbrains/adaptor/test/bubblesort.sample");
String code = loadFile(BUBBLESORT_SAMPLE);
String output =
"x\n"+
"i\n"+
"j\n"+
"swap\n"+
"x";
String xpath = "//block/statement/vardef/ID";
String xpath = "//block/vardef/ID";
checkXPathResults(code, xpath, output);
}

public void testTopLevelVarDefIDsInScopes() throws Exception {
String code = loadFile("test/org/antlr/jetbrains/adaptor/test/bubblesort.sample");
String code = loadFile(BUBBLESORT_SAMPLE);
String output =
"x\n"+
"i";
String xpath = "//function/block/statement/vardef/ID";
String xpath = "//function/block/vardef/ID";
checkXPathResults(code, xpath, output);
}

public void testRuleUnderWildcard() throws Exception {
String code = loadFile("test/org/antlr/jetbrains/adaptor/test/test.sample");
String code = loadFile(TEST_SAMPLE);
String output =
"var y = x\n"+
"x\n"+
"[\n"+
"1\n"+
"]\n"+
"=\n"+
"\"sdflkjsdf\"\n"+
"return\n"+
"false;";
"false";
String xpath = "//function/*/statement/*";
checkXPathResults(code, xpath, output);
}

public void testAllNonWhileTokens() throws Exception {
String code = loadFile("test/org/antlr/jetbrains/adaptor/test/bubblesort.sample");
String code = loadFile(BUBBLESORT_SAMPLE);
String output =
"(\n"+
")\n"+
Expand All @@ -125,15 +126,15 @@ public void testAllNonWhileTokens() throws Exception {
}

public void testGetNestedIf() throws Exception {
String code = loadFile("test/org/antlr/jetbrains/adaptor/test/bubblesort.sample");
String code = loadFile(BUBBLESORT_SAMPLE);
String output =
"if";
String xpath = "//'if'";
checkXPathResults(code, xpath, output);
}

public void testWildcardUnderFuncThenJustTokens() throws Exception {
String code = loadFile("test/org/antlr/jetbrains/adaptor/test/test.sample");
String code = loadFile(TEST_SAMPLE);
String output =
"func\n"+
"f\n"+
Expand Down Expand Up @@ -165,15 +166,11 @@ public void testWildcardUnderFuncThenJustTokens() throws Exception {

// S U P P O R T

protected void checkXPathResults(String code, String xpath, String allNodesText) throws IOException {
checkXPathResults(SampleLanguage.INSTANCE, code, xpath, allNodesText);
}

protected void checkXPathResults(Language language, String code, String xpath, String allNodesText) throws IOException {
protected void checkXPathResults(String code, String xpath, String allNodesText) {
myFile = createPsiFile("a", code);
ensureParsed(myFile);
assertEquals(code, myFile.getText());
Collection<? extends PsiElement> nodes = XPath.findAll(language, myFile, xpath);
Collection<? extends PsiElement> nodes = XPath.findAll(SampleLanguage.INSTANCE, myFile, xpath);
StringBuilder buf = new StringBuilder();
for (PsiElement t : nodes) {
buf.append(t.getText());
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/antlr/jetbrains/adaptor/test/test.sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ func f(x:[]) {

func g(x:int, y:float) { }

func h() : boolean { return false; }
func h() : boolean { return false }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comma isn't allowed there (or is this an implicit test for invalid syntax?)


var z = 9