Java Code Examples for org.eclipse.xtext.util.CancelIndicator

The following examples show how to use org.eclipse.xtext.util.CancelIndicator. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: xtext-xtend   Source File: QuickfixTestBuilder.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public QuickfixTestBuilder create(final String fileName, final String model) {
  try {
    QuickfixTestBuilder _xblockexpression = null;
    {
      final String positionMarker = this.getPositionMarker(model);
      final IFile file = this._workbenchTestHelper.createFile(fileName, model.replace(positionMarker, ""));
      this.editor = this.openEditorSafely(file);
      final IXtextDocument document = this.editor.getDocument();
      Assert.assertNotNull("Error getting document from editor", document);
      final IUnitOfWork<List<Issue>, XtextResource> _function = (XtextResource it) -> {
        return this.issues = this._iResourceValidator.validate(it, CheckMode.NORMAL_AND_FAST, CancelIndicator.NullImpl);
      };
      document.<List<Issue>>readOnly(_function);
      this.caretOffset = model.indexOf(positionMarker);
      _xblockexpression = this;
    }
    return _xblockexpression;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 2
Source Project: xtext-core   Source File: GeneratorComponent.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void invoke(IWorkflowContext ctx) {
	GeneratorDelegate instance = getCompiler();
	IFileSystemAccess2 fileSystemAccess = getConfiguredFileSystemAccess();
	for (String slot : slotNames) {
		Object object = ctx.get(slot);
		if (object == null) {
			throw new IllegalStateException("Slot '"+slot+"' was empty!");
		}
		if (object instanceof Iterable) {
			Iterable<?> iterable = (Iterable<?>) object;
			for (Object object2 : iterable) {
				if (!(object2 instanceof Resource)) {
					throw new IllegalStateException("Slot contents was not a Resource but a '"+object.getClass().getSimpleName()+"'!");
				}
				GeneratorContext context = new GeneratorContext();
				context.setCancelIndicator(CancelIndicator.NullImpl);
				instance.generate((Resource) object2, fileSystemAccess, context);
			}
		} else if (object instanceof Resource) {
			instance.doGenerate((Resource) object, fileSystemAccess);
		} else {
			throw new IllegalStateException("Slot contents was not a Resource but a '"+object.getClass().getSimpleName()+"'!");
		}
	}
}
 
Example 3
Source Project: n4js   Source File: ResourceLoadingStatistics.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private FileLoadInfo investigate(IN4JSProject project, URI fileURI, IProgressMonitor monitor) {
	final CancelIndicator cancelIndicator = new MonitorBasedCancelIndicator(monitor);
	operationCanceledManager.checkCanceled(cancelIndicator);

	final ResourceSet resSet = n4jsCore.createResourceSet(Optional.of(project));
	final N4JSResource res = (N4JSResource) resSet.createResource(fileURI);
	try {
		res.load(Collections.emptyMap());
	} catch (IOException e) {
		e.printStackTrace();
	}
	res.getContents(); // trigger loading of AST
	res.resolveLazyCrossReferences(cancelIndicator);

	// now start counting what was loaded incidentally ...
	return investigate(resSet);
}
 
Example 4
Source Project: n4js   Source File: PostProcessingAwareResource.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private void doMainPostProcessing(CancelIndicator cancelIndicator) {
	try {
		postProcessingThrowable = null;
		isPostProcessing = true;

		if (postProcessor == null) {
			throw new IllegalStateException("post processor is null");
		}
		if (postProcessor.expectsLazyLinkResolution()) {
			// in next line: call on 'super' because the method in 'this' forwards here!!
			super.resolveLazyCrossReferences(cancelIndicator);
		}

		postProcessor.performPostProcessing(this, cancelIndicator);

	} catch (Throwable th) {
		markAsPostProcessingDone();
		postProcessingThrowable = th;
		throw th;
	}
}
 
Example 5
Source Project: xtext-extras   Source File: XbaseInterpreter.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected Object _doEvaluate(XBasicForLoopExpression forLoop, IEvaluationContext context, CancelIndicator indicator) {
	IEvaluationContext forkedContext = context.fork();
	for (XExpression initExpression : forLoop.getInitExpressions()) {
		internalEvaluate(initExpression, forkedContext, indicator);
	}
	XExpression expression = forLoop.getExpression();
	Object condition = expression == null ? Boolean.TRUE : internalEvaluate(expression, forkedContext, indicator);
	while (Boolean.TRUE.equals(condition)) {
		internalEvaluate(forLoop.getEachExpression(), forkedContext, indicator);
		for (XExpression updateExpression : forLoop.getUpdateExpressions()) {
			internalEvaluate(updateExpression, forkedContext, indicator);
		}
		condition = expression == null ? Boolean.TRUE : internalEvaluate(expression, forkedContext, indicator);
	}
	return null;
}
 
Example 6
protected void computeReferencedJvmTypeHighlighting(IHighlightedPositionAcceptor acceptor, EObject referencer,
		CancelIndicator cancelIndicator) {
	for (EReference reference : referencer.eClass().getEAllReferences()) {
		EClass referencedType = reference.getEReferenceType();
		if (EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_TYPE, referencedType)) {
			List<EObject> referencedObjects = EcoreUtil2.getAllReferencedObjects(referencer, reference);
			if (referencedObjects.size() > 0)
				operationCanceledManager.checkCanceled(cancelIndicator);
			for (EObject referencedObject : referencedObjects) {
				EObject resolvedReferencedObject = EcoreUtil.resolve(referencedObject, referencer);
				if (resolvedReferencedObject != null && !resolvedReferencedObject.eIsProxy()) {
					highlightReferenceJvmType(acceptor, referencer, reference, resolvedReferencedObject);
				}
			}
		}
	}
}
 
Example 7
Source Project: statecharts   Source File: RenameElementHandler.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	NamedElement element = refactoring.getContextObject();
	if (element != null) {
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

		List<Issue> issues = validator.validate(element.eResource(), CheckMode.NORMAL_AND_FAST,
				CancelIndicator.NullImpl);
		Stream<Issue> errors = issues.stream().filter(issue -> issue.getSeverity() == Severity.ERROR);

		RenameDialog dialog = new RenameDialog(window.getShell(), "Rename..", "Please enter new name: ",
				element.getName(), new NameUniquenessValidator(element), errors.count() > 0);

		if (dialog.open() == Window.OK) {
			String newName = dialog.getNewName();
			if (newName != null) {
				((RenameRefactoring) refactoring).setNewName(newName);
				refactoring.execute();
			}
		}

	}
	return null;
}
 
Example 8
protected Map<String, List<Diagnostic>> getDiagnostics() {
  try {
    final Function1<CancelIndicator, HashMap<String, List<Diagnostic>>> _function = (CancelIndicator it) -> {
      final HashMap<String, List<Diagnostic>> result = CollectionLiterals.<String, List<Diagnostic>>newHashMap();
      final Function1<Pair<String, Object>, Object> _function_1 = (Pair<String, Object> it_1) -> {
        return it_1.getValue();
      };
      Iterable<PublishDiagnosticsParams> _filter = Iterables.<PublishDiagnosticsParams>filter(ListExtensions.<Pair<String, Object>, Object>map(this.notifications, _function_1), PublishDiagnosticsParams.class);
      for (final PublishDiagnosticsParams diagnostic : _filter) {
        result.put(diagnostic.getUri(), diagnostic.getDiagnostics());
      }
      return result;
    };
    return this.languageServer.getRequestManager().<HashMap<String, List<Diagnostic>>>runRead(_function).get();
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 9
Source Project: xtext-core   Source File: LazyLinkingResource.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * resolves any lazy cross references in this resource, adding Issues for unresolvable elements to this resource.
 * This resource might still contain resolvable proxies after this method has been called.
 * 
 * @param mon a {@link CancelIndicator} can be used to stop the resolution.
 */
public void resolveLazyCrossReferences(final CancelIndicator mon) {
	final CancelIndicator monitor = mon == null ? CancelIndicator.NullImpl : mon;
	TreeIterator<Object> iterator = EcoreUtil.getAllContents(this, true);
	while (iterator.hasNext()) {
		operationCanceledManager.checkCanceled(monitor);
		InternalEObject source = (InternalEObject) iterator.next();
		EStructuralFeature[] eStructuralFeatures = ((EClassImpl.FeatureSubsetSupplier) source.eClass()
				.getEAllStructuralFeatures()).crossReferences();
		if (eStructuralFeatures != null) {
			for (EStructuralFeature crossRef : eStructuralFeatures) {
				operationCanceledManager.checkCanceled(monitor);
				resolveLazyCrossReference(source, crossRef);
			}
		}
	}
}
 
Example 10
Source Project: n4js   Source File: XLanguageServerImpl.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void didRefreshOpenFile(OpenFileContext ofc, CancelIndicator ci) {
	if (client instanceof LanguageClientExtensions) {

		LanguageClientExtensions clientExtensions = (LanguageClientExtensions) client;
		XtextResource resource = ofc.getResource();
		IResourceServiceProvider resourceServiceProvider = resource.getResourceServiceProvider();
		IColoringService coloringService = resourceServiceProvider.get(IColoringService.class);

		if (coloringService != null) {
			XDocument doc = ofc.getDocument();
			List<? extends ColoringInformation> colInfos = coloringService.getColoring(resource, doc);

			if (!IterableExtensions.isNullOrEmpty(colInfos)) {
				String uri = resource.getURI().toString();
				ColoringParams colParams = new ColoringParams(uri, colInfos);
				clientExtensions.updateColoring(colParams);
			}
		}
	}

	ILanguageServerAccess.Context ctx = new ILanguageServerAccess.Context(ofc.getResource(), ofc.getDocument(),
			true, ci);
	semanticHighlightingRegistry.update(ctx);
}
 
Example 11
Source Project: xtext-core   Source File: RequestManagerTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test(timeout = 1000)
public void testRunWriteLogExceptionCancellable() {
  final Runnable _function = () -> {
    final Function0<Object> _function_1 = () -> {
      throw new RuntimeException();
    };
    final Function2<CancelIndicator, Object, Object> _function_2 = (CancelIndicator $0, Object $1) -> {
      return null;
    };
    final CompletableFuture<Object> future = this.requestManager.<Object, Object>runWrite(_function_1, _function_2);
    try {
      future.join();
    } catch (final Throwable _t) {
      if (_t instanceof Exception) {
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  };
  final LoggingTester.LogCapture logResult = LoggingTester.captureLogging(Level.ALL, WriteRequest.class, _function);
  logResult.assertLogEntry("Error during request:");
}
 
Example 12
Source Project: xtext-xtend   Source File: LinkingTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testBug345433_01() throws Exception {
	String classAsString = 
		"import static extension org.eclipse.xtext.GrammarUtil.*\n" +
		"class Foo {" +
		"	org.eclipse.xtext.Grammar grammar\n" +
		"	def function1() {\n" + 
		"		grammar.containedRuleCalls.filter(e | " +
		"			!e.isAssigned() && !e.isEObjectRuleCall()" +
		"		).map(e | e.rule)\n" + 
		"	}\n" +
		"	def function2() {\n" +
		"		newArrayList(function1().head())\n" +
		"	}\n" +
		"}";
	XtendClass clazz = clazz(classAsString);
	IResourceValidator validator = ((XtextResource) clazz.eResource()).getResourceServiceProvider().getResourceValidator();
	List<Issue> issues = validator.validate(clazz.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
	assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
	XtendFunction function1 = (XtendFunction) clazz.getMembers().get(1);
	JvmOperation operation1 = associator.getDirectlyInferredOperation(function1);
	assertEquals("java.lang.Iterable<org.eclipse.xtext.AbstractRule>", operation1.getReturnType().getIdentifier());
	XtendFunction function2 = (XtendFunction) clazz.getMembers().get(2);
	JvmOperation operation2 = associator.getDirectlyInferredOperation(function2);
	assertEquals("java.util.ArrayList<org.eclipse.xtext.AbstractRule>", operation2.getReturnType().getIdentifier());
}
 
Example 13
Source Project: xtext-web   Source File: ContentAssistService.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Apply a text update and then create content assist proposals. This document
 * read operation is scheduled with higher priority, so currently running
 * operations may be canceled. The document processing is rescheduled as
 * background work afterwards.
 */
public ContentAssistResult createProposalsWithUpdate(XtextWebDocumentAccess document, String deltaText,
		int deltaOffset, int deltaReplaceLength, ITextRegion selection, int caretOffset, int proposalsLimit)
		throws InvalidRequestException {
	String[] stateIdWrapper = new String[1];
	ContentAssistContext[] contexts = document
			.modify(new CancelableUnitOfWork<ContentAssistContext[], IXtextWebDocument>() {
				@Override
				public ContentAssistContext[] exec(IXtextWebDocument it, CancelIndicator cancelIndicator)
						throws Exception {
					it.setDirty(true);
					it.createNewStateId();
					stateIdWrapper[0] = it.getStateId();
					it.updateText(deltaText, deltaOffset, deltaReplaceLength);
					return getContexts(it, selection, caretOffset);
				}
			});
	List<ContentAssistContext> contextsList = Arrays.asList(contexts);
	return createProposals(contextsList, stateIdWrapper[0], proposalsLimit);
}
 
Example 14
Source Project: xtext-extras   Source File: XbaseInterpreter.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected Object _doEvaluate(XListLiteral literal, IEvaluationContext context, CancelIndicator indicator) {
	IResolvedTypes resolveTypes = typeResolver.resolveTypes(literal);
	LightweightTypeReference type = resolveTypes.getActualType(literal);
	List<Object> list = newArrayList();
	for(XExpression element: literal.getElements()) {
		if (indicator.isCanceled())
			throw new InterpreterCanceledException();
		list.add(internalEvaluate(element, context, indicator));
	}
	if(type != null && type.isArray()) {
		try {
			LightweightTypeReference componentType = type.getComponentType();
			return Conversions.unwrapArray(list, getJavaType(componentType.getType()));
		} catch (ClassNotFoundException e) {
		}
	}
	return Collections.unmodifiableList(list);
}
 
Example 15
Source Project: n4js   Source File: N4JSCodeActionService.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Applies all fixes of the same kind to the project containing the given URI.
 */
public WorkspaceEdit applyToProject(URI uri, String issueCode, String fixId, CancelIndicator cancelIndicator) {

	WorkspaceEdit result = new WorkspaceEdit();
	QuickFixImplementation quickfix = findOriginatingQuickfix(issueCode, fixId);
	if (quickfix == null) {
		return result;
	}

	Optional<? extends IN4JSProject> project = n4jsCore.findProject(uri);
	if (!project.isPresent()) {
		return result;
	}
	List<URI> urisInProject = Lists.newArrayList(
			IterableExtensions.flatMap(project.get().getSourceContainers(), sc -> sc));

	Map<String, List<TextEdit>> allEdits = new HashMap<>();
	for (URI currURI : urisInProject) {
		Map<String, List<TextEdit>> edits = doApplyToFile(currURI, issueCode, quickfix, cancelIndicator);
		allEdits.putAll(edits);
	}
	result.setChanges(allEdits);
	return result;
}
 
Example 16
Source Project: statecharts   Source File: SCTResourceTest.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testLinkingError1() throws Exception {
	Statechart statechart = createStatechart("internal: event Event1");
	res.getContents().add(statechart);
	Transition transition = createTransition("Event2 [true] / 3 * 3");
	res.getContents().add(transition);
	res.resolveLazyCrossReferences(CancelIndicator.NullImpl);
	System.out.println(res.getLinkingDiagnostics());
	assertEquals(1, res.getLinkingDiagnostics().size());
}
 
Example 17
@Override
public Collection<FoldedPosition> getFoldingRegions(final IXtextDocument xtextDocument) {
	return xtextDocument.tryReadOnly(new CancelableUnitOfWork<Collection<FoldedPosition>, XtextResource>() {
		@Override
		public Collection<FoldedPosition> exec(XtextResource xtextResource, CancelIndicator cancelIndicator)
				throws Exception {
			try {
				DefaultFoldingRegionProvider.this.cancelIndicator = cancelIndicator;
				return doGetFoldingRegions(xtextDocument, xtextResource);
			} finally {
				DefaultFoldingRegionProvider.this.cancelIndicator = null;
			}
		}
	}, () -> Collections.emptyList());
}
 
Example 18
Source Project: xtext-core   Source File: EcoreUtil2.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public static void resolveAll(Resource resource, CancelIndicator monitor) {
	for (Iterator<EObject> i = resource.getAllContents(); i.hasNext();) {
		if (monitor.isCanceled())
			throw new OperationCanceledException();
		EObject eObject = i.next();
		resolveCrossReferences(eObject, monitor);
	}
}
 
Example 19
Source Project: xtext-extras   Source File: XbaseInterpreter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected Object evaluateGetAndAssign(XAbstractFeatureCall featureCall, IEvaluationContext context, CancelIndicator indicator) {
	XAbstractFeatureCall operand = (XAbstractFeatureCall) featureCall.getActualArguments().get(0);
	
	Object originalValue = internalEvaluate(operand, context, indicator);
	Object value = applyGetAndAssignOperator(originalValue, featureCall.getConcreteSyntaxFeatureName());
	
	assignValueTo(operand.getFeature(), featureCall, value, context, indicator);
	return originalValue;
}
 
Example 20
Source Project: xtext-core   Source File: XtextValidationTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testMissingArgument() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" +
			"generate metamodel 'myURI'\n" +
			"Model: rule=Rule<First=true, Second=false>;\n" + 
			"Rule<First, Missing, Second>: name=ID;");

	IResourceValidator validator = get(IResourceValidator.class);
	List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
	assertEquals(issues.toString(), 1, issues.size());
	assertEquals("Missing argument for parameter Missing", issues.get(0).getMessage());
}
 
Example 21
Source Project: n4js   Source File: N4JSMarkerUpdater.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private void updateMarkersForExternalLibraries(Delta delta, ResourceSet resourceSet, IProgressMonitor monitor) {
	URI uri = delta.getUri();
	if (n4jsCore.isNoValidate(uri)) {
		return;
	}

	Resource resource = resourceSet.getResource(uri, true);
	IResourceValidator validator = getValidator(resource);
	IN4JSProject prj = n4jsCore.findProject(uri).orNull();
	CancelIndicator cancelIndicator = getCancelIndicator(monitor);

	if (prj != null && prj.isExternal() && prj.exists() && prj instanceof N4JSEclipseProject && uri.isFile()) {
		// transform file uri in workspace iResource
		IFile file = URIUtils.convertFileUriToPlatformFile(uri);

		if (file != null && resource != null) {
			List<Issue> list = validator.validate(resource, CheckMode.NORMAL_AND_FAST, cancelIndicator);

			if (SHOW_ONLY_EXTERNAL_ERRORS) {
				for (Iterator<Issue> iter = list.iterator(); iter.hasNext();) {
					if (iter.next().getSeverity() != Severity.ERROR) {
						iter.remove();
					}
				}
			}

			try {
				validatorExtension.createMarkers(file, resource, list);
			} catch (CoreException e) {
				e.printStackTrace();
			}
		}
	}
}
 
Example 22
Source Project: xtext-core   Source File: LanguageServerImpl.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.21
 */
@Override
public void didChangeWorkspaceFolders(DidChangeWorkspaceFoldersParams params) {
	requestManager.runWrite(() -> {
		workspaceManager.didChangeWorkspaceFolders(params, CancelIndicator.NullImpl);
		return null;
	}, (a, b) -> null);
}
 
Example 23
public AbstractExpectationTest expects(final String input) {
  try {
    this.rootExpression = this.expression(input, false);
    this.getResolver().initializeFrom(this.rootExpression);
    this.resolvedTypes = this.getResolver().reentrantResolve(CancelIndicator.NullImpl);
    this.pendingAssert = true;
    return this;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 24
Source Project: n4js   Source File: XLanguageServerImpl.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Compute the references. Executed in read request.
 */
protected List<? extends Location> references(OpenFileContext ofc, ReferenceParams params,
		CancelIndicator cancelIndicator) {
	URI uri = ofc.getURI();
	DocumentSymbolService documentSymbolService = getService(uri, DocumentSymbolService.class);
	if ((documentSymbolService == null)) {
		return Collections.emptyList();
	}
	XtextResource res = ofc.getResource();
	XDocument doc = ofc.getDocument();
	return documentSymbolService.getReferences(doc, res, params, resourceAccess,
			openFilesManager.createLiveScopeIndex(), cancelIndicator);
}
 
Example 25
Source Project: n4js   Source File: XLanguageServerImpl.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Convert the given params to an enriched instance of options.
 */
public ICodeActionService2.Options toOptions(CodeActionParams params, XDocument doc, XtextResource res,
		CancelIndicator cancelIndicator) {

	ICodeActionService2.Options options = new ICodeActionService2.Options();
	options.setDocument(doc);
	options.setResource(res);
	options.setLanguageServerAccess(access);
	options.setCodeActionParams(params);
	options.setCancelIndicator(cancelIndicator);
	return options;
}
 
Example 26
Source Project: n4js   Source File: XLanguageServerImpl.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Compute the code lenses.
 */
protected List<? extends CodeLens> codeLens(OpenFileContext ofc, CodeLensParams params,
		CancelIndicator cancelIndicator) {
	URI uri = ofc.getURI();
	ICodeLensService codeLensService = getService(uri, ICodeLensService.class);
	if ((codeLensService == null)) {
		return Collections.emptyList();
	}
	XtextResource res = ofc.getResource();
	XDocument doc = ofc.getDocument();
	List<? extends CodeLens> result = codeLensService.computeCodeLenses(doc, res, params, cancelIndicator);
	installURI(result, uri.toString());
	return result;
}
 
Example 27
Source Project: sarl   Source File: SARLCodeMiningProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void createCodeMinings(IDocument document, XtextResource resource, CancelIndicator indicator,
		IAcceptor<? super ICodeMining> acceptor) throws BadLocationException {
	createImplicitActionReturnType(resource, acceptor);
	createImplicitFieldType(resource, acceptor);
	createImplicitVariableType(resource, acceptor);
}
 
Example 28
Source Project: n4js   Source File: XLanguageServerImpl.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Create the text edits for the formatter. Executed in a read request.
 */
protected List<? extends TextEdit> rangeFormatting(OpenFileContext ofc, DocumentRangeFormattingParams params,
		CancelIndicator cancelIndicator) {
	URI uri = ofc.getURI();
	FormattingService formatterService = getService(uri, FormattingService.class);
	if ((formatterService == null)) {
		return Collections.emptyList();
	}
	XtextResource res = ofc.getResource();
	XDocument doc = ofc.getDocument();
	return formatterService.format(doc, res, params, cancelIndicator);
}
 
Example 29
Source Project: statecharts   Source File: SCTResourceTest.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testRemoveOrphanedLinkingDiagnostics() throws Exception {
	Statechart statechart = createStatechart("internal: event Event1");
	res.getContents().add(statechart);
	Transition transition = createTransition("Event2 [true] / 3 * 3");
	res.getContents().add(transition);
	res.resolveLazyCrossReferences(CancelIndicator.NullImpl);
	assertEquals(1, res.getLinkingDiagnostics().size());
	transition.setSpecification("Event1 [true] / 3 * 3");
	res.resolveLazyCrossReferences(CancelIndicator.NullImpl);
	assertEquals(0, res.getLinkingDiagnostics().size());
}
 
Example 30
Source Project: n4js   Source File: IssuesProvider.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("javadoc")
public IssuesProvider(IResourceValidator resourceValidator, Resource res, CheckMode checkMode,
		OperationCanceledManager operationCanceledManager, CancelIndicator ci) {
	this.rv = resourceValidator;
	this.r = res;
	this.checkMode = checkMode;
	this.operationCanceledManager = operationCanceledManager;
	this.ci = ci;
}