|
69 | 69 | * cppcheck --enable=all |
70 | 70 | */ |
71 | 71 | public class CppCheckAnalyzer implements ICodeAnalyser { |
72 | | - public static final long DELAY_TIME = 500; |
| 72 | + //1 second |
| 73 | + private static final long DELAY_TIME = 1000; |
| 74 | + |
73 | 75 | private static final String TAG = "CppCheckAnalyzer"; |
74 | 76 |
|
75 | 77 | private static final String CPPCHECK_PROGRAM = "cppcheck"; |
@@ -144,50 +146,54 @@ protected void onPreExecute() { |
144 | 146 |
|
145 | 147 | @Override |
146 | 148 | protected String doInBackground(Void... voids) { |
147 | | - IEditAreaView editText = mEditorDelegate.getEditText(); |
148 | | - |
149 | | - File originFile = mEditorDelegate.getDocument().getFile(); |
150 | | - File tmpFile = new File(getCppCheckTmpDir(), originFile.getName()); |
151 | | - |
152 | | - LocalFileWriter localFileWriter = new LocalFileWriter(tmpFile, "UTF-8"); |
153 | 149 | try { |
154 | | - localFileWriter.writeToFile(editText.getText()); |
155 | | - } catch (IOException e) { |
156 | | - e.printStackTrace(); |
| 150 | + IEditAreaView editText = mEditorDelegate.getEditText(); |
| 151 | + |
| 152 | + File originFile = mEditorDelegate.getDocument().getFile(); |
| 153 | + File tmpFile = new File(getCppCheckTmpDir(), originFile.getName()); |
| 154 | + |
| 155 | + LocalFileWriter localFileWriter = new LocalFileWriter(tmpFile, "UTF-8"); |
| 156 | + try { |
| 157 | + localFileWriter.writeToFile(editText.getText()); |
| 158 | + } catch (IOException e) { |
| 159 | + e.printStackTrace(); |
| 160 | + return null; |
| 161 | + } |
| 162 | + |
| 163 | + ArgumentBuilder builder = new ArgumentBuilder(CPPCHECK_PROGRAM); |
| 164 | + builder.addFlags(CppCheckOutputParser.TEMPLATE); |
| 165 | + builder.addFlags(tmpFile.getAbsolutePath()); |
| 166 | + |
| 167 | + String enableFlags = ""; |
| 168 | + //flags |
| 169 | + Preferences setting = Preferences.getInstance(mContext); |
| 170 | + boolean warn = setting.getBoolean(mContext.getString(R.string.pref_key_cpp_check_warning), true); |
| 171 | + if (warn) enableFlags += "warning"; |
| 172 | + boolean performance = setting.getBoolean(mContext.getString(R.string.pref_key_cpp_check_performance), true); |
| 173 | + if (performance) { |
| 174 | + if (!enableFlags.isEmpty()) enableFlags += ","; |
| 175 | + enableFlags += "performance"; |
| 176 | + } |
| 177 | + boolean information = setting.getBoolean(mContext.getString(R.string.pref_key_cpp_check_information), true); |
| 178 | + if (information) { |
| 179 | + if (!enableFlags.isEmpty()) enableFlags += ","; |
| 180 | + enableFlags += "information"; |
| 181 | + } |
| 182 | + if (!enableFlags.isEmpty()) { |
| 183 | + builder.addFlags("--enable=" + enableFlags); |
| 184 | + } |
| 185 | + |
| 186 | + String cmd = builder.build(); |
| 187 | + CommandResult result = Shell.exec(mContext, tmpFile.getParent(), cmd); |
| 188 | + if (isCancelled()) { |
| 189 | + return null; |
| 190 | + } |
| 191 | + |
| 192 | + if (DLog.DEBUG) DLog.d(TAG, "result = " + result); |
| 193 | + return result.getMessage().replace(tmpFile.getAbsolutePath(), originFile.getAbsolutePath()); |
| 194 | + } catch (Exception e) { |
157 | 195 | return null; |
158 | 196 | } |
159 | | - |
160 | | - ArgumentBuilder builder = new ArgumentBuilder(CPPCHECK_PROGRAM); |
161 | | - builder.addFlags(CppCheckOutputParser.TEMPLATE); |
162 | | - builder.addFlags(tmpFile.getAbsolutePath()); |
163 | | - |
164 | | - String enableFlags = ""; |
165 | | - //flags |
166 | | - Preferences setting = Preferences.getInstance(mContext); |
167 | | - boolean warn = setting.getBoolean(mContext.getString(R.string.pref_key_cpp_check_warning), true); |
168 | | - if (warn) enableFlags += "warning"; |
169 | | - boolean performance = setting.getBoolean(mContext.getString(R.string.pref_key_cpp_check_performance), true); |
170 | | - if (performance) { |
171 | | - if (!enableFlags.isEmpty()) enableFlags += ","; |
172 | | - enableFlags += "performance"; |
173 | | - } |
174 | | - boolean information = setting.getBoolean(mContext.getString(R.string.pref_key_cpp_check_information), true); |
175 | | - if (information) { |
176 | | - if (!enableFlags.isEmpty()) enableFlags += ","; |
177 | | - enableFlags += "information"; |
178 | | - } |
179 | | - if (!enableFlags.isEmpty()) { |
180 | | - builder.addFlags("--enable=" + enableFlags); |
181 | | - } |
182 | | - |
183 | | - String cmd = builder.build(); |
184 | | - CommandResult result = Shell.exec(mContext, tmpFile.getParent(), cmd); |
185 | | - if (isCancelled()) { |
186 | | - return null; |
187 | | - } |
188 | | - |
189 | | - if (DLog.DEBUG) DLog.d(TAG, "result = " + result); |
190 | | - return result.getMessage().replace(tmpFile.getAbsolutePath(), originFile.getAbsolutePath()); |
191 | 197 | } |
192 | 198 |
|
193 | 199 | private File getCppCheckTmpDir() { |
|
0 commit comments