Ejemplo n.º 1
0
 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 + "'");
       }
     }
   }
 }
Ejemplo n.º 2
0
 private void addWildcardImport(ImportList il, Declaration dec) {
   if (!hidesToplevel(dec)) {
     Import i = new Import();
     i.setAlias(dec.getName());
     i.setDeclaration(dec);
     i.setWildcardImport(true);
     addWildcardImport(il, dec, i);
   }
 }
Ejemplo n.º 3
0
 private String importMember(
     Tree.ImportMemberOrType member, Package importedPackage, ImportList il) {
   Tree.Identifier id = member.getIdentifier();
   if (id == null) {
     return null;
   }
   Import i = new Import();
   member.setImportModel(i);
   Tree.Alias alias = member.getAlias();
   String name = name(id);
   if (alias == null) {
     i.setAlias(name);
   } else {
     i.setAlias(name(alias.getIdentifier()));
   }
   if (isNonimportable(importedPackage, name)) {
     id.addError("root type may not be imported");
     return name;
   }
   Declaration d = importedPackage.getMember(name, null, false);
   if (d == null) {
     String correction = correct(importedPackage, unit, name);
     String message = correction == null ? "" : " (did you mean '" + correction + "'?)";
     id.addError("imported declaration not found: '" + name + "'" + message, 100);
     unit.getUnresolvedReferences().add(id);
   } else {
     if (!declaredInPackage(d, unit)) {
       if (!d.isShared()) {
         id.addError("imported declaration is not shared: '" + name + "'", 400);
       } else if (d.isPackageVisibility()) {
         id.addError("imported package private declaration is not visible: '" + name + "'");
       } else if (d.isProtectedVisibility()) {
         id.addError("imported protected declaration is not visible: '" + name + "'");
       }
     }
     i.setDeclaration(d);
     member.setDeclarationModel(d);
     if (il.hasImport(d)) {
       id.addError("already imported: '" + name + "'");
     } else if (!checkForHiddenToplevel(id, i, alias)) {
       addImport(member, il, i);
     }
     checkAliasCase(alias, d);
   }
   if (d != null) {
     importMembers(member, d);
   }
   return name;
 }
Ejemplo n.º 4
0
 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 + "'");
     }
   }
 }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 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);
     }
   }
 }
Ejemplo n.º 7
0
 private String importMember(Tree.ImportMemberOrType member, TypeDeclaration td, ImportList il) {
   Tree.Identifier id = member.getIdentifier();
   if (id == null) {
     return null;
   }
   Import i = new Import();
   member.setImportModel(i);
   Tree.Alias alias = member.getAlias();
   String name = name(id);
   if (alias == null) {
     i.setAlias(name);
   } else {
     i.setAlias(name(alias.getIdentifier()));
   }
   Declaration m = td.getMember(name, null, false);
   if (m == null) {
     String correction = correct(td, null, unit, name);
     String message = correction == null ? "" : " (did you mean '" + correction + "'?)";
     id.addError(
         "imported declaration not found: '" + name + "' of '" + td.getName() + "'" + message,
         100);
     unit.getUnresolvedReferences().add(id);
   } else {
     List<Declaration> members = m.getContainer().getMembers();
     for (Declaration d : members) {
       String dn = d.getName();
       if (dn != null && dn.equals(name) && !d.sameKind(m) && !d.isAnonymous()) {
         // crazy interop cases like isOpen() + open()
         id.addError("ambiguous member declaration: '" + name + "' of '" + td.getName() + "'");
         return null;
       }
     }
     if (!m.isShared()) {
       id.addError(
           "imported declaration is not shared: '" + name + "' of '" + td.getName() + "'", 400);
     } else if (!declaredInPackage(m, unit)) {
       if (m.isPackageVisibility()) {
         id.addError(
             "imported package private declaration is not visible: '"
                 + name
                 + "' of '"
                 + td.getName()
                 + "'");
       } else if (m.isProtectedVisibility()) {
         id.addError(
             "imported protected declaration is not visible: '"
                 + name
                 + "' of '"
                 + td.getName()
                 + "'");
       }
     }
     i.setTypeDeclaration(td);
     if (!m.isStaticallyImportable()
         && !isToplevelClassConstructor(td, m)
         && !isToplevelAnonymousClass(m.getContainer())) {
       if (alias == null) {
         member.addError("does not specify an alias");
       }
     }
     i.setDeclaration(m);
     member.setDeclarationModel(m);
     if (il.hasImport(m)) {
       id.addError("already imported: '" + name + "' of '" + td.getName() + "'");
     } else {
       if (m.isStaticallyImportable()
           || isToplevelClassConstructor(td, m)
           || isToplevelAnonymousClass(m.getContainer())) {
         if (!checkForHiddenToplevel(id, i, alias)) {
           addImport(member, il, i);
         }
       } else {
         addMemberImport(member, il, i);
       }
     }
     checkAliasCase(alias, m);
   }
   if (m != null) {
     importMembers(member, m);
   }
   // imtl.addError("member aliases may not have member aliases");
   return name;
 }