use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit in project ceylon by eclipse.
the class JsCompiler method getStitchedFile.
VirtualFile getStitchedFile(final Declaration d, final String suffix) {
String fqn = d.getQualifiedNameString();
String name = d.getName();
if (name == null && d instanceof Constructor) {
name = "default$constructor";
if (fqn.endsWith(".null")) {
fqn = fqn.substring(0, fqn.length() - 4);
}
fqn = fqn + name;
}
if (fqn.startsWith("ceylon.language")) {
fqn = fqn.substring(15);
}
if (fqn.startsWith("::")) {
fqn = fqn.substring(2);
}
fqn = fqn.replace('.', '/').replace("::", "/");
File path;
if (isCompilingLanguageModule()) {
path = new File(Stitcher.LANGMOD_JS_SRC, fqn + suffix);
} else {
PhasedUnit pu = tc.getPhasedUnitFromRelativePath(d.getUnit().getRelativePath());
path = new File(getFullPath(pu).getParentFile(), name + suffix);
}
return findFile(path);
}
use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit in project ceylon by eclipse.
the class TestModelClasses method initTests.
@SuppressWarnings("unchecked")
@BeforeClass
public static void initTests() {
TestModelMethodsAndAttributes.initTypechecker();
MetamodelVisitor mmg = null;
for (PhasedUnit pu : TestModelMethodsAndAttributes.tc.getPhasedUnits().getPhasedUnits()) {
if (pu.getPackage().getModule().getNameAsString().equals("t2")) {
if (mmg == null) {
mmg = new MetamodelVisitor(pu.getPackage().getModule());
}
pu.getCompilationUnit().visit(mmg);
}
}
topLevelModel = mmg.getModel();
model = (Map<String, Object>) topLevelModel.get("t2");
}
use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit in project ceylon by eclipse.
the class TestModelMethodsAndAttributes method initModel.
@SuppressWarnings("unchecked")
@BeforeClass
public static void initModel() {
initTypechecker();
MetamodelVisitor mmg = null;
for (PhasedUnit pu : tc.getPhasedUnits().getPhasedUnits()) {
if (pu.getPackage().getModule().getNameAsString().equals("t1")) {
if (mmg == null) {
mmg = new MetamodelVisitor(pu.getPackage().getModule());
}
pu.getCompilationUnit().visit(mmg);
}
}
topLevelModel = mmg.getModel();
model = (Map<String, Object>) topLevelModel.get("t1");
}
use of org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit 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.PhasedUnit in project ceylon by eclipse.
the class LanguageCompiler method loadCompiledModules.
private List<JCCompilationUnit> loadCompiledModules(List<JCCompilationUnit> trees, LinkedList<JCCompilationUnit> moduleTrees) {
compilerDelegate.visitModules(phasedUnits);
Modules modules = ceylonContext.getModules();
// now make sure the phase units have their modules and packages set correctly
for (PhasedUnit pu : phasedUnits.getPhasedUnits()) {
Package pkg = pu.getPackage();
loadModuleFromSource(pkg, modules, moduleTrees, trees);
}
// also make sure we have packages and modules set up for every Java file we compile
for (JCCompilationUnit cu : trees) {
// skip Ceylon CUs
if (cu instanceof CeylonCompilationUnit)
continue;
String packageName = "";
if (cu.pid != null)
packageName = TreeInfo.fullName(cu.pid).toString();
/*
* Stef: see javadoc for findOrCreateModulelessPackage() for why this is here.
*/
Package pkg = modelLoader.findOrCreateModulelessPackage(packageName);
loadModuleFromSource(pkg, modules, moduleTrees, trees);
}
for (PhasedUnit phasedUnit : phasedUnits.getPhasedUnits()) {
if (!phasedUnit.getCompilationUnit().getModuleDescriptors().isEmpty()) {
String name = phasedUnit.getPackage().getNameAsString();
CeylonPhasedUnit cpu = (CeylonPhasedUnit) phasedUnit;
CeylonFileObject cfo = (CeylonFileObject) cpu.getFileObject();
moduleNamesToFileObjects.put(name, cfo);
}
}
if (addModuleTrees) {
for (JCCompilationUnit moduleTree : moduleTrees) {
trees = trees.append(moduleTree);
}
}
return trees;
}
Aggregations