PageRenderTime 85ms CodeModel.GetById 28ms RepoModel.GetById 2ms app.codeStats 0ms

/plugins/Xrefactory/trunk/com/xrefactory/jedit/Dispatch.java

#
Java | 1143 lines | 1125 code | 17 blank | 1 comment | 18 complexity | 63e936516e88295325ddbc857ae9078f MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. package com.xrefactory.jedit;
  2. import org.gjt.sp.jedit.*;
  3. import java.io.*;
  4. import org.gjt.sp.jedit.help.*;
  5. import javax.swing.*;
  6. import org.gjt.sp.jedit.io.*;
  7. import java.awt.*;
  8. public class Dispatch {
  9. static String currentTag;
  10. static int attrLen;
  11. static int attrLine;
  12. static int attrCol;
  13. static int attrOffset;
  14. static int attrVal;
  15. static int attrLevel;
  16. static int attrNumber;
  17. static int attrBeep;
  18. static int attrSelected;
  19. static int attrMType;
  20. static int attrBase;
  21. static int attrDRefn;
  22. static int attrRefn;
  23. static int attrIndent;
  24. static int attrInterface;
  25. static int attrDefinition;
  26. static int attrTreeUp;
  27. static int attrContinue;
  28. static int attrNoFocus;
  29. static String attrTreeDeps;
  30. static String attrType;
  31. static String attrVClass;
  32. static String attrSymbol;
  33. static String stringVal;
  34. static String block;
  35. static void clearAttributes() {
  36. attrLen = 0;
  37. attrLine = 0;
  38. attrCol = 0;
  39. attrOffset = 0;
  40. attrVal = 0;
  41. attrLevel = 0;
  42. attrNumber = 0;
  43. attrBeep = 0;
  44. attrSelected = 0;
  45. attrMType = 0;
  46. attrBase = 0;
  47. attrDRefn = 0;
  48. attrRefn = 0;
  49. attrIndent = 0;
  50. attrInterface = 0;
  51. attrDefinition = 0;
  52. attrTreeUp = 0;
  53. attrNoFocus = 0;
  54. attrTreeDeps = null;
  55. attrType = null;
  56. attrVClass = null;
  57. }
  58. static void browseUrlIfConfirmed(String url, DispatchData data) {
  59. // sometimes it throws exception FileNotFoundor or what
  60. try {
  61. int confirm = JOptionPane.YES_OPTION;
  62. if (Opt.askBeforeBrowsingJavadoc()) {
  63. confirm = JOptionPane.showConfirmDialog(
  64. s.getProbableParent(data.callerComponent),
  65. "Browse URL: "+url+"?", "Confirmation",
  66. JOptionPane.YES_NO_OPTION,
  67. JOptionPane.QUESTION_MESSAGE);
  68. }
  69. if (confirm == JOptionPane.YES_OPTION) {
  70. s.browseUrl(url, false, s.getParentView(data.callerComponent));
  71. }
  72. } catch (Exception e) {}
  73. }
  74. public static void editorPreCheck(String str) throws XrefException {
  75. Buffer buffer = s.getBuffer();
  76. int caret = s.getCaretPosition();
  77. String text = buffer.getText(caret, str.length());
  78. if (! text.equals(str)) {
  79. throw new XrefException("expecting string "+str+" at this place, probably not updated references?");
  80. }
  81. }
  82. public static void editorReplace(String str, String with) throws XrefException {
  83. Buffer buffer = s.getBuffer();
  84. int caret = s.getCaretPosition();
  85. String text = buffer.getText(caret, str.length());
  86. if (! text.equals(str)) {
  87. throw new XrefException("should replace "+str+" with "+with+", but find "+text+" on this place");
  88. }
  89. buffer.remove(caret, str.length());
  90. buffer.insert(caret, with);
  91. }
  92. static void protocolCheckEq(String s1, String s2) throws Exception {
  93. if (! s1.equals(s2)) {
  94. throw new XrefException("Internal protocol error, got '"+s1+"' while expecting '"+s2+"'");
  95. }
  96. }
  97. public static int skipMyXmlIdentifier(XrefCharBuffer ss, int i, int len) {
  98. char c;
  99. c = ss.buf[i];
  100. while (i<len && (Character.isLetterOrDigit(c) || c=='-')) {
  101. i++;
  102. c = ss.buf[i];
  103. }
  104. return(i);
  105. }
  106. public static int skipAttribute(XrefCharBuffer ss, int i, int len) {
  107. char c;
  108. c = ss.buf[i];
  109. if (c=='"') {
  110. c = ' ';
  111. while (i<len && c!='"' && c!='\n') {
  112. i++;
  113. c = ss.buf[i];
  114. }
  115. if (i<len && c=='"') i++;
  116. } else {
  117. while (i<len && c!='>' && (! Character.isWhitespace(c))) {
  118. i++;
  119. c = ss.buf[i];
  120. }
  121. }
  122. return(i);
  123. }
  124. public static String unquote(String a) {
  125. int len = a.length();
  126. if (len>=2 && a.charAt(0)=='"' && a.charAt(len-1)=='"') {
  127. return(a.substring(1,len-1));
  128. } else {
  129. return(a);
  130. }
  131. }
  132. public static String getContext(XrefCharBuffer ss, int i, int len) {
  133. int j = i+20;
  134. String suffix="";
  135. if (j>=len) j=len;
  136. else suffix=" ...";
  137. return(ss.substring(i,j)+suffix);
  138. }
  139. public static int parseXmlTag(XrefCharBuffer ss, int i, int len) throws Exception {
  140. int j;
  141. char c;
  142. String attrib, attrval;
  143. i = s.skipBlank(ss, i, len);
  144. if (i>=len) throw new XrefException("parsing beyond end of communication string");
  145. if (ss.buf[i]!='<') {
  146. throw new XrefException("tag does not start with '<' ("+getContext(ss,i,len)+")");
  147. }
  148. i++;
  149. j = i;
  150. if (ss.buf[i]=='/') {
  151. // closing tag
  152. i++;
  153. }
  154. i = skipMyXmlIdentifier(ss, i, len);
  155. currentTag = ss.substring(j, i);
  156. //&System.err.println("Tag == " + currentTag + "\n");
  157. i = s.skipBlank(ss, i, len);
  158. while (ss.buf[i]!='>') {
  159. j=i; i=skipMyXmlIdentifier(ss, i, len);
  160. attrib = ss.substring(j,i);
  161. i = s.skipBlank(ss, i, len);
  162. if (ss.buf[i]!='=') throw new XrefException("= expected after attribute " + attrib);
  163. i++;
  164. j=i; i = skipAttribute(ss, i, len);
  165. attrval = ss.substring(j,i);
  166. // Integer.parseInt(ss.substring(j,i));
  167. // TODO!!!! do this via some hash table or what
  168. // this is pretty inefficient
  169. if (false) {
  170. } else if (attrib.equals(Protocol.PPCA_VCLASS)) {
  171. attrVClass = unquote(attrval);
  172. } else if (attrib.equals(Protocol.PPCA_BASE)) {
  173. attrBase = Integer.parseInt(attrval);
  174. } else if (attrib.equals(Protocol.PPCA_COL)) {
  175. attrCol = Integer.parseInt(attrval);
  176. } else if (attrib.equals(Protocol.PPCA_DEFINITION)) {
  177. attrDefinition = Integer.parseInt(attrval);
  178. } else if (attrib.equals(Protocol.PPCA_DEF_REFN)) {
  179. attrDRefn = Integer.parseInt(attrval);
  180. } else if (attrib.equals(Protocol.PPCA_INDENT)) {
  181. attrIndent = Integer.parseInt(attrval);
  182. } else if (attrib.equals(Protocol.PPCA_INTERFACE)) {
  183. attrInterface = Integer.parseInt(attrval);
  184. } else if (attrib.equals(Protocol.PPCA_LEN)) {
  185. attrLen = Integer.parseInt(attrval);
  186. } else if (attrib.equals(Protocol.PPCA_LINE)) {
  187. attrLine = Integer.parseInt(attrval);
  188. } else if (attrib.equals(Protocol.PPCA_OFFSET)) {
  189. attrOffset = Integer.parseInt(attrval);
  190. } else if (attrib.equals(Protocol.PPCA_REFN)) {
  191. attrRefn = Integer.parseInt(attrval);
  192. } else if (attrib.equals(Protocol.PPCA_SELECTED)) {
  193. attrSelected = Integer.parseInt(attrval);
  194. } else if (attrib.equals(Protocol.PPCA_TREE_DEPS)) {
  195. attrTreeDeps = unquote(attrval);
  196. } else if (attrib.equals(Protocol.PPCA_TREE_UP)) {
  197. attrTreeUp = Integer.parseInt(attrval);
  198. } else if (attrib.equals(Protocol.PPCA_MTYPE)) {
  199. attrMType = Integer.parseInt(attrval);
  200. } else if (attrib.equals(Protocol.PPCA_TYPE)) {
  201. attrType = unquote(attrval);
  202. } else if (attrib.equals(Protocol.PPCA_BEEP)) {
  203. attrBeep = Integer.parseInt(attrval);
  204. } else if (attrib.equals(Protocol.PPCA_VALUE)) {
  205. attrVal = Integer.parseInt(attrval);
  206. } else if (attrib.equals(Protocol.PPCA_LEVEL)) {
  207. attrLevel = Integer.parseInt(attrval);
  208. } else if (attrib.equals(Protocol.PPCA_NUMBER)) {
  209. attrNumber = Integer.parseInt(attrval);
  210. } else if (attrib.equals(Protocol.PPCA_CONTINUE)) {
  211. attrContinue = Integer.parseInt(attrval);
  212. } else if (attrib.equals(Protocol.PPCA_NO_FOCUS)) {
  213. attrNoFocus = Integer.parseInt(attrval);
  214. } else if (attrib.equals(Protocol.PPCA_SYMBOL)) {
  215. attrSymbol = unquote(attrval);
  216. } else if (s.debug) {
  217. throw new XrefException("unknown XML attribute '" + attrib + "'");
  218. }
  219. i = s.skipBlank(ss, i, len);
  220. }
  221. i++;
  222. return(i);
  223. }
  224. public static int parseXmlTagHandleMessages(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  225. boolean loop = true;
  226. while (loop) {
  227. clearAttributes();
  228. i = parseXmlTag(ss, i, len);
  229. if (false) {
  230. } else if (currentTag.equals(Protocol.PPC_ERROR)) {
  231. i = dispatchError(ss, i, len, data);
  232. } else if (currentTag.equals(Protocol.PPC_FATAL_ERROR)) {
  233. i = dispatchFatalError(ss, i, len, data);
  234. } else if (currentTag.equals(Protocol.PPC_WARNING)) {
  235. i = dispatchWarning(ss, i, len, data);
  236. } else if (currentTag.equals(Protocol.PPC_DEBUG_INFORMATION)) {
  237. i = dispatchDebugMessage(ss, i, len, data);
  238. } else if (currentTag.equals(Protocol.PPC_INFORMATION)) {
  239. i = dispatchMessage(ss, i, len, data);
  240. } else if (currentTag.equals(Protocol.PPC_BOTTOM_INFORMATION)) {
  241. i = dispatchBottomMessage(ss, i, len, data, Protocol.PPC_BOTTOM_INFORMATION);
  242. } else if (currentTag.equals(Protocol.PPC_BOTTOM_WARNING)) {
  243. i = dispatchBottomMessage(ss, i, len, data, Protocol.PPC_BOTTOM_WARNING);
  244. } else if (currentTag.equals(Protocol.PPC_IGNORE)) {
  245. i = dispatchIgnore(ss, i, len, data);
  246. } else if (currentTag.equals(Protocol.PPC_LICENSE_ERROR)) {
  247. i = dispatchLicenseError(ss, i, len, data);
  248. } else {
  249. loop = false;
  250. }
  251. if (loop) {
  252. i = s.skipBlank(ss, i, len);
  253. if (i>=len) loop = false;
  254. }
  255. }
  256. return(i);
  257. }
  258. public static int dispatchError(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  259. String message = ss.substring(i, i+attrLen);
  260. i += attrLen;
  261. i = parseXmlTagHandleMessages(ss, i, len,data);
  262. protocolCheckEq(currentTag, "/"+Protocol.PPC_ERROR);
  263. throw new XrefErrorException(message);
  264. //&return(i);
  265. }
  266. public static int dispatchLicenseError(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  267. String message = ss.substring(i, i+attrLen);
  268. i += attrLen;
  269. i = parseXmlTagHandleMessages(ss, i, len,data);
  270. protocolCheckEq(currentTag, "/"+Protocol.PPC_LICENSE_ERROR);
  271. int answer = JOptionPane.showOptionDialog(s.getProbableParent(data.callerComponent),
  272. message,
  273. "Xrefactory Warning",
  274. JOptionPane.OK_CANCEL_OPTION,
  275. JOptionPane.WARNING_MESSAGE,
  276. null,
  277. new String[]{"Browse Url","Continue"},
  278. "Continue"
  279. );
  280. if (answer == 0) {
  281. s.browseUrl(s.xrefRegistrationUrl, true, s.getParentView(data.callerComponent));
  282. }
  283. return(i);
  284. }
  285. public static int dispatchFatalError(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  286. String message = ss.substring(i, i+attrLen);
  287. i += attrLen;
  288. i = parseXmlTagHandleMessages(ss, i, len,data);
  289. protocolCheckEq(currentTag, "/"+Protocol.PPC_FATAL_ERROR);
  290. throw new XrefErrorException(message);
  291. //&return(i);
  292. }
  293. public static int dispatchWarning(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  294. String message = ss.substring(i, i+attrLen);
  295. i += attrLen;
  296. i = parseXmlTagHandleMessages(ss, i, len,data);
  297. protocolCheckEq(currentTag, "/"+Protocol.PPC_WARNING);
  298. JOptionPane.showMessageDialog(s.getProbableParent(data.callerComponent),
  299. message, "Xrefactory Warning", JOptionPane.WARNING_MESSAGE);
  300. return(i);
  301. }
  302. public static int dispatchMessage(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  303. String message = ss.substring(i, i+attrLen);
  304. i += attrLen;
  305. i = parseXmlTagHandleMessages(ss, i, len,data);
  306. protocolCheckEq(currentTag, "/"+Protocol.PPC_INFORMATION);
  307. JOptionPane.showMessageDialog(s.getProbableParent(data.callerComponent),
  308. message, "Xrefactory Info", JOptionPane.INFORMATION_MESSAGE);
  309. return(i);
  310. }
  311. public static int dispatchDebugMessage(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  312. String message = ss.substring(i, i+attrLen);
  313. i += attrLen;
  314. i = parseXmlTagHandleMessages(ss, i, len,data);
  315. protocolCheckEq(currentTag, "/"+Protocol.PPC_DEBUG_INFORMATION);
  316. if (s.debug) {
  317. JOptionPane.showMessageDialog(s.getProbableParent(data.callerComponent),
  318. message, "Xrefactory Debug Info", JOptionPane.INFORMATION_MESSAGE);
  319. }
  320. return(i);
  321. }
  322. public static int dispatchBottomMessage(XrefCharBuffer ss, int i, int len, DispatchData data, String ctag) throws Exception {
  323. String message = ss.substring(i, i+attrLen);
  324. i += attrLen;
  325. if (attrBeep!=0) s.view.getToolkit().beep();
  326. i = parseXmlTagHandleMessages(ss, i, len,data);
  327. protocolCheckEq(currentTag, "/"+ctag);
  328. //&s.getParentView(data.callerComponent).getStatus().setMessageAndClear(message);
  329. SwingUtilities.invokeLater(new s.MessageDisplayer(message,true));
  330. return(i);
  331. }
  332. public static int dispatchAskConfirmation(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  333. String message = ss.substring(i, i+attrLen);
  334. i += attrLen;
  335. i = parseXmlTagHandleMessages(ss, i, len,data);
  336. protocolCheckEq(currentTag, "/"+Protocol.PPC_ASK_CONFIRMATION);
  337. int confirm = JOptionPane.showConfirmDialog(s.getProbableParent(data.callerComponent),
  338. message, "Confirmation",
  339. JOptionPane.YES_NO_OPTION,
  340. JOptionPane.WARNING_MESSAGE);
  341. if (confirm != JOptionPane.YES_OPTION) throw new XrefAbortException();
  342. return(i);
  343. }
  344. public static int dispatchIgnore(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  345. String message = ss.substring(i, i+attrLen);
  346. i += attrLen;
  347. i = parseXmlTagHandleMessages(ss, i, len,data);
  348. protocolCheckEq(currentTag, "/"+Protocol.PPC_IGNORE);
  349. return(i);
  350. }
  351. // unused to be deleted
  352. public static int dispatchFileSaveAs(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  353. String fname = ss.substring(i, i+attrLen);
  354. i += attrLen;
  355. i = parseXmlTagHandleMessages(ss, i, len,data);
  356. protocolCheckEq(currentTag, "/"+Protocol.PPC_FILE_SAVE_AS);
  357. s.getBuffer().save(s.view, fname, true);
  358. try {Thread.currentThread().sleep(35);} catch (InterruptedException e){}
  359. VFSManager.waitForRequests();
  360. return(i);
  361. }
  362. // unused to be deleted
  363. public static int dispatchMoveDirectory(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  364. i = parseXmlTagHandleMessages(ss, i, len,data);
  365. protocolCheckEq(currentTag, Protocol.PPC_STRING_VALUE);
  366. String oldname = ss.substring(i, i+attrLen);
  367. i += attrLen;
  368. i = parseXmlTagHandleMessages(ss, i, len,data);
  369. protocolCheckEq(currentTag, "/"+Protocol.PPC_STRING_VALUE);
  370. i = parseXmlTagHandleMessages(ss, i, len,data);
  371. protocolCheckEq(currentTag, Protocol.PPC_STRING_VALUE);
  372. String newname = ss.substring(i, i+attrLen);
  373. i += attrLen;
  374. i = parseXmlTagHandleMessages(ss, i, len,data);
  375. protocolCheckEq(currentTag, "/"+Protocol.PPC_STRING_VALUE);
  376. i = parseXmlTagHandleMessages(ss, i, len,data);
  377. protocolCheckEq(currentTag, "/"+Protocol.PPC_MOVE_DIRECTORY);
  378. int confirm = JOptionPane.showConfirmDialog(
  379. s.getProbableParent(data.callerComponent),
  380. "\tCan I move directory\n"+oldname+"\n\tto\n"+newname,
  381. "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
  382. if (confirm == JOptionPane.YES_OPTION) {
  383. File ff = new File(oldname);
  384. ff.renameTo(new File(newname));
  385. }
  386. return(i);
  387. }
  388. public static int dispatchMoveFileAs(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  389. String fname = ss.substring(i, i+attrLen);
  390. i += attrLen;
  391. i = parseXmlTagHandleMessages(ss, i, len,data);
  392. protocolCheckEq(currentTag, "/"+Protocol.PPC_MOVE_FILE_AS);
  393. File ff = new File(fname);
  394. ff.getParentFile().mkdirs();
  395. File oldfile = new File(s.getBuffer().getPath());
  396. oldfile.delete();
  397. if (s.getBuffer().save(s.view, fname, true)) {
  398. // sleeping is a hack fixing jEdit dead-lock problem
  399. try {Thread.currentThread().sleep(35);} catch (InterruptedException e){}
  400. VFSManager.waitForRequests();
  401. Buffer oldb = jEdit.getBuffer(oldfile.getAbsolutePath());
  402. if (oldb!=null && oldb!=s.getBuffer()) {
  403. jEdit.closeBuffer(s.view, oldb);
  404. }
  405. try {Thread.currentThread().sleep(15);} catch (InterruptedException e){}
  406. VFSManager.waitForRequests();
  407. } else {
  408. throw new XrefException("can not move the file");
  409. }
  410. return(i);
  411. }
  412. public static int dispatchGoto(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  413. i = parseXmlTagHandleMessages(ss, i, len,data);
  414. if (currentTag.equals(Protocol.PPC_OFFSET_POSITION)) {
  415. String path = ss.substring(i, i+attrLen);
  416. int offset = attrOffset;
  417. i += attrLen;
  418. i = parseXmlTagHandleMessages(ss, i, len,data);
  419. protocolCheckEq(currentTag, "/"+Protocol.PPC_OFFSET_POSITION);
  420. s.moveToPosition(s.getParentView(data.callerComponent), path, offset);
  421. } else {
  422. protocolCheckEq(currentTag, Protocol.PPC_LC_POSITION);
  423. String path = ss.substring(i, i+attrLen);
  424. int line = attrLine;
  425. int col = attrCol;
  426. i += attrLen;
  427. i = parseXmlTagHandleMessages(ss, i, len,data);
  428. protocolCheckEq(currentTag, "/"+Protocol.PPC_LC_POSITION);
  429. s.moveToPosition(s.getParentView(data.callerComponent), path, line, col);
  430. }
  431. i = parseXmlTagHandleMessages(ss, i, len,data);
  432. protocolCheckEq(currentTag, "/"+Protocol.PPC_GOTO);
  433. return(i);
  434. }
  435. public static int dispatchPreCheck(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  436. String str = ss.substring(i, i+attrLen);
  437. i += attrLen;
  438. i = parseXmlTagHandleMessages(ss, i, len,data);
  439. protocolCheckEq(currentTag, "/"+Protocol.PPC_REFACTORING_PRECHECK);
  440. editorPreCheck(str);
  441. return(i);
  442. }
  443. public static int dispatchString(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  444. i = parseXmlTagHandleMessages(ss, i, len,data);
  445. protocolCheckEq(currentTag, Protocol.PPC_STRING_VALUE);
  446. stringVal = ss.substring(i, i+attrLen);
  447. i += attrLen;
  448. i = parseXmlTagHandleMessages(ss, i, len,data);
  449. protocolCheckEq(currentTag, "/"+Protocol.PPC_STRING_VALUE);
  450. return(i);
  451. }
  452. public static int dispatchReplacement(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  453. i = dispatchString(ss, i, len, data);
  454. String str = stringVal;
  455. i = dispatchString(ss, i, len, data);
  456. String with = stringVal;
  457. i = parseXmlTagHandleMessages(ss, i, len,data);
  458. protocolCheckEq(currentTag, "/"+Protocol.PPC_REFACTORING_REPLACEMENT);
  459. editorReplace(str, with);
  460. return(i);
  461. }
  462. public static int dispatchDisplayResolution(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  463. String message = ss.substring(i, i+attrLen);
  464. boolean cont = attrContinue!=0;
  465. i += attrLen;
  466. i = parseXmlTagHandleMessages(ss, i, len,data);
  467. protocolCheckEq(currentTag, "/"+Protocol.PPC_DISPLAY_RESOLUTION);
  468. // Frame did not work, as it looses pointer to s.view
  469. //&if (cont) {
  470. new ResolutionDialog(message, attrMType, data, cont);
  471. //&} else {
  472. //&new ResolutionFrame(message, attrMType, data, cont);
  473. //&throw new XrefAbortException();
  474. //&}
  475. return(i);
  476. }
  477. public static int dispatchDisplayOrUpdateBrowser(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  478. String message = ss.substring(i, i+attrLen);
  479. i += attrLen;
  480. i = parseXmlTagHandleMessages(ss, i, len,data);
  481. protocolCheckEq(currentTag, "/"+Protocol.PPC_DISPLAY_OR_UPDATE_BROWSER);
  482. s.showAndUpdateBrowser(s.getParentView(data.callerComponent));
  483. return(i);
  484. }
  485. /*& // old way of displaying class tree
  486. public static int dispatchDisplayClassTree(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  487. XrefCharBuffer tree = new XrefCharBuffer();
  488. int minLine = 1000000;
  489. int cline = -1;
  490. String prefix;
  491. int callerLine = 0;
  492. clearAttributes();
  493. i = parseXmlTagHandleMessages(ss, i, len,data);
  494. while (currentTag.equals(Protocol.PPC_CLASS)) {
  495. String ctclass = ss.substring(i, i+attrLen);
  496. i += attrLen;
  497. cline ++;
  498. if (cline != 0) tree.append("\n");
  499. if (attrBase==1) {
  500. prefix = ">>";
  501. if (callerLine==0) callerLine = cline;
  502. } else {
  503. prefix = " ";
  504. }
  505. if (attrTreeUp==1) {
  506. tree.append(prefix + attrTreeDeps + "(" + ctclass + ") ");
  507. } else {
  508. tree.append(prefix + attrTreeDeps + ctclass + " ");
  509. }
  510. if (minLine>attrLine) minLine = attrLine;
  511. i = parseXmlTagHandleMessages(ss, i, len,data);
  512. protocolCheckEq(currentTag, "/"+Protocol.PPC_CLASS);
  513. clearAttributes();
  514. i = parseXmlTagHandleMessages(ss, i, len,data);
  515. }
  516. protocolCheckEq(currentTag, "/"+Protocol.PPC_DISPLAY_CLASS_TREE);
  517. new DockableClassTree(s.getParentFrame(data.callerComponent), tree.toString(), data, minLine, callerLine);
  518. return(i);
  519. }
  520. &*/
  521. public static int dispatchDisplayClassTree(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  522. XrefTreeNode [] tt = new XrefTreeNode[s.XREF_MAX_TREE_DEEP];
  523. tt[0] = new XrefTreeNode("root", null, 0,0,0, false,false,false,false,false,false);
  524. i = dispatchParseOneSymbolClassHierarchy(ss, i, len, data, tt, "");
  525. protocolCheckEq(currentTag, "/"+Protocol.PPC_DISPLAY_CLASS_TREE);
  526. s.view.getDockableWindowManager().showDockableWindow(s.dockableClassTreeWindowName);
  527. DockableClassTree ctViewer = s.getClassTreeViewer(s.view);
  528. ctViewer.setTree(tt[0]);
  529. return(i);
  530. }
  531. static int dispatchParseOneSymbolClassHierarchy(XrefCharBuffer ss, int i, int len, DispatchData data, XrefTreeNode [] tt, String symbol) throws Exception {
  532. tt[1] = new XrefTreeNode(symbol, tt[0], 0,0,0, false,false,false,true,false,false);
  533. clearAttributes();
  534. i = parseXmlTagHandleMessages(ss, i, len,data);
  535. while (currentTag.equals(Protocol.PPC_CLASS)) {
  536. String ctclass = ss.substring(i, i+attrLen);
  537. i += attrLen;
  538. int deep = attrIndent+2;
  539. s.assertt(deep < s.XREF_MAX_TREE_DEEP);
  540. tt[deep] = new XrefTreeNode(ctclass, tt[deep-1],
  541. attrLine, attrRefn, attrDRefn,
  542. attrBase==1,attrSelected==1,attrInterface==1,
  543. false,attrDefinition==1, false);
  544. i = parseXmlTagHandleMessages(ss, i, len,data);
  545. protocolCheckEq(currentTag, "/"+Protocol.PPC_CLASS);
  546. clearAttributes();
  547. i = parseXmlTagHandleMessages(ss, i, len,data);
  548. }
  549. return(i);
  550. }
  551. static int dispatchParseTreeDescription(XrefCharBuffer ss, int i, int len, DispatchData data, XrefTreeNode [] tt) throws Exception {
  552. tt[0] = new XrefTreeNode("root", null, 0,0,0, false,false,false,false,false,false);
  553. XrefTreeNode nonVirtuals = new XrefTreeNode(s.XREF_NON_MEMBER_SYMBOL_NAME, tt[0],
  554. 0, 0, 0, false,false,false,true,false,false);
  555. i = parseXmlTagHandleMessages(ss, i, len,data);
  556. while (currentTag.equals(Protocol.PPC_VIRTUAL_SYMBOL)
  557. || currentTag.equals(Protocol.PPC_SYMBOL)) {
  558. String symbol = ss.substring(i, i+attrLen);
  559. i += attrLen;
  560. if (currentTag.equals(Protocol.PPC_SYMBOL)) {
  561. new XrefTreeNode(symbol, nonVirtuals,
  562. attrLine, attrRefn, attrDRefn,
  563. attrBase==1,attrSelected==1,attrInterface==1,
  564. false,attrDefinition==1, false);
  565. i = parseXmlTagHandleMessages(ss, i, len,data);
  566. protocolCheckEq(currentTag, "/"+Protocol.PPC_SYMBOL);
  567. clearAttributes();
  568. i = parseXmlTagHandleMessages(ss, i, len,data);
  569. } else {
  570. i = parseXmlTagHandleMessages(ss, i, len,data);
  571. protocolCheckEq(currentTag, "/"+Protocol.PPC_VIRTUAL_SYMBOL);
  572. i = dispatchParseOneSymbolClassHierarchy(ss, i, len, data, tt, symbol);
  573. }
  574. }
  575. if (nonVirtuals.subNodes.size()==0) tt[0].removeSubNode(nonVirtuals);
  576. return(i);
  577. }
  578. public static int dispatchSymbolResolution(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  579. XrefTreeNode [] tt = new XrefTreeNode[s.XREF_MAX_TREE_DEEP];
  580. i = dispatchParseTreeDescription(ss, i, len, data, tt);
  581. protocolCheckEq(currentTag, "/"+Protocol.PPC_SYMBOL_RESOLUTION);
  582. BrowserTopPanel bpanel = s.getParentBrowserTopPanel(data.callerComponent);
  583. s.assertt(bpanel!=null);
  584. bpanel.treePanel.xtree.setTree(tt[0]);
  585. return(i);
  586. }
  587. public static int dispatchReferenceList(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  588. boolean firstFlag = true;
  589. XrefCharBuffer refs = new XrefCharBuffer();
  590. int crefn = attrVal;
  591. i = parseXmlTagHandleMessages(ss, i, len,data);
  592. while (currentTag.equals(Protocol.PPC_SRC_LINE)) {
  593. if (! firstFlag) refs.append("\n");
  594. firstFlag = false;
  595. for(int j=0; j<attrRefn; j++) {
  596. if (j!=0) refs.append("\n");
  597. refs.append(ss, i, attrLen);
  598. }
  599. i += attrLen;
  600. i = parseXmlTagHandleMessages(ss, i, len,data);
  601. protocolCheckEq(currentTag, "/"+Protocol.PPC_SRC_LINE);
  602. i = parseXmlTagHandleMessages(ss, i, len,data);
  603. }
  604. protocolCheckEq(currentTag, "/"+Protocol.PPC_REFERENCE_LIST);
  605. BrowserTopPanel bpanel = s.getParentBrowserTopPanel(data.callerComponent);
  606. s.assertt(bpanel!=null);
  607. bpanel.referencesPanel.reflist.setRefs(refs.toString(), crefn);
  608. return(i);
  609. }
  610. public static int dispatchUpdateCurrentReference(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  611. int val = attrVal;
  612. i += attrLen;
  613. i = parseXmlTagHandleMessages(ss, i, len,data);
  614. protocolCheckEq(currentTag, "/"+Protocol.PPC_UPDATE_CURRENT_REFERENCE);
  615. BrowserTopPanel bpanel = s.getParentBrowserTopPanel(data.callerComponent);
  616. s.assertt(bpanel!=null);
  617. bpanel.referencesPanel.reflist.setCurrentRef(val);
  618. return(i);
  619. }
  620. public static int dispatchProgress(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  621. // TDODO!!!
  622. //&ProgressMonitor progress = new ProgressMonitor(s.getProbableParent(data.callerComponent), "Updating references", null, 0, 100);
  623. i = parseXmlTagHandleMessages(ss, i, len,data);
  624. protocolCheckEq(currentTag, "/"+Protocol.PPC_PROGRESS);
  625. //&progress.close();
  626. return(i);
  627. }
  628. public static int dispatchUpdateReport(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  629. // O.K. skip everything until end of report
  630. // TODO, do this seriously, counting eventual nestings
  631. i += attrLen;
  632. clearAttributes();
  633. i = parseXmlTag(ss, i, len);
  634. while (i<len && ! currentTag.equals("/"+Protocol.PPC_UPDATE_REPORT)) {
  635. i += attrLen;
  636. clearAttributes();
  637. i = parseXmlTag(ss, i, len);
  638. // make an exception and report fatal error, as task is exited now
  639. if (currentTag.equals(Protocol.PPC_FATAL_ERROR)) {
  640. i = dispatchFatalError(ss, i, len, data);
  641. }
  642. }
  643. protocolCheckEq(currentTag, "/"+Protocol.PPC_UPDATE_REPORT);
  644. return(i);
  645. }
  646. public static int dispatchVersionMismatch(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  647. String taskVersion = ss.substring(i, i+attrLen);
  648. i += attrLen;
  649. i = parseXmlTag(ss, i, len);
  650. protocolCheckEq(currentTag, "/"+Protocol.PPC_VERSION_MISMATCH);
  651. s.checkVersionCorrespondance(taskVersion, data);
  652. return(i);
  653. }
  654. public static int dispatchBrowseUrl(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  655. String message = ss.substring(i, i+attrLen);
  656. i += attrLen;
  657. i = parseXmlTagHandleMessages(ss, i, len,data);
  658. protocolCheckEq(currentTag, "/"+Protocol.PPC_BROWSE_URL);
  659. browseUrlIfConfirmed(message, data);
  660. //&new HelpViewer(message);
  661. return(i);
  662. }
  663. public static int dispatchSingleCompletion(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  664. String completion = ss.substring(i, i+attrLen);
  665. i += attrLen;
  666. i = parseXmlTagHandleMessages(ss, i, len,data);
  667. protocolCheckEq(currentTag, "/"+Protocol.PPC_SINGLE_COMPLETION);
  668. int caret = s.getCaretPosition();
  669. s.insertCompletion(s.getBuffer(), caret, completion);
  670. return(i);
  671. }
  672. public static int dispatchFqtCompletion(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  673. String completion = ss.substring(i, i+attrLen);
  674. i += attrLen;
  675. i = parseXmlTagHandleMessages(ss, i, len,data);
  676. protocolCheckEq(currentTag, "/"+Protocol.PPC_FQT_COMPLETION);
  677. int caret = s.getCaretPosition();
  678. CompletionDialog.insertFqtCompletion(s.getBuffer(), caret, completion);
  679. return(i);
  680. }
  681. public static int dispatchCompletionList(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  682. boolean firstFlag = true;
  683. XrefCharBuffer completions = new XrefCharBuffer();
  684. i = parseXmlTagHandleMessages(ss, i, len,data);
  685. while (currentTag.equals(Protocol.PPC_MULTIPLE_COMPLETION_LINE)) {
  686. if (! firstFlag) completions.append("\n");
  687. firstFlag = false;
  688. completions.append(ss, i, attrLen);
  689. i += attrLen;
  690. i = parseXmlTagHandleMessages(ss, i, len,data);
  691. protocolCheckEq(currentTag, "/"+Protocol.PPC_MULTIPLE_COMPLETION_LINE);
  692. i = parseXmlTagHandleMessages(ss, i, len,data);
  693. }
  694. protocolCheckEq(currentTag, "/"+Protocol.PPC_MULTIPLE_COMPLETIONS);
  695. CompletionDialog.showCompletionDialog(completions.toString(), data, attrNoFocus);
  696. return(i);
  697. }
  698. public static int dispatchFullCompletionList(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  699. int ci, max;
  700. ci = 0;
  701. max = attrNumber;
  702. CompletionDialog3 cd = CompletionDialog3.initCompletionDialog(data, max, attrNoFocus);
  703. i = parseXmlTagHandleMessages(ss, i, len,data);
  704. while (currentTag.equals(Protocol.PPC_MULTIPLE_COMPLETION_LINE)) {
  705. s.assertt(ci < max);
  706. cd.lns[ci] = new CompletionDialog3.LineData(cd.completions.bufi,
  707. cd.completions.bufi + attrVal,
  708. attrVClass);
  709. cd.completions.append(ss, i, attrLen);
  710. ci ++;
  711. i += attrLen;
  712. i = parseXmlTagHandleMessages(ss, i, len,data);
  713. protocolCheckEq(currentTag, "/"+Protocol.PPC_MULTIPLE_COMPLETION_LINE);
  714. i = parseXmlTagHandleMessages(ss, i, len,data);
  715. }
  716. cd.lns[ci] = new CompletionDialog3.LineData(cd.completions.bufi, -1, "");
  717. protocolCheckEq(currentTag, "/"+Protocol.PPC_FULL_MULTIPLE_COMPLETIONS);
  718. CompletionDialog3.showCompletionDialog();
  719. return(i);
  720. }
  721. public static int dispatchAllCompletionsList(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  722. XrefCharBuffer completions = new XrefCharBuffer();
  723. completions.append(ss, i, attrLen);
  724. i += attrLen;
  725. i = parseXmlTagHandleMessages(ss, i, len,data);
  726. protocolCheckEq(currentTag, "/"+Protocol.PPC_ALL_COMPLETIONS);
  727. CompletionDialog.showCompletionDialog(completions.toString(), data, attrNoFocus);
  728. return(i);
  729. }
  730. public static int dispatchSymbolList(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  731. XrefCharBuffer symbols = new XrefCharBuffer();
  732. i = parseXmlTagHandleMessages(ss, i, len,data);
  733. while (currentTag.equals(Protocol.PPC_STRING_VALUE)) {
  734. symbols.append(ss, i, attrLen);
  735. symbols.append("\n");
  736. i += attrLen;
  737. i = parseXmlTagHandleMessages(ss, i, len,data);
  738. protocolCheckEq(currentTag, "/"+Protocol.PPC_STRING_VALUE);
  739. i = parseXmlTagHandleMessages(ss, i, len,data);
  740. }
  741. protocolCheckEq(currentTag, "/"+Protocol.PPC_SYMBOL_LIST);
  742. data.symbolList = symbols;
  743. return(i);
  744. }
  745. /* TODO, delete this method, it is useless since 1.6.0 */
  746. public static int dispatchSetProject(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  747. data.info = ss.substring( i, i+attrLen);
  748. i += attrLen;
  749. i = parseXmlTagHandleMessages(ss, i, len,data);
  750. protocolCheckEq(currentTag, "/"+Protocol.PPC_SET_PROJECT);
  751. return(i);
  752. }
  753. public static int dispatchSetInfo(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  754. data.info = ss.substring( i, i+attrLen);
  755. i += attrLen;
  756. i = parseXmlTagHandleMessages(ss, i, len,data);
  757. protocolCheckEq(currentTag, "/"+Protocol.PPC_SET_INFO);
  758. return(i);
  759. }
  760. public static int dispatchNoProject(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  761. int rr;
  762. String file = ss.substring( i, i+attrLen);
  763. i += attrLen;
  764. i = parseXmlTagHandleMessages(ss, i, len,data);
  765. if (data.projectCreationAllowed) {
  766. protocolCheckEq(currentTag, "/"+Protocol.PPC_NO_PROJECT);
  767. rr = JOptionPane.showConfirmDialog(s.getProbableParent(data.callerComponent),
  768. "No project for file "+file+".\nCreate new project?" , "No Project", JOptionPane.YES_NO_OPTION);
  769. if (rr==JOptionPane.YES_OPTION) {
  770. OptionsForProjectsDialog od = new OptionsForProjectsDialog(s.view, true);
  771. }
  772. }
  773. throw new XrefAbortException();
  774. }
  775. public static int dispatchNoSymbol(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  776. // handle no symbol by pushing symbol by name
  777. String name = s.getIdentifierOnCaret();
  778. i += attrLen;
  779. i = parseXmlTagHandleMessages(ss, i, len,data);
  780. protocolCheckEq(currentTag, "/"+Protocol.PPC_NO_SYMBOL);
  781. new Push(new String[] {"-olcxpushname="+name, "-olnodialog"}, data);
  782. return(i);
  783. }
  784. public static int dispatchAvailableRefactorings(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  785. boolean firstFlag = true;
  786. Refactorings refactors[] = new Refactorings[Protocol.PPC_MAX_AVAILABLE_REFACTORINGS];
  787. int refactoringsi = 0;
  788. i = parseXmlTagHandleMessages(ss, i, len,data);
  789. while (currentTag.equals(Protocol.PPC_INT_VALUE)) {
  790. Refactorings rrr = Refactorings.getRefactoringFromCode(attrVal);
  791. if (rrr!=null) {
  792. s.assertt(refactoringsi < Protocol.PPC_MAX_AVAILABLE_REFACTORINGS);
  793. refactors[refactoringsi] = rrr;
  794. refactors[refactoringsi].param = ss.substring(i, i+attrLen);
  795. refactoringsi++;
  796. }
  797. i += attrLen;
  798. i = parseXmlTagHandleMessages(ss, i, len,data);
  799. protocolCheckEq(currentTag, "/"+Protocol.PPC_INT_VALUE);
  800. i = parseXmlTagHandleMessages(ss, i, len,data);
  801. }
  802. protocolCheckEq(currentTag, "/"+Protocol.PPC_AVAILABLE_REFACTORINGS);
  803. Refactorings[] refactorings = new Refactorings[refactoringsi];
  804. System.arraycopy(refactors, 0, refactorings, 0, refactoringsi);
  805. new RefactoringDialog(refactorings);
  806. return(i);
  807. }
  808. public static int dispatchCopyBlock(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  809. int cc = s.getCaretPosition();
  810. block = s.getBuffer().getText(cc, cc+attrVal);
  811. i = parseXmlTagHandleMessages(ss, i, len,data);
  812. protocolCheckEq(currentTag, "/"+Protocol.PPC_REFACTORING_COPY_BLOCK);
  813. return(i);
  814. }
  815. public static int dispatchCutBlock(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  816. Buffer buffer = s.getBuffer();
  817. int blen = buffer.getLength();
  818. int caret = s.getCaretPosition();
  819. // O.K. next line is to handle special case of final newline
  820. // automatically added by jEdit to saved files
  821. if (caret+attrVal == blen+1) buffer.insert(blen, "\n");
  822. block = buffer.getText(caret, attrVal);
  823. buffer.remove(caret, attrVal);
  824. i = parseXmlTagHandleMessages(ss, i, len,data);
  825. protocolCheckEq(currentTag, "/"+Protocol.PPC_REFACTORING_CUT_BLOCK);
  826. return(i);
  827. }
  828. public static int dispatchPasteBlock(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  829. Buffer buffer = s.getBuffer();
  830. int caret = s.getCaretPosition();
  831. buffer.insert(caret, block);
  832. // do indentation somewhere later to not perturb refactorings offsets
  833. //&int blocklines = s.getNumberOfCharOccurences(block,'\n');
  834. //&int line = buffer.getLineOfOffset(caret);
  835. //&buffer.indentLines(buffer.getLineOfOffset(caret), line+blocklines);
  836. i = parseXmlTagHandleMessages(ss, i, len,data);
  837. protocolCheckEq(currentTag, "/"+Protocol.PPC_REFACTORING_PASTE_BLOCK);
  838. return(i);
  839. }
  840. public static int dispatchKillBufferRemoveFile(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  841. String message = ss.substring( i, i+attrLen);
  842. i += attrLen;
  843. int confirm = JOptionPane.YES_OPTION;
  844. confirm = JOptionPane.showConfirmDialog(
  845. s.view,
  846. message,
  847. "Confirmation",
  848. JOptionPane.YES_NO_OPTION,
  849. JOptionPane.QUESTION_MESSAGE);
  850. if (confirm == JOptionPane.YES_OPTION) {
  851. Buffer buf = s.getBuffer();
  852. buf.save(s.view, null);
  853. (new File(buf.getPath())).delete();
  854. jEdit.closeBuffer(s.view, buf);
  855. }
  856. i = parseXmlTagHandleMessages(ss, i, len,data);
  857. protocolCheckEq(currentTag, "/"+Protocol.PPC_KILL_BUFFER_REMOVE_FILE);
  858. return(i);
  859. }
  860. public static int dispatchIndent(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  861. Buffer buffer = s.getBuffer();
  862. int caret = s.getCaretPosition();
  863. int line = buffer.getLineOfOffset(caret);
  864. buffer.indentLines(line, line+attrVal-1);
  865. i = parseXmlTagHandleMessages(ss, i, len,data);
  866. protocolCheckEq(currentTag, "/"+Protocol.PPC_INDENT);
  867. return(i);
  868. }
  869. public static int dispatchExtractDialog(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  870. i += attrLen;
  871. i = parseXmlTagHandleMessages(ss, i, len,data);
  872. protocolCheckEq(currentTag, Protocol.PPC_STRING_VALUE);
  873. String invocation = ss.substring( i, i+attrLen);
  874. i += attrLen;
  875. i = parseXmlTag(ss, i, len);
  876. protocolCheckEq(currentTag, "/"+Protocol.PPC_STRING_VALUE);
  877. i = parseXmlTagHandleMessages(ss, i, len,data);
  878. protocolCheckEq(currentTag, Protocol.PPC_STRING_VALUE);
  879. String theHead = ss.substring( i, i+attrLen);
  880. i += attrLen;
  881. i = parseXmlTag(ss, i, len);
  882. protocolCheckEq(currentTag, "/"+Protocol.PPC_STRING_VALUE);
  883. i = parseXmlTagHandleMessages(ss, i, len,data);
  884. protocolCheckEq(currentTag, Protocol.PPC_STRING_VALUE);
  885. String theTail = ss.substring( i, i+attrLen);
  886. i += attrLen;
  887. i = parseXmlTag(ss, i, len);
  888. protocolCheckEq(currentTag, "/"+Protocol.PPC_STRING_VALUE);
  889. i = parseXmlTagHandleMessages(ss, i, len,data);
  890. protocolCheckEq(currentTag, Protocol.PPC_INT_VALUE);
  891. int targetLine = attrVal;
  892. i += attrLen;
  893. i = parseXmlTag(ss, i, len);
  894. protocolCheckEq(currentTag, "/"+Protocol.PPC_INT_VALUE);
  895. i = parseXmlTagHandleMessages(ss, i, len,data);
  896. protocolCheckEq(currentTag, "/"+Protocol.PPC_EXTRACTION_DIALOG);
  897. new ExtractMethodDialog(invocation, theHead, theTail, targetLine);
  898. return(i);
  899. }
  900. public static int dispatchRecordAt(XrefCharBuffer ss, int i, int len, DispatchData data) throws Exception {
  901. int j;
  902. String unenclosed;
  903. i = s.skipBlank(ss, i, len);
  904. for(j=i; ss.buf[i] != '<' && i<len; i++) ;
  905. if (i!=j && s.debug) {
  906. unenclosed = ss.substring(j, i);
  907. JOptionPane.showMessageDialog(s.view, "Unenclosed string\n" + unenclosed,
  908. "Xrefactory Error", JOptionPane.ERROR_MESSAGE);
  909. }
  910. if (j>=len) throw new XrefException("unexpected end of communication");
  911. clearAttributes();
  912. i = parseXmlTagHandleMessages(ss, i, len,data);
  913. if (i>=len || data.panic) {
  914. // no action in such cases
  915. } else if (currentTag.equals(Protocol.PPC_SINGLE_COMPLETION)) {
  916. i = dispatchSingleCompletion(ss, i, len, data);
  917. } else if (currentTag.equals(Protocol.PPC_FQT_COMPLETION)) {
  918. i = dispatchFqtCompletion(ss, i, len, data);
  919. } else if (currentTag.equals(Protocol.PPC_MULTIPLE_COMPLETIONS)) {
  920. i = dispatchCompletionList(ss, i, len, data);
  921. } else if (currentTag.equals(Protocol.PPC_FULL_MULTIPLE_COMPLETIONS)) {
  922. i = dispatchFullCompletionList(ss, i, len, data);
  923. } else if (currentTag.equals(Protocol.PPC_ALL_COMPLETIONS)) {
  924. i = dispatchAllCompletionsList(ss, i, len, data);
  925. } else if (currentTag.equals(Protocol.PPC_SYMBOL_LIST)) {
  926. i = dispatchSymbolList(ss, i, len, data);
  927. } else if (currentTag.equals(Protocol.PPC_SET_PROJECT)) {
  928. i = dispatchSetProject(ss, i, len, data);
  929. } else if (currentTag.equals(Protocol.PPC_SET_INFO)) {
  930. i = dispatchSetInfo(ss, i, len, data);
  931. } else if (currentTag.equals(Protocol.PPC_NO_PROJECT)) {
  932. i = dispatchNoProject(ss, i, len, data);
  933. } else if (currentTag.equals(Protocol.PPC_NO_SYMBOL)) {
  934. i = dispatchNoSymbol(ss, i, len, data);
  935. } else if (currentTag.equals(Protocol.PPC_UPDATE_CURRENT_REFERENCE)) {
  936. i = dispatchUpdateCurrentReference(ss, i, len, data);
  937. } else if (currentTag.equals(Protocol.PPC_BROWSE_URL)) {
  938. i = dispatchBrowseUrl(ss, i, len, data);
  939. } else if (currentTag.equals(Protocol.PPC_GOTO)) {
  940. i = dispatchGoto(ss, i, len, data);
  941. } else if (currentTag.equals(Protocol.PPC_REFACTORING_PRECHECK)) {
  942. i = dispatchPreCheck(ss, i, len, data);
  943. } else if (currentTag.equals(Protocol.PPC_REFACTORING_REPLACEMENT)) {
  944. i = dispatchReplacement(ss, i, len, data);
  945. } else if (currentTag.equals(Protocol.PPC_DISPLAY_OR_UPDATE_BROWSER)) {
  946. i = dispatchDisplayOrUpdateBrowser(ss, i, len, data);
  947. } else if (currentTag.equals(Protocol.PPC_DISPLAY_CLASS_TREE)) {
  948. i = dispatchDisplayClassTree(ss, i, len, data);
  949. } else if (currentTag.equals(Protocol.PPC_DISPLAY_RESOLUTION)) {
  950. i = dispatchDisplayResolution(ss, i, len, data);
  951. } else if (currentTag.equals(Protocol.PPC_SYMBOL_RESOLUTION)) {
  952. i = dispatchSymbolResolution(ss, i, len, data);
  953. } else if (currentTag.equals(Protocol.PPC_REFERENCE_LIST)) {
  954. i = dispatchReferenceList(ss, i, len, data);
  955. } else if (currentTag.equals(Protocol.PPC_ASK_CONFIRMATION)) {
  956. i = dispatchAskConfirmation(ss, i, len, data);
  957. } else if (currentTag.equals(Protocol.PPC_FILE_SAVE_AS)) {
  958. i = dispatchFileSaveAs(ss, i, len, data);
  959. } else if (currentTag.equals(Protocol.PPC_MOVE_FILE_AS)) {
  960. i = dispatchMoveFileAs(ss, i, len, data);
  961. } else if (currentTag.equals(Protocol.PPC_MOVE_DIRECTORY)) {
  962. i = dispatchMoveDirectory(ss, i, len, data);
  963. } else if (currentTag.equals(Protocol.PPC_AVAILABLE_REFACTORINGS)) {
  964. i = dispatchAvailableRefactorings(ss, i, len, data);
  965. } else if (currentTag.equals(Protocol.PPC_REFACTORING_COPY_BLOCK)) {
  966. i = dispatchCopyBlock(ss, i, len, data);
  967. } else if (currentTag.equals(Protocol.PPC_REFACTORING_CUT_BLOCK)) {
  968. i = dispatchCutBlock(ss, i, len, data);
  969. } else if (currentTag.equals(Protocol.PPC_REFACTORING_PASTE_BLOCK)) {
  970. i = dispatchPasteBlock(ss, i, len, data);
  971. } else if (currentTag.equals(Protocol.PPC_KILL_BUFFER_REMOVE_FILE)) {
  972. i = dispatchKillBufferRemoveFile(ss, i, len, data);
  973. } else if (currentTag.equals(Protocol.PPC_INDENT)) {
  974. i = dispatchIndent(ss, i, len, data);
  975. } else if (currentTag.equals(Protocol.PPC_EXTRACTION_DIALOG)) {
  976. i = dispatchExtractDialog(ss, i, len, data);
  977. } else if (currentTag.equals(Protocol.PPC_UPDATE_REPORT)) {
  978. i = dispatchUpdateReport(ss, i, len, data);
  979. } else if (currentTag.equals(Protocol.PPC_VERSION_MISMATCH)) {
  980. i = dispatchVersionMismatch(ss, i, len, data);
  981. } else if (currentTag.equals(Protocol.PPC_PROGRESS)) {
  982. i = dispatchProgress(ss, i, len, data);
  983. } else if (currentTag.equals(Protocol.PPC_SYNCHRO_RECORD)) {
  984. // this is usualy a problem, but ignore it for debuging
  985. } else {
  986. throw new XrefException("unknown XML Tag " + currentTag);
  987. }
  988. return(i);
  989. }
  990. public static void dispatch(XrefCharBuffer ss, DispatchData data) {
  991. //&JOptionPane.showMessageDialog(s.getProbableParent(data.callerComponent), ss, "Got", JOptionPane.INFORMATION_MESSAGE);
  992. if (s.debug) System.err.println("Dispatching: " + ss);
  993. int i = 0;
  994. int len = ss.length();
  995. try {
  996. i = s.skipBlank(ss, i, len);
  997. while (i<len && ! data.panic) {
  998. i = dispatchRecordAt(ss, i, len, data);
  999. i = s.skipBlank(ss, i, len);
  1000. }
  1001. } catch (XrefAbortException e) {
  1002. data.panic = true;
  1003. } catch (XrefErrorException e) {
  1004. if (s.debug) e.printStackTrace(System.err);
  1005. JOptionPane.showMessageDialog(s.getProbableParent(data.callerComponent),
  1006. e, "Xrefactory Error", JOptionPane.ERROR_MESSAGE);
  1007. data.panic = true;
  1008. } catch (Exception e) {
  1009. JOptionPane.showMessageDialog(s.getProbableParent(data.callerComponent),
  1010. e, "Xrefactory Internal Error", JOptionPane.ERROR_MESSAGE);
  1011. e.printStackTrace();
  1012. data.panic = true;
  1013. }
  1014. }
  1015. public static String reportToHtml(XrefCharBuffer ss) {
  1016. XrefCharBuffer res = new XrefCharBuffer();
  1017. int i, len;
  1018. i = 0;
  1019. len = ss.length();
  1020. res.append("<html><pre>\n");
  1021. try {
  1022. while (i<len) {
  1023. clearAttributes();
  1024. i = parseXmlTag(ss, i, len);
  1025. if (currentTag.equals(Protocol.PPC_ERROR)
  1026. || currentTag.equals(Protocol.PPC_FATAL_ERROR)
  1027. || currentTag.equals(Protocol.PPC_WARNING)
  1028. ) {
  1029. res.append("<font color=red>");
  1030. int j = attrLen;
  1031. while (j>0 && Character.isWhitespace(ss.buf[i+j-1])) j--;
  1032. res.append(ss.substring(i, i+j));
  1033. res.append("</font>\n");
  1034. i += attrLen;
  1035. i = parseXmlTag(ss, i, len);
  1036. } else if (currentTag.equals(Protocol.PPC_INFORMATION)
  1037. || currentTag.equals(Protocol.PPC_BOTTOM_INFORMATION)
  1038. ) {
  1039. res.append("<font color=gray>");
  1040. res.append(ss.substring(i, i+attrLen));
  1041. res.append("</font>\n");
  1042. i += attrLen;
  1043. i = parseXmlTag(ss, i, len);
  1044. } else {
  1045. res.append(ss.substring(i, i+attrLen));
  1046. res.append("\n");
  1047. i += attrLen;
  1048. }
  1049. i = s.skipBlank(ss, i, len);
  1050. }
  1051. } catch(Exception e) {
  1052. e.printStackTrace(System.err);
  1053. JOptionPane.showMessageDialog(s.view,
  1054. "Problem while parsing report " + e,
  1055. "Xrefactory Error",
  1056. JOptionPane.ERROR_MESSAGE);
  1057. }
  1058. res.append("\n</pre></html>\n");
  1059. if (s.debug) System.err.println("HTML == \n" + res.toString());
  1060. return(res.toString());
  1061. }
  1062. }