use of org.eclipse.xtext.util.concurrent.IUnitOfWork in project xtext-xtend by eclipse.
the class Declarators method getDeclaratorData.
public Declarators.DeclaratorsData getDeclaratorData(final TargetURIs targetURIs, final IReferenceFinder.IResourceAccess resourceAccess) {
Declarators.DeclaratorsData result = targetURIs.<Declarators.DeclaratorsData>getUserData(Declarators.KEY);
if ((result != null)) {
return result;
}
final HashSet<QualifiedName> declaratorNames = CollectionLiterals.<QualifiedName>newHashSet();
final Consumer<URI> _function = (URI uri) -> {
final IUnitOfWork<Object, ResourceSet> _function_1 = (ResourceSet it) -> {
Object _xblockexpression = null;
{
final Consumer<URI> _function_2 = (URI objectURI) -> {
final EObject object = it.getEObject(objectURI, true);
if ((object != null)) {
final JvmType type = EcoreUtil2.<JvmType>getContainerOfType(object, JvmType.class);
if ((type != null)) {
QualifiedName _lowerCase = this.nameConverter.toQualifiedName(type.getIdentifier()).toLowerCase();
declaratorNames.add(_lowerCase);
QualifiedName _lowerCase_1 = this.nameConverter.toQualifiedName(type.getQualifiedName('.')).toLowerCase();
declaratorNames.add(_lowerCase_1);
}
}
};
targetURIs.getEObjectURIs(uri).forEach(_function_2);
_xblockexpression = null;
}
return _xblockexpression;
};
resourceAccess.<Object>readOnly(uri, _function_1);
};
targetURIs.getTargetResourceURIs().forEach(_function);
Declarators.DeclaratorsData _declaratorsData = new Declarators.DeclaratorsData(declaratorNames);
result = _declaratorsData;
targetURIs.<Declarators.DeclaratorsData>putUserData(Declarators.KEY, result);
return result;
}
use of org.eclipse.xtext.util.concurrent.IUnitOfWork in project xtext-xtend by eclipse.
the class CodeBuilderQuickfix method getXtendModification.
protected IModification getXtendModification(final ICodeBuilder.Xtend builder) {
final IModification _function = (IModificationContext it) -> {
final XtendTypeDeclaration xtendClass = builder.getXtendType();
final IEditorPart editor = this.editorOpener.open(EcoreUtil.getURI(xtendClass), false);
if ((!(editor instanceof XtextEditor))) {
return;
}
final XtextEditor xtextEditor = ((XtextEditor) editor);
final IXtextDocument document = xtextEditor.getDocument();
final Wrapper<Integer> wrapper = Wrapper.<Integer>forType(Integer.class);
final IUnitOfWork<ReplacingAppendable, XtextResource> _function_1 = (XtextResource resource) -> {
ReplacingAppendable _xblockexpression = null;
{
int offset = builder.getInsertOffset(resource);
wrapper.set(Integer.valueOf(offset));
final int typeIndentation = this.getTypeIndentation(resource, document, xtendClass);
DocumentSourceAppender.Factory.OptionalParameters _optionalParameters = new DocumentSourceAppender.Factory.OptionalParameters();
final Procedure1<DocumentSourceAppender.Factory.OptionalParameters> _function_2 = (DocumentSourceAppender.Factory.OptionalParameters it_1) -> {
int _indentationLevel = builder.getIndentationLevel();
int _plus = (_indentationLevel + typeIndentation);
it_1.baseIndentationLevel = _plus;
it_1.ensureEmptyLinesAround = true;
};
DocumentSourceAppender.Factory.OptionalParameters _doubleArrow = ObjectExtensions.<DocumentSourceAppender.Factory.OptionalParameters>operator_doubleArrow(_optionalParameters, _function_2);
_xblockexpression = this.appendableFactory.create(document, resource, offset, 0, _doubleArrow);
}
return _xblockexpression;
};
final ReplacingAppendable appendable = document.<ReplacingAppendable>readOnly(_function_1);
Integer offset = wrapper.get();
builder.build(appendable);
appendable.commitChanges();
xtextEditor.setHighlightRange(((offset).intValue() + 1), appendable.length(), true);
};
return _function;
}
use of org.eclipse.xtext.util.concurrent.IUnitOfWork in project xtext-eclipse by eclipse.
the class ImportURINavigationTest method doTestNavigation.
protected void doTestNavigation(IUnitOfWork<URI, IFile> uriComputation, boolean expectFQN) throws Exception {
IJavaProject project = JavaProjectSetupUtil.createJavaProject("importuriuitestlanguage.project");
try {
IFile first = project.getProject().getFile("src/first.importuriuitestlanguage");
first.create(new StringInputStream("type ASimpleType"), true, null);
ResourceSet resourceSet = resourceSetProvider.get(project.getProject());
Resource resource = resourceFactory.createResource(URI.createURI("synthetic://second.importuriuitestlanguage"));
resourceSet.getResources().add(resource);
String model = "import '" + uriComputation.exec(first) + "' type MyType extends ASimpleType";
resource.load(new StringInputStream(model), null);
EcoreUtil.resolveAll(resource);
Assert.assertTrue(resource.getErrors().isEmpty());
IHyperlink[] hyperlinks = helper.createHyperlinksByOffset((XtextResource) resource, model.indexOf("SimpleType"), false);
Assert.assertEquals(1, hyperlinks.length);
IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
Assert.assertNull(activePage.getActiveEditor());
if (expectFQN) {
Assert.assertEquals(URI.createURI(first.getLocationURI().toString()), ((XtextHyperlink) hyperlinks[0]).getURI().trimFragment());
} else {
Assert.assertEquals(URI.createPlatformResourceURI(first.getFullPath().toString(), true), ((XtextHyperlink) hyperlinks[0]).getURI().trimFragment());
}
hyperlinks[0].open();
IEditorPart editor = activePage.getActiveEditor();
Assert.assertNotNull(editor);
IXtextDocument document = xtextDocumentUtil.getXtextDocument(editor);
document.readOnly(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource state) throws Exception {
Assert.assertEquals("platform:/resource/importuriuitestlanguage.project/src/first.importuriuitestlanguage", state.getURI().toString());
}
});
Assert.assertEquals("type ASimpleType", document.get());
IEditorPart newPart = IDE.openEditor(activePage, first);
Assert.assertEquals(1, activePage.getEditorReferences().length);
Assert.assertEquals(editor, newPart);
} finally {
project.getProject().delete(true, null);
}
}
use of org.eclipse.xtext.util.concurrent.IUnitOfWork in project xtext-eclipse by eclipse.
the class EditorResourceAccessTest method testAccess.
@Test
public void testAccess() throws Exception {
EditorResourceAccess access = TestsActivator.getInstance().getInjector(getEditorId()).getInstance(EditorResourceAccess.class);
IUnitOfWork<Boolean, ResourceSet> isEmpty = new IUnitOfWork<Boolean, ResourceSet>() {
@Override
public Boolean exec(ResourceSet state) throws Exception {
return state.getResources().get(0).getContents().isEmpty();
}
};
assertTrue(access.readOnly(uri, isEmpty));
XtextEditor editor = openEditor(file);
runAsyncJobs();
assertTrue(access.readOnly(uri, isEmpty));
editor.getDocument().set("A");
runAsyncJobs();
waitForReconciler(editor);
runAsyncJobs();
assertFalse(access.readOnly(uri, isEmpty));
editor.close(false);
runAsyncJobs();
assertTrue(access.readOnly(uri, isEmpty));
}
use of org.eclipse.xtext.util.concurrent.IUnitOfWork in project xtext-eclipse by eclipse.
the class SelectionUtil method getSelectedFile.
public static IFile getSelectedFile(ISelection selection) {
if (selection instanceof IStructuredSelection) {
IStructuredSelection ssel = (IStructuredSelection) selection;
Object firstElement = ssel.getFirstElement();
IFile file = Adapters.adapt(firstElement, IFile.class);
if (file != null) {
return file;
} else if (firstElement instanceof IOutlineNode) {
IOutlineNode outlineNode = (IOutlineNode) firstElement;
return outlineNode.tryReadOnly(new IUnitOfWork<IFile, EObject>() {
@Override
public IFile exec(EObject state) throws Exception {
Resource resource = state.eResource();
URI uri = resource.getURI();
IPath path = new Path(uri.toPlatformString(true));
return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
}
});
}
}
return null;
}
Aggregations