Search in sources :

Example 1 with EObjectDiagnosticImpl

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);
}
Also used : EObjectDiagnosticImpl(org.eclipse.xtext.validation.EObjectDiagnosticImpl) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature)

Example 2 with 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);
}
Also used : EObjectDiagnosticImpl(org.eclipse.xtext.validation.EObjectDiagnosticImpl) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature)

Example 3 with 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);
}
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) MutableClassDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration) Test(org.junit.Test)

Example 4 with EObjectDiagnosticImpl

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();
    }
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) Stopwatches(org.eclipse.xtext.util.internal.Stopwatches) CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) Resource(org.eclipse.emf.ecore.resource.Resource) JvmType(org.eclipse.xtext.common.types.JvmType) EList(org.eclipse.emf.common.util.EList) EObjectDiagnosticImpl(org.eclipse.xtext.validation.EObjectDiagnosticImpl) XtendAnnotationTarget(org.eclipse.xtend.core.xtend.XtendAnnotationTarget) ActiveAnnotationContexts(org.eclipse.xtend.core.macro.ActiveAnnotationContexts) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ActiveAnnotationContext(org.eclipse.xtend.core.macro.ActiveAnnotationContext) EObject(org.eclipse.emf.ecore.EObject) EList(org.eclipse.emf.common.util.EList) List(java.util.List) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 5 with EObjectDiagnosticImpl

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

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