A semantic search engine for source code https://bitshift.benkurtovic.com/
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

160 Zeilen
6.3 KiB

  1. package com.bitshift.parsing.symbols;
  2. import java.util.List;
  3. import java.util.Map;
  4. import java.util.HashMap;
  5. import java.util.ArrayList;
  6. import com.bitshift.parsing.symbols.Symbols;
  7. /*TODO: Overwrite toString.*/
  8. public class JavaSymbols extends Symbols {
  9. private String _packageName;
  10. private Map<String, Object> _classes;
  11. private Map<String, Object> _interfaces;
  12. private Map<String, Object> _methods;
  13. private Map<String, Object> _fields;
  14. private Map<String, Object> _vars;
  15. public JavaSymbols() {
  16. _packageName = null;
  17. _classes = new HashMap<String, Object>();
  18. _interfaces = new HashMap<String, Object>();
  19. _methods = new HashMap<String, Object>();
  20. _fields = new HashMap<String, Object>();
  21. _vars = new HashMap<String, Object>();
  22. }
  23. public boolean setPackage(String name) {
  24. _packageName = name;
  25. return true;
  26. }
  27. public boolean insertClassDeclaration(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) {
  28. List<Integer> pos = new ArrayList<Integer>(4);
  29. pos.add(startLine); pos.add(startCol); pos.add(endLine); pos.add(endCol);
  30. List<List<Integer>> copy = (List<List<Integer>>)_classes.get(name);
  31. copy = (copy == null) ? new ArrayList<List<Integer>>() : copy;
  32. copy.add(0, pos);
  33. this._classes.put(name, copy);
  34. return true;
  35. }
  36. public boolean insertClassInstance(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) {
  37. List<Integer> pos = new ArrayList<Integer>(4);
  38. pos.add(startLine); pos.add(startCol); pos.add(endLine); pos.add(endCol);
  39. List<List<Integer>> copy = (List<List<Integer>>)_classes.get(name);
  40. copy = (copy == null) ? new ArrayList<List<Integer>>() : copy;
  41. copy.add(pos);
  42. this._classes.put(name, copy);
  43. return true;
  44. }
  45. public boolean insertInterfaceDeclaration(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) {
  46. List<Integer> pos = new ArrayList<Integer>(4);
  47. pos.add(startLine); pos.add(startCol); pos.add(endLine); pos.add(endCol);
  48. List<List<Integer>> copy = (List<List<Integer>>)_classes.get(name);
  49. copy = (copy == null) ? new ArrayList<List<Integer>>() : copy;
  50. copy.add(0, pos);
  51. this._interfaces.put(name, copy);
  52. return true;
  53. }
  54. public boolean insertInterfaceInstance(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) {
  55. List<Integer> pos = new ArrayList<Integer>(4);
  56. pos.add(startLine); pos.add(startCol); pos.add(endLine); pos.add(endCol);
  57. List<List<Integer>> copy = (List<List<Integer>>)_classes.get(name);
  58. copy = (copy == null) ? new ArrayList<List<Integer>>() : copy;
  59. copy.add(pos);
  60. this._interfaces.put(name, copy);
  61. return true;
  62. }
  63. public boolean insertMethodDeclaration(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) {
  64. List<Integer> pos = new ArrayList<Integer>(4);
  65. pos.add(startLine); pos.add(startCol); pos.add(endLine); pos.add(endCol);
  66. List<List<Integer>> copy = (List<List<Integer>>)_classes.get(name);
  67. copy = (copy == null) ? new ArrayList<List<Integer>>() : copy;
  68. copy.add(0, pos);
  69. this._methods.put(name, copy);
  70. return true;
  71. }
  72. public boolean insertMethodInvocation(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) {
  73. List<Integer> pos = new ArrayList<Integer>(4);
  74. pos.add(startLine); pos.add(startCol); pos.add(endLine); pos.add(endCol);
  75. List<List<Integer>> copy = (List<List<Integer>>)_classes.get(name);
  76. copy = (copy == null) ? new ArrayList<List<Integer>>() : copy;
  77. copy.add(pos);
  78. this._methods.put(name, copy);
  79. return true;
  80. }
  81. public boolean insertFieldDeclaration(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) {
  82. List<Integer> pos = new ArrayList<Integer>(4);
  83. pos.add(startLine); pos.add(startCol); pos.add(endLine); pos.add(endCol);
  84. List<List<Integer>> copy = (List<List<Integer>>)_classes.get(name);
  85. copy = (copy == null) ? new ArrayList<List<Integer>>() : copy;
  86. copy.add(0, pos);
  87. this._fields.put(name, copy);
  88. return true;
  89. }
  90. public boolean insertFieldAccess(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) {
  91. List<Integer> pos = new ArrayList<Integer>(4);
  92. pos.add(startLine); pos.add(startCol); pos.add(endLine); pos.add(endCol);
  93. List<List<Integer>> copy = (List<List<Integer>>)_classes.get(name);
  94. copy = (copy == null) ? new ArrayList<List<Integer>>() : copy;
  95. copy.add(pos);
  96. this._fields.put(name, copy);
  97. return true;
  98. }
  99. public boolean insertVariableDeclaration(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) {
  100. List<Integer> pos = new ArrayList<Integer>(4);
  101. pos.add(startLine); pos.add(startCol); pos.add(endLine); pos.add(endCol);
  102. List<List<Integer>> copy = (List<List<Integer>>)_classes.get(name);
  103. copy = (copy == null) ? new ArrayList<List<Integer>>() : copy;
  104. copy.add(0, pos);
  105. this._vars.put(name, copy);
  106. return true;
  107. }
  108. public boolean insertVariableAccess(String name, Integer startLine, Integer startCol, Integer endLine, Integer endCol) {
  109. List<Integer> pos = new ArrayList<Integer>(4);
  110. pos.add(startLine); pos.add(startCol); pos.add(endLine); pos.add(endCol);
  111. List<List<Integer>> copy = (List<List<Integer>>)_classes.get(name);
  112. copy = (copy == null) ? new ArrayList<List<Integer>>() : copy;
  113. copy.add(pos);
  114. this._vars.put(name, copy);
  115. return true;
  116. }
  117. public String toString() {
  118. StringBuilder builder = new StringBuilder();
  119. builder.append("classes:" + this._classes + ",");
  120. builder.append("interfaces:" + this._interfaces + ",");
  121. builder.append("methods:" + this._methods + ",");
  122. builder.append("fields:" + this._fields + ",");
  123. builder.append("vars:" + this._vars + ",");
  124. return "{" + builder.toString() + "}";
  125. }
  126. }