Search in sources :

Example 1 with DiagnosticMessage

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;
    }
}
Also used : DiagnosticMessage(org.eclipse.xtext.diagnostics.DiagnosticMessage)

Example 2 with DiagnosticMessage

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

Example 3 with DiagnosticMessage

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;
}
Also used : DiagnosticMessage(org.eclipse.xtext.diagnostics.DiagnosticMessage)

Example 4 with DiagnosticMessage

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);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ILinkingDiagnosticMessageProvider(org.eclipse.xtext.linking.ILinkingDiagnosticMessageProvider) ILinkingDiagnosticContext(org.eclipse.xtext.linking.ILinkingDiagnosticMessageProvider.ILinkingDiagnosticContext) DiagnosticMessage(org.eclipse.xtext.diagnostics.DiagnosticMessage) EObject(org.eclipse.emf.ecore.EObject) InternalEList(org.eclipse.emf.ecore.util.InternalEList) List(java.util.List) InternalEList(org.eclipse.emf.ecore.util.InternalEList) ILinkingDiagnosticContext(org.eclipse.xtext.linking.ILinkingDiagnosticMessageProvider.ILinkingDiagnosticContext) EReference(org.eclipse.emf.ecore.EReference)

Example 5 with DiagnosticMessage

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);
    }
}
Also used : DiagnosticMessage(org.eclipse.xtext.diagnostics.DiagnosticMessage) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic)

Aggregations

DiagnosticMessage (org.eclipse.xtext.diagnostics.DiagnosticMessage)12 EObject (org.eclipse.emf.ecore.EObject)4 ExceptionDiagnostic (org.eclipse.xtext.diagnostics.ExceptionDiagnostic)3 ILinkingDiagnosticMessageProvider (org.eclipse.xtext.linking.ILinkingDiagnosticMessageProvider)3 ILinkingDiagnosticContext (org.eclipse.xtext.linking.ILinkingDiagnosticMessageProvider.ILinkingDiagnosticContext)3 XtextLinkingDiagnostic (org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic)3 List (java.util.List)2 EReference (org.eclipse.emf.ecore.EReference)2 InternalEList (org.eclipse.emf.ecore.util.InternalEList)2 AbstractRule (org.eclipse.xtext.AbstractRule)2 RuleCall (org.eclipse.xtext.RuleCall)2 LinkedHashSet (java.util.LinkedHashSet)1 EAnnotation (org.eclipse.emf.ecore.EAnnotation)1 EClass (org.eclipse.emf.ecore.EClass)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 AbstractElement (org.eclipse.xtext.AbstractElement)1 AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)1 EnumRule (org.eclipse.xtext.EnumRule)1