use of org.eclipse.n4js.dts.DtsParser in project n4js by eclipse.
the class N4JSResource method doLoad.
/**
* Ensures that state is discarded before loading (i.e. the second slot is unloaded).
*/
@Override
protected void doLoad(InputStream inputStream, Map<?, ?> options) throws IOException {
if (options != null && options.containsKey(OPTION_CLEAR_FUNCTION_BODIES)) {
optionClearFunctionBodies = Boolean.TRUE == options.get(OPTION_CLEAR_FUNCTION_BODIES);
}
if (contents != null && !contents.isEmpty()) {
discardStateFromDescription(true);
}
if (isOpaque()) {
IParseResult result = new JSParseResult(inputStream);
updateInternalState(this.getParseResult(), result);
} else {
ResourceType resourceType = ResourceType.getResourceType(getURI());
if (resourceType == ResourceType.DTS) {
setValidationDisabled(true);
try (Reader reader = createReader(inputStream)) {
IParseResult result = new DtsParser().parse(reader, this);
updateInternalState(this.getParseResult(), result);
}
} else {
super.doLoad(inputStream, options);
}
}
}
use of org.eclipse.n4js.dts.DtsParser in project n4js by eclipse.
the class DtsParsesDefinitelyTypedTest method assertParseCounts.
static void assertParseCounts(Path repoRoot, int minPass, int maxFail, int maxError) throws IOException {
Path typesFolder = repoRoot.resolve("types");
List<Path> files = Files.walk(typesFolder, FileVisitOption.FOLLOW_LINKS).filter(file -> {
if (!file.toString().endsWith(".d.ts")) {
return false;
}
String relPath = typesFolder.relativize(file).toString();
for (String exclude : EXCLUDES) {
if (exclude != null && !exclude.isBlank() && relPath.startsWith(exclude)) {
return false;
}
}
return true;
}).collect(Collectors.toList());
Collections.sort(files, (p1, p2) -> p1.toString().compareTo(p2.toString()));
int filesCount = files.size();
int pass = 0;
int fail = 0;
int error = 0;
System.out.println("Processing " + filesCount + " files ...");
Stopwatch sw = Stopwatch.createStarted();
for (Path file : files) {
try (BufferedReader buf = new BufferedReader(new InputStreamReader(new FileInputStream(file.toFile())))) {
N4JSResource resource = new N4JSResource();
resource.setURI(new FileURI(file).toURI());
DtsParseResult parseResult = new DtsParser().parse(buf, resource);
if (parseResult.hasSyntaxErrors()) {
fail++;
} else {
pass++;
}
} catch (Throwable e) {
e.printStackTrace();
if (e instanceof Error) {
throw e;
}
error++;
}
}
System.out.println("Done processing " + filesCount + " files in " + sw.elapsed(TimeUnit.SECONDS) + "s");
System.out.println(" passed: " + pass + " (" + percent(pass, filesCount) + ")");
System.out.println(" failed: " + fail + " (" + percent(fail, filesCount) + ")");
System.out.println(" errors: " + error + " (" + percent(error, filesCount) + ")");
if (error > maxError) {
Assert.fail("More errors detected than expected: " + error);
}
if (fail > maxFail) {
Assert.fail("More failures detected than expected: " + fail);
}
if (pass < minPass) {
Assert.fail("Less passes detected than expected: " + pass);
}
}
Aggregations