use of net.jangaroo.jooc.ast.CompilationUnit in project jangaroo-tools by CoreMedia.
the class Jooc method reportPublicApiViolations.
private void reportPublicApiViolations(CompilationUnit unit) {
for (CompilationUnit compilationUnit : unit.getDependenciesAsCompilationUnits()) {
if (compilationUnit.getSource() instanceof ZipEntryInputSource && compilationUnit.getAnnotation(PUBLIC_API_EXCLUSION_ANNOTATION_NAME) != null) {
String msg = "PUBLIC API VIOLATION: " + compilationUnit.getPrimaryDeclaration().getQualifiedNameStr();
File sourceFile = new File(unit.getSymbol().getFileName());
if (getConfig().getPublicApiViolationsMode() == PublicApiViolationsMode.WARN) {
JangarooParser.warning(msg, sourceFile);
} else {
throw JangarooParser.error(msg, sourceFile);
}
}
}
}
use of net.jangaroo.jooc.ast.CompilationUnit in project jangaroo-tools by CoreMedia.
the class JangarooParser method doParse.
public static CompilationUnit doParse(InputSource in, CompileLog log, SemicolonInsertionMode semicolonInsertionMode) {
Scanner s;
try {
s = new Scanner(new InputStreamReader(new BOMStripperInputStream(in.getInputStream()), "UTF-8"));
} catch (IOException e) {
throw new CompilerError("Cannot read input file: " + in.getPath(), e);
}
s.setInputSource(in);
JooParser p = new JooParser(s);
p.setCompileLog(log);
p.setSemicolonInsertionMode(semicolonInsertionMode);
try {
Symbol tree = p.parse();
return (CompilationUnit) tree.value;
} catch (Scanner.ScanError se) {
log.error(se.getSym(), se.getMessage());
return null;
} catch (JooParser.FatalSyntaxError e) {
// message already logged in parser
return null;
} catch (Exception e) {
throw new IllegalArgumentException("could not parse Jangaroo source", e);
}
}
use of net.jangaroo.jooc.ast.CompilationUnit in project jangaroo-tools by CoreMedia.
the class JangarooParser method parse.
protected CompilationUnit parse(InputSource in) {
if (!in.getName().endsWith(Jooc.AS_SUFFIX)) {
throw error("Input file must end with '" + Jooc.AS_SUFFIX + "': " + in.getName());
}
if (config.isVerbose()) {
// NOSONAR this is a cmd line tool
System.out.println("Parsing " + in.getPath() + " (" + (in.isInSourcePath() ? "source" : "class") + "path)");
}
CompilationUnit unit = doParse(in, log, config.getSemicolonInsertionMode());
if (unit != null) {
unit.setCompiler(this);
unit.setSource(in);
}
return unit;
}
use of net.jangaroo.jooc.ast.CompilationUnit in project jangaroo-tools by CoreMedia.
the class JangarooParser method importSource.
public CompilationUnit importSource(InputSource source) {
CompilationUnit unit = parse(source);
if (unit != null) {
unit.scope(globalScope);
String prefix = unit.getPackageDeclaration().getQualifiedNameStr();
String qname = CompilerUtils.qName(prefix, unit.getPrimaryDeclaration().getIde().getName());
checkValidFileName(qname, unit, source);
compilationUnitsByQName.put(qname, unit);
}
return unit;
}
use of net.jangaroo.jooc.ast.CompilationUnit in project jangaroo-tools by CoreMedia.
the class SingleFileCompilationUnitSinkFactory method createSink.
public CompilationUnitSink createSink(PackageDeclaration packageDeclaration, IdeDeclaration primaryDeclaration, File sourceFile, final boolean verbose) {
final File outFile = getOutputFile(sourceFile, packageDeclaration.getQualifiedName());
String fileName = outFile.getName();
String classPart = fileName.substring(0, fileName.lastIndexOf('.'));
String className = primaryDeclaration.getName();
if (!classPart.equals(className)) {
Jooc.warning(primaryDeclaration.getSymbol(), "class name should be equal to file name: expected " + classPart + ", found " + className);
}
createOutputDirs(outFile);
return new CompilationUnitSink() {
public File writeOutput(CompilationUnit compilationUnit) {
if (verbose) {
// NOSONAR this is a cmd line tool
System.out.println("writing file: '" + outFile.getAbsolutePath() + "'");
}
try {
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8");
try {
if (generateApi) {
ApiModelGenerator apiModelGenerator = new ApiModelGenerator(isExcludeClassByDefault(getOptions()));
apiModelGenerator.generateModel(compilationUnit).visit(new ActionScriptCodeGeneratingModelVisitor(writer));
} else {
JsWriter out = new JsWriter(writer);
try {
out.setOptions(getOptions());
compilationUnit.visit(new JsCodeGenerator(out));
} finally {
out.close();
}
}
} catch (IOException e) {
// noinspection ResultOfMethodCallIgnored
// NOSONAR
outFile.delete();
throw Jooc.error("error writing file: '" + outFile.getAbsolutePath() + "'", outFile, e);
}
} catch (IOException e) {
throw Jooc.error("cannot open output file for writing: '" + outFile.getAbsolutePath() + "'", outFile, e);
}
return outFile;
}
};
}
Aggregations