use of org.eclipse.ceylon.model.typechecker.model.ModuleImport in project ceylon by eclipse.
the class CeylonDoc method getIcons.
protected final List<String> getIcons(Object obj) {
List<String> icons = new ArrayList<String>();
if (obj instanceof Declaration) {
Declaration decl = (Declaration) obj;
Annotation deprecated = Util.findAnnotation(decl, "deprecated");
if (deprecated != null) {
icons.add("icon-decoration-deprecated");
}
if (decl instanceof ClassOrInterface || decl instanceof Constructor) {
if (decl instanceof Interface) {
icons.add("icon-interface");
if (Util.isEnumerated((ClassOrInterface) decl)) {
icons.add("icon-decoration-enumerated");
}
}
if (decl instanceof Class) {
Class klass = (Class) decl;
if (klass.isAnonymous()) {
icons.add("icon-object");
} else {
icons.add("icon-class");
}
if (klass.isAbstract()) {
icons.add("icon-decoration-abstract");
}
if (klass.isFinal() && !klass.isAnonymous() && !klass.isAnnotation()) {
icons.add("icon-decoration-final");
}
if (Util.isEnumerated(klass)) {
icons.add("icon-decoration-enumerated");
}
}
if (decl instanceof Constructor) {
icons.add("icon-class");
}
if (!decl.isShared()) {
icons.add("icon-decoration-local");
}
}
if (decl instanceof TypedDeclaration) {
if (decl.isShared()) {
icons.add("icon-shared-member");
} else {
icons.add("icon-local-member");
}
if (decl.isFormal()) {
icons.add("icon-decoration-formal");
}
if (decl.isActual()) {
Declaration refinedDeclaration = decl.getRefinedDeclaration();
if (refinedDeclaration != null) {
if (refinedDeclaration.isFormal()) {
icons.add("icon-decoration-impl");
}
if (refinedDeclaration.isDefault()) {
icons.add("icon-decoration-over");
}
}
}
if (((TypedDeclaration) decl).isVariable()) {
icons.add("icon-decoration-variable");
}
}
if (decl instanceof TypeAlias || decl instanceof NothingType) {
icons.add("icon-type-alias");
}
if (decl.isAnnotation()) {
icons.add("icon-decoration-annotation");
}
}
if (obj instanceof Package) {
Package pkg = (Package) obj;
icons.add("icon-package");
if (!pkg.isShared()) {
icons.add("icon-decoration-local");
}
}
if (obj instanceof ModuleImport) {
ModuleImport moduleImport = (ModuleImport) obj;
icons.add("icon-module");
if (moduleImport.isExport()) {
icons.add("icon-module-exported-decoration");
}
if (moduleImport.isOptional()) {
icons.add("icon-module-optional-decoration");
}
}
if (obj instanceof Module) {
icons.add("icon-module");
}
return icons;
}
use of org.eclipse.ceylon.model.typechecker.model.ModuleImport in project ceylon by eclipse.
the class AnalyzerUtil method importedPackage.
static Package importedPackage(Tree.ImportPath path, Unit unit) {
if (path != null && !path.getIdentifiers().isEmpty()) {
String nameToImport = formatPath(path.getIdentifiers());
Module module = path.getUnit().getPackage().getModule();
Package pkg = module.getPackage(nameToImport);
if (pkg != null) {
Module pkgMod = pkg.getModule();
if (pkgMod.equals(module)) {
return pkg;
}
if (!pkg.isShared()) {
path.addError("imported package is not visible: package '" + nameToImport + "' is not shared by module '" + pkgMod.getNameAsString() + "'", 402);
} else if (!pkg.withinRestrictions(unit)) {
path.addError("imported package is not visible: package '" + nameToImport + "' is restricted by module '" + pkgMod.getNameAsString() + "'");
}
// if (module.isDefault() &&
// !pkg.getModule().isDefault() &&
// !pkg.getModule().getNameAsString()
// .equals(Module.LANGUAGE_MODULE_NAME)) {
// path.addError("package belongs to a module and may not be imported by default module: " +
// nameToImport);
// }
// check that the package really does belong to
// an imported module, to work around bug where
// default package thinks it can see stuff in
// all modules in the same source dir
Set<Module> visited = new HashSet<Module>();
for (ModuleImport mi : module.getImports()) {
if (findModuleInTransitiveImports(mi.getModule(), pkgMod, visited)) {
return pkg;
}
}
} else {
for (ModuleImport mi : module.getImports()) {
if (mi.isNative()) {
String name = mi.getModule().getNameAsString();
Backends backends = path.getUnit().getSupportedBackends();
if (!isForBackend(mi.getNativeBackends(), backends) && (nameToImport.equals(name) || nameToImport.startsWith(name + "."))) {
return null;
}
if (!isForBackend(Backend.Java.asSet(), backends) && unit.isJdkPackage(nameToImport)) {
return null;
}
}
}
}
String help = module.isDefaultModule() ? " (define a module and add module import to its module descriptor)" : " (add module import to module descriptor of '" + module.getNameAsString() + "')";
path.addError("package not found in imported modules: '" + nameToImport + "'" + help, 7000);
}
return null;
}
use of org.eclipse.ceylon.model.typechecker.model.ModuleImport in project ceylon by eclipse.
the class AnalyzerUtil method importedModule.
static Module importedModule(Tree.ImportPath path, boolean restriction) {
if (path != null && !path.getIdentifiers().isEmpty()) {
String nameToImport = formatPath(path.getIdentifiers());
Module module = path.getUnit().getPackage().getModule();
Package pkg = module.getPackage(nameToImport);
if (pkg != null) {
Module mod = pkg.getModule();
String moduleName = mod.getNameAsString();
if (!pkg.getNameAsString().equals(moduleName)) {
path.addError("not a module: '" + nameToImport + "' is a package belonging to '" + moduleName + "'");
return null;
}
if (mod.equals(module)) {
return mod;
}
// check that the package really does belong to
// an imported module, to work around bug where
// default package thinks it can see stuff in
// all modules in the same source dir
Set<Module> visited = new HashSet<Module>();
for (ModuleImport mi : module.getImports()) {
if (findModuleInTransitiveImports(mi.getModule(), mod, visited)) {
return mod;
}
}
}
if (!restriction) {
path.addError("module not found in imported modules: '" + nameToImport + "'", 7000);
}
}
return null;
}
use of org.eclipse.ceylon.model.typechecker.model.ModuleImport in project ceylon by eclipse.
the class NpmDescriptorGenerator method generateDescriptor.
public String generateDescriptor() throws IOException {
Map<String, Object> desc = new HashMap<>();
desc.put("name", name(mod));
desc.put("version", mod.getVersion());
for (Annotation ann : mod.getAnnotations()) {
List<String> args = ann.getPositionalArguments();
if ("doc".equals(ann.getName())) {
desc.put("description", args.get(0));
} else if ("license".equals(ann.getName())) {
desc.put("license", args.get(0));
} else if ("by".equals(ann.getName()) && !args.isEmpty()) {
desc.put("author", args.get(0));
desc.put("contributors", args);
}
}
if (!mod.getImports().isEmpty()) {
Map<String, String> deps = new HashMap<>(mod.getImports().size());
Map<String, String> opts = new HashMap<>(mod.getImports().size());
for (ModuleImport imp : mod.getImports()) {
if (imp.isOptional()) {
opts.put(name(imp.getModule()), imp.getModule().getVersion());
} else if (!imp.isNative() || imp.getNativeBackends().supports(Backend.JavaScript)) {
deps.put(name(imp.getModule()), imp.getModule().getVersion());
}
}
if (!deps.isEmpty()) {
desc.put("dependencies", deps);
}
if (!opts.isEmpty()) {
desc.put("optionalDependencies", opts);
}
}
List<String> files = new ArrayList<>((src ? 6 : 4) + (resources ? 1 : 0));
final String modName = mod.getNameAsString() + "-" + mod.getVersion();
files.add(modName + ArtifactContext.JS);
files.add(modName + ArtifactContext.JS + ArtifactContext.SHA1);
files.add(modName + ArtifactContext.JS_MODEL);
files.add(modName + ArtifactContext.JS_MODEL + ArtifactContext.SHA1);
if (src) {
files.add(modName + ArtifactContext.SRC);
files.add(modName + ArtifactContext.SRC + ArtifactContext.SHA1);
}
if (resources) {
files.add(ArtifactContext.RESOURCES);
}
desc.put("files", files);
desc.put("main", files.get(0));
StringWriter sw = new StringWriter();
JSONObject.writeJSON(desc, sw);
return sw.toString();
}
use of org.eclipse.ceylon.model.typechecker.model.ModuleImport in project ceylon by eclipse.
the class ModuleSourceMapper method attachErrorToDependencyDeclaration.
public void attachErrorToDependencyDeclaration(ModuleImport moduleImport, List<Module> dependencyTree, String error, boolean isError) {
if (!attachErrorToDependencyDeclaration(moduleImport, error, isError)) {
// the error to
if (dependencyTree.size() >= 2) {
Module rootModule = dependencyTree.get(0);
Module originalImportedModule = dependencyTree.get(1);
// find the original import
for (ModuleImport imp : rootModule.getImports()) {
if (imp.getModule() == originalImportedModule) {
// found it, try to attach the error
if (attachErrorToDependencyDeclaration(imp, error, isError)) {
// we're done
return;
} else {
// failed
break;
}
}
}
}
System.err.println("This might be a type checker bug, please report. \nExpecting to add missing dependency error on non present definition: " + error);
}
}
Aggregations