Java Code Examples for org.eclipse.xtext.ui.editor.model.XtextDocument#set()

The following examples show how to use org.eclipse.xtext.ui.editor.model.XtextDocument#set() . 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: Bug297909Test.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testReconcileDocument() throws Exception {
	Injector injector = doGetSetup().createInjectorAndDoEMFRegistration();
	XtextDocument document = injector.getInstance(XtextDocument.class);
	document.setValidationJob(new Job("Job") {
		@Override
		protected IStatus run(IProgressMonitor monitor) {
			return Status.OK_STATUS;
		}
	});
	XtextResource resource = injector.getInstance(XtextResource.class);
	XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
	resourceSet.getResources().add(resource);
	resource.load(new StringInputStream(""), Collections.singletonMap(XtextResource.OPTION_ENCODING, Charset.defaultCharset().name()));
	document.setInput(resource);
	document.set("abstract rules firstRule");
	XtextDocumentReconcileStrategy strategy = injector.getInstance(XtextDocumentReconcileStrategy.class);
	strategy.setDocument(document);
	strategy.setResource(resource);
	try {
		strategy.reconcile(new ReconcilerReplaceRegion(0, document.getLength(), document.get()));
		fail("Expected ParseException");
	} catch(ParseException expected) {
		assertTrue(expected.getMessage().contains("Make sure the EPackage has been registered"));
	}
}
 
Example 2
Source File: XtextDocumentModifyTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private IXtextDocument createDocument(String model) throws Exception {
	resource = getResource(new StringInputStream(model));
	DocumentTokenSource tokenSource = new DocumentTokenSource();
	tokenSource.setLexer(new Provider<Lexer>(){
		@Override
		public Lexer get() {
			return new InternalXtextLexer();
		}});
	
	final XtextDocument document = new XtextDocument(tokenSource, get(ITextEditComposer.class), new OutdatedStateManager(), new OperationCanceledManager()) {
		@Override
		public <T> T internalModify(IUnitOfWork<T, XtextResource> work) {
			try {
				return work.exec((XtextResource) resource);
			}
			catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
	};
	document.set(model);
	return document;
}
 
Example 3
Source File: DocumentPartitionerTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public XtextDocument getDocument(String s) {
	TerminalsTokenTypeToPartitionMapper mapper = new TerminalsTokenTypeToPartitionMapper() {{
		setTokenDefProvider(new AntlrTokenDefProvider() {
			{
				setAntlrTokenFileProvider(new XtextAntlrTokenFileProvider());
			}
		});
	}};
	PartitionTokenScanner scanner = new PartitionTokenScanner();
	scanner.setMapper(mapper);
	DocumentPartitioner partitioner = new DocumentPartitioner(scanner, mapper);
	DocumentTokenSource tokenSource = new DocumentTokenSource();
	tokenSource.setLexer(new Provider<Lexer>() {
		@Override
		public Lexer get() {
			return new org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer();
		}
	});
	XtextDocument document = new XtextDocument(tokenSource, null, new OutdatedStateManager(), new OperationCanceledManager());
	document.setDocumentPartitioner(partitioner);
	partitioner.connect(document);
	document.set(s);
	return document;
}
 
Example 4
Source File: AbstractXtextDocumentTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public XtextDocument getDocument(String s) {
	TerminalsTokenTypeToPartitionMapper mapper = new TerminalsTokenTypeToPartitionMapper() {{
		setTokenDefProvider(new AntlrTokenDefProvider() {
			{
				setAntlrTokenFileProvider(new XtextAntlrTokenFileProvider());
			}
		});
	}};
	PartitionTokenScanner scanner = new PartitionTokenScanner();
	scanner.setMapper(mapper);
	DocumentPartitioner partitioner = new DocumentPartitioner(scanner, mapper);
	DocumentTokenSource tokenSource = new DocumentTokenSource();
	tokenSource.setLexer(new Provider<Lexer>() {
		@Override
		public Lexer get() {
			return new org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer();
		}
	});
	XtextDocument document = new XtextDocument(tokenSource, null, outdatedStateManager, operationCanceledManager);
	document.setDocumentPartitioner(partitioner);
	partitioner.connect(document);
	document.set(s);
	return document;
}
 
Example 5
Source File: EmbeddedEditorModelAccess.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void setModel(XtextDocument document, String prefix, String editablePart, String suffix) {
	if (this.insertLineBreaks) {
		String delimiter = document.getDefaultLineDelimiter();
		prefix = prefix + delimiter;
		suffix = delimiter + suffix;
	}
	String model = prefix + editablePart + suffix;
	document.set(model);
	XtextResource resource = createResource(model);
	document.setInput(resource);
	AnnotationModel annotationModel = new AnnotationModel();
	if (document instanceof ISynchronizable) {
		Object lock = ((ISynchronizable) document).getLockObject();
		if (lock == null) {
			lock = new Object();
			((ISynchronizable) document).setLockObject(lock);
		}
		((ISynchronizable) annotationModel).setLockObject(lock);
	}
	this.viewer.setDocument(document, annotationModel, prefix.length(), editablePart.length());
}
 
Example 6
Source File: PresentationDamagerTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Document createDocument(final String before) throws Exception {
  XtextDocument _xblockexpression = null;
  {
    XtendDocumentTokenSource _xtendDocumentTokenSource = new XtendDocumentTokenSource();
    final Procedure1<XtendDocumentTokenSource> _function = (XtendDocumentTokenSource it) -> {
      AntlrTokenDefProvider _antlrTokenDefProvider = new AntlrTokenDefProvider();
      final Procedure1<AntlrTokenDefProvider> _function_1 = (AntlrTokenDefProvider it_1) -> {
        XtendAntlrTokenFileProvider _xtendAntlrTokenFileProvider = new XtendAntlrTokenFileProvider();
        it_1.setAntlrTokenFileProvider(_xtendAntlrTokenFileProvider);
      };
      AntlrTokenDefProvider _doubleArrow = ObjectExtensions.<AntlrTokenDefProvider>operator_doubleArrow(_antlrTokenDefProvider, _function_1);
      it.setTokenDefProvider(_doubleArrow);
      final Provider<Lexer> _function_2 = () -> {
        return this.createLexer();
      };
      it.setLexer(_function_2);
      it.setFlexerFactory(this.flexerFactory);
    };
    final XtendDocumentTokenSource source = ObjectExtensions.<XtendDocumentTokenSource>operator_doubleArrow(_xtendDocumentTokenSource, _function);
    final XtextDocument document = new XtextDocument(source, null, this.outdatedStateManager, this.operationCanceledManager);
    document.set(before);
    _xblockexpression = document;
  }
  return _xblockexpression;
}
 
Example 7
Source File: ReplacingAppendableTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected XtextDocument insertListField(final String model, final String fieldName)
		throws Exception {
	final int cursorPosition = model.indexOf('|');
	String actualModel = model.replace("|", " ");
	final XtendFile file = testHelper.xtendFile("Foo", actualModel);
	final XtextDocument document = documentProvider.get();
	document.set(actualModel);
	XtextResource xtextResource = (XtextResource) file.eResource();
	document.setInput(xtextResource);
	final EObject context = eObjectAtOffsetHelper.resolveElementAt(xtextResource, cursorPosition);
	document.modify(new IUnitOfWork.Void<XtextResource>() {
		@Override
		public void process(XtextResource state) throws Exception {
			ReplacingAppendable a = appendableFactory.create(document, state, cursorPosition, 1);
			ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, context);
			LightweightTypeReference typeRef = owner.toLightweightTypeReference(services.getTypeReferences().getTypeForName(List.class, context, typesFactory.createJvmWildcardTypeReference()));
			a.append(typeRef);
			a.append(" ").append(fieldName);
			a.commitChanges();
		}
	});
	return document;
}
 
Example 8
Source File: ModificationContextRegistry.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new document with the contents of the given {@link XtextResource}.
 * 
 * @param resource
 *          the resource to be used as input to the document
 * @return the created document
 */
private ICoreXtextDocument createDocument(final XtextResource resource) {
  XtextDocument document = documentProvider.get();
  if (resource.getParseResult() != null && resource.getParseResult().getRootNode() != null) {
    document.set(resource.getParseResult().getRootNode().getText());
  }
  document.setInput(resource);
  return new XtextDocumentAdapter(document);
}
 
Example 9
Source File: OutlineTreeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected XtextDocument createXtextDocument(String modelAsText) throws Exception {
	final XtextResource resource = getResource(modelAsText, "test.outlinetestlanguage");
	DocumentTokenSource tokenSource = new DocumentTokenSource();
	tokenSource.setLexer(new Provider<Lexer>(){
		@Override
		public Lexer get() {
			return new InternalXtextLexer();
		}});
	XtextDocument xtextDocument = new XtextDocument(tokenSource, null, new OutdatedStateManager(), new OperationCanceledManager());
	xtextDocument.setInput(resource);
	xtextDocument.set(modelAsText);
	return xtextDocument;	
}
 
Example 10
Source File: DocumentRewriterTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected XtextDocument createDocument(final String content) throws Exception {
  XtextDocument _xblockexpression = null;
  {
    final IFile file = this._workbenchTestHelper.createFile("Foo", content);
    final Resource resource = this._workbenchTestHelper.getResourceSet().getResource(URI.createPlatformResourceURI(file.getFullPath().toString(), true), true);
    XtendDocumentTokenSource _xtendDocumentTokenSource = new XtendDocumentTokenSource();
    final Procedure1<XtendDocumentTokenSource> _function = (XtendDocumentTokenSource it) -> {
      AntlrTokenDefProvider _antlrTokenDefProvider = new AntlrTokenDefProvider();
      final Procedure1<AntlrTokenDefProvider> _function_1 = (AntlrTokenDefProvider it_1) -> {
        XtendAntlrTokenFileProvider _xtendAntlrTokenFileProvider = new XtendAntlrTokenFileProvider();
        it_1.setAntlrTokenFileProvider(_xtendAntlrTokenFileProvider);
      };
      AntlrTokenDefProvider _doubleArrow = ObjectExtensions.<AntlrTokenDefProvider>operator_doubleArrow(_antlrTokenDefProvider, _function_1);
      it.setTokenDefProvider(_doubleArrow);
      final Provider<Lexer> _function_2 = () -> {
        InternalXtendLexer _internalXtendLexer = new InternalXtendLexer();
        return ((Lexer) _internalXtendLexer);
      };
      it.setLexer(_function_2);
      it.setFlexerFactory(this.flexerFactory);
    };
    final XtendDocumentTokenSource source = ObjectExtensions.<XtendDocumentTokenSource>operator_doubleArrow(_xtendDocumentTokenSource, _function);
    final XtextDocument document = new XtextDocument(source, null, this.outdatedStateManager, this.operationCanceledManager);
    document.set(content);
    document.setInput(((XtextResource) resource));
    _xblockexpression = document;
  }
  return _xblockexpression;
}
 
Example 11
Source File: DotHtmlLabelQuickfixDelegator.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * The implementation of the following helper methods are taken from the
 * org.eclipse.xtext.ui.testing.ContentAssistProcessorTestBuilder class.
 */
private IXtextDocument getDocument(String model) {
	XtextResource xtextResource = getXtextResource(model);
	XtextDocument document = injector.getInstance(XtextDocument.class);
	document.set(model);
	document.setInput(xtextResource);
	return document;
}
 
Example 12
Source File: DotEditorUtils.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private static IXtextDocument getDocument(final Injector injector,
		final XtextResource xtextResource, final String model) {
	XtextDocument document = injector.getInstance(XtextDocument.class);
	document.set(model);
	document.setInput(xtextResource);
	DocumentPartitioner partitioner = injector
			.getInstance(DocumentPartitioner.class);
	partitioner.connect(document);
	document.setDocumentPartitioner(partitioner);
	return document;
}
 
Example 13
Source File: AbstractQuickfixTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * The implementation of the following helper methods are taken from the
 * {@code org.eclipse.xtext.ui.testing.ContentAssistProcessorTestBuilder} class.
 */
protected IXtextDocument getDocument(String model) {
	XtextResource xtextResource = getXtextResource(model);
	XtextDocument document = injector.getInstance(XtextDocument.class);
	document.set(model);
	document.setInput(xtextResource);
	return document;
}
 
Example 14
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public IXtextDocument getDocument(final XtextResource xtextResource, final String model) {
	XtextDocument document = get(XtextDocument.class);
	document.set(model);
	document.setInput(xtextResource);
	DocumentPartitioner partitioner = get(DocumentPartitioner.class);
	partitioner.connect(document);
	document.setDocumentPartitioner(partitioner);
	return document;
}
 
Example 15
Source File: AbstractDamagerRepairerTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected Document createDocument(String before) throws Exception {
	DocumentTokenSource source = new DocumentTokenSource();
	source.setLexer(new Provider<Lexer>() {
		@Override
		public Lexer get() {
			return createLexer();
		}
	});
	XtextDocument document = new XtextDocument(source, null, outdatedStateManager, operationCanceledManager);
	document.set(before);
	return document;
}
 
Example 16
Source File: ContentAssistProcessorTestBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public IXtextDocument getDocument(final XtextResource xtextResource, final String model) {
	XtextDocument document = get(XtextDocument.class);
	document.set(model);
	document.setInput(xtextResource);
	DocumentPartitioner partitioner = get(DocumentPartitioner.class);
	partitioner.connect(document);
	document.setDocumentPartitioner(partitioner);
	return document;
}
 
Example 17
Source File: AbstractDamagerRepairerTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected Document createDocument(String before) throws Exception {
	DocumentTokenSource source = new DocumentTokenSource();
	source.setLexer(new Provider<Lexer>() {
		@Override
		public Lexer get() {
			return createLexer();
		}
	});
	XtextDocument document = new XtextDocument(source, null, outdatedStateManager, operationCanceledManager);
	document.set(before);
	return document;
}
 
Example 18
Source File: DamagerRepairerPerformanceTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected Document createDocument(String before) {
	DocumentTokenSource source = new DocumentTokenSource();
	source.setLexer(new Provider<Lexer>() {
		@Override
		public Lexer get() {
			return new org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer();
		}
	});
	XtextDocument document = new XtextDocument(source, null, new OutdatedStateManager(), new OperationCanceledManager());
	document.set(before);
	return document;
}
 
Example 19
Source File: BacktrackingLexerPresentationDamagerTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Document createDocument(String before) throws Exception {
	DocumentTokenSource source = new BacktrackingLexerDocumentTokenSource();
	source.setLexer(new Provider<Lexer>() {
		@Override
		public Lexer get() {
			return createLexer();
		}
	});
	XtextDocument document = new XtextDocument(source, null, outdatedStateManager, operationCanceledManager);
	document.set(before);
	return document;
}