Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Xtext,从所选内容运行插件_Java_Plugins_Xtext_Xtend - Fatal编程技术网

Java Xtext,从所选内容运行插件

Java Xtext,从所选内容运行插件,java,plugins,xtext,xtend,Java,Plugins,Xtext,Xtend,我有一个DSLmyDsl,我用这个代码运行 它位于Xtend class LaunchMydslShortcut implements ILaunchShortcut { @Inject private IResourceForEditorInputFactory resourceFactory; override launch(ISelection selection, String mode) { println("launch from selec

我有一个DSL
myDsl
,我用这个代码运行 它位于
Xtend

class LaunchMydslShortcut implements ILaunchShortcut {
    @Inject
    private IResourceForEditorInputFactory resourceFactory;

    override launch(ISelection selection, String mode) {
        println("launch from selection")


    }

    override launch(IEditorPart editor, String mode) {
        val input = editor.editorInput

        if (editor instanceof XtextEditor && input instanceof FileEditorInput) {
            val resource = resourceFactory.createResource(input)
            resource.load(newHashMap())
            val program = resource.contents.head as Script
            new MyDslInterpreter().exec(program)
        }
    }
我想从方法
launch(ISelection selection,String模式)

我得去资源中心打电话给我的同事。如何执行此操作?

以下是处理程序对文件调用Xtext IGenerator的代码。你应该能够适应你的情况

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        Object firstElement = structuredSelection.getFirstElement();
        if (firstElement instanceof IFile) {
            IFile file = (IFile) firstElement;
            IProject project = file.getProject();
            IFolder srcGenFolder = project.getFolder("src-gen");
            if (!srcGenFolder.exists()) {
                try {
                    srcGenFolder.create(true, true,
                            new NullProgressMonitor());
                } catch (CoreException e) {
                    return null;
                }
            }

            final EclipseResourceFileSystemAccess fsa = fileAccessProvider.get();
            fsa.setOutputPath(srcGenFolder.getFullPath().toString());

            URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
            ResourceSet rs = resourceSetProvider.get(project);
            Resource r = rs.getResource(uri, true);
            generator.doGenerate(r, fsa);

        }
    }

你看了吗?没有,我想看看能不能用在我的电脑上case@ChristianDietrich完成了,开始工作了