Search in sources :

Example 16 with Severity

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);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) Element(org.eclipse.xtend.lib.macro.declaration.Element) Resource(org.eclipse.emf.ecore.resource.Resource) Severity(org.eclipse.xtext.diagnostics.Severity) IOException(java.io.IOException) Result(org.eclipse.xtext.xbase.testing.CompilationTestHelper.Result) Function(com.google.common.base.Function) EObjectDiagnosticImpl(org.eclipse.xtext.validation.EObjectDiagnosticImpl) ProblemImpl(org.eclipse.xtend.core.macro.declaration.ProblemImpl) Problem(org.eclipse.xtend.lib.macro.services.Problem) TransformationContextImpl(org.eclipse.xtend.core.macro.TransformationContextImpl)

Example 17 with Severity

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));
                }
            }
        }
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ReplaceRegion(org.eclipse.xtext.util.ReplaceRegion) IScope(org.eclipse.xtext.scoping.IScope) Severity(org.eclipse.xtext.diagnostics.Severity) RichString(org.eclipse.xtend.core.xtend.RichString) IEObjectDocumentationProviderExtension(org.eclipse.xtext.documentation.IEObjectDocumentationProviderExtension) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Check(org.eclipse.xtext.validation.Check)

Example 18 with Severity

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);
}
Also used : Issue(org.eclipse.xtext.validation.Issue) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) Severity(org.eclipse.xtext.diagnostics.Severity) ResourceValidatorImpl(org.eclipse.xtext.validation.ResourceValidatorImpl) IDiagnosticConverter(org.eclipse.xtext.validation.IDiagnosticConverter) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) List(java.util.List)

Example 19 with Severity

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);
                }
            }
        }
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) Severity(org.eclipse.xtext.diagnostics.Severity) JvmMember(org.eclipse.xtext.common.types.JvmMember) IssueSeverities(org.eclipse.xtext.validation.IssueSeverities)

Example 20 with Severity

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);
    }
}
Also used : DecorationOverlayIcon(org.eclipse.jface.viewers.DecorationOverlayIcon) Severity(org.eclipse.xtext.diagnostics.Severity) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor)

Aggregations

Severity (org.eclipse.xtext.diagnostics.Severity)20 Issue (org.eclipse.xtext.validation.Issue)8 List (java.util.List)5 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)5 Diagnostic (org.eclipse.emf.ecore.resource.Resource.Diagnostic)5 ExceptionDiagnostic (org.eclipse.xtext.diagnostics.ExceptionDiagnostic)5 IDiagnosticConverter (org.eclipse.xtext.validation.IDiagnosticConverter)5 ResourceValidatorImpl (org.eclipse.xtext.validation.ResourceValidatorImpl)5 IOException (java.io.IOException)3 EObject (org.eclipse.emf.ecore.EObject)3 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)2 DecorationOverlayIcon (org.eclipse.jface.viewers.DecorationOverlayIcon)2 Diagnostic (org.eclipse.lsp4j.Diagnostic)2 DiagnosticSeverity (org.eclipse.lsp4j.DiagnosticSeverity)2 Check (org.eclipse.xtext.validation.Check)2 ComparisonFailure (org.junit.ComparisonFailure)2 Function (com.google.common.base.Function)1 CoreException (org.eclipse.core.runtime.CoreException)1 URI (org.eclipse.emf.common.util.URI)1 EClass (org.eclipse.emf.ecore.EClass)1