1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Mon Jan 24 15:44:15 2011 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Mon Jan 24 15:44:51 2011 +0000 1.3 @@ -1236,6 +1236,7 @@ 1.4 */ 1.5 Symbol access(Symbol sym, 1.6 DiagnosticPosition pos, 1.7 + Symbol location, 1.8 Type site, 1.9 Name name, 1.10 boolean qualified, 1.11 @@ -1246,23 +1247,46 @@ 1.12 if (!site.isErroneous() && 1.13 !Type.isErroneous(argtypes) && 1.14 (typeargtypes==null || !Type.isErroneous(typeargtypes))) 1.15 - logResolveError(errSym, pos, site, name, argtypes, typeargtypes); 1.16 + logResolveError(errSym, pos, location, site, name, argtypes, typeargtypes); 1.17 sym = errSym.access(name, qualified ? site.tsym : syms.noSymbol); 1.18 } 1.19 return sym; 1.20 } 1.21 1.22 - /** Same as above, but without type arguments and arguments. 1.23 + /** Same as original access(), but without location. 1.24 + */ 1.25 + Symbol access(Symbol sym, 1.26 + DiagnosticPosition pos, 1.27 + Type site, 1.28 + Name name, 1.29 + boolean qualified, 1.30 + List<Type> argtypes, 1.31 + List<Type> typeargtypes) { 1.32 + return access(sym, pos, site.tsym, site, name, qualified, argtypes, typeargtypes); 1.33 + } 1.34 + 1.35 + /** Same as original access(), but without type arguments and arguments. 1.36 + */ 1.37 + Symbol access(Symbol sym, 1.38 + DiagnosticPosition pos, 1.39 + Symbol location, 1.40 + Type site, 1.41 + Name name, 1.42 + boolean qualified) { 1.43 + if (sym.kind >= AMBIGUOUS) 1.44 + return access(sym, pos, location, site, name, qualified, List.<Type>nil(), null); 1.45 + else 1.46 + return sym; 1.47 + } 1.48 + 1.49 + /** Same as original access(), but without location, type arguments and arguments. 1.50 */ 1.51 Symbol access(Symbol sym, 1.52 DiagnosticPosition pos, 1.53 Type site, 1.54 Name name, 1.55 boolean qualified) { 1.56 - if (sym.kind >= AMBIGUOUS) 1.57 - return access(sym, pos, site, name, qualified, List.<Type>nil(), null); 1.58 - else 1.59 - return sym; 1.60 + return access(sym, pos, site.tsym, site, name, qualified); 1.61 } 1.62 1.63 /** Check that sym is not an abstract method. 1.64 @@ -1380,6 +1404,11 @@ 1.65 Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env, 1.66 Type site, Name name, List<Type> argtypes, 1.67 List<Type> typeargtypes) { 1.68 + return resolveQualifiedMethod(pos, env, site.tsym, site, name, argtypes, typeargtypes); 1.69 + } 1.70 + Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env, 1.71 + Symbol location, Type site, Name name, List<Type> argtypes, 1.72 + List<Type> typeargtypes) { 1.73 Symbol sym = startResolution(); 1.74 List<MethodResolutionPhase> steps = methodResolutionSteps; 1.75 while (steps.nonEmpty() && 1.76 @@ -1404,7 +1433,7 @@ 1.77 MethodResolutionPhase errPhase = 1.78 firstErroneousResolutionPhase(); 1.79 sym = access(methodResolutionCache.get(errPhase), 1.80 - pos, site, name, true, argtypes, typeargtypes); 1.81 + pos, location, site, name, true, argtypes, typeargtypes); 1.82 env.info.varArgs = errPhase.isVarargsRequired; 1.83 } 1.84 } else if (allowMethodHandles && sym.isPolymorphicSignatureGeneric()) { 1.85 @@ -1471,7 +1500,7 @@ 1.86 List<Type> argtypes, 1.87 List<Type> typeargtypes) { 1.88 Symbol sym = resolveQualifiedMethod( 1.89 - pos, env, site, name, argtypes, typeargtypes); 1.90 + pos, env, site.tsym, site, name, argtypes, typeargtypes); 1.91 if (sym.kind == MTH) return (MethodSymbol)sym; 1.92 else throw new FatalError( 1.93 diags.fragment("fatal.err.cant.locate.meth", 1.94 @@ -1546,11 +1575,13 @@ 1.95 null; 1.96 Symbol errSym = new ResolveError(WRONG_MTH, "diamond error") { 1.97 @Override 1.98 - JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) { 1.99 + JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, 1.100 + Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) { 1.101 String key = details == null ? 1.102 "cant.apply.diamond" : 1.103 "cant.apply.diamond.1"; 1.104 - return diags.create(dkind, log.currentSource(), pos, key, diags.fragment("diamond", site.tsym), details); 1.105 + return diags.create(dkind, log.currentSource(), pos, key, 1.106 + diags.fragment("diamond", site.tsym), details); 1.107 } 1.108 }; 1.109 MethodResolutionPhase errPhase = firstErroneousResolutionPhase(); 1.110 @@ -1729,17 +1760,18 @@ 1.111 1.112 public void logAccessError(Env<AttrContext> env, JCTree tree, Type type) { 1.113 AccessError error = new AccessError(env, type.getEnclosingType(), type.tsym); 1.114 - logResolveError(error, tree.pos(), type.getEnclosingType(), null, null, null); 1.115 + logResolveError(error, tree.pos(), type.getEnclosingType().tsym, type.getEnclosingType(), null, null, null); 1.116 } 1.117 //where 1.118 private void logResolveError(ResolveError error, 1.119 DiagnosticPosition pos, 1.120 + Symbol location, 1.121 Type site, 1.122 Name name, 1.123 List<Type> argtypes, 1.124 List<Type> typeargtypes) { 1.125 JCDiagnostic d = error.getDiagnostic(JCDiagnostic.DiagnosticType.ERROR, 1.126 - pos, site, name, argtypes, typeargtypes); 1.127 + pos, location, site, name, argtypes, typeargtypes); 1.128 if (d != null) { 1.129 d.setFlag(DiagnosticFlag.RESOLVE_ERROR); 1.130 log.report(d); 1.131 @@ -1809,6 +1841,7 @@ 1.132 */ 1.133 abstract JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, 1.134 DiagnosticPosition pos, 1.135 + Symbol location, 1.136 Type site, 1.137 Name name, 1.138 List<Type> argtypes, 1.139 @@ -1874,6 +1907,7 @@ 1.140 @Override 1.141 JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, 1.142 DiagnosticPosition pos, 1.143 + Symbol location, 1.144 Type site, 1.145 Name name, 1.146 List<Type> argtypes, 1.147 @@ -1884,16 +1918,23 @@ 1.148 return null; 1.149 1.150 if (isOperator(name)) { 1.151 + boolean isUnaryOp = argtypes.size() == 1; 1.152 + String key = argtypes.size() == 1 ? 1.153 + "operator.cant.be.applied" : 1.154 + "operator.cant.be.applied.1"; 1.155 + Type first = argtypes.head; 1.156 + Type second = !isUnaryOp ? argtypes.tail.head : null; 1.157 return diags.create(dkind, log.currentSource(), pos, 1.158 - "operator.cant.be.applied", name, argtypes); 1.159 + key, name, first, second); 1.160 } 1.161 boolean hasLocation = false; 1.162 - if (!site.tsym.name.isEmpty()) { 1.163 - if (site.tsym.kind == PCK && !site.tsym.exists()) { 1.164 + if (!location.name.isEmpty()) { 1.165 + if (location.kind == PCK && !site.tsym.exists()) { 1.166 return diags.create(dkind, log.currentSource(), pos, 1.167 - "doesnt.exist", site.tsym); 1.168 + "doesnt.exist", location); 1.169 } 1.170 - hasLocation = true; 1.171 + hasLocation = !location.name.equals(names._this) && 1.172 + !location.name.equals(names._super); 1.173 } 1.174 boolean isConstructor = kind == ABSENT_MTH && 1.175 name == names.table.names.init; 1.176 @@ -1904,7 +1945,7 @@ 1.177 return diags.create(dkind, log.currentSource(), pos, 1.178 errKey, kindname, idname, //symbol kindname, name 1.179 typeargtypes, argtypes, //type parameters and arguments (if any) 1.180 - typeKindName(site), site); //location kindname, type 1.181 + getLocationDiag(location)); //location kindname, type 1.182 } 1.183 else { 1.184 return diags.create(dkind, log.currentSource(), pos, 1.185 @@ -1925,6 +1966,16 @@ 1.186 } 1.187 return key + suffix; 1.188 } 1.189 + private JCDiagnostic getLocationDiag(Symbol location) { 1.190 + boolean isVar = location.kind == VAR; 1.191 + String key = isVar ? 1.192 + "location.1" : 1.193 + "location"; 1.194 + return diags.fragment(key, 1.195 + kindName(location), 1.196 + location, 1.197 + isVar ? location.type : null); 1.198 + } 1.199 } 1.200 1.201 /** 1.202 @@ -1965,6 +2016,7 @@ 1.203 @Override 1.204 JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, 1.205 DiagnosticPosition pos, 1.206 + Symbol location, 1.207 Type site, 1.208 Name name, 1.209 List<Type> argtypes, 1.210 @@ -2016,6 +2068,7 @@ 1.211 @Override 1.212 JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, 1.213 DiagnosticPosition pos, 1.214 + Symbol location, 1.215 Type site, 1.216 Name name, 1.217 List<Type> argtypes, 1.218 @@ -2031,7 +2084,7 @@ 1.219 return new JCDiagnostic.MultilineDiagnostic(err, candidateDetails(site)); 1.220 } else { 1.221 return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind, pos, 1.222 - site, name, argtypes, typeargtypes); 1.223 + location, site, name, argtypes, typeargtypes); 1.224 } 1.225 } 1.226 1.227 @@ -2131,6 +2184,7 @@ 1.228 @Override 1.229 JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, 1.230 DiagnosticPosition pos, 1.231 + Symbol location, 1.232 Type site, 1.233 Name name, 1.234 List<Type> argtypes, 1.235 @@ -2140,7 +2194,7 @@ 1.236 1.237 if (sym.name == names.init && sym.owner != site.tsym) { 1.238 return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind, 1.239 - pos, site, name, argtypes, typeargtypes); 1.240 + pos, location, site, name, argtypes, typeargtypes); 1.241 } 1.242 else if ((sym.flags() & PUBLIC) != 0 1.243 || (env != null && this.site != null 1.244 @@ -2175,6 +2229,7 @@ 1.245 @Override 1.246 JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, 1.247 DiagnosticPosition pos, 1.248 + Symbol location, 1.249 Type site, 1.250 Name name, 1.251 List<Type> argtypes, 1.252 @@ -2205,6 +2260,7 @@ 1.253 @Override 1.254 JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, 1.255 DiagnosticPosition pos, 1.256 + Symbol location, 1.257 Type site, 1.258 Name name, 1.259 List<Type> argtypes,