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);
}
}
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;
}
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();
}
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);
}
}
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);
}
Aggregations