Example #1
0
  public static Set<MethodSymbol> findSuperMethods(MethodSymbol methodSymbol, Types types) {
    Set<MethodSymbol> supers = new HashSet<>();
    if (methodSymbol.isStatic()) {
      return supers;
    }

    TypeSymbol owner = (TypeSymbol) methodSymbol.owner;
    // Iterates over an ordered list of all super classes and interfaces.
    for (Type sup : types.closure(owner.type)) {
      if (sup == owner.type) {
        continue; // Skip the owner of the method
      }
      Scope scope = sup.tsym.members();
      for (Symbol sym : scope.getSymbolsByName(methodSymbol.name)) {
        if (sym != null
            && !sym.isStatic()
            && ((sym.flags() & Flags.SYNTHETIC) == 0)
            && sym.name.contentEquals(methodSymbol.name)
            && methodSymbol.overrides(sym, owner, types, true)) {
          supers.add((MethodSymbol) sym);
        }
      }
    }
    return supers;
  }
Example #2
0
 /** Double size of hash table. */
 private void dble() {
   assert shared == 0;
   Entry[] oldtable = table;
   Entry[] newtable = new Entry[oldtable.length * 2];
   for (Scope s = this; s != null; s = s.next) {
     if (s.table == oldtable) {
       assert s == this || s.shared != 0;
       s.table = newtable;
       s.hashMask = newtable.length - 1;
     }
   }
   for (int i = 0; i < newtable.length; i++) newtable[i] = sentinel;
   for (int i = 0; i < oldtable.length; i++) copy(oldtable[i]);
 }
  public void printScope(String label, Scope scope, Details details) {
    if (scope == null) {
      printNull(label);
    } else {
      switch (details) {
        case SUMMARY:
          {
            indent();
            out.print(label);
            out.print(": [");
            String sep = "";
            for (Symbol sym : scope.getSymbols()) {
              out.print(sep);
              out.print(sym.name);
              sep = ",";
            }
            out.println("]");
            break;
          }

        case FULL:
          {
            indent();
            out.println(label);

            indent(+1);
            printFullScopeImpl(scope);
            indent(-1);
            break;
          }
      }
    }
  }
Example #4
0
 /** @return all values of the given enum type, in declaration order. */
 public static LinkedHashSet<String> enumValues(TypeSymbol enumType) {
   if (enumType.getKind() != ElementKind.ENUM) {
     throw new IllegalStateException();
   }
   Scope scope = enumType.members();
   Deque<String> values = new ArrayDeque<>();
   for (Symbol sym : scope.getSymbols()) {
     if (sym instanceof VarSymbol) {
       VarSymbol var = (VarSymbol) sym;
       if ((var.flags() & Flags.ENUM) != 0) {
         /**
          * Javac gives us the members backwards, apparently. It's worth making an effort to
          * preserve declaration order because it's useful for diagnostics (e.g. in {@link
          * MissingCasesInEnumSwitch}).
          */
         values.push(sym.name.toString());
       }
     }
   }
   return new LinkedHashSet<>(values);
 }
 void printFullScopeImpl(Scope scope) {
   indent();
   out.println(scope.getClass().getName());
   printSymbol("owner", scope.owner, Details.SUMMARY);
   if (SCOPE_IMPL_CLASS.equals(scope.getClass().getName())) {
     printScope("next", (Scope) getField(scope, scope.getClass(), "next"), Details.SUMMARY);
     printObject("shared", getField(scope, scope.getClass(), "shared"), Details.SUMMARY);
     Object[] table = (Object[]) getField(scope, scope.getClass(), "table");
     for (int i = 0; i < table.length; i++) {
       if (i > 0) out.print(", ");
       else indent();
       out.print(i + ":" + entryToString(table[i], table, false));
     }
     out.println();
   } else if (FILTER_SCOPE_CLASS.equals(scope.getClass().getName())) {
     printScope("origin", (Scope) getField(scope, scope.getClass(), "origin"), Details.FULL);
   } else if (scope instanceof CompoundScope) {
     printList("delegates", (List<?>) getField(scope, CompoundScope.class, "subScopes"));
   } else {
     for (Symbol sym : scope.getSymbols()) {
       printSymbol(sym.name.toString(), sym, Details.SUMMARY);
     }
   }
 }
Example #6
0
  public void visitClassDef(JCClassDecl tree) {
    Symbol owner = env.info.scope.owner;
    Scope enclScope = enterScope(env);
    ClassSymbol c;
    if (owner.kind == PCK) {
      // We are seeing a toplevel class.
      PackageSymbol packge = (PackageSymbol) owner;
      for (Symbol q = packge; q != null && q.kind == PCK; q = q.owner) q.flags_field |= EXISTS;
      c = reader.enterClass(tree.name, packge);
      packge.members().enterIfAbsent(c);
      if ((tree.mods.flags & PUBLIC) != 0 && !classNameMatchesFileName(c, env)) {
        log.error(tree.pos(), "class.public.should.be.in.file", tree.name);
      }
    } else {
      if (!tree.name.isEmpty() && !chk.checkUniqueClassName(tree.pos(), tree.name, enclScope)) {
        result = null;
        return;
      }
      if (owner.kind == TYP) {
        // We are seeing a member class.
        c = reader.enterClass(tree.name, (TypeSymbol) owner);
        if ((owner.flags_field & INTERFACE) != 0) {
          tree.mods.flags |= PUBLIC | STATIC;
        }
      } else {
        // We are seeing a local class.
        c = reader.defineClass(tree.name, owner);
        c.flatname = chk.localClassName(c);
        if (!c.name.isEmpty()) chk.checkTransparentClass(tree.pos(), c, env.info.scope);
      }
    }
    tree.sym = c;

    // Enter class into `compiled' table and enclosing scope.
    if (chk.compiled.get(c.flatname) != null) {
      duplicateClass(tree.pos(), c);
      result = types.createErrorType(tree.name, (TypeSymbol) owner, Type.noType);
      tree.sym = (ClassSymbol) result.tsym;
      return;
    }
    chk.compiled.put(c.flatname, c);
    enclScope.enter(c);

    // Set up an environment for class block and store in `typeEnvs'
    // table, to be retrieved later in memberEnter and attribution.
    Env<AttrContext> localEnv = classEnv(tree, env);
    typeEnvs.put(c, localEnv);

    // Fill out class fields.
    c.completer = memberEnter;
    c.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, c, tree);
    c.sourcefile = env.toplevel.sourcefile;
    c.members_field = new Scope(c);

    ClassType ct = (ClassType) c.type;
    if (owner.kind != PCK && (c.flags_field & STATIC) == 0) {
      // We are seeing a local or inner class.
      // Set outer_field of this class to closest enclosing class
      // which contains this class in a non-static context
      // (its "enclosing instance class"), provided such a class exists.
      Symbol owner1 = owner;
      while ((owner1.kind & (VAR | MTH)) != 0 && (owner1.flags_field & STATIC) == 0) {
        owner1 = owner1.owner;
      }
      if (owner1.kind == TYP) {
        ct.setEnclosingType(owner1.type);
      }
    }

    // Enter type parameters.
    ct.typarams_field = classEnter(tree.typarams, localEnv);

    // Add non-local class to uncompleted, to make sure it will be
    // completed later.
    if (!c.isLocal() && uncompleted != null) uncompleted.append(c);
    //      System.err.println("entering " + c.fullname + " in " + c.owner);//DEBUG

    // Recursively enter all member classes.
    classEnter(tree.defs, localEnv);

    result = c.type;
  }
Example #7
0
 public String toString() {
   return "AttrContext[" + scope.toString() + "]";
 }
Example #8
0
 public Iterable<Symbol> getLocalElements() {
   if (scope == null) return List.nil();
   return scope.getElements();
 }
Example #9
0
 public AttrContext dupUnshared() { // DRC - added this method
   return dup(scope.dupUnshared());
 }
Example #10
0
 public Entry lookup(Name name) {
   return delegatee.lookup(name);
 }