diff options
Diffstat (limited to 'src/cppcheckplus/text')
-rw-r--r-- | src/cppcheckplus/text/DeflectRow.java | 126 | ||||
-rw-r--r-- | src/cppcheckplus/text/FileTools.java | 84 | ||||
-rw-r--r-- | src/cppcheckplus/text/LineNumberHeaderView.java | 80 | ||||
-rw-r--r-- | src/cppcheckplus/text/MyButtonEditor.java | 88 | ||||
-rw-r--r-- | src/cppcheckplus/text/MyButtonRenderer.java | 62 | ||||
-rw-r--r-- | src/cppcheckplus/text/MyPanel.java | 31 | ||||
-rw-r--r-- | src/cppcheckplus/text/MyTextArea.java | 60 | ||||
-rw-r--r-- | src/cppcheckplus/text/MyTextPanel.java | 72 | ||||
-rw-r--r-- | src/cppcheckplus/text/MyTextPanel1.java | 58 | ||||
-rw-r--r-- | src/cppcheckplus/text/ViewPanel.java | 213 | ||||
-rw-r--r-- | src/cppcheckplus/text/creatTable.java | 321 | ||||
-rw-r--r-- | src/cppcheckplus/text/stdClangType.java | 9 |
12 files changed, 1204 insertions, 0 deletions
diff --git a/src/cppcheckplus/text/DeflectRow.java b/src/cppcheckplus/text/DeflectRow.java new file mode 100644 index 0000000..5b113a6 --- /dev/null +++ b/src/cppcheckplus/text/DeflectRow.java | |||
@@ -0,0 +1,126 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | public class DeflectRow { | ||
4 | |||
5 | public DeflectRow(String until, String file, String line, String level, String type, String cwe, | ||
6 | String description,int issure) { | ||
7 | super(); | ||
8 | this.until = until; | ||
9 | this.file = file; | ||
10 | this.line = line; | ||
11 | this.level = level; | ||
12 | this.type = type; | ||
13 | this.cwe = cwe; | ||
14 | this.description = description; | ||
15 | this.issure = issure; | ||
16 | } | ||
17 | @Override | ||
18 | public String toString() { | ||
19 | return "DeflectRow [until=" + until + ", file=" + file + ", line=" + line + ", level=" + level + ", type=" | ||
20 | + type + ", cwe=" + cwe + ", description=" + description + "]"; | ||
21 | } | ||
22 | private String until = null; | ||
23 | public String getUntil() { | ||
24 | return until; | ||
25 | } | ||
26 | public void setUntil(String until) { | ||
27 | this.until = until; | ||
28 | } | ||
29 | public String getFile() { | ||
30 | return file; | ||
31 | } | ||
32 | public void setFile(String file) { | ||
33 | this.file = file; | ||
34 | } | ||
35 | public String getLine() { | ||
36 | return line; | ||
37 | } | ||
38 | public void setLine(String line) { | ||
39 | this.line = line; | ||
40 | } | ||
41 | public String getLevel() { | ||
42 | return level; | ||
43 | } | ||
44 | public void setLevel(String level) { | ||
45 | this.level = level; | ||
46 | } | ||
47 | public String getType() { | ||
48 | return type; | ||
49 | } | ||
50 | public void setType(String type) { | ||
51 | this.type = type; | ||
52 | } | ||
53 | public String getCwe() { | ||
54 | return cwe; | ||
55 | } | ||
56 | public void setCwe(String cwe) { | ||
57 | this.cwe = cwe; | ||
58 | } | ||
59 | public String getDescription() { | ||
60 | return description; | ||
61 | } | ||
62 | public void setDescription(String description) { | ||
63 | this.description = description; | ||
64 | } | ||
65 | public int getIssure() { | ||
66 | return issure; | ||
67 | } | ||
68 | public void setIssure(int issure) { | ||
69 | this.issure = issure; | ||
70 | } | ||
71 | private String file = null; | ||
72 | private String line = null; | ||
73 | private String level = null; | ||
74 | private String type = null; | ||
75 | private String cwe = null; | ||
76 | private String description = null; | ||
77 | private int issure = 0; //0是未确认, 1是确认正确, 2是确认误报 | ||
78 | |||
79 | @Override | ||
80 | public int hashCode() { | ||
81 | final int prime = 31; | ||
82 | int result = 1; | ||
83 | result = prime * result + ((file == null) ? 0 : file.hashCode()); | ||
84 | result = prime * result + ((level == null) ? 0 : level.hashCode()); | ||
85 | result = prime * result + ((line == null) ? 0 : line.hashCode()); | ||
86 | result = prime * result + ((type == null) ? 0 : type.hashCode()); | ||
87 | return result; | ||
88 | } | ||
89 | |||
90 | @Override | ||
91 | public boolean equals(Object obj) { | ||
92 | if (this == obj) | ||
93 | return true; | ||
94 | if (obj == null) | ||
95 | return false; | ||
96 | if (getClass() != obj.getClass()) | ||
97 | return false; | ||
98 | DeflectRow other = (DeflectRow) obj; | ||
99 | if (file == null) { | ||
100 | if (other.file != null) | ||
101 | return false; | ||
102 | } else if (!file.equals(other.file)) | ||
103 | return false; | ||
104 | if (level == null) { | ||
105 | if (other.level != null) | ||
106 | return false; | ||
107 | } else if (!level.equals(other.level)) | ||
108 | return false; | ||
109 | if (line == null) { | ||
110 | if (other.line != null) | ||
111 | return false; | ||
112 | } else if (!line.equals(other.line)) | ||
113 | return false; | ||
114 | if (type == null) { | ||
115 | if (other.type != null) | ||
116 | return false; | ||
117 | } else if (!type.equals(other.type)) | ||
118 | return false; | ||
119 | if (until == null) { | ||
120 | if (other.until != null) | ||
121 | return false; | ||
122 | } else if (until.equals(other.until)) | ||
123 | return false; | ||
124 | return true; | ||
125 | } | ||
126 | } \ No newline at end of file | ||
diff --git a/src/cppcheckplus/text/FileTools.java b/src/cppcheckplus/text/FileTools.java new file mode 100644 index 0000000..95dd4fb --- /dev/null +++ b/src/cppcheckplus/text/FileTools.java | |||
@@ -0,0 +1,84 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | import java.io.BufferedReader; | ||
4 | import java.io.BufferedWriter; | ||
5 | import java.io.File; | ||
6 | import java.io.FileOutputStream; | ||
7 | import java.io.FileReader; | ||
8 | import java.io.FileWriter; | ||
9 | import java.util.Vector; | ||
10 | |||
11 | import org.dom4j.Document; | ||
12 | import org.dom4j.DocumentHelper; | ||
13 | import org.dom4j.Element; | ||
14 | import org.dom4j.io.OutputFormat; | ||
15 | import org.dom4j.io.XMLWriter; | ||
16 | |||
17 | public class FileTools { | ||
18 | |||
19 | public static String readFile(File file) { | ||
20 | StringBuilder resultStr = new StringBuilder(); | ||
21 | try { | ||
22 | BufferedReader bReader = new BufferedReader(new FileReader(file)); | ||
23 | String line = bReader.readLine(); | ||
24 | while (line != null) { | ||
25 | resultStr.append(line + "\r\n"); | ||
26 | line = bReader.readLine(); | ||
27 | } | ||
28 | bReader.close(); | ||
29 | } catch (Exception e) { | ||
30 | e.printStackTrace(); | ||
31 | } | ||
32 | return resultStr.toString(); | ||
33 | } | ||
34 | |||
35 | public static void writeFile(File file, String str) { | ||
36 | try { | ||
37 | BufferedWriter bWriter = new BufferedWriter(new FileWriter(file)); | ||
38 | bWriter.write(str); | ||
39 | bWriter.close(); | ||
40 | } catch (Exception e) { | ||
41 | e.printStackTrace(); | ||
42 | } | ||
43 | } | ||
44 | |||
45 | public static void writeFile(File file, Vector<DeflectRow> rows) {// xml | ||
46 | try { | ||
47 | Document doc = DocumentHelper.createDocument(); | ||
48 | Element root = doc.addElement("缺陷报告"); | ||
49 | int n = 0; | ||
50 | if (rows != null && rows.size() > 0) { | ||
51 | for (DeflectRow row : rows) { | ||
52 | if (row.getIssure() == 0 || row.getIssure() == 2) | ||
53 | continue; | ||
54 | n++; | ||
55 | Element empEle = root.addElement("item"); | ||
56 | |||
57 | Element untilEle = empEle.addElement("工具"); | ||
58 | untilEle.addText(row.getUntil()); | ||
59 | Element fileEle = empEle.addElement("文件路径"); | ||
60 | fileEle.addText(row.getFile()); | ||
61 | Element lineEle = empEle.addElement("行号"); | ||
62 | lineEle.addText(row.getLine()); | ||
63 | Element levelEle = empEle.addElement("级别"); | ||
64 | levelEle.addText(row.getLevel()); | ||
65 | Element typeEle = empEle.addElement("类型"); | ||
66 | typeEle.addText(row.getType()); | ||
67 | Element descEle = empEle.addElement("描述"); | ||
68 | descEle.addText(row.getDescription()); | ||
69 | empEle.addAttribute("id", n + ""); | ||
70 | } | ||
71 | XMLWriter writer = new XMLWriter(OutputFormat.createPrettyPrint()); | ||
72 | FileOutputStream fos = new FileOutputStream(file); | ||
73 | writer.setOutputStream(fos); | ||
74 | writer.write(doc); | ||
75 | System.out.println("写出完毕!"); | ||
76 | writer.close(); | ||
77 | |||
78 | } | ||
79 | } catch (Exception e) { | ||
80 | e.printStackTrace(); | ||
81 | } | ||
82 | } | ||
83 | |||
84 | } \ No newline at end of file | ||
diff --git a/src/cppcheckplus/text/LineNumberHeaderView.java b/src/cppcheckplus/text/LineNumberHeaderView.java new file mode 100644 index 0000000..85819fa --- /dev/null +++ b/src/cppcheckplus/text/LineNumberHeaderView.java | |||
@@ -0,0 +1,80 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | import java.awt.Color; | ||
4 | import java.awt.Dimension; | ||
5 | import java.awt.Font; | ||
6 | import java.awt.FontMetrics; | ||
7 | import java.awt.Graphics; | ||
8 | import java.awt.Rectangle; | ||
9 | |||
10 | public class LineNumberHeaderView extends javax.swing.JComponent { | ||
11 | |||
12 | private final Font DEFAULT_FONT = new Font("Serif", 0, 16); | ||
13 | public final Color DEFAULT_BACKGROUD = new Color(228, 228, 228); | ||
14 | public final Color DEFAULT_FOREGROUD = Color.BLACK; | ||
15 | public final int nHEIGHT = Integer.MAX_VALUE - 1000000; | ||
16 | public final int MARGIN = 2; | ||
17 | private int lineHeight; | ||
18 | private int fontLineHeight; | ||
19 | private int currentRowWidth; | ||
20 | private FontMetrics fontMetrics; | ||
21 | |||
22 | public LineNumberHeaderView() { | ||
23 | setFont(DEFAULT_FONT); | ||
24 | setForeground(DEFAULT_FOREGROUD); | ||
25 | setBackground(DEFAULT_BACKGROUD); | ||
26 | setPreferredSize(9999); | ||
27 | } | ||
28 | |||
29 | public void setPreferredSize(int row) { | ||
30 | int width = fontMetrics.stringWidth(String.valueOf(row)); | ||
31 | if (currentRowWidth < width) { | ||
32 | currentRowWidth = width; | ||
33 | setPreferredSize(new Dimension(2 * MARGIN + width, nHEIGHT)); | ||
34 | } | ||
35 | } | ||
36 | |||
37 | @Override | ||
38 | public void setFont(Font font) { | ||
39 | super.setFont(font); | ||
40 | fontMetrics = getFontMetrics(getFont()); | ||
41 | fontLineHeight = fontMetrics.getHeight(); | ||
42 | } | ||
43 | |||
44 | public int getLineHeight() { | ||
45 | if (lineHeight == 0) { | ||
46 | return fontLineHeight; | ||
47 | } | ||
48 | return lineHeight; | ||
49 | } | ||
50 | |||
51 | public void setLineHeight(int lineHeight) { | ||
52 | if (lineHeight > 0) { | ||
53 | this.lineHeight = lineHeight; | ||
54 | } | ||
55 | } | ||
56 | |||
57 | public int getStartOffset() { | ||
58 | return 0; | ||
59 | } | ||
60 | |||
61 | @Override | ||
62 | protected void paintComponent(Graphics g) { | ||
63 | int nlineHeight = getLineHeight(); | ||
64 | int startOffset = getStartOffset(); | ||
65 | Rectangle drawHere = g.getClipBounds(); | ||
66 | g.setColor(getBackground()); | ||
67 | g.fillRect(drawHere.x, drawHere.y, drawHere.width, drawHere.height); | ||
68 | g.setColor(getForeground()); | ||
69 | int startLineNum = (drawHere.y / nlineHeight) + 1; | ||
70 | int endLineNum = startLineNum + (drawHere.height / nlineHeight); | ||
71 | int start = (drawHere.y / nlineHeight) * nlineHeight + nlineHeight - startOffset; | ||
72 | for (int i = startLineNum; i <= endLineNum; ++i) { | ||
73 | String lineNum = String.valueOf(i); | ||
74 | int width = fontMetrics.stringWidth(lineNum); | ||
75 | g.drawString(lineNum + " ", MARGIN + currentRowWidth - width - 1, start); | ||
76 | start += nlineHeight; | ||
77 | } | ||
78 | setPreferredSize(endLineNum); | ||
79 | } | ||
80 | } | ||
diff --git a/src/cppcheckplus/text/MyButtonEditor.java b/src/cppcheckplus/text/MyButtonEditor.java new file mode 100644 index 0000000..6ce0007 --- /dev/null +++ b/src/cppcheckplus/text/MyButtonEditor.java | |||
@@ -0,0 +1,88 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | import java.awt.BorderLayout; | ||
4 | import java.awt.Component; | ||
5 | import java.awt.event.ActionEvent; | ||
6 | import java.awt.event.ActionListener; | ||
7 | |||
8 | import javax.swing.AbstractCellEditor; | ||
9 | import javax.swing.Icon; | ||
10 | import javax.swing.JButton; | ||
11 | import javax.swing.JOptionPane; | ||
12 | import javax.swing.JPanel; | ||
13 | import javax.swing.JTable; | ||
14 | import javax.swing.table.TableCellEditor; | ||
15 | |||
16 | import cppcheckplus.control.MyContorlUtil; | ||
17 | |||
18 | public class MyButtonEditor extends AbstractCellEditor implements TableCellEditor { | ||
19 | |||
20 | /** | ||
21 | * serialVersionUID | ||
22 | */ | ||
23 | private static final long serialVersionUID = -6546334664166791132L; | ||
24 | |||
25 | private JPanel panel; | ||
26 | |||
27 | private JButton button; | ||
28 | |||
29 | private int state; | ||
30 | public static Icon icon0; | ||
31 | public static Icon icon1; | ||
32 | public static Icon icon2; | ||
33 | public MyButtonEditor() { | ||
34 | |||
35 | initButton(); | ||
36 | |||
37 | initPanel(); | ||
38 | |||
39 | panel.add(this.button, BorderLayout.CENTER); | ||
40 | } | ||
41 | |||
42 | private void initButton() { | ||
43 | button = new JButton(); | ||
44 | |||
45 | icon0 = MyContorlUtil.getImageIcon("control/images/onError.gif"); | ||
46 | icon1 = MyContorlUtil.getImageIcon("control/images/agree_ok.gif"); | ||
47 | icon2 = MyContorlUtil.getImageIcon("control/images/agree_no.gif"); | ||
48 | button.addActionListener(new ActionListener() { | ||
49 | public void actionPerformed(ActionEvent e) { | ||
50 | int res = JOptionPane.showConfirmDialog(null, "你想确认报告吗?", "choose one", | ||
51 | JOptionPane.YES_NO_OPTION); | ||
52 | |||
53 | if (res == JOptionPane.YES_OPTION) { | ||
54 | state=(state+1)%3; | ||
55 | } | ||
56 | // stopped!!!! | ||
57 | fireEditingStopped(); | ||
58 | |||
59 | } | ||
60 | }); | ||
61 | |||
62 | } | ||
63 | |||
64 | private void initPanel() { | ||
65 | panel = new JPanel(); | ||
66 | |||
67 | panel.setLayout(new BorderLayout()); | ||
68 | } | ||
69 | |||
70 | @Override | ||
71 | public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { | ||
72 | state = (Integer) value; | ||
73 | |||
74 | if(state==0) | ||
75 | button.setIcon(icon0); | ||
76 | else if(state==1) | ||
77 | button.setIcon(icon1); | ||
78 | else if(state==2) | ||
79 | button.setIcon(icon2); | ||
80 | return panel; | ||
81 | } | ||
82 | |||
83 | @Override | ||
84 | public Object getCellEditorValue() { | ||
85 | return state; | ||
86 | } | ||
87 | |||
88 | } \ No newline at end of file | ||
diff --git a/src/cppcheckplus/text/MyButtonRenderer.java b/src/cppcheckplus/text/MyButtonRenderer.java new file mode 100644 index 0000000..e030620 --- /dev/null +++ b/src/cppcheckplus/text/MyButtonRenderer.java | |||
@@ -0,0 +1,62 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | import java.awt.BorderLayout; | ||
4 | import java.awt.Component; | ||
5 | |||
6 | import javax.swing.Icon; | ||
7 | import javax.swing.JButton; | ||
8 | import javax.swing.JPanel; | ||
9 | import javax.swing.JTable; | ||
10 | import javax.swing.table.TableCellRenderer; | ||
11 | |||
12 | import cppcheckplus.control.MyContorlUtil; | ||
13 | |||
14 | public class MyButtonRenderer implements TableCellRenderer { | ||
15 | private JPanel panel; | ||
16 | |||
17 | private JButton button; | ||
18 | |||
19 | public static Icon icon0; | ||
20 | public static Icon icon1; | ||
21 | public static Icon icon2; | ||
22 | private int state;//0是未确认, 1是确认正确, 2是确认误报 | ||
23 | |||
24 | public MyButtonRenderer() { | ||
25 | initButton(); | ||
26 | |||
27 | initPanel(); | ||
28 | |||
29 | panel.add(button, BorderLayout.CENTER); | ||
30 | } | ||
31 | |||
32 | private void initButton() { | ||
33 | button = new JButton(); | ||
34 | icon0 = MyContorlUtil.getImageIcon("control/images/onError.gif"); | ||
35 | icon1 = MyContorlUtil.getImageIcon("control/images/agree_ok.gif"); | ||
36 | icon2 = MyContorlUtil.getImageIcon("control/images/agree_no.gif"); | ||
37 | if(state==0) | ||
38 | button.setIcon(icon0); | ||
39 | else if(state==1) | ||
40 | button.setIcon(icon1); | ||
41 | else if(state==2) | ||
42 | button.setIcon(icon2); | ||
43 | } | ||
44 | |||
45 | private void initPanel() { | ||
46 | panel = new JPanel(); | ||
47 | panel.setLayout(new BorderLayout()); | ||
48 | } | ||
49 | |||
50 | public Component getTableCellRendererComponent(JTable table, Object value, | ||
51 | boolean isSelected, boolean hasFocus, int row, int column) { | ||
52 | state = (Integer) value; | ||
53 | if(state==0) | ||
54 | button.setIcon(icon0); | ||
55 | else if(state==1) | ||
56 | button.setIcon(icon1); | ||
57 | else if(state==2) | ||
58 | button.setIcon(icon2); | ||
59 | return panel; | ||
60 | } | ||
61 | |||
62 | } \ No newline at end of file | ||
diff --git a/src/cppcheckplus/text/MyPanel.java b/src/cppcheckplus/text/MyPanel.java new file mode 100644 index 0000000..cec59ac --- /dev/null +++ b/src/cppcheckplus/text/MyPanel.java | |||
@@ -0,0 +1,31 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | import java.awt.BorderLayout; | ||
4 | import java.awt.Graphics; | ||
5 | import java.awt.Image; | ||
6 | |||
7 | import javax.swing.ImageIcon; | ||
8 | import javax.swing.JPanel; | ||
9 | |||
10 | import cppcheckplus.control.MyContorlUtil; | ||
11 | |||
12 | public class MyPanel extends JPanel{ | ||
13 | ImageIcon icon; | ||
14 | Image img; | ||
15 | public MyPanel(){ | ||
16 | // /img/HomeImg.jpg 是存放在你正在编写的项目的bin文件夹下的img文件夹下的一个图片 | ||
17 | icon=new ImageIcon(MyContorlUtil.getImage("control/images/back2.jpg")); | ||
18 | img=icon.getImage(); | ||
19 | } | ||
20 | public MyPanel(BorderLayout borderLayout) { | ||
21 | icon=new ImageIcon(MyContorlUtil.getImage("control/images/back2.jpg")); | ||
22 | img=icon.getImage(); | ||
23 | setLayout(borderLayout); | ||
24 | } | ||
25 | public void paintComponent(Graphics g) { | ||
26 | super.paintComponent(g); | ||
27 | //下面这行是为了背景图片可以跟随窗口自行调整大小,可以自己设置成固定大小 | ||
28 | g.drawImage(img, 0, 0,this.getWidth(), this.getHeight(), this); | ||
29 | } | ||
30 | } | ||
31 | |||
diff --git a/src/cppcheckplus/text/MyTextArea.java b/src/cppcheckplus/text/MyTextArea.java new file mode 100644 index 0000000..9860093 --- /dev/null +++ b/src/cppcheckplus/text/MyTextArea.java | |||
@@ -0,0 +1,60 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | import java.awt.Dimension; | ||
4 | import java.awt.Graphics; | ||
5 | import java.awt.Graphics2D; | ||
6 | import java.awt.Image; | ||
7 | import java.awt.TexturePaint; | ||
8 | |||
9 | import javax.swing.BorderFactory; | ||
10 | import javax.swing.ImageIcon; | ||
11 | import javax.swing.JTextArea; | ||
12 | import javax.swing.border.Border; | ||
13 | import javax.swing.plaf.metal.MetalTextFieldUI; | ||
14 | |||
15 | import cppcheckplus.control.MyContorlUtil; | ||
16 | |||
17 | public class MyTextArea extends JTextArea{ | ||
18 | private Image backgroundLeftImage; | ||
19 | private Image backgroundRightImage; | ||
20 | private ImageIcon backgroundImageIcon; | ||
21 | private TexturePaint paint; | ||
22 | private Border border; | ||
23 | |||
24 | public MyTextArea () | ||
25 | { | ||
26 | backgroundLeftImage = MyContorlUtil.getImage("xujun/control/images/textfield_background_left.png"); | ||
27 | backgroundRightImage = MyContorlUtil.getImage("xujun/control/images/textfield_background_right.png"); | ||
28 | backgroundImageIcon = MyContorlUtil.getImageIcon("xujun/control/images/textfield_background.png"); | ||
29 | paint = MyContorlUtil.createTexturePaint("xujun/control/images/textfield_background.png"); | ||
30 | border = BorderFactory.createEmptyBorder(1, 3, 1, 3); | ||
31 | init(); | ||
32 | } | ||
33 | public MyTextArea (String text) | ||
34 | { | ||
35 | this(); | ||
36 | setText(text); | ||
37 | } | ||
38 | |||
39 | private void init() | ||
40 | { | ||
41 | setBorder(border); | ||
42 | setUI(new MetalTextFieldUI() { | ||
43 | |||
44 | protected void paintBackground(Graphics g) | ||
45 | { | ||
46 | Graphics2D g2d = (Graphics2D)g; | ||
47 | g2d.setPaint(paint); | ||
48 | g2d.fillRect(0, 0, getWidth(), getHeight()); | ||
49 | g2d.drawImage(backgroundLeftImage, 0, 0, null); | ||
50 | g2d.drawImage(backgroundRightImage, getWidth() - backgroundRightImage.getWidth(null), 0, null); | ||
51 | } | ||
52 | |||
53 | }); | ||
54 | } | ||
55 | |||
56 | public Dimension getPreferredSize() | ||
57 | { | ||
58 | return new Dimension(super.getPreferredSize().width, backgroundImageIcon.getIconHeight()); | ||
59 | } | ||
60 | } | ||
diff --git a/src/cppcheckplus/text/MyTextPanel.java b/src/cppcheckplus/text/MyTextPanel.java new file mode 100644 index 0000000..8ef60c4 --- /dev/null +++ b/src/cppcheckplus/text/MyTextPanel.java | |||
@@ -0,0 +1,72 @@ | |||
1 | |||
2 | package cppcheckplus.text; | ||
3 | |||
4 | import java.awt.BorderLayout; | ||
5 | import java.awt.Font; | ||
6 | |||
7 | import javax.swing.JPanel; | ||
8 | import javax.swing.JScrollPane; | ||
9 | import javax.swing.JTextArea; | ||
10 | |||
11 | import cppcheckplus.control.XChartletFullScreenListenter; | ||
12 | |||
13 | |||
14 | public class MyTextPanel extends JPanel implements XChartletFullScreenListenter | ||
15 | { | ||
16 | private BorderLayout layout; | ||
17 | private boolean isFullScreen; | ||
18 | private JTextArea textArea; | ||
19 | private JScrollPane scroll; | ||
20 | private LineNumberHeaderView lineNumberHeader=null; | ||
21 | public static final int LINEHEIGHT =16; | ||
22 | public JTextArea getTextArea() { | ||
23 | return textArea; | ||
24 | } | ||
25 | |||
26 | |||
27 | public MyTextPanel() | ||
28 | { | ||
29 | layout = new BorderLayout(); | ||
30 | setLayout(layout); | ||
31 | textArea=new JTextArea(""); | ||
32 | Font x = new Font("Serif",0,LINEHEIGHT); | ||
33 | textArea.setFont(x); | ||
34 | scroll = new JScrollPane(textArea); | ||
35 | //scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); | ||
36 | //scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); | ||
37 | //scroll.setPreferredSize(new Dimension(300, 200)); | ||
38 | |||
39 | if (lineNumberHeader == null) { | ||
40 | lineNumberHeader = new LineNumberHeaderView(); | ||
41 | //设置行号的高度,如果和textarea的行高不匹配,可以修改此值 | ||
42 | lineNumberHeader.setLineHeight(LINEHEIGHT+4); | ||
43 | } | ||
44 | scroll.setRowHeaderView(lineNumberHeader); | ||
45 | add(scroll); | ||
46 | } | ||
47 | |||
48 | public void initialize() | ||
49 | { | ||
50 | setLayout(layout); | ||
51 | add(scroll); | ||
52 | } | ||
53 | |||
54 | |||
55 | @Override | ||
56 | public void fullScreen(JPanel chartPanellet) | ||
57 | { | ||
58 | removeAll(); | ||
59 | isFullScreen = !isFullScreen; | ||
60 | if (isFullScreen) | ||
61 | { | ||
62 | setLayout(new BorderLayout()); | ||
63 | add(chartPanellet, "Center"); | ||
64 | } else | ||
65 | { | ||
66 | initialize(); | ||
67 | } | ||
68 | repaint(); | ||
69 | revalidate(); | ||
70 | } | ||
71 | |||
72 | } | ||
diff --git a/src/cppcheckplus/text/MyTextPanel1.java b/src/cppcheckplus/text/MyTextPanel1.java new file mode 100644 index 0000000..4a70ce5 --- /dev/null +++ b/src/cppcheckplus/text/MyTextPanel1.java | |||
@@ -0,0 +1,58 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | import java.awt.BorderLayout; | ||
4 | import java.awt.TextArea; | ||
5 | |||
6 | import javax.swing.JPanel; | ||
7 | |||
8 | import cppcheckplus.control.XChartletFullScreenListenter; | ||
9 | |||
10 | |||
11 | |||
12 | public class MyTextPanel1 extends JPanel implements XChartletFullScreenListenter | ||
13 | { | ||
14 | private BorderLayout layout; | ||
15 | private boolean isFullScreen; | ||
16 | private TextArea textArea; | ||
17 | |||
18 | public TextArea getTextArea() { | ||
19 | return textArea; | ||
20 | } | ||
21 | public void setTextArea(TextArea textArea) { | ||
22 | this.textArea = textArea; | ||
23 | } | ||
24 | |||
25 | public MyTextPanel1() | ||
26 | { | ||
27 | layout = new BorderLayout(); | ||
28 | setLayout(layout); | ||
29 | textArea=new TextArea(""); | ||
30 | |||
31 | add(textArea); | ||
32 | } | ||
33 | |||
34 | public void initialize() | ||
35 | { | ||
36 | setLayout(layout); | ||
37 | add(textArea); | ||
38 | } | ||
39 | |||
40 | |||
41 | @Override | ||
42 | public void fullScreen(JPanel chartPanellet) | ||
43 | { | ||
44 | removeAll(); | ||
45 | isFullScreen = !isFullScreen; | ||
46 | if (isFullScreen) | ||
47 | { | ||
48 | setLayout(new BorderLayout()); | ||
49 | add(chartPanellet, "Center"); | ||
50 | } else | ||
51 | { | ||
52 | initialize(); | ||
53 | } | ||
54 | repaint(); | ||
55 | revalidate(); | ||
56 | } | ||
57 | |||
58 | } | ||
diff --git a/src/cppcheckplus/text/ViewPanel.java b/src/cppcheckplus/text/ViewPanel.java new file mode 100644 index 0000000..c5b79d9 --- /dev/null +++ b/src/cppcheckplus/text/ViewPanel.java | |||
@@ -0,0 +1,213 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | import java.awt.BorderLayout; | ||
4 | import java.util.Vector; | ||
5 | |||
6 | import javax.swing.JPanel; | ||
7 | import javax.swing.JScrollPane; | ||
8 | import javax.swing.JTable; | ||
9 | import javax.swing.table.DefaultTableModel; | ||
10 | import javax.swing.table.TableColumn; | ||
11 | |||
12 | import cppcheckplus.control.XChartletFullScreenListenter; | ||
13 | |||
14 | |||
15 | public class ViewPanel extends JPanel implements XChartletFullScreenListenter { | ||
16 | |||
17 | private static final long serialVersionUID = 1L; | ||
18 | private DefaultTableModel model; | ||
19 | private JScrollPane jsp; | ||
20 | private JTable table; | ||
21 | private Vector<DeflectRow> results=new Vector<DeflectRow>(); | ||
22 | private BorderLayout layout; | ||
23 | private boolean isFullScreen; | ||
24 | |||
25 | public JTable getTable() { | ||
26 | return table; | ||
27 | } | ||
28 | |||
29 | public void setTable(JTable table) { | ||
30 | this.table = table; | ||
31 | } | ||
32 | |||
33 | public ViewPanel() { | ||
34 | |||
35 | layout = new BorderLayout(); | ||
36 | setLayout(layout); | ||
37 | |||
38 | String[] colnames = { "序号", "工具", "文件", "行号", "级别", "类型", "描述", "人工确认" }; | ||
39 | // 填充数据 | ||
40 | model = new DefaultTableModel(colnames, 0){ | ||
41 | @Override | ||
42 | public Object getValueAt(int row, int column) { | ||
43 | if(results!=null && row<results.size()){ | ||
44 | switch(column){ | ||
45 | case 1: | ||
46 | return results.elementAt(row).getUntil(); | ||
47 | case 2: | ||
48 | return results.elementAt(row).getFile(); | ||
49 | case 3: | ||
50 | return results.elementAt(row).getLine(); | ||
51 | case 4: | ||
52 | return results.elementAt(row).getLevel(); | ||
53 | case 5: | ||
54 | return results.elementAt(row).getType(); | ||
55 | case 6: | ||
56 | return results.elementAt(row).getDescription(); | ||
57 | case 7: | ||
58 | return results.elementAt(row).getIssure(); | ||
59 | case 0: | ||
60 | return row+1; | ||
61 | } | ||
62 | } | ||
63 | return null; | ||
64 | } | ||
65 | |||
66 | @Override | ||
67 | public boolean isCellEditable(int row, int column) { | ||
68 | if (column == 7 || column == 2 || column == 5) | ||
69 | return true; | ||
70 | return false; | ||
71 | } | ||
72 | /* | ||
73 | @Override | ||
74 | public int getRowCount() { | ||
75 | return results.size(); | ||
76 | }*/ | ||
77 | |||
78 | @Override | ||
79 | public int getColumnCount() { | ||
80 | return 8; | ||
81 | } | ||
82 | |||
83 | @Override | ||
84 | public void setValueAt(Object aValue, int row, int column){ | ||
85 | if(results!=null && row<results.size()){ | ||
86 | switch(column){ | ||
87 | case 1: | ||
88 | results.elementAt(row).setUntil((String)aValue); | ||
89 | break; | ||
90 | case 2: | ||
91 | results.elementAt(row).setFile((String)aValue); | ||
92 | break; | ||
93 | case 3: | ||
94 | results.elementAt(row).setLine((String)aValue); | ||
95 | break; | ||
96 | case 4: | ||
97 | results.elementAt(row).setLevel((String)aValue); | ||
98 | break; | ||
99 | case 5: | ||
100 | results.elementAt(row).setType((String)aValue); | ||
101 | break; | ||
102 | case 6: | ||
103 | results.elementAt(row).setDescription((String)aValue); | ||
104 | break; | ||
105 | case 7: | ||
106 | results.elementAt(row).setIssure((Integer)aValue); | ||
107 | break; | ||
108 | } | ||
109 | } | ||
110 | fireTableCellUpdated(row, column); | ||
111 | } | ||
112 | |||
113 | }; | ||
114 | |||
115 | table = new JTable(model); | ||
116 | TableColumn c1 = table.getColumnModel().getColumn(0); | ||
117 | c1.setPreferredWidth(30); | ||
118 | c1.setMaxWidth(30); | ||
119 | c1.setMinWidth(30); | ||
120 | TableColumn c2 = table.getColumnModel().getColumn(1); | ||
121 | c2.setPreferredWidth(60); | ||
122 | c2.setMaxWidth(60); | ||
123 | c2.setMinWidth(60); | ||
124 | TableColumn c3 = table.getColumnModel().getColumn(2); | ||
125 | c3.setPreferredWidth(160); | ||
126 | c3.setMaxWidth(160); | ||
127 | c3.setMinWidth(160); | ||
128 | TableColumn c4 = table.getColumnModel().getColumn(3); | ||
129 | c4.setPreferredWidth(40); | ||
130 | c4.setMaxWidth(40); | ||
131 | c4.setMinWidth(40); | ||
132 | TableColumn c5 = table.getColumnModel().getColumn(4); | ||
133 | c5.setPreferredWidth(30); | ||
134 | c5.setMaxWidth(30); | ||
135 | c5.setMinWidth(30); | ||
136 | TableColumn c6 = table.getColumnModel().getColumn(5); | ||
137 | c6.setPreferredWidth(100); | ||
138 | c6.setMaxWidth(100); | ||
139 | c6.setMinWidth(100); | ||
140 | TableColumn c8 = table.getColumnModel().getColumn(7); | ||
141 | c8.setPreferredWidth(100); | ||
142 | c8.setMaxWidth(100); | ||
143 | c8.setMinWidth(100); | ||
144 | |||
145 | table.getColumnModel().getColumn(7).setCellEditor(new MyButtonEditor()); | ||
146 | table.getColumnModel().getColumn(7).setCellRenderer(new MyButtonRenderer()); | ||
147 | table.setRowSelectionAllowed(false); | ||
148 | |||
149 | |||
150 | jsp = new JScrollPane(table); | ||
151 | add(jsp, BorderLayout.CENTER); | ||
152 | } | ||
153 | |||
154 | public ViewPanel(Vector<DeflectRow> rows) { | ||
155 | this(); | ||
156 | results = rows; | ||
157 | fillTable(results); | ||
158 | } | ||
159 | |||
160 | public void clearTable() { | ||
161 | model.setRowCount(0);// 清除原有行 | ||
162 | results.clear(); | ||
163 | table.invalidate(); | ||
164 | } | ||
165 | |||
166 | public void update(Vector<DeflectRow> rows) { | ||
167 | results = rows; | ||
168 | fillTable(results); | ||
169 | } | ||
170 | |||
171 | public void initialize() { | ||
172 | setLayout(layout); | ||
173 | add(jsp); | ||
174 | } | ||
175 | |||
176 | public void fillTable(Vector<DeflectRow> rows) { | ||
177 | |||
178 | model.setRowCount(0);// 清除原有行 | ||
179 | int n = 0; | ||
180 | if (rows != null && rows.size() > 0) { | ||
181 | for (DeflectRow row : rows) { | ||
182 | n++; | ||
183 | Object[] arr = new Object[8]; | ||
184 | arr[0] = String.valueOf(n); | ||
185 | arr[1] = row.getUntil(); | ||
186 | arr[2] = row.getFile(); | ||
187 | arr[3] = row.getLine(); | ||
188 | arr[4] = row.getLevel(); | ||
189 | arr[5] = row.getType(); | ||
190 | arr[6] = row.getDescription(); | ||
191 | arr[7] = row.getIssure(); | ||
192 | // 添加数据到表格 | ||
193 | model.addRow(arr); | ||
194 | } | ||
195 | } | ||
196 | table.invalidate(); | ||
197 | } | ||
198 | |||
199 | @Override | ||
200 | public void fullScreen(JPanel chartPanellet) { | ||
201 | removeAll(); | ||
202 | isFullScreen = !isFullScreen; | ||
203 | if (isFullScreen) { | ||
204 | setLayout(new BorderLayout()); | ||
205 | add(chartPanellet, "Center"); | ||
206 | } else { | ||
207 | initialize(); | ||
208 | } | ||
209 | repaint(); | ||
210 | revalidate(); | ||
211 | } | ||
212 | |||
213 | } | ||
diff --git a/src/cppcheckplus/text/creatTable.java b/src/cppcheckplus/text/creatTable.java new file mode 100644 index 0000000..0295eb6 --- /dev/null +++ b/src/cppcheckplus/text/creatTable.java | |||
@@ -0,0 +1,321 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | import java.util.Vector; | ||
4 | import java.util.regex.Pattern; | ||
5 | |||
6 | import javax.xml.parsers.DocumentBuilder; | ||
7 | import javax.xml.parsers.DocumentBuilderFactory; | ||
8 | |||
9 | import org.w3c.dom.Document; | ||
10 | import org.w3c.dom.Element; | ||
11 | import org.w3c.dom.Node; | ||
12 | import org.w3c.dom.NodeList; | ||
13 | |||
14 | import cppcheckplus.control.MyContorlUtil; | ||
15 | |||
16 | public class creatTable { | ||
17 | |||
18 | public String tableNameTemp = ""; | ||
19 | public Vector<DeflectRow> cppcheckplusResults = new Vector<DeflectRow>(); | ||
20 | public Vector<DeflectRow> flawfinderResults = new Vector<DeflectRow>(); | ||
21 | public Vector<DeflectRow> clangResults = new Vector<DeflectRow>(); | ||
22 | public Vector<DeflectRow> results = new Vector<DeflectRow>(); | ||
23 | public Vector<stdClangType> stdclang = new Vector<stdClangType>(); | ||
24 | |||
25 | public void initSTDClang(String xml){ | ||
26 | try | ||
27 | { | ||
28 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); | ||
29 | DocumentBuilder db = dbf.newDocumentBuilder(); | ||
30 | Document doc = db.parse(MyContorlUtil.getXMLFile(xml)); | ||
31 | Element root = doc.getDocumentElement(); | ||
32 | NodeList stdlist = root.getChildNodes(); | ||
33 | if (stdlist != null) | ||
34 | { | ||
35 | for (int i = 0; i < stdlist.getLength(); i++) | ||
36 | { | ||
37 | org.w3c.dom.Node menu = stdlist.item(i); | ||
38 | if (menu.getNodeType() == Node.ELEMENT_NODE) | ||
39 | { | ||
40 | if (menu.getNodeName().equalsIgnoreCase("clangNode")) | ||
41 | { | ||
42 | stdClangType node = new stdClangType(); | ||
43 | node.cwe=MyContorlUtil.getStringAttribute(menu, "cwe"); | ||
44 | node.level=MyContorlUtil.getStringAttribute(menu, "level"); | ||
45 | node.target=MyContorlUtil.getStringAttribute(menu, "target"); | ||
46 | node.len=Integer.valueOf(MyContorlUtil.getStringAttribute(menu, "len")); | ||
47 | node.type=MyContorlUtil.getStringAttribute(menu, "type"); | ||
48 | stdclang.add(node); | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | } | ||
54 | catch (Exception ex) | ||
55 | { | ||
56 | ex.printStackTrace(); | ||
57 | } | ||
58 | } | ||
59 | |||
60 | public void makeTable() {// 统一并输出 | ||
61 | results.clear(); | ||
62 | for (int i = 0; i < cppcheckplusResults.size(); i++) { | ||
63 | addObject(results,cppcheckplusResults.elementAt(i)); | ||
64 | } | ||
65 | for (int i = 0; i < clangResults.size(); i++) { | ||
66 | addObject(results,clangResults.elementAt(i)); | ||
67 | } | ||
68 | for (int i = 0; i < flawfinderResults.size(); i++) { | ||
69 | addObject(results,flawfinderResults.elementAt(i)); | ||
70 | } | ||
71 | } | ||
72 | |||
73 | public void clearall() {// 清除 | ||
74 | results.clear(); | ||
75 | clangResults.clear(); | ||
76 | flawfinderResults.clear(); | ||
77 | cppcheckplusResults.clear(); | ||
78 | } | ||
79 | |||
80 | public static void addObject(Vector<DeflectRow> nodes, DeflectRow node) { | ||
81 | if (!nodes.contains(node)) { | ||
82 | nodes.add(node); | ||
83 | } | ||
84 | else{//重复检测的缺陷需要标注 | ||
85 | int nodesNum = nodes.size(); | ||
86 | for(int i=0; i<nodesNum; i++){ | ||
87 | if(nodes.elementAt(i).equals(node)) | ||
88 | nodes.elementAt(i).setIssure(1); | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | |||
93 | //按文件、类型和级别排序 | ||
94 | public void ord(int ordType) {//1文件,2类型,3级别 | ||
95 | //final int prime = 31; | ||
96 | //Vector<DeflectRow> other = new Vector<DeflectRow>(); | ||
97 | if(ordType==1){//按照文件排序 | ||
98 | int memNum = results.size(); | ||
99 | for(int i=0; i<memNum-1; i++){ | ||
100 | for(int j=0; j<memNum-i-1; j++){ | ||
101 | if(results.elementAt(j).getFile().hashCode() | ||
102 | > results.elementAt(j+1).getFile().hashCode()){ | ||
103 | DeflectRow temp=results.elementAt(j); | ||
104 | results.set(j, results.elementAt(j+1)); | ||
105 | results.set(j+1, temp); | ||
106 | } | ||
107 | } | ||
108 | } | ||
109 | } | ||
110 | else if(ordType==2){//按照类型排序 | ||
111 | int memNum = results.size(); | ||
112 | for(int i=0; i<memNum-1; i++){ | ||
113 | for(int j=0; j<memNum-i-1; j++){ | ||
114 | if(results.elementAt(j).getType().hashCode() | ||
115 | > results.elementAt(j+1).getType().hashCode()){ | ||
116 | DeflectRow temp=results.elementAt(j); | ||
117 | results.set(j, results.elementAt(j+1)); | ||
118 | results.set(j+1, temp); | ||
119 | } | ||
120 | } | ||
121 | } | ||
122 | } | ||
123 | else if(ordType==3){//按照级别筛选 | ||
124 | int memNum = results.size(); | ||
125 | for(int i=0; i<memNum-1; i++){ | ||
126 | for(int j=0; j<memNum-i-1; j++){ | ||
127 | if(results.elementAt(j).getLevel().hashCode() | ||
128 | > results.elementAt(j+1).getLevel().hashCode()){ | ||
129 | DeflectRow temp=results.elementAt(j); | ||
130 | results.set(j, results.elementAt(j+1)); | ||
131 | results.set(j+1, temp); | ||
132 | } | ||
133 | } | ||
134 | } | ||
135 | } | ||
136 | } | ||
137 | |||
138 | public void toRowsOfCppcheckResult(String input) {// | ||
139 | String[] temp = input.split("\\$"); | ||
140 | int size = temp.length; | ||
141 | String until = null; | ||
142 | String file = null; | ||
143 | String line = null; | ||
144 | String level = null; | ||
145 | String type = null; | ||
146 | String cwe = null; | ||
147 | String description = null; | ||
148 | if (size > 6) { | ||
149 | if (temp[1].length() == 0) | ||
150 | return; | ||
151 | until = temp[0]; | ||
152 | file = temp[1]; | ||
153 | line = temp[2]; | ||
154 | level = temp[3]; | ||
155 | if (temp[3].equals("error")) | ||
156 | level = "4"; | ||
157 | else if (temp[3].equals("warning")) | ||
158 | level = "3"; | ||
159 | else if (temp[2].equals("style")) | ||
160 | level = "1"; | ||
161 | else if (temp[2].equals("information")) | ||
162 | level = "0"; | ||
163 | else | ||
164 | level = "2"; | ||
165 | type = temp[4]; | ||
166 | description = temp[5]; | ||
167 | cwe = temp[6]; | ||
168 | DeflectRow node = new DeflectRow(until, file, line, level, type, cwe, description, 0); | ||
169 | stdCppcheck(node); | ||
170 | cppcheckplusResults.add(node); | ||
171 | } | ||
172 | } | ||
173 | |||
174 | public void stdCppcheck(DeflectRow node) { | ||
175 | String cwe = node.getCwe(); | ||
176 | int cwenum = Integer.parseInt(cwe); | ||
177 | switch(cwenum){ //cppcheck向flawfinder看齐 | ||
178 | case 134: | ||
179 | node.setLevel("4"); | ||
180 | node.setType("format"); | ||
181 | break; | ||
182 | case 367: | ||
183 | node.setLevel("4"); | ||
184 | node.setType("race"); | ||
185 | break; | ||
186 | case 120: | ||
187 | node.setLevel("4"); | ||
188 | node.setType("buff"); | ||
189 | break; | ||
190 | case 78: | ||
191 | node.setLevel("4"); | ||
192 | node.setType("shell"); | ||
193 | break; | ||
194 | case 327: | ||
195 | node.setLevel("3"); | ||
196 | node.setType("random"); | ||
197 | break; | ||
198 | case 119: | ||
199 | node.setLevel("4"); | ||
200 | node.setType("buffer"); | ||
201 | break; | ||
202 | case 362: | ||
203 | node.setLevel("2"); | ||
204 | node.setType("misc"); | ||
205 | break; | ||
206 | case 190: | ||
207 | node.setLevel("2"); | ||
208 | node.setType("integer"); | ||
209 | break; | ||
210 | default: | ||
211 | ; | ||
212 | } | ||
213 | } | ||
214 | |||
215 | public void toRowsOfClang(String input) { | ||
216 | String[] temp = input.split(":"); | ||
217 | int size = temp.length; | ||
218 | String until = null; | ||
219 | String file = null; | ||
220 | String line = null; | ||
221 | String column = null; | ||
222 | String level = null; | ||
223 | String type = null; | ||
224 | String cwe = null; | ||
225 | String description = null; | ||
226 | if (size > 5) { | ||
227 | until = "clang-tidy"; | ||
228 | file = temp[0] + ":" + temp[1]; | ||
229 | line = temp[2]; | ||
230 | column = temp[3]; | ||
231 | level = temp[4];// warning,note, error | ||
232 | type = ""; | ||
233 | description = temp[5]; | ||
234 | cwe = "0"; | ||
235 | // 标准化 | ||
236 | DeflectRow node = new DeflectRow(until, file, line, level, type, cwe, description, 0); | ||
237 | stdClang(node); | ||
238 | clangResults.add(node); | ||
239 | } | ||
240 | } | ||
241 | |||
242 | public void stdClang(DeflectRow node) { | ||
243 | String describ = node.getDescription(); | ||
244 | int len = describ.length(); | ||
245 | boolean isFound = false; | ||
246 | for (int i = 0; i < stdclang.size(); i++) { | ||
247 | if(len>stdclang.elementAt(i).len){ | ||
248 | if (describ.substring(1, stdclang.elementAt(i).len).equals(stdclang.elementAt(i).target)) { | ||
249 | node.setCwe(stdclang.elementAt(i).cwe); | ||
250 | node.setLevel(stdclang.elementAt(i).level); | ||
251 | node.setType(stdclang.elementAt(i).type); | ||
252 | isFound=true; | ||
253 | return; | ||
254 | } | ||
255 | } | ||
256 | } | ||
257 | if(!isFound){ | ||
258 | node.setCwe("未知"); | ||
259 | node.setLevel("2"); | ||
260 | node.setType("other"); | ||
261 | } | ||
262 | } | ||
263 | |||
264 | |||
265 | public void toRowsOfFlawfinder(String csvFileName) {// csv | ||
266 | |||
267 | String until = null; | ||
268 | // public String defObject = null; | ||
269 | String file = null; | ||
270 | String location = null; | ||
271 | String level = null; | ||
272 | String type = null; | ||
273 | String function = null; | ||
274 | String description = null; | ||
275 | DeflectRow node = new DeflectRow(until, file, location, level, type, function, description, 0); | ||
276 | } | ||
277 | |||
278 | public boolean isInteger(String str){ | ||
279 | Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); | ||
280 | return pattern.matcher(str).matches(); | ||
281 | } | ||
282 | |||
283 | public void toRowsOfflawfinder(String input) { | ||
284 | // File,Line,Column,Level,Category,Name,Warning,Suggestion,Note,CWEs,Context,Fingerprint | ||
285 | String[] temp = input.split(","); | ||
286 | int size = temp.length; | ||
287 | String until = null; | ||
288 | String file = null; | ||
289 | String line = null; | ||
290 | String column = null; | ||
291 | String level = null; | ||
292 | String category = null; | ||
293 | String name = null; | ||
294 | String warning = null; | ||
295 | String suggestion = null; | ||
296 | String note = null; | ||
297 | String cwe = null; | ||
298 | String context = null; | ||
299 | String fingerprint = null; | ||
300 | if (size > 11) { | ||
301 | if(!isInteger(temp[1])) | ||
302 | return; | ||
303 | until = "flawfinder"; | ||
304 | file = temp[0]; | ||
305 | line = temp[1]; | ||
306 | column = temp[2]; | ||
307 | level = temp[3]; | ||
308 | category = temp[4]; | ||
309 | name = temp[5]; | ||
310 | warning = temp[6]; | ||
311 | suggestion = temp[7]; | ||
312 | note = temp[8]; | ||
313 | cwe = temp[9]; | ||
314 | context = temp[10]; | ||
315 | fingerprint = temp[11]; | ||
316 | DeflectRow node = new DeflectRow(until, file, line, level, category, cwe, warning, 0); | ||
317 | flawfinderResults.add(node); | ||
318 | } | ||
319 | } | ||
320 | |||
321 | } | ||
diff --git a/src/cppcheckplus/text/stdClangType.java b/src/cppcheckplus/text/stdClangType.java new file mode 100644 index 0000000..42e9c37 --- /dev/null +++ b/src/cppcheckplus/text/stdClangType.java | |||
@@ -0,0 +1,9 @@ | |||
1 | package cppcheckplus.text; | ||
2 | |||
3 | public class stdClangType { | ||
4 | public int len; | ||
5 | public String cwe; | ||
6 | public String type; | ||
7 | public String level; | ||
8 | public String target; | ||
9 | } | ||