use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.
the class ExtractMethodUserInputPage method createSignaturePreview.
protected void createSignaturePreview(Composite composite) {
Label previewLabel = new Label(composite, SWT.NONE);
previewLabel.setText("Method signature preview:");
GridData gridData = new GridData(SWT.FILL);
gridData.horizontalSpan = 2;
previewLabel.setLayoutData(gridData);
signaturePreview = editorFactory.newEditor(new IEditedResourceProvider() {
@Override
public XtextResource createResource() {
URI resourceURI = EcoreUtil2.getPlatformResourceOrNormalizedURI(refactoring.getXtendClass()).trimFragment();
IProject project = projectUtil.getProject(resourceURI);
ResourceSet resourceSet = resourceSetProvider.get(project);
return (XtextResource) resourceSet.getResource(resourceURI, true);
}
}).readOnly().withParent(composite);
GridData gridData2 = new GridData(GridData.FILL_HORIZONTAL);
gridData2.horizontalSpan = 2;
signaturePreview.getViewer().getControl().setLayoutData(gridData2);
partialEditor = signaturePreview.createPartialEditor(getPartialEditorModelPrefix(), refactoring.getMethodSignature(), getPartialEditorModelSuffix(), true);
}
use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.
the class XtendFileRenameParticipant method createRenameElementContexts.
@Override
protected List<? extends IRenameElementContext> createRenameElementContexts(Object element) {
if (super.getNewName().endsWith(".xtend")) {
IFile file = (IFile) element;
final IPath filePath = file.getFullPath();
final IPath newPath = file.getFullPath().removeLastSegments(1).append(getNewName() + ".xtend");
String className = trimFileExtension(file.getName());
if (className != null) {
ResourceSet resourceSet = resourceSetProvider.get(file.getProject());
URI resourceURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
Resource resource = resourceSet.getResource(resourceURI, true);
if (resource != null && !resource.getContents().isEmpty()) {
for (XtendTypeDeclaration type : EcoreUtil2.eAllOfType(resource.getContents().get(0), XtendTypeDeclaration.class)) {
if (equal(className, type.getName())) {
IRenameElementContext renameElementContext = renameContextFactory.createRenameElementContext(type, null, null, (XtextResource) resource);
if (renameElementContext instanceof IChangeRedirector.Aware)
((IChangeRedirector.Aware) renameElementContext).setChangeRedirector(new IChangeRedirector() {
@Override
public IPath getRedirectedPath(IPath source) {
return source.equals(filePath) ? newPath : source;
}
});
return singletonList(renameElementContext);
}
}
}
}
}
return super.createRenameElementContexts(element);
}
use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.
the class ParserTest method testAllGrammarElementsUniqueAfterReparse.
@Test
public void testAllGrammarElementsUniqueAfterReparse() throws Exception {
String text = "class Foo { def m() { newArrayList() } }";
XtendClass clazz = clazz(text);
XtextResource resource = (XtextResource) clazz.eResource();
resource.update(text.indexOf('m'), 0, "m");
ICompositeNode root = resource.getParseResult().getRootNode();
assertSame(root, root.getRootNode());
Set<EObject> grammarElements = Sets.newHashSet();
for (INode node : root.getAsTreeIterable()) {
if (node instanceof ICompositeNode) {
if (node.getGrammarElement() == null) {
fail("node without grammar element");
}
if (!grammarElements.add(node.getGrammarElement())) {
fail(node.getGrammarElement().toString());
}
}
}
}
use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.
the class PartialParserTest method testEqualModels_05.
@Test
public void testEqualModels_05() throws Exception {
String model = "package org.eclipse.xtend.core.tests.smoke\n" + "\n" + "import org.eclipse.emf.ecore.EClass\n" + "import org.eclipse.emf.ecore.EPackage\n" + "import org.eclipse.emf.ecore.EStructuralFeature\n" + "import org.eclipse.emf.ecore.EObject\n" + "\n" + "class Case_6 {\n" + "\n" + " def dispatch transform(EClass model) {\n" + " model.ETypeParameters.map(e|transform(e))\n" + " }\n" + " \n" + " def dispatch transform(EPackage packageDecl) {\n" + " packageDecl.eContents.map(e | transform(e as EStructuralFeature))\n" + " }\n" + " \n" + " def dispatch transform(EStructuralFeature entity) {\n" + " val inferredType = null\n" + " newArrayList";
XtextResource resource = doTestUpdateAtOffset(model, 524, 0, "(i", "Case_6.xtend");
compareWithNewResource(resource, model + "(", 525, 1, "i", "Case_6.xtend");
validateWithoutException(resource);
}
use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.
the class PartialParserTest method testBug480818.
@Test
public void testBug480818() throws Exception {
String code = "class Example {\n" + " val greeting = 'hello world!'\n" + " def sayHello() {\n" + " println(greeting)\n" + " prinntln(greeting)\n" + " }}";
XtextResource resource = createResource(code, "Example.xtend");
String before = EmfFormatter.listToStr(resource.getContents());
resource.update(code.lastIndexOf("prinntln") + 2, 1, "i");
// here before bug 480818 was fixed a StackOverflowException occured
String after = EmfFormatter.listToStr(resource.getContents());
assertEquals(before, after);
}
Aggregations