This commit is contained in:
Clément Fournier
2020-01-05 19:22:17 +01:00
parent e9dbe0233f
commit 6f61522971
3 changed files with 142 additions and 2 deletions

View File

@@ -22,6 +22,13 @@
</configuration>
</plugin>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
@@ -70,10 +77,20 @@
<artifactId>pmd-core</artifactId>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-lang-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
</project>

View File

@@ -115,7 +115,7 @@ abstract class AbstractModelicaNode extends AbstractNode implements Node, Modeli
@Override
public void jjtSetLastToken(GenericToken token) {
// don't let jjtree override tokens we've chosen
if (lastToken != null) {
if (lastToken == null) {
super.jjtSetLastToken(token);
}
}

View File

@@ -0,0 +1,123 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.modelica.ast
import io.kotlintest.should
import io.kotlintest.shouldBe
import io.kotlintest.specs.FunSpec
import net.sourceforge.pmd.lang.LanguageRegistry
import net.sourceforge.pmd.lang.ast.Node
import net.sourceforge.pmd.lang.ast.test.matchNode
import net.sourceforge.pmd.lang.ast.test.shouldBe
import java.io.StringReader
class ModelicaCoordsTest : FunSpec({
test("Test line/column numbers for implicit nodes") {
"""
package TestPackage
package EmptyPackage
end EmptyPackage;
end TestPackage;
""".trim().parseModelica() should matchNode<ASTStoredDefinition> {
it.assertBounds(1, 1, 4, 16)
child<ASTClassDefinition> {
it.assertBounds(1, 1, 4, 15)
child<ASTClassPrefixes> {
it.assertBounds(1, 1, 1, 7)
child<ASTPackageClause> {
it.assertBounds(1, 1, 1, 7)
}
}
child<ASTClassSpecifier> {
it.assertBounds(1, 9, 4, 15)
child<ASTSimpleLongClassSpecifier> {
it.assertBounds(1, 9, 4, 15)
child<ASTSimpleName> {
it.assertBounds(1, 9, 1, 19)
}
child<ASTComposition> {
it.assertBounds(2, 3, 3, 19)
child<ASTElementList> {
it.assertBounds(2, 3, 3, 19)
child<ASTRegularElement> {
it.assertBounds(2, 3, 3, 18)
child<ASTClassDefinition> {
it.assertBounds(2, 3, 3, 18)
it.isPartial shouldBe false
child<ASTClassPrefixes> {
it.assertBounds(2, 3, 2, 9)
child<ASTPackageClause> {
it.assertBounds(2, 3, 2, 9)
}
}
child<ASTClassSpecifier> {
it.assertBounds(2, 11, 3, 18)
child<ASTSimpleLongClassSpecifier> {
it.assertBounds(2, 11, 3, 18)
it.simpleClassName shouldBe "EmptyPackage"
child<ASTSimpleName> {
it.assertBounds(2, 11, 2, 22)
}
child<ASTComposition> {
it.assertBounds(3, 3, 3, 2)
child<ASTElementList> {
/*
This ElementList is empty and has no explicit token.
*/
it.assertBounds(3, 3, 3, 2)
}
}
child<ASTSimpleName> {
it.assertBounds(3, 7, 3, 18)
}
}
}
}
}
}
}
child<ASTSimpleName> {
it.assertBounds(4, 5, 4, 15)
}
}
}
}
}
}
})
fun String.parseModelica(): ASTStoredDefinition {
val ver = LanguageRegistry.getLanguage("Modelica").defaultVersion.languageVersionHandler
val parser = ver.getParser(ver.defaultParserOptions)
return parser.parse(":dummy:", StringReader(this)) as ASTStoredDefinition
}
fun Node.assertBounds(bline: Int, bcol: Int, eline: Int, ecol: Int) {
this::getBeginLine shouldBe bline
this::getBeginColumn shouldBe bcol
this::getEndLine shouldBe eline
this::getEndColumn shouldBe ecol
}