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

changeset 308
03944ee4fac4
parent 299
22872b24d38c
child 359
8227961c64d3
equal deleted inserted replaced
307:ca063536e4a6 308:03944ee4fac4
914 // otherwise validate the rest of the expression 914 // otherwise validate the rest of the expression
915 tree.selected.accept(this); 915 tree.selected.accept(this);
916 } 916 }
917 } 917 }
918 918
919 public void visitAnnotatedType(JCAnnotatedType tree) {
920 tree.underlyingType.accept(this);
921 }
922
919 /** Default visitor method: do nothing. 923 /** Default visitor method: do nothing.
920 */ 924 */
921 public void visitTree(JCTree tree) { 925 public void visitTree(JCTree tree) {
922 } 926 }
923 927
1804 if (skipAnnotations) return; 1808 if (skipAnnotations) return;
1805 for (JCAnnotation a : annotations) 1809 for (JCAnnotation a : annotations)
1806 validateAnnotation(a, s); 1810 validateAnnotation(a, s);
1807 } 1811 }
1808 1812
1813 /** Check the type annotations
1814 */
1815 public void validateTypeAnnotations(List<JCTypeAnnotation> annotations, boolean isTypeParameter) {
1816 if (skipAnnotations) return;
1817 for (JCTypeAnnotation a : annotations)
1818 validateTypeAnnotation(a, isTypeParameter);
1819 }
1820
1809 /** Check an annotation of a symbol. 1821 /** Check an annotation of a symbol.
1810 */ 1822 */
1811 public void validateAnnotation(JCAnnotation a, Symbol s) { 1823 public void validateAnnotation(JCAnnotation a, Symbol s) {
1812 validateAnnotation(a); 1824 validateAnnotation(a);
1813 1825
1816 1828
1817 if (a.annotationType.type.tsym == syms.overrideType.tsym) { 1829 if (a.annotationType.type.tsym == syms.overrideType.tsym) {
1818 if (!isOverrider(s)) 1830 if (!isOverrider(s))
1819 log.error(a.pos(), "method.does.not.override.superclass"); 1831 log.error(a.pos(), "method.does.not.override.superclass");
1820 } 1832 }
1833 }
1834
1835 public void validateTypeAnnotation(JCTypeAnnotation a, boolean isTypeParameter) {
1836 if (a.type == null)
1837 throw new AssertionError("annotation tree hasn't been attributed yet: " + a);
1838 validateAnnotation(a);
1839
1840 if (!isTypeAnnotation(a, isTypeParameter))
1841 log.error(a.pos(), "annotation.type.not.applicable");
1821 } 1842 }
1822 1843
1823 /** Is s a method symbol that overrides a method in a superclass? */ 1844 /** Is s a method symbol that overrides a method in a superclass? */
1824 boolean isOverrider(Symbol s) { 1845 boolean isOverrider(Symbol s) {
1825 if (s.kind != MTH || s.isStatic()) 1846 if (s.kind != MTH || s.isStatic())
1832 Scope scope = sup.tsym.members(); 1853 Scope scope = sup.tsym.members();
1833 for (Scope.Entry e = scope.lookup(m.name); e.scope != null; e = e.next()) { 1854 for (Scope.Entry e = scope.lookup(m.name); e.scope != null; e = e.next()) {
1834 if (!e.sym.isStatic() && m.overrides(e.sym, owner, types, true)) 1855 if (!e.sym.isStatic() && m.overrides(e.sym, owner, types, true))
1835 return true; 1856 return true;
1836 } 1857 }
1858 }
1859 return false;
1860 }
1861
1862 /** Is the annotation applicable to type annotations */
1863 boolean isTypeAnnotation(JCTypeAnnotation a, boolean isTypeParameter) {
1864 Attribute.Compound atTarget =
1865 a.annotationType.type.tsym.attribute(syms.annotationTargetType.tsym);
1866 if (atTarget == null) return true;
1867 Attribute atValue = atTarget.member(names.value);
1868 if (!(atValue instanceof Attribute.Array)) return true; // error recovery
1869 Attribute.Array arr = (Attribute.Array) atValue;
1870 for (Attribute app : arr.values) {
1871 if (!(app instanceof Attribute.Enum)) return true; // recovery
1872 Attribute.Enum e = (Attribute.Enum) app;
1873 if (!isTypeParameter && e.value.name == names.TYPE_USE)
1874 return true;
1875 else if (isTypeParameter && e.value.name == names.TYPE_PARAMETER)
1876 return true;
1837 } 1877 }
1838 return false; 1878 return false;
1839 } 1879 }
1840 1880
1841 /** Is the annotation applicable to the symbol? */ 1881 /** Is the annotation applicable to the symbol? */
1872 { if (s.kind == TYP && (s.flags() & ANNOTATION) != 0) 1912 { if (s.kind == TYP && (s.flags() & ANNOTATION) != 0)
1873 return true; 1913 return true;
1874 } 1914 }
1875 else if (e.value.name == names.PACKAGE) 1915 else if (e.value.name == names.PACKAGE)
1876 { if (s.kind == PCK) return true; } 1916 { if (s.kind == PCK) return true; }
1917 else if (e.value.name == names.TYPE_USE)
1918 { if (s.kind == TYP ||
1919 s.kind == VAR ||
1920 (s.kind == MTH && !s.isConstructor() &&
1921 s.type.getReturnType().tag != VOID))
1922 return true;
1923 }
1877 else 1924 else
1878 return true; // recovery 1925 return true; // recovery
1879 } 1926 }
1880 return false; 1927 return false;
1881 } 1928 }

mercurial