Search in sources :

Example 76 with XtextResource

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);
}
Also used : LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic)

Example 77 with XtextResource

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;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) EObject(org.eclipse.emf.ecore.EObject) XtextResource(org.eclipse.xtext.resource.XtextResource) IParseResult(org.eclipse.xtext.parser.IParseResult)

Example 78 with XtextResource

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);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) TextSelection(org.eclipse.jface.text.TextSelection) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) XtextResource(org.eclipse.xtext.resource.XtextResource) ExtractMethodRefactoring(org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 79 with XtextResource

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);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) TextSelection(org.eclipse.jface.text.TextSelection) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) ExtractVariableRefactoring(org.eclipse.xtext.xbase.ui.refactoring.ExtractVariableRefactoring) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) XtextResource(org.eclipse.xtext.resource.XtextResource) Change(org.eclipse.ltk.core.refactoring.Change) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 80 with XtextResource

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;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) Issue(org.eclipse.xtext.validation.Issue) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) LazyStringInputStream(org.eclipse.xtext.util.LazyStringInputStream) XtextResource(org.eclipse.xtext.resource.XtextResource) Predicate(com.google.common.base.Predicate)

Aggregations

XtextResource (org.eclipse.xtext.resource.XtextResource)627 Test (org.junit.Test)367 Resource (org.eclipse.emf.ecore.resource.Resource)107 EObject (org.eclipse.emf.ecore.EObject)99 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)67 StringInputStream (org.eclipse.xtext.util.StringInputStream)67 URI (org.eclipse.emf.common.util.URI)62 Diagnostic (org.eclipse.emf.common.util.Diagnostic)55 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)55 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)46 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)40 Grammar (org.eclipse.xtext.Grammar)32 IUnitOfWork (org.eclipse.xtext.util.concurrent.IUnitOfWork)31 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)30 IFile (org.eclipse.core.resources.IFile)29 Issue (org.eclipse.xtext.validation.Issue)29 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)28 List (java.util.List)26 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)26 INode (org.eclipse.xtext.nodemodel.INode)23