use of org.eclipse.xtext.validation.EObjectDiagnosticImpl in project xtext-xtend by eclipse.
the class ProblemSupportImpl method addError.
@Override
public void addError(final Element element, final String message) {
this.checkCanceled();
this.checkValidationAllowed();
final Pair<Resource, EObject> resAndObj = this.getResourceAndEObject(element);
EList<Resource.Diagnostic> _errors = resAndObj.getKey().getErrors();
EObject _value = resAndObj.getValue();
EStructuralFeature _significantFeature = this.getSignificantFeature(resAndObj.getValue());
EObjectDiagnosticImpl _eObjectDiagnosticImpl = new EObjectDiagnosticImpl(Severity.ERROR, "user.issue", message, _value, _significantFeature, (-1), null);
_errors.add(_eObjectDiagnosticImpl);
}
use of org.eclipse.xtext.validation.EObjectDiagnosticImpl in project xtext-xtend by eclipse.
the class ProblemSupportImpl method addWarning.
@Override
public void addWarning(final Element element, final String message) {
this.checkCanceled();
this.checkValidationAllowed();
final Pair<Resource, EObject> resAndObj = this.getResourceAndEObject(element);
EList<Resource.Diagnostic> _warnings = resAndObj.getKey().getWarnings();
EObject _value = resAndObj.getValue();
EStructuralFeature _significantFeature = this.getSignificantFeature(resAndObj.getValue());
EObjectDiagnosticImpl _eObjectDiagnosticImpl = new EObjectDiagnosticImpl(Severity.WARNING, "user.issue", message, _value, _significantFeature, (-1), null);
_warnings.add(_eObjectDiagnosticImpl);
}
use of org.eclipse.xtext.validation.EObjectDiagnosticImpl in project xtext-xtend by eclipse.
the class ProblemSupportTests method testErrorOnDerivedElement.
@Test
public void testErrorOnDerivedElement() {
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) -> {
final MutableClassDeclaration derived = it.getTypeLookup().findClass("MyClass");
it.getProblemSupport().addError(derived, "error on derived element");
Assert.assertEquals("error on derived element", 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 ActiveAnnotationContextProvider method computeContext.
public ActiveAnnotationContexts computeContext(final XtendFile file) {
final Stopwatches.StoppedTask task = Stopwatches.forTask("[macros] findActiveAnnotations (ActiveAnnotationContextProvider.computeContext)");
task.start();
try {
final ActiveAnnotationContexts result = ActiveAnnotationContexts.installNew(file.eResource());
final CompilationUnitImpl compilationUnit = this.compilationUnitProvider.get();
compilationUnit.setXtendFile(file);
result.compilationUnit = compilationUnit;
final IAcceptor<Pair<JvmAnnotationType, XAnnotation>> _function = (Pair<JvmAnnotationType, XAnnotation> it) -> {
boolean _containsKey = result.getContexts().containsKey(it.getKey());
boolean _not = (!_containsKey);
if (_not) {
final ActiveAnnotationContext fa = new ActiveAnnotationContext();
fa.setCompilationUnit(compilationUnit);
final JvmType processorType = this._xAnnotationExtensions.getProcessorType(it.getKey());
try {
final Object processorInstance = this._processorInstanceForJvmTypeProvider.getProcessorInstance(processorType);
if ((processorInstance == null)) {
String _identifier = processorType.getIdentifier();
String _plus = ("Couldn\'t instantiate the annotation processor of type \'" + _identifier);
String _plus_1 = (_plus + "\'. This is usually the case when the processor resides in the same project as the annotated element.");
throw new IllegalStateException(_plus_1);
}
fa.setProcessorInstance(processorInstance);
} catch (final Throwable _t) {
if (_t instanceof VirtualMachineError) {
final VirtualMachineError e = (VirtualMachineError) _t;
throw e;
} else if (_t instanceof Throwable) {
final Throwable e_1 = (Throwable) _t;
this.operationCanceledManager.propagateAsErrorIfCancelException(e_1);
String _switchResult = null;
boolean _matched = false;
if (e_1 instanceof ExceptionInInitializerError) {
_matched = true;
_switchResult = ((ExceptionInInitializerError) e_1).getException().getMessage();
}
if (!_matched) {
_switchResult = e_1.getMessage();
}
final String msg = _switchResult;
EList<Resource.Diagnostic> _errors = file.eResource().getErrors();
StringConcatenation _builder = new StringConcatenation();
_builder.append("Problem while loading annotation processor: ");
_builder.append(msg);
XAnnotation _value = it.getValue();
EObjectDiagnosticImpl _eObjectDiagnosticImpl = new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.PROCESSING_ERROR, _builder.toString(), _value, XAnnotationsPackage.Literals.XANNOTATION__ANNOTATION_TYPE, (-1), null);
_errors.add(_eObjectDiagnosticImpl);
} else {
throw Exceptions.sneakyThrow(_t);
}
}
result.getContexts().put(it.getKey(), fa);
}
List<XtendAnnotationTarget> _annotatedSourceElements = result.getContexts().get(it.getKey()).getAnnotatedSourceElements();
XtendAnnotationTarget _annotatedTarget = this._xAnnotationExtensions.getAnnotatedTarget(it.getValue());
_annotatedSourceElements.add(_annotatedTarget);
};
this.searchAnnotatedElements(file, _function);
return result;
} catch (final Throwable _t) {
if (_t instanceof Throwable) {
final Throwable e = (Throwable) _t;
this.operationCanceledManager.propagateAsErrorIfCancelException(e);
boolean _matched = false;
if (e instanceof VirtualMachineError) {
_matched = true;
throw ((VirtualMachineError) e);
}
if (!_matched) {
if (e instanceof LinkageError) {
_matched = true;
throw ((LinkageError) e);
}
}
ActiveAnnotationContextProvider.logger.warn("Error finding the elements to be processed by active annotations", e);
return ActiveAnnotationContexts.installNew(file.eResource());
} else {
throw Exceptions.sneakyThrow(_t);
}
} finally {
task.stop();
}
}
use of org.eclipse.xtext.validation.EObjectDiagnosticImpl in project xtext-xtend by eclipse.
the class XtendCompilerTester method compile.
public void compile(CharSequence source, final IAcceptor<CompilationResult> acceptor) {
try {
compilationTestHelper.configureFreshWorkspace();
compilationTestHelper.compile(source, new IAcceptor<CompilationTestHelper.Result>() {
@Override
public void accept(final Result t) {
acceptor.accept(new CompilationResult() {
@Override
public Map<String, String> getGeneratedCode() {
return t.getGeneratedCode();
}
@Override
public String getGeneratedCode(String typeName) {
return t.getGeneratedCode(typeName);
}
@Override
public String getSingleGeneratedCode() {
return t.getSingleGeneratedCode();
}
@Override
public Class<?> getCompiledClass() {
return t.getCompiledClass();
}
@Override
public Class<?> getCompiledClass(String className) {
return t.getCompiledClass(className);
}
@Override
public List<? extends Problem> getProblems(Element element) {
return getTransformationContext().getProblems(element);
}
@Override
public List<? extends Problem> getAllProblems() {
Resource resource = compilationUnitImpl.getXtendFile().eResource();
Iterable<EObjectDiagnosticImpl> issues = Iterables.filter(Iterables.concat(resource.getErrors(), resource.getWarnings()), EObjectDiagnosticImpl.class);
List<Problem> result = Lists.newArrayList(Iterables.transform(issues, new Function<EObjectDiagnosticImpl, Problem>() {
@Override
public Problem apply(EObjectDiagnosticImpl diag) {
ProblemImpl result = new ProblemImpl(diag.getCode(), diag.getMessage(), translateSeverity(diag.getSeverity()));
return result;
}
private org.eclipse.xtend.lib.macro.services.Problem.Severity translateSeverity(Severity severity) {
switch(severity) {
case ERROR:
return Problem.Severity.ERROR;
case WARNING:
return Problem.Severity.WARNING;
case INFO:
return Problem.Severity.INFO;
case IGNORE:
return Problem.Severity.IGNORE;
default:
throw new IllegalArgumentException(String.valueOf(severity));
}
}
}));
return result;
}
@Override
public Map<String, CharSequence> getAllGeneratedResources() {
return t.getAllGeneratedResources();
}
CompilationUnitImpl compilationUnitImpl;
{
compilationUnitImpl = compilationUnitProvider.get();
XtendFile xtendFile = (XtendFile) t.getResourceSet().getResources().get(0).getContents().get(0);
compilationUnitImpl.setXtendFile(xtendFile);
}
@Override
public CompilationUnit getCompilationUnit() {
return compilationUnitImpl;
}
@Override
public TransformationContext getTransformationContext() {
TransformationContextImpl transformationContextImpl = new TransformationContextImpl();
transformationContextImpl.setUnit(compilationUnitImpl);
return transformationContextImpl;
}
});
}
});
} catch (IOException e) {
Exceptions.sneakyThrow(e);
}
}
Aggregations