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

changeset 1492
df694c775e8a
parent 1445
376d6c1b49e5
child 1496
f785dcac17b7
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Mon Jan 14 19:52:36 2013 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Mon Jan 14 13:50:01 2013 -0800
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -2592,30 +2592,30 @@
    1.11      }
    1.12  
    1.13      /**
    1.14 -     * Validate the proposed container 'containedBy' on the
    1.15 +     * Validate the proposed container 'repeatable' on the
    1.16       * annotation type symbol 's'. Report errors at position
    1.17       * 'pos'.
    1.18       *
    1.19 -     * @param s The (annotation)type declaration annotated with a @ContainedBy
    1.20 -     * @param containedBy the @ContainedBy on 's'
    1.21 +     * @param s The (annotation)type declaration annotated with a @Repeatable
    1.22 +     * @param repeatable the @Repeatable on 's'
    1.23       * @param pos where to report errors
    1.24       */
    1.25 -    public void validateContainedBy(TypeSymbol s, Attribute.Compound containedBy, DiagnosticPosition pos) {
    1.26 -        Assert.check(types.isSameType(containedBy.type, syms.containedByType));
    1.27 +    public void validateRepeatable(TypeSymbol s, Attribute.Compound repeatable, DiagnosticPosition pos) {
    1.28 +        Assert.check(types.isSameType(repeatable.type, syms.repeatableType));
    1.29  
    1.30          Type t = null;
    1.31 -        List<Pair<MethodSymbol,Attribute>> l = containedBy.values;
    1.32 +        List<Pair<MethodSymbol,Attribute>> l = repeatable.values;
    1.33          if (!l.isEmpty()) {
    1.34              Assert.check(l.head.fst.name == names.value);
    1.35              t = ((Attribute.Class)l.head.snd).getValue();
    1.36          }
    1.37  
    1.38          if (t == null) {
    1.39 -            log.error(pos, "invalid.container.wrong.containedby", s, containedBy);
    1.40 +            // errors should already have been reported during Annotate
    1.41              return;
    1.42          }
    1.43  
    1.44 -        validateHasContainerFor(t.tsym, s, pos);
    1.45 +        validateValue(t.tsym, s, pos);
    1.46          validateRetention(t.tsym, s, pos);
    1.47          validateDocumented(t.tsym, s, pos);
    1.48          validateInherited(t.tsym, s, pos);
    1.49 @@ -2623,79 +2623,18 @@
    1.50          validateDefault(t.tsym, s, pos);
    1.51      }
    1.52  
    1.53 -    /**
    1.54 -     * Validate the proposed container 'containerFor' on the
    1.55 -     * annotation type symbol 's'. Report errors at position
    1.56 -     * 'pos'.
    1.57 -     *
    1.58 -     * @param s The (annotation)type declaration annotated with a @ContainerFor
    1.59 -     * @param containerFor the @ContainedFor on 's'
    1.60 -     * @param pos where to report errors
    1.61 -     */
    1.62 -    public void validateContainerFor(TypeSymbol s, Attribute.Compound containerFor, DiagnosticPosition pos) {
    1.63 -        Assert.check(types.isSameType(containerFor.type, syms.containerForType));
    1.64 -
    1.65 -        Type t = null;
    1.66 -        List<Pair<MethodSymbol,Attribute>> l = containerFor.values;
    1.67 -        if (!l.isEmpty()) {
    1.68 -            Assert.check(l.head.fst.name == names.value);
    1.69 -            t = ((Attribute.Class)l.head.snd).getValue();
    1.70 +    private void validateValue(TypeSymbol container, TypeSymbol contained, DiagnosticPosition pos) {
    1.71 +        Scope.Entry e = container.members().lookup(names.value);
    1.72 +        if (e.scope != null && e.sym.kind == MTH) {
    1.73 +            MethodSymbol m = (MethodSymbol) e.sym;
    1.74 +            Type ret = m.getReturnType();
    1.75 +            if (!(ret.hasTag(ARRAY) && types.isSameType(((ArrayType)ret).elemtype, contained.type))) {
    1.76 +                log.error(pos, "invalid.repeatable.annotation.value.return",
    1.77 +                        container, ret, types.makeArrayType(contained.type));
    1.78 +            }
    1.79 +        } else {
    1.80 +            log.error(pos, "invalid.repeatable.annotation.no.value", container);
    1.81          }
    1.82 -
    1.83 -        if (t == null) {
    1.84 -            log.error(pos, "invalid.container.wrong.containerfor", s, containerFor);
    1.85 -            return;
    1.86 -        }
    1.87 -
    1.88 -        validateHasContainedBy(t.tsym, s, pos);
    1.89 -    }
    1.90 -
    1.91 -    private void validateHasContainedBy(TypeSymbol container, TypeSymbol contained, DiagnosticPosition pos) {
    1.92 -        Attribute.Compound containedBy = container.attribute(syms.containedByType.tsym);
    1.93 -
    1.94 -        if (containedBy == null) {
    1.95 -            log.error(pos, "invalid.container.no.containedby", container, syms.containedByType.tsym);
    1.96 -            return;
    1.97 -        }
    1.98 -
    1.99 -        Type t = null;
   1.100 -        List<Pair<MethodSymbol,Attribute>> l = containedBy.values;
   1.101 -        if (!l.isEmpty()) {
   1.102 -            Assert.check(l.head.fst.name == names.value);
   1.103 -            t = ((Attribute.Class)l.head.snd).getValue();
   1.104 -        }
   1.105 -
   1.106 -        if (t == null) {
   1.107 -            log.error(pos, "invalid.container.wrong.containedby", container, contained);
   1.108 -            return;
   1.109 -        }
   1.110 -
   1.111 -        if (!types.isSameType(t, contained.type))
   1.112 -            log.error(pos, "invalid.container.wrong.containedby", t.tsym, contained);
   1.113 -    }
   1.114 -
   1.115 -    private void validateHasContainerFor(TypeSymbol container, TypeSymbol contained, DiagnosticPosition pos) {
   1.116 -        Attribute.Compound containerFor = container.attribute(syms.containerForType.tsym);
   1.117 -
   1.118 -        if (containerFor == null) {
   1.119 -            log.error(pos, "invalid.container.no.containerfor", container, syms.containerForType.tsym);
   1.120 -            return;
   1.121 -        }
   1.122 -
   1.123 -        Type t = null;
   1.124 -        List<Pair<MethodSymbol,Attribute>> l = containerFor.values;
   1.125 -        if (!l.isEmpty()) {
   1.126 -            Assert.check(l.head.fst.name == names.value);
   1.127 -            t = ((Attribute.Class)l.head.snd).getValue();
   1.128 -        }
   1.129 -
   1.130 -        if (t == null) {
   1.131 -            log.error(pos, "invalid.container.wrong.containerfor", container, contained);
   1.132 -            return;
   1.133 -        }
   1.134 -
   1.135 -        if (!types.isSameType(t, contained.type))
   1.136 -            log.error(pos, "invalid.container.wrong.containerfor", t.tsym, contained);
   1.137      }
   1.138  
   1.139      private void validateRetention(Symbol container, Symbol contained, DiagnosticPosition pos) {
   1.140 @@ -2715,7 +2654,7 @@
   1.141              }
   1.142          }
   1.143          if (error ) {
   1.144 -            log.error(pos, "invalid.containedby.annotation.retention",
   1.145 +            log.error(pos, "invalid.repeatable.annotation.retention",
   1.146                        container, containerRetention,
   1.147                        contained, containedRetention);
   1.148          }
   1.149 @@ -2724,7 +2663,7 @@
   1.150      private void validateDocumented(Symbol container, Symbol contained, DiagnosticPosition pos) {
   1.151          if (contained.attribute(syms.documentedType.tsym) != null) {
   1.152              if (container.attribute(syms.documentedType.tsym) == null) {
   1.153 -                log.error(pos, "invalid.containedby.annotation.not.documented", container, contained);
   1.154 +                log.error(pos, "invalid.repeatable.annotation.not.documented", container, contained);
   1.155              }
   1.156          }
   1.157      }
   1.158 @@ -2732,7 +2671,7 @@
   1.159      private void validateInherited(Symbol container, Symbol contained, DiagnosticPosition pos) {
   1.160          if (contained.attribute(syms.inheritedType.tsym) != null) {
   1.161              if (container.attribute(syms.inheritedType.tsym) == null) {
   1.162 -                log.error(pos, "invalid.containedby.annotation.not.inherited", container, contained);
   1.163 +                log.error(pos, "invalid.repeatable.annotation.not.inherited", container, contained);
   1.164              }
   1.165          }
   1.166      }
   1.167 @@ -2752,7 +2691,7 @@
   1.168          // contained has target, but container has not, error
   1.169          Attribute.Array containerTarget = getAttributeTargetAttribute(container);
   1.170          if (containerTarget == null) {
   1.171 -            log.error(pos, "invalid.containedby.annotation.incompatible.target", container, contained);
   1.172 +            log.error(pos, "invalid.repeatable.annotation.incompatible.target", container, contained);
   1.173              return;
   1.174          }
   1.175  
   1.176 @@ -2775,7 +2714,7 @@
   1.177          }
   1.178  
   1.179          if (!isTargetSubset(containedTargets, containerTargets)) {
   1.180 -            log.error(pos, "invalid.containedby.annotation.incompatible.target", container, contained);
   1.181 +            log.error(pos, "invalid.repeatable.annotation.incompatible.target", container, contained);
   1.182          }
   1.183      }
   1.184  
   1.185 @@ -2809,7 +2748,7 @@
   1.186                  elm.kind == Kinds.MTH &&
   1.187                  ((MethodSymbol)elm).defaultValue == null) {
   1.188                  log.error(pos,
   1.189 -                          "invalid.containedby.annotation.elem.nondefault",
   1.190 +                          "invalid.repeatable.annotation.elem.nondefault",
   1.191                            container,
   1.192                            elm);
   1.193              }

mercurial