Ejemplo n.º 1
0
  public static Object getPackageOrDeclaration(IProject project, String qualifiedName) {
    Object result = null;

    String pkgName = null;
    int pkgSepIndex = qualifiedName.indexOf("::");
    if (pkgSepIndex == -1) {
      pkgName = qualifiedName;
    } else {
      pkgName = qualifiedName.substring(0, pkgSepIndex);
    }

    Package pkg = getPackage(project, pkgName);
    if (pkg != null && pkgSepIndex != -1) {
      Declaration d;
      int memberSepIndex = qualifiedName.indexOf(".", pkgSepIndex);
      if (memberSepIndex != -1) {
        String baseName = qualifiedName.substring(pkgSepIndex + 2, memberSepIndex);
        String methodName = qualifiedName.substring(memberSepIndex + 1);
        d = pkg.getMember(baseName, null, false);
        d = extractAnonymousClassIfRequired(d);
        if (d != null) {
          Declaration m = d.getMember(methodName, null, false);
          if (m instanceof Function && d instanceof Class) {
            result = new MethodWithContainer((Class) d, (Function) m);
          }
        }
      } else {
        String baseName = qualifiedName.substring(pkgSepIndex + 2);
        d = pkg.getMember(baseName, null, false);
        result = extractAnonymousClassIfRequired(d);
      }
    } else {
      result = pkg;
    }

    return result;
  }
Ejemplo n.º 2
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;
 }