Java 类org.eclipse.xtext.resource.EObjectAtOffsetHelper 实例源码

项目:smaccm    文件:AadlHandler.java   
private URI getSelectionURI(ISelection currentSelection) {
    if (currentSelection instanceof IStructuredSelection) {
        IStructuredSelection iss = (IStructuredSelection) currentSelection;
        if (iss.size() == 1) {
            EObjectNode node = (EObjectNode) iss.getFirstElement();
            return node.getEObjectURI();
        }
    } else if (currentSelection instanceof TextSelection) {
        // Selection may be stale, get latest from editor
        XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor();
        TextSelection ts = (TextSelection) xtextEditor.getSelectionProvider().getSelection();
        return xtextEditor.getDocument().readOnly(resource -> {
            EObject e = new EObjectAtOffsetHelper().resolveContainedElementAt(resource, ts.getOffset());
            return EcoreUtil2.getURI(e);
        });
    }
    return null;
}
项目:n4js    文件:TestDiscoveryUIUtils.java   
private static EObject getSelectedElement(final XtextEditor editor, final ITextSelection textSelection) {
    return editor.getDocument().modify(
            resource -> {
                final IResourceServiceProvider serviceProvider = resource.getResourceServiceProvider();
                final EObjectAtOffsetHelper offsetHelper = serviceProvider.get(EObjectAtOffsetHelper.class);
                return offsetHelper.resolveElementAt(resource, textSelection.getOffset());
            });
}
项目:gemoc-studio-modeldebugging    文件:AbstractGemocLanguageProjectHandler.java   
protected Language getSelectedLanguage(XtextResource resource, int offset){
    final EObjectAtOffsetHelper eObjectAtOffsetHelper =
        resource.getResourceServiceProvider().get(EObjectAtOffsetHelper.class);
    EObject selectedElement = eObjectAtOffsetHelper.resolveContainedElementAt(resource, offset);
    if (selectedElement != null) {
        EObject currentElem = selectedElement;
        while(currentElem != null){
            if(currentElem instanceof Language){
                return (Language)currentElem;
            }
            currentElem = currentElem.eContainer();
        }
    }
    return null;
}
项目:PDFReporter-Studio    文件:EditingAreaHelper.java   
/**
 * Given the current position in the editing area, tries
 * to recover the corresponding actual node.
 * 
 * @return the actual node, <code>null</code> if not possible
 */
public ICompositeNode getActualNode(){
    if(xtextAdapter.getXtextParseResult()!=null){
        int caretOffset = textArea.getCaretOffset();
        EObjectAtOffsetHelper eobjHelper=new EObjectAtOffsetHelper();
        EObject resolvedEObj = eobjHelper.resolveElementAt(xtextAdapter.getFakeResourceContext().getFakeResource(), caretOffset);
        return NodeModelUtils.findActualNodeFor(resolvedEObj);
    }
    return null;
}
项目:CooperateModelingEnvironment    文件:EditorHandlingUtils.java   
public static Optional<EObject> findEObjectAtPosition(XtextEditor editor, ITextSelection selection) {
    Optional<EObjectAtOffsetHelper> helper = determineEPackage(editor)
            .flatMap(InjectingFactoryRegistry.getInstance()::getFactory)
            .map(f -> f.inject(EObjectAtOffsetHelper.class)).map(EObjectAtOffsetHelper.class::cast);
    if (!helper.isPresent()) {
        return Optional.empty();
    }
    return Optional.ofNullable(editor.getDocument().priorityReadOnly(new IUnitOfWork<EObject, XtextResource>() {
        @Override
        public EObject exec(XtextResource resource) throws Exception {
            return helper.get().resolveElementAt(resource, selection.getOffset());
        }
    }));
}
项目:CooperateModelingEnvironment    文件:RenameUMLElementRefactoringHandler.java   
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    try {
        final XtextEditor editor = EditorUtils.getActiveXtextEditor(event);
        Optional<EPackage> ePackage = EditorHandlingUtils.determineEPackage(editor);
        Optional<EObjectAtOffsetHelper> eObjectAtOffsetHelper = ePackage
                .flatMap(InjectingFactoryRegistry.INSTANCE::getFactory)
                .map(f -> f.inject(EObjectAtOffsetHelper.class)).map(EObjectAtOffsetHelper.class::cast);
        if (!eObjectAtOffsetHelper.isPresent()) {
            throw new IllegalStateException("Unable to create required helper classes.");
        }

        if (editor != null) {
            final ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
            EObject selectedEObject = editor.getDocument()
                    .priorityReadOnly(new IUnitOfWork<EObject, XtextResource>() {
                        @Override
                        public EObject exec(XtextResource resource) throws Exception {
                            return eObjectAtOffsetHelper.get().resolveElementAt(resource, selection.getOffset());
                        }
                    });
            startRename(selectedEObject, editor, editor.getShell());
        }
    } catch (OperationCanceledException e) {
        LOGGER.debug("Refactoring operation has been canceled.", e);
    } catch (Exception exc) {
        LOGGER.error("Error initializing refactoring", exc);
        MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error initializing refactoring",
                exc.getMessage() + "\nSee log for details");
    }
    return null;
}
项目:CooperateModelingEnvironment    文件:FocusIUnitOfWork.java   
@Override
public void process(XtextResource state) throws Exception {
    EObjectAtOffsetHelper helper = new EObjectAtOffsetHelper();
    if (offset != -1) {
        focusedElement = helper.resolveContainedElementAt(state, offset);
    }
}
项目:ModelDebugging    文件:AbstractGemocLanguageProjectHandler.java   
protected Language getSelectedLanguage(XtextResource resource, int offset){
    final EObjectAtOffsetHelper eObjectAtOffsetHelper =
        resource.getResourceServiceProvider().get(EObjectAtOffsetHelper.class);
    EObject selectedElement = eObjectAtOffsetHelper.resolveContainedElementAt(resource, offset);
    if (selectedElement != null) {
        EObject currentElem = selectedElement;
        while(currentElem != null){
            if(currentElem instanceof Language){
                return (Language)currentElem;
            }
            currentElem = currentElem.eContainer();
        }
    }
    return null;
}
项目:xtext-extras    文件:DefaultXbaseRuntimeModule.java   
public Class<? extends EObjectAtOffsetHelper> bindEObjectAtOffsetHelper() {
    return BrokenConstructorCallAwareEObjectAtOffsetHelper.class;
}
项目:smaccm    文件:AgreeAnnexContentAssist.java   
protected EObjectAtOffsetHelper getOffsetHelper() {
    if(offsetHelper == null){
        offsetHelper = injector.getInstance(EObjectAtOffsetHelper.class);
    }
    return offsetHelper;
}