use of com.redhat.ceylon.compiler.typechecker.context.PhasedUnits in project ceylon-compiler by ceylon.
the class CeylonDocModuleSourceMapper method createPhasedUnits.
@Override
protected PhasedUnits createPhasedUnits() {
PhasedUnits units = super.createPhasedUnits();
String fileEncoding = tool.getEncoding();
if (fileEncoding == null) {
fileEncoding = CeylonConfig.get(DefaultToolOptions.DEFAULTS_ENCODING);
}
if (fileEncoding != null) {
units.setEncoding(fileEncoding);
}
return units;
}
use of com.redhat.ceylon.compiler.typechecker.context.PhasedUnits in project ceylon-compiler by ceylon.
the class CeylonVersionTool method run.
@Override
public void run() throws IOException, RecognitionException {
// TODO if version is empty? Prompt? Or should --set have an optional argument?
TypeCheckerBuilder tcb = new TypeCheckerBuilder();
for (File path : this.sourceFolders) {
tcb.addSrcDirectory(applyCwd(path));
}
TypeChecker tc = tcb.getTypeChecker();
PhasedUnits pus = tc.getPhasedUnits();
pus.visitModules();
ArrayList<Module> moduleList = new ArrayList<Module>(pus.getModuleSourceMapper().getCompiledModules());
Collections.sort(moduleList, new Comparator<Module>() {
@Override
public int compare(Module m1, Module m2) {
if (match(m1) && !match(m2)) {
return -1;
} else if (!match(m1) && match(m2)) {
return +1;
}
int cmp = m1.getNameAsString().compareToIgnoreCase(m2.getNameAsString());
if (cmp == 0) {
cmp = m1.getVersion().compareTo(m2.getVersion());
}
return cmp;
}
});
// first update all module versions and remember which version we assigned to which module
// because the user can update every individual version
Map<String, String> updatedModuleVersions = new HashMap<String, String>();
for (Module module : moduleList) {
boolean isMatch = match(module);
if (newVersion == null) {
output(module, isMatch);
} else if (isMatch) {
if (!updateModuleVersion(module, updatedModuleVersions)) {
return;
}
}
}
// now do dependencies because we know which modules we did update
if (newVersion != null && !noUpdateDependencies) {
for (Module module : moduleList) {
if (!updateModuleImports(module, updatedModuleVersions)) {
return;
}
}
}
}
use of com.redhat.ceylon.compiler.typechecker.context.PhasedUnits in project ceylon-compiler by ceylon.
the class CeylonModuleRunner method postCompile.
private void postCompile(Context context, ErrorCollector listener, String moduleName, File srcDir, String[] dependencies, Set<String> removeAtRuntime, String[] modulesUsingCheckFunction, String[] modulesUsingCheckModule) throws Exception {
// now fetch stuff from the context
PhasedUnits phasedUnits = LanguageCompiler.getPhasedUnitsInstance(context);
List<Runner> moduleRunners = new LinkedList<Runner>();
// Get a class loader for the car
// XXX Need to use CMR if the module has dependencies
URL[] carUrls = getCarUrls(moduleName, dependencies, removeAtRuntime, outRepo);
URLClassLoader cl = classLoaderForModule(carUrls);
Runnable moduleInitialiser = getModuleInitialiser(moduleName, carUrls, dependencies, removeAtRuntime, cl);
if (cl != null) {
loadCompiledTests(moduleRunners, srcDir, cl, phasedUnits, moduleName, modulesUsingCheckFunction, modulesUsingCheckModule);
}
CeylonTestGroup ceylonTestGroup = new CeylonTestGroup(moduleRunners, moduleName, moduleInitialiser);
children.put(ceylonTestGroup, ceylonTestGroup.getDescription());
}
use of com.redhat.ceylon.compiler.typechecker.context.PhasedUnits in project ceylon-compiler by ceylon.
the class NamingTests method getDecls.
protected List<Declaration> getDecls(String resource) throws Exception {
final String name = PKGNAME.replace('.', '/') + "/" + resource;
File file = new File("test/src", name);
if (!file.exists()) {
throw new RuntimeException("Unable to find resource " + name);
}
RepositoryManagerBuilder builder = new RepositoryManagerBuilder(new NullLogger(), false, 20000, java.net.Proxy.NO_PROXY);
RepositoryManager repoManager = builder.buildRepository();
VFS vfs = new VFS();
Context context = new Context(repoManager, vfs);
PhasedUnits pus = new PhasedUnits(context);
// Make the module manager think we're looking at this package
// even though there's no module descriptor
pus.getModuleSourceMapper().push(PKGNAME);
pus.parseUnit(vfs.getFromFile(file), vfs.getFromFile(new File("test-src")));
final java.util.List<PhasedUnit> listOfUnits = pus.getPhasedUnits();
PhasedUnit pu = listOfUnits.get(0);
pu.validateTree();
pu.scanDeclarations();
pu.scanTypeDeclarations();
pu.validateRefinement();
pu.analyseTypes();
pu.analyseFlow();
return pu.getDeclarations();
}
use of com.redhat.ceylon.compiler.typechecker.context.PhasedUnits in project ceylon-compiler by ceylon.
the class LanguageCompiler method getPhasedUnitsInstance.
/**
* Get the PhasedUnits instance for this context.
*/
public static PhasedUnits getPhasedUnitsInstance(final Context context) {
PhasedUnits phasedUnits = context.get(phasedUnitsKey);
if (phasedUnits == null) {
com.redhat.ceylon.compiler.typechecker.context.Context ceylonContext = getCeylonContextInstance(context);
phasedUnits = new PhasedUnits(ceylonContext, new ModuleManagerFactory() {
@Override
public ModuleManager createModuleManager(com.redhat.ceylon.compiler.typechecker.context.Context ceylonContext) {
CompilerDelegate phasedUnitsManager = getCompilerDelegate(context);
return phasedUnitsManager.getModuleManager();
}
@Override
public ModuleSourceMapper createModuleManagerUtil(com.redhat.ceylon.compiler.typechecker.context.Context ceylonContext, ModuleManager moduleManager) {
CompilerDelegate phasedUnitsManager = getCompilerDelegate(context);
return phasedUnitsManager.getModuleSourceMapper();
}
});
context.put(phasedUnitsKey, phasedUnits);
}
return phasedUnits;
}
Aggregations