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

changeset 1521
71f35e4b93a5
parent 1510
7873d37f5b37
child 1550
1df20330f6bd
equal deleted inserted replaced
1520:5c956be64b9e 1521:71f35e4b93a5
1 /* 1 /*
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
53 import java.util.EnumSet; 53 import java.util.EnumSet;
54 import java.util.Iterator; 54 import java.util.Iterator;
55 import java.util.LinkedHashMap; 55 import java.util.LinkedHashMap;
56 import java.util.LinkedHashSet; 56 import java.util.LinkedHashSet;
57 import java.util.Map; 57 import java.util.Map;
58 import java.util.Set;
59 58
60 import javax.lang.model.element.ElementVisitor; 59 import javax.lang.model.element.ElementVisitor;
61 60
62 import static com.sun.tools.javac.code.Flags.*; 61 import static com.sun.tools.javac.code.Flags.*;
63 import static com.sun.tools.javac.code.Flags.BLOCK; 62 import static com.sun.tools.javac.code.Flags.BLOCK;
694 693
695 Type varargsFormal = useVarargs ? formals.last() : null; 694 Type varargsFormal = useVarargs ? formals.last() : null;
696 695
697 if (varargsFormal == null && 696 if (varargsFormal == null &&
698 argtypes.size() != formals.size()) { 697 argtypes.size() != formals.size()) {
699 report(MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args 698 reportMC(MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args
700 } 699 }
701 700
702 while (argtypes.nonEmpty() && formals.head != varargsFormal) { 701 while (argtypes.nonEmpty() && formals.head != varargsFormal) {
703 ResultInfo mresult = methodCheckResult(false, formals.head, deferredAttrContext, warn); 702 ResultInfo mresult = methodCheckResult(false, formals.head, deferredAttrContext, warn);
704 mresult.check(null, argtypes.head); 703 mresult.check(null, argtypes.head);
705 argtypes = argtypes.tail; 704 argtypes = argtypes.tail;
706 formals = formals.tail; 705 formals = formals.tail;
707 } 706 }
708 707
709 if (formals.head != varargsFormal) { 708 if (formals.head != varargsFormal) {
710 report(MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args 709 reportMC(MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args
711 } 710 }
712 711
713 if (useVarargs) { 712 if (useVarargs) {
714 //note: if applicability check is triggered by most specific test, 713 //note: if applicability check is triggered by most specific test,
715 //the last argument of a varargs is _not_ an array type (see JLS 15.12.2.5) 714 //the last argument of a varargs is _not_ an array type (see JLS 15.12.2.5)
722 //check varargs element type accessibility 721 //check varargs element type accessibility
723 varargsAccessible(env, elt, inferenceContext); 722 varargsAccessible(env, elt, inferenceContext);
724 } 723 }
725 } 724 }
726 725
727 private void report(MethodCheckDiag diag, InferenceContext inferenceContext, Object... args) { 726 private void reportMC(MethodCheckDiag diag, InferenceContext inferenceContext, Object... args) {
728 boolean inferDiag = inferenceContext != infer.emptyContext; 727 boolean inferDiag = inferenceContext != infer.emptyContext;
729 InapplicableMethodException ex = inferDiag ? 728 InapplicableMethodException ex = inferDiag ?
730 infer.inferenceException : inapplicableMethodException; 729 infer.inferenceException : inapplicableMethodException;
731 if (inferDiag && (!diag.inferKey.equals(diag.basicKey))) { 730 if (inferDiag && (!diag.inferKey.equals(diag.basicKey))) {
732 Object[] args2 = new Object[args.length + 1]; 731 Object[] args2 = new Object[args.length + 1];
746 } 745 }
747 }); 746 });
748 } else { 747 } else {
749 if (!isAccessible(env, t)) { 748 if (!isAccessible(env, t)) {
750 Symbol location = env.enclClass.sym; 749 Symbol location = env.enclClass.sym;
751 report(MethodCheckDiag.INACCESSIBLE_VARARGS, inferenceContext, t, Kinds.kindName(location), location); 750 reportMC(MethodCheckDiag.INACCESSIBLE_VARARGS, inferenceContext, t, Kinds.kindName(location), location);
752 } 751 }
753 } 752 }
754 } 753 }
755 754
756 private ResultInfo methodCheckResult(final boolean varargsCheck, Type to, 755 private ResultInfo methodCheckResult(final boolean varargsCheck, Type to,
759 MethodCheckDiag methodDiag = varargsCheck ? 758 MethodCheckDiag methodDiag = varargsCheck ?
760 MethodCheckDiag.VARARG_MISMATCH : MethodCheckDiag.ARG_MISMATCH; 759 MethodCheckDiag.VARARG_MISMATCH : MethodCheckDiag.ARG_MISMATCH;
761 760
762 @Override 761 @Override
763 public void report(DiagnosticPosition pos, JCDiagnostic details) { 762 public void report(DiagnosticPosition pos, JCDiagnostic details) {
764 report(methodDiag, deferredAttrContext.inferenceContext, details); 763 reportMC(methodDiag, deferredAttrContext.inferenceContext, details);
765 } 764 }
766 }; 765 };
767 return new MethodResultInfo(to, checkContext); 766 return new MethodResultInfo(to, checkContext);
768 } 767 }
769 }; 768 };

mercurial