Imports.java 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package API;
  7. import compiler.IvannosysCompiler;
  8. import java.util.HashMap;
  9. /**
  10. *
  11. * @author Eugenio
  12. */
  13. public class Imports {
  14. protected static HashMap<String, String> imports = new HashMap<>();
  15. protected static HashMap<String, Boolean> loaded = new HashMap<>();
  16. protected static HashMap<String, Boolean> used = new HashMap<>();
  17. protected static IvannosysCompiler compiler;
  18. public static void _init(IvannosysCompiler compiler) {
  19. Imports.compiler = compiler;
  20. }
  21. public static void Add(String path) throws Exception {
  22. Imports.Add(path, "");
  23. }
  24. public static boolean Load(String alias) throws Exception {
  25. if (!imports.containsKey(alias)) {
  26. return false;
  27. }
  28. if (!loaded.containsKey(alias)) {
  29. compiler.LoadPackage(alias, imports.get(alias));
  30. loaded.put(alias, true);
  31. }
  32. return true;
  33. }
  34. public static void Add(String path, String alias) throws Exception {
  35. if (alias.equals("")) {
  36. String[] parts = path.split("/");
  37. alias = parts[parts.length - 1];
  38. }
  39. if (!imports.containsKey(alias)) {
  40. imports.put(alias, path);
  41. }
  42. Load(alias);
  43. }
  44. public static HashMap<String, String> imports() {
  45. return imports;
  46. }
  47. }