src/share/classes/com/sun/tools/javac/comp/Resolve.java

changeset 302
18e0269f25e3
parent 299
22872b24d38c
child 325
ad07b7ea9685
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Fri Jun 19 11:40:47 2009 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Wed Jun 24 10:50:27 2009 +0100
     1.3 @@ -82,15 +82,15 @@
     1.4          syms = Symtab.instance(context);
     1.5  
     1.6          varNotFound = new
     1.7 -            ResolveError(ABSENT_VAR, syms.errSymbol, "variable not found");
     1.8 +            SymbolNotFoundError(ABSENT_VAR);
     1.9          wrongMethod = new
    1.10 -            ResolveError(WRONG_MTH, syms.errSymbol, "method not found");
    1.11 +            InapplicableSymbolError(syms.errSymbol);
    1.12          wrongMethods = new
    1.13 -            ResolveError(WRONG_MTHS, syms.errSymbol, "wrong methods");
    1.14 +            InapplicableSymbolsError(syms.errSymbol);
    1.15          methodNotFound = new
    1.16 -            ResolveError(ABSENT_MTH, syms.errSymbol, "method not found");
    1.17 +            SymbolNotFoundError(ABSENT_MTH);
    1.18          typeNotFound = new
    1.19 -            ResolveError(ABSENT_TYP, syms.errSymbol, "type not found");
    1.20 +            SymbolNotFoundError(ABSENT_TYP);
    1.21  
    1.22          names = Names.instance(context);
    1.23          log = Log.instance(context);
    1.24 @@ -110,11 +110,11 @@
    1.25  
    1.26      /** error symbols, which are returned when resolution fails
    1.27       */
    1.28 -    final ResolveError varNotFound;
    1.29 -    final ResolveError wrongMethod;
    1.30 -    final ResolveError wrongMethods;
    1.31 -    final ResolveError methodNotFound;
    1.32 -    final ResolveError typeNotFound;
    1.33 +    final SymbolNotFoundError varNotFound;
    1.34 +    final InapplicableSymbolError wrongMethod;
    1.35 +    final InapplicableSymbolsError wrongMethods;
    1.36 +    final SymbolNotFoundError methodNotFound;
    1.37 +    final SymbolNotFoundError typeNotFound;
    1.38  
    1.39  /* ************************************************************************
    1.40   * Identifier resolution
    1.41 @@ -710,13 +710,13 @@
    1.42              return new AmbiguityError(m1, m2);
    1.43          case AMBIGUOUS:
    1.44              AmbiguityError e = (AmbiguityError)m2;
    1.45 -            Symbol err1 = mostSpecific(m1, e.sym1, env, site, allowBoxing, useVarargs);
    1.46 +            Symbol err1 = mostSpecific(m1, e.sym, env, site, allowBoxing, useVarargs);
    1.47              Symbol err2 = mostSpecific(m1, e.sym2, env, site, allowBoxing, useVarargs);
    1.48              if (err1 == err2) return err1;
    1.49 -            if (err1 == e.sym1 && err2 == e.sym2) return m2;
    1.50 +            if (err1 == e.sym && err2 == e.sym2) return m2;
    1.51              if (err1 instanceof AmbiguityError &&
    1.52                  err2 instanceof AmbiguityError &&
    1.53 -                ((AmbiguityError)err1).sym1 == ((AmbiguityError)err2).sym1)
    1.54 +                ((AmbiguityError)err1).sym == ((AmbiguityError)err2).sym)
    1.55                  return new AmbiguityError(m1, m2);
    1.56              else
    1.57                  return new AmbiguityError(err1, err2);
    1.58 @@ -1192,18 +1192,12 @@
    1.59                    List<Type> argtypes,
    1.60                    List<Type> typeargtypes) {
    1.61          if (sym.kind >= AMBIGUOUS) {
    1.62 -//          printscopes(site.tsym.members());//DEBUG
    1.63 +            ResolveError errSym = (ResolveError)sym;
    1.64              if (!site.isErroneous() &&
    1.65                  !Type.isErroneous(argtypes) &&
    1.66                  (typeargtypes==null || !Type.isErroneous(typeargtypes)))
    1.67 -                ((ResolveError)sym).report(log, pos, site, name, argtypes, typeargtypes);
    1.68 -            do {
    1.69 -                sym = ((ResolveError)sym).sym;
    1.70 -            } while (sym.kind >= AMBIGUOUS);
    1.71 -            if (sym == syms.errSymbol // preserve the symbol name through errors
    1.72 -                || ((sym.kind & ERRONEOUS) == 0 // make sure an error symbol is returned
    1.73 -                    && (sym.kind & TYP) != 0))
    1.74 -                sym = types.createErrorType(name, qualified ? site.tsym : syms.noSymbol, sym.type).tsym;
    1.75 +                logResolveError(errSym, pos, site, name, argtypes, typeargtypes);
    1.76 +            sym = errSym.access(name, qualified ? site.tsym : syms.noSymbol);
    1.77          }
    1.78          return sym;
    1.79      }
    1.80 @@ -1583,7 +1577,19 @@
    1.81  
    1.82      public void logAccessError(Env<AttrContext> env, JCTree tree, Type type) {
    1.83          AccessError error = new AccessError(env, type.getEnclosingType(), type.tsym);
    1.84 -        error.report(log, tree.pos(), type.getEnclosingType(), null, null, null);
    1.85 +        logResolveError(error, tree.pos(), type.getEnclosingType(), null, null, null);
    1.86 +    }
    1.87 +    //where
    1.88 +    private void logResolveError(ResolveError error,
    1.89 +            DiagnosticPosition pos,
    1.90 +            Type site,
    1.91 +            Name name,
    1.92 +            List<Type> argtypes,
    1.93 +            List<Type> typeargtypes) {
    1.94 +        JCDiagnostic d = error.getDiagnostic(JCDiagnostic.DiagnosticType.ERROR,
    1.95 +                pos, site, name, argtypes, typeargtypes);
    1.96 +        if (d != null)
    1.97 +            log.report(d);
    1.98      }
    1.99  
   1.100      private final LocalizedString noArgs = new LocalizedString("compiler.misc.no.args");
   1.101 @@ -1592,152 +1598,71 @@
   1.102          return argtypes.isEmpty() ? noArgs : argtypes;
   1.103      }
   1.104  
   1.105 -    /** Root class for resolve errors.
   1.106 -     *  Instances of this class indicate "Symbol not found".
   1.107 -     *  Instances of subclass indicate other errors.
   1.108 +    /**
   1.109 +     * Root class for resolution errors. Subclass of ResolveError
   1.110 +     * represent a different kinds of resolution error - as such they must
   1.111 +     * specify how they map into concrete compiler diagnostics.
   1.112       */
   1.113 -    private class ResolveError extends Symbol {
   1.114 +    private abstract class ResolveError extends Symbol {
   1.115  
   1.116 -        ResolveError(int kind, Symbol sym, String debugName) {
   1.117 +        /** The name of the kind of error, for debugging only. */
   1.118 +        final String debugName;
   1.119 +
   1.120 +        ResolveError(int kind, String debugName) {
   1.121              super(kind, 0, null, null, null);
   1.122              this.debugName = debugName;
   1.123 -            this.sym = sym;
   1.124          }
   1.125  
   1.126 -        /** The name of the kind of error, for debugging only.
   1.127 -         */
   1.128 -        final String debugName;
   1.129 -
   1.130 -        /** The symbol that was determined by resolution, or errSymbol if none
   1.131 -         *  was found.
   1.132 -         */
   1.133 -        final Symbol sym;
   1.134 -
   1.135 -        /** The symbol that was a close mismatch, or null if none was found.
   1.136 -         *  wrongSym is currently set if a simgle method with the correct name, but
   1.137 -         *  the wrong parameters was found.
   1.138 -         */
   1.139 -        Symbol wrongSym;
   1.140 -
   1.141 -        /** An auxiliary explanation set in case of instantiation errors.
   1.142 -         */
   1.143 -        JCDiagnostic explanation;
   1.144 -
   1.145 -
   1.146 +        @Override
   1.147          public <R, P> R accept(ElementVisitor<R, P> v, P p) {
   1.148              throw new AssertionError();
   1.149          }
   1.150  
   1.151 -        /** Print the (debug only) name of the kind of error.
   1.152 -         */
   1.153 +        @Override
   1.154          public String toString() {
   1.155 -            return debugName + " wrongSym=" + wrongSym + " explanation=" + explanation;
   1.156 +            return debugName;
   1.157          }
   1.158  
   1.159 -        /** Update wrongSym and explanation and return this.
   1.160 -         */
   1.161 -        ResolveError setWrongSym(Symbol sym, JCDiagnostic explanation) {
   1.162 -            this.wrongSym = sym;
   1.163 -            this.explanation = explanation;
   1.164 -            return this;
   1.165 +        @Override
   1.166 +        public boolean exists() {
   1.167 +            return false;
   1.168          }
   1.169  
   1.170 -        /** Update wrongSym and return this.
   1.171 +        /**
   1.172 +         * Create an external representation for this erroneous symbol to be
   1.173 +         * used during attribution - by default this returns the symbol of a
   1.174 +         * brand new error type which stores the original type found
   1.175 +         * during resolution.
   1.176 +         *
   1.177 +         * @param name     the name used during resolution
   1.178 +         * @param location the location from which the symbol is accessed
   1.179           */
   1.180 -        ResolveError setWrongSym(Symbol sym) {
   1.181 -            this.wrongSym = sym;
   1.182 -            this.explanation = null;
   1.183 -            return this;
   1.184 +        protected Symbol access(Name name, TypeSymbol location) {
   1.185 +            return types.createErrorType(name, location, syms.errSymbol.type).tsym;
   1.186          }
   1.187  
   1.188 -        public boolean exists() {
   1.189 -            switch (kind) {
   1.190 -            case HIDDEN:
   1.191 -            case ABSENT_VAR:
   1.192 -            case ABSENT_MTH:
   1.193 -            case ABSENT_TYP:
   1.194 -                return false;
   1.195 -            default:
   1.196 -                return true;
   1.197 -            }
   1.198 -        }
   1.199 +        /**
   1.200 +         * Create a diagnostic representing this resolution error.
   1.201 +         *
   1.202 +         * @param dkind     The kind of the diagnostic to be created (e.g error).
   1.203 +         * @param pos       The position to be used for error reporting.
   1.204 +         * @param site      The original type from where the selection took place.
   1.205 +         * @param name      The name of the symbol to be resolved.
   1.206 +         * @param argtypes  The invocation's value arguments,
   1.207 +         *                  if we looked for a method.
   1.208 +         * @param typeargtypes  The invocation's type arguments,
   1.209 +         *                      if we looked for a method.
   1.210 +         */
   1.211 +        abstract JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
   1.212 +                DiagnosticPosition pos,
   1.213 +                Type site,
   1.214 +                Name name,
   1.215 +                List<Type> argtypes,
   1.216 +                List<Type> typeargtypes);
   1.217  
   1.218 -        /** Report error.
   1.219 -         *  @param log       The error log to be used for error reporting.
   1.220 -         *  @param pos       The position to be used for error reporting.
   1.221 -         *  @param site      The original type from where the selection took place.
   1.222 -         *  @param name      The name of the symbol to be resolved.
   1.223 -         *  @param argtypes  The invocation's value arguments,
   1.224 -         *                   if we looked for a method.
   1.225 -         *  @param typeargtypes  The invocation's type arguments,
   1.226 -         *                   if we looked for a method.
   1.227 -         */
   1.228 -        void report(Log log, DiagnosticPosition pos, Type site, Name name,
   1.229 -                    List<Type> argtypes, List<Type> typeargtypes) {
   1.230 -            if (argtypes == null)
   1.231 -                argtypes = List.nil();
   1.232 -            if (typeargtypes == null)
   1.233 -                typeargtypes = List.nil();
   1.234 -            if (name != names.error) {
   1.235 -                KindName kindname = absentKind(kind);
   1.236 -                Name idname = name;
   1.237 -                if (kind >= WRONG_MTHS && kind <= ABSENT_MTH) {
   1.238 -                    if (isOperator(name)) {
   1.239 -                        log.error(pos, "operator.cant.be.applied",
   1.240 -                                  name, argtypes);
   1.241 -                        return;
   1.242 -                    }
   1.243 -                    if (name == names.init) {
   1.244 -                        kindname = KindName.CONSTRUCTOR;
   1.245 -                        idname = site.tsym.name;
   1.246 -                    }
   1.247 -                }
   1.248 -                if (kind == WRONG_MTH) {
   1.249 -                    Symbol ws = wrongSym.asMemberOf(site, types);
   1.250 -                    log.error(pos,
   1.251 -                              "cant.apply.symbol" + (explanation != null ? ".1" : ""),
   1.252 -                              kindname,
   1.253 -                              ws.name == names.init ? ws.owner.name : ws.name,
   1.254 -                              methodArguments(ws.type.getParameterTypes()),
   1.255 -                              methodArguments(argtypes),
   1.256 -                              kindName(ws.owner),
   1.257 -                              ws.owner.type,
   1.258 -                              explanation);
   1.259 -                } else if (!site.tsym.name.isEmpty()) {
   1.260 -                    if (site.tsym.kind == PCK && !site.tsym.exists())
   1.261 -                        log.error(pos, "doesnt.exist", site.tsym);
   1.262 -                    else {
   1.263 -                        String errKey = getErrorKey("cant.resolve.location",
   1.264 -                                                    argtypes, typeargtypes,
   1.265 -                                                    kindname);
   1.266 -                        log.error(pos, errKey, kindname, idname, //symbol kindname, name
   1.267 -                                  typeargtypes, argtypes, //type parameters and arguments (if any)
   1.268 -                                  typeKindName(site), site); //location kindname, type
   1.269 -                    }
   1.270 -                } else {
   1.271 -                    String errKey = getErrorKey("cant.resolve",
   1.272 -                                                argtypes, typeargtypes,
   1.273 -                                                kindname);
   1.274 -                    log.error(pos, errKey, kindname, idname, //symbol kindname, name
   1.275 -                              typeargtypes, argtypes); //type parameters and arguments (if any)
   1.276 -                }
   1.277 -            }
   1.278 -        }
   1.279 -        //where
   1.280 -        String getErrorKey(String key, List<Type> argtypes, List<Type> typeargtypes, KindName kindname) {
   1.281 -            String suffix = "";
   1.282 -            switch (kindname) {
   1.283 -                case METHOD:
   1.284 -                case CONSTRUCTOR: {
   1.285 -                    suffix += ".args";
   1.286 -                    suffix += typeargtypes.nonEmpty() ? ".params" : "";
   1.287 -                }
   1.288 -            }
   1.289 -            return key + suffix;
   1.290 -        }
   1.291 -
   1.292 -        /** A name designates an operator if it consists
   1.293 -         *  of a non-empty sequence of operator symbols +-~!/*%&|^<>=
   1.294 +        /**
   1.295 +         * A name designates an operator if it consists
   1.296 +         * of a non-empty sequence of operator symbols +-~!/*%&|^<>=
   1.297           */
   1.298          boolean isOperator(Name name) {
   1.299              int i = 0;
   1.300 @@ -1747,9 +1672,206 @@
   1.301          }
   1.302      }
   1.303  
   1.304 -    /** Resolve error class indicating that a symbol is not accessible.
   1.305 +    /**
   1.306 +     * This class is the root class of all resolution errors caused by
   1.307 +     * an invalid symbol being found during resolution.
   1.308       */
   1.309 -    class AccessError extends ResolveError {
   1.310 +    abstract class InvalidSymbolError extends ResolveError {
   1.311 +
   1.312 +        /** The invalid symbol found during resolution */
   1.313 +        Symbol sym;
   1.314 +
   1.315 +        InvalidSymbolError(int kind, Symbol sym, String debugName) {
   1.316 +            super(kind, debugName);
   1.317 +            this.sym = sym;
   1.318 +        }
   1.319 +
   1.320 +        @Override
   1.321 +        public boolean exists() {
   1.322 +            return true;
   1.323 +        }
   1.324 +
   1.325 +        @Override
   1.326 +        public String toString() {
   1.327 +             return super.toString() + " wrongSym=" + sym;
   1.328 +        }
   1.329 +
   1.330 +        @Override
   1.331 +        public Symbol access(Name name, TypeSymbol location) {
   1.332 +            if (sym.kind >= AMBIGUOUS)
   1.333 +                return ((ResolveError)sym).access(name, location);
   1.334 +            else if ((sym.kind & ERRONEOUS) == 0 && (sym.kind & TYP) != 0)
   1.335 +                return types.createErrorType(name, location, sym.type).tsym;
   1.336 +            else
   1.337 +                return sym;
   1.338 +        }
   1.339 +    }
   1.340 +
   1.341 +    /**
   1.342 +     * InvalidSymbolError error class indicating that a symbol matching a
   1.343 +     * given name does not exists in a given site.
   1.344 +     */
   1.345 +    class SymbolNotFoundError extends ResolveError {
   1.346 +
   1.347 +        SymbolNotFoundError(int kind) {
   1.348 +            super(kind, "symbol not found error");
   1.349 +        }
   1.350 +
   1.351 +        @Override
   1.352 +        JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
   1.353 +                DiagnosticPosition pos,
   1.354 +                Type site,
   1.355 +                Name name,
   1.356 +                List<Type> argtypes,
   1.357 +                List<Type> typeargtypes) {
   1.358 +            argtypes = argtypes == null ? List.<Type>nil() : argtypes;
   1.359 +            typeargtypes = typeargtypes == null ? List.<Type>nil() : typeargtypes;
   1.360 +            if (name == names.error)
   1.361 +                return null;
   1.362 +
   1.363 +            if (isOperator(name)) {
   1.364 +                return diags.create(dkind, false, log.currentSource(), pos,
   1.365 +                        "operator.cant.be.applied", name, argtypes);
   1.366 +            }
   1.367 +            boolean hasLocation = false;
   1.368 +            if (!site.tsym.name.isEmpty()) {
   1.369 +                if (site.tsym.kind == PCK && !site.tsym.exists()) {
   1.370 +                    return diags.create(dkind, false, log.currentSource(), pos,
   1.371 +                        "doesnt.exist", site.tsym);
   1.372 +                }
   1.373 +                hasLocation = true;
   1.374 +            }
   1.375 +            boolean isConstructor = kind == ABSENT_MTH &&
   1.376 +                    name == names.table.names.init;
   1.377 +            KindName kindname = isConstructor ? KindName.CONSTRUCTOR : absentKind(kind);
   1.378 +            Name idname = isConstructor ? site.tsym.name : name;
   1.379 +            String errKey = getErrorKey(kindname, typeargtypes.nonEmpty(), hasLocation);
   1.380 +            if (hasLocation) {
   1.381 +                return diags.create(dkind, false, log.currentSource(), pos,
   1.382 +                        errKey, kindname, idname, //symbol kindname, name
   1.383 +                        typeargtypes, argtypes, //type parameters and arguments (if any)
   1.384 +                        typeKindName(site), site); //location kindname, type
   1.385 +            }
   1.386 +            else {
   1.387 +                return diags.create(dkind, false, log.currentSource(), pos,
   1.388 +                        errKey, kindname, idname, //symbol kindname, name
   1.389 +                        typeargtypes, argtypes); //type parameters and arguments (if any)
   1.390 +            }
   1.391 +        }
   1.392 +        //where
   1.393 +        private String getErrorKey(KindName kindname, boolean hasTypeArgs, boolean hasLocation) {
   1.394 +            String key = "cant.resolve";
   1.395 +            String suffix = hasLocation ? ".location" : "";
   1.396 +            switch (kindname) {
   1.397 +                case METHOD:
   1.398 +                case CONSTRUCTOR: {
   1.399 +                    suffix += ".args";
   1.400 +                    suffix += hasTypeArgs ? ".params" : "";
   1.401 +                }
   1.402 +            }
   1.403 +            return key + suffix;
   1.404 +        }
   1.405 +    }
   1.406 +
   1.407 +    /**
   1.408 +     * InvalidSymbolError error class indicating that a given symbol
   1.409 +     * (either a method, a constructor or an operand) is not applicable
   1.410 +     * given an actual arguments/type argument list.
   1.411 +     */
   1.412 +    class InapplicableSymbolError extends InvalidSymbolError {
   1.413 +
   1.414 +        /** An auxiliary explanation set in case of instantiation errors. */
   1.415 +        JCDiagnostic explanation;
   1.416 +
   1.417 +        InapplicableSymbolError(Symbol sym) {
   1.418 +            super(WRONG_MTH, sym, "inapplicable symbol error");
   1.419 +        }
   1.420 +
   1.421 +        /** Update sym and explanation and return this.
   1.422 +         */
   1.423 +        InapplicableSymbolError setWrongSym(Symbol sym, JCDiagnostic explanation) {
   1.424 +            this.sym = sym;
   1.425 +            this.explanation = explanation;
   1.426 +            return this;
   1.427 +        }
   1.428 +
   1.429 +        /** Update sym and return this.
   1.430 +         */
   1.431 +        InapplicableSymbolError setWrongSym(Symbol sym) {
   1.432 +            this.sym = sym;
   1.433 +            this.explanation = null;
   1.434 +            return this;
   1.435 +        }
   1.436 +
   1.437 +        @Override
   1.438 +        public String toString() {
   1.439 +            return super.toString() + " explanation=" + explanation;
   1.440 +        }
   1.441 +
   1.442 +        @Override
   1.443 +        JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
   1.444 +                DiagnosticPosition pos,
   1.445 +                Type site,
   1.446 +                Name name,
   1.447 +                List<Type> argtypes,
   1.448 +                List<Type> typeargtypes) {
   1.449 +            if (name == names.error)
   1.450 +                return null;
   1.451 +
   1.452 +            if (isOperator(name)) {
   1.453 +                return diags.create(dkind, false, log.currentSource(),
   1.454 +                        pos, "operator.cant.be.applied", name, argtypes);
   1.455 +            }
   1.456 +            else {
   1.457 +                Symbol ws = sym.asMemberOf(site, types);
   1.458 +                return diags.create(dkind, false, log.currentSource(), pos,
   1.459 +                          "cant.apply.symbol" + (explanation != null ? ".1" : ""),
   1.460 +                          kindName(ws),
   1.461 +                          ws.name == names.init ? ws.owner.name : ws.name,
   1.462 +                          methodArguments(ws.type.getParameterTypes()),
   1.463 +                          methodArguments(argtypes),
   1.464 +                          kindName(ws.owner),
   1.465 +                          ws.owner.type,
   1.466 +                          explanation);
   1.467 +            }
   1.468 +        }
   1.469 +
   1.470 +        @Override
   1.471 +        public Symbol access(Name name, TypeSymbol location) {
   1.472 +            return types.createErrorType(name, location, syms.errSymbol.type).tsym;
   1.473 +        }
   1.474 +    }
   1.475 +
   1.476 +    /**
   1.477 +     * ResolveError error class indicating that a set of symbols
   1.478 +     * (either methods, constructors or operands) is not applicable
   1.479 +     * given an actual arguments/type argument list.
   1.480 +     */
   1.481 +    class InapplicableSymbolsError extends ResolveError {
   1.482 +        InapplicableSymbolsError(Symbol sym) {
   1.483 +            super(WRONG_MTHS, "inapplicable symbols");
   1.484 +        }
   1.485 +
   1.486 +        @Override
   1.487 +        JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
   1.488 +                DiagnosticPosition pos,
   1.489 +                Type site,
   1.490 +                Name name,
   1.491 +                List<Type> argtypes,
   1.492 +                List<Type> typeargtypes) {
   1.493 +            return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind, pos,
   1.494 +                    site, name, argtypes, typeargtypes);
   1.495 +        }
   1.496 +    }
   1.497 +
   1.498 +    /**
   1.499 +     * An InvalidSymbolError error class indicating that a symbol is not
   1.500 +     * accessible from a given site
   1.501 +     */
   1.502 +    class AccessError extends InvalidSymbolError {
   1.503 +
   1.504 +        private Env<AttrContext> env;
   1.505 +        private Type site;
   1.506  
   1.507          AccessError(Symbol sym) {
   1.508              this(null, null, sym);
   1.509 @@ -1763,111 +1885,107 @@
   1.510                  log.error("proc.messager", sym + " @ " + site + " is inaccessible.");
   1.511          }
   1.512  
   1.513 -        private Env<AttrContext> env;
   1.514 -        private Type site;
   1.515 +        @Override
   1.516 +        public boolean exists() {
   1.517 +            return false;
   1.518 +        }
   1.519  
   1.520 -        /** Report error.
   1.521 -         *  @param log       The error log to be used for error reporting.
   1.522 -         *  @param pos       The position to be used for error reporting.
   1.523 -         *  @param site      The original type from where the selection took place.
   1.524 -         *  @param name      The name of the symbol to be resolved.
   1.525 -         *  @param argtypes  The invocation's value arguments,
   1.526 -         *                   if we looked for a method.
   1.527 -         *  @param typeargtypes  The invocation's type arguments,
   1.528 -         *                   if we looked for a method.
   1.529 -         */
   1.530 -        void report(Log log, DiagnosticPosition pos, Type site, Name name,
   1.531 -                    List<Type> argtypes, List<Type> typeargtypes) {
   1.532 -            if (sym.owner.type.tag != ERROR) {
   1.533 -                if (sym.name == names.init && sym.owner != site.tsym)
   1.534 -                    new ResolveError(ABSENT_MTH, sym.owner, "absent method " + sym).report(
   1.535 -                        log, pos, site, name, argtypes, typeargtypes);
   1.536 -                if ((sym.flags() & PUBLIC) != 0
   1.537 -                    || (env != null && this.site != null
   1.538 -                        && !isAccessible(env, this.site)))
   1.539 -                    log.error(pos, "not.def.access.class.intf.cant.access",
   1.540 -                        sym, sym.location());
   1.541 -                else if ((sym.flags() & (PRIVATE | PROTECTED)) != 0)
   1.542 -                    log.error(pos, "report.access", sym,
   1.543 -                              asFlagSet(sym.flags() & (PRIVATE | PROTECTED)),
   1.544 -                              sym.location());
   1.545 -                else
   1.546 -                    log.error(pos, "not.def.public.cant.access",
   1.547 -                              sym, sym.location());
   1.548 +        @Override
   1.549 +        JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
   1.550 +                DiagnosticPosition pos,
   1.551 +                Type site,
   1.552 +                Name name,
   1.553 +                List<Type> argtypes,
   1.554 +                List<Type> typeargtypes) {
   1.555 +            if (sym.owner.type.tag == ERROR)
   1.556 +                return null;
   1.557 +
   1.558 +            if (sym.name == names.init && sym.owner != site.tsym) {
   1.559 +                return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind,
   1.560 +                        pos, site, name, argtypes, typeargtypes);
   1.561 +            }
   1.562 +            else if ((sym.flags() & PUBLIC) != 0
   1.563 +                || (env != null && this.site != null
   1.564 +                    && !isAccessible(env, this.site))) {
   1.565 +                return diags.create(dkind, false, log.currentSource(),
   1.566 +                        pos, "not.def.access.class.intf.cant.access",
   1.567 +                    sym, sym.location());
   1.568 +            }
   1.569 +            else if ((sym.flags() & (PRIVATE | PROTECTED)) != 0) {
   1.570 +                return diags.create(dkind, false, log.currentSource(),
   1.571 +                        pos, "report.access", sym,
   1.572 +                        asFlagSet(sym.flags() & (PRIVATE | PROTECTED)),
   1.573 +                        sym.location());
   1.574 +            }
   1.575 +            else {
   1.576 +                return diags.create(dkind, false, log.currentSource(),
   1.577 +                        pos, "not.def.public.cant.access", sym, sym.location());
   1.578              }
   1.579          }
   1.580      }
   1.581  
   1.582 -    /** Resolve error class indicating that an instance member was accessed
   1.583 -     *  from a static context.
   1.584 +    /**
   1.585 +     * InvalidSymbolError error class indicating that an instance member
   1.586 +     * has erroneously been accessed from a static context.
   1.587       */
   1.588 -    class StaticError extends ResolveError {
   1.589 +    class StaticError extends InvalidSymbolError {
   1.590 +
   1.591          StaticError(Symbol sym) {
   1.592              super(STATICERR, sym, "static error");
   1.593          }
   1.594  
   1.595 -        /** Report error.
   1.596 -         *  @param log       The error log to be used for error reporting.
   1.597 -         *  @param pos       The position to be used for error reporting.
   1.598 -         *  @param site      The original type from where the selection took place.
   1.599 -         *  @param name      The name of the symbol to be resolved.
   1.600 -         *  @param argtypes  The invocation's value arguments,
   1.601 -         *                   if we looked for a method.
   1.602 -         *  @param typeargtypes  The invocation's type arguments,
   1.603 -         *                   if we looked for a method.
   1.604 -         */
   1.605 -        void report(Log log,
   1.606 -                    DiagnosticPosition pos,
   1.607 -                    Type site,
   1.608 -                    Name name,
   1.609 -                    List<Type> argtypes,
   1.610 -                    List<Type> typeargtypes) {
   1.611 +        @Override
   1.612 +        JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
   1.613 +                DiagnosticPosition pos,
   1.614 +                Type site,
   1.615 +                Name name,
   1.616 +                List<Type> argtypes,
   1.617 +                List<Type> typeargtypes) {
   1.618              Symbol errSym = ((sym.kind == TYP && sym.type.tag == CLASS)
   1.619                  ? types.erasure(sym.type).tsym
   1.620                  : sym);
   1.621 -            log.error(pos, "non-static.cant.be.ref",
   1.622 -                      kindName(sym), errSym);
   1.623 +            return diags.create(dkind, false, log.currentSource(), pos,
   1.624 +                    "non-static.cant.be.ref", kindName(sym), errSym);
   1.625          }
   1.626      }
   1.627  
   1.628 -    /** Resolve error class indicating an ambiguous reference.
   1.629 +    /**
   1.630 +     * InvalidSymbolError error class indicating that a pair of symbols
   1.631 +     * (either methods, constructors or operands) are ambiguous
   1.632 +     * given an actual arguments/type argument list.
   1.633       */
   1.634 -    class AmbiguityError extends ResolveError {
   1.635 -        Symbol sym1;
   1.636 +    class AmbiguityError extends InvalidSymbolError {
   1.637 +
   1.638 +        /** The other maximally specific symbol */
   1.639          Symbol sym2;
   1.640  
   1.641          AmbiguityError(Symbol sym1, Symbol sym2) {
   1.642              super(AMBIGUOUS, sym1, "ambiguity error");
   1.643 -            this.sym1 = sym1;
   1.644              this.sym2 = sym2;
   1.645          }
   1.646  
   1.647 -        /** Report error.
   1.648 -         *  @param log       The error log to be used for error reporting.
   1.649 -         *  @param pos       The position to be used for error reporting.
   1.650 -         *  @param site      The original type from where the selection took place.
   1.651 -         *  @param name      The name of the symbol to be resolved.
   1.652 -         *  @param argtypes  The invocation's value arguments,
   1.653 -         *                   if we looked for a method.
   1.654 -         *  @param typeargtypes  The invocation's type arguments,
   1.655 -         *                   if we looked for a method.
   1.656 -         */
   1.657 -        void report(Log log, DiagnosticPosition pos, Type site, Name name,
   1.658 -                    List<Type> argtypes, List<Type> typeargtypes) {
   1.659 +        @Override
   1.660 +        JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
   1.661 +                DiagnosticPosition pos,
   1.662 +                Type site,
   1.663 +                Name name,
   1.664 +                List<Type> argtypes,
   1.665 +                List<Type> typeargtypes) {
   1.666              AmbiguityError pair = this;
   1.667              while (true) {
   1.668 -                if (pair.sym1.kind == AMBIGUOUS)
   1.669 -                    pair = (AmbiguityError)pair.sym1;
   1.670 +                if (pair.sym.kind == AMBIGUOUS)
   1.671 +                    pair = (AmbiguityError)pair.sym;
   1.672                  else if (pair.sym2.kind == AMBIGUOUS)
   1.673                      pair = (AmbiguityError)pair.sym2;
   1.674                  else break;
   1.675              }
   1.676 -            Name sname = pair.sym1.name;
   1.677 -            if (sname == names.init) sname = pair.sym1.owner.name;
   1.678 -            log.error(pos, "ref.ambiguous", sname,
   1.679 -                      kindName(pair.sym1),
   1.680 -                      pair.sym1,
   1.681 -                      pair.sym1.location(site, types),
   1.682 +            Name sname = pair.sym.name;
   1.683 +            if (sname == names.init) sname = pair.sym.owner.name;
   1.684 +            return diags.create(dkind, false, log.currentSource(),
   1.685 +                      pos, "ref.ambiguous", sname,
   1.686 +                      kindName(pair.sym),
   1.687 +                      pair.sym,
   1.688 +                      pair.sym.location(site, types),
   1.689                        kindName(pair.sym2),
   1.690                        pair.sym2,
   1.691                        pair.sym2.location(site, types));

mercurial