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

jdepend.framework.AbstractParser Maven / Gradle / Ivy

There is a newer version: 2.9.5
Show newest version
package jdepend.framework;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * The AbstractParser class is the base class
 * for classes capable of parsing files to create a
 * JavaClass instance.
 *
 * @author Mike Clark
 * @author Clarkware Consulting, Inc.
 */

public abstract class AbstractParser {

    private List parseListeners;
    private PackageFilter filter;
    public static boolean DEBUG = false;


    public AbstractParser() {
        this(PackageFilter.all().excludingProperties());
    }

    public AbstractParser(PackageFilter filter) {
        setFilter(filter);
        parseListeners = new ArrayList();
    }

    public void addParseListener(ParserListener listener) {
        parseListeners.add(listener);
    }

    /**
     * Registered parser listeners are informed that the resulting
     * JavaClass was parsed.
     */
    public abstract JavaClass parse(InputStream is) throws IOException;

    /**
     * Informs registered parser listeners that the specified
     * JavaClass was parsed.
     *
     * @param jClass Parsed Java class.
     */
    protected void onParsedJavaClass(JavaClass jClass) {
        for (ParserListener parseListener : parseListeners) {
            parseListener.onParsedJavaClass(jClass);
        }
    }

    protected PackageFilter getFilter() {
        if (filter == null) {
            setFilter(PackageFilter.all().excludingProperties());
        }
        return filter;
    }

    protected void setFilter(PackageFilter filter) {
        this.filter = filter;
    }

    protected void debug(String message) {
        if (DEBUG) {
            System.err.println(message);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy