use of org.eclipse.ceylon.model.typechecker.model.ImportScope in project ceylon by eclipse.
the class ImportVisitor method checkForHiddenToplevel.
private boolean checkForHiddenToplevel(Tree.Identifier id, Import i, Tree.Alias alias, ImportList il) {
ImportScope scope = getImportScope(il);
for (Declaration d : scope.getMembers()) {
String n = d.getName();
Declaration idec = i.getDeclaration();
if (n != null && i.getAlias().equals(n) && !idec.equals(d) && // alias:
!isLegalAliasFreeImport(d, idec)) {
String qn = d.getQualifiedNameString();
String message = scope instanceof Unit ? "toplevel declaration with this name declared in this unit" : "declaration with this name declared in this scope";
if (alias == null) {
String iqn = idec.getQualifiedNameString();
id.addError(message + ": imported '" + iqn + "' would hide '" + qn + "' (add an alias to the import)");
} else {
alias.addError(message + ": imported '" + n + "' would hide '" + qn + "' (choose a different alias for the import)");
}
return true;
}
}
return false;
}
use of org.eclipse.ceylon.model.typechecker.model.ImportScope in project ceylon by eclipse.
the class ImportVisitor method addWildcardImport.
private void addWildcardImport(ImportList il, Declaration dec, Import i) {
if (notOverloaded(dec)) {
String alias = i.getAlias();
if (alias != null) {
ImportScope scope = getImportScope(il);
Import o = scope.getImport(dec.getName());
if (o != null && o.isWildcardImport()) {
if (o.getDeclaration().equals(dec) || dec.isNativeHeader()) {
// this case only happens in the IDE,
// due to reuse of the Unit
scope.removeImport(o);
il.getImports().remove(o);
} else if (!dec.isNative()) {
i.setAmbiguous(true);
o.setAmbiguous(true);
}
}
scope.addImport(i);
il.getImports().add(i);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.ImportScope in project ceylon by eclipse.
the class ImportVisitor method addImport.
private void addImport(Tree.ImportMemberOrType member, ImportList il, Import i) {
String alias = i.getAlias();
if (alias != null) {
Map<String, String> mods = unit.getModifiers();
if (mods.containsKey(alias) && mods.get(alias).equals(alias)) {
// spec says you can't hide a language modifier
// unless the modifier itself has an alias
// (this is perhaps a little heavy-handed)
// instead, it should be a warning
member.addUsageWarning(Warning.hidesLanguageModifier, "import hides a language modifier: '" + alias + "' is a language modifier");
} else {
ImportScope scope = getImportScope(il);
Import o = scope.getImport(alias);
if (o == null) {
scope.addImport(i);
il.getImports().add(i);
} else if (o.isWildcardImport()) {
scope.removeImport(o);
il.getImports().remove(o);
scope.addImport(i);
il.getImports().add(i);
} else {
member.addError("duplicate import alias: '" + alias + "' is already used");
}
}
}
}
Aggregations