< prev index next >

test/langtools/tools/javac/processing/model/element/TestOrigin.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2012, 2015, 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. --- 1,7 ---- /* ! * Copyright (c) 2012, 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.
*** 28,48 **** * @library /tools/lib * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.main * jdk.jdeps/com.sun.tools.classfile * @build toolbox.ToolBox toolbox.JavacTask toolbox.TestRunner ! * @build TestOrigin * @run main TestOrigin */ import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; - import java.util.ArrayList; import java.util.Arrays; - import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; --- 28,46 ---- * @library /tools/lib * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.main * jdk.jdeps/com.sun.tools.classfile * @build toolbox.ToolBox toolbox.JavacTask toolbox.TestRunner ! * @build TestOrigin ListMembersAP * @run main TestOrigin */ import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set;
*** 93,103 **** List<String> log; List<String> expected; //from source: log = new JavacTask(tb) ! .options("-processor", ListMembersAP.class.getName()) .outdir(classes) .files(tb.findJavaFiles(src)) .run() .writeAll() .getOutputLines(Task.OutputKind.STDOUT); --- 91,101 ---- List<String> log; List<String> expected; //from source: log = new JavacTask(tb) ! .options("-processor", "ListMembersAP") .outdir(classes) .files(tb.findJavaFiles(src)) .run() .writeAll() .getOutputLines(Task.OutputKind.STDOUT);
*** 111,121 **** //from class: log = new JavacTask(tb) .options("-classpath", classes.toString(), "-processorpath", System.getProperty("test.classes"), ! "-processor", ListMembersAP.class.getName()) .outdir(classes) .files(src.resolve("Dummy.java")) .run() .writeAll() .getOutputLines(Task.OutputKind.STDOUT); --- 109,119 ---- //from class: log = new JavacTask(tb) .options("-classpath", classes.toString(), "-processorpath", System.getProperty("test.classes"), ! "-processor", "ListMembersAP") .outdir(classes) .files(src.resolve("Dummy.java")) .run() .writeAll() .getOutputLines(Task.OutputKind.STDOUT);
*** 126,164 **** if (!expected.equals(log)) throw new AssertionError("expected output not found: " + log); } - @SupportedAnnotationTypes("*") - public static final class ListMembersAP extends AbstractProcessor { - - @Override - public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { - if (!roundEnv.processingOver()) - return false; - - Elements elements = processingEnv.getElementUtils(); - TypeElement test = elements.getTypeElement("test.Test"); - List<? extends Element> members = new ArrayList<>(test.getEnclosedElements()); - - Collections.sort(members, - (e1, e2) -> e1.getSimpleName().toString().compareTo(e2.getSimpleName().toString())); - - for (Element el : members) { - System.out.println(el.getSimpleName() + ":" + elements.getOrigin(el)); - } - - return false; - } - - @Override - public SourceVersion getSupportedSourceVersion() { - return SourceVersion.latestSupported(); - } - - } - @Test public void testRepeatableAnnotations(Path base) throws Exception { Path src = base.resolve("src"); tb.writeJavaFiles(src, "package test; @A @A public class Test { }", --- 124,133 ----
< prev index next >