use of org.eclipse.ceylon.model.typechecker.model.ModuleImport in project ceylon by eclipse.
the class ModuleVisitor method visit.
@Override
public void visit(Tree.ImportModule that) {
super.visit(that);
String version = getVersionString(that.getVersion(), that.getConstantVersion(), that);
if (that.getVersion() == null && version != null) {
that.setVersion(new Tree.QuotedLiteral(new CommonToken(STRING_LITERAL, "\"" + version + "\"")));
}
List<String> name;
Node node;
Tree.ImportPath importPath = that.getImportPath();
Tree.QuotedLiteral quotedLiteral = that.getQuotedLiteral();
if (importPath != null) {
name = getNameAsList(importPath);
node = importPath;
} else if (quotedLiteral != null) {
String nameString = getNameString(quotedLiteral);
name = asList(nameString.split("\\."));
node = quotedLiteral;
} else {
name = Collections.emptyList();
node = null;
}
if (node != null) {
Tree.QuotedLiteral artifact = that.getArtifact();
if (artifact != null) {
name = new ArrayList<String>(name);
String nameString = getNameString(artifact);
name.add("");
name.addAll(asList(nameString.split("\\.")));
}
Tree.QuotedLiteral classifier = that.getClassifier();
if (classifier != null) {
String nameString = getNameString(classifier);
name.add("");
name.addAll(asList(nameString.split("\\.")));
}
}
if (phase == Phase.SRC_MODULE) {
String path = formatPath(name);
that.setName(path);
} else if (phase == Phase.REMAINING) {
// set in previous phase
String path = that.getName();
Tree.Identifier ns = that.getNamespace();
String namespace = ns != null ? ns.getText() : null;
boolean hasMavenName = isMavenModule(path);
boolean forCeylon = (importPath != null && namespace == null) || (importPath == null && namespace == null && !hasMavenName) || DefaultRepository.NAMESPACE.equals(namespace);
if (name.isEmpty()) {
that.addError("missing module name");
} else if (name.get(0).equals(DEFAULT_MODULE_NAME)) {
if (forCeylon) {
node.addError("reserved module name: 'default'");
}
} else if (name.size() == 1 && name.get(0).equals("ceylon")) {
if (forCeylon) {
node.addError("reserved module name: 'ceylon'");
}
} else if (name.size() > 1 && name.get(0).equals("ceylon") && name.get(1).equals("language")) {
if (forCeylon) {
node.addError("the language module is imported implicitly");
}
} else {
if (namespace == null && hasMavenName) {
namespace = MavenRepository.NAMESPACE;
node.addUsageWarning(Warning.missingImportPrefix, "use of old style Maven imports is deprecated, prefix with 'maven:'");
}
Tree.AnnotationList al = that.getAnnotationList();
Unit u = unit.getUnit();
Backends bs = getNativeBackend(al, u);
if (!bs.none()) {
for (Backend b : bs) {
if (!b.isRegistered()) {
node.addError("illegal native backend name: '\"" + b.nativeAnnotation + "\"' (must be either '\"jvm\"' or '\"js\"')");
}
}
if (!moduleBackends.none() && !moduleBackends.supports(bs)) {
node.addError("native backend name on import conflicts with module descriptor: '\"" + bs.names() + "\"' is not in '\"" + moduleBackends.names() + "\"'");
}
}
Module importedModule = moduleManager.getOrCreateModule(name, version);
if (importPath != null) {
importPath.setModel(importedModule);
}
if (!completeOnlyAST && mainModule != null) {
if (importedModule.getVersion() == null) {
importedModule.setVersion(version);
}
ModuleImport moduleImport = moduleManager.findImport(mainModule, importedModule);
if (moduleImport == null) {
boolean optional = hasAnnotation(al, "optional", u);
boolean export = hasAnnotation(al, "shared", u);
moduleImport = new ModuleImport(namespace, importedModule, optional, export, bs);
moduleImport.getAnnotations().clear();
buildAnnotations(al, moduleImport.getAnnotations());
mainModule.addImport(moduleImport);
}
moduleManagerUtil.addModuleDependencyDefinition(moduleImport, that);
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.ModuleImport in project ceylon by eclipse.
the class ModuleSourceMapper method overrideModuleImports.
protected void overrideModuleImports(Module module, ArtifactResult artifact) {
Overrides overrides = getContext().getRepositoryManager().getOverrides();
if (overrides != null) {
Set<ModuleDependencyInfo> existingModuleDependencies = new HashSet<>();
for (ModuleImport i : module.getImports()) {
Module m = i.getModule();
if (m != null) {
existingModuleDependencies.add(new ModuleDependencyInfo(i.getNamespace(), m.getNameAsString(), m.getVersion(), i.isOptional(), i.isExport(), i.getNativeBackends()));
}
}
ModuleInfo sourceModuleInfo = new ModuleInfo(artifact.namespace(), artifact.name(), artifact.version(), artifact.groupId(), artifact.artifactId(), artifact.classifier(), null, existingModuleDependencies);
ModuleInfo newModuleInfo = overrides.applyOverrides(artifact.name(), artifact.version(), sourceModuleInfo);
List<ModuleImport> newModuleImports = new ArrayList<>();
for (ModuleDependencyInfo dep : newModuleInfo.getDependencies()) {
Module dependency = getModuleManager().getOrCreateModule(ModuleManager.splitModuleName(dep.getName()), dep.getVersion());
Backends backends = dependency.getNativeBackends();
ModuleImport newImport = new ModuleImport(dep.getNamespace(), dependency, dep.isOptional(), dep.isExport(), backends);
newModuleImports.add(newImport);
}
module.overrideImports(newModuleImports);
}
}
use of org.eclipse.ceylon.model.typechecker.model.ModuleImport in project ceylon by eclipse.
the class VisibilityVisitor method isVisibleFromOtherModules.
private static boolean isVisibleFromOtherModules(Declaration member, Module thisModule, TypeDeclaration type, List<Module> modules) {
// type parameters are OK
if (type instanceof TypeParameter) {
return true;
}
Module typeModule = getModule(type);
if (typeModule != null && thisModule != null && !thisModule.equals(typeModule)) {
// language module stuff is implicitly exported
if (typeModule.isLanguageModule()) {
return true;
}
// try to find a direct import first
for (ModuleImport imp : thisModule.getImports()) {
if (imp.isExport() && imp.getModule().equals(typeModule)) {
// found it
return true;
}
}
// then try the more expensive implicit imports
Set<Module> visited = new HashSet<Module>();
visited.add(thisModule);
for (ModuleImport imp : thisModule.getImports()) {
// now try implicit dependencies
if (imp.isExport() && includedImplicitly(imp.getModule(), typeModule, visited)) {
// found it
return true;
}
}
modules.add(typeModule);
// couldn't find it
return false;
}
// more likely an error was already reported
return true;
}
use of org.eclipse.ceylon.model.typechecker.model.ModuleImport in project ceylon by eclipse.
the class JsonModule method getPackage.
@Override
public Package getPackage(String name) {
if ("default".equals(name)) {
name = "";
}
// search direct packages
Package p = getDirectPackage(name);
if (p != null) {
return p;
}
// search imported modules
HashSet<Module> visited = new HashSet<Module>();
visited.add(this);
for (ModuleImport imp : getImports()) {
p = getPackageFromImport(name, imp.getModule(), visited);
if (p != null) {
return p;
}
}
// not found
return null;
}
use of org.eclipse.ceylon.model.typechecker.model.ModuleImport in project ceylon by eclipse.
the class MavenPomUtil method writePomXml.
private static void writePomXml(File outputFolder, String groupId, String artifactId, Module module, JdkProvider jdkProvider) {
try (OutputStream os = new FileOutputStream(new File(outputFolder, "pom.xml"))) {
XMLStreamWriter out = XMLOutputFactory.newInstance().createXMLStreamWriter(new OutputStreamWriter(os, "utf-8"));
out.writeStartDocument();
out.writeCharacters("\n");
// FIXME: what to do with the default module?
out.writeStartElement("project");
out.writeAttribute("xmlns", "http://maven.apache.org/POM/4.0.0");
out.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
out.writeAttribute("xsi:schemaLocation", "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd");
out.writeCharacters("\n ");
out.writeStartElement("modelVersion");
out.writeCharacters("4.0.0");
out.writeEndElement();
out.writeCharacters("\n ");
out.writeStartElement("groupId");
out.writeCharacters(groupId);
out.writeEndElement();
out.writeCharacters("\n ");
out.writeStartElement("artifactId");
out.writeCharacters(artifactId);
out.writeEndElement();
out.writeCharacters("\n ");
out.writeStartElement("version");
out.writeCharacters(module.getVersion());
out.writeEndElement();
out.writeCharacters("\n ");
out.writeStartElement("name");
out.writeCharacters(module.getNameAsString());
out.writeEndElement();
List<ModuleImport> imports = module.getImports();
if (!imports.isEmpty()) {
out.writeCharacters("\n ");
out.writeStartElement("dependencies");
for (ModuleImport dep : imports) {
if (!ModelUtil.isForBackend(dep.getNativeBackends(), Backend.Java)) {
continue;
}
Module moduleDependency = dep.getModule();
final String dependencyName = moduleDependency.getNameAsString();
// skip c.l and jdk
if (dependencyName.equals(Module.LANGUAGE_MODULE_NAME) || jdkProvider.isJDKModule(dependencyName))
continue;
String depGroupId;
String depArtifactId;
String depClassifier;
if (moduleDependency.getGroupId() != null) {
depGroupId = moduleDependency.getGroupId();
depArtifactId = artifactId(moduleDependency);
depClassifier = moduleDependency.getClassifier();
} else {
String[] mavenCoordinates = ModuleUtil.getMavenCoordinates(dependencyName);
depGroupId = mavenCoordinates[0];
depArtifactId = mavenCoordinates[1];
depClassifier = mavenCoordinates[2];
}
out.writeCharacters("\n ");
out.writeStartElement("dependency");
out.writeCharacters("\n ");
out.writeStartElement("groupId");
out.writeCharacters(depGroupId);
out.writeEndElement();
out.writeCharacters("\n ");
out.writeStartElement("artifactId");
out.writeCharacters(depArtifactId);
out.writeEndElement();
if (depClassifier != null) {
out.writeCharacters("\n ");
out.writeStartElement("classifier");
out.writeCharacters(depClassifier);
out.writeEndElement();
}
out.writeCharacters("\n ");
out.writeStartElement("version");
out.writeCharacters(moduleDependency.getVersion());
out.writeEndElement();
if (dep.isOptional()) {
out.writeCharacters("\n ");
out.writeStartElement("optional");
out.writeCharacters("true");
out.writeEndElement();
}
out.writeCharacters("\n ");
out.writeEndElement();
}
out.writeCharacters("\n ");
out.writeEndElement();
}
out.writeCharacters("\n");
out.writeEndElement();
out.writeEndDocument();
out.flush();
} catch (IOException | XMLStreamException e) {
throw new RuntimeException(e);
}
}
Aggregations