use of javax.lang.model.element.TypeElement in project motan by weibocom.
the class MotanAsyncProcessor method addMethods.
private void addMethods(TypeElement interfaceClazz, TypeSpec.Builder classBuilder) {
List<? extends Element> elements = interfaceClazz.getEnclosedElements();
if (elements != null && !elements.isEmpty()) {
for (Element e : elements) {
if (ElementKind.METHOD.equals(e.getKind())) {
ExecutableElement method = (ExecutableElement) e;
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(method.getSimpleName().toString() + ASYNC).addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT).returns(ResponseFuture.class).addTypeVariables(getTypeNames(method.getTypeParameters()));
// add method params
List<? extends VariableElement> vars = method.getParameters();
for (VariableElement var : vars) {
methodBuilder.addParameter(ParameterSpec.builder(TypeName.get(var.asType()), var.getSimpleName().toString()).build());
}
classBuilder.addMethod(methodBuilder.build());
}
}
}
}
use of javax.lang.model.element.TypeElement in project motan by weibocom.
the class MotanAsyncProcessor method process.
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver()) {
return true;
}
for (Element elem : roundEnv.getElementsAnnotatedWith(MotanAsync.class)) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "MotanAsyncProcessor will process " + elem.toString() + ", generate class path:" + TARGET_DIR);
try {
writeAsyncClass(elem);
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "MotanAsyncProcessor done for " + elem.toString());
} catch (Exception e) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "MotanAsyncProcessor process " + elem.toString() + " fail. exception:" + e.getMessage());
e.printStackTrace();
}
}
return true;
}
use of javax.lang.model.element.TypeElement in project intellij-community by JetBrains.
the class JavacASTAnalyser method process.
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
final Set<? extends Element> elements = roundEnv.getRootElements();
for (Element element : elements) {
if (!(element instanceof TypeElement)) {
continue;
}
final TypeElement typeElement = (TypeElement) element;
final ImportsCollector importsCollector = new ImportsCollector();
importsCollector.scan(myTrees.getPath(typeElement).getParentPath().getLeaf(), myTrees);
final Set<String> imports = importsCollector.getImports();
final Set<String> staticImports = importsCollector.getStaticImports();
if (!imports.isEmpty() || !staticImports.isEmpty()) {
final String className = typeElement.getQualifiedName().toString();
myOutputConsumer.registerImports(className, imports, staticImports);
}
break;
}
return mySuppressOtherProcessors;
}
use of javax.lang.model.element.TypeElement in project lombok by rzwitserloot.
the class TestAp method process.
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
roundCounter++;
log("TestAP in round " + roundCounter);
boolean foundGetTest = false;
int annotatedElemCount = 0;
for (Element annotated : roundEnv.getElementsAnnotatedWith(ExampleAnnotation.class)) {
annotatedElemCount++;
for (Element child : annotated.getEnclosedElements()) {
if (child.getSimpleName().toString().equals("getTest") && child.getKind() == ElementKind.METHOD)
foundGetTest = true;
if (child instanceof ExecutableElement) {
TypeMirror returnType = ((ExecutableElement) child).getReturnType();
System.out.println("RETURN TYPE for " + child.getSimpleName() + ": " + returnType.getClass() + " -- " + returnType.toString());
}
}
}
if (foundGetTest)
log("RESULT: POSITIVE -- found the getTest method");
else if (annotatedElemCount > 0)
log("RESULT: NEGATIVE -- found the example class but there's no getTest method in it according to the type mirror.");
else
log("RESULT: AMBIVALENT -- The example class is not provided by 'getElementsAnnotatedWith' in this round. Not an issue, unless previously you got a NEGATIVE result.");
return false;
}
use of javax.lang.model.element.TypeElement in project spring-framework by spring-projects.
the class TypeHelper method getType.
public String getType(TypeMirror type) {
if (type == null) {
return null;
}
if (type instanceof DeclaredType) {
DeclaredType declaredType = (DeclaredType) type;
Element enclosingElement = declaredType.asElement().getEnclosingElement();
if (enclosingElement != null && enclosingElement instanceof TypeElement) {
return getQualifiedName(enclosingElement) + "$" + declaredType.asElement().getSimpleName().toString();
} else {
return getQualifiedName(declaredType.asElement());
}
}
return type.toString();
}
Aggregations