Skip to content

Commit

Permalink
Merge pull request #89 from witspirit/v1.64.0
Browse files Browse the repository at this point in the history
V1.64.0
  • Loading branch information
picimako authored May 23, 2024
2 parents eed8424 + b801437 commit 84ab31f
Show file tree
Hide file tree
Showing 77 changed files with 2,474 additions and 630 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ jobs:
./gradlew listProductsReleases # prepare list of IDEs for Plugin Verifier
# Run tests
- name: Run Tests
- name: Run JUnit 5 Tests
run: ./gradlew test -Pidea.home.path=./intellij-community

# Run tests
- name: Run JUnit 3 Tests
run: ./gradlew testWithJunit3 -Pidea.home.path=./intellij-community

# Collect Tests Result of failed tests
- name: Collect Tests Result
if: ${{ failure() }}
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

## [Unreleased]

## [1.64.0]
### Changed
- New supported IDE version range: 2023.1.6-2024.2-EAP
- Did some optimizations on the unused step definition method inspection. Now it also marks the method name instead of
the entire method.
- Did some optimizations on the undefined step inspection.
- Removed duplicate reporting of steps that don't have step definition methods.
- Removed the class `StoryAnnotator` that didn't seem to do much useful.
- Improved the implementations of JBehave step reference handling.

## [1.63.0]
### Changed
- New supported IDE version range: 2022.2.5-2024.1-EAP
Expand Down
20 changes: 14 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ kotlin {

dependencies {
//https://kotlinlang.org/docs/reflection.html#jvm-dependency
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.0")
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.23")
implementation("org.jbehave:jbehave-core:5.2.0")
testImplementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.0")
testImplementation("org.assertj:assertj-core:3.25.2")
testImplementation("junit:junit:4.13.2")
testImplementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.23")
testImplementation("org.assertj:assertj-core:3.25.3")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.2")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.2")
}

// Configure Gradle IntelliJ Plugin - read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
Expand Down Expand Up @@ -87,14 +89,20 @@ tasks {
}

test {
useJUnitPlatform()
//Required for running tests in 2021.3 due to it not finding test classes properly.
//See https://app.slack.com/client/T5P9YATH9/C5U8BM1MK/thread/C5U8BM1MK-1639934273.054400
isScanForTestClasses = false
include("**/*Test.class")
exclude("**/StoryLocalizedLexer_FrenchTest.class")
include("**/codeInspector/*Test.class", "**/resolver/*Test.class", "**/utility/*Test.class", "**/service/*Test.class")
exclude("**/highlighter/*Test.class", "**/parser/*Test.class", "**/spellchecker/*Test.class", "**/structure/*Test.class")
}

// runPluginVerifier {
// ideVersions.set(listOf("IC-232.7754.73"))
// }
}

tasks.register<Test>("testWithJunit3") {
include("**/highlighter/*Test.class", "**/parser/*Test.class", "**/spellchecker/*Test.class", "**/structure/*Test.class")
exclude("**/highlighter/StoryLocalizedLexer_FrenchTest.class")
}
15 changes: 6 additions & 9 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,28 @@ pluginGroup = com.github.kumaraman21.intellijbehave
pluginName = JBehave Support
pluginRepositoryUrl = https:/witspirit/IntelliJBehave
# SemVer format -> https://semver.org
pluginVersion = 1.63.0
pluginVersion = 1.64.0

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 222.4554.10
pluginUntilBuild = 241.*
pluginSinceBuild = 231.9414.13
pluginUntilBuild = 242.*

# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformType = IC
platformVersion = 2022.2.5
platformVersion = 2023.1.6

# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
platformPlugins =java,Kotlin

# Gradle Releases -> https:/gradle/gradle/releases
gradleVersion = 8.5
gradleVersion = 8.6

# Opt-out flag for bundling Kotlin standard library -> https://jb.gg/intellij-platform-kotlin-stdlib
kotlin.stdlib.default.dependency = false

# Enable Gradle Configuration Cache -> https://docs.gradle.org/current/userguide/configuration_cache.html
org.gradle.unsafe.configuration-cache = false
org.gradle.configuration-cache = true

# Enable Gradle Build Cache -> https://docs.gradle.org/current/userguide/build_cache.html
org.gradle.caching = true

# Enable Gradle Kotlin DSL Lazy Property Assignment -> https://docs.gradle.org/current/userguide/kotlin_dsl.html#kotdsl:assignment
systemProp.org.gradle.unsafe.kotlin.assignment = true
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[versions]
# libraries
annotations = "24.0.1"
annotations = "24.1.0"

# plugins
kotlin = "1.9.0"
changelog = "2.1.2"
gradleIntelliJPlugin = "1.17.0"
kotlin = "1.9.23"
changelog = "2.2.0"
gradleIntelliJPlugin = "1.17.2"

[libraries]
annotations = { group = "org.jetbrains", name = "annotations", version.ref = "annotations" }
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import com.intellij.psi.PsiReference;
import org.jetbrains.annotations.NotNull;

/**
* Reports JBehave steps in Story files that have no Java step definition methods.
*/
public class UndefinedStepInspection extends LocalInspectionTool {

@NotNull
Expand All @@ -44,27 +47,23 @@ public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, bool
return new PsiElementVisitor() {

@Override
public void visitElement(PsiElement psiElement) {
public void visitElement(@NotNull PsiElement psiElement) {
super.visitElement(psiElement);

if (!(psiElement instanceof JBehaveStep)) {
if (!(psiElement instanceof JBehaveStep step)) {
return;
}

JBehaveStep step = (JBehaveStep) psiElement;
PsiReference[] references = step.getReferences();

if (references.length != 1 || !(references[0] instanceof StepPsiReference)) {
return;
}
if (references.length == 1 && references[0] instanceof StepPsiReference reference) {
JavaStepDefinition definition = reference.resolveToDefinition();

StepPsiReference reference = (StepPsiReference) references[0];
JavaStepDefinition definition = reference.resolveToDefinition();

if (definition == null) {
holder.registerProblem(step, "Step <code>#ref</code> is not defined");
} else {
highlightParameters(step, definition, holder);
if (definition == null) {
holder.registerProblem(step, "Step <code>#ref</code> is not defined");
} else {
highlightParameters(step, definition, holder);
}
}
}
};
Expand All @@ -73,24 +72,22 @@ public void visitElement(PsiElement psiElement) {

private void highlightParameters(JBehaveStep step, JavaStepDefinition javaStepDefinition, ProblemsHolder holder) {
String stepText = step.getStepText();

String annotationText = javaStepDefinition.getAnnotationTextFor(stepText);
ParametrizedString pString = new ParametrizedString(annotationText);

int offset = step.getStepTextOffset();
for (StringToken token : pString.tokenize(stepText)) {
for (StringToken token : new ParametrizedString(annotationText).tokenize(stepText)) {
int length = token.getValue().length();
if (token.isIdentifier()) {
registerHiglighting(StorySyntaxHighlighter.TABLE_CELL, step, TextRange.from(offset, length), holder);
registerHighlighting(StorySyntaxHighlighter.TABLE_CELL, step, TextRange.from(offset, length), holder);
}
offset += length;
}
}

private static void registerHiglighting(TextAttributesKey attributesKey,
JBehaveStep step,
TextRange range,
ProblemsHolder holder) {
private static void registerHighlighting(TextAttributesKey attributesKey,
JBehaveStep step,
TextRange range,
ProblemsHolder holder) {
final ProblemDescriptor descriptor = new ProblemDescriptorImpl(
step, step, "", LocalQuickFix.EMPTY_ARRAY,
ProblemHighlightType.INFORMATION, false, range, false, null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,32 @@
*/
package com.github.kumaraman21.intellijbehave.codeInspector;

import static com.github.kumaraman21.intellijbehave.service.JBehaveUtil.isStepDefinition;

import com.github.kumaraman21.intellijbehave.parser.JBehaveStep;
import com.github.kumaraman21.intellijbehave.parser.StoryFile;
import com.github.kumaraman21.intellijbehave.resolver.StepPsiReference;
import com.github.kumaraman21.intellijbehave.service.JavaStepDefinition;
import com.intellij.codeInspection.AbstractBaseJavaLocalInspectionTool;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ContentIterator;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.JavaElementVisitor;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiManager;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiReference;
import org.jetbrains.annotations.NotNull;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static com.github.kumaraman21.intellijbehave.service.JBehaveUtil.isStepDefinition;

/**
* Reports Java JBehave step definition methods when they are not used in any Story file.
*/
public class UnusedStepDeclarationInspection extends AbstractBaseJavaLocalInspectionTool {
@NotNull
@Override
Expand All @@ -48,10 +53,8 @@ public String getShortName() {
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new JavaElementVisitor() {
@Override
public void visitMethod(final PsiMethod method) {
Boolean isStepDefinition = ApplicationManager.getApplication().runReadAction((Computable<Boolean>) () -> isStepDefinition(method));

if (!isStepDefinition) {
public void visitMethod(final @NotNull PsiMethod method) {
if (method.getNameIdentifier() == null || !ReadAction.compute(() -> isStepDefinition(method))) {
return;
}

Expand All @@ -63,26 +66,26 @@ public void visitMethod(final PsiMethod method) {
for (JBehaveStep step : stepUsages) {
PsiReference[] references = step.getReferences();

if (references.length != 1 || !(references[0] instanceof StepPsiReference)) {
return;
}

StepPsiReference reference = (StepPsiReference) references[0];
JavaStepDefinition definition = reference.resolveToDefinition();
if (references.length == 1 && references[0] instanceof StepPsiReference reference) {
JavaStepDefinition definition = reference.resolveToDefinition();

if (definition != null && definition.getAnnotatedMethod() != null && definition.getAnnotatedMethod().isEquivalentTo(method)) {
return;
if (definition != null) {
PsiMethod annotatedMethod = definition.getAnnotatedMethod();
if (annotatedMethod != null && annotatedMethod.isEquivalentTo(method)) {
return;
}
}
}
}

holder.registerProblem(method, "Step <code>#ref</code> is never used");
holder.registerProblem(method.getNameIdentifier(), "Step <code>#ref</code> is never used");
}
};
}

private static class StepUsageFinder implements ContentIterator {
private Project project;
private Set<JBehaveStep> stepUsages = new HashSet<>();
private final Project project;
private final Set<JBehaveStep> stepUsages = new HashSet<>();

private StepUsageFinder(Project project) {
this.project = project;
Expand All @@ -94,10 +97,8 @@ public boolean processFile(VirtualFile virtualFile) {
return true;
}

PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
if (psiFile instanceof StoryFile) {
List<JBehaveStep> steps = ((StoryFile) psiFile).getSteps();
stepUsages.addAll(steps);
if (PsiManager.getInstance(project).findFile(virtualFile) instanceof StoryFile storyFile) {
stepUsages.addAll(storyFile.getSteps());
}
return true;
}
Expand Down
Loading

0 comments on commit 84ab31f

Please sign in to comment.