3
I’m making a plugin and when I right click on a class of Package Explorer, my Handler could reference the clicked class.
When I right click on a class of Package explorer opens the menu, in this menu I created a new function (line), when I click on it it is treated in Handler which is a class, and in this Handler I would like to know how I get an instance(reference) of the class I right-clicked.
The Interface part is implemented in xml plugin.
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.jdt.ui.PackageExplorer">
<command
commandId="br.usp.each.saeg.badua.dataflow.handler"
label="Dataflow Coverage"
style="push">
<visibleWhen
checkEnabled="false">
<with
variable="activeMenuSelection">
<iterate
ifEmpty="false"
operator="or">
<adapt
type="org.eclipse.jdt.core.ICompilationUnit">
</adapt>
</iterate>
</with>
</visibleWhen>
</command>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="DataflowHandler"
id="br.usp.each.saeg.badua.dataflow.handler"
name="DataflowViewHandler">
</command>
</extension>
</plugin>
and have the class Dataflowhandler.java that is the Handler
import org.eclipse.core.commands.Abstracthandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.PlatformUI;
public class DataflowHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
#codigo para conseguir a instancia da classe selecionada
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
Basically what I need is that when I click on this button I get a reference to the Main.java class, which is the class I right-clicked on.
Thank you very much for the reply Anthony, as there was some time since I posted this doubt had already managed to work with these Icompilationunit, but the article can still be useful because I am not using AST. Hahaha can leave, I will. Abs!
– Louiz