Search in sources :

Example 1 with InputSource

use of net.jangaroo.jooc.input.InputSource in project jangaroo-tools by CoreMedia.

the class IncludeEvaluator method createReader.

public static Reader createReader(String includeDirective, InputSource source) throws IOException {
    String filename = includeDirective.substring(BEGIN_INDEX, includeDirective.length() - 1);
    Matcher matcher = FILENAME_WITH_LINE_RANGE_PATTERN.matcher(filename);
    boolean hasLineRange = matcher.matches();
    if (hasLineRange) {
        filename = matcher.group(1);
    }
    File file = new File(filename);
    InputStream in = null;
    if (!file.exists() && !file.isAbsolute()) {
        InputSource parent = source.getParent();
        InputSource input = parent.getChild(filename);
        if (input == null) {
            throw new IOException("cannot find input file " + parent.getPath() + parent.getFileSeparatorChar() + filename);
        }
        in = input.getInputStream();
    }
    if (in == null) {
        in = new FileInputStream(file);
    }
    Reader result = new InputStreamReader(in, "UTF-8");
    if (hasLineRange) {
        int startLine = Integer.parseInt(matcher.group(2)) + 1;
        int endLine = Integer.parseInt(matcher.group(3));
        result = new LineRangeReader(result, startLine, endLine);
    }
    return result;
}
Also used : InputSource(net.jangaroo.jooc.input.InputSource) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with InputSource

use of net.jangaroo.jooc.input.InputSource in project jangaroo-tools by CoreMedia.

the class ConfigClassBuilderTest method buildConfigClass.

private ConfigClass buildConfigClass(String resourceName, String module) throws URISyntaxException {
    File sourceFile = new File(getClass().getResource("/" + module + "/" + resourceName).toURI());
    InputSource inputSource = new FileInputSource(sourceFile, true);
    CompilationUnit compilationUnit = new Jooc().doParse(inputSource, new StdOutCompileLog(), SemicolonInsertionMode.QUIRKS);
    ConfigClassBuilder configClassBuilder = new ConfigClassBuilder(compilationUnit);
    return configClassBuilder.buildConfigClass();
}
Also used : CompilationUnit(net.jangaroo.jooc.ast.CompilationUnit) InputSource(net.jangaroo.jooc.input.InputSource) FileInputSource(net.jangaroo.jooc.input.FileInputSource) FileInputSource(net.jangaroo.jooc.input.FileInputSource) ConfigClassBuilder(net.jangaroo.exml.as.ConfigClassBuilder) Jooc(net.jangaroo.jooc.Jooc) StdOutCompileLog(net.jangaroo.jooc.StdOutCompileLog) File(java.io.File)

Example 3 with InputSource

use of net.jangaroo.jooc.input.InputSource in project jangaroo-tools by CoreMedia.

the class ConfigClassRegistry method scanAsFiles.

private void scanAsFiles(Map<String, File> sourceFilesByName) {
    InputSource configPackageInputSource = sourcePathInputSource.getChild(config.getConfigClassPackage().replace('.', File.separatorChar));
    if (configPackageInputSource != null) {
        for (InputSource source : configPackageInputSource.list()) {
            File file = ((FileInputSource) source).getFile();
            if (file.isFile() && file.getName().endsWith(Jooc.AS_SUFFIX)) {
                try {
                    File sourceDir = getConfig().findSourceDir(file);
                    String qName = CompilerUtils.qNameFromFile(sourceDir, file);
                    ConfigClass actionScriptConfigClass = findActionScriptConfigClass(qName);
                    if (actionScriptConfigClass != null) {
                        addSourceConfigClass(sourceFilesByName, file, actionScriptConfigClass);
                    }
                } catch (IOException e) {
                    throw new ExmlcException("could not read AS file", e);
                }
            }
        }
    }
}
Also used : PathInputSource(net.jangaroo.jooc.input.PathInputSource) InputSource(net.jangaroo.jooc.input.InputSource) FileInputSource(net.jangaroo.jooc.input.FileInputSource) FileInputSource(net.jangaroo.jooc.input.FileInputSource) ExmlcException(net.jangaroo.exml.api.ExmlcException) IOException(java.io.IOException) File(java.io.File)

Example 4 with InputSource

use of net.jangaroo.jooc.input.InputSource in project jangaroo-tools by CoreMedia.

the class ConfigClassRegistry method tryGenerateClass.

private void tryGenerateClass(String qname) {
    ExmlSourceFile exmlSourceFile = getExmlSourceFilesByConfigClassName().get(qname);
    if (exmlSourceFile != null) {
        exmlSourceFile.generateConfigClass();
    } else {
        // is there an EXML file for the qname interpreted as a target class name?
        InputSource exmlInputSource = sourcePathInputSource.getChild(JangarooParser.getInputSourceFileName(qname, sourcePathInputSource, Exmlc.EXML_SUFFIX));
        if (exmlInputSource != null) {
            String configClassName = computeConfigClassNameFromTargetClassName(qname);
            exmlSourceFile = getExmlSourceFilesByConfigClassName().get(configClassName);
            if (exmlSourceFile != null) {
                exmlSourceFile.generateTargetClass();
            }
        }
    }
}
Also used : PathInputSource(net.jangaroo.jooc.input.PathInputSource) InputSource(net.jangaroo.jooc.input.InputSource) FileInputSource(net.jangaroo.jooc.input.FileInputSource)

Example 5 with InputSource

use of net.jangaroo.jooc.input.InputSource in project jangaroo-tools by CoreMedia.

the class JangarooParser method getCompilationUnit.

public CompilationUnit getCompilationUnit(String qname) {
    CompilationUnit compilationUnit = compilationUnitsByQName.get(qname);
    if (compilationUnit == null) {
        InputSource source = findSource(qname);
        if (source == null) {
            return null;
        }
        compilationUnit = importSource(source);
    }
    return compilationUnit;
}
Also used : CompilationUnit(net.jangaroo.jooc.ast.CompilationUnit) InputSource(net.jangaroo.jooc.input.InputSource)

Aggregations

InputSource (net.jangaroo.jooc.input.InputSource)6 File (java.io.File)4 FileInputSource (net.jangaroo.jooc.input.FileInputSource)4 IOException (java.io.IOException)3 CompilationUnit (net.jangaroo.jooc.ast.CompilationUnit)3 PathInputSource (net.jangaroo.jooc.input.PathInputSource)3 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1 ExmlcException (net.jangaroo.exml.api.ExmlcException)1 ConfigClassBuilder (net.jangaroo.exml.as.ConfigClassBuilder)1 Jooc (net.jangaroo.jooc.Jooc)1 StdOutCompileLog (net.jangaroo.jooc.StdOutCompileLog)1 CompilationUnitSinkFactory (net.jangaroo.jooc.backend.CompilationUnitSinkFactory)1 MergedOutputCompilationUnitSinkFactory (net.jangaroo.jooc.backend.MergedOutputCompilationUnitSinkFactory)1 SingleFileCompilationUnitSinkFactory (net.jangaroo.jooc.backend.SingleFileCompilationUnitSinkFactory)1 ZipEntryInputSource (net.jangaroo.jooc.input.ZipEntryInputSource)1