Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ace8fe729c8afcbdcac30bcca2131dfa64a16025 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*******************************************************************************
 * Copyright (c) 2016 IBM Corporation.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jdt.apt.pluggable.tests.processors.buildertester;

import java.io.BufferedWriter;
import java.io.IOException;
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.TypeElement;
import javax.tools.Diagnostic.Kind;
import javax.tools.FileObject;

@SupportedAnnotationTypes("targets.bug468893.Annotation")
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class Bug468893Processor extends AbstractProcessor {

	private static int count = 0;

	public Bug468893Processor() {
		count = 0;
	}
	@Override
	public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
		if (roundEnv.processingOver()) {
			count++;
			processingEnv.getMessager().printMessage(Kind.WARNING, "Processing over...");
			try {
				FileObject resource = processingEnv.getFiler().createSourceFile("generated.TypeIndex");
				BufferedWriter w = new BufferedWriter(resource.openWriter());
				try {
					w.append("package generated;");
					w.newLine();
					w.append("public interface TypeIndex {");
					w.newLine();
					w.append("\tpublic static final String ANNOTATED = null;");
					w.newLine();
					w.append("}");
					w.newLine();
				} finally {
					w.close();
				}
			} catch (IOException e) {
				processingEnv.getMessager().printMessage(Kind.ERROR, "Could not create output " + e.getMessage());
				throw new RuntimeException(e);
			}
		}
		return false;
	}

	public static int count() {
		return count;
	}
}

Back to the top