TypeMirror findInterface(TypeElement shadowPickerType, Class<?> interfaceClass) { TypeMirror shadowPickerMirror = elements .getTypeElement(interfaceClass.getName()) .asType(); for (TypeMirror typeMirror : shadowPickerType.getInterfaces()) { if (types.erasure(typeMirror).equals(types.erasure(shadowPickerMirror))) { return typeMirror; } } return null; }
private boolean isSetterApplicable(ArgumentAnnotatedField field, ExecutableElement setterMethod) { List<? extends VariableElement> parameters = setterMethod.getParameters(); if (parameters == null || parameters.size() != 1) { return false; } VariableElement parameter = parameters.get(0); return parameter.asType().equals(field.getElement().asType()); }
/** * Check if the given class or any of its super classes have a super method with the given name. * Private methods are ignored since the generated subclass can't call super on those. */ protected boolean hasSuperMethod(TypeElement classElement, Element attribute) { if (!Utils.isEpoxyModel(classElement.asType())) { return false; } for (Element subElement : classElement.getEnclosedElements()) { if (subElement.getKind() == ElementKind.METHOD) { ExecutableElement method = (ExecutableElement) subElement; if (!method.getModifiers().contains(Modifier.PRIVATE) && method.getSimpleName().toString().equals(attribute.getSimpleName().toString()) && method.getParameters().size() == 1 && method.getParameters().get(0).asType().equals(attribute.asType())) { return true; } } } Element superClass = typeUtils.asElement(classElement.getSuperclass()); return (superClass instanceof TypeElement) && hasSuperMethod((TypeElement) superClass, attribute); }
@Override public Optional<ExecutableElement> factoryMethod() { Optional<ExecutableElement> staticFactory = ElementFilter.methodsIn(element().getEnclosedElements()).stream() .filter(element -> element.getModifiers().contains(Modifier.STATIC)) .filter(element -> element.getSimpleName().toString().equalsIgnoreCase("create")) .filter(element -> element.getParameters().size() > 0) .filter(element -> element.getReturnType().equals(element().asType())) .findAny(); Optional<ExecutableElement> constructor = ElementFilter.constructorsIn(element().getEnclosedElements()).stream() .filter(element -> element.getParameters().size() > 0) .findAny(); return staticFactory.isPresent() ? staticFactory : constructor; }
public boolean existsWithin(TypeMirror type, List<Element> supportedTypes) { for (Element supportedType : supportedTypes) { if (typeUtils.erasure(type).equals(typeUtils.erasure(supportedType.asType()))) { return true; } } return false; }
/** * Get information about methods returning class type of the original class so we can duplicate * them in the generated class for chaining purposes */ protected void collectMethodsReturningClassType(TypeElement modelClass, Types typeUtils) { TypeElement clazz = modelClass; while (clazz.getSuperclass().getKind() != TypeKind.NONE) { for (Element subElement : clazz.getEnclosedElements()) { Set<Modifier> modifiers = subElement.getModifiers(); if (subElement.getKind() == ElementKind.METHOD && !modifiers.contains(Modifier.PRIVATE) && !modifiers.contains(Modifier.FINAL) && !modifiers.contains(Modifier.STATIC)) { TypeMirror methodReturnType = ((ExecutableType) subElement.asType()).getReturnType(); if (methodReturnType.equals(clazz.asType()) || typeUtils.isSubtype(clazz.asType(), methodReturnType)) { ExecutableElement castedSubElement = ((ExecutableElement) subElement); List<? extends VariableElement> params = castedSubElement.getParameters(); String methodName = subElement.getSimpleName().toString(); if (methodName.equals(RESET_METHOD) && params.isEmpty()) { continue; } methodsReturningClassType.add(new MethodInfo(methodName, modifiers, buildParamSpecs(params), castedSubElement.isVarArgs())); } } } clazz = (TypeElement) typeUtils.asElement(clazz.getSuperclass()); } }
/** * Given an attribute in a given type finds the corresponding attribute that it is referencing * in that referencing type. * * @param attribute attribute * @param referenced type being referenced * @return optional element it references */ Optional<? extends AttributeDescriptor> referencingAttribute(AttributeDescriptor attribute, EntityDescriptor referenced) { String referencedColumn = attribute.referencedColumn(); if (Names.isEmpty(referencedColumn)) { // using the id List<AttributeDescriptor> keys = referenced.attributes().stream() .filter(AttributeDescriptor::isKey).collect(Collectors.toList()); if (keys.size() == 1) { return Optional.of(keys.get(0)); } else { return keys.stream() .filter(other -> other.typeMirror().equals(attribute.typeMirror())) .findFirst(); } } else { return referenced.attributes().stream() .filter(other -> other.name().equals(referencedColumn)) .findFirst(); } }
private static ClassType determineShadowedClassName(ClassSymbol owner, VisitorState state) { for (Compound compound : owner.getAnnotationMirrors()) { if (Implements.class.getName().equals(compound.getAnnotationType().toString())) { for (Entry<MethodSymbol, Attribute> entry : compound.getElementValues().entrySet()) { String key = entry.getKey().name.toString(); Attribute value = entry.getValue(); if (key.equals("value")) { TypeMirror typeMirror = valueVisitor.visit(value); if (!typeMirror.equals(state.getTypeFromString("void"))) { return (ClassType) typeMirror; } } if (key.equals("className")) { String name = classNameVisitor.visit(value); if (!name.isEmpty()) { return (ClassType) state.getTypeFromString(name); } } } } } throw new RuntimeException("couldn't determine shadowed class for " + owner); }
declaredType.getEnclosingType())); for (TypeMirror tm : declaredType.getTypeArguments()) { if (!tm.equals(typeMirror)) { debugType(tm, element, indent + " "); type.getParameterTypes(), type.getReturnType())); for (TypeMirror tm : type.getParameterTypes()) { if (!tm.equals(typeMirror)) { debugType(tm, element, indent + " ");
private boolean isMethodProcessable(ExecutableElement element) { // if an immutable type with an implementation provided skip it if (!isUnimplementable() && element().getKind().isClass() && isImmutable() && !element.getModifiers().contains(Modifier.ABSTRACT)) { if (!ImmutableAnnotationKind.of(element()).isPresent() || !ImmutableAnnotationKind.of(element()).get().hasAnyMemberAnnotation(element)) { return false; } } String name = element.getSimpleName().toString(); // skip kotlin data class methods with component1, component2.. names if (isUnimplementable() && name.startsWith("component") && name.length() > "component".length()) { return false; } TypeMirror type = element.getReturnType(); boolean isInterface = element().getKind().isInterface(); boolean isTransient = Mirrors.findAnnotationMirror(element, Transient.class).isPresent(); // must be a getter style method with no args, can't return void or itself or its builder return type.getKind() != TypeKind.VOID && element.getParameters().isEmpty() && (isImmutable() || isInterface || !element.getModifiers().contains(Modifier.FINAL)) && (!isImmutable() || !type.equals(element().asType())) && !type.equals(builderType().orElse(null)) && !element.getModifiers().contains(Modifier.STATIC) && !element.getModifiers().contains(Modifier.DEFAULT) && (!isTransient || isInterface) && !name.equals("toString") && !name.equals("hashCode"); }
&& candidateConstructor.getParameters().get(0).asType().equals(valueAttribute.containedTypeElement.asType());
@Override public boolean eraseSuperClass(TypeElement classdecl, TypeElement superClass) { return superClass.getQualifiedName().toString().startsWith("java.") && !(superClass.asType().equals(context.symtab.throwableType) || superClass.asType().equals(context.symtab.exceptionType) || superClass.asType().equals(context.symtab.runtimeExceptionType) || superClass.asType().equals(context.symtab.errorType)) && !Util.isSourceElement(superClass); }
public boolean equals(Object obj) { return type != null && obj instanceof MirroredTypeExceptionProxy && type.equals(((MirroredTypeExceptionProxy) obj).type); }
public boolean equals(Object obj) { if (obj instanceof DecoratedTypeMirror) { return equals(((DecoratedTypeMirror) obj).delegate); } return delegate.equals(obj); }
private boolean isCompatibileType(TypeMirror left, TypeMirror right) { if (left.equals(right)) return true; final String leftStr = left.toString(); final String rightStr = right.toString(); if (leftStr.equals(rightStr)) return true; int ind = leftStr.indexOf('<'); if (ind == -1 || rightStr.indexOf('<') != ind) return false; if (left.getKind() != right.getKind()) return false; if (!leftStr.substring(0, ind).equals(rightStr.substring(0, ind))) return false; return types.isAssignable(right, left); }
public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Reference)) return false; final Reference that = (Reference) o; return annotations.equals(that.annotations) && type.equals(that.type); }
private TypeMirror resolveTypeParameter( TypeMirror formalType, List<TypeParameterDeclaration> typeParameterDeclarations) { for (TypeParameterDeclaration typeParameterDecl : typeParameterDeclarations) { if (formalType.equals(typeParameterDecl.getFormalType())) { return typeParameterDecl.getActualType(); } } return formalType; } }
public boolean isArrayButNotByteArray(TypeMirror t) { if(!isArray(t)) return false; ArrayType at = (ArrayType) t; TypeMirror ct = at.getComponentType(); return !ct.equals(primitiveByte); }
@Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof PrimitiveTypeNode)) { return false; } PrimitiveTypeNode other = (PrimitiveTypeNode) obj; return getType().equals(other.getType()); }
@Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof TypeCastNode)) { return false; } TypeCastNode other = (TypeCastNode) obj; // TODO: TypeMirror.equals may be too restrictive. // Check whether Types.isSameType is the better comparison. return getOperand().equals(other.getOperand()) && getType().equals(other.getType()); }