616N/A/*
2362N/A * Copyright (c) 2004, 2007, Oracle and/or its affiliates. All rights reserved.
616N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
616N/A *
616N/A * This code is free software; you can redistribute it and/or modify it
616N/A * under the terms of the GNU General Public License version 2 only, as
616N/A * published by the Free Software Foundation.
616N/A *
616N/A * This code is distributed in the hope that it will be useful, but WITHOUT
616N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
616N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
616N/A * version 2 for more details (a copy is included in the LICENSE file that
616N/A * accompanied this code).
616N/A *
616N/A * You should have received a copy of the GNU General Public License version
616N/A * 2 along with this work; if not, write to the Free Software Foundation,
616N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
616N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
616N/A */
616N/A
616N/A
616N/Aimport com.sun.mirror.apt.*;
616N/Aimport com.sun.mirror.declaration.*;
616N/Aimport com.sun.mirror.type.*;
616N/Aimport com.sun.mirror.util.*;
616N/A
616N/Aimport java.util.Collection;
616N/Aimport java.util.Set;
616N/Aimport java.util.Arrays;
616N/A
616N/Aimport static java.util.Collections.*;
616N/A
616N/A/*
616N/A * This class is used to test the ability to store static state across
616N/A * apt rounds.
616N/A */
616N/Apublic class StaticApf implements AnnotationProcessorFactory {
616N/A static int round = -1;
616N/A
616N/A // Process any set of annotations
616N/A private static final Collection<String> supportedAnnotations
616N/A = unmodifiableCollection(Arrays.asList("*"));
616N/A
616N/A // No supported options
616N/A private static final Collection<String> supportedOptions = emptySet();
616N/A
616N/A public Collection<String> supportedAnnotationTypes() {
616N/A return supportedAnnotations;
616N/A }
616N/A
616N/A public Collection<String> supportedOptions() {
616N/A return supportedOptions;
616N/A }
616N/A
616N/A public AnnotationProcessor getProcessorFor(Set<AnnotationTypeDeclaration> atds,
616N/A AnnotationProcessorEnvironment env) {
616N/A return new StaticAp(env);
616N/A }
616N/A
616N/A private static class StaticAp implements AnnotationProcessor {
616N/A private final AnnotationProcessorEnvironment env;
616N/A StaticAp(AnnotationProcessorEnvironment env) {
616N/A this.env = env;
616N/A }
616N/A
616N/A public void process() {
616N/A int size = env.getSpecifiedTypeDeclarations().size();
616N/A
616N/A try {
616N/A round++;
616N/A switch (size) {
616N/A case 0:
616N/A if (round == 0) {
616N/A env.getFiler().createSourceFile("Round1").print("class Round1 {}");
616N/A } else
616N/A throw new RuntimeException("Got " + size + " decl's in round " + round);
616N/A break;
616N/A
case 1:
if (round == 1) {
env.getFiler().createSourceFile("AhOne").print("class AhOne {}");
env.getFiler().createSourceFile("AndAhTwo").print("class AndAhTwo {}");
env.getFiler().createClassFile("Foo");
} else
throw new RuntimeException("Got " + size + " decl's in round " + round);
break;
case 2:
if (round != 2) {
throw new RuntimeException("Got " + size + " decl's in round " + round);
}
break;
}
} catch (java.io.IOException ioe) {
throw new RuntimeException();
}
}
}
}