use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits in project ceylon by eclipse.
the class ModuleSourceMapper method resolveModule.
public void resolveModule(ArtifactResult artifact, Module module, ModuleImport moduleImport, LinkedList<Module> dependencyTree, List<PhasedUnits> phasedUnitsOfDependencies, boolean forCompiledModule) {
// This implementation relies on the ability to read the model from source
// the compiler for example subclasses this to read lazily and from the compiled model
ArtifactContext artifactContext = new ArtifactContext(null, module.getNameAsString(), module.getVersion(), ArtifactContext.SRC);
RepositoryManager repositoryManager = context.getRepositoryManager();
Exception exceptionOnGetArtifact = null;
ArtifactResult sourceArtifact = null;
try {
sourceArtifact = repositoryManager.getArtifactResult(artifactContext);
} catch (Exception e) {
exceptionOnGetArtifact = e;
}
if (sourceArtifact == null) {
ModuleHelper.buildErrorOnMissingArtifact(artifactContext, module, moduleImport, dependencyTree, exceptionOnGetArtifact, this, true);
} else {
PhasedUnits modulePhasedUnits = createPhasedUnits();
ClosableVirtualFile virtualArtifact = null;
try {
virtualArtifact = context.getVfs().getFromZipFile(sourceArtifact.artifact());
modulePhasedUnits.parseUnit(virtualArtifact);
// populate module.getDependencies()
modulePhasedUnits.visitModules();
addToPhasedUnitsOfDependencies(modulePhasedUnits, phasedUnitsOfDependencies, module);
} catch (Exception e) {
StringBuilder error = new StringBuilder("unable to read source artifact for ");
error.append(artifactContext.toString());
error.append("\ndue to connection error: ").append(e.getMessage());
attachErrorToDependencyDeclaration(moduleImport, dependencyTree, error.toString(), true);
} finally {
if (virtualArtifact != null) {
virtualArtifact.close();
}
}
}
}
use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits in project ceylon by eclipse.
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 org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits in project ceylon by eclipse.
the class ModelLoaderTests method verifyCompilerClassLoading.
protected void verifyCompilerClassLoading(String ceylon, final ModelComparison modelCompare) {
// now compile the ceylon decl file
CeyloncTaskImpl task = getCompilerTask(ceylon);
// get the context to grab the phased units
Context context = task.getContext();
if (simpleAnnotationModels) {
CeylonEnter.instance(context);
ExpressionTransformer.getInstance(context).simpleAnnotationModels = true;
CeylonTransformer.getInstance(context).simpleAnnotationModels = true;
StatementTransformer.getInstance(context).simpleAnnotationModels = true;
ClassTransformer.getInstance(context).simpleAnnotationModels = true;
}
Boolean success = task.call();
Assert.assertTrue(success);
PhasedUnits phasedUnits = LanguageCompiler.getPhasedUnitsInstance(context);
// find out what was in that file
Assert.assertEquals(2, phasedUnits.getPhasedUnits().size());
PhasedUnit one = phasedUnits.getPhasedUnits().get(0);
PhasedUnit two = phasedUnits.getPhasedUnits().get(1);
PhasedUnit phasedUnit = one.getUnitFile().getName().endsWith("module.ceylon") ? two : one;
final Map<String, Declaration> decls = new HashMap<String, Declaration>();
for (Declaration decl : phasedUnit.getUnit().getDeclarations()) {
if (decl.isToplevel()) {
decls.put(getQualifiedPrefixedName(decl), decl);
}
}
// now compile the ceylon usage file
// remove the extension, make lowercase and add "test"
String testfile = ceylon.substring(0, ceylon.length() - 7).toLowerCase() + "test.ceylon";
JavacTaskImpl task2 = getCompilerTask(testfile);
// get the context to grab the declarations
final Context context2 = task2.getContext();
// declarations from the jar anymore because we've overridden the jar and the javac jar index is corrupted
class Listener implements TaskListener {
@Override
public void started(TaskEvent e) {
}
@Override
public void finished(TaskEvent e) {
if (e.getKind() == Kind.ENTER) {
AbstractModelLoader modelLoader = CeylonModelLoader.instance(context2);
Modules modules = LanguageCompiler.getCeylonContextInstance(context2).getModules();
// now see if we can find our declarations
compareDeclarations(modelCompare, decls, modelLoader, modules);
}
}
}
Listener listener = new Listener();
task2.setTaskListener(listener);
success = task2.call();
Assert.assertTrue("Compilation failed", success);
// now check with the runtime model loader too
String module = moduleForJavaModelLoading();
String version = "1";
ModuleWithArtifact moduleWithArtifact = new ModuleWithArtifact(module, version);
synchronized (RUN_LOCK) {
// this initialises the metamodel, even if we don't use the resulting ClassLoader
URLClassLoader classLoader;
try {
classLoader = getClassLoader("runtime model loader tests", moduleWithArtifact);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
try {
RuntimeModuleManager moduleManager = Metamodel.getModuleManager();
RuntimeModelLoader modelLoader = moduleManager.getModelLoader();
Modules modules = moduleManager.getModules();
// now see if we can find our declarations
compareDeclarations(modelCompare, decls, modelLoader, modules);
} finally {
try {
classLoader.close();
} catch (IOException e) {
// ignore
e.printStackTrace();
}
}
}
}
use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits in project ceylon by eclipse.
the class JsModuleSourceMapper method createPhasedUnits.
@Override
protected PhasedUnits createPhasedUnits() {
PhasedUnits units = super.createPhasedUnits();
String fileEncoding = encoding;
if (fileEncoding == null) {
fileEncoding = CeylonConfig.get(DefaultToolOptions.DEFAULTS_ENCODING);
}
if (fileEncoding != null) {
units.setEncoding(fileEncoding);
}
return units;
}
use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits in project ceylon by eclipse.
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;
}
}
}
if (updateDistribution) {
updatedModuleVersions.put("ceylon.bootstrap", newVersion);
updatedModuleVersions.put("ceylon.language", newVersion);
updatedModuleVersions.put("ceylon.runtime", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.compiler.java", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.compiler.js", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.typechecker", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.common", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.cli", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.model", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.module-loader", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.module-resolver", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.module-resolver-aether", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.module-resolver-webdav", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.module-resolver-javascript", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.langtools.classfile", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.tool.provider", newVersion);
updatedModuleVersions.put("org.eclipse.ceylon.tools", newVersion);
}
// now do dependencies because we know which modules we did update
if (newVersion != null && !noUpdateDependencies) {
for (Module module : moduleList) {
if (!updateModuleImports(module, updatedModuleVersions)) {
return;
}
}
}
}
Aggregations