use of javax.lang.model.element.ExecutableElement in project immutables by immutables.
the class FactoryMethodAttributesCollector method collect.
void collect() {
ExecutableElement factoryMethodElement = (ExecutableElement) protoclass.sourceElement();
Parameterizable element = (Parameterizable) (factoryMethodElement.getKind() == ElementKind.CONSTRUCTOR ? factoryMethodElement.getEnclosingElement() : type.element);
for (VariableElement parameter : factoryMethodElement.getParameters()) {
TypeMirror returnType = parameter.asType();
ValueAttribute attribute = new ValueAttribute();
attribute.isGenerateAbstract = true;
attribute.reporter = reporter;
attribute.returnType = returnType;
attribute.element = parameter;
String parameterName = parameter.getSimpleName().toString();
attribute.names = styles.forAccessorWithRaw(parameterName, parameterName);
attribute.containingType = type;
attributes.add(attribute);
}
Instantiator encodingInstantiator = protoclass.encodingInstantiator();
@Nullable InstantiationCreator instantiationCreator = encodingInstantiator.creatorFor(element);
for (ValueAttribute attribute : attributes) {
attribute.initAndValidate(instantiationCreator);
}
if (instantiationCreator != null) {
type.additionalImports(instantiationCreator.imports);
}
type.attributes.addAll(attributes);
type.throwing = extractThrowsClause(factoryMethodElement);
}
use of javax.lang.model.element.ExecutableElement in project immutables by immutables.
the class FromSupertypesModel method isEligibleFromType.
private boolean isEligibleFromType(TypeElement typeElement, ValueAttribute attr) {
if (!typeElement.getTypeParameters().isEmpty()) {
return false;
}
@Nullable ExecutableElement accessor = findMethod(typeElement, attr.names.get);
if (accessor == null) {
// it (null) should never happen in theory
return false;
}
boolean sameReturnType = accessor.getReturnType().toString().equals(attr.returnType.toString());
if (sameReturnType) {
return true;
}
reporter.warning("Generated 'Builder.from' method will not copy from attribute '%s'" + " because it has different return type in supertype" + " (And we cannot handle generic specialization or covarian overrides yet)." + " Sometimes it is possible to avoid this by providing abstract override method in this value object", attr.name());
return false;
}
use of javax.lang.model.element.ExecutableElement in project immutables by immutables.
the class AccessorAttributesCollector method collectGeneratedCandidateMethods.
private void collectGeneratedCandidateMethods(TypeElement type) {
TypeElement originalType = CachingElements.getDelegate(type);
List<? extends Element> accessorsInSourceOrder;
if (originalType.getKind() == ElementKind.ANNOTATION_TYPE) {
accessorsInSourceOrder = SourceOrdering.getEnclosedElements(originalType);
} else {
AccessorProvider provider = SourceOrdering.getAllAccessorsProvider(processing.getElementUtils(), processing.getTypeUtils(), originalType);
accessorsInSourceOrder = provider.get();
accessorMapping = provider.accessorMapping();
}
for (ExecutableElement element : ElementFilter.methodsIn(accessorsInSourceOrder)) {
if (isElegibleAccessorMethod(element)) {
processGenerationCandidateMethod(element, originalType);
}
}
// inform use during checking for warnings.
for (Element element : processing.getElementUtils().getAllMembers(originalType)) {
if (element.getKind() == ElementKind.METHOD) {
switch(element.getSimpleName().toString()) {
case HASH_CODE_METHOD:
case TO_STRING_METHOD:
case EQUALS_METHOD:
processUtilityCandidateMethod((ExecutableElement) element, originalType);
break;
default:
}
}
}
}
use of javax.lang.model.element.ExecutableElement in project immutables by immutables.
the class ValueType method getNonAttributeAbstractMethodSignatures.
public Set<String> getNonAttributeAbstractMethodSignatures() {
if (element.getKind().isClass() || element.getKind().isInterface()) {
Set<String> signatures = new LinkedHashSet<>();
List<? extends Element> members = constitution.protoclass().environment().processing().getElementUtils().getAllMembers(CachingElements.getDelegate((TypeElement) element));
for (ExecutableElement m : ElementFilter.methodsIn(members)) {
if (!m.getParameters().isEmpty() || m.getSimpleName().contentEquals(AccessorAttributesCollector.HASH_CODE_METHOD) || m.getSimpleName().contentEquals(AccessorAttributesCollector.TO_STRING_METHOD)) {
if (m.getModifiers().contains(Modifier.ABSTRACT)) {
TypeMirror returnType = m.getReturnType();
if (!AccessorAttributesCollector.isEclipseImplementation(m)) {
returnType = AccessorAttributesCollector.asInheritedMemberReturnType(constitution.protoclass().processing(), CachingElements.getDelegate((TypeElement) element), m);
}
signatures.add(toSignature(m, returnType));
}
}
}
return signatures;
}
return Collections.emptySet();
}
use of javax.lang.model.element.ExecutableElement in project hibernate-orm by hibernate.
the class XmlMetaEntity method getType.
/**
* Returns the entity type for a property.
*
* @param propertyName The property name
* @param explicitTargetEntity The explicitly specified target entity type or {@code null}.
* @param expectedElementKind Determines property vs field access type
*
* @return The entity type for this property or {@code null} if the property with the name and the matching access
* type does not exist.
*/
private String getType(String propertyName, String explicitTargetEntity, ElementKind expectedElementKind) {
for (Element elem : element.getEnclosedElements()) {
if (!expectedElementKind.equals(elem.getKind())) {
continue;
}
TypeMirror mirror;
String name = elem.getSimpleName().toString();
if (ElementKind.METHOD.equals(elem.getKind())) {
name = StringUtil.getPropertyName(name);
mirror = ((ExecutableElement) elem).getReturnType();
} else {
mirror = elem.asType();
}
if (name == null || !name.equals(propertyName)) {
continue;
}
if (explicitTargetEntity != null) {
// TODO should there be a check of the target entity class and if it is loadable?
return explicitTargetEntity;
}
switch(mirror.getKind()) {
case INT:
{
return "java.lang.Integer";
}
case LONG:
{
return "java.lang.Long";
}
case BOOLEAN:
{
return "java.lang.Boolean";
}
case BYTE:
{
return "java.lang.Byte";
}
case SHORT:
{
return "java.lang.Short";
}
case CHAR:
{
return "java.lang.Char";
}
case FLOAT:
{
return "java.lang.Float";
}
case DOUBLE:
{
return "java.lang.Double";
}
case DECLARED:
{
return mirror.toString();
}
case TYPEVAR:
{
return mirror.toString();
}
default:
{
}
}
}
context.logMessage(Diagnostic.Kind.WARNING, "Unable to determine type for property " + propertyName + " of class " + getQualifiedName() + " using access type " + accessTypeInfo.getDefaultAccessType());
return null;
}
Aggregations