MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / imports

Method imports

src/main/java/fieldnashorn/TernSupport.java:597–669  ·  view source on GitHub ↗
(ScriptEngine engine, String boxName, String allText, int line, int ch)

Source from the content-addressed store, hash-verified

595 int c = 0;
596 for (int i = 0; i < line; i++) {
597 c += lines[i].length() + 1;
598 }
599
600 c += ch;
601
602
603 final int finalC = c;
604 Log.log("completion.debug", () -> " line :" + line + " -> " + ch + " -> " + finalC);
605
606 engine.eval("var __c=new __fieldglobal.self.tern.Context()");
607 Object[] ret = (Object[]) engine.eval("__fieldglobal.self.tern.withContext(__c, function()" +
608 "{\n" +
609 "\tvar a = __fieldglobal.self.tern.parse(__someFile)\n" +
610 "\t__fieldglobal.self.tern.analyze(a)\n" +
611 "\tvar n = __fieldglobal.self.tern.findExpressionAround(a, " + c + ", " + c + ")\n" +
612 "\treturn Java.to([n.node.start, n.node.end])" +
613 "})");
614 Log.log("completion.debug", () -> " expression to analyze is :" + ret[0] + " " + ret[1] + " "
615 + allText.substring(((Number) ret[0]).intValue(), ((Number) ret[1]).intValue()));
616
617
618 String s = allText.substring(((Number) ret[0]).intValue(), ((Number) ret[1]).intValue());
619
620 try {
621
622 String left = s, right = "";
623
624
625 Log.log("completion.debug", () -> " inside import help left is <" + left + ">");
626
627 List<Pair<String, String>> possibleJavaClassesFor = javaSupport
628 .getPossibleJavaClassesFor(left);
629
630 Log.log("completion.debug", () -> " possible javaclasses :");
631 possibleJavaClassesFor.forEach(System.out::println);
632
633 for (Pair<String, String> p : possibleJavaClassesFor) {
634 int tail = Math.max(p.first.lastIndexOf("."), p.first.lastIndexOf("$"));
635
636 Completion ex = new Completion(c - left.length(), c, p.first.substring(tail +
637 1), p.second);
638 String typeName = p.first.replaceAll("\\$", ".");
639
640 if (typeName.endsWith("."))
641 typeName = typeName.substring(0, typeName.length() - 1);
642
643 ex.header = "var " + p.first.substring(tail + 1) + " = Java.type('" + typeName
644 + "')";
645 r.add(ex);
646 }
647
648 } catch (Throwable t) {
649 Log.log("completion.debug", () -> " suppressed exception in auto-evaluating completion" +
650 " <" + t + ">");
651 }
652 } catch (ScriptException e) {
653 e.printStackTrace();
654 }

Callers

nothing calls this directly

Calls 9

logMethod · 0.95
evalMethod · 0.80
putMethod · 0.45
splitMethod · 0.45
lengthMethod · 0.45
forEachMethod · 0.45
maxMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected