package org.metaborg.meta.nabl2.constraints.nameresolution;

import org.immutables.serial.Serial;
import org.immutables.value.Value;
import org.metaborg.meta.nabl2.constraints.IConstraint;
import org.metaborg.meta.nabl2.constraints.messages.IMessageContent;
import org.metaborg.meta.nabl2.constraints.messages.IMessageInfo;
import org.metaborg.meta.nabl2.constraints.messages.MessageContent;
import org.metaborg.meta.nabl2.terms.ITerm;

import com.google.common.base.Preconditions;

@Value.Immutable
@Serial.Version(value = 42L)
public abstract class CDeclProperty implements INameResolutionConstraint {

    @Value.Parameter public abstract ITerm getDeclaration();

    @Value.Parameter public abstract ITerm getKey();

    @Value.Parameter public abstract ITerm getValue();

    @Value.Parameter public abstract int getPriority();

    @Value.Parameter @Override public abstract IMessageInfo getMessageInfo();

    @Value.Check public void check() {
        Preconditions.checkArgument(getKey().isGround());
    }

    @Override public <T> T match(Cases<T> cases) {
        return cases.caseProperty(this);
    }

    @Override public <T> T match(IConstraint.Cases<T> cases) {
        return cases.caseNameResolution(this);
    }

    @Override public <T, E extends Throwable> T matchOrThrow(CheckedCases<T, E> cases) throws E {
        return cases.caseProperty(this);
    }

    @Override public <T, E extends Throwable> T matchOrThrow(IConstraint.CheckedCases<T, E> cases) throws E {
        return cases.caseNameResolution(this);
    }

    @Override public IMessageContent pp() {
        return MessageContent.builder().append(getDeclaration()).append(".").append(getKey()).append(" := ")
                .append(getValue()).build();
    }

    @Override public String toString() {
        return pp().toString();
    }

}
@@ -377,32 +377,95 @@
 MessageContent;%0A
+import org.metaborg.meta.nabl2.spoofax.analysis.AnalysisTerms;%0A
 import org.metab
@@ -1639,24 +1639,210 @@
 tent pp() %7B%0A
+        if(getKey().equals(AnalysisTerms.TYPE_KEY)) %7B%0A            return MessageContent.builder().append(getDeclaration()).append(%22 : %22).append(getValue()).build();%0A        %7D else %7B%0A    
         retu
@@ -1954,16 +1954,20 @@
         
+  
+  
 .append(
@@ -1983,24 +1983,34 @@
 )).build();%0A
+        %7D%0A
     %7D%0A%0A    @

Improve pretty-printing of typeOf constraints.