File indexing completed on 2024-04-28 05:49:18

0001 /***************************************************************************
0002                           xslt_parser.cpp  -  description
0003                              -------------------
0004     begin                : Mar 28 2007
0005     author               : 2007 jiri Tyr
0006     email                : jiri.tyr@vslib.cz
0007  ***************************************************************************/
0008 /***************************************************************************
0009  *                                                                         *
0010  *   SPDX-License-Identifier: GPL-2.0-or-later
0011  *                                                                         *
0012  ***************************************************************************/
0013 
0014 #include "plugin_katesymbolviewer.h"
0015 
0016 void KatePluginSymbolViewerView::parseXsltSymbols(void)
0017 {
0018     if (!m_mainWindow->activeView()) {
0019         return;
0020     }
0021 
0022     m_macro->setText(i18n("Show Params"));
0023     m_struct->setText(i18n("Show Variables"));
0024     m_func->setText(i18n("Show Templates"));
0025 
0026     QTreeWidgetItem *node = nullptr;
0027     QTreeWidgetItem *mcrNode = nullptr, *sctNode = nullptr, *clsNode = nullptr;
0028     QTreeWidgetItem *lastMcrNode = nullptr, *lastSctNode = nullptr, *lastClsNode = nullptr;
0029 
0030     KTextEditor::Document *kv = m_mainWindow->activeView()->document();
0031     // kdDebug(13000)<<"Lines counted :"<<kv->numLines()<<endl;
0032 
0033     if (m_treeOn->isChecked()) {
0034         mcrNode = new QTreeWidgetItem(m_symbols, QStringList(i18n("Params")));
0035         sctNode = new QTreeWidgetItem(m_symbols, QStringList(i18n("Variables")));
0036         clsNode = new QTreeWidgetItem(m_symbols, QStringList(i18n("Templates")));
0037         mcrNode->setIcon(0, m_icon_typedef);
0038         sctNode->setIcon(0, m_icon_variable);
0039         clsNode->setIcon(0, m_icon_class);
0040 
0041         if (m_expandOn->isChecked()) {
0042             m_symbols->expandItem(mcrNode);
0043             m_symbols->expandItem(sctNode);
0044             m_symbols->expandItem(clsNode);
0045         }
0046 
0047         lastMcrNode = mcrNode;
0048         lastSctNode = sctNode;
0049         lastClsNode = clsNode;
0050 
0051         m_symbols->setRootIsDecorated(1);
0052     } else {
0053         m_symbols->setRootIsDecorated(0);
0054     }
0055 
0056     bool is_comment = false, is_template = false;
0057     for (int i = 0; i < kv->lines(); i++) {
0058         QString cl = kv->line(i);
0059         cl = cl.trimmed();
0060 
0061         if (cl.indexOf(QLatin1String("<!--")) >= 0) {
0062             is_comment = true;
0063         }
0064         if (cl.indexOf(QLatin1String("-->")) >= 0) {
0065             is_comment = false;
0066             continue;
0067         }
0068 
0069         if (cl.indexOf(QRegularExpression(QLatin1String("^</xsl:template>"))) >= 0) {
0070             is_template = false;
0071             continue;
0072         }
0073 
0074         if (is_comment || is_template) {
0075             continue;
0076         }
0077 
0078         if (cl.indexOf(QRegularExpression(QLatin1String("^<xsl:param "))) == 0 && m_macro->isChecked()) {
0079             QString stripped = cl.remove(QRegularExpression(QLatin1String("^<xsl:param +name=\"")));
0080             stripped.remove(QRegularExpression(QLatin1String("\".*")));
0081 
0082             if (m_treeOn->isChecked()) {
0083                 node = new QTreeWidgetItem(mcrNode, lastMcrNode);
0084                 lastMcrNode = node;
0085             } else {
0086                 node = new QTreeWidgetItem(m_symbols);
0087             }
0088             node->setText(0, stripped);
0089             node->setIcon(0, m_icon_typedef);
0090             node->setText(1, QString::number(i, 10));
0091         }
0092 
0093         if (cl.indexOf(QRegularExpression(QLatin1String("^<xsl:variable "))) == 0 && m_struct->isChecked()) {
0094             QString stripped = cl.remove(QRegularExpression(QLatin1String("^<xsl:variable +name=\"")));
0095             stripped.remove(QRegularExpression(QLatin1String("\".*")));
0096 
0097             if (m_treeOn->isChecked()) {
0098                 node = new QTreeWidgetItem(sctNode, lastSctNode);
0099                 lastSctNode = node;
0100             } else {
0101                 node = new QTreeWidgetItem(m_symbols);
0102             }
0103             node->setText(0, stripped);
0104             node->setIcon(0, m_icon_variable);
0105             node->setText(1, QString::number(i, 10));
0106         }
0107 
0108         if (cl.indexOf(QRegularExpression(QLatin1String("^<xsl:template +match="))) == 0 && m_func->isChecked()) {
0109             QString stripped = cl.remove(QRegularExpression(QLatin1String("^<xsl:template +match=\"")));
0110             stripped.remove(QRegularExpression(QLatin1String("\".*")));
0111 
0112             if (m_treeOn->isChecked()) {
0113                 node = new QTreeWidgetItem(clsNode, lastClsNode);
0114                 lastClsNode = node;
0115             } else {
0116                 node = new QTreeWidgetItem(m_symbols);
0117             }
0118             node->setText(0, stripped);
0119             node->setIcon(0, m_icon_context);
0120             node->setText(1, QString::number(i, 10));
0121         }
0122 
0123         if (cl.indexOf(QRegularExpression(QLatin1String("^<xsl:template +name="))) == 0 && m_func->isChecked()) {
0124             QString stripped = cl.remove(QRegularExpression(QLatin1String("^<xsl:template +name=\"")));
0125             stripped.remove(QRegularExpression(QLatin1String("\".*")));
0126 
0127             if (m_treeOn->isChecked()) {
0128                 node = new QTreeWidgetItem(clsNode, lastClsNode);
0129                 lastClsNode = node;
0130             } else {
0131                 node = new QTreeWidgetItem(m_symbols);
0132             }
0133             node->setText(0, stripped);
0134             node->setIcon(0, m_icon_class);
0135             node->setText(1, QString::number(i, 10));
0136         }
0137 
0138         if (cl.indexOf(QLatin1String("<xsl:template")) >= 0) {
0139             is_template = true;
0140         }
0141     }
0142 }