use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.
the class LinkingErrorTest method assertNoExceptions.
protected void assertNoExceptions(EObject object) {
Resource resource = object.eResource();
if (resource instanceof LazyLinkingResource)
((LazyLinkingResource) resource).resolveLazyCrossReferences(CancelIndicator.NullImpl);
List<Diagnostic> errors = object.eResource().getErrors();
for (Diagnostic error : errors) {
if (error instanceof ExceptionDiagnostic) {
((ExceptionDiagnostic) error).getException().printStackTrace();
}
assertFalse(error.toString(), error instanceof ExceptionDiagnostic);
}
validateWithoutException((XtextResource) resource);
}
use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.
the class XtendBatchCompiler method getXtendFile.
/* @Nullable */
protected XtendFile getXtendFile(Resource resource) {
XtextResource xtextResource = (XtextResource) resource;
IParseResult parseResult = xtextResource.getParseResult();
if (parseResult != null) {
EObject model = parseResult.getRootASTElement();
if (model instanceof XtendFile) {
XtendFile xtendFile = (XtendFile) model;
return xtendFile;
}
}
return null;
}
use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.
the class ExtractMethodIntegrationTest method assertExtractForbidden.
protected void assertExtractForbidden(final CharSequence input, final Procedure1<? super ExtractMethodRefactoring> initializer, final String messageFragment) {
try {
final String inputString = input.toString();
final IFile file = this.workbenchTestHelper.createFile("Foo", inputString.replace("$", ""));
final XtextEditor editor = this.workbenchTestHelper.openEditor(file);
try {
final IUnitOfWork<String, XtextResource> _function = (XtextResource it) -> {
String _xblockexpression = null;
{
int _indexOf = inputString.indexOf("$");
int _lastIndexOf = inputString.lastIndexOf("$");
int _indexOf_1 = inputString.indexOf("$");
int _minus = (_lastIndexOf - _indexOf_1);
int _minus_1 = (_minus - 1);
TextSelection _textSelection = new TextSelection(_indexOf, _minus_1);
final List<XExpression> selection = this.util.findSelectedSiblingExpressions(it, _textSelection);
final ExtractMethodRefactoring refactoring = this.refactoringProvider.get();
refactoring.initialize(editor, selection, true);
refactoring.setMethodName("bar");
NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
final RefactoringStatus status = refactoring.checkInitialConditions(_nullProgressMonitor);
initializer.apply(refactoring);
NullProgressMonitor _nullProgressMonitor_1 = new NullProgressMonitor();
status.merge(refactoring.checkFinalConditions(_nullProgressMonitor_1));
Assert.assertTrue(status.toString(), status.hasError());
final String message = status.getMessageMatchingSeverity(RefactoringStatus.ERROR);
Assert.assertTrue(message, message.toLowerCase().contains(messageFragment.toLowerCase()));
_xblockexpression = "";
}
return _xblockexpression;
};
editor.getDocument().<String>readOnly(_function);
} finally {
editor.close(false);
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.
the class ExtractVariableIntegrationTest method assertAfterExtract.
protected void assertAfterExtract(final CharSequence input, final CharSequence expected, final boolean isFinal) {
try {
final String inputString = input.toString();
final String model = inputString.replace("$", "");
final IFile file = this.workbenchTestHelper.createFile("Foo", model);
final XtextEditor editor = this.workbenchTestHelper.openEditor(file);
try {
final IUnitOfWork<Change, XtextResource> _function = (XtextResource it) -> {
Change _xblockexpression = null;
{
final int offset = inputString.indexOf("$");
int _lastIndexOf = inputString.lastIndexOf("$");
int _minus = (_lastIndexOf - 1);
final int length = (_minus - offset);
final TextSelection textSelection = new TextSelection(offset, length);
final XExpression selection = this.util.findSelectedExpression(it, textSelection);
final ExtractVariableRefactoring refactoring = this.refactoringProvider.get();
refactoring.setFinal(isFinal);
refactoring.initialize(editor, selection);
NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
final RefactoringStatus status = refactoring.checkAllConditions(_nullProgressMonitor);
Assert.assertTrue(status.toString(), status.isOK());
NullProgressMonitor _nullProgressMonitor_1 = new NullProgressMonitor();
Change _createChange = refactoring.createChange(_nullProgressMonitor_1);
NullProgressMonitor _nullProgressMonitor_2 = new NullProgressMonitor();
_xblockexpression = _createChange.perform(_nullProgressMonitor_2);
}
return _xblockexpression;
};
editor.getDocument().<Change>readOnly(_function);
Assert.assertEquals(expected.toString(), editor.getDocument().get());
} finally {
editor.close(false);
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.
the class AbstractXtendTestCase method file.
protected XtendFile file(String string, boolean validate, boolean shouldBeSyntacticallyValid) throws Exception {
XtextResourceSet set = getResourceSet();
String fileName = getFileName(string);
Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
resource.load(new LazyStringInputStream(string, StandardCharsets.ISO_8859_1.name()), null);
if (shouldBeSyntacticallyValid) {
assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
}
if (validate) {
List<Issue> issues = Lists.newArrayList(Iterables.filter(((XtextResource) resource).getResourceServiceProvider().getResourceValidator().validate(resource, CheckMode.ALL, CancelIndicator.NullImpl), new Predicate<Issue>() {
@Override
public boolean apply(Issue issue) {
return issue.getSeverity() == Severity.ERROR;
}
}));
assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
}
XtendFile file = (XtendFile) resource.getContents().get(0);
return file;
}
Aggregations