1 /* |
1 /* |
2 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
388 |
388 |
389 if (sym.getKind() == ElementKind.PARAMETER || |
389 if (sym.getKind() == ElementKind.PARAMETER || |
390 sym.getKind() == ElementKind.LOCAL_VARIABLE || |
390 sym.getKind() == ElementKind.LOCAL_VARIABLE || |
391 sym.getKind() == ElementKind.RESOURCE_VARIABLE || |
391 sym.getKind() == ElementKind.RESOURCE_VARIABLE || |
392 sym.getKind() == ElementKind.EXCEPTION_PARAMETER) { |
392 sym.getKind() == ElementKind.EXCEPTION_PARAMETER) { |
393 // Make sure all type annotations from the symbol are also |
393 appendTypeAnnotationsToOwner(sym, typeAnnotations); |
394 // on the owner. If the owner is an initializer block, propagate |
394 } |
395 // to the type. |
395 } |
396 final long ownerFlags = sym.owner.flags(); |
396 |
397 if ((ownerFlags & Flags.BLOCK) != 0) { |
397 private void appendTypeAnnotationsToOwner(Symbol sym, List<Attribute.TypeCompound> typeAnnotations) { |
398 // Store init and clinit type annotations with the ClassSymbol |
398 // Make sure all type annotations from the symbol are also |
399 // to allow output in Gen.normalizeDefs. |
399 // on the owner. If the owner is an initializer block, propagate |
400 ClassSymbol cs = (ClassSymbol) sym.owner.owner; |
400 // to the type. |
401 if ((ownerFlags & Flags.STATIC) != 0) { |
401 final long ownerFlags = sym.owner.flags(); |
402 cs.appendClassInitTypeAttributes(typeAnnotations); |
402 if ((ownerFlags & Flags.BLOCK) != 0) { |
403 } else { |
403 // Store init and clinit type annotations with the ClassSymbol |
404 cs.appendInitTypeAttributes(typeAnnotations); |
404 // to allow output in Gen.normalizeDefs. |
405 } |
405 ClassSymbol cs = (ClassSymbol) sym.owner.owner; |
|
406 if ((ownerFlags & Flags.STATIC) != 0) { |
|
407 cs.appendClassInitTypeAttributes(typeAnnotations); |
406 } else { |
408 } else { |
407 sym.owner.appendUniqueTypeAttributes(sym.getRawTypeAttributes()); |
409 cs.appendInitTypeAttributes(typeAnnotations); |
408 } |
410 } |
|
411 } else { |
|
412 sym.owner.appendUniqueTypeAttributes(typeAnnotations); |
409 } |
413 } |
410 } |
414 } |
411 |
415 |
412 // This method has a similar purpose as |
416 // This method has a similar purpose as |
413 // {@link com.sun.tools.javac.parser.JavacParser.insertAnnotationsToMostInner(JCExpression, List<JCTypeAnnotation>, boolean)} |
417 // {@link com.sun.tools.javac.parser.JavacParser.insertAnnotationsToMostInner(JCExpression, List<JCTypeAnnotation>, boolean)} |
941 } else { |
945 } else { |
942 throw new AssertionError("Could not determine position of tree " + tree + |
946 throw new AssertionError("Could not determine position of tree " + tree + |
943 " within frame " + frame); |
947 " within frame " + frame); |
944 } |
948 } |
945 |
949 |
|
950 case BINDING_PATTERN: |
946 case VARIABLE: |
951 case VARIABLE: |
947 VarSymbol v = ((JCVariableDecl)frame).sym; |
952 VarSymbol v = frame.hasTag(Tag.BINDINGPATTERN) ? ((JCBindingPattern) frame).symbol : ((JCVariableDecl) frame).sym; |
948 if (v.getKind() != ElementKind.FIELD) { |
953 if (v.getKind() != ElementKind.FIELD) { |
949 v.owner.appendUniqueTypeAttributes(v.getRawTypeAttributes()); |
954 appendTypeAnnotationsToOwner(v, v.getRawTypeAttributes()); |
950 } |
955 } |
951 switch (v.getKind()) { |
956 switch (v.getKind()) { |
952 case LOCAL_VARIABLE: |
957 case LOCAL_VARIABLE: |
953 return TypeAnnotationPosition |
958 return TypeAnnotationPosition |
954 .localVariable(location.toList(), currentLambda, |
959 .localVariable(location.toList(), currentLambda, |