use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits in project ceylon by eclipse.
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 org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits in project ceylon by eclipse.
the class LanguageCompiler method initRound.
@Override
public void initRound(JavaCompiler prev) {
super.initRound(prev);
// round compilers don't add module trees, it's already done by the first one
addModuleTrees = false;
PhasedUnits oldPUs = ((LanguageCompiler) prev).phasedUnits;
ModuleManager moduleManager = phasedUnits.getModuleManager();
ModuleSourceMapper moduleSourceMapper = phasedUnits.getModuleSourceMapper();
for (PhasedUnit pu : oldPUs.getPhasedUnits()) {
if (pu instanceof CeylonPhasedUnit) {
CeylonPhasedUnit cpu = (CeylonPhasedUnit) pu;
// FIXME: this is bad in many ways
String pkgName;
try {
pkgName = getPackage(((CeylonPhasedUnit) pu).getFileObject());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
continue;
}
// make a Package with no module yet, we will resolve them later
/*
* Stef: see javadoc for findOrCreateModulelessPackage() for why this is here.
*/
org.eclipse.ceylon.model.typechecker.model.Package p = modelLoader.findOrCreateModulelessPackage(pkgName == null ? "" : pkgName);
CeylonPhasedUnit newPu = new CeylonPhasedUnit(pu.getUnitFile(), pu.getSrcDir(), pu.getCompilationUnit(), p, moduleManager, moduleSourceMapper, ceylonContext, cpu.getFileObject(), cpu.getLineMap());
phasedUnits.addPhasedUnit(pu.getUnitFile(), newPu);
} else {
phasedUnits.addPhasedUnit(pu.getUnitFile(), pu);
}
}
}
use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits in project ceylon by eclipse.
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) {
org.eclipse.ceylon.compiler.typechecker.context.Context ceylonContext = getCeylonContextInstance(context);
phasedUnits = new PhasedUnits(ceylonContext, new ModuleManagerFactory() {
@Override
public ModuleManager createModuleManager(org.eclipse.ceylon.compiler.typechecker.context.Context ceylonContext) {
CompilerDelegate phasedUnitsManager = getCompilerDelegate(context);
return phasedUnitsManager.getModuleManager();
}
@Override
public ModuleSourceMapper createModuleManagerUtil(org.eclipse.ceylon.compiler.typechecker.context.Context ceylonContext, ModuleManager moduleManager) {
CompilerDelegate phasedUnitsManager = getCompilerDelegate(context);
return phasedUnitsManager.getModuleSourceMapper();
}
});
context.put(phasedUnitsKey, phasedUnits);
}
return phasedUnits;
}
use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits in project ceylon by eclipse.
the class CeylonDocTool method initialize.
@Override
public void initialize(CeylonTool mainTool) throws Exception {
super.initialize(mainTool);
TypeCheckerBuilder builder = new TypeCheckerBuilder();
for (File src : sourceFolders) {
builder.addSrcDirectory(src);
}
// set up the artifact repository
RepositoryManager repository = getRepositoryManager();
builder.setRepositoryManager(repository);
// make a destination repo
outputRepositoryManager = getOutputRepositoryManager();
// create the actual list of modules to process
List<File> srcs = FileUtil.applyCwd(cwd, sourceFolders);
Collection<String> expandedModules = ModuleWildcardsHelper.expandWildcards(srcs, moduleSpecs, null);
final List<ModuleSpec> modules = ModuleSpec.parseEachList(expandedModules);
final Callable<PhasedUnits> getPhasedUnits = new Callable<PhasedUnits>() {
@Override
public PhasedUnits call() throws Exception {
return typeChecker.getPhasedUnits();
}
};
// we need to plug in the module manager which can load from .cars
builder.moduleManagerFactory(new ModuleManagerFactory() {
@Override
public ModuleManager createModuleManager(Context context) {
return new PhasedUnitsModuleManager(getPhasedUnits, context, modules, outputRepositoryManager, bootstrapCeylon, getLogger());
}
@Override
public ModuleSourceMapper createModuleManagerUtil(Context context, ModuleManager moduleManager) {
return new LazyModuleSourceMapper(context, (PhasedUnitsModuleManager) moduleManager, null, false, null, getEncoding());
}
});
// only parse what we asked for
List<String> moduleFilters = new LinkedList<String>();
for (ModuleSpec spec : modules) {
moduleFilters.add(spec.getName());
if (spec.getName().equals(Module.LANGUAGE_MODULE_NAME) && !bootstrapCeylon) {
throw new CeylondException("error.languageModuleBootstrapOptionMissing");
}
}
builder.setModuleFilters(moduleFilters);
String fileEncoding = getEncoding();
if (fileEncoding == null) {
fileEncoding = CeylonConfig.get(DefaultToolOptions.DEFAULTS_ENCODING);
}
if (fileEncoding != null) {
builder.encoding(fileEncoding);
}
// We do this ourselves, so we can report on the resolution errors before
// running typeChecker.process();
builder.skipDependenciesVerification();
typeChecker = builder.getTypeChecker();
{
PhasedUnits phasedUnits = typeChecker.getPhasedUnits();
phasedUnits.getModuleManager().prepareForTypeChecking();
phasedUnits.visitModules();
phasedUnits.getModuleManager().modulesVisited();
}
ModuleValidator moduleValidator = new ModuleValidator(typeChecker.getContext(), typeChecker.getPhasedUnits());
moduleValidator.verifyModuleDependencyTree();
AssertionVisitor av = new AssertionVisitor();
for (PhasedUnit pu : typeChecker.getPhasedUnits().getPhasedUnits()) {
pu.getCompilationUnit().visit(av);
}
if (haltOnError && av.getErrors() > 0) {
throw new CeylondException("error.failedParsing", new Object[] { av.getErrors() }, null);
}
typeChecker.process();
if (haltOnError && typeChecker.getErrors() > 0) {
throw new CeylondException("error.failedTypechecking", new Object[] { typeChecker.getErrors() }, null);
}
initModules(modules);
initPhasedUnits();
}
Aggregations