Search in sources :

Example 6 with EObjectDiagnosticImpl

use of org.eclipse.xtext.validation.EObjectDiagnosticImpl in project xtext-xtend by eclipse.

the class ProblemSupportTests method testErrorOnSource.

@Test
public void testErrorOnSource() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class MyClass {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("String foo = \'foo\'");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
        it.getProblemSupport().addError(IterableExtensions.head(it.getSourceTypeDeclarations()), "error on source");
        Assert.assertEquals("error on source", IterableExtensions.<Resource.Diagnostic>head(it.getXtendFile().eResource().getErrors()).getMessage());
        Resource.Diagnostic _head = IterableExtensions.<Resource.Diagnostic>head(it.getXtendFile().eResource().getErrors());
        Assert.assertEquals(IterableExtensions.<XtendTypeDeclaration>head(it.getXtendFile().getXtendTypes()), ((EObjectDiagnosticImpl) _head).getProblematicObject());
    };
    this.asCompilationUnit(this.validFile(_builder), _function);
}
Also used : EObjectDiagnosticImpl(org.eclipse.xtext.validation.EObjectDiagnosticImpl) CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Resource(org.eclipse.emf.ecore.resource.Resource) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) Test(org.junit.Test)

Example 7 with EObjectDiagnosticImpl

use of org.eclipse.xtext.validation.EObjectDiagnosticImpl in project xtext-xtend by eclipse.

the class CompilationUnitImpl method handleProcessingError.

public void handleProcessingError(final Iterable<? extends EObject> sourceElements, final Resource resource, final Throwable t) {
    if ((t instanceof VirtualMachineError)) {
        throw ((VirtualMachineError) t);
    }
    boolean _equals = Objects.equal(this.lastPhase, ActiveAnnotationContexts.AnnotationCallback.GENERATION);
    if (_equals) {
        Throwables.propagateIfPossible(t);
        String _messageWithoutStackTrace = this.getMessageWithoutStackTrace(t);
        throw new RuntimeException(_messageWithoutStackTrace, t);
    }
    final String msg = this.getMessageWithStackTrace(t);
    final EList<Resource.Diagnostic> errors = resource.getErrors();
    for (final EObject target : sourceElements) {
        boolean _matched = false;
        if (target instanceof XtendAnnotationTarget) {
            _matched = true;
            final EList<XAnnotation> annotations = ((XtendAnnotationTarget) target).getAnnotations();
            EObject _xifexpression = null;
            boolean _isEmpty = annotations.isEmpty();
            if (_isEmpty) {
                _xifexpression = target;
            } else {
                _xifexpression = IterableExtensions.<XAnnotation>head(annotations);
            }
            EObjectDiagnosticImpl _eObjectDiagnosticImpl = new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.PROCESSING_ERROR, msg, _xifexpression, null, (-1), null);
            errors.add(_eObjectDiagnosticImpl);
        }
        if (!_matched) {
            EObjectDiagnosticImpl _eObjectDiagnosticImpl = new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.PROCESSING_ERROR, msg, target, null, (-1), null);
            errors.add(_eObjectDiagnosticImpl);
        }
    }
}
Also used : XtendAnnotationTarget(org.eclipse.xtend.core.xtend.XtendAnnotationTarget) EObjectDiagnosticImpl(org.eclipse.xtext.validation.EObjectDiagnosticImpl) EObject(org.eclipse.emf.ecore.EObject) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation)

Example 8 with EObjectDiagnosticImpl

use of org.eclipse.xtext.validation.EObjectDiagnosticImpl in project xtext-xtend by eclipse.

the class ProblemSupportImpl method getProblems.

@Override
public List<? extends Problem> getProblems(final Element element) {
    this.checkCanceled();
    final Pair<Resource, EObject> resAndObj = this.getResourceAndEObject(element);
    final Resource resource = resAndObj.getKey();
    EList<Resource.Diagnostic> _errors = resource.getErrors();
    EList<Resource.Diagnostic> _warnings = resource.getWarnings();
    final Iterable<EObjectDiagnosticImpl> issues = Iterables.<EObjectDiagnosticImpl>filter(Iterables.<Resource.Diagnostic>concat(_errors, _warnings), EObjectDiagnosticImpl.class);
    final Function1<EObjectDiagnosticImpl, Boolean> _function = (EObjectDiagnosticImpl diag) -> {
        EObject _problematicObject = diag.getProblematicObject();
        EObject _value = resAndObj.getValue();
        return Boolean.valueOf(Objects.equal(_problematicObject, _value));
    };
    final Function1<EObjectDiagnosticImpl, Problem> _function_1 = (EObjectDiagnosticImpl diag) -> {
        String _code = diag.getCode();
        String _message = diag.getMessage();
        Problem.Severity _translateSeverity = this.translateSeverity(diag.getSeverity());
        ProblemImpl _problemImpl = new ProblemImpl(_code, _message, _translateSeverity);
        return ((Problem) _problemImpl);
    };
    final Iterable<Problem> result = IterableExtensions.<EObjectDiagnosticImpl, Problem>map(IterableExtensions.<EObjectDiagnosticImpl>filter(issues, _function), _function_1);
    return IterableExtensions.<Problem>toList(result);
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) Severity(org.eclipse.xtext.diagnostics.Severity) EObjectDiagnosticImpl(org.eclipse.xtext.validation.EObjectDiagnosticImpl) EObject(org.eclipse.emf.ecore.EObject) ProblemImpl(org.eclipse.xtend.core.macro.declaration.ProblemImpl) Problem(org.eclipse.xtend.lib.macro.services.Problem)

Aggregations

EObjectDiagnosticImpl (org.eclipse.xtext.validation.EObjectDiagnosticImpl)8 Resource (org.eclipse.emf.ecore.resource.Resource)7 EObject (org.eclipse.emf.ecore.EObject)5 CompilationUnitImpl (org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl)4 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)2 ProblemImpl (org.eclipse.xtend.core.macro.declaration.ProblemImpl)2 XtendAnnotationTarget (org.eclipse.xtend.core.xtend.XtendAnnotationTarget)2 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)2 Problem (org.eclipse.xtend.lib.macro.services.Problem)2 Severity (org.eclipse.xtext.diagnostics.Severity)2 XAnnotation (org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation)2 Test (org.junit.Test)2 Function (com.google.common.base.Function)1 IOException (java.io.IOException)1 List (java.util.List)1 EList (org.eclipse.emf.common.util.EList)1 ActiveAnnotationContext (org.eclipse.xtend.core.macro.ActiveAnnotationContext)1 ActiveAnnotationContexts (org.eclipse.xtend.core.macro.ActiveAnnotationContexts)1 TransformationContextImpl (org.eclipse.xtend.core.macro.TransformationContextImpl)1