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

Method _transform

src/main/java/fieldnashorn/babel/Translate.java:84–135  ·  view source on GitHub ↗
(String c)

Source from the content-addressed store, hash-verified

82 }
83
84 private Pair<String, Function<Integer, Integer>> _transform(String c) throws TranslationFailedException {
85
86 try {
87 File f = File.createTempFile("field", ".js", new File(congifurationDirectory));
88 f.deleteOnExit();
89 File error = File.createTempFile("field", ".error", new File(congifurationDirectory));
90 error.deleteOnExit();
91
92 FileWriter fw = new FileWriter(f);
93 fw.append(c);
94 fw.close();
95
96
97 int success = new ProcessBuilder().directory(new File(congifurationDirectory))
98 .command(command.replace("#", f.getAbsolutePath()).split(" "))
99 .redirectError(error)
100 .start()
101 .waitFor();
102
103 if (success == 0) {
104 String code = new String(Files.readAllBytes(new File(f.getAbsolutePath() + ".5.js").toPath()));
105 String mapping = new String(Files.readAllBytes(new File(f.getAbsolutePath() + ".5.js.map").toPath()));
106
107
108 SourceMapConsumerV3 sm = new SourceMapConsumerV3();
109 sm.parse(mapping);
110
111 codeCache.put(c, code);
112
113 Function<Integer, Integer> fn = x -> x;
114 try {
115 fn = x -> sm.getMappingForLine(x, 1)
116 .getLineNumber();
117 mapCache.put(c, fn);
118 } catch (NullPointerException e) {
119 e.printStackTrace();
120 }
121
122 return new Pair<>((first ? preamble : "") + code, fn);
123 } else {
124 String code = new String(Files.readAllBytes(error.toPath()));
125 throw new TranslationFailedException(code);
126 }
127 } catch (InterruptedException e) {
128 e.printStackTrace();
129 } catch (IOException e) {
130 e.printStackTrace();
131 } catch (SourceMapParseException e) {
132 e.printStackTrace();
133 }
134 return null;
135 }
136
137}

Callers 1

transformMethod · 0.95

Calls 9

parseMethod · 0.95
getMappingForLineMethod · 0.95
replaceMethod · 0.80
closeMethod · 0.65
getLineNumberMethod · 0.65
appendMethod · 0.45
startMethod · 0.45
splitMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected