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

📄 errorlogger.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        if (sortKeysToGroupNames != null)        {            // The keys must be sorted to keep same order as in the original ErrorLogger            Set<Integer> set = sortKeysToGroupNames.keySet();            List<Integer> sortedInt = new ArrayList<Integer>(set.size());            sortedInt.addAll(set); // adding to a list to sort them            Collections.sort(sortedInt);            for (Integer i : sortedInt)            {                String groupName = sortKeysToGroupNames.get(i);                buffWriter.println("    <GroupLog message=\"" + correctXmlString(groupName) + "\">");                // Errors                for (MessageLog log : allErrors) {                    if (log.getSortKey() == i.intValue())                        log.xmlDescription(buffWriter);                }                // Warnings                for (WarningLog log : allWarnings) {                    if (log.getSortKey() == i.intValue())                        log.xmlDescription(buffWriter);                }                buffWriter.println("    </GroupLog>");            }        }        else // plain style        {            // Errors            for (MessageLog log : allErrors) {                log.xmlDescription(buffWriter);            }            // Warnings            for (WarningLog log : allWarnings) {                log.xmlDescription(buffWriter);            }        }        buffWriter.println("</" + className + ">");        buffWriter.close();    }    /**     * Set a group name for a sortKey.  Doing so causes all errors with     * this sort key to be put in a sub-tree of the error tree with     * the groupName as the title of the sub-tree.     * @param sortKey the error log sortKey     * @param groupName the group name     */    public void setGroupName(int sortKey, String groupName) {        if (sortKeysToGroupNames == null) {            sortKeysToGroupNames = new HashMap<Integer,String>();        }        sortKeysToGroupNames.put(new Integer(sortKey), groupName);    }    /**     * Get a group name for a sortKey. It creates the hash map if it     * doesn't exist     * @param sortKey the error log sortKey     * @return the group name. Null if no group name was found     */    public String getGroupName(int sortKey)    {        if (sortKeysToGroupNames == null) {            sortKeysToGroupNames = new HashMap<Integer,String>();        }        return sortKeysToGroupNames.get(new Integer(sortKey));    }    /**     * Method called when all errors are logged.  Initializes pointers for replay of errors.     */    public synchronized void termLogging(boolean explain)    {//        termLogging_(true);        Job.getUserInterface().termLogging(this, explain, true);//        alreadyExplained = true;    }    public synchronized void termLogging_(boolean terminate)    {        // enumerate the errors        int errs = 0;        for(MessageLog el : allErrors)        {            el.index = ++errs;        }	    for(WarningLog el : allWarnings)        {            el.index = ++errs;        }        if (terminate)            terminated = true;    }    /**     * Method to retrieve general information about the errorLogger.     * @return general information about the errorLogger.     */    public String getInfo()    {        return (errorSystem + " found "+getNumErrors()+" errors, "+getNumWarnings()+" warnings!");    }    /**     * Method to sort the errors by their "key" (a value provided to "logerror()").     * Obviously, this should be called after all errors have been reported.     */    public synchronized void sortLogs()    {        Collections.sort(allErrors, new ErrorLogOrder());	    Collections.sort(allWarnings, new ErrorLogOrder());    }    /**     * Method to tell the number of logged errors.     * @return the number of "ErrorLog" objects logged.     */    public synchronized int getNumErrors() { return allErrors.size(); }        /**     * Method to tell the number of logged errors.     * @return the number of "ErrorLog" objects logged.     */    public synchronized int getNumWarnings() { return allWarnings.size(); }    /**     * Method to tell the number of logged errors.     * @return the number of "ErrorLog" objects logged.     */    public synchronized int getNumLogs() { return getNumWarnings() + getNumErrors(); }    public MessageLog getLog(int i) {        return i < allErrors.size() ? allErrors.get(i) : allWarnings.get(i - allErrors.size());    }    public int getLogIndex(MessageLog log)    {        int index = allErrors.indexOf(log);        if (index != -1)            return index;        index = allWarnings.indexOf(log);        if (index != -1)            return index + allErrors.size();        assert(false); // it should not reach one        return -1;    }        /**     * Method to list all logged errors and warnings.     * @return an Iterator over all of the "ErrorLog" objects.     */    public synchronized Iterator<MessageLog> getLogs() {        List<MessageLog> copy = new ArrayList<MessageLog>();        for (MessageLog ml : allErrors) {            copy.add(ml);        }	    for (WarningLog wl : allWarnings) {            copy.add(wl);        }        return copy.iterator();    }    public synchronized void deleteLog(int i) {        if (i < allErrors.size())            allErrors.remove(i);        else            allWarnings.remove(i - allErrors.size());    }    // ----------------------------- Explorer Tree Stuff ---------------------------//     public void databaseEndChangeBatch(Undo.ChangeBatch batch) {//         // check if any errors need to be deleted//         boolean changed = false;//         for (Iterator<MessageLog> it = getLogs(); it.hasNext(); ) {//             MessageLog err = it.next();//             if (!err.isValid()) {//                 deleteLog(err);//                 changed = true;//             }//         }//         if (changed)//             WindowFrame.wantToRedoErrorTree();//     }//     public void databaseChanged(Undo.Change evt) {}//     public boolean isGUIListener() {//         return true;//     }    public static class XMLParser    {        public ErrorLogger process(URL fileURL, boolean verbose)        {            try            {                // Factory call                SAXParserFactory factory = SAXParserFactory.newInstance();                factory.setNamespaceAware(true);                factory.setValidating(true);                // create the parser                SAXParser parser = factory.newSAXParser();                URLConnection urlCon = fileURL.openConnection();                InputStream inputStream = urlCon.getInputStream();                if (verbose) System.out.println("Parsing XML file \"" + fileURL + "\"");                XMLHandler handler = new XMLHandler();                parser.parse(inputStream, handler);                if (verbose) System.out.println("End Parsing XML file ...");                return handler.logger;            }            catch (Exception e)            {                e.printStackTrace();                return null;            }        }        private class XMLHandler extends DefaultHandler        {            private ErrorLogger logger = null;            private Cell curCell;            private String message = "";        	private List<ErrorHighlight> highlights;        	private Set<String> badCellNames = new HashSet<String>();            private int theSortLayer = -1, sortGroups = 1; // start from 1 so the errors without group would be all together            XMLHandler()            {            }            public InputSource resolveEntity (String publicId, String systemId) throws IOException, SAXException            {                System.out.println("It shouldn't reach this point!");                return null;            }            /**             * Method to finish the logger including counting of elements.             * @throws SAXException             */            public void endDocument () throws SAXException            {                logger.termLogging(true);            }            public void endElement (String uri, String localName, String qName)            {                boolean errorLogBody = qName.equals("MessageLog");                boolean warnLogBody = qName.equals("WarningLog");                boolean grpLogBody = qName.equals("GroupLog");                if (errorLogBody || warnLogBody)                {                    int sortLayer = 0;                    if (theSortLayer != -1) // use the group information from the file                       sortLayer = theSortLayer;                    else if (curCell != null) sortLayer = curCell.hashCode(); // sort by cell                    if (errorLogBody)                        logger.logAnError(message, curCell, sortLayer, highlights);                    else                        logger.logAWarning(message, curCell, sortLayer, highlights);                    message = "";                }                else if (grpLogBody)                {                    theSortLayer = -1; // reset to null again                }            }            public void startElement (String uri, String localName, String qName, Attributes attributes)            {                boolean loggerBody = qName.equals("ErrorLogger");                boolean groupBody = qName.equals("GroupLog");                boolean errorLogBody = qName.equals("MessageLog");                boolean warnLogBody = qName.equals("WarningLog");                boolean geoTypeBody = qName.equals("ERRORTYPEGEOM");                boolean thickLineTypeBody = qName.equals("ERRORTYPETHICKLINE");                boolean thinLineTypeBody = qName.equals("ERRORTYPELINE");                if (!loggerBody && !errorLogBody && !warnLogBody && !geoTypeBody                        && !groupBody                        && !thinLineTypeBody && !thickLineTypeBody) return;                String cellName = null, geomName = null, viewName = null, libraryName = null;                EPoint p1 = null, p2 = null;                for (int i = 0; i < attributes.getLength(); i++)                {                    if (attributes.getQName(i).equals("errorSystem"))                    {                        // Ignore the rest of the attribute and generate the logger                        logger = ErrorLogger.newInstance(attributes.getValue(i));                        return;                    }                    else if (attributes.getQName(i).startsWith("message"))                        message = attributes.getValue(i);                    else if (attributes.getQName(i).startsWith("cell"))                    {                        String origName = attributes.getValue(i);                        String[] names = TextUtils.parseString(attributes.getValue(i), "{}");                        cellName = origName; // names[0];                        viewName = names[1];                        // cellName might contain library name                        names = TextUtils.parseString(cellName, ":");                        if (names.length > 1)                        {                            libraryName = names[0];                            cellName = names[1];                        }                    }                    else if (attributes.getQName(i).startsWith("geom"))                        geomName = attributes.getValue(i);                    else if (attributes.getQName(i).startsWith("p1"))                    {                        String[] points = TextUtils.parseString(attributes.getValue(i), "(,)");                        double x = Double.parseDouble(points[0]);                        double y = Double.parseDouble(points[1]);                        p1 = new EPoint(x, y);                    }                    else if (attributes.getQName(i).startsWith("p2"))                    {                        String[] points = TextUtils.parseString(attributes.getValue(i), "(,)");                        double x = Double.parseDouble(points[0]);                        double y = Double.parseDouble(points[1]);                        p2 = new EPoint(x, y);                    }                    else if (attributes.getQName(i).startsWith("center"))                    {//                        String[] points = TextUtils.parseString(attributes.getValue(i), "(,)");                    }                    else                        new Error("Invalid attribute in XMLParser");                }                if (groupBody)                {                    assert (message != null);                    theSortLayer = sortGroups;                    logger.setGroupName(sortGroups++, message);                }                else                {                    if (viewName != null)                    {                        View view = View.findView(viewName);                        curCell = Library.findCellInLibraries(cellName, view, libraryName);                        if ((curCell == null || !curCell.isLinked()))                        {                            if (!badCellNames.contains(cellName))                            {                                badCellNames.add(cellName);                                System.out.println("Cannot find cell: " + cellName);                            }                            //return;                        }                    }                    if (errorLogBody || warnLogBody)                    {                        highlights = new ArrayList<ErrorHighlight>();                    }                    else if (geoTypeBody)                    {                        assert(curCell != null);                        Geometric geom = curCell.findNode(geomName);                        if (geom == null) // try arc instead                            geom = curCell.findArc(geomName);                        if (geom != null)                            highlights.add(ErrorHighlight.newInstance(null, geom));                        else                            System.out.println("Invalid geometry " + geomName + " in " + curCell);                    }                    else if (thinLineTypeBody || thickLineTypeBody)                    {                        highlights.add(new ErrorHighLine(curCell, p1, p2, thickLineTypeBody));                    }                    else                        new Error("Invalid attribute in XMLParser");                }            }            public void fatalError(SAXParseException e)            {                System.out.println("Parser Fatal Error in " + e.getLineNumber() + " " + e.getPublicId() + " " + e.getSystemId());                e.printStackTrace();            }            public void warning(SAXParseException e)            {                System.out.println("Parser Warning in " + e.getLineNumber() + " " + e.getPublicId() + " " + e.getSystemId());                e.printStackTrace();            }            public void error(SAXParseException e)            {                System.out.println("Parser Error in " + e.getLineNumber() + " " + e.getPublicId() + " " + e.getSystemId());                e.printStackTrace();            }        }    }}

⌨️ 快捷键说明

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