public static boolean checkReturnType( AnnotationMirror mirror, MethodDeclaration methodDeclaration, EclipseMessager messager) { TypeMirror returnType = methodDeclaration.getReturnType(); String returnTypeName = returnType.toString(); if (!(returnTypeName.startsWith("java.util.List") || returnTypeName.startsWith("java.util.Collection"))) { messager.printFixableError( methodDeclaration.getPosition(), "Method should return java.util.List or java.util.Collection", PLUGIN_ID, ERROR_wrong_return_type); return false; } return true; }
public static boolean checkTransferInfo( AnnotationMirror mirror, MethodDeclaration methodDeclaration, boolean checkReturnType, EclipseMessager messager) { Map<AnnotationTypeElementDeclaration, AnnotationValue> valueMap = mirror.getElementValues(); Set<Map.Entry<AnnotationTypeElementDeclaration, AnnotationValue>> valueSet = valueMap.entrySet(); boolean found = false; for (Map.Entry<AnnotationTypeElementDeclaration, AnnotationValue> annoKeyValue : valueSet) { if (annoKeyValue.getKey().getSimpleName().equals("transferInfo")) { found = true; checkTransferInfoType(annoKeyValue.getValue(), messager); checkIfAnnotationValueAttributeIsEntity( (AnnotationMirror) annoKeyValue.getValue().getValue(), "mappedBy", messager); break; } } if (!found && checkReturnType) { TypeMirror returnType = methodDeclaration.getReturnType(); String returnTypeName = returnType.toString(); if (returnTypeName.equals("java.util.List<?>") || returnTypeName.equals("java.util.List") || returnTypeName.equals("java.util.Collection<?>") || returnTypeName.equals("java.util.Collection")) { // System.out.println(returnType); SourcePosition pos = mirror.getPosition(); messager.printFixableError( pos, CLASS_OF_THE_COLLECTION_ELEMENTS_IS_NOT_SPECIFIED_AND_TRANSFER_INFO_PARAMETER_IS_MISSING, PLUGIN_ID, ERROR_transferInfo_is_missing); return false; } } return true; }