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);
}
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);
}
}
}
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);
}
Aggregations