<commit_before>package com.redhat.ceylon.eclipse.imp.parser;

import org.antlr.runtime.CommonToken;
import org.antlr.runtime.Token;
import org.eclipse.imp.parser.IMessageHandler;

import com.redhat.ceylon.compiler.typechecker.parser.RecognitionError;
import com.redhat.ceylon.compiler.typechecker.tree.AnalysisMessage;
import com.redhat.ceylon.compiler.typechecker.tree.Message;
import com.redhat.ceylon.compiler.typechecker.tree.Node;
import com.redhat.ceylon.compiler.typechecker.tree.Visitor;

public class ErrorVisitor extends Visitor {
    private final IMessageHandler handler;

    public ErrorVisitor(IMessageHandler handler) {
        this.handler = handler;
    }

    @Override
    public void visitAny(Node node) {
        super.visitAny(node);
        for (Message error : node.getErrors()) {
            String errorMessage = error.getMessage();
            int startOffset = 0;
            int endOffset = 0;
            int startCol = 0;
            int startLine = 0;

            // Map<String, Object> attributes = new HashMap<String, Object>();
            if (error instanceof RecognitionError) {
                RecognitionError recognitionError = (RecognitionError) error;
                CommonToken token = (CommonToken) recognitionError
                        .getRecognitionException().token;
                startOffset = token.getStartIndex();
                endOffset = token.getStopIndex();
                startCol = token.getCharPositionInLine();
                startLine = token.getLine();
                // attributes.put(SEVERITY_KEY, ERROR);
            }
            if (error instanceof AnalysisMessage) {
                AnalysisMessage analysisMessage = (AnalysisMessage) error;
                Node errorNode = CeylonSourcePositionLocator
                        .getIdentifyingNode(analysisMessage.getTreeNode());
                if (errorNode == null)
                    errorNode = analysisMessage.getTreeNode();
                Token token = errorNode.getToken();
                startOffset = errorNode.getStartIndex();
                endOffset = errorNode.getStopIndex();
                startCol = token.getCharPositionInLine();
                startLine = token.getLine();
                /*
                 * if (error instanceof AnalysisWarning) {
                 * attributes.put(SEVERITY_KEY, WARNING); } else {
                 * attributes.put(SEVERITY_KEY, ERROR); }
                 */
            }

            handler.handleSimpleMessage(errorMessage, startOffset, endOffset,
                    startCol, startCol, startLine, startLine/* , attributes */);
        }
    }
}<commit_msg>init problem attributes for use in quick fixes<commit_after>package com.redhat.ceylon.eclipse.imp.parser;

import java.util.HashMap;
import java.util.Map;

import org.antlr.runtime.CommonToken;
import org.antlr.runtime.Token;
import org.eclipse.imp.parser.IMessageHandler;

import com.redhat.ceylon.compiler.typechecker.parser.RecognitionError;
import com.redhat.ceylon.compiler.typechecker.tree.AnalysisMessage;
import com.redhat.ceylon.compiler.typechecker.tree.Message;
import com.redhat.ceylon.compiler.typechecker.tree.Node;
import com.redhat.ceylon.compiler.typechecker.tree.Visitor;

public abstract class ErrorVisitor extends Visitor {
    private final IMessageHandler handler;
    
    public ErrorVisitor(IMessageHandler handler) {
        this.handler = handler;
    }

    @Override
    public void visitAny(Node node) {
        super.visitAny(node);
        for (Message error : node.getErrors()) {
            String errorMessage = error.getMessage();
            int startOffset = 0;
            int endOffset = 0;
            int startCol = 0;
            int startLine = 0;

            Map<String, Object> attributes = new HashMap<String, Object>();
            if (error instanceof RecognitionError) {
                RecognitionError recognitionError = (RecognitionError) error;
                CommonToken token = (CommonToken) recognitionError
                        .getRecognitionException().token;
                startOffset = token.getStartIndex();
                endOffset = token.getStopIndex();
                startCol = token.getCharPositionInLine();
                startLine = token.getLine();
            }
            if (error instanceof AnalysisMessage) {
                AnalysisMessage analysisMessage = (AnalysisMessage) error;
                Node errorNode = CeylonSourcePositionLocator
                        .getIdentifyingNode(analysisMessage.getTreeNode());
                if (errorNode == null)
                    errorNode = analysisMessage.getTreeNode();
                Token token = errorNode.getToken();
                startOffset = errorNode.getStartIndex();
                endOffset = errorNode.getStopIndex();
                startCol = token.getCharPositionInLine();
                startLine = token.getLine();
            }
            attributes.put("CeylonMessageClass", error.getClass().getSimpleName());
            attributes.put(IMessageHandler.SEVERITY_KEY, getSeverity(error));
            //TODO: get a real error code from the type checker!
            attributes.put(IMessageHandler.ERROR_CODE_KEY, 69);

            handler.handleSimpleMessage(errorMessage, startOffset, endOffset,
                    startCol, startCol, startLine, startLine, attributes);
        }
    }

    public abstract int getSeverity(Message error);
}
{'fraction_non_alphanumeric': 0.0886284563266801, 'fraction_numerical': 0.0018311664530305805, 'mean_word_length': 2.2319526627218935, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4159228', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1334, 'n_words': 284}