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;
}
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();
}
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);
}
}
}
}
}
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();
}
}
}
}
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;
}
Aggregations