Пример #1
0
  @Override
  public void visit(Tree.ClassBody that) {
    if (that.getScope() == declaration.getContainer()) {
      Tree.Statement les = getLastExecutableStatement(that);
      Tree.Declaration lc = getLastConstructor(that);
      declarationSection = les == null;
      lastExecutableStatement = les;
      lastConstructor = lc;
      super.visit(that);
      declarationSection = false;
      lastExecutableStatement = null;
      lastConstructor = null;

      if (!declaration.isAnonymous()) {
        if (isSharedDeclarationUninitialized()) {
          getDeclaration(that)
              .addError(
                  "must be definitely specified by class initializer: "
                      + message(declaration)
                      + " is shared",
                  1401);
        }
      }
    } else {
      super.visit(that);
    }
  }
Пример #2
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;
 }