use of org.eclipse.xtext.diagnostics.DiagnosticMessage in project coffeescript-eclipse by adamschmideg.
the class SuppressingLinkingDiagnosticMessageProvider method getUnresolvedProxyMessage.
@Override
public /**
* XXX: Instead of properly handling built-ins, just catch diagnostic with a link to a built-in
* and don't forward it
*/
DiagnosticMessage getUnresolvedProxyMessage(final ILinkingDiagnosticContext context) {
if (builtins.getPrefixes().contains(context.getLinkText())) {
// No problem, it's a builtin
return null;
} else {
DiagnosticMessage msg = super.getUnresolvedProxyMessage(context);
DiagnosticMessage diagnostic = new DiagnosticMessage(msg.getMessage(), Severity.WARNING, msg.getIssueCode(), msg.getIssueData());
return diagnostic;
}
}
use of org.eclipse.xtext.diagnostics.DiagnosticMessage 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);
}
};
}
use of org.eclipse.xtext.diagnostics.DiagnosticMessage in project xtext-core by eclipse.
the class TransformationDiagnosticsProducer method acceptError.
@Override
public void acceptError(TransformationErrorCode errorCode, String message, EObject element) {
setTarget(element, null);
lastError = errorCode;
addDiagnostic(new DiagnosticMessage(message, Severity.ERROR, null));
lastError = null;
}
use of org.eclipse.xtext.diagnostics.DiagnosticMessage in project xtext-core by eclipse.
the class Linker method ensureIsLinked.
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void ensureIsLinked(EObject obj, INode node, CrossReference ref, Set<EReference> handledReferences, IDiagnosticProducer producer) {
final EReference eRef = GrammarUtil.getReference(ref, obj.eClass());
if (eRef == null) {
ILinkingDiagnosticMessageProvider.ILinkingDiagnosticContext context = createDiagnosticContext(obj, eRef, node);
DiagnosticMessage message = diagnosticMessageProvider.getIllegalCrossReferenceMessage(context, ref);
producer.addDiagnostic(message);
return;
}
handledReferences.add(eRef);
beforeEnsureIsLinked(obj, eRef, producer);
producer.setTarget(obj, eRef);
try {
final List<EObject> links = getLinkedObject(obj, eRef, node);
if (links == null || links.isEmpty()) {
if (!isNullValidResult(obj, eRef, node)) {
ILinkingDiagnosticMessageProvider.ILinkingDiagnosticContext context = createDiagnosticContext(obj, eRef, node);
DiagnosticMessage message = diagnosticMessageProvider.getUnresolvedProxyMessage(context);
producer.addDiagnostic(message);
}
return;
}
if (eRef.getUpperBound() >= 0 && links.size() > eRef.getUpperBound()) {
ILinkingDiagnosticMessageProvider.ILinkingDiagnosticContext context = createDiagnosticContext(obj, eRef, node);
DiagnosticMessage message = diagnosticMessageProvider.getViolatedBoundsConstraintMessage(context, links.size());
producer.addDiagnostic(message);
return;
}
if (eRef.getUpperBound() == 1) {
obj.eSet(eRef, links.get(0));
} else {
// eRef.getUpperBound() == -1 ||
// eRef.getUpperBound() < links.size
// TODO extract and check weather equals or identity is used by list
final List<EObject> list = (List<EObject>) obj.eGet(eRef);
if (links.size() > 1 && eRef.isUnique() && (list instanceof InternalEList)) {
final Set<EObject> addUs = new LinkedHashSet<EObject>(links);
// addUs.removeAll(list); // removeAll calls most likely list.contains() which is rather slow
for (int i = 0; i < list.size(); i++) addUs.remove(list.get(i));
if (!((InternalEList) list).addAllUnique(addUs)) {
ILinkingDiagnosticMessageProvider.ILinkingDiagnosticContext context = createDiagnosticContext(obj, eRef, node);
DiagnosticMessage message = diagnosticMessageProvider.getViolatedBoundsConstraintMessage(context, links.size());
producer.addDiagnostic(message);
}
} else if (!list.addAll(links)) {
ILinkingDiagnosticMessageProvider.ILinkingDiagnosticContext context = createDiagnosticContext(obj, eRef, node);
DiagnosticMessage message = diagnosticMessageProvider.getViolatedBoundsConstraintMessage(context, links.size());
producer.addDiagnostic(message);
}
}
} catch (IllegalNodeException e) {
ILinkingDiagnosticMessageProvider.ILinkingDiagnosticContext context = createDiagnosticContext(obj, eRef, node);
DiagnosticMessage message = diagnosticMessageProvider.getIllegalNodeMessage(context, e);
producer.addDiagnostic(message);
if (log.isDebugEnabled()) {
log.debug(e.getMessage(), e);
}
}
}
use of org.eclipse.xtext.diagnostics.DiagnosticMessage in project xtext-core by eclipse.
the class LazyLinkingResource method removeDiagnostic.
protected void removeDiagnostic(Triple<EObject, EReference, INode> triple) {
// return early if there's nothing to remove
if (getErrors().isEmpty() && getWarnings().isEmpty())
return;
DiagnosticMessage message = createDiagnosticMessage(triple);
List<Diagnostic> list = getDiagnosticList(message);
if (!list.isEmpty()) {
Diagnostic diagnostic = createDiagnostic(triple, message);
list.remove(diagnostic);
}
}
Aggregations