use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.
the class UIParticipant method createLabelProvider.
@Override
public ILabelProvider createLabelProvider() {
return new ILabelProvider() {
@Override
public void removeListener(ILabelProviderListener listener) {
}
@Override
public boolean isLabelProperty(Object element, String property) {
return false;
}
@Override
public void dispose() {
}
@Override
public void addListener(ILabelProviderListener listener) {
}
@Override
public String getText(Object element) {
IReferenceDescription referenceDescription = (IReferenceDescription) element;
URI containerEObjectURI = referenceDescription.getContainerEObjectURI();
final URI eObjectURI = (containerEObjectURI == null) ? referenceDescription.getSourceEObjectUri() : containerEObjectURI;
IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(eObjectURI.trimFragment());
if (resourceDescription != null) {
for (IEObjectDescription eObjectDescription : resourceDescription.getExportedObjects()) {
if (eObjectDescription.getEObjectURI().equals(eObjectURI)) {
return globalDescriptionsLabelProvider.getText(eObjectDescription);
}
}
}
return "unknown";
}
@Override
public Image getImage(Object element) {
IReferenceDescription referenceDescription = (IReferenceDescription) element;
URI containerEObjectURI = referenceDescription.getContainerEObjectURI();
final URI eObjectURI = (containerEObjectURI == null) ? referenceDescription.getSourceEObjectUri() : containerEObjectURI;
IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(eObjectURI.trimFragment());
if (resourceDescription != null) {
for (IEObjectDescription eObjectDescription : resourceDescription.getExportedObjects()) {
if (eObjectDescription.getEObjectURI().equals(eObjectURI)) {
return globalDescriptionsLabelProvider.getImage(eObjectDescription);
}
}
}
return null;
}
};
}
use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.
the class DirtyStateEditorSupportIntegrationTest method testUndoRedo.
/**
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=354123
*/
@Test
public void testUndoRedo() {
this.pushKey((IterableExtensions.<Character>head(((Iterable<Character>) Conversions.doWrapArray("a".toCharArray())))).charValue(), 0);
Assert.assertEquals(1, this.events.size());
Assert.assertEquals("fooa", IterableExtensions.<String>last(IterableExtensions.<IEObjectDescription>head(IterableExtensions.<IResourceDescription.Delta>head(IterableExtensions.<IResourceDescription.Event>last(this.events).getDeltas()).getNew().getExportedObjects()).getQualifiedName().getSegments()));
ISourceViewer _internalSourceViewer = this.editor.getInternalSourceViewer();
final IUndoManager undoManager = ((XtextSourceViewer) _internalSourceViewer).getUndoManager();
undoManager.undo();
NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
this.syncUtil.yieldToQueuedDisplayJobs(_nullProgressMonitor);
this.syncUtil.waitForReconciler(this.editor);
Assert.assertEquals(2, this.events.size());
Assert.assertNull(IterableExtensions.<IResourceDescription.Delta>head(IterableExtensions.<IResourceDescription.Event>last(this.events).getDeltas()).getNew());
undoManager.redo();
NullProgressMonitor _nullProgressMonitor_1 = new NullProgressMonitor();
this.syncUtil.yieldToQueuedDisplayJobs(_nullProgressMonitor_1);
this.syncUtil.waitForReconciler(this.editor);
Assert.assertEquals(3, this.events.size());
Assert.assertEquals("fooa", IterableExtensions.<String>last(IterableExtensions.<IEObjectDescription>head(IterableExtensions.<IResourceDescription.Delta>head(IterableExtensions.<IResourceDescription.Event>last(this.events).getDeltas()).getNew().getExportedObjects()).getQualifiedName().getSegments()));
}
use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.
the class DirtyStateEditorSupportIntegrationTest method testSaveAndEdit.
/**
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=488380
*/
@Test
public void testSaveAndEdit() {
this.pushKey((IterableExtensions.<Character>head(((Iterable<Character>) Conversions.doWrapArray("a".toCharArray())))).charValue(), 0);
Assert.assertEquals(1, this.events.size());
Assert.assertEquals("fooa", IterableExtensions.<String>last(IterableExtensions.<IEObjectDescription>head(IterableExtensions.<IResourceDescription.Delta>head(IterableExtensions.<IResourceDescription.Event>last(this.events).getDeltas()).getNew().getExportedObjects()).getQualifiedName().getSegments()));
NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
this.editor.doSave(_nullProgressMonitor);
NullProgressMonitor _nullProgressMonitor_1 = new NullProgressMonitor();
this.syncUtil.yieldToQueuedDisplayJobs(_nullProgressMonitor_1);
Assert.assertEquals(2, this.events.size());
Assert.assertNull(IterableExtensions.<IResourceDescription.Delta>head(IterableExtensions.<IResourceDescription.Event>last(this.events).getDeltas()).getNew());
this.pushKey(((char) 0), SWT.BS);
Assert.assertEquals(3, this.events.size());
Assert.assertEquals("foo", IterableExtensions.<String>last(IterableExtensions.<IEObjectDescription>head(IterableExtensions.<IResourceDescription.Delta>head(IterableExtensions.<IResourceDescription.Event>last(this.events).getDeltas()).getNew().getExportedObjects()).getQualifiedName().getSegments()));
}
use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.
the class RefactoringCrossReferenceSerializerTest method testSerializer.
@Test
public void testSerializer() throws Exception {
RefactoringCrossReferenceSerializer.RefTextEvaluator evaluator = new RefactoringCrossReferenceSerializer.RefTextEvaluator() {
@Override
public boolean isValid(IEObjectDescription target) {
return true;
}
@Override
public boolean isBetterThan(String newText, String currentText) {
return newText.length() < currentText.length();
}
};
String model = "bar { ref foo } foo";
String wsRelativePath = "test/test." + getCurrentFileExtension();
IFile file = createFile(wsRelativePath, model);
Main main = (Main) getModel(file.getContents());
XtextResource resource = (XtextResource) main.eResource();
resource.setURI(URI.createPlatformResourceURI(wsRelativePath, true));
Element bar = (Element) main.getElements().get(0);
Element foo = bar.getReferenced().get(0);
assertEquals("foo", foo.getName());
CrossReference crossref = GrammarUtil.containedCrossReferences(grammarAccess.getElementRule()).get(0);
TextRegion linkTextRegion = new TextRegion(model.lastIndexOf("foo"), 3);
String linkText = facade.getCrossRefText(bar, crossref, foo, evaluator, linkTextRegion, status);
assertEquals(linkText, "foo");
assertTrue(status.getRefactoringStatus().isOK());
foo.setName("fooBar");
resource.getCache().clear(resource);
String linkText1 = facade.getCrossRefText(bar, crossref, foo, evaluator, linkTextRegion, status);
assertEquals(linkText1, "fooBar");
assertTrue(status.getRefactoringStatus().isOK());
assertEquals(foo, ((Main) resource.getContents().get(0)).getElements().get(1));
foo.setName("bar");
resource.getCache().clear(resource);
assertNull(facade.getCrossRefText(bar, crossref, foo, evaluator, linkTextRegion, status));
}
use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.
the class XbaseProposalProvider method createLocalVariableAndImplicitProposals.
protected void createLocalVariableAndImplicitProposals(EObject context, IExpressionScope.Anchor anchor, ContentAssistContext contentAssistContext, ICompletionProposalAcceptor acceptor) {
String prefix = contentAssistContext.getPrefix();
if (prefix.length() > 0) {
if (!Character.isJavaIdentifierStart(prefix.charAt(0))) {
if (prefix.length() > 1) {
if (prefix.charAt(0) == '^' && !Character.isJavaIdentifierStart(prefix.charAt(1))) {
return;
}
}
}
}
// long time = System.currentTimeMillis();
Function<IEObjectDescription, ICompletionProposal> proposalFactory = getProposalFactory(getFeatureCallRuleName(), contentAssistContext);
IResolvedTypes resolvedTypes = context != null ? typeResolver.resolveTypes(context) : typeResolver.resolveTypes(contentAssistContext.getResource());
IExpressionScope expressionScope = resolvedTypes.getExpressionScope(context, anchor);
// TODO use the type name information
IScope scope = expressionScope.getFeatureScope();
getCrossReferenceProposalCreator().lookupCrossReference(scope, context, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, acceptor, getFeatureDescriptionPredicate(contentAssistContext), proposalFactory);
// System.out.printf("XbaseProposalProvider.createLocalVariableAndImplicitProposals = %d\n", System.currentTimeMillis() - time);
// time = System.currentTimeMillis();
// TODO use the type name information
proposeDeclaringTypeForStaticInvocation(context, null, /* ignore */
contentAssistContext, acceptor);
// System.out.printf("XbaseProposalProvider.proposeDeclaringTypeForStaticInvocation = %d\n", System.currentTimeMillis() - time);
}
Aggregations