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

changeset 122
1a9276e7cb18
parent 113
eff38cc97183
child 154
6508d7e812e1
equal deleted inserted replaced
121:609fb59657b4 122:1a9276e7cb18
762 private Validator validator = new Validator(); 762 private Validator validator = new Validator();
763 763
764 /** Visitor method: Validate a type expression, if it is not null, catching 764 /** Visitor method: Validate a type expression, if it is not null, catching
765 * and reporting any completion failures. 765 * and reporting any completion failures.
766 */ 766 */
767 void validate(JCTree tree) { 767 void validate(JCTree tree, Env<AttrContext> env) {
768 try { 768 try {
769 if (tree != null) tree.accept(validator); 769 if (tree != null) {
770 validator.env = env;
771 tree.accept(validator);
772 checkRaw(tree, env);
773 }
770 } catch (CompletionFailure ex) { 774 } catch (CompletionFailure ex) {
771 completionError(tree.pos(), ex); 775 completionError(tree.pos(), ex);
772 } 776 }
773 } 777 }
778 //where
779 void checkRaw(JCTree tree, Env<AttrContext> env) {
780 if (lint.isEnabled(Lint.LintCategory.RAW) &&
781 tree.type.tag == CLASS &&
782 !env.enclClass.name.isEmpty() && //anonymous or intersection
783 tree.type.isRaw()) {
784 log.warning(tree.pos(), "raw.class.use", tree.type, tree.type.tsym.type);
785 }
786 }
774 787
775 /** Visitor method: Validate a list of type expressions. 788 /** Visitor method: Validate a list of type expressions.
776 */ 789 */
777 void validate(List<? extends JCTree> trees) { 790 void validate(List<? extends JCTree> trees, Env<AttrContext> env) {
778 for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail) 791 for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail)
779 validate(l.head); 792 validate(l.head, env);
780 }
781
782 /** Visitor method: Validate a list of type parameters.
783 */
784 void validateTypeParams(List<JCTypeParameter> trees) {
785 for (List<JCTypeParameter> l = trees; l.nonEmpty(); l = l.tail)
786 validate(l.head);
787 } 793 }
788 794
789 /** A visitor class for type validation. 795 /** A visitor class for type validation.
790 */ 796 */
791 class Validator extends JCTree.Visitor { 797 class Validator extends JCTree.Visitor {
792 798
793 public void visitTypeArray(JCArrayTypeTree tree) { 799 public void visitTypeArray(JCArrayTypeTree tree) {
794 validate(tree.elemtype); 800 validate(tree.elemtype, env);
795 } 801 }
796 802
797 public void visitTypeApply(JCTypeApply tree) { 803 public void visitTypeApply(JCTypeApply tree) {
798 if (tree.type.tag == CLASS) { 804 if (tree.type.tag == CLASS) {
799 List<Type> formals = tree.type.tsym.type.getTypeArguments(); 805 List<Type> formals = tree.type.tsym.type.getTypeArguments();
803 ListBuffer<TypeVar> tvars_buf = new ListBuffer<TypeVar>(); 809 ListBuffer<TypeVar> tvars_buf = new ListBuffer<TypeVar>();
804 810
805 // For matching pairs of actual argument types `a' and 811 // For matching pairs of actual argument types `a' and
806 // formal type parameters with declared bound `b' ... 812 // formal type parameters with declared bound `b' ...
807 while (args.nonEmpty() && forms.nonEmpty()) { 813 while (args.nonEmpty() && forms.nonEmpty()) {
808 validate(args.head); 814 validate(args.head, env);
809 815
810 // exact type arguments needs to know their 816 // exact type arguments needs to know their
811 // bounds (for upper and lower bound 817 // bounds (for upper and lower bound
812 // calculations). So we create new TypeVars with 818 // calculations). So we create new TypeVars with
813 // bounds substed with actuals. 819 // bounds substed with actuals.
847 visitSelectInternal((JCFieldAccess)tree.clazz); 853 visitSelectInternal((JCFieldAccess)tree.clazz);
848 } 854 }
849 } 855 }
850 856
851 public void visitTypeParameter(JCTypeParameter tree) { 857 public void visitTypeParameter(JCTypeParameter tree) {
852 validate(tree.bounds); 858 validate(tree.bounds, env);
853 checkClassBounds(tree.pos(), tree.type); 859 checkClassBounds(tree.pos(), tree.type);
854 } 860 }
855 861
856 @Override 862 @Override
857 public void visitWildcard(JCWildcard tree) { 863 public void visitWildcard(JCWildcard tree) {
858 if (tree.inner != null) 864 if (tree.inner != null)
859 validate(tree.inner); 865 validate(tree.inner, env);
860 } 866 }
861 867
862 public void visitSelect(JCFieldAccess tree) { 868 public void visitSelect(JCFieldAccess tree) {
863 if (tree.type.tag == CLASS) { 869 if (tree.type.tag == CLASS) {
864 visitSelectInternal(tree); 870 visitSelectInternal(tree);
868 if (tree.selected.type.isParameterized() && tree.type.tsym.type.getTypeArguments().nonEmpty()) 874 if (tree.selected.type.isParameterized() && tree.type.tsym.type.getTypeArguments().nonEmpty())
869 log.error(tree.pos(), "improperly.formed.type.param.missing"); 875 log.error(tree.pos(), "improperly.formed.type.param.missing");
870 } 876 }
871 } 877 }
872 public void visitSelectInternal(JCFieldAccess tree) { 878 public void visitSelectInternal(JCFieldAccess tree) {
873 if (tree.type.getEnclosingType().tag != CLASS && 879 if (tree.type.tsym.isStatic() &&
874 tree.selected.type.isParameterized()) { 880 tree.selected.type.isParameterized()) {
875 // The enclosing type is not a class, so we are 881 // The enclosing type is not a class, so we are
876 // looking at a static member type. However, the 882 // looking at a static member type. However, the
877 // qualifying expression is parameterized. 883 // qualifying expression is parameterized.
878 log.error(tree.pos(), "cant.select.static.class.from.param.type"); 884 log.error(tree.pos(), "cant.select.static.class.from.param.type");
879 } else { 885 } else {
880 // otherwise validate the rest of the expression 886 // otherwise validate the rest of the expression
881 validate(tree.selected); 887 tree.selected.accept(this);
882 } 888 }
883 } 889 }
884 890
885 /** Default visitor method: do nothing. 891 /** Default visitor method: do nothing.
886 */ 892 */
887 public void visitTree(JCTree tree) { 893 public void visitTree(JCTree tree) {
888 } 894 }
895
896 Env<AttrContext> env;
889 } 897 }
890 898
891 /* ************************************************************************* 899 /* *************************************************************************
892 * Exception checking 900 * Exception checking
893 **************************************************************************/ 901 **************************************************************************/

mercurial