Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License. See License.txt in the project root for
license information.
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
package com.microsoft.azure.management.apigeneration;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic.Kind;
@SupportedAnnotationTypes({
"com.microsoft.azure.management.apigeneration.LangDefinition",
"com.microsoft.azure.management.apigeneration.Fluent",
"com.microsoft.azure.management.apigeneration.Beta"})
public class LangDefinitionProcessor extends AbstractProcessor {
private AbstractProcessor innerProcessor;
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
try {
Class<AbstractProcessor> clz = AbstractProcessor.class;
Object clzObj = LangDefinitionProcessor.class.getClassLoader().loadClass("com.microsoft.azure.management.apigeneration.LangProcessor").newInstance();
this.innerProcessor = clz.cast(clzObj);
this.innerProcessor.init(processingEnv);
} catch(final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
this.innerProcessor = null;
}
}
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if(roundEnv.processingOver()) {
return true;
}
// Process @Beta
processBeta(roundEnv);
// Process other conversion annotations
if(this.innerProcessor != null) {
return this.innerProcessor.process(annotations, roundEnv);
}
return true;
}
private void processBeta(RoundEnvironment roundEnv) {
Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(Beta.class);
for (Element element : elements) {
StringBuilder info = new StringBuilder()
.append("@Beta: ")
.append(element.getSimpleName())
.append(" - ")
.append(element.getAnnotation(Beta.class).warningText());
processingEnv.getMessager().printMessage(Kind.WARNING, info.toString());
}
}
}