📄 errorlogger.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: ErrorLogger.java * * Copyright (c) 2004 Sun Microsystems and Free Software * * Electric(tm) is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * Electric(tm) is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Electric(tm); see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, Mass 02111-1307, USA. */package com.sun.electric.tool.user;import com.sun.electric.database.geometry.EPoint;import com.sun.electric.database.geometry.PolyBase;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.hierarchy.EDatabase;import com.sun.electric.database.hierarchy.Export;import com.sun.electric.database.hierarchy.Library;import com.sun.electric.database.hierarchy.View;import com.sun.electric.database.id.CellId;import com.sun.electric.database.text.ArrayIterator;import com.sun.electric.database.text.TextUtils;import com.sun.electric.database.topology.Geometric;import com.sun.electric.database.variable.VarContext;import com.sun.electric.tool.Job;import java.awt.geom.Point2D;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.PrintStream;import java.io.Serializable;import java.net.URL;import java.net.URLConnection;import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Set;import javax.xml.parsers.SAXParser;import javax.xml.parsers.SAXParserFactory;import org.xml.sax.Attributes;import org.xml.sax.InputSource;import org.xml.sax.SAXException;import org.xml.sax.SAXParseException;import org.xml.sax.helpers.DefaultHandler;/** * Class for logging errors. * Holds a log of errors: * <p>ErrorLogger errorLogger = ErrorLogger.newInstance(String s): get new logger for s * <p>MessageLog errorLog = errorLogger.logError(string msg, cell c, int k): * Create a new log with message 'msg', for cell 'c', with sortKey 'k'. * <p>Various methods for adding highlights to errorLog: * <p>To end logging, call errorLogger.termLogging(boolean explain). */public class ErrorLogger implements Serializable{ /** * Method to replace invalid characters in XML such as > or < * @param message * @return */ private static String correctXmlString(String message) { String m = message.replaceAll(">", ">"); m = m.replaceAll("<", "<"); return m; } /** * Create a Log of a single message. */ public static class MessageLog implements Comparable<MessageLog>, Serializable { private final String message; final CellId logCellId; // cell associated with log (not really used) private final int sortKey; private final ErrorHighlight[] highlights; protected int index; public MessageLog(String message, Cell cell, int sortKey, List<ErrorHighlight> highlights) { this(message, cell != null ? (CellId)cell.getId() : null, sortKey, highlights); } public MessageLog(String message, CellId logCellId, int sortKey, List<ErrorHighlight> highlights) { this.message = message; this.logCellId = logCellId; this.sortKey = sortKey; this.highlights = highlights.toArray(ErrorHighlight.NULL_ARRAY); index = 0; } public Cell getCell() { return (logCellId!=null)?EDatabase.clientDatabase().getCell(logCellId):null;} public String getMessageString() { return message; } public Iterator<ErrorHighlight> getHighlights() { return ArrayIterator.iterator(highlights); } public int getSortKey() { return sortKey; } /** * Compare objects lexicographically based on string comparator CASE_INSENSITIVE_ORDER * This method doesn't guarantee (compare(x, y)==0) == (x.equals(y)) * @param log1 * @return Returns a negative integer, zero, or a positive integer as the * first message has smaller than, equal to, or greater than the second lexicographically */ public int compareTo(MessageLog log1) { return (String.CASE_INSENSITIVE_ORDER.compare(message, log1.message)); } public boolean findGeometries(Geometric geo1, Cell cell1, Geometric geo2, Cell cell2) { boolean eh1found = false; boolean eh2found = false; for(ErrorHighlight eh : highlights) { if (eh.containsObject(cell1, geo1)) eh1found = true; if (eh.containsObject(cell2, geo2)) eh2found = true; if (eh1found && eh2found) return (true); } return (false); } /** * Method to describe error "elv". */ public String getMessage() { return "["+index+"] "+message; } protected void xmlDescription(PrintStream msg) { String className = this.getClass().getSimpleName(); String cellInfo = ""; if (logCellId != null) { Cell logCell = getCell(); if (logCell != null) cellInfo = "cellName=\"" + logCell.describe(false) + "\""; } // replace those characters that XML defines as special such as ">" and "&" String m = correctXmlString(message); msg.append("\t<" + className + " message=\"" + m + "\" " + cellInfo + ">\n"); for(ErrorHighlight eh : highlights) { eh.xmlDescription(msg, EDatabase.clientDatabase()); } msg.append("\t</" + className + ">\n"); } /** * Returns true if this error log is still valid * (In a linked Cell, and all highlights are still valid) */ public boolean isValid(EDatabase database) { if (logCellId == null) return true; if (database.getCell(logCellId) == null) return false; // check validity of highlights boolean allValid = true; for (ErrorHighlight erh : highlights) { if (!erh.isValid(database)) { allValid = false; break; } } return allValid; } } private static class ErrorLogOrder implements Comparator<MessageLog> { public int compare(MessageLog el1, MessageLog el2) { int sortedKey = el1.sortKey - el2.sortKey; if (sortedKey == 0) // Identical, compare lexicographically sortedKey = el1.compareTo(el2); return sortedKey; //el1.sortKey - el2.sortKey; } } /** * Create a Log of a single warning. */ public static class WarningLog extends MessageLog { public WarningLog(String message, Cell cell, int sortKey, List<ErrorHighlight> highlights) { super(message, cell, sortKey, highlights); } }// private boolean alreadyExplained; private int errorLimit; private List<MessageLog> allErrors; private List<WarningLog> allWarnings; private boolean limitExceeded; private String errorSystem; private boolean terminated; private boolean persistent; // cannot be deleted private HashMap<Integer,String> sortKeysToGroupNames; // association of sortKeys to GroupNames public HashMap<Integer,String> getSortKeyToGroupNames() { return sortKeysToGroupNames; } public String getSystem() { return errorSystem; } public boolean isPersistent() {return persistent;} public ErrorLogger() {} /** * Create a new ErrorLogger instance. * @return a new ErrorLogger for logging errors */ public static ErrorLogger newInstance(String system) { return newInstance(system, false); } /** * Create a new ErrorLogger instance. * @return a new ErrorLogger for logging errors */ public static ErrorLogger newInstance(String system, boolean persistent) { ErrorLogger logger = new ErrorLogger(); logger.allErrors = new ArrayList<MessageLog>(); logger.allWarnings = new ArrayList<WarningLog>(); logger.limitExceeded = false; logger.errorSystem = system; logger.errorLimit = User.getErrorLimit(); logger.terminated = false; logger.persistent = persistent;// logger.alreadyExplained = false; logger.sortKeysToGroupNames = null; return logger; } public void addMessages(List<MessageLog> messages) { if (messages == null) return; // to avoid to increate empty lists during incremental checking for (MessageLog m: messages) { if (m instanceof WarningLog) allWarnings.add((WarningLog)m); else allErrors.add(m); }// if (persistent) Job.getUserInterface(). wantToRedoErrorTree(); } public void deleteMessages(List<MessageLog> messages) { if (messages == null) return; // to avoid to increate empty lists during incremental checking for (MessageLog m: messages) { if (m instanceof WarningLog) allWarnings.remove(m); else allErrors.remove(m); }// if (persistent) Job.getUserInterface(). wantToRedoErrorTree(); } /** * Factory method to create an error message and log. * with the given text "message" applying to cell "cell". * Returns a pointer to the message (0 on error) which can be used to add highlights. */ private synchronized MessageLog logAnError(String message, Cell cell, int sortKey, List<ErrorHighlight> highlights) { CellId cellId = cell != null ? cell.getId() : null; return logAnError(message, cellId, sortKey, highlights); } /** * Factory method to create an error message and log. * with the given text "message" applying to cell "cell". * Returns a pointer to the message (0 on error) which can be used to add highlights. */ private synchronized MessageLog logAnError(String message, CellId cellId, int sortKey, List<ErrorHighlight> highlights) { if (terminated && !persistent) { System.out.println("WARNING: "+errorSystem+" already terminated, should not log new error"); } // if too many errors, don't save it if (errorLimit > 0 && getNumErrors() >= errorLimit) { if (!limitExceeded) { System.out.println("WARNING: more than " + errorLimit + " errors found, ignoring the rest"); limitExceeded = true; } return null; } // create a new ErrorLog object MessageLog el = new MessageLog(message, cellId, sortKey, highlights); // add the ErrorLog into the global list allErrors.add(el);// currentLogNumber = allErrors.size()-1;// if (persistent) Job.getUserInterface().wantToRedoErrorTree(); return el; } /** * Factory method to log an error message. * @param message the string to display. * @param sortKey the sorting order of this message. */ public synchronized void logError(String message, int sortKey) { List<ErrorHighlight> h = new ArrayList<ErrorHighlight>(); logAnError(message, (CellId)null, sortKey, h); } /** * Factory method to log an error message. * @param message the string to display. * @param cell the cell in which this message applies. * @param sortKey the sorting order of this message. */ public synchronized void logError(String message, Cell cell, int sortKey) { List<ErrorHighlight> h = new ArrayList<ErrorHighlight>(); logAnError(message, cell, sortKey, h); } /** * Factory method to log an error message. * @param message the string to display. * @param cellId the Id of the cell in which this message applies. * @param sortKey the sorting order of this message. */ public synchronized void logError(String message, CellId cellId, int sortKey) { List<ErrorHighlight> h = new ArrayList<ErrorHighlight>(); logAnError(message, cellId, sortKey, h); } /** * Factory method to log an error message. * @param message the string to display. * @param geom the node or arc to display * @param cell the cell in which this message applies. * @param context the VarContext of the Cell. * @param sortKey the sorting order of this message. */ public synchronized void logError(String message, Geometric geom, Cell cell, VarContext context, int sortKey) { List<ErrorHighlight> h = new ArrayList<ErrorHighlight>(); h.add(ErrorHighlight.newInstance(context, geom)); logAnError(message, cell, sortKey, h); } /** * Factory method to log an error message. * @param message the string to display. * @param pp the Export to display * @param sortKey the sorting order of this message. */ public synchronized void logError(String message, Export pp, int sortKey) { Cell cell = pp.getParent(); List<ErrorHighlight> h = new ArrayList<ErrorHighlight>(); h.add(new ErrorHighExport(null, pp)); logAnError(message, cell, sortKey, h); } /** * Factory method to log an error message. * @param message the string to display. * @param pt the point to display * @param cell the cell in which this message applies. * @param sortKey the sorting order of this message. */ public synchronized void logError(String message, EPoint pt, Cell cell, int sortKey) { List<ErrorHighlight> h = new ArrayList<ErrorHighlight>(); h.add(new ErrorHighPoint(cell, pt)); logAnError(message, cell, sortKey, h);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -