org.eclipse.xtext.ui.editor.validation.ValidationJob Java Examples

The following examples show how to use org.eclipse.xtext.ui.editor.validation.ValidationJob. 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 File: OwnResourceValidatorAwareValidatingEditorCallback.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private ValidationJob newValidationJob(final XtextEditor editor) {

		final IXtextDocument document = editor.getDocument();
		final IAnnotationModel annotationModel = editor.getInternalSourceViewer().getAnnotationModel();

		final IssueResolutionProvider issueResolutionProvider = getService(editor, IssueResolutionProvider.class);
		final MarkerTypeProvider markerTypeProvider = getService(editor, MarkerTypeProvider.class);
		final MarkerCreator markerCreator = getService(editor, MarkerCreator.class);

		final IValidationIssueProcessor issueProcessor = new CompositeValidationIssueProcessor(
				new AnnotationIssueProcessor(document, annotationModel, issueResolutionProvider),
				new MarkerIssueProcessor(editor.getResource(), annotationModel, markerCreator, markerTypeProvider));

		return editor.getDocument().modify(resource -> {
			final IResourceServiceProvider serviceProvider = resource.getResourceServiceProvider();
			final IResourceValidator resourceValidator = serviceProvider.getResourceValidator();
			return new ValidationJob(resourceValidator, editor.getDocument(), issueProcessor, ALL);
		});
	}
 
Example #2
Source File: GamlEditor.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
private void scheduleValidationJob() {
	if (!isEditable()) { return; }
	final IValidationIssueProcessor processor = new MarkerIssueProcessor(getResource(),
			getInternalSourceViewer().getAnnotationModel(), markerCreator, markerTypeProvider);
	final ValidationJob validate = new ValidationJob(validator, getDocument(), processor, CheckMode.FAST_ONLY) {
		@Override
		protected IStatus run(final IProgressMonitor monitor) {
			final List<Issue> issues = getDocument().readOnly(resource -> {
				if (resource.isValidationDisabled()) { return Collections.emptyList(); }
				return validator.validate(resource, getCheckMode(), null);
			});
			processor.processIssues(issues, monitor);
			return Status.OK_STATUS;
		}

	};
	validate.schedule();

}
 
Example #3
Source File: ValidateActionHandlerTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testExpensiveMarkerCreation() throws Exception {
	IFile iFile = createFile("foo/bar.testlanguage", "stuff foo");
	XtextEditor xtextEditor = openEditor(iFile);
	IHandlerService handlerService = xtextEditor.getSite().getService(IHandlerService.class);
	handlerService.executeCommand("org.eclipse.xtext.ui.tests.TestLanguage.validate", null);
	closeEditors();
	Job[] find = Job.getJobManager().find(ValidationJob.XTEXT_VALIDATION_FAMILY);
	for (Job job : find) {
		job.join();
	}
	IResource file = xtextEditor.getResource();
	IMarker[] markers = file.findMarkers(MarkerTypes.EXPENSIVE_VALIDATION, true, IResource.DEPTH_ZERO);
	assertEquals(1, markers.length);

}
 
Example #4
Source File: XtextEditor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public <T> T getAdapter(Class<T> adapter) {
	if (IContentOutlinePage.class.isAssignableFrom(adapter)) {
		return adapter.cast(getContentOutlinePage());
	}
	if (ValidationJob.class.equals(adapter)) {
		IXtextDocument document = getDocument();
		return document.getAdapter(adapter);
	}
	return super.getAdapter(adapter);
}
 
Example #5
Source File: XtextDocument.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public <T> T getAdapter(Class<T> adapterType) {
	if (ValidationJob.class.equals(adapterType)) {
		return adapterType.cast(validationJob);
	}
	return IXtextDocument.super.getAdapter(adapterType);
}
 
Example #6
Source File: XtextDocumentProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void disposeElementInfo(Object element, ElementInfo info) {
	if (info.fDocument instanceof XtextDocument) {
		XtextDocument document = (XtextDocument) info.fDocument;
		ValidationJob job = (ValidationJob) document.getValidationJob();
		if (job != null) {
			job.cancel();
		}
		document.disposeInput();
	}
	super.disposeElementInfo(element, info);
}
 
Example #7
Source File: XtextDocumentProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.4
 */
protected void registerAnnotationInfoProcessor(ElementInfo info) {
	XtextDocument doc = (XtextDocument) info.fDocument;
	if(info.fModel != null) {
		AnnotationIssueProcessor annotationIssueProcessor = new AnnotationIssueProcessor(doc, info.fModel,
			issueResolutionProvider);
		ValidationJob job = new ValidationJob(resourceValidator, doc, annotationIssueProcessor, CheckMode.FAST_ONLY);
		doc.setValidationJob(job);
	}
}
 
Example #8
Source File: StyledTextXtextAdapter.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
protected ValidationJob createValidationJob() {
	return new ValidationJob(getValidator(), getXtextDocument(), new AnnotationIssueProcessor(getXtextDocument(),
			getXtextSourceviewer().getAnnotationModel(), getResolutionProvider()), CheckMode.FAST_ONLY);
}
 
Example #9
Source File: StyledTextXtextAdapter.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
protected ValidationJob getValidationJob() {
	return this.validationJob;
}