OpenJDK / amber / amber
changeset 56929:b2747f122ad9 records-and-sealed
adding test to check that anno processor wont see annotations before being trimmed
author | vromero |
---|---|
date | Fri, 12 Jul 2019 16:45:48 -0400 |
parents | e458917a1c54 |
children | f02972e89dec 400d527fd8a5 |
files | src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java test/langtools/tools/javac/records/annotations/AnnoProcessorOnRecordsTest.java |
diffstat | 2 files changed, 119 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java Fri Jul 12 14:47:44 2019 -0400 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java Fri Jul 12 16:45:48 2019 -0400 @@ -2874,6 +2874,8 @@ } } + //System.out.println("at Check.validateAnnotation: flags: " + Flags.toString(s.flags_field) + ", declaration tree " + declarationTree); + if (a.type.tsym.isAnnotationType() && !annotationApplicable(a, s)) { // debug //System.out.println("at Check.validateAnnotation: flags: " + Flags.toString(s.flags_field) + ", declaration tree " + declarationTree); @@ -3182,8 +3184,7 @@ return true; } else if (target == names.PARAMETER) { if (s.kind == VAR && - (s.owner.kind == MTH && (s.flags() & PARAMETER) != 0) || - (s.owner.kind == TYP && s.owner.isRecord())) { + (s.owner.kind == MTH && (s.flags() & PARAMETER) != 0)) { return true; } } else if (target == names.CONSTRUCTOR) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/records/annotations/AnnoProcessorOnRecordsTest.java Fri Jul 12 16:45:48 2019 -0400 @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @summary check that anno processors wont see annotations before being trimmed from records + * @modules jdk.compiler/com.sun.tools.javac.code + * jdk.compiler/com.sun.tools.javac.util + * @library /tools/javac/lib + * @build AnnoProcessorOnRecordsTest JavacTestingAbstractProcessor + * @compile -XDaccessInternalAPI -processor AnnoProcessorOnRecordsTest -proc:only AnnoProcessorOnRecordsTest.java + */ + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.Set; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.TypeElement; +import javax.tools.Diagnostic.Kind; + +import com.sun.tools.javac.code.Symbol; +import com.sun.tools.javac.code.Symbol.VarSymbol; + +import com.sun.tools.javac.util.Assert; + +@SupportedAnnotationTypes("*") +public class AnnoProcessorOnRecordsTest extends JavacTestingAbstractProcessor { + + @Retention(RetentionPolicy.RUNTIME) + @Target({ ElementType.PARAMETER }) + @interface Parameter {} + + @Retention(RetentionPolicy.RUNTIME) + @Target({ ElementType.METHOD }) + @interface Method {} + + @Retention(RetentionPolicy.RUNTIME) + @Target({ ElementType.FIELD }) + @interface Field {} + + @Retention(RetentionPolicy.RUNTIME) + @interface All {} + + record R1(@Parameter int i) {} + + record R2(@Method int i) {} + + record R3(@Field int i) {} + + record R4(@All int i) {} + + public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) { + for (TypeElement te : tes) { + for (Element e : renv.getElementsAnnotatedWith(te)) { + Symbol s = (Symbol)e; + if (s.isRecord() || s.owner.isRecord()) { + // debug + // System.out.println(te.toString()); + switch (te.toString()) { + case "AnnoProcessorOnRecordsTest.Parameter" : + // debug + // System.out.println(s.getKind()); + Assert.check(s.getKind() == ElementKind.PARAMETER); + break; + case "AnnoProcessorOnRecordsTest.Method": + // debug + // System.out.println(s.getKind()); + Assert.check(s.getKind() == ElementKind.METHOD); + break; + case "AnnoProcessorOnRecordsTest.Field": + // debug + // System.out.println(s.getKind()); + Assert.check(s.getKind() == ElementKind.FIELD); + break; + case "AnnoProcessorOnRecordsTest.All": + // debug + // System.out.println(s.getKind()); + Assert.check(s.getKind() == ElementKind.FIELD || s.getKind() == ElementKind.METHOD || s.getKind() == ElementKind.PARAMETER); + break; + default: + } + } + } + } + return true; + } +}