Search in sources :

Example 1 with CompilationUnit

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);
            }
        }
    }
}
Also used : CompilationUnit(net.jangaroo.jooc.ast.CompilationUnit) ZipEntryInputSource(net.jangaroo.jooc.input.ZipEntryInputSource) File(java.io.File)

Example 2 with CompilationUnit

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);
    }
}
Also used : CompilationUnit(net.jangaroo.jooc.ast.CompilationUnit) InputStreamReader(java.io.InputStreamReader) Symbol(java_cup.runtime.Symbol) BOMStripperInputStream(net.jangaroo.utils.BOMStripperInputStream) IOException(java.io.IOException) IOException(java.io.IOException)

Example 3 with CompilationUnit

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;
}
Also used : CompilationUnit(net.jangaroo.jooc.ast.CompilationUnit)

Example 4 with CompilationUnit

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;
}
Also used : CompilationUnit(net.jangaroo.jooc.ast.CompilationUnit)

Example 5 with CompilationUnit

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;
        }
    };
}
Also used : CompilationUnit(net.jangaroo.jooc.ast.CompilationUnit) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) File(java.io.File) JsWriter(net.jangaroo.jooc.JsWriter)

Aggregations

CompilationUnit (net.jangaroo.jooc.ast.CompilationUnit)10 File (java.io.File)4 IOException (java.io.IOException)3 InputSource (net.jangaroo.jooc.input.InputSource)3 FileInputSource (net.jangaroo.jooc.input.FileInputSource)2 ZipEntryInputSource (net.jangaroo.jooc.input.ZipEntryInputSource)2 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Symbol (java_cup.runtime.Symbol)1 ConfigClassBuilder (net.jangaroo.exml.as.ConfigClassBuilder)1 Jooc (net.jangaroo.jooc.Jooc)1 JsWriter (net.jangaroo.jooc.JsWriter)1 StdOutCompileLog (net.jangaroo.jooc.StdOutCompileLog)1 Ide (net.jangaroo.jooc.ast.Ide)1 ImportDirective (net.jangaroo.jooc.ast.ImportDirective)1 QualifiedIde (net.jangaroo.jooc.ast.QualifiedIde)1 CompilationUnitSinkFactory (net.jangaroo.jooc.backend.CompilationUnitSinkFactory)1