IntelliJ autocompletion plugin development for Gherkin steps - intellij-idea

I've recently started working on IntelliJ plugin development and got stuck a bit with autocompletion implementation.
Don't want to go deep into the details of plugins idea, but I would like to pass some strings through autocompletion into the Gherkin steps.
If Gherkin plugin in IntelliJ is disabled (file is expressed as plain text), there are no problems for passing 'Message' value to step through autocompletion. If plugin is enabled, it does not work.
Example of scenario:
Scenario: Successful message appearance
When user access home page
When user sees message "Message"
Example of completion contributor:
public SimpleCompletionContributor() {
extend(CompletionType.BASIC, PlatformPatterns.psiElement(),
new CompletionProvider<>() {
public void addCompletions(#NotNull CompletionParameters parameters,
#NotNull ProcessingContext context,
#NotNull CompletionResultSet resultSet) {
resultSet.addElement(LookupElementBuilder.create("Message"));
}
});
}
Structure of entire document observed via PsiPlugin:
As I understand, Gherkin plugin changes interpretation of file, and currently I can do nothing about it. What I am missing?
Thanks!

Related

How can I navigate to Lombok generated implementations

I'm wondering if it would be possible to navigate directly to the methods generated by Lombok using Intellij IDEA.
For instance, for this given example:
#Builder
public class AClass {
private String body;
}
trying to go to the implementation of AClass#builder in an instruction like AClass.builder().build() results in Intellij navigating to AClass, instead of taking me to the real compiled method, which is generated under target directory
Please feel free to create an issue here: https://youtrack.jetbrains.com/issues/IDEA
Currently you can't change the behavior.

Intellij Idea does not detect and underline non-existing methods in the editor pane

In the idea editor and my java project , idea does not detect non-existing methods and underline in the editor pane, so i could not use alt + enter to generate new methods.
Example screenshot is below :
BTW : powersave mode is disabled, in the project setting sources are selected.
Project window is seen below:
I created demo maven project in idea, still the problem continues.
I created DemoNew Class.
public class DemoNew {
}
Then i created DemoImpl class:
public class DemoImpl {
public static void main(String[] args) {
DemoNew demoObject = new DemoNew();
demoObject.ssss(); // idea does not detect this non-existing method.
}
}
As seen above, idea does not detect the non existing ssss method in DemoNew class.
I uploaded demo project and my settings in intellij idea.
demo project and settings
After compiling project, still idea does not underline non-existing method with red color in the editor pane.
JetBrains Team answered the question
Looks like JDK uses wrong locale:
https://youtrack.jetbrains.com/issue/IDEA-190718 Please try to add
"-Dsun.locale.formatasdefault=true" option to JVM settings.
I added that parameters from intellij idea / help / edit custom vm options.
And parameters are seen below.
-Dsun.locale.formatasdefault=true
-Duser.language=en
-Duser.region=US
-Dfile.encoding=UTF8
I added last four items in the file.
That fixed the problem.

IntelliJ type error when using Geb static content DSL with parameters

Whenever I use a static-content defined closure that takes parameters, IntelliJ will complain that the types do not match (even if I specify the type inside the closure).
For example, if I use this static content block:
static content = {
myModule { $('myModule').module(CustomModule) }
namedModule { String name -> $(".$name").module(CustomModule) }
}
Both of the above items can be used successfully in my tests, but if I was to use 'namedModule' in one of my tests as follows:
page.namedModule("moduleName").moduleMethod("blah blah blah")
IntelliJ will highlight the parameter "moduleName" in yellow with the error:
'namedModule' cannot be applied to '(java.lang.String)'
We are trying to refactor our tests in a way that means you can navigate through the code easier (e.g. avoiding any Geb/Groovy 'magic' that IntelliJ can't resolve), and this is one of the last remaining issues preventing this from being possible.
This is a known limitation to Geb support in IntelliJ. IntelliJ always treats content definitions as properties of pages and modules even though they can be parametrised. Given that Geb support in IntelliJ is open sourced we could probably add support for this.
In the mean time, as a workaround you can use methods for parametrised content instead of content definitions and IntelliJ will be able to understand these and be able to refactor them:
void namedModule(String name) {
$(".$name").module(CustomModule)
}
There are some caveats, though:
you will loose ability to use content definition options; if you need to use these for a content definition then I suggest creating a parameterised "private" content definition (for example with a _ at the beginning of the name) that you will only ever access from within the page or module
RequiredPageContentNotPresent will not be thrown even if the returned content is empty; to work around it you will either need to add manual verification to each such method or use a strategy outlined in the first bullet point with using "private" content definitions

Remove version control from Eclipose RCP project

I have an Eclipse RCP application that uses EGit and JGit to implement the version control of projects.
In some cases, I want to make it so that a project is no longer under version control. This implies both deleting the project's .git directory on the file system, and making my application aware that the project is not under version control.
I tried looking through the JGit API for solutions to this, but could not find anything useful. Simply deleting the .git directory using a file manipulation API is not sufficient, as some files in it seem to be locked (very likely by JGit).
Sorry, I'm not 100% sure because your scenario is not clear enough to me, however you said that your application is based also on EGit, so I assume that you are using the standard eclipse APIs to manage the projects. If this is the case, what you are looking for is: org.eclipse.team.core.RepositoryProvider
This is an example:
public class UntrackProject extends AbstractHandler implements IHandler {
#Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IProject project = getProject(); // get the project, for example using the selection service
try {
RepositoryProvider.unmap(project);
//TODO Refresh your viewer to show changes
} catch (TeamException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
For reference, you can check the handler of the context menu "Disconnect", that does exactly what you are looking for: org.eclipse.egit.ui.internal.actions.DisconnectActionHandler
https://git.eclipse.org/c/egit/egit.git/tree/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/DisconnectActionHandler.java
It uses a lot of internal classes of egit, but in the end it uses the RepositoryProvider's API.
Note that the method RepositoryProvider.unmap(project) does NOT delete the repository, it just disconnects the project.
I hope this helps!

How to handle a failed test in JBehave / Thucydides / Selenium?

I'm pretty new to Thucydides / JBehave, but haven't found any solutions posted to this one. This is the first time I've used Thucydides / JBehave, but have used Selenium before.
I have my .story file. The .story file lists 5 scenario's.
Each scenario is implemented in it's own POJO java class.
e.g
public class ManagerBypassLoginSteps
{
#Steps
ManagerSteps managerSteps;
#Given("the manager is not logged in")
public void mangerLogsIn()
{
managerSteps.start();
}
#When("the manager goes to a different page")
public void managerToDashboardPage()
{
managerSteps.goesToDashboardPage();
}
#Then("they should see the login page")
public void managerShouldSeeLoginPage()
{
managerSteps.verifyOnLoginPage();
managerSteps.close();
}
}
The ManagerSteps class extends net.thucydides.core.steps.ScenarioSteps, but is otherwise just a POJO. The ManagerSteps calls the page objects - all very normal stuff and as per the examples.
In the scenario above, the test fails as the code displays an error message instead of returning the user to the log in page - that's fine, the security code doesn't meet the specified requirements (yet) But, after the assert inside the ManagerSteps class fails, the test appears to stop. This means I have a browser instance just sitting there until I close it. When run as a series of tests, this means a broswer in the Selenium grid is now tied up.
I need a way to detect a test failure, to call to the page object to close / quit.
I can't find the equivalent of a #Before or #After that will always run, I could find it I could use the #After to close the page object's webDriver.
I am not using Thucydides to manage the WebDriver lifecycle as I couldn't find any examples of this that did not use the ThucydidesRunner.class.
Do I have to use the ThucydidesRunner.class ? My impression from the Thucydides manual for integrating with JBehave (http://thucydides.info/docs/thucydides/_writing_acceptance_tests_with_jbehave.html) didn't suggest it was required.
How does everyone else handle test failures in this situation ?
The real problem I had was closing the browser, after a test failure.
The best way to manage the WebDriver appear to be to use the Thucydides #ManagedDriver annotation to handle the lifecyle.
I ended up using a very simple JUnit runner like so
public class UserLogin extends ThucydidesJUnitStory
{
#Managed
public WebDriver webdriver;
#ManagedPages(defaultUrl = "http://localhost:8080/dc-bus-main-web")
public Pages pages;
}
When this is started, it maps to the user_login.story file, through JBehave's naming convention, then starts normally.