⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parsermessage.java

📁 plugin for eclipse
💻 JAVA
字号:
/*
 * Created on May 31, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package isis.anp.common;

import isis.anp.nesc.ot.Outline;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


/**
 * Error/Warning message.
 * 
 * @author sallai
 */
public class ParserMessage extends Exception {

	private static final long serialVersionUID = 1L;

	public static final Level INFO = new Level(1, "INFO");

	public static final Level WARNING = new Level(2, "WARNING");

	public static final Level ERROR = new Level(4, "ERROR");

	public static final Level INTERNAL_ERROR = new Level(8, "INTERNAL ERROR");

	String message;

	List exceptions = new ArrayList();

	CodeLocation location;

	Level level;

	public ParserMessage(Level level, String m, CodeLocation location,
			Exception e) {
		this.addException(e);
		this.setMessage(m);
		this.setLocation(location);
		this.setLevel(level);
	}

	public void outline(Outline o) {
		o.addTabs();
		o.append(getLevel().getLabel() + ": ");
		o.append(getMessage());
		if (location != null) {
			o.append(" (Location: " + getLocation() + ")");
		}
		o.addNewLine();

		Iterator iter = this.getExceptions().iterator();
		while (iter.hasNext()) {
			Exception exception = (Exception) iter.next();
			if (exception != null) {

				o.incTabs();

				if (exception instanceof ParserMessage) {
					ParserMessage m = (ParserMessage) exception;
					m.outline(o);
				} else {
					o.addTabs();
					o.append("Exception: " + exception.toString());
					o.addNewLine();
				}
				o.decTabs();

			}
		}
	}

	public String toString() {
		Outline o = new Outline();
		outline(o);
		return o.toString();
	}

	/**
	 * @return Returns the exception.
	 */
	public List getExceptions() {
		return exceptions;
	}

	/**
	 * @return Returns the level.
	 */
	public Level getLevel() {
		return level;
	}

	/**
	 * @param level
	 *            The level to set.
	 */
	public void setLevel(Level level) {
		this.level = level;
	}

	/**
	 * @return Returns the location.
	 */
	public CodeLocation getLocation() {
		return location;
	}

	/**
	 * @param location
	 *            The location to set.
	 */
	public void setLocation(CodeLocation location) {
		this.location = location;
	}

	/**
	 * @return Returns the message.
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * @param message
	 *            The message to set.
	 */
	public void setMessage(String message) {
		this.message = message;
	}

	public static final class Level implements Comparable {
		private int level;

		private String label;

		private Level(int level, String label) {
			this.level = level;
			this.label = label;
		}

		public int compareTo(Object arg0) {
			if (arg0 instanceof Level) {
				Level other = (Level) arg0;

				if (other.level < this.level)
					return 1;
				else if (other.level > this.level)
					return -1;
				else if (other.level == this.level)
					return 0;
			}

			return -1;
		}

		/**
		 * @return Returns the label.
		 */
		public String getLabel() {
			return label;
		}

		/**
		 * @return Returns the level.
		 */
		public int getLevel() {
			return level;
		}
	}

	public void addException(Exception e) {
		if (e == null)
			return;
		exceptions.add(e);
	}

	
	public List getFlatMessageList(int mask) {
		return this.getFlatMessageList(mask, new ArrayList(), null);
	}
	
	private List getFlatMessageList(int mask, List l, CodeLocation parentMessageLocation) {
		// inherit parent's location
		if(this.getLocation() == null) this.setLocation(parentMessageLocation);
		
		// add to flattened list
		if((this.getLevel().getLevel() | mask) == mask)	l.add(this);
		
		// recurse
		Iterator i = this.getExceptions().iterator();
		while (i.hasNext()) {
			Exception e = (Exception) i.next();
			if (e instanceof ParserMessage) {
				ParserMessage m = (ParserMessage) e;
				m.getFlatMessageList(mask, l, this.getLocation());
			} else {
//				if((mask | ParserMessage.ERROR.getLevel()) == mask)
//					l.add(e);
			}
		}
		return l;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -