You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

UnsolvedSymbolDumper.java 3.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. MIT License
  3. Copyright (c) 2018-2019 Gang ZHANG
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. */
  20. package depends.format.detail;
  21. import java.io.File;
  22. import java.io.FileNotFoundException;
  23. import java.io.PrintWriter;
  24. import java.util.HashSet;
  25. import java.util.Set;
  26. import java.util.TreeMap;
  27. import com.fasterxml.jackson.annotation.JsonInclude.Include;
  28. import com.fasterxml.jackson.databind.ObjectMapper;
  29. import com.fasterxml.jackson.databind.SerializationFeature;
  30. import depends.extractor.UnsolvedBindings;
  31. import multilang.depends.util.file.strip.LeadingNameStripper;
  32. public class UnsolvedSymbolDumper{
  33. private Set<UnsolvedBindings> unsolved;
  34. private String name;
  35. private String outputDir;
  36. private LeadingNameStripper leadingNameStripper;
  37. public UnsolvedSymbolDumper(Set<UnsolvedBindings> unsolved, String name, String outputDir, LeadingNameStripper leadingNameStripper) {
  38. this.unsolved = unsolved;
  39. this.name = name;
  40. this.outputDir = outputDir;
  41. this.leadingNameStripper = leadingNameStripper;
  42. }
  43. public void output() {
  44. outputDetail();
  45. outputGrouped();
  46. }
  47. private void outputGrouped() {
  48. TreeMap<String, Set<String>> grouped = new TreeMap<String, Set<String>>();
  49. for (UnsolvedBindings symbol: unsolved) {
  50. String depended = symbol.getRawName();
  51. String from = leadingNameStripper.stripFilename(symbol.getSourceDisplay());
  52. Set<String> list = grouped.get(depended);
  53. if (list==null) {
  54. list = new HashSet<>();
  55. grouped.put(depended, list);
  56. }
  57. list.add(from);
  58. }
  59. ObjectMapper om = new ObjectMapper();
  60. om.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
  61. om.configure(SerializationFeature.INDENT_OUTPUT, true);
  62. om.setSerializationInclusion(Include.NON_NULL);
  63. try {
  64. om.writerWithDefaultPrettyPrinter().writeValue(new File(outputDir + File.separator + name +"-PotentialExternalDependencies.json"), grouped);
  65. } catch (Exception e) {
  66. e.printStackTrace();
  67. }
  68. }
  69. private void outputDetail() {
  70. PrintWriter writer;
  71. try {
  72. writer = new PrintWriter(outputDir + File.separator + name +"-PotentialExternalDependencies.txt");
  73. for (UnsolvedBindings symbol: unsolved) {
  74. String source = leadingNameStripper.stripFilename(symbol.getSourceDisplay());
  75. writer.println(""+symbol.getRawName()+", "+source);
  76. }
  77. writer.close();
  78. } catch (FileNotFoundException e) {
  79. e.printStackTrace();
  80. }
  81. }
  82. }

GeekAI 是基于 AI 大语言模型 API 实现的 AI 助手全套开源解决方案,自带运营管理后台,开箱即用。集成了 OpenAI, Azure, ChatGLM,讯飞星火,文心一言等多个平台的大语言模型。采用 Go + Vue3 + element-plus 实现。

Contributors (2)