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) member.addError("import hides a language modifier: '" + alias + "'"); } else { Import o = unit.getImport(alias); if (o == null) { unit.getImports().add(i); il.getImports().add(i); } else if (o.isWildcardImport()) { unit.getImports().remove(o); il.getImports().remove(o); unit.getImports().add(i); il.getImports().add(i); } else { member.addError("duplicate import alias: '" + alias + "'"); } } } }
private void addMemberImport(Tree.ImportMemberOrType member, ImportList il, Import i) { String alias = i.getAlias(); if (alias != null) { if (il.getImport(alias) == null) { unit.getImports().add(i); il.getImports().add(i); } else { member.addError("duplicate member import alias: '" + alias + "'"); } } }
private void addWildcardImport(ImportList il, Declaration dec, Import i) { if (notOverloaded(dec)) { String alias = i.getAlias(); if (alias != null) { Import o = unit.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 unit.getImports().remove(o); il.getImports().remove(o); } else if (!dec.isNative()) { i.setAmbiguous(true); o.setAmbiguous(true); } } unit.getImports().add(i); il.getImports().add(i); } } }
private boolean checkForHiddenToplevel(Tree.Identifier id, Import i, Tree.Alias alias) { for (Declaration d : unit.getDeclarations()) { String n = d.getName(); Declaration idec = i.getDeclaration(); if (d.isToplevel() && n != null && i.getAlias().equals(n) && !idec.equals(d) && // it is legal to import an object declaration // in the current package without providing an // alias: !isLegalAliasFreeImport(d, idec)) { if (alias == null) { id.addError("toplevel declaration with this name declared in this unit: '" + n + "'"); } else { alias.addError("toplevel declaration with this name declared in this unit: '" + n + "'"); } return true; } } return false; }