Search in sources :

Example 1 with AbstractDiagnosticProducerDecorator

use of org.eclipse.xtext.diagnostics.AbstractDiagnosticProducerDecorator in project xtext-core by eclipse.

the class XtextLinker method createDiagnosticProducer.

@Override
protected IDiagnosticProducer createDiagnosticProducer(final IDiagnosticConsumer consumer) {
    return new AbstractDiagnosticProducerDecorator(super.createDiagnosticProducer(consumer)) {

        private boolean filter = false;

        @Override
        public void addDiagnostic(DiagnosticMessage message) {
            if (!filter)
                super.addDiagnostic(message);
        }

        @Override
        public void setTarget(EObject object, EStructuralFeature feature) {
            super.setTarget(object, feature);
            // we don't want to mark generated types as errors unless generation fails
            filter = isTypeRef(object, feature) || isGeneratedPackage(object, feature) || isEnumLiteral(object, feature);
        }

        private boolean isEnumLiteral(EObject object, EStructuralFeature feature) {
            if (feature == XtextPackage.eINSTANCE.getEnumLiteralDeclaration_EnumLiteral()) {
                EnumRule rule = GrammarUtil.containingEnumRule(object);
                return rule.getType() == null || rule.getType().getClassifier() == null;
            }
            return false;
        }

        private boolean isGeneratedPackage(EObject object, EStructuralFeature feature) {
            return (feature == XtextPackage.eINSTANCE.getAbstractMetamodelDeclaration_EPackage() && (object instanceof GeneratedMetamodel));
        }

        private boolean isTypeRef(EObject object, EStructuralFeature feature) {
            return (feature == XtextPackage.eINSTANCE.getTypeRef_Classifier() && ((TypeRef) object).getMetamodel() instanceof GeneratedMetamodel);
        }
    };
}
Also used : EnumRule(org.eclipse.xtext.EnumRule) GeneratedMetamodel(org.eclipse.xtext.GeneratedMetamodel) DiagnosticMessage(org.eclipse.xtext.diagnostics.DiagnosticMessage) AbstractDiagnosticProducerDecorator(org.eclipse.xtext.diagnostics.AbstractDiagnosticProducerDecorator) EObject(org.eclipse.emf.ecore.EObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1 EnumRule (org.eclipse.xtext.EnumRule)1 GeneratedMetamodel (org.eclipse.xtext.GeneratedMetamodel)1 AbstractDiagnosticProducerDecorator (org.eclipse.xtext.diagnostics.AbstractDiagnosticProducerDecorator)1 DiagnosticMessage (org.eclipse.xtext.diagnostics.DiagnosticMessage)1