use of org.eclipse.ceylon.model.typechecker.model.Module in project ceylon by eclipse.
the class LanguageCompiler method loadModuleFromSource.
private Module loadModuleFromSource(String pkgName, LinkedList<JCCompilationUnit> moduleTrees, List<JCCompilationUnit> parsedTrees) {
if (pkgName.isEmpty())
return null;
String moduleClassName = pkgName + ".module";
JavaFileObject fileObject;
try {
if (options.get(Option.VERBOSE) != null) {
log.printRawLines(WriterKind.NOTICE, "[Trying to load source for module " + moduleClassName + "]");
}
fileObject = fileManager.getJavaFileForInput(StandardLocation.SOURCE_PATH, moduleClassName, Kind.SOURCE);
if (options.get(Option.VERBOSE) != null) {
log.printRawLines(WriterKind.NOTICE, "[Got file object: " + fileObject + "]");
}
} catch (IOException e) {
e.printStackTrace();
return loadModuleFromSource(getParentPackage(pkgName), moduleTrees, parsedTrees);
}
if (fileObject != null) {
// we really want to compile.
for (JCCompilationUnit parsedTree : parsedTrees) {
if (parsedTree.sourcefile.equals(fileObject) && parsedTree instanceof CeylonCompilationUnit) {
// same file! we already parsed it, let's return this one's module
PhasedUnit phasedUnit = ((CeylonCompilationUnit) parsedTree).phasedUnit;
// the module visitor does load the module but does not set the unit's package module
if (phasedUnit.getPackage().getModule() == null) {
// so find the module it created
for (Module mod : ceylonContext.getModules().getListOfModules()) {
// we recognise it with the unit
if (mod.getUnit() == phasedUnit.getUnit()) {
// set the package's module
Package pkg = phasedUnit.getPackage();
pkg.setModule(mod);
mod.getPackages().add(pkg);
modulesLoadedFromSource.add(mod);
break;
}
}
}
// now return it
return phasedUnit.getPackage().getModule();
}
}
JCCompilationUnit javaCompilationUnit = parse(fileObject);
Module module;
if (javaCompilationUnit instanceof CeylonCompilationUnit) {
CeylonCompilationUnit ceylonCompilationUnit = (CeylonCompilationUnit) javaCompilationUnit;
moduleTrees.add(ceylonCompilationUnit);
// parse the module info from there
module = ceylonCompilationUnit.phasedUnit.visitSrcModulePhase();
ceylonCompilationUnit.phasedUnit.visitRemainingModulePhase();
// now set the module
if (module != null) {
ceylonCompilationUnit.phasedUnit.getPackage().setModule(module);
}
} else {
// there was a syntax error in the module descriptor, make a pretend module so that we can
// correctly mark all declarations as part of that module, but we won't generate any code
// for it
ModuleManager moduleManager = phasedUnits.getModuleManager();
module = moduleManager.getOrCreateModule(Arrays.asList(pkgName.split("\\.")), "bogus");
}
// now remember it
if (module != null) {
modulesLoadedFromSource.add(module);
return module;
}
}
return loadModuleFromSource(getParentPackage(pkgName), moduleTrees, parsedTrees);
}
use of org.eclipse.ceylon.model.typechecker.model.Module in project ceylon by eclipse.
the class CeyloncCompilerDelegate method loadStandardModules.
@Override
public void loadStandardModules(AbstractModelLoader modelLoader) {
org.eclipse.ceylon.compiler.typechecker.context.Context ceylonContext = LanguageCompiler.getCeylonContextInstance(context);
Module languageModule = ceylonContext.getModules().getLanguageModule();
if (languageModule.getVersion() == null) {
languageModule.setVersion(TypeChecker.LANGUAGE_MODULE_VERSION);
}
modelLoader.loadStandardModules();
}
use of org.eclipse.ceylon.model.typechecker.model.Module in project ceylon by eclipse.
the class LazyModuleSourceMapper method preResolveDependenciesIfRequired.
@Override
public void preResolveDependenciesIfRequired(RepositoryManager repositoryManager) {
AbstractModelLoader modelLoader = getModuleManager().getModelLoader();
if (!modelLoader.isFullyExportMavenDependencies())
return;
if (statusPrinter != null) {
statusPrinter.clearLine();
statusPrinter.log("Pre-resolving dependencies");
}
if (verbose) {
log.printRawLines(WriterKind.NOTICE, "[Pre-resolving dependencies]");
}
Set<Module> compiledModules = getCompiledModules();
Map<String, String> modules = new HashMap<>();
ModuleImport anyImport = null;
for (Module module : compiledModules) {
for (ModuleImport imp : module.getImports()) {
if (imp.getModule() == null || !compiledModules.contains(imp.getModule())) {
if (anyImport == null)
anyImport = imp;
String name = imp.getModule().getNameAsString();
if (imp.getNamespace() != null)
name = imp.getNamespace() + ":" + name;
modules.put(name, imp.getModule().getVersion());
}
}
}
if (statusPrinter != null) {
statusPrinter.clearLine();
statusPrinter.log("Pre-resolving found " + modules.size() + " to pre-resolve");
}
if (verbose) {
log.printRawLines(WriterKind.NOTICE, "[Pre-resolving " + modules.size() + " modules]");
}
if (modules.isEmpty())
return;
Entry<String, String> first = modules.entrySet().iterator().next();
CompilerModuleLoader ml = new CompilerModuleLoader(repositoryManager, null, modules, verbose, statusPrinter, log);
boolean giveup = false;
try {
ml.loadModule(first.getKey(), first.getValue(), ModuleScope.COMPILE);
} catch (ModuleNotFoundException e) {
attachErrorToDependencyDeclaration(anyImport, "Pre-resolving of module failed: " + e.getMessage(), true);
giveup = true;
}
if (statusPrinter != null) {
statusPrinter.clearLine();
// don't try to read the module count if pre-resolving failed
if (giveup)
statusPrinter.log("Pre-resolving failed");
else
statusPrinter.log("Pre-resolving resolved " + ml.getModuleCount());
}
if (verbose) {
// don't try to read the module count if pre-resolving failed
if (giveup)
log.printRawLines(WriterKind.NOTICE, "[Pre-resolved failed]");
else
log.printRawLines(WriterKind.NOTICE, "[Pre-resolved " + ml.getModuleCount() + " modules]");
}
if (giveup)
return;
Overrides overrides = repositoryManager.getOverrides();
if (overrides == null) {
overrides = Overrides.create();
repositoryManager.setOverrides(overrides);
}
ml.setupOverrides(overrides);
ml.cleanup();
}
use of org.eclipse.ceylon.model.typechecker.model.Module in project ceylon by eclipse.
the class LazyModuleSourceMapper method addModuleDependencyDefinition.
@Override
public void addModuleDependencyDefinition(ModuleImport moduleImport, Node definition) {
super.addModuleDependencyDefinition(moduleImport, definition);
Module module = moduleImport.getModule();
if (module == null)
return;
String nameAsString = module.getNameAsString();
String version = module.getVersion();
if (version != null && (JDKUtils.isJDKModule(nameAsString) || JDKUtils.isOracleJDKModule(nameAsString))) {
// FIXME: this does not work for JDK9 or Android
if (JDKUtils.jdk.isLowerVersion(version)) {
definition.addUsageWarning(Warning.importsOtherJdk, "You import JDK7, which is provided by the JDK8 you are running on, but" + " we cannot check that you are not using any JDK8-specific classes or methods. Upgrade your import to JDK8 if you depend on" + " JDK8 classes or methods.", Backend.Java);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Module in project ceylon by eclipse.
the class CeylonDocToolTests method bug2346.
@Test
public void bug2346() throws Exception {
String pathname = "test/ceylondoc";
String moduleName = "org.eclipse.ceylon.ceylondoc.test.modules.bug2346";
Module module = new Module();
module.setName(Arrays.asList(moduleName));
module.setVersion("1");
CeylonDocTool tool = tool(Arrays.asList(new File(pathname)), Arrays.asList(new File("doc")), Arrays.asList(moduleName), true, false, false);
tool.run();
}
Aggregations