All Downloads are FREE. Search and download functionalities are using the official Maven repository.

patterntesting.tool.aspectj.AjcErrorHandler Maven / Gradle / Ivy

Go to download

PatternTesting Tools (patterntesting-tools) is the container for tools around PatternTesting like the Ant extensions and Maven plugin.

The newest version!
/* 
 *========================================================================
 * 
 * Copyright 2001-2004 Vincent Massol & Matt Smith.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 *========================================================================
 */
package patterntesting.tool.aspectj;

import java.util.*;

import org.aspectj.bridge.*;

/**
 * Error handler to pass to the Ajc compiler in order to get
 * structured error information.
 *
 * @author Vincent Massol
 * @author Matt Smith
 *
 * @version $Id: AjcErrorHandler.java,v 1.5 2009/12/30 13:33:04 oboehm Exp $
 */
public class AjcErrorHandler extends MessageHandler {

    /** counter for the logged warnings */
    protected static int loggedWarnings = 0;

    /**
     * Lists of errors received from the Ajc compiler. Array of
     * {@link AjcFileResult} objects.
     */
    private Hashtable errors = new Hashtable();

    /**
     * @return the list of errors received from the Ajc compiler as
     *          a List of AjcResult objects
     */
    public Enumeration getResults() {
        return this.errors.elements();
    }

    /**
     * @return the map of errors received from the Ajc compiler as
     *          a map of AjcResult objects
     */
    public Map getErrorResults() {
        return errors;
    }

    /** 
	 * @see org.aspectj.bridge.IMessageHandler#handleMessage(org.aspectj.bridge.IMessage)
	 */
    public boolean handleMessage(IMessage message) {
        ISourceLocation location = message.getSourceLocation();
        if (location != null) {
            String path = location.getSourceFile().getPath();
            AjcFileResult fileResult = (AjcFileResult) this.errors.get(path);
            if (fileResult == null) {
                fileResult = new AjcFileResult(path);
                this.errors.put(path, fileResult);
            }
            if (message.getKind() == IMessage.ERROR) {
                fileResult.addError(new AjcResult(location.getLine(), message
                        .getMessage()));
            } else {
                fileResult.addWarning(new AjcResult(location.getLine(), message
                        .getMessage()));
            }
            // this.write();
        }
        return true;
    }

	/**
	 * @see Object#toString()
	 */
    public String toString() {
    	if (errors.size() > 0) {
    		return "AjcErrorHandler: with error/warning(s)";
    	} else {
    		return super.toString();
    	}
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy