langtools/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java
author jjg
Wed, 21 Aug 2013 16:13:50 -0700
changeset 19651 b1aa46cc2198
parent 18010 604faee85350
child 20249 93f8eae31092
permissions -rw-r--r--
8023515: import type-annotations updates Reviewed-by: jjg Contributed-by: wdietl@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     1
/*
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     2
 * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     4
 *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    10
 *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    15
 * accompanied this code).
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    16
 *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    20
 *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    23
 * questions.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    24
 */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    25
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    26
package com.sun.tools.javac.code;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    27
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    28
import javax.lang.model.element.Element;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    29
import javax.lang.model.element.ElementKind;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    30
import javax.lang.model.type.TypeKind;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    31
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
    32
import javax.tools.JavaFileObject;
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
    33
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    34
import com.sun.tools.javac.code.Attribute;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    35
import com.sun.tools.javac.code.Attribute.TypeCompound;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    36
import com.sun.tools.javac.code.Flags;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    37
import com.sun.tools.javac.code.Kinds;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    38
import com.sun.tools.javac.code.Type.AnnotatedType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    39
import com.sun.tools.javac.code.Type.ArrayType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    40
import com.sun.tools.javac.code.Type.CapturedType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    41
import com.sun.tools.javac.code.Type.ClassType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    42
import com.sun.tools.javac.code.Type.ErrorType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    43
import com.sun.tools.javac.code.Type.ForAll;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    44
import com.sun.tools.javac.code.Type.MethodType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    45
import com.sun.tools.javac.code.Type.PackageType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    46
import com.sun.tools.javac.code.Type.TypeVar;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    47
import com.sun.tools.javac.code.Type.UndetVar;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    48
import com.sun.tools.javac.code.Type.Visitor;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    49
import com.sun.tools.javac.code.Type.WildcardType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    50
import com.sun.tools.javac.code.TypeAnnotationPosition.TypePathEntry;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    51
import com.sun.tools.javac.code.TypeAnnotationPosition.TypePathEntryKind;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    52
import com.sun.tools.javac.code.TypeTag;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    53
import com.sun.tools.javac.code.Symbol.VarSymbol;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
    54
import com.sun.tools.javac.code.Symbol.MethodSymbol;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
    55
import com.sun.tools.javac.comp.Annotate;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    56
import com.sun.tools.javac.comp.Annotate.Annotator;
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
    57
import com.sun.tools.javac.comp.AttrContext;
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
    58
import com.sun.tools.javac.comp.Env;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    59
import com.sun.tools.javac.tree.JCTree;
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
    60
import com.sun.tools.javac.tree.TreeInfo;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    61
import com.sun.tools.javac.tree.JCTree.JCBlock;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    62
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    63
import com.sun.tools.javac.tree.JCTree.JCExpression;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
    64
import com.sun.tools.javac.tree.JCTree.JCLambda;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    65
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
    66
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
    67
import com.sun.tools.javac.tree.JCTree.JCNewClass;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    68
import com.sun.tools.javac.tree.JCTree.JCTypeApply;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    69
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    70
import com.sun.tools.javac.tree.TreeScanner;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    71
import com.sun.tools.javac.tree.JCTree.*;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    72
import com.sun.tools.javac.util.Assert;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    73
import com.sun.tools.javac.util.List;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    74
import com.sun.tools.javac.util.ListBuffer;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    75
import com.sun.tools.javac.util.Log;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    76
import com.sun.tools.javac.util.Names;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    77
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    78
/**
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    79
 * Contains operations specific to processing type annotations.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    80
 * This class has two functions:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    81
 * separate declaration from type annotations and insert the type
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    82
 * annotations to their types;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    83
 * and determine the TypeAnnotationPositions for all type annotations.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    84
 */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    85
public class TypeAnnotations {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    86
    // Class cannot be instantiated.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    87
    private TypeAnnotations() {}
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    88
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    89
    /**
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    90
     * Separate type annotations from declaration annotations and
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    91
     * determine the correct positions for type annotations.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    92
     * This version only visits types in signatures and should be
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    93
     * called from MemberEnter.
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
    94
     * The method takes the Annotate object as parameter and
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
    95
     * adds an Annotator to the correct Annotate queue for
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
    96
     * later processing.
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
    97
     */
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
    98
    public static void organizeTypeAnnotationsSignatures(final Symtab syms, final Names names,
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
    99
            final Log log, final Env<AttrContext> env, final JCClassDecl tree, final Annotate annotate) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   100
        annotate.afterRepeated( new Annotator() {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   101
            @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   102
            public void enterAnnotation() {
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
   103
                JavaFileObject oldSource = log.useSource(env.toplevel.sourcefile);
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
   104
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
   105
                try {
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
   106
                    new TypeAnnotationPositions(syms, names, log, true).scan(tree);
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
   107
                } finally {
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
   108
                    log.useSource(oldSource);
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
   109
                }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   110
            }
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   111
        } );
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   112
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   113
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   114
    /**
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   115
     * This version only visits types in bodies, that is, field initializers,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   116
     * top-level blocks, and method bodies, and should be called from Attr.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   117
     */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   118
    public static void organizeTypeAnnotationsBodies(Symtab syms, Names names, Log log, JCClassDecl tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   119
        new TypeAnnotationPositions(syms, names, log, false).scan(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   120
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   121
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   122
    public enum AnnotationType { DECLARATION, TYPE, BOTH };
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   123
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   124
    /**
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   125
     * Determine whether an annotation is a declaration annotation,
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   126
     * a type annotation, or both.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   127
     */
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   128
    public static AnnotationType annotationType(Symtab syms, Names names,
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   129
            Attribute.Compound a, Symbol s) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   130
        Attribute.Compound atTarget =
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   131
            a.type.tsym.attribute(syms.annotationTargetType.tsym);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   132
        if (atTarget == null) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   133
            return inferTargetMetaInfo(a, s);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   134
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   135
        Attribute atValue = atTarget.member(names.value);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   136
        if (!(atValue instanceof Attribute.Array)) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   137
            Assert.error("annotationType(): bad @Target argument " + atValue +
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   138
                    " (" + atValue.getClass() + ")");
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   139
            return AnnotationType.DECLARATION; // error recovery
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   140
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   141
        Attribute.Array arr = (Attribute.Array) atValue;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   142
        boolean isDecl = false, isType = false;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   143
        for (Attribute app : arr.values) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   144
            if (!(app instanceof Attribute.Enum)) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   145
                Assert.error("annotationType(): unrecognized Attribute kind " + app +
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   146
                        " (" + app.getClass() + ")");
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   147
                isDecl = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   148
                continue;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   149
            }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   150
            Attribute.Enum e = (Attribute.Enum) app;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   151
            if (e.value.name == names.TYPE) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   152
                if (s.kind == Kinds.TYP)
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   153
                    isDecl = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   154
            } else if (e.value.name == names.FIELD) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   155
                if (s.kind == Kinds.VAR &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   156
                        s.owner.kind != Kinds.MTH)
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   157
                    isDecl = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   158
            } else if (e.value.name == names.METHOD) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   159
                if (s.kind == Kinds.MTH &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   160
                        !s.isConstructor())
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   161
                    isDecl = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   162
            } else if (e.value.name == names.PARAMETER) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   163
                if (s.kind == Kinds.VAR &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   164
                        s.owner.kind == Kinds.MTH &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   165
                        (s.flags() & Flags.PARAMETER) != 0)
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   166
                    isDecl = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   167
            } else if (e.value.name == names.CONSTRUCTOR) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   168
                if (s.kind == Kinds.MTH &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   169
                        s.isConstructor())
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   170
                    isDecl = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   171
            } else if (e.value.name == names.LOCAL_VARIABLE) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   172
                if (s.kind == Kinds.VAR &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   173
                        s.owner.kind == Kinds.MTH &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   174
                        (s.flags() & Flags.PARAMETER) == 0)
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   175
                    isDecl = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   176
            } else if (e.value.name == names.ANNOTATION_TYPE) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   177
                if (s.kind == Kinds.TYP &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   178
                        (s.flags() & Flags.ANNOTATION) != 0)
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   179
                    isDecl = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   180
            } else if (e.value.name == names.PACKAGE) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   181
                if (s.kind == Kinds.PCK)
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   182
                    isDecl = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   183
            } else if (e.value.name == names.TYPE_USE) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   184
                if (s.kind == Kinds.TYP ||
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   185
                        s.kind == Kinds.VAR ||
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   186
                        (s.kind == Kinds.MTH && !s.isConstructor() &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   187
                        !s.type.getReturnType().hasTag(TypeTag.VOID)) ||
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   188
                        (s.kind == Kinds.MTH && s.isConstructor()))
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   189
                    isType = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   190
            } else if (e.value.name == names.TYPE_PARAMETER) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   191
                /* Irrelevant in this case */
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   192
                // TYPE_PARAMETER doesn't aid in distinguishing between
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   193
                // Type annotations and declaration annotations on an
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   194
                // Element
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   195
            } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   196
                Assert.error("annotationType(): unrecognized Attribute name " + e.value.name +
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   197
                        " (" + e.value.name.getClass() + ")");
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   198
                isDecl = true;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   199
            }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   200
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   201
        if (isDecl && isType) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   202
            return AnnotationType.BOTH;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   203
        } else if (isType) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   204
            return AnnotationType.TYPE;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   205
        } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   206
            return AnnotationType.DECLARATION;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   207
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   208
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   209
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   210
    /** Infer the target annotation kind, if none is give.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   211
     * We only infer declaration annotations.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   212
     */
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   213
    private static AnnotationType inferTargetMetaInfo(Attribute.Compound a, Symbol s) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   214
        return AnnotationType.DECLARATION;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   215
    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   216
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   217
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   218
    private static class TypeAnnotationPositions extends TreeScanner {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   219
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   220
        private final Symtab syms;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   221
        private final Names names;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   222
        private final Log log;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   223
        private final boolean sigOnly;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   224
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   225
        private TypeAnnotationPositions(Symtab syms, Names names, Log log, boolean sigOnly) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   226
            this.syms = syms;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   227
            this.names = names;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   228
            this.log = log;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   229
            this.sigOnly = sigOnly;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   230
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   231
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   232
        /*
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   233
         * When traversing the AST we keep the "frames" of visited
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   234
         * trees in order to determine the position of annotations.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   235
         */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   236
        private ListBuffer<JCTree> frames = ListBuffer.lb();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   237
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   238
        protected void push(JCTree t) { frames = frames.prepend(t); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   239
        protected JCTree pop() { return frames.next(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   240
        // could this be frames.elems.tail.head?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   241
        private JCTree peek2() { return frames.toList().tail.head; }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   242
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   243
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   244
        public void scan(JCTree tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   245
            push(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   246
            super.scan(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   247
            pop();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   248
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   249
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   250
        /**
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   251
         * Separates type annotations from declaration annotations.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   252
         * This step is needed because in certain locations (where declaration
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   253
         * and type annotations can be mixed, e.g. the type of a field)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   254
         * we never build an JCAnnotatedType. This step finds these
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   255
         * annotations and marks them as if they were part of the type.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   256
         */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   257
        private void separateAnnotationsKinds(JCTree typetree, Type type, Symbol sym,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   258
                TypeAnnotationPosition pos) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   259
            /*
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   260
            System.out.printf("separateAnnotationsKinds(typetree: %s, type: %s, symbol: %s, pos: %s%n",
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   261
                    typetree, type, sym, pos);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   262
            */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   263
            List<Attribute.Compound> annotations = sym.getRawAttributes();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   264
            ListBuffer<Attribute.Compound> declAnnos = new ListBuffer<Attribute.Compound>();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   265
            ListBuffer<Attribute.TypeCompound> typeAnnos = new ListBuffer<Attribute.TypeCompound>();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   266
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   267
            for (Attribute.Compound a : annotations) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   268
                switch (annotationType(syms, names, a, sym)) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   269
                case DECLARATION:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   270
                    declAnnos.append(a);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   271
                    break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   272
                case BOTH: {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   273
                    declAnnos.append(a);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   274
                    Attribute.TypeCompound ta = toTypeCompound(a, pos);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   275
                    typeAnnos.append(ta);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   276
                    break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   277
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   278
                case TYPE: {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   279
                    Attribute.TypeCompound ta = toTypeCompound(a, pos);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   280
                    typeAnnos.append(ta);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   281
                    break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   282
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   283
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   284
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   285
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
   286
            sym.resetAnnotations();
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
   287
            sym.setDeclarationAttributes(declAnnos.toList());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   288
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   289
            if (typeAnnos.isEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   290
                return;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   291
            }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   292
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   293
            List<Attribute.TypeCompound> typeAnnotations = typeAnnos.toList();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   294
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   295
            if (type == null) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   296
                // When type is null, put the type annotations to the symbol.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   297
                // This is used for constructor return annotations, for which
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   298
                // no appropriate type exists.
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
   299
                sym.appendUniqueTypeAttributes(typeAnnotations);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   300
                return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   301
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   302
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   303
            // type is non-null and annotations are added to that type
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   304
            type = typeWithAnnotations(typetree, type, typeAnnotations, log);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   305
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   306
            if (sym.getKind() == ElementKind.METHOD) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   307
                sym.type.asMethodType().restype = type;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   308
            } else if (sym.getKind() == ElementKind.PARAMETER) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   309
                sym.type = type;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   310
                if (sym.getQualifiedName().equals(names._this)) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   311
                    sym.owner.type.asMethodType().recvtype = type;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   312
                    // note that the typeAnnotations will also be added to the owner below.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   313
                } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   314
                    MethodType methType = sym.owner.type.asMethodType();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   315
                    List<VarSymbol> params = ((MethodSymbol)sym.owner).params;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   316
                    List<Type> oldArgs = methType.argtypes;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   317
                    ListBuffer<Type> newArgs = new ListBuffer<Type>();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   318
                    while (params.nonEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   319
                        if (params.head == sym) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   320
                            newArgs.add(type);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   321
                        } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   322
                            newArgs.add(oldArgs.head);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   323
                        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   324
                        oldArgs = oldArgs.tail;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   325
                        params = params.tail;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   326
                    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   327
                    methType.argtypes = newArgs.toList();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   328
                }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   329
            } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   330
                sym.type = type;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   331
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   332
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
   333
            sym.appendUniqueTypeAttributes(typeAnnotations);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   334
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   335
            if (sym.getKind() == ElementKind.PARAMETER ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   336
                    sym.getKind() == ElementKind.LOCAL_VARIABLE ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   337
                    sym.getKind() == ElementKind.RESOURCE_VARIABLE ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   338
                    sym.getKind() == ElementKind.EXCEPTION_PARAMETER) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   339
                // Make sure all type annotations from the symbol are also
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   340
                // on the owner.
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
   341
                sym.owner.appendUniqueTypeAttributes(sym.getRawTypeAttributes());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   342
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   343
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   344
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   345
        // This method has a similar purpose as
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   346
        // {@link com.sun.tools.javac.parser.JavacParser.insertAnnotationsToMostInner(JCExpression, List<JCTypeAnnotation>, boolean)}
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   347
        // We found a type annotation in a declaration annotation position,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   348
        // for example, on the return type.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   349
        // Such an annotation is _not_ part of an JCAnnotatedType tree and we therefore
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   350
        // need to set its position explicitly.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   351
        // The method returns a copy of type that contains these annotations.
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   352
        //
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   353
        // As a side effect the method sets the type annotation position of "annotations".
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   354
        // Note that it is assumed that all annotations share the same position.
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   355
        private static Type typeWithAnnotations(final JCTree typetree, final Type type,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   356
                final List<Attribute.TypeCompound> annotations, Log log) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   357
            // System.out.printf("typeWithAnnotations(typetree: %s, type: %s, annotations: %s)%n",
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   358
            //         typetree, type, annotations);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   359
            if (annotations.isEmpty()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   360
                return type;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   361
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   362
            if (type.hasTag(TypeTag.ARRAY)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   363
                Type toreturn;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   364
                Type.ArrayType tomodify;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   365
                Type.ArrayType arType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   366
                {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   367
                    Type touse = type;
16556
f4adc5bb4652 8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents: 15718
diff changeset
   368
                    if (type.isAnnotated()) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   369
                        Type.AnnotatedType atype = (Type.AnnotatedType)type;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   370
                        toreturn = new Type.AnnotatedType(atype.underlyingType);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   371
                        ((Type.AnnotatedType)toreturn).typeAnnotations = atype.typeAnnotations;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   372
                        touse = atype.underlyingType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   373
                        arType = (Type.ArrayType) touse;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   374
                        tomodify = new Type.ArrayType(null, arType.tsym);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   375
                        ((Type.AnnotatedType)toreturn).underlyingType = tomodify;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   376
                    } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   377
                        arType = (Type.ArrayType) touse;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   378
                        tomodify = new Type.ArrayType(null, arType.tsym);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   379
                        toreturn = tomodify;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   380
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   381
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   382
                JCArrayTypeTree arTree = arrayTypeTree(typetree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   383
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   384
                ListBuffer<TypePathEntry> depth = ListBuffer.lb();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   385
                depth = depth.append(TypePathEntry.ARRAY);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   386
                while (arType.elemtype.hasTag(TypeTag.ARRAY)) {
16556
f4adc5bb4652 8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents: 15718
diff changeset
   387
                    if (arType.elemtype.isAnnotated()) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   388
                        Type.AnnotatedType aelemtype = (Type.AnnotatedType) arType.elemtype;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   389
                        Type.AnnotatedType newAT = new Type.AnnotatedType(aelemtype.underlyingType);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   390
                        tomodify.elemtype = newAT;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   391
                        newAT.typeAnnotations = aelemtype.typeAnnotations;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   392
                        arType = (Type.ArrayType) aelemtype.underlyingType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   393
                        tomodify = new Type.ArrayType(null, arType.tsym);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   394
                        newAT.underlyingType = tomodify;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   395
                    } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   396
                        arType = (Type.ArrayType) arType.elemtype;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   397
                        tomodify.elemtype = new Type.ArrayType(null, arType.tsym);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   398
                        tomodify = (Type.ArrayType) tomodify.elemtype;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   399
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   400
                    arTree = arrayTypeTree(arTree.elemtype);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   401
                    depth = depth.append(TypePathEntry.ARRAY);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   402
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   403
                Type arelemType = typeWithAnnotations(arTree.elemtype, arType.elemtype, annotations, log);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   404
                tomodify.elemtype = arelemType;
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   405
                {
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   406
                    // All annotations share the same position; modify the first one.
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   407
                    Attribute.TypeCompound a = annotations.get(0);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   408
                    TypeAnnotationPosition p = a.position;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   409
                    p.location = p.location.prependList(depth.toList());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   410
                }
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   411
                typetree.type = toreturn;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   412
                return toreturn;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   413
            } else if (type.hasTag(TypeTag.TYPEVAR)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   414
                // Nothing to do for type variables.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   415
                return type;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   416
            } else if (type.getKind() == TypeKind.UNION) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   417
                // There is a TypeKind, but no TypeTag.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   418
                JCTypeUnion tutree = (JCTypeUnion) typetree;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   419
                JCExpression fst = tutree.alternatives.get(0);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   420
                Type res = typeWithAnnotations(fst, fst.type, annotations, log);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   421
                fst.type = res;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   422
                // TODO: do we want to set res as first element in uct.alternatives?
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   423
                // UnionClassType uct = (com.sun.tools.javac.code.Type.UnionClassType)type;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   424
                // Return the un-annotated union-type.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   425
                return type;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   426
            } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   427
                Type enclTy = type;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   428
                Element enclEl = type.asElement();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   429
                JCTree enclTr = typetree;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   430
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   431
                while (enclEl != null &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   432
                        enclEl.getKind() != ElementKind.PACKAGE &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   433
                        enclTy != null &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   434
                        enclTy.getKind() != TypeKind.NONE &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   435
                        enclTy.getKind() != TypeKind.ERROR &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   436
                        (enclTr.getKind() == JCTree.Kind.MEMBER_SELECT ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   437
                         enclTr.getKind() == JCTree.Kind.PARAMETERIZED_TYPE ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   438
                         enclTr.getKind() == JCTree.Kind.ANNOTATED_TYPE)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   439
                    // Iterate also over the type tree, not just the type: the type is already
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   440
                    // completely resolved and we cannot distinguish where the annotation
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   441
                    // belongs for a nested type.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   442
                    if (enclTr.getKind() == JCTree.Kind.MEMBER_SELECT) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   443
                        // only change encl in this case.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   444
                        enclTy = enclTy.getEnclosingType();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   445
                        enclEl = enclEl.getEnclosingElement();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   446
                        enclTr = ((JCFieldAccess)enclTr).getExpression();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   447
                    } else if (enclTr.getKind() == JCTree.Kind.PARAMETERIZED_TYPE) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   448
                        enclTr = ((JCTypeApply)enclTr).getType();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   449
                    } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   450
                        // only other option because of while condition
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   451
                        enclTr = ((JCAnnotatedType)enclTr).getUnderlyingType();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   452
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   453
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   454
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   455
                /** We are trying to annotate some enclosing type,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   456
                 * but nothing more exists.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   457
                 */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   458
                if (enclTy != null &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   459
                        enclTy.getKind() == TypeKind.NONE &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   460
                        (enclTr.getKind() == JCTree.Kind.IDENTIFIER ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   461
                         enclTr.getKind() == JCTree.Kind.MEMBER_SELECT ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   462
                         enclTr.getKind() == JCTree.Kind.PARAMETERIZED_TYPE ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   463
                         enclTr.getKind() == JCTree.Kind.ANNOTATED_TYPE)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   464
                    // TODO: also if it's "java. @A lang.Object", that is,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   465
                    // if it's on a package?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   466
                    log.error(enclTr.pos(), "cant.annotate.nested.type", enclTr.toString());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   467
                    return type;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   468
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   469
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   470
                // At this point we have visited the part of the nested
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   471
                // type that is written in the source code.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   472
                // Now count from here to the actual top-level class to determine
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   473
                // the correct nesting.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   474
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   475
                // The genericLocation for the annotation.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   476
                ListBuffer<TypePathEntry> depth = ListBuffer.lb();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   477
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   478
                Type topTy = enclTy;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   479
                while (enclEl != null &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   480
                        enclEl.getKind() != ElementKind.PACKAGE &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   481
                        topTy != null &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   482
                        topTy.getKind() != TypeKind.NONE &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   483
                        topTy.getKind() != TypeKind.ERROR) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   484
                    topTy = topTy.getEnclosingType();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   485
                    enclEl = enclEl.getEnclosingElement();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   486
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   487
                    if (topTy != null && topTy.getKind() != TypeKind.NONE) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   488
                        // Only count enclosing types.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   489
                        depth = depth.append(TypePathEntry.INNER_TYPE);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   490
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   491
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   492
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   493
                if (depth.nonEmpty()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   494
                    // Only need to change the annotation positions
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   495
                    // if they are on an enclosed type.
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   496
                    // All annotations share the same position; modify the first one.
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   497
                    Attribute.TypeCompound a = annotations.get(0);
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   498
                    TypeAnnotationPosition p = a.position;
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   499
                    p.location = p.location.appendList(depth.toList());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   500
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   501
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   502
                Type ret = typeWithAnnotations(type, enclTy, annotations);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   503
                typetree.type = ret;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   504
                return ret;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   505
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   506
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   507
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   508
        private static JCArrayTypeTree arrayTypeTree(JCTree typetree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   509
            if (typetree.getKind() == JCTree.Kind.ARRAY_TYPE) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   510
                return (JCArrayTypeTree) typetree;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   511
            } else if (typetree.getKind() == JCTree.Kind.ANNOTATED_TYPE) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   512
                return (JCArrayTypeTree) ((JCAnnotatedType)typetree).underlyingType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   513
            } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   514
                Assert.error("Could not determine array type from type tree: " + typetree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   515
                return null;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   516
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   517
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   518
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   519
        /** Return a copy of the first type that only differs by
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   520
         * inserting the annotations to the left-most/inner-most type
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   521
         * or the type given by stopAt.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   522
         *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   523
         * We need the stopAt parameter to know where on a type to
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   524
         * put the annotations.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   525
         * If we have nested classes Outer > Middle > Inner, and we
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   526
         * have the source type "@A Middle.Inner", we will invoke
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   527
         * this method with type = Outer.Middle.Inner,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   528
         * stopAt = Middle.Inner, and annotations = @A.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   529
         *
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   530
         * @param type The type to copy.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   531
         * @param stopAt The type to stop at.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   532
         * @param annotations The annotations to insert.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   533
         * @return A copy of type that contains the annotations.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   534
         */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   535
        private static Type typeWithAnnotations(final Type type,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   536
                final Type stopAt,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   537
                final List<Attribute.TypeCompound> annotations) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   538
            Visitor<Type, List<TypeCompound>> visitor =
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   539
                    new Type.Visitor<Type, List<Attribute.TypeCompound>>() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   540
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   541
                public Type visitClassType(ClassType t, List<TypeCompound> s) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   542
                    // assert that t.constValue() == null?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   543
                    if (t == stopAt ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   544
                        t.getEnclosingType() == Type.noType) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   545
                        return new AnnotatedType(s, t);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   546
                    } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   547
                        ClassType ret = new ClassType(t.getEnclosingType().accept(this, s),
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   548
                                t.typarams_field, t.tsym);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   549
                        ret.all_interfaces_field = t.all_interfaces_field;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   550
                        ret.allparams_field = t.allparams_field;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   551
                        ret.interfaces_field = t.interfaces_field;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   552
                        ret.rank_field = t.rank_field;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   553
                        ret.supertype_field = t.supertype_field;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   554
                        return ret;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   555
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   556
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   557
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   558
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   559
                public Type visitAnnotatedType(AnnotatedType t, List<TypeCompound> s) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   560
                    return new AnnotatedType(t.typeAnnotations, t.underlyingType.accept(this, s));
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   561
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   562
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   563
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   564
                public Type visitWildcardType(WildcardType t, List<TypeCompound> s) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   565
                    return new AnnotatedType(s, t);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   566
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   567
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   568
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   569
                public Type visitArrayType(ArrayType t, List<TypeCompound> s) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   570
                    ArrayType ret = new ArrayType(t.elemtype.accept(this, s), t.tsym);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   571
                    return ret;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   572
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   573
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   574
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   575
                public Type visitMethodType(MethodType t, List<TypeCompound> s) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   576
                    // Impossible?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   577
                    return t;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   578
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   579
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   580
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   581
                public Type visitPackageType(PackageType t, List<TypeCompound> s) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   582
                    // Impossible?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   583
                    return t;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   584
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   585
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   586
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   587
                public Type visitTypeVar(TypeVar t, List<TypeCompound> s) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   588
                    return new AnnotatedType(s, t);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   589
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   590
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   591
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   592
                public Type visitCapturedType(CapturedType t, List<TypeCompound> s) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   593
                    return new AnnotatedType(s, t);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   594
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   595
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   596
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   597
                public Type visitForAll(ForAll t, List<TypeCompound> s) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   598
                    // Impossible?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   599
                    return t;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   600
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   601
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   602
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   603
                public Type visitUndetVar(UndetVar t, List<TypeCompound> s) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   604
                    // Impossible?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   605
                    return t;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   606
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   607
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   608
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   609
                public Type visitErrorType(ErrorType t, List<TypeCompound> s) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   610
                    return new AnnotatedType(s, t);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   611
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   612
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   613
                @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   614
                public Type visitType(Type t, List<TypeCompound> s) {
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   615
                    return new AnnotatedType(s, t);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   616
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   617
            };
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   618
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   619
            return type.accept(visitor, annotations);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   620
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   621
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   622
        private static Attribute.TypeCompound toTypeCompound(Attribute.Compound a, TypeAnnotationPosition p) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   623
            // It is safe to alias the position.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   624
            return new Attribute.TypeCompound(a, p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   625
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   626
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   627
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   628
        /* This is the beginning of the second part of organizing
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   629
         * type annotations: determine the type annotation positions.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   630
         */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   631
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   632
        private void resolveFrame(JCTree tree, JCTree frame,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   633
                List<JCTree> path, TypeAnnotationPosition p) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   634
            /*
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   635
            System.out.println("Resolving tree: " + tree + " kind: " + tree.getKind());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   636
            System.out.println("    Framing tree: " + frame + " kind: " + frame.getKind());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   637
            */
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   638
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   639
            // Note that p.offset is set in
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   640
            // com.sun.tools.javac.jvm.Gen.setTypeAnnotationPositions(int)
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   641
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   642
            switch (frame.getKind()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   643
                case TYPE_CAST:
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   644
                    JCTypeCast frameTC = (JCTypeCast) frame;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   645
                    p.type = TargetType.CAST;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   646
                    if (frameTC.clazz.hasTag(Tag.TYPEINTERSECTION)) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   647
                        // This case was already handled by INTERSECTION_TYPE
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   648
                    } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   649
                        p.type_index = 0;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   650
                    }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   651
                    p.pos = frame.pos;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   652
                    return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   653
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   654
                case INSTANCE_OF:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   655
                    p.type = TargetType.INSTANCEOF;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   656
                    p.pos = frame.pos;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   657
                    return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   658
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   659
                case NEW_CLASS:
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   660
                    JCNewClass frameNewClass = (JCNewClass) frame;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   661
                    if (frameNewClass.def != null) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   662
                        // Special handling for anonymous class instantiations
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   663
                        JCClassDecl frameClassDecl = frameNewClass.def;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   664
                        if (frameClassDecl.extending == tree) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   665
                            p.type = TargetType.CLASS_EXTENDS;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   666
                            p.type_index = -1;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   667
                        } else if (frameClassDecl.implementing.contains(tree)) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   668
                            p.type = TargetType.CLASS_EXTENDS;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   669
                            p.type_index = frameClassDecl.implementing.indexOf(tree);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   670
                        } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   671
                            // In contrast to CLASS below, typarams cannot occur here.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   672
                            Assert.error("Could not determine position of tree " + tree +
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   673
                                    " within frame " + frame);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   674
                        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   675
                    } else if (frameNewClass.typeargs.contains(tree)) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   676
                        p.type = TargetType.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   677
                        p.type_index = frameNewClass.typeargs.indexOf(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   678
                    } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   679
                        p.type = TargetType.NEW;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   680
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   681
                    p.pos = frame.pos;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   682
                    return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   683
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   684
                case NEW_ARRAY:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   685
                    p.type = TargetType.NEW;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   686
                    p.pos = frame.pos;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   687
                    return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   688
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   689
                case ANNOTATION_TYPE:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   690
                case CLASS:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   691
                case ENUM:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   692
                case INTERFACE:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   693
                    p.pos = frame.pos;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   694
                    if (((JCClassDecl)frame).extending == tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   695
                        p.type = TargetType.CLASS_EXTENDS;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   696
                        p.type_index = -1;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   697
                    } else if (((JCClassDecl)frame).implementing.contains(tree)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   698
                        p.type = TargetType.CLASS_EXTENDS;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   699
                        p.type_index = ((JCClassDecl)frame).implementing.indexOf(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   700
                    } else if (((JCClassDecl)frame).typarams.contains(tree)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   701
                        p.type = TargetType.CLASS_TYPE_PARAMETER;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   702
                        p.parameter_index = ((JCClassDecl)frame).typarams.indexOf(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   703
                    } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   704
                        Assert.error("Could not determine position of tree " + tree +
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   705
                                " within frame " + frame);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   706
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   707
                    return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   708
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   709
                case METHOD: {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   710
                    JCMethodDecl frameMethod = (JCMethodDecl) frame;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   711
                    p.pos = frame.pos;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   712
                    if (frameMethod.thrown.contains(tree)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   713
                        p.type = TargetType.THROWS;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   714
                        p.type_index = frameMethod.thrown.indexOf(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   715
                    } else if (frameMethod.restype == tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   716
                        p.type = TargetType.METHOD_RETURN;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   717
                    } else if (frameMethod.typarams.contains(tree)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   718
                        p.type = TargetType.METHOD_TYPE_PARAMETER;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   719
                        p.parameter_index = frameMethod.typarams.indexOf(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   720
                    } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   721
                        Assert.error("Could not determine position of tree " + tree +
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   722
                                " within frame " + frame);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   723
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   724
                    return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   725
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   726
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   727
                case PARAMETERIZED_TYPE: {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   728
                    List<JCTree> newPath = path.tail;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   729
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   730
                    if (((JCTypeApply)frame).clazz == tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   731
                        // generic: RAW; noop
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   732
                    } else if (((JCTypeApply)frame).arguments.contains(tree)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   733
                        JCTypeApply taframe = (JCTypeApply) frame;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   734
                        int arg = taframe.arguments.indexOf(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   735
                        p.location = p.location.prepend(new TypePathEntry(TypePathEntryKind.TYPE_ARGUMENT, arg));
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   736
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   737
                        Type typeToUse;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   738
                        if (newPath.tail != null && newPath.tail.head.hasTag(Tag.NEWCLASS)) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   739
                            // If we are within an anonymous class instantiation, use its type,
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   740
                            // because it contains a correctly nested type.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   741
                            typeToUse = newPath.tail.head.type;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   742
                        } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   743
                            typeToUse = taframe.type;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   744
                        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   745
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   746
                        locateNestedTypes(typeToUse, p);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   747
                    } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   748
                        Assert.error("Could not determine type argument position of tree " + tree +
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   749
                                " within frame " + frame);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   750
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   751
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   752
                    resolveFrame(newPath.head, newPath.tail.head, newPath, p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   753
                    return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   754
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   755
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   756
                case MEMBER_REFERENCE: {
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   757
                    JCMemberReference mrframe = (JCMemberReference) frame;
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   758
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   759
                    if (mrframe.expr == tree) {
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   760
                        switch (mrframe.mode) {
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   761
                        case INVOKE:
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   762
                            p.type = TargetType.METHOD_REFERENCE;
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   763
                            break;
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   764
                        case NEW:
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   765
                            p.type = TargetType.CONSTRUCTOR_REFERENCE;
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   766
                            break;
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   767
                        default:
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   768
                            Assert.error("Unknown method reference mode " + mrframe.mode +
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   769
                                    " for tree " + tree + " within frame " + frame);
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   770
                        }
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   771
                        p.pos = frame.pos;
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   772
                    } else if (mrframe.typeargs != null &&
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   773
                            mrframe.typeargs.contains(tree)) {
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   774
                        int arg = mrframe.typeargs.indexOf(tree);
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   775
                        p.type_index = arg;
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   776
                        switch (mrframe.mode) {
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   777
                        case INVOKE:
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   778
                            p.type = TargetType.METHOD_REFERENCE_TYPE_ARGUMENT;
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   779
                            break;
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   780
                        case NEW:
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   781
                            p.type = TargetType.CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT;
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   782
                            break;
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   783
                        default:
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   784
                            Assert.error("Unknown method reference mode " + mrframe.mode +
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   785
                                    " for tree " + tree + " within frame " + frame);
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   786
                        }
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   787
                        p.pos = frame.pos;
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   788
                    } else {
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   789
                        Assert.error("Could not determine type argument position of tree " + tree +
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   790
                                " within frame " + frame);
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   791
                    }
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   792
                    return;
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   793
                }
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   794
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   795
                case ARRAY_TYPE: {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   796
                    ListBuffer<TypePathEntry> index = ListBuffer.lb();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   797
                    index = index.append(TypePathEntry.ARRAY);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   798
                    List<JCTree> newPath = path.tail;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   799
                    while (true) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   800
                        JCTree npHead = newPath.tail.head;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   801
                        if (npHead.hasTag(JCTree.Tag.TYPEARRAY)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   802
                            newPath = newPath.tail;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   803
                            index = index.append(TypePathEntry.ARRAY);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   804
                        } else if (npHead.hasTag(JCTree.Tag.ANNOTATED_TYPE)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   805
                            newPath = newPath.tail;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   806
                        } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   807
                            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   808
                        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   809
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   810
                    p.location = p.location.prependList(index.toList());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   811
                    resolveFrame(newPath.head, newPath.tail.head, newPath, p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   812
                    return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   813
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   814
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   815
                case TYPE_PARAMETER:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   816
                    if (path.tail.tail.head.hasTag(JCTree.Tag.CLASSDEF)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   817
                        JCClassDecl clazz = (JCClassDecl)path.tail.tail.head;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   818
                        p.type = TargetType.CLASS_TYPE_PARAMETER_BOUND;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   819
                        p.parameter_index = clazz.typarams.indexOf(path.tail.head);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   820
                        p.bound_index = ((JCTypeParameter)frame).bounds.indexOf(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   821
                        if (((JCTypeParameter)frame).bounds.get(0).type.isInterface()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   822
                            // Account for an implicit Object as bound 0
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   823
                            p.bound_index += 1;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   824
                        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   825
                    } else if (path.tail.tail.head.hasTag(JCTree.Tag.METHODDEF)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   826
                        JCMethodDecl method = (JCMethodDecl)path.tail.tail.head;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   827
                        p.type = TargetType.METHOD_TYPE_PARAMETER_BOUND;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   828
                        p.parameter_index = method.typarams.indexOf(path.tail.head);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   829
                        p.bound_index = ((JCTypeParameter)frame).bounds.indexOf(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   830
                        if (((JCTypeParameter)frame).bounds.get(0).type.isInterface()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   831
                            // Account for an implicit Object as bound 0
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   832
                            p.bound_index += 1;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   833
                        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   834
                    } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   835
                        Assert.error("Could not determine position of tree " + tree +
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   836
                                " within frame " + frame);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   837
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   838
                    p.pos = frame.pos;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   839
                    return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   840
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   841
                case VARIABLE:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   842
                    VarSymbol v = ((JCVariableDecl)frame).sym;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   843
                    p.pos = frame.pos;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   844
                    switch (v.getKind()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   845
                        case LOCAL_VARIABLE:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   846
                            p.type = TargetType.LOCAL_VARIABLE;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   847
                            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   848
                        case FIELD:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   849
                            p.type = TargetType.FIELD;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   850
                            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   851
                        case PARAMETER:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   852
                            if (v.getQualifiedName().equals(names._this)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   853
                                // TODO: Intro a separate ElementKind?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   854
                                p.type = TargetType.METHOD_RECEIVER;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   855
                            } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   856
                                p.type = TargetType.METHOD_FORMAL_PARAMETER;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   857
                                p.parameter_index = methodParamIndex(path, frame);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   858
                            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   859
                            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   860
                        case EXCEPTION_PARAMETER:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   861
                            p.type = TargetType.EXCEPTION_PARAMETER;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   862
                            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   863
                        case RESOURCE_VARIABLE:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   864
                            p.type = TargetType.RESOURCE_VARIABLE;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   865
                            break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   866
                        default:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   867
                            Assert.error("Found unexpected type annotation for variable: " + v + " with kind: " + v.getKind());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   868
                    }
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   869
                    if (v.getKind() != ElementKind.FIELD) {
18010
604faee85350 8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents: 17578
diff changeset
   870
                        v.owner.appendUniqueTypeAttributes(v.getRawTypeAttributes());
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   871
                    }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   872
                    return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   873
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   874
                case ANNOTATED_TYPE: {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   875
                    if (frame == tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   876
                        // This is only true for the first annotated type we see.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   877
                        // For any other annotated types along the path, we do
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   878
                        // not care about inner types.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   879
                        JCAnnotatedType atypetree = (JCAnnotatedType) frame;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   880
                        final Type utype = atypetree.underlyingType.type;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   881
                        if (utype == null) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   882
                            // This might happen during DeferredAttr;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   883
                            // we will be back later.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   884
                            return;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   885
                        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   886
                        Symbol tsym = utype.tsym;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   887
                        if (tsym.getKind().equals(ElementKind.TYPE_PARAMETER) ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   888
                                utype.getKind().equals(TypeKind.WILDCARD) ||
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   889
                                utype.getKind().equals(TypeKind.ARRAY)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   890
                            // Type parameters, wildcards, and arrays have the declaring
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   891
                            // class/method as enclosing elements.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   892
                            // There is actually nothing to do for them.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   893
                        } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   894
                            locateNestedTypes(utype, p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   895
                        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   896
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   897
                    List<JCTree> newPath = path.tail;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   898
                    resolveFrame(newPath.head, newPath.tail.head, newPath, p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   899
                    return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   900
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   901
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   902
                case UNION_TYPE: {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   903
                    List<JCTree> newPath = path.tail;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   904
                    resolveFrame(newPath.head, newPath.tail.head, newPath, p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   905
                    return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   906
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   907
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   908
                case INTERSECTION_TYPE: {
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   909
                    JCTypeIntersection isect = (JCTypeIntersection)frame;
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   910
                    p.type_index = isect.bounds.indexOf(tree);
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   911
                    List<JCTree> newPath = path.tail;
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   912
                    resolveFrame(newPath.head, newPath.tail.head, newPath, p);
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   913
                    return;
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   914
                }
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
   915
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   916
                case METHOD_INVOCATION: {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   917
                    JCMethodInvocation invocation = (JCMethodInvocation)frame;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   918
                    if (!invocation.typeargs.contains(tree)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   919
                        Assert.error("{" + tree + "} is not an argument in the invocation: " + invocation);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   920
                    }
19651
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
   921
                    MethodSymbol exsym = (MethodSymbol) TreeInfo.symbol(invocation.getMethodSelect());
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
   922
                    if (exsym == null) {
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
   923
                        Assert.error("could not determine symbol for {" + invocation + "}");
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
   924
                    } else if (exsym.isConstructor()) {
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
   925
                        p.type = TargetType.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT;
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
   926
                    } else {
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
   927
                        p.type = TargetType.METHOD_INVOCATION_TYPE_ARGUMENT;
b1aa46cc2198 8023515: import type-annotations updates
jjg
parents: 18010
diff changeset
   928
                    }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   929
                    p.pos = invocation.pos;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   930
                    p.type_index = invocation.typeargs.indexOf(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   931
                    return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   932
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   933
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   934
                case EXTENDS_WILDCARD:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   935
                case SUPER_WILDCARD: {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   936
                    // Annotations in wildcard bounds
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   937
                    p.location = p.location.prepend(TypePathEntry.WILDCARD);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   938
                    List<JCTree> newPath = path.tail;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   939
                    resolveFrame(newPath.head, newPath.tail.head, newPath, p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   940
                    return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   941
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   942
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   943
                case MEMBER_SELECT: {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   944
                    List<JCTree> newPath = path.tail;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   945
                    resolveFrame(newPath.head, newPath.tail.head, newPath, p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   946
                    return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   947
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   948
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   949
                default:
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   950
                    Assert.error("Unresolved frame: " + frame + " of kind: " + frame.getKind() +
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   951
                            "\n    Looking for tree: " + tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   952
                    return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   953
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   954
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   955
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   956
        private static void locateNestedTypes(Type type, TypeAnnotationPosition p) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   957
            // The number of "steps" to get from the full type to the
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   958
            // left-most outer type.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   959
            ListBuffer<TypePathEntry> depth = ListBuffer.lb();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   960
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   961
            Type encl = type.getEnclosingType();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   962
            while (encl != null &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   963
                    encl.getKind() != TypeKind.NONE &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   964
                    encl.getKind() != TypeKind.ERROR) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   965
                depth = depth.append(TypePathEntry.INNER_TYPE);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   966
                encl = encl.getEnclosingType();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   967
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   968
            if (depth.nonEmpty()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   969
                p.location = p.location.prependList(depth.toList());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   970
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   971
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   972
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   973
        private static int methodParamIndex(List<JCTree> path, JCTree param) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   974
            List<JCTree> curr = path;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   975
            while (curr.head.getTag() != Tag.METHODDEF &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   976
                    curr.head.getTag() != Tag.LAMBDA) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   977
                curr = curr.tail;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   978
            }
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   979
            if (curr.head.getTag() == Tag.METHODDEF) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   980
                JCMethodDecl method = (JCMethodDecl)curr.head;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   981
                return method.params.indexOf(param);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   982
            } else if (curr.head.getTag() == Tag.LAMBDA) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   983
                JCLambda lambda = (JCLambda)curr.head;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   984
                return lambda.params.indexOf(param);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   985
            } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   986
                Assert.error("methodParamIndex expected to find method or lambda for param: " + param);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   987
                return -1;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
   988
            }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   989
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   990
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   991
        // Each class (including enclosed inner classes) is visited separately.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   992
        // This flag is used to prevent from visiting inner classes.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   993
        private boolean isInClass = false;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   994
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   995
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   996
        public void visitClassDef(JCClassDecl tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   997
            if (isInClass)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   998
                return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
   999
            isInClass = true;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1000
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1001
            if (sigOnly) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1002
                scan(tree.mods);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1003
                scan(tree.typarams);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1004
                scan(tree.extending);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1005
                scan(tree.implementing);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1006
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1007
            scan(tree.defs);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1008
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1009
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1010
        /**
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1011
         * Resolve declaration vs. type annotations in methods and
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1012
         * then determine the positions.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1013
         */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1014
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1015
        public void visitMethodDef(final JCMethodDecl tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1016
            if (tree.sym == null) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1017
                // Something most be wrong, e.g. a class not found.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1018
                // Quietly ignore. (See test FailOver15.java)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1019
                return;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1020
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1021
            if (sigOnly) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1022
                if (!tree.mods.annotations.isEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1023
                    // Nothing to do for separateAnnotationsKinds if
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1024
                    // there are no annotations of either kind.
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1025
                    TypeAnnotationPosition pos = new TypeAnnotationPosition();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1026
                    pos.type = TargetType.METHOD_RETURN;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1027
                    if (tree.sym.isConstructor()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1028
                        pos.pos = tree.pos;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1029
                        // Use null to mark that the annotations go with the symbol.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1030
                        separateAnnotationsKinds(tree, null, tree.sym, pos);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1031
                    } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1032
                        pos.pos = tree.restype.pos;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1033
                        separateAnnotationsKinds(tree.restype, tree.sym.type.getReturnType(),
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1034
                                tree.sym, pos);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1035
                    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1036
                }
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1037
                if (tree.recvparam != null && tree.recvparam.sym != null &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1038
                        !tree.recvparam.mods.annotations.isEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1039
                    // Nothing to do for separateAnnotationsKinds if
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1040
                    // there are no annotations of either kind.
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1041
                    // TODO: make sure there are no declaration annotations.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1042
                    TypeAnnotationPosition pos = new TypeAnnotationPosition();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1043
                    pos.type = TargetType.METHOD_RECEIVER;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1044
                    pos.pos = tree.recvparam.vartype.pos;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1045
                    separateAnnotationsKinds(tree.recvparam.vartype, tree.recvparam.sym.type,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1046
                            tree.recvparam.sym, pos);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1047
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1048
                int i = 0;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1049
                for (JCVariableDecl param : tree.params) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1050
                    if (!param.mods.annotations.isEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1051
                        // Nothing to do for separateAnnotationsKinds if
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1052
                        // there are no annotations of either kind.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1053
                        TypeAnnotationPosition pos = new TypeAnnotationPosition();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1054
                        pos.type = TargetType.METHOD_FORMAL_PARAMETER;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1055
                        pos.parameter_index = i;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1056
                        pos.pos = param.vartype.pos;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1057
                        separateAnnotationsKinds(param.vartype, param.sym.type, param.sym, pos);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1058
                    }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1059
                    ++i;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1060
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1061
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1062
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1063
            push(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1064
            // super.visitMethodDef(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1065
            if (sigOnly) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1066
                scan(tree.mods);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1067
                scan(tree.restype);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1068
                scan(tree.typarams);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1069
                scan(tree.recvparam);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1070
                scan(tree.params);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1071
                scan(tree.thrown);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1072
            } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1073
                scan(tree.defaultValue);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1074
                scan(tree.body);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1075
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1076
            pop();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1077
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1078
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1079
        /* Store a reference to the current lambda expression, to
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1080
         * be used by all type annotations within this expression.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1081
         */
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1082
        private JCLambda currentLambda = null;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1083
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1084
        public void visitLambda(JCLambda tree) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1085
            JCLambda prevLambda = currentLambda;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1086
            try {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1087
                currentLambda = tree;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1088
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1089
                int i = 0;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1090
                for (JCVariableDecl param : tree.params) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1091
                    if (!param.mods.annotations.isEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1092
                        // Nothing to do for separateAnnotationsKinds if
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1093
                        // there are no annotations of either kind.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1094
                        TypeAnnotationPosition pos = new TypeAnnotationPosition();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1095
                        pos.type = TargetType.METHOD_FORMAL_PARAMETER;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1096
                        pos.parameter_index = i;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1097
                        pos.pos = param.vartype.pos;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1098
                        pos.onLambda = tree;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1099
                        separateAnnotationsKinds(param.vartype, param.sym.type, param.sym, pos);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1100
                    }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1101
                    ++i;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1102
                }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1103
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1104
                push(tree);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1105
                scan(tree.body);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1106
                scan(tree.params);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1107
                pop();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1108
            } finally {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1109
                currentLambda = prevLambda;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1110
            }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1111
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1112
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1113
        /**
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1114
         * Resolve declaration vs. type annotations in variable declarations and
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1115
         * then determine the positions.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1116
         */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1117
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1118
        public void visitVarDef(final JCVariableDecl tree) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1119
            if (tree.mods.annotations.isEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1120
                // Nothing to do for separateAnnotationsKinds if
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1121
                // there are no annotations of either kind.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1122
            } else if (tree.sym == null) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1123
                // Something is wrong already. Quietly ignore.
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
  1124
            } else if (tree.sym.getKind() == ElementKind.PARAMETER) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1125
                // Parameters are handled in visitMethodDef or visitLambda.
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1126
            } else if (tree.sym.getKind() == ElementKind.FIELD) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1127
                if (sigOnly) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1128
                    TypeAnnotationPosition pos = new TypeAnnotationPosition();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1129
                    pos.type = TargetType.FIELD;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1130
                    pos.pos = tree.pos;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1131
                    separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1132
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1133
            } else if (tree.sym.getKind() == ElementKind.LOCAL_VARIABLE) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1134
                TypeAnnotationPosition pos = new TypeAnnotationPosition();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1135
                pos.type = TargetType.LOCAL_VARIABLE;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1136
                pos.pos = tree.pos;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1137
                pos.onLambda = currentLambda;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1138
                separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1139
            } else if (tree.sym.getKind() == ElementKind.EXCEPTION_PARAMETER) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1140
                TypeAnnotationPosition pos = new TypeAnnotationPosition();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1141
                pos.type = TargetType.EXCEPTION_PARAMETER;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1142
                pos.pos = tree.pos;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1143
                pos.onLambda = currentLambda;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1144
                separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1145
            } else if (tree.sym.getKind() == ElementKind.RESOURCE_VARIABLE) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1146
                TypeAnnotationPosition pos = new TypeAnnotationPosition();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1147
                pos.type = TargetType.RESOURCE_VARIABLE;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1148
                pos.pos = tree.pos;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1149
                pos.onLambda = currentLambda;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1150
                separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
  1151
            } else if (tree.sym.getKind() == ElementKind.ENUM_CONSTANT) {
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
  1152
                // No type annotations can occur here.
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1153
            } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1154
                // There is nothing else in a variable declaration that needs separation.
15718
8e54c8e43d38 8008077: update reference impl for type-annotations
jjg
parents: 15385
diff changeset
  1155
                Assert.error("Unhandled variable kind: " + tree + " of kind: " + tree.sym.getKind());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1156
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1157
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1158
            push(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1159
            // super.visitVarDef(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1160
            scan(tree.mods);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1161
            scan(tree.vartype);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1162
            if (!sigOnly) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1163
                scan(tree.init);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1164
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1165
            pop();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1166
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1167
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1168
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1169
        public void visitBlock(JCBlock tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1170
            // Do not descend into top-level blocks when only interested
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1171
            // in the signature.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1172
            if (!sigOnly) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1173
                scan(tree.stats);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1174
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1175
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1176
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1177
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1178
        public void visitAnnotatedType(JCAnnotatedType tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1179
            push(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1180
            findPosition(tree, tree, tree.annotations);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1181
            pop();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1182
            super.visitAnnotatedType(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1183
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1184
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1185
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1186
        public void visitTypeParameter(JCTypeParameter tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1187
            findPosition(tree, peek2(), tree.annotations);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1188
            super.visitTypeParameter(tree);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1189
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1190
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1191
        @Override
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1192
        public void visitNewClass(JCNewClass tree) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1193
            if (tree.def != null &&
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1194
                    !tree.def.mods.annotations.isEmpty()) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1195
                JCClassDecl classdecl = tree.def;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1196
                TypeAnnotationPosition pos = new TypeAnnotationPosition();
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1197
                pos.type = TargetType.CLASS_EXTENDS;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1198
                pos.pos = tree.pos;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1199
                if (classdecl.extending == tree.clazz) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1200
                    pos.type_index = -1;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1201
                } else if (classdecl.implementing.contains(tree.clazz)) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1202
                    pos.type_index = classdecl.implementing.indexOf(tree.clazz);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1203
                } else {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1204
                    // In contrast to CLASS elsewhere, typarams cannot occur here.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1205
                    Assert.error("Could not determine position of tree " + tree);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1206
                }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1207
                Type before = classdecl.sym.type;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1208
                separateAnnotationsKinds(classdecl, tree.clazz.type, classdecl.sym, pos);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1209
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1210
                // classdecl.sym.type now contains an annotated type, which
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1211
                // is not what we want there.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1212
                // TODO: should we put this type somewhere in the superclass/interface?
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1213
                classdecl.sym.type = before;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1214
            }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1215
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1216
            scan(tree.encl);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1217
            scan(tree.typeargs);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1218
            scan(tree.clazz);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1219
            scan(tree.args);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1220
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1221
            // The class body will already be scanned.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1222
            // scan(tree.def);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1223
        }
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1224
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1225
        @Override
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1226
        public void visitNewArray(JCNewArray tree) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1227
            findPosition(tree, tree, tree.annotations);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1228
            int dimAnnosCount = tree.dimAnnotations.size();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1229
            ListBuffer<TypePathEntry> depth = ListBuffer.lb();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1230
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1231
            // handle annotations associated with dimensions
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1232
            for (int i = 0; i < dimAnnosCount; ++i) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1233
                TypeAnnotationPosition p = new TypeAnnotationPosition();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1234
                p.pos = tree.pos;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1235
                p.onLambda = currentLambda;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1236
                p.type = TargetType.NEW;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1237
                if (i != 0) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1238
                    depth = depth.append(TypePathEntry.ARRAY);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1239
                    p.location = p.location.appendList(depth.toList());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1240
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1241
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1242
                setTypeAnnotationPos(tree.dimAnnotations.get(i), p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1243
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1244
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1245
            // handle "free" annotations
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1246
            // int i = dimAnnosCount == 0 ? 0 : dimAnnosCount - 1;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1247
            // TODO: is depth.size == i here?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1248
            JCExpression elemType = tree.elemtype;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1249
            depth = depth.append(TypePathEntry.ARRAY);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1250
            while (elemType != null) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1251
                if (elemType.hasTag(JCTree.Tag.ANNOTATED_TYPE)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1252
                    JCAnnotatedType at = (JCAnnotatedType)elemType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1253
                    TypeAnnotationPosition p = new TypeAnnotationPosition();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1254
                    p.type = TargetType.NEW;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1255
                    p.pos = tree.pos;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1256
                    p.onLambda = currentLambda;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1257
                    locateNestedTypes(elemType.type, p);
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1258
                    p.location = p.location.prependList(depth.toList());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1259
                    setTypeAnnotationPos(at.annotations, p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1260
                    elemType = at.underlyingType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1261
                } else if (elemType.hasTag(JCTree.Tag.TYPEARRAY)) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1262
                    depth = depth.append(TypePathEntry.ARRAY);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1263
                    elemType = ((JCArrayTypeTree)elemType).elemtype;
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1264
                } else if (elemType.hasTag(JCTree.Tag.SELECT)) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1265
                    elemType = ((JCFieldAccess)elemType).selected;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1266
                } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1267
                    break;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1268
                }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1269
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1270
            scan(tree.elems);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1271
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1272
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1273
        private void findPosition(JCTree tree, JCTree frame, List<JCAnnotation> annotations) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1274
            if (!annotations.isEmpty()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1275
                /*
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1276
                System.out.println("Finding pos for: " + annotations);
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1277
                System.out.println("    tree: " + tree + " kind: " + tree.getKind());
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1278
                System.out.println("    frame: " + frame + " kind: " + frame.getKind());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1279
                */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1280
                TypeAnnotationPosition p = new TypeAnnotationPosition();
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1281
                p.onLambda = currentLambda;
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1282
                resolveFrame(tree, frame, frames.toList(), p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1283
                setTypeAnnotationPos(annotations, p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1284
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1285
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1286
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1287
        private static void setTypeAnnotationPos(List<JCAnnotation> annotations,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1288
                TypeAnnotationPosition position) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1289
            for (JCAnnotation anno : annotations) {
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1290
                // attribute might be null during DeferredAttr;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1291
                // we will be back later.
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1292
                if (anno.attribute != null) {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1293
                    ((Attribute.TypeCompound) anno.attribute).position = position;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1294
                }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1295
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1296
        }
17578
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1297
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1298
        @Override
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1299
        public String toString() {
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1300
            return super.toString() + ": sigOnly: " + sigOnly;
46ac954e4a84 8013852: update reference impl for type-annotations
jjg
parents: 17278
diff changeset
  1301
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1302
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents:
diff changeset
  1303
}