Modify AST in plugin headless mode - eclipse-plugin

I have created a plugin in eclipse with support of cdt api's, the plugin does some code refactoring, and it works fine, I want to extend this plugin to run in headless mode, I created an entry point that implements IApplication and it works fine to enter the start method, the problem comes in applying code changes, when I try to modify the code
Change c = rewriter.rewriteAST();
try {
c.perform(new NullProgressMonitor());
} catch (CoreException e) {
logger.error("Faild to persist changes",e);
}
it gives me exception says Caused by: java.lang.IllegalStateException: Workbench has not been created yet.
but it does code refactor, my question does the Change.perform is apart of the UI module and how to avoid this exception?
Full stack trace link: https://pastebin.com/iiKzvisQ

Related

IntelliJ autocompletion plugin development for Gherkin steps

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!

"No tests were found" with Junit 5 and IntelliJ

Q&A-Style question as the existing questions don't match the simple typo I made here:
Goal
Execute simple JUnit tests via the IntelliJ IDE using the UI (right-click: run test)
Problem
IntelliJ tells that "no tests were found"
Code
import org.junit.jupiter.api.Test;
public class Test {
#Test
private void testAMethod() { (...) }
}
change to
public void testAMethod() { (...) }
According to Junit5 document
Test classes, test methods, and lifecycle methods are not required to
be public, but they must not be private.
https://junit.org/junit5/docs/current/user-guide/
Another possibility of this error message is when using a non-void return type. Switch to void and it will work.
I know it is not relevant but if someone else is facing issue like me and none of the above solution works for you then check your target folder does it have classes files in this. I was having this same issue then I checked my target/classes folder and found it empty. Then I build my mvn again using mvn clean install and then it work like charm.
when build was success but class file was not generated as I was using DskipTests
The issue was a simply typo - the test was not visible from outside:
#Test
// Before
private void testAMethod() { (...)
// After
void testAMethod() { (...)
Junit in IntelliJ won't work on Java 10 or above. Try downgrading the project SDK to Java 8 and the tests will work like a charm.

React: Calling JS function after bridge has been destroyed --- How to find which function

I'm working on an update for our app. I've added a HeadlessTask and I've started seeing this warning in the console:
React: Calling JS function after bridge has been destroyed
How can I get the name of the function being executed?
From the error message I assume you're in java (react-native Android):
When you reload on react-native, what happens behind the scenes is that the react context is getting destroyed, and a new one is being created.
That error get's thrown whenever a react-native Native Module is trying to do work, by using the old react context (the one that was valid before the reload).
The last time I saw that error it also included an explanation as to which module tried to do work by using the old context. Typically it's the RCTDeviceEventEmitter module trying to send a message to javascript.
You'll have to open logcat on Android studio and read the full error message.
p.s: If you're using react-native-navigation in your project, (after you discover which module is the trouble maker by using the logcat), make sure to search on their issues as they are heavily using the native side of react-native android, and I've seen lot's of similar issues so far.
Never found a good solution to this until recently, so thought I'd put this here in case it helps someone else. I finally got around this error by doing the following:
public class RNMyNativeModule extends ReactContextBaseModule {
private ReactApplicationContext currentContext;
public RNMyNativeModule(ReactApplicationContext reactContext) {
super(reactContext);
currentContext = reactContext;
}
public void myEmitFn(String emitMe) {
currentContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("RNMyNativeModuleEvent", emitMe);
}
}
Basically, in your module constructor, make sure you capture the currentContext in it's own variable, and just use that whenever you need it. Otherwise it gets overwritten and destroyed whenever a live reload happens, and getReactApplicationContext() is not actually giving you the current context.

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 Debug NinjectWebCommon.cs?

We are trying to debug through ninjectwebcommon.cs to find the binding for a respository.
In VS 2012, I am putting a Debugpoint on the kernel.bind but it doesnot hit anytime. Can someone sugggest me how to debug this?
I have NInject Version v4.0.30319
The not-so-simple and (obviously) temporary solution for me was to create a background thread in NinjectWebCommon.RegisterServices with the configuration I was debugging:
var thread = new System.Threading.Thread(() =>
{
while (!System.Diagnostics.Debugger.IsAttached)
{
System.Threading.Thread.Sleep(100);
}
// custom code, including kernel.Bind<>() calls here
});
thread.IsBackground = true;
thread.Start();
The idea here is to keep the thread you've created from executing the debuggable code until the debugger is actually attached. Setting the IsBackground property is important, because this allows the rest of the RegisterServices method to complete, which in turn allows the application to start and allows the debugger to attach.
Ninject is open source. You can download the entire project from their Github page at https://github.com/ninject. From there you can point Visual Studio to those projects instead of using the compiled assemblies.
Another option would be to use http://symbolsource.org as a Symbol Server. But it looks like they only have Ninject 3.