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