use of org.eclipse.xtext.diagnostics.Severity 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);
}
}
use of org.eclipse.xtext.diagnostics.Severity in project xtext-xtend by eclipse.
the class XtendValidator method checkJavaDocRefs.
@Check
public void checkJavaDocRefs(XtendMember member) {
if (isIgnored(IssueCodes.JAVA_DOC_LINKING_DIAGNOSTIC))
return;
List<INode> documentationNodes = ((IEObjectDocumentationProviderExtension) documentationProvider).getDocumentationNodes(member);
for (INode node : documentationNodes) {
for (ReplaceRegion region : javaDocTypeReferenceProvider.computeTypeRefRegions(node)) {
String typeRefString = region.getText();
if (typeRefString != null && typeRefString.length() > 0) {
IScope scope = scopeProvider.getScope(member, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
IEObjectDescription candidate = scope.getSingleElement(qualifiedNameConverter.toQualifiedName(typeRefString));
if (candidate == null) {
Severity severity = getIssueSeverities(getContext(), getCurrentObject()).getSeverity(IssueCodes.JAVA_DOC_LINKING_DIAGNOSTIC);
if (severity != null)
getChain().add(createDiagnostic(severity, "javaDoc: " + typeRefString + " cannot be resolved to a type", member, region.getOffset(), region.getLength(), IssueCodes.JAVA_DOC_LINKING_DIAGNOSTIC));
}
}
}
}
}
use of org.eclipse.xtext.diagnostics.Severity in project xtext-xtend by eclipse.
the class LinkingErrorTest method validateWithoutException.
protected void validateWithoutException(XtextResource resource) {
ResourceValidatorImpl validator = resourceValidatorProvider.get();
assertNotSame(validator, resource.getResourceServiceProvider().getResourceValidator());
validator.setDiagnosticConverter(new IDiagnosticConverter() {
@Override
public void convertValidatorDiagnostic(org.eclipse.emf.common.util.Diagnostic diagnostic, IAcceptor<Issue> acceptor) {
if (diagnostic instanceof BasicDiagnostic) {
List<?> data = diagnostic.getData();
if (!data.isEmpty() && data.get(0) instanceof Throwable) {
Throwable t = (Throwable) data.get(0);
// and AssertionError does not take a throwable as argument
throw new Error(t);
}
}
}
@Override
public void convertResourceDiagnostic(Diagnostic diagnostic, Severity severity, IAcceptor<Issue> acceptor) {
if (diagnostic instanceof ExceptionDiagnostic) {
Exception e = ((ExceptionDiagnostic) diagnostic).getException();
// and AssertionError does not take a throwable as argument
throw new Error(new RuntimeException(e));
}
}
});
validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
}
use of org.eclipse.xtext.diagnostics.Severity in project xtext-xtend by eclipse.
the class CachingResourceValidatorImpl method addWarningsForOrphanedJvmElements.
private void addWarningsForOrphanedJvmElements(final Resource resource, final CancelIndicator monitor, final IAcceptor<Issue> acceptor) {
final IssueSeverities issueSeverities = this.issueSeveritiesProvider.getIssueSeverities(resource);
final Severity severity = issueSeverities.getSeverity(IssueCodes.ORPHAN_ELEMENT);
boolean _equals = Objects.equal(severity, Severity.IGNORE);
if (_equals) {
return;
}
Iterable<JvmDeclaredType> _filter = Iterables.<JvmDeclaredType>filter(IterableExtensions.<EObject>tail(resource.getContents()), JvmDeclaredType.class);
for (final JvmDeclaredType jvmType : _filter) {
final Function1<JvmMember, Boolean> _function = (JvmMember it) -> {
boolean _isSynthetic = this._jvmTypeExtensions.isSynthetic(it);
return Boolean.valueOf((!_isSynthetic));
};
Iterable<JvmMember> _iterable = IteratorExtensions.<JvmMember>toIterable(IteratorExtensions.<JvmMember>filter(Iterators.<JvmMember>filter(jvmType.eAllContents(), JvmMember.class), _function));
for (final JvmMember jvmMember : _iterable) {
{
this.operationCanceledManager.checkCanceled(monitor);
final EObject sourceElement = this._iJvmModelAssociations.getPrimarySourceElement(jvmMember);
if ((sourceElement == null)) {
this.addWarningForOrphanedJvmElement(resource, jvmMember, severity, acceptor);
}
}
}
}
}
use of org.eclipse.xtext.diagnostics.Severity in project xtext-xtend by eclipse.
the class XtendEditorErrorTickUpdater method updateEditorImage.
@Override
protected void updateEditorImage(XtextEditor xtextEditor) {
if (xtextEditor != null && !xtextEditor.isEditable()) {
Severity severity = getSeverity(xtextEditor);
if (severity != null && severity != Severity.INFO) {
ImageDescriptor descriptor = severity == Severity.ERROR ? XtextPluginImages.DESC_OVR_ERROR : XtextPluginImages.DESC_OVR_WARNING;
// TODO replace with new constructor that takes an ImageDescription when on Oxygen+
DecorationOverlayIcon decorationOverlayIcon = new DecorationOverlayIcon(pluginImageHelper.getImage(images.forReadonly()), descriptor, IDecoration.BOTTOM_LEFT);
scheduleUpdateEditor(decorationOverlayIcon);
} else {
scheduleUpdateEditor(images.forReadonly());
}
} else {
super.updateEditorImage(xtextEditor);
}
}
Aggregations