Search in sources :

Example 6 with CancelIndicator

use of org.eclipse.xtext.util.CancelIndicator in project xtext-core by eclipse.

the class OutdatedStateManager method exec.

public <R extends Object, P extends Resource> R exec(final IUnitOfWork<R, P> work, final P param) {
    try {
        R _xblockexpression = null;
        {
            final Boolean wasCancelationAllowed = this.cancelationAllowed.get();
            R _xtrycatchfinallyexpression = null;
            try {
                R _xblockexpression_1 = null;
                {
                    if ((work instanceof CancelableUnitOfWork<?, ?>)) {
                        CancelIndicator _xifexpression = null;
                        if ((param == null)) {
                            final CancelIndicator _function = () -> {
                                return true;
                            };
                            _xifexpression = _function;
                        } else {
                            _xifexpression = this.newCancelIndicator(param.getResourceSet());
                        }
                        ((CancelableUnitOfWork<?, ?>) work).setCancelIndicator(_xifexpression);
                    } else {
                        this.cancelationAllowed.set(Boolean.valueOf(false));
                    }
                    _xblockexpression_1 = work.exec(param);
                }
                _xtrycatchfinallyexpression = _xblockexpression_1;
            } finally {
                this.cancelationAllowed.set(wasCancelationAllowed);
            }
            _xblockexpression = _xtrycatchfinallyexpression;
        }
        return _xblockexpression;
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : CancelableUnitOfWork(org.eclipse.xtext.util.concurrent.CancelableUnitOfWork) CancelIndicator(org.eclipse.xtext.util.CancelIndicator)

Example 7 with CancelIndicator

use of org.eclipse.xtext.util.CancelIndicator in project xtext-xtend by eclipse.

the class OverrideIndicatorModelListener method updateAnnotationModel.

private IStatus updateAnnotationModel(IProgressMonitor monitor) {
    if (xtextEditor == null || xtextEditor.getDocument() == null || xtextEditor.getInternalSourceViewer().getAnnotationModel() == null) {
        return Status.OK_STATUS;
    }
    IXtextDocument xtextDocument = xtextEditor.getDocument();
    IAnnotationModel annotationModel = xtextEditor.getInternalSourceViewer().getAnnotationModel();
    Map<Annotation, Position> annotationToPosition = xtextDocument.readOnly(new CancelableUnitOfWork<Map<Annotation, Position>, XtextResource>() {

        @Override
        public Map<Annotation, Position> exec(XtextResource xtextResource, CancelIndicator cancelIndicator) {
            if (xtextResource == null)
                return Collections.emptyMap();
            return createOverrideIndicatorAnnotationMap(xtextResource, cancelIndicator);
        }
    });
    if (monitor.isCanceled())
        return Status.CANCEL_STATUS;
    if (annotationModel instanceof IAnnotationModelExtension) {
        IAnnotationModelExtension annotationModelExtension = (IAnnotationModelExtension) annotationModel;
        Object lockObject = getLockObject(annotationModel);
        synchronized (lockObject) {
            annotationModelExtension.replaceAnnotations(overrideIndicatorAnnotations.toArray(new Annotation[overrideIndicatorAnnotations.size()]), annotationToPosition);
        }
        overrideIndicatorAnnotations = annotationToPosition.keySet();
    }
    return Status.OK_STATUS;
}
Also used : Position(org.eclipse.jface.text.Position) XtextResource(org.eclipse.xtext.resource.XtextResource) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) EObject(org.eclipse.emf.ecore.EObject) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) Map(java.util.Map) Annotation(org.eclipse.jface.text.source.Annotation) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 8 with CancelIndicator

use of org.eclipse.xtext.util.CancelIndicator in project xtext-xtend by eclipse.

the class ExtractMethodRefactoring method checkInitialConditions.

@Override
public RefactoringStatus checkInitialConditions(final IProgressMonitor pm) throws CoreException, OperationCanceledException {
    StatusWrapper status = statusProvider.get();
    IResolvedTypes resolvedTypes = typeResolver.resolveTypes(firstExpression, new CancelIndicator() {

        @Override
        public boolean isCanceled() {
            return pm.isCanceled();
        }
    });
    try {
        Set<String> calledExternalFeatureNames = newHashSet();
        returnType = calculateReturnType(resolvedTypes);
        if (returnType != null && !equal("void", returnType.getIdentifier()))
            returnExpression = lastExpression;
        boolean isReturnAllowed = isEndOfOriginalMethod();
        for (EObject element : EcoreUtil2.eAllContents(originalMethod.getExpression())) {
            if (pm.isCanceled()) {
                throw new OperationCanceledException();
            }
            boolean isLocalExpression = EcoreUtil.isAncestor(expressions, element);
            if (element instanceof XFeatureCall) {
                XFeatureCall featureCall = (XFeatureCall) element;
                JvmIdentifiableElement feature = featureCall.getFeature();
                LightweightTypeReference featureType = resolvedTypes.getActualType(featureCall);
                boolean isLocalFeature = EcoreUtil.isAncestor(expressions, feature);
                if (!isLocalFeature && isLocalExpression) {
                    // call-out
                    if (feature instanceof JvmFormalParameter || feature instanceof XVariableDeclaration) {
                        if (!calledExternalFeatureNames.contains(feature.getSimpleName())) {
                            calledExternalFeatureNames.add(feature.getSimpleName());
                            ParameterInfo parameterInfo = new ParameterInfo(featureType.getIdentifier(), feature.getSimpleName(), parameterInfos.size());
                            parameterInfos.add(parameterInfo);
                            parameter2type.put(parameterInfo, featureType);
                        }
                        externalFeatureCalls.put(feature.getSimpleName(), featureCall);
                    }
                } else if (isLocalFeature && !isLocalExpression) {
                    // call-in
                    if (returnExpression != null) {
                        status.add(RefactoringStatus.FATAL, "Ambiguous return value: Multiple local variables are accessed in subsequent code.");
                        break;
                    }
                    returnExpression = featureCall;
                    returnType = featureType;
                }
            } else if (isLocalExpression) {
                if (element instanceof XReturnExpression && !isReturnAllowed) {
                    status.add(RefactoringStatus.FATAL, "Extracting method would break control flow due to return statements.");
                    break;
                } else if (element instanceof JvmTypeReference) {
                    JvmType type = ((JvmTypeReference) element).getType();
                    if (type instanceof JvmTypeParameter) {
                        JvmOperation operation = associations.getDirectlyInferredOperation(originalMethod);
                        if (operation != null) {
                            List<JvmTypeParameter> typeParameters = operation.getTypeParameters();
                            if (typeParameters.contains(type))
                                neededTypeParameters.add((JvmTypeParameter) type);
                        }
                    }
                } else if (element instanceof JvmFormalParameter)
                    localFeatureNames.add(((JvmFormalParameter) element).getName());
                else if (element instanceof XVariableDeclaration)
                    localFeatureNames.add(((XVariableDeclaration) element).getIdentifier());
            }
        }
    } catch (OperationCanceledException e) {
        throw e;
    } catch (Exception exc) {
        handleException(exc, status);
    }
    return status.getRefactoringStatus();
}
Also used : XVariableDeclaration(org.eclipse.xtext.xbase.XVariableDeclaration) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) StatusWrapper(org.eclipse.xtext.ui.refactoring.impl.StatusWrapper) RichString(org.eclipse.xtend.core.xtend.RichString) ParameterInfo(org.eclipse.jdt.internal.corext.refactoring.ParameterInfo) JvmType(org.eclipse.xtext.common.types.JvmType) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) BadLocationException(org.eclipse.jface.text.BadLocationException) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) EObject(org.eclipse.emf.ecore.EObject) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) XReturnExpression(org.eclipse.xtext.xbase.XReturnExpression)

Example 9 with CancelIndicator

use of org.eclipse.xtext.util.CancelIndicator in project xtext-xtend by eclipse.

the class DirtyStateEditorValidationTest method testChangedOverriddenSignature.

@Test
public void testChangedOverriddenSignature() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("interface Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def void bar()");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final String interface_ = _builder.toString();
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("interface Foo {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("def void bar(String b)");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        final String interfaceChanged = _builder_1.toString();
        StringConcatenation _builder_2 = new StringConcatenation();
        _builder_2.append("class Bar implements Foo {");
        _builder_2.newLine();
        _builder_2.append("\t");
        _builder_2.append("override bar() {}");
        _builder_2.newLine();
        _builder_2.append("}");
        _builder_2.newLine();
        final String class_ = _builder_2.toString();
        final IFile interfaceFile = this.helper.createFile("Foo.xtend", interface_);
        final IFile classFile = this.helper.createFile("Bar.xtend", class_);
        this._syncUtil.waitForBuild(null);
        Assert.assertEquals(0, classFile.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE).length);
        final XtextEditor interfaceEditor = this.helper.openEditor(interfaceFile);
        final XtextEditor classEditor = this.helper.openEditor(classFile);
        this.assertNumberOfErrorAnnotations(classEditor, 0);
        interfaceEditor.getDocument().set(interfaceChanged);
        this._syncUtil.waitForReconciler(interfaceEditor);
        this._syncUtil.waitForReconciler(classEditor);
        final IUnitOfWork<Object, XtextResource> _function = (XtextResource it) -> {
            final CancelIndicator _function_1 = () -> {
                return false;
            };
            final List<Issue> issues = this.validator.validate(it, CheckMode.NORMAL_AND_FAST, _function_1);
            Assert.assertEquals(issues.toString(), 2, issues.size());
            return null;
        };
        classEditor.getDocument().<Object>readOnly(_function);
        interfaceEditor.getDocument().set(interface_);
        this._syncUtil.waitForReconciler(interfaceEditor);
        this._syncUtil.waitForReconciler(classEditor);
        final IUnitOfWork<Object, XtextResource> _function_1 = (XtextResource it) -> {
            final CancelIndicator _function_2 = () -> {
                return false;
            };
            final List<Issue> issues = this.validator.validate(it, CheckMode.NORMAL_AND_FAST, _function_2);
            Assert.assertTrue(issues.toString(), issues.isEmpty());
            return null;
        };
        classEditor.getDocument().<Object>readOnly(_function_1);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtextResource(org.eclipse.xtext.resource.XtextResource) List(java.util.List) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) Test(org.junit.Test)

Example 10 with CancelIndicator

use of org.eclipse.xtext.util.CancelIndicator in project xtext-core by eclipse.

the class LanguageServerImpl method didChange.

@Override
public void didChange(final DidChangeTextDocumentParams params) {
    final Function0<BuildManager.Buildable> _function = () -> {
        final Function1<TextDocumentContentChangeEvent, TextEdit> _function_1 = (TextDocumentContentChangeEvent event) -> {
            Range _range = event.getRange();
            String _text = event.getText();
            return new TextEdit(_range, _text);
        };
        return this.workspaceManager.didChange(this._uriExtensions.toUri(params.getTextDocument().getUri()), params.getTextDocument().getVersion(), ListExtensions.<TextDocumentContentChangeEvent, TextEdit>map(params.getContentChanges(), _function_1));
    };
    final Function2<CancelIndicator, BuildManager.Buildable, List<IResourceDescription.Delta>> _function_1 = (CancelIndicator cancelIndicator, BuildManager.Buildable buildable) -> {
        return buildable.build(cancelIndicator);
    };
    this.requestManager.<BuildManager.Buildable, List<IResourceDescription.Delta>>runWrite(_function, _function_1);
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Range(org.eclipse.lsp4j.Range) TextDocumentContentChangeEvent(org.eclipse.lsp4j.TextDocumentContentChangeEvent) TextEdit(org.eclipse.lsp4j.TextEdit) BuildManager(org.eclipse.xtext.ide.server.BuildManager) ArrayList(java.util.ArrayList) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) CancelIndicator(org.eclipse.xtext.util.CancelIndicator)

Aggregations

CancelIndicator (org.eclipse.xtext.util.CancelIndicator)18 URI (org.eclipse.emf.common.util.URI)5 List (java.util.List)4 EObject (org.eclipse.emf.ecore.EObject)4 XtextResource (org.eclipse.xtext.resource.XtextResource)4 BuildManager (org.eclipse.xtext.ide.server.BuildManager)3 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)3 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 IFile (org.eclipse.core.resources.IFile)2 CompletionList (org.eclipse.lsp4j.CompletionList)2 ICodeLensResolver (org.eclipse.xtext.ide.server.codelens.ICodeLensResolver)2 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)2 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)2 Function2 (org.eclipse.xtext.xbase.lib.Functions.Function2)2 Binder (com.google.inject.Binder)1 AnnotatedBindingBuilder (com.google.inject.binder.AnnotatedBindingBuilder)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1