Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2017-2018 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.annotation.processing.visitor;
import io.micronaut.annotation.processing.PublicMethodVisitor;
import io.micronaut.core.annotation.AnnotationMetadata;
import io.micronaut.core.naming.NameUtils;
import io.micronaut.core.util.CollectionUtils;
import io.micronaut.inject.ast.ClassElement;
import io.micronaut.inject.ast.ElementModifier;
import io.micronaut.inject.ast.FieldElement;
import io.micronaut.inject.ast.PropertyElement;
import io.micronaut.inject.processing.JavaModelUtils;
import javax.annotation.Nonnull;
import javax.lang.model.element.*;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.TypeVariable;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
* A class element returning data from a {@link TypeElement}.
*
* @author James Kleeh
* @since 1.0
*/
public class JavaClassElement extends AbstractJavaElement implements ClassElement {
private final TypeElement classElement;
private final JavaVisitorContext visitorContext;
private final List extends TypeMirror> typeArguments;
/**
* @param classElement The {@link TypeElement}
* @param annotationMetadata The annotation metadata
* @param visitorContext The visitor context
*/
JavaClassElement(TypeElement classElement, AnnotationMetadata annotationMetadata, JavaVisitorContext visitorContext) {
super(classElement, annotationMetadata);
this.classElement = classElement;
this.visitorContext = visitorContext;
this.typeArguments = Collections.emptyList();
}
/**
* @param classElement The {@link TypeElement}
* @param annotationMetadata The annotation metadata
* @param visitorContext The visitor context
* @param typeArguments The type arguments
*/
JavaClassElement(TypeElement classElement, AnnotationMetadata annotationMetadata, JavaVisitorContext visitorContext, List extends TypeMirror> typeArguments) {
super(classElement, annotationMetadata);
this.classElement = classElement;
this.visitorContext = visitorContext;
this.typeArguments = typeArguments;
}
@Override
public Optional getSuperType() {
final TypeMirror superclass = classElement.getSuperclass();
if (superclass != null) {
final Element element = visitorContext.getTypes().asElement(superclass);
if (element instanceof TypeElement) {
TypeElement superElement = (TypeElement) element;
if (!Object.class.getName().equals(superElement.getQualifiedName().toString())) {
return Optional.of(
new JavaClassElement(
superElement,
visitorContext.getAnnotationUtils().getAnnotationMetadata(superElement),
visitorContext
)
);
}
}
}
return Optional.empty();
}
@Override
public boolean isAbstract() {
return classElement.getModifiers().contains(Modifier.ABSTRACT);
}
@Override
public boolean isInterface() {
return JavaModelUtils.isInterface(classElement);
}
@Override
public List getBeanProperties() {
Map props = new LinkedHashMap<>();
Map fields = new LinkedHashMap<>();
classElement.asType().accept(new PublicMethodVisitor